/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/WikiEdit.wp2
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/WikiEdit.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Sun Apr 25 07:06:50 2004 UTC (21 years ago) by wakaba
Branch: MAIN
Branch point for: paragraph-200404
Changes since 1.11: +48 -10 lines
LeafProp database module added; content_prop implemented; Media type property implemented

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiEdit
5     @Description:
6     @@@: WikiPage editing components
7     @@lang:en
8 wakaba 1.9 @License: %%Perl%%
9 wakaba 1.1 @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.9 @Date.RCS:
16 wakaba 1.12 $Date: 2004/04/17 04:16:15 $
17 wakaba 1.1 @RequiredModule[list]:
18     Digest::SHA1
19 wakaba 1.2 @RequiredPlugin[list]:
20     WikiView
21     WikiStruct
22     WikiLinking
23     WikiFormCore
24 wakaba 1.3 WikiFormText
25 wakaba 1.6 WikiResource
26 wakaba 1.2 HTML
27 wakaba 1.7 @Use:
28     use Message::Util::Error;
29 wakaba 1.12 @Namespace:
30     @@media-type:
31     http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt#
32 wakaba 1.1
33     PluginConst:
34     @NS_XHTML1:
35     http://www.w3.org/1999/xhtml
36    
37     ViewDefinition:
38     @Mode: edit
39     @Condition:
40     @@http-method[list]:
41     GET
42     HEAD
43     @Description:
44     @@@: Edit WikiPage content as whole, as a plaintext
45     @@lang: en
46     @template:
47     @@http-status-code: 200
48     @@media-type: text/html
49     @@use-media-type-charset: 1
50     @@expires: %%edit%%
51     @@body:
52     %html-document (
53     title => {%res(name=>{Edit:WebPageTitle});}p,
54 wakaba 1.2 link-meta => {%template (name => links);
55     %html-meta(name => ROBOTS, content => NOINDEX);}p,
56 wakaba 1.1 content => {
57     %template (
58     name => ws--page,
59 wakaba 1.2 -content => {%template (name => we--edit-body);},
60 wakaba 1.1 );
61     }p,
62     );
63    
64     ViewDefinition:
65     @Mode: write
66     @Condition:
67     @@http-method[list]:
68     POST
69     @Description:
70     @@@: Saving modified (new) WikiPage content
71     @@lang: en
72 wakaba 1.7 @Use:
73     use Message::Util::Error;
74 wakaba 1.1 @method:
75     @@@:
76 wakaba 1.12 my $wiki = $self->{view}->{wiki};
77     my $touch = $wiki->{input}->parameter ('we--touch');
78 wakaba 1.1
79 wakaba 1.12 $wiki->{var}->{db}->{read_only}->{'content'} = 0;
80     $wiki->{var}->{db}->{read_only}->{'content_prop'} = 0;
81     $wiki->{var}->{db}->{read_only}->{'lastmodified'} = 0
82 wakaba 1.1 if $touch;
83 wakaba 1.12 $wiki->{var}->{db}->{read_only}->{'referer'} = 0;
84     $wiki->init_db;
85 wakaba 1.1
86 wakaba 1.12 my $page = $wiki->{var}->{page};
87 wakaba 1.1
88     ## Check confliction
89 wakaba 1.7 my $current_content;
90     try {
91     $current_content = $self->{view}->{wiki}->{db}->get (content => $page);
92     } catch SuikaWiki::DB::Util::Error with {
93 wakaba 1.9 my $err = shift;
94     if ($err->{-type} eq 'ERROR_REPORTED') {
95     $err->throw;
96     } else {
97     $self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
98     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
99     }
100 wakaba 1.7 };
101 wakaba 1.10
102     my $current_digest = '';
103 wakaba 1.1 if (length $current_content) {
104 wakaba 1.10 $current_digest = __FUNCPACK__->digest ($current_content,
105 wakaba 1.2 normalize => 1);
106 wakaba 1.1 my $prev_digest
107     = $self->{view}->{wiki}->{input}->parameter ('we--digest');
108     if ($current_digest ne $prev_digest) {
109 wakaba 1.2 return $self->{view}->{wiki}->view_in_mode
110     (mode => '-conflict');
111 wakaba 1.1 }
112     }
113    
114     my $new_content
115     = $self->{view}->{wiki}->{input}->parameter ('we--content');
116     if (length $new_content) {
117 wakaba 1.10 ## Really modified?
118     my $new_digest = __FUNCPACK__->digest ($new_content, normalize => 1);
119     if ($current_digest ne $new_digest) {
120    
121     ## Update content
122 wakaba 1.7 try {
123 wakaba 1.10 $self->{view}->{wiki}->{db}->set (content => $page => $new_content);
124 wakaba 1.7 } catch SuikaWiki::DB::Util::Error with {
125 wakaba 1.9 my $err = shift;
126 wakaba 1.10 if ($err->{-type} eq 'ERROR_REPORTED') {
127     $err->throw;
128     } else {
129     $self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
130     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
131     }
132 wakaba 1.7 };
133 wakaba 1.12
134     UPDATE_MEDIATYPE: {
135     my $mt = $wiki->{input}->parameter ('wf--media-type');
136     last UPDATE_MEDIATYPE if not $mt or $mt eq '#asis';
137     CHECK_MEDIATYPE: {
138     for (keys %{$wiki->{config}
139     ->{<Q:media-type:accept-media-type>}||{}}) {
140     last CHECK_MEDIATYPE if $mt eq $_;
141     }
142     last UPDATE_MEDIATYPE;
143     }
144    
145     my $prop = $wiki->{db}->get (content_prop => $page);
146     $prop->set_attribute (<Q:media-type:media-type> => $mt);
147     $wiki->{db}->set (content_prop => $page => $prop);
148     }
149 wakaba 1.10
150     ## Update lastmodified
151     if ($touch) {
152     try {
153     $self->{view}->{wiki}->{db}->set (lastmodified => $page => time);
154     } catch SuikaWiki::DB::Util::Error with {
155     my $err = shift;
156     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
157     };
158     }
159 wakaba 1.1 }
160 wakaba 1.10
161 wakaba 1.1 my $new_mode = $self->{view}->{wiki}->{input}->parameter
162     ('we--mode-modified');
163     $new_mode =~ s/[^0-9A-Za-z._-]+//g;
164 wakaba 1.10 my $uri = $self->{view}->{wiki}->uri_reference
165     (page => $page,
166     mode => $new_mode,
167     up_to_date => 1,
168     param => {we__mode_modified => $new_mode});
169 wakaba 1.1
170     require SuikaWiki::Output::HTTP;
171     my $output = SuikaWiki::Output::HTTP->new
172 wakaba 1.10 (wiki => $self->{view}->{wiki});
173 wakaba 1.1 $output->set_redirect (uri => $uri, status_code => 303);
174     $output->output (output => 'http-cgi');
175     } else {
176 wakaba 1.7 try {
177     $self->{view}->{wiki}->{db}->delete (content => $page);
178     $self->{view}->{wiki}->{db}->delete (lastmodified => $page) if $touch;
179     } catch SuikaWiki::DB::Util::Error with {
180 wakaba 1.9 my $err = shift;
181     if ($err->{-type} eq 'ERROR_REPORTED') {
182     $err->throw;
183     } else {
184     $self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
185     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
186     }
187 wakaba 1.7 };
188 wakaba 1.2 $self->{view}->{wiki}->view_in_mode (mode => '-deleted');
189 wakaba 1.1 }
190     @@Name: main
191    
192     ViewDefinition:
193     @Mode: adminedit
194     @Condition:
195     @@http-method[list]:
196     GET
197     HEAD
198     @Description:
199     @@@: Edit WikiPage content as whole, as a plaintext (administrator mode)
200     @@lang: en
201     @template:
202     @@http-status-code: 200
203     @@media-type: application/xhtml+xml
204     @@use-media-type-charset: 1
205     @@expires: %%edit%%
206     @@body:
207 wakaba 1.2 %html-document (
208     title => {%res(name=>{Edit:Admin:WebPageTitle});}p,
209 wakaba 1.6 link-meta => {%template (name => links);
210 wakaba 1.2 %html-meta(name=>ROBOTS,content=>NOINDEX);}p,
211     content => {
212     %template (
213     name => ws--page,
214     -content => {%template (name => we--adminedit-body);},
215     );
216     }p,
217     );
218 wakaba 1.1
219 wakaba 1.2 ViewDefinition:
220 wakaba 1.1 @Mode: -conflict
221     @Condition:
222     @@http-method[list]:
223     GET
224     HEAD
225     @Description:
226     @@@: Confliction message
227     @@lang: en
228     @template:
229     @@http-status-code: 409
230     @@media-type: text/html
231     @@use-media-type-charset: 1
232     @@body:
233 wakaba 1.2 %html-document (
234     title => {%res(name=>{Edit:Conflict:WebPageTitle});}p,
235     link-meta => {%template(name=>links);
236     %html-meta(name=>ROBOTS,content=>NOINDEX);}p,
237     content => {
238     %template (
239     name => ws--page,
240     -content => {
241 wakaba 1.6 %section (
242 wakaba 1.2 title => {%res(name=>{Edit:Conflict:Title});}p, heading,
243     content => {%template (name => we--conflict-body);}p,
244     );
245     },
246     );
247     }p,
248     );
249    
250     ViewDefinition:
251     @Mode: -deleted
252     @Condition:
253     @@http-method[list]:
254     GET
255     HEAD
256     @Expires:%%view%%
257     @Description:
258     @@@: Confliction message
259     @@lang: en
260     @template:
261     @@http-status-code: 200
262     @@media-type: text/html
263     @@use-media-type-charset: 1
264     @@body:
265     %html-document (
266     title => {%res (name => {Edit:Deleted:WebPageTitle});}p,
267     link-meta => {%template (name => links);
268     %html-meta (name => ROBOTS, content => NOINDEX);}p,
269     content => {
270     %template (
271     name => ws--page,
272     -content => {
273 wakaba 1.6 %section (
274 wakaba 1.2 title => {%res(name=>{Edit:Deleted:Title});}p, heading,
275     content => {
276     %paragraph (content => {%res
277     (name => {Edit:Deleted:Description});}p);
278     }p,
279     );
280     },
281     );
282     }p,
283     );
284 wakaba 1.1
285     ViewFragment:
286     @Name: links
287     @Description:
288     @@@: Link to edit mode of the WikiPage
289     @@lang:en
290     @Formatting:
291 wakaba 1.6 %link-wiki(mode => edit, up-to-date,
292     rel => edit, class => wiki-cmd,
293     description => {%res(name=>{Link:Edit:Description});}p);
294     %link-wiki(mode => adminedit, up-to-date,
295     rel=>edit, class => wiki-cmd,
296     description => {%res(name=>{Link:AdminEdit:Description});}p);
297 wakaba 1.1
298     ViewFragment:
299     @Name: navbar
300     @Description:
301     @@@: Link to edit mode of the WikiPage
302     @Order: 10
303     @Formatting:
304 wakaba 1.3 %link-to-wikipage (
305     mode => edit,
306     rel => edit,
307     up-to-date,
308     label => {%link-to-it (
309     class => wiki-cmd,
310     label => {%res (name => EditThisPage);}p,
311     description => {%res (name => EditThisPageLong);}p,
312     );},
313     page-anchor-name => edit,
314     );
315 wakaba 1.2
316     ViewFragment:
317     @Template[list]:
318     we--conflict-body
319     @Order: 30
320     @Description:
321     @@@: Conflict report
322     @@lang:en
323     @Formatting:
324     %paragraph (content=>{%res(name=>{Edit:Conflict:Description});}p);
325     %we--conflict-modified-content;
326 wakaba 1.6 %section (
327 wakaba 1.2 id => edit-conflict-diff,
328     title => {%res(name=>{Edit:Conflict:Diff:Title});}p, heading,
329     content => {
330     %paragraph (
331     content => {%res(name=>{Edit:Conflict:Diff:Description});}p);
332     %conflict-diff;
333     }p,
334     );
335    
336     ViewFragment:
337     @Template[list]: we--edit-body
338     @Order:80
339     @Description:
340     @@@: Editing WikiPage form section
341     @@lang:en
342     @Formatting:
343 wakaba 1.6 %section (
344 wakaba 1.2 id => edit,
345     title => {%res (name => {Edit:Title});}p, heading,
346     content => {%edit-form;}p,
347     );
348    
349     ViewFragment:
350     @Template[list]: we--adminedit-body
351     @Order:80
352     @Description:
353     @@@: Editing WikiPage form section (Admin edit mode)
354     @@lang:en
355     @Formatting:
356 wakaba 1.6 %section (
357 wakaba 1.2 id => edit,
358     title => {%res(name=>{Edit:Title});}p, heading,
359     content => {%edit-form(admin);}p,
360     );
361    
362     ViewFragment:
363     @Template[list]: we--conflict-body
364     @Order: 80
365     @Description:
366     @@@: Editing-WikiPage-form section (conflict mode)
367     @@lang:en
368     @Formatting:
369 wakaba 1.6 %section (
370 wakaba 1.2 id => edit,
371     title => {%res(name=>{Edit:Title});}p, heading,
372     content => {
373     %paragraph(name=>{%res(name=>{Edit:Conflict:Edit:Description});}p);
374     %edit-form;
375     }p,
376     );
377 wakaba 1.1
378     ViewFragment:
379     @Name: we--edit
380     @Description:
381     @@@: Edit form --- main textarea
382     @@lang:en
383     @Order: 0
384     @Formatting:
385 wakaba 1.5 %textarea (id => we--content, size => {%res (name=>{Edit:Form:Size});}p,
386 wakaba 1.6 source => content, lines => {%res (name=>{Edit:Form:Lines});}p);
387 wakaba 1.1 ViewFragment:
388     @Name: we--edit
389     @Description:
390     @@@: Submit button
391     @@lang:en
392     @Order: 200
393     @Formatting:
394     %submit(label=>{%res(name=>{Edit:Save});}p);
395    
396     FormattingRule:
397     @Category[list]: view
398     @Name: edit-form
399     @Description:
400     @@@: Provides WikiPage editing form
401     @@lang: en
402     @Parameter:
403     @@Name: admin
404     @@Type: boolean
405     @@Default: {0}
406     @@Description:
407     @@@@: Whether administrator's editing mode or not
408     @@@lang:en
409 wakaba 1.5 @Parameter:
410     @@Name: page
411     @@Type: WikiName
412     @@Default: (auto)
413     @@Description:
414     @@@@: WikiPage that is editing
415     @@@lang:en
416 wakaba 1.1 @Formatting:
417 wakaba 1.5 __ATTRTEXT:%admin__;__ATTRTEXT:%page__;
418 wakaba 1.8 my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page});
419 wakaba 1.5 my $template = $o->{wiki}->{view}->assemble_template ('we__edit');
420     local $o->{var} = {
421 wakaba 1.1 #content
422     is_admin_mode => $p->{admin},
423     is_conflict_mode => 0,
424     #is_new_page_template
425     };
426 wakaba 1.12 my $content = __FUNCPACK__->get_content ($o, $page);
427     $o->{var}->{content} = $content->{content};
428     $o->{var}->{content_prop} = $content->{content_prop};
429 wakaba 1.5 SuikaWiki::Plugin->module_package ('WikiFormCore')
430     ->make_form_in_html
431     ($p->{-parent}, $template,
432     wiki => $o->{wiki},
433     o => $o,
434     index => -1,
435     output => {
436     mode => 'write',
437     page => $page,
438     hidden => sub {
439     my ($hidden, $o) = @_;
440 wakaba 1.3 for ($hidden->append_new_node (type => '#element',
441 wakaba 1.5 namespace_uri => $NS_XHTML1,
442     local_name => 'input')) {
443 wakaba 1.1 $_->set_attribute (type => 'hidden');
444     $_->set_attribute (name => 'we--digest');
445 wakaba 1.2 $_->set_attribute (value => ($o->{var}->{is_new_page_template}?'':
446 wakaba 1.5 __FUNCPACK__->digest ($o->{var}->{content},
447     normalize => 1)));
448 wakaba 1.1 $_->option (use_EmptyElemTag => 1);
449     }
450 wakaba 1.5 },
451     });
452    
453 wakaba 1.1
454     FormattingRule:
455     @Category[list]: view
456 wakaba 1.2 @Name: we--conflict-modified-content
457 wakaba 1.1 @Description:
458     @@@:
459 wakaba 1.2 Modified content that is conflicted with current content
460 wakaba 1.1 @@lang:en
461     @Formatting:
462 wakaba 1.3 $p->{-parent}->append_new_node (type => '#element',
463 wakaba 1.2 namespace_uri => $NS_XHTML1,
464 wakaba 1.3 local_name => 'pre')
465     ->append_text (scalar $o->{wiki}->{input}->parameter ('we--content'));
466 wakaba 1.1
467     FormattingRule:
468     @Category[list]:view
469     @Name: conflict-diff
470     @Description:
471     @@@:
472     Provides marked diff between latest WikiPage content and
473     submitted one
474     @@lang:en
475     @Formatting:
476 wakaba 1.6 my $before = scalar $o->{wiki}->{input}->parameter ('we--content');
477 wakaba 1.7 my $after;
478     try {
479     $after = $o->{wiki}->{db}->get (content => $o->{wiki}->{var}->{page});
480     } catch SuikaWiki::DB::Util::Error with {
481 wakaba 1.9 my $err = shift;
482     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
483 wakaba 1.7 $after = undef;
484     };
485 wakaba 1.6 __FUNCPACK__->diff_in_html (\$before => \$after, $p->{-parent});
486    
487     Function:
488     @Name: diff_in_html
489     @Main:
490     my (undef, $before, $after, $parent, %opt) = @_;
491 wakaba 1.3 require Algorithm::Diff;
492 wakaba 1.6 my $diff = $parent->append_new_node (type => '#element',
493     namespace_uri => $NS_XHTML1,
494     local_name => 'pre');
495 wakaba 1.3 $diff->set_attribute (class => 'diff');
496 wakaba 1.6 for (Algorithm::Diff::diff
497     ([split /\x0D?\x0A/, $$before]=>[split /\x0D?\x0A/, $$after])) {
498 wakaba 1.1 for (@{$_}) {
499     my ($sign, $lineno, $text) = @{$_};
500 wakaba 1.3 my $line = $diff->append_new_node (type => '#element',
501 wakaba 1.2 namespace_uri => $NS_XHTML1,
502     local_name => ({qw/+ ins - del/}->{$sign}||'span'));
503    
504     $line->set_attribute (class => 'line');
505     for ($line->append_new_node (type => '#element',
506     namespace_uri => $NS_XHTML1,
507     local_name => 'span')) {
508     $_->set_attribute (class => 'lineno');
509     $_->append_text ($lineno);
510     }
511     $line->append_text (' ');
512     for ($line->append_new_node (type => '#element',
513     namespace_uri => $NS_XHTML1,
514     local_name => 'span')) {
515     $_->set_attribute (class => 'sign');
516     $_->append_text ($sign);
517     }
518     $line->append_text (' ');
519     for ($line->append_new_node (type => '#element',
520     namespace_uri => $NS_XHTML1,
521     local_name => 'span')) {
522     $_->set_attribute (class => 'content');
523     $_->append_text ($text);
524     }
525     $line->append_text ("\n");
526     } # diff lines
527 wakaba 1.1 }
528    
529     FormattingRule:
530     @Name:mode-after-edit-selection
531 wakaba 1.5 @Category[list]:form-input
532 wakaba 1.8 @Parameter:
533     @@Name: description
534     @@Type: text
535     @@Default: (none)
536     @@Description:
537     @@@@: Human readable description about this input
538     @@@lang: en
539 wakaba 1.1 @Formatting:
540 wakaba 1.8 ## TODO: media-type prop support
541 wakaba 1.1 my $magic = '';
542     $magic = $1 if $o->{var}->{content} =~ m/^([^\x0A\x0D]+)/s;
543    
544 wakaba 1.5 my $name = 'we--mode-modified';
545 wakaba 1.1 my $selected_mode = $o->{wiki}->{input}->parameter ($name);
546     unless ($selected_mode) {
547     if ($magic =~ /C(?:on(?:fig|st)|SS)/) {
548     $selected_mode = 'edit';
549     } else {
550     $selected_mode = 'default';
551     }
552     }
553    
554 wakaba 1.3 my $SELECT = $p->{-parent}->append_new_node (type => '#element',
555     namespace_uri => $NS_XHTML1,
556     local_name => 'select');
557 wakaba 1.1 $SELECT->set_attribute (name => $name);
558 wakaba 1.8 __ATTRTEXT:%description__;
559     $SELECT->set_attribute (title => $p->{description})
560     if length $p->{description};
561 wakaba 1.1 for (qw/default read edit/) {
562     for my $OPTION ($SELECT->append_new_node (type => '#element',
563     namespace_uri => $NS_XHTML1,
564     local_name => 'option')) {
565     $OPTION->set_attribute (value => $_);
566 wakaba 1.6 my $label = SuikaWiki::Plugin->module_package ('WikiResource')
567     ->append_node (name => 'Edit:SaveAnd:'.$_.':Label',
568     param => $o,
569     wiki => $o->{wiki});
570     $OPTION->set_attribute (label => $label->inner_text);
571     $OPTION->append_node ($label);
572 wakaba 1.1 $OPTION->set_attribute
573 wakaba 1.6 (title => SuikaWiki::Plugin->module_package ('WikiResource')
574     ->append_node (name => 'Edit:SaveAnd:'.$_.':Description',
575     param => $o,
576     wiki => $o->{wiki})->inner_text);
577 wakaba 1.1 $OPTION->set_attribute (selected => 'selected')
578     if $selected_mode eq $_;
579     }
580     }
581    
582 wakaba 1.5 FormattingRule:
583     @Category[list]:form-input
584     @Name:we--update-lastmodified-datetime
585     @Description:
586     @@@:
587     This direction force to update last-modified date-time
588     of the WikiPage modified.
589     \
590     Allowing user to select whether last-modified date-time should be
591     updated, use another formatting rule provided by WikiFormSelection
592 wakaba 1.10 module, like:
593     \
594     \ %check (id => we--touch,
595     \ label => {%res (name => {Edit:UpdateTimeStamp});}p,
596     \ description => {%res
597     \ (name => {Edit:UpdateTimeStamp:Description});}p,
598     \ default);
599 wakaba 1.5 \
600     WikiForm other that editing form might not be affected by this
601     parameter. See also "we--touch" parameter.
602     @@lang:en
603     @Formatting:
604     for ($p->{-parent}->append_new_node
605     (type => '#element',
606     namespace_uri => $NS_XHTML1,
607     local_name => 'input')) {
608     $_->set_attribute (type => 'hidden');
609     $_->set_attribute (name => 'we--touch');
610     $_->set_attribute (value => 'on');
611     $_->option (use_EmptyElemTag => 1);
612     }
613    
614    
615 wakaba 1.1 Resource:
616 wakaba 1.2 @Edit:Conflict:Title:
617     @@@:Confliction detected!
618     @@lang:en
619     @Edit:Conflict:WebPageTitle:
620     @@@:%page-name; (Edit : 409 CONFLICTION)
621     @@lang:en
622     @Edit:Deleted:Description:
623     @@@:Content of WikiPage %page-name; has been removed.
624     @@lang:en
625     @Edit:Deleted:Title:
626     @@@:WikiPage Deleted
627     @@lang:en
628     @Edit:Deleted:WebPageTitle:
629     @@@:%page-name; (Deleted)
630     @@lang:en
631 wakaba 1.1 @Edit:Form:Lines:15
632     @Edit:Form:Size:18
633     @Edit:Save:
634     @@@:Save
635     @@lang:en
636 wakaba 1.8 @Edit:SaveAnd:Description:
637     @@@: Select what to do after saving content
638     @@lang: en
639 wakaba 1.1 @Edit:SaveAnd:default:Description:
640     @@@: Save modified content and show content with your default view mode
641     @@lang:en
642     @Edit:SaveAnd:default:Label:
643     @@@: Default view
644     @@lang:en
645     @Edit:SaveAnd:edit:Description:
646     @@@: Save modified content and show content in the edit mode again
647     @@lang:en
648     @Edit:SaveAnd:edit:Label:
649     @@@: Edit again
650     @@lang:en
651     @Edit:SaveAnd:read:Description:
652     @@@: Save modified content and show content in the read mode
653     @@lang:en
654     @Edit:SaveAnd:read:Label:
655     @@@: Show content
656     @@lang:en
657     @EditThisPage:
658     @@@: Edit
659     @@lang:en
660     @EditThisPageLong:
661     @@@: Edit this WikiPage
662     @@lang:en
663     @Edit:WebPageTitle:
664     @@@: %page-name; (Modification)
665     @@lang:en
666     @Edit:Title:
667     @@@: Modification of the WikiPage
668     @@lang:en
669     @Link:AdminEdit:Description:
670     @@@: Edit this WikiPage (administrator's mode)
671     @@lang:en
672     @Link:Edit:Description:
673     @@@: Edit this WikiPage
674     @@lang:en
675 wakaba 1.8 @Mode:adminedit:
676     @@@: Editing (for administrator)
677     @@lang: en
678     @Mode:edit:
679     @@@: Editing
680     @@lang: en
681 wakaba 1.1
682     Function:
683 wakaba 1.2 @Name:digest
684     @Description:
685     @@@: Compute digest of given string
686     @@lang:en
687     @Main:
688 wakaba 1.5 my (undef, $s, %opt) = @_;
689 wakaba 1.2 require Digest::SHA1;
690     if ($opt{normalize}) {
691     $s =~ s/\x0D\x0A/\x0A/g;
692     $s =~ tr/\x0D/\x0A/;
693     }
694     Digest::SHA1::sha1_base64 ($s);
695    
696     Function:
697 wakaba 1.1 @Name:get_content
698     @Description:
699 wakaba 1.12 @@@:
700     Get WikiPage content to be modified. For new (currently not exist)
701 wakaba 1.1 WikiPage, new page template content is returned.
702     @@lang:en
703     @Main:
704 wakaba 1.5 my (undef, $o, $page) = @_;
705 wakaba 1.1 my $content;
706 wakaba 1.12 my $content_prop;
707 wakaba 1.7 try {
708     $content = $o->{wiki}->{db}->get (content => $page);
709 wakaba 1.12 $content_prop = $o->{wiki}->{db}->get (content_prop => $page);
710 wakaba 1.7
711     unless (length $content) {
712     ## TODO: use namespaced template page
713     $content = $o->{wiki}->{db}->get
714     (content => $o->{wiki}->{config}->{page}->{NewPageTemplate});
715 wakaba 1.12 $content_prop = $o->{wiki}->{db}->get
716     (content_prop => $o->{wiki}->{config}->{page}->{NewPageTemplate})
717     ->clone;
718 wakaba 1.7 $o->{var}->{is_new_page_template} = 1;
719     }
720     } catch SuikaWiki::DB::Util::Error with {
721 wakaba 1.9 my $err = shift;
722     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
723 wakaba 1.7 $o->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
724     throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
725     };
726 wakaba 1.12
727     unless ($content_prop->get_attribute_value (<Q:media-type:media-type>, default => undef)) {
728     if ($content =~ m[^(?:\#\?|/\*\s*)([\w.+-]+(?:/[\w.+-]+)?)]) {
729     $content_prop->set_attribute (<Q:media-type:media-type> => 'MAGIC:'.$1.'##');
730     } else {
731     $content_prop->set_attribute (<Q:media-type:media-type> => 'IMT:text/x-suikawiki;version="0.9"##');
732     }
733     }
734    
735     {content => $content, content_prop => $content_prop};
736 wakaba 1.1
737     Parameter:
738 wakaba 1.2 @Name: we--content
739     @Type: text
740     @Default: ""
741     @Description:
742     @@@:
743     Content of WikiPage (to be)
744     @@lang:en
745    
746     Parameter:
747 wakaba 1.1 @Name: we--digest
748     @Type: "Base64ed SHA1"
749     @Default: {undef}
750     @Description:
751     @@@:
752     SHA1 digest value of the WikiPage content before the modification.
753     This value is used to detect confliction of modifying.
754     Empty value (undef or length-zero-string) means that
755     there were no WikiPage content.
756 wakaba 1.2 @@lang:en
757    
758     Parameter:
759     @Name: we--mode-modified
760     @Type: mode-name
761     @Default: "default"
762     @Description:
763     @@@:
764     WikiEngine running mode to be specified after modification is completed
765 wakaba 1.1 @@lang:en
766    
767     Parameter:
768     @Name: we--touch
769 wakaba 1.5 @Type:
770     form:checkbox-value
771 wakaba 1.1 @Default: "off"
772     @Description:
773     @@@:
774     Whether last-modified date-time of the WikiPage should be updated or not
775     when the WikiPage is modified.
776     @@lang:en

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24