/[pub]/suikawiki/script/misc/plugins/WikiPageRemove.wp2
Suika

Contents of /suikawiki/script/misc/plugins/WikiPageRemove.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Feb 1 12:12:23 2004 UTC (20 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +17 -5 lines
Use try..catch for WikiDB

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiPageRemove
5     @Description:
6     @@@: WikiPage removing
7     @@lang:en
8     @License: %%GPL%%
9     @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.2 @Date.RCS: $Date: 2004/01/16 07:56:13 $
16 wakaba 1.1 @RequiredPlugin[list]:
17     Error
18     WikiEdit
19     WikiFormCore
20     WikiResource
21 wakaba 1.2 @Use:
22     use Message::Util::Error;
23 wakaba 1.1
24     PluginConst:
25     @NS_XHTML1:
26     http://www.w3.org/1999/xhtml
27    
28     ViewDefinition:
29     @Mode: wpr--remove
30     @Condition:
31     @@http-method[list]:
32     POST
33     @Description:
34     @@@: Removing a WikiPage
35     @@lang: en
36     @method:
37     @@Name: main
38     @@@:
39     $self->{view}->{wiki}->{var}->{db}->{read_only}->{'content'} = 0;
40     $self->{view}->{wiki}->{var}->{db}->{read_only}->{'lastmodified'} = 0;
41     $self->{view}->init_db;
42     my $page = $self->{view}->{wiki}->{var}->{page};
43    
44     ## Check confliction
45 wakaba 1.2 my $current_content;
46     try {
47     $current_content = $self->{view}->{wiki}->{db}->get (content => $page);
48     } catch SuikaWiki::DB::Util::Error with {
49     $self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
50     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
51     };
52 wakaba 1.1 if (length $current_content) {
53     my $current_digest = SuikaWiki::Plugin->module_package ('WikiEdit')
54     ->digest ($current_content,
55     normalize => 1);
56     my $prev_digest
57     = $self->{view}->{wiki}->{input}->parameter ('we--digest');
58     if ($current_digest ne $prev_digest) {
59     SuikaWiki::Plugin->module_package ('Error')
60     ->report_error_simple
61     ($self->{view}->{wiki},
62     WikiPageRename => SuikaWiki::Plugin
63     ->module_package
64     ('WikiResource')
65     ->get_text
66     (name =>
67     'WikiPageRename:Modified',
68     param => {wiki => $self->{view}->{wiki}},
69     wiki => $self->{view}->{wiki}));
70     $self->{view}->{wiki}->view_in_mode (mode => '-general-error');
71     throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';
72     }
73     }
74    
75 wakaba 1.2 try {
76     $self->{view}->{wiki}->{db}->delete (content => $page);
77     $self->{view}->{wiki}->{db}->delete (lastmodified => $page);
78     } catch SuikaWiki::DB::Util::Error with {
79     $self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
80     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
81     };
82 wakaba 1.1 $self->{view}->{wiki}->view_in_mode (mode => '-deleted');
83    
84     FormattingRule:
85     @Category[list]: view
86     @Name: wpr--remove-button
87     @Description:
88     @@@: Removing button
89     @@lang: en
90     @Parameter:
91     @@Name: page
92     @@Type: WikiName
93     @@Default: (auto)
94     @@Description:
95     @@@@: WikiPage that is editing
96     @@@lang:en
97     @Formatting:
98     __ATTRTEXT:%page__;
99    
100     my $page = $p->{page} ? [split m#//#, $p->{page}]
101     : $o->{wiki}->{var}->{page};
102     local $o->{var} = {
103     #content
104     is_admin_mode => 0,
105     is_conflict_mode => 0,
106     #is_new_page_template
107     };
108     $o->{var}->{content} = SuikaWiki::Plugin->module_package ('WikiEdit')
109     ->get_content ($o, $page);
110     SuikaWiki::Plugin->module_package ('WikiFormCore')
111     ->make_form_in_html
112     ($p->{-parent}, ' ',
113     wiki => $o->{wiki},
114     o => $o,
115     index => -1,
116     output => {
117     mode => 'wpr--remove',
118     page => $page,
119     hidden => sub {
120     my ($hidden, $o) = @_;
121     for ($hidden->append_new_node (type => '#element',
122     namespace_uri => $NS_XHTML1,
123     local_name => 'input')) {
124     $_->set_attribute (type => 'hidden');
125     $_->set_attribute (name => 'we--digest');
126     $_->set_attribute (value => ($o->{var}->{is_new_page_template}?'':
127     SuikaWiki::Plugin->module_package ('WikiEdit')
128     ->digest ($o->{var}->{content},
129     normalize => 1)));
130     $_->option (use_EmptyElemTag => 1);
131     }
132     for ($hidden->append_new_node (type => '#element',
133     namespace_uri => $NS_XHTML1,
134     local_name => 'input')) {
135     $_->set_attribute (type => 'submit');
136     $_->set_attribute (value => SuikaWiki::Plugin
137     ->module_package ('WikiResource')
138     ->append_node
139     (name => 'WikiPageRemove:Remove:Label',
140     param => $o,
141     wiki => $o->{wiki})->inner_text);
142     $_->set_attribute (title => SuikaWiki::Plugin
143     ->module_package ('WikiResource')
144     ->append_node
145     (name =>
146     'WikiPageRemove:Remove:Description',
147     param => $o,
148     wiki => $o->{wiki})->inner_text);
149     $_->option (use_EmptyElemTag => 1);
150     }
151     },
152     });
153    
154    
155     Resource:
156     @WikiPageRename:Modified:
157     @@@:
158     WikiPage you are attempting to remove ("%page-name;") has been modified.
159     Please review latest version of the page before removal.
160     @@lang:en
161     @WikiPageRemove:Remove:Description:
162     @@@:Removing WikiPage "%page-name;", w/o any caution nor backup.
163     @@lang:en
164     @WikiPageRemove:Remove:Label:
165     @@@:Remove WikiPage
166     @@lang:en

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24