/[pub]/suikawiki/script/lib/suikawiki.pl
Suika

Contents of /suikawiki/script/lib/suikawiki.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Sun Jul 27 05:57:28 2003 UTC (21 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +16 -9 lines
File MIME type: text/plain
Use compatible anchor mode for NN 3-4

1 # -*- perl -*-
2 use strict;
3
4 package main;
5 our $VERSION = '2.'.do{my @r=(q$Revision: 1.9 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
6 binmode STDOUT; binmode STDIN;
7 use Fcntl;
8 require SuikaWiki::Plugin;
9 our %embed_command = (
10 form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
11 );
12 our ($modifier_dbtype,%uri,%PathTo,%PageName,$kanjicode);
13
14 our %form;
15 our %database;
16 our $database = bless {}, 'wiki::dummy';
17 my %command_do = (
18 default => \&do_view,
19 adminchangepassword => \&do_adminchangepassword,
20 write => \&do_write,
21 comment => \&do_comment,
22 RandomJump => sub {
23 my @list = keys %main::database;
24 &main::_http_see_other (page => $list[rand @list]);
25 },
26 wikiform => \&do_wikiform,
27 );
28 our $UA = ''; ## User agent name
29 $| = 1;
30 require SuikaWiki::Name::Space;
31 my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
32
33 sub _wiki_exit () {
34 &close_db;
35 exit;
36 }
37
38 sub do_view {
39 require SuikaWiki::View;
40 my $content = $main::database{$main::form{mypage}};
41 my $lm = SuikaWiki::Plugin->_database->mtime ($main::form{mypage});
42 ## Determine mode
43 my $view = $form{mycmd};
44 if (!$view || $view eq 'default' || $view =~ /[^0-9A-Za-z_]/) {
45 ## BUG: this code is not strict
46 if ($main::ENV{HTTP_COOKIE} =~ /SelectedMode=([0-9A-Za-z_-]+)/) {
47 $view = $1; $view =~ tr/-/_/;
48 } else {
49 $view = 'read';
50 }
51 }
52 ## Get content and its meta info
53 my ($magic, $content) = SuikaWiki::Plugin->magic_and_content ($content);
54 $magic ||= '#?SuikaWiki/0.9';
55 my $o = bless {param => \%main::form, page => $main::form{mypage}, toc => [],
56 magic => $magic, content => $content,
57 &main::_compatible_options ()}, 'SuikaWiki::Plugin';
58 my $view_def = SuikaWiki::View->definition ($view);
59 if (!$view_def->check ($o)) {
60 print "Status: 406 Unsupported Media Type\n";
61 $view = '-UnsupportedMediaType';
62 $view_def = SuikaWiki::View->definition ($view);
63 }
64 my $prop = $view_def->properties;
65 my $media = $prop->{media};
66 if ($prop->{xmedia} && $main::UA =~ /Gecko/) { ## TODO: conneg
67 $media = $prop->{xmedia};
68 $o->{media} = $media;
69 } elsif ($main::UA =~ m#Mozilla/0\..+Windows#) {
70 $main::kanjicode = 'shift_jis';
71 }
72
73 if ($prop->{preprocess}) {
74 _wiki_exit () unless &{$prop->{preprocess}} (o => $o);
75 }
76
77 ## Output CGI/HTTP headers
78 if ($magic =~ m!^\#\?SuikaWiki/0.9!) {
79 &main::print_header ($main::form{mypage},
80 -last_modified => ($magic =~ /interactive="yes"/ ? time : $lm),
81 -expires => ($magic =~ /interactive="yes"/ ? 1 : undef), o => $o,
82 -media => $media, -view => $view_def, -magic => $magic, content => $content);
83 } else {
84 &main::print_header($main::form{mypage}, -media => $media, -view => $view_def,
85 -magic => $magic, -last_modified => $lm, o => $o);
86 }
87 ## Output HTTP message body
88 my $fmt = SuikaWiki::Plugin->formatter ('view');
89 my $s = $fmt->replace ($view_def->as_string => $o, {formatter => $fmt});
90 if ($main::kanjicode eq 'euc') {
91 #require Compress::Zlib;
92 #print scalar Compress::Zlib::memGzip (''.$s);
93 print $s;
94 } else {
95 $s .= '';
96 print &main::code_convert (\$s => $main::kanjicode);
97 }
98 }
99
100 sub _do_view_msg (%) {
101 require SuikaWiki::View;
102 my %option = @_;
103 my $o = $option{-o} || bless {param => \%form, page => $option{-page},
104 &_compatible_options ()}, 'SuikaWiki::Plugin';
105 $o->{toc} = [];
106 $o->{condition} = \%option; ## This parameter really used??
107 my $view_def = SuikaWiki::View->definition ($option{-view});
108 unless ($view_def->check ($o)) {
109 print "Status: 406 Unsupported Media Type\n";
110 $option{-view} = '-UnsupportedMediaType';
111 $view_def = SuikaWiki::View->definition ($option{-view});
112 }
113 my $prop = $view_def->properties;
114 my $media = $prop->{media};
115 if ($prop->{xmedia} && $UA =~ /Gecko/) {
116 $media = $prop->{xmedia};
117 $o->{media} = $media;
118 }
119 &print_header($option{-page}, -media => $media, -view => $view_def, o => $o, -goto => $option{-goto});
120 ## Output HTTP message body
121 my $fmt = SuikaWiki::Plugin->formatter ('view');
122 my $s = $fmt->replace ($view_def->as_string => $o, {formatter => $fmt});
123 if ($main::kanjicode eq 'euc') {
124 print $s;
125 } else {
126 print &main::code_convert (\$s => $main::kanjicode);
127 }
128 }
129
130 # [move to SuikaWiki::Plugin::WikiAdmin]
131 sub do_adminchangepassword {
132 if ($form{mynewpassword} ne $form{mynewpassword2}) {
133 &_do_view_msg (-view => '-error', -page => $form{mypage},
134 error_message => &Resource ('Error:PasswordMismatch'));
135 return;
136 }
137 my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
138 if ($validpassword_crypt) {
139 if (not &valid_password($form{myoldpassword})) {
140 &_do_view_msg (-view => '-error', -page => $form{mypage},
141 error_message => &Resource ('Error:PasswordIsIncorrect'));
142 return;
143 }
144 }
145 my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
146 my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
147 my $salt1 = $token[(time | $$) % scalar(@token)];
148 my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
149 my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
150 $database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted);
151
152 &_do_view_msg (-view => '-wrote', -page => $form{mypage});
153 }
154
155 # [move to SuikaWiki::WikiDB]
156 sub valid_password ($) {
157 my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
158 return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
159 }
160
161 # [move to SuikaWiki::Plugin::WikiEdit]
162 sub do_write {
163 if (&frozen_reject()) {
164 return;
165 }
166
167 if (not &is_editable($form{mypage})) {
168 &_do_view_msg (-view => '-error', -page => $form{mypage},
169 error_message => &Resource ('Error:ThisPageIsUneditable'));
170 return;
171 }
172
173 ## Check confliction
174 if ($form{myLastModified} ne $database->mtime ($form{mypage})) {
175 &_do_view_msg (-view => '-conflict', -page => $form{mypage});
176 return;
177 }
178
179 if ($form{mymsg}) {
180 if ($form{mytouch} || !ref $database) {
181 $database{$form{mypage}} = $form{mymsg};
182 } else {
183 $database->STORE ($form{mypage} => $form{mymsg}, -touch => 0);
184 }
185 $database->meta (IsFrozen => $form{mypage} => 0 + $form{myfrozen});
186 my $uri = SuikaWiki::Plugin->_uri_wiki_page ($form{mypage}, mode => ($form{after_edit_cmd}||'default'), with_lm => 1, absolute => 1);
187 $uri .= qq(;after_edit_cmd=@{[SuikaWiki::Plugin->encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
188 if ($form{__comment_anchor_index}) {
189 $uri .= qq(#anchor-$form{__comment_anchor_index});
190 } elsif ($form{__wikiform_anchor_index}) {
191 $uri .= qq(#wikiform-$form{__wikiform_anchor_index});
192 }
193 &_http_see_other (uri => $uri, page => $form{mypage}, alternate_view => '-wrote');
194 } else {
195 delete $database{$form{mypage}};
196 &_do_view_msg (-view => '-deleted', -page => $form{mypage});
197 }
198 }
199
200 sub _http_see_other (%) {
201 my %o = @_;
202 $o{uri} ||= SuikaWiki::Plugin->_uri_wiki_page ($o{page}, absolute => 1);
203 if ($o{alternate_view} && ($main::ENV{SERVER_PROTOCOL} eq 'HTTP/0.9'
204 || $main::ENV{SERVER_PROTOCOL} eq 'HTTP/1.0')
205 && !($main::UA =~ m#Microsoft Internet Explorer|Mozilla#)) {
206 &_do_view_msg (-view => $o{alternate_view}, -page => $o{page}, -goto => $o{uri}, -o => $o{o});
207 } else {
208 my $status = q(303 See Other);
209 if ($main::UA =~ m!Mozilla/[0-4]\.|Microsoft Internet Explorer!) {
210 $status = q(302 See Other);
211 }
212 my $euri = SuikaWiki::Plugin->escape ($o{uri});
213 print qq(Status: $status
214 Location: $o{uri}
215 Content-Type: text/html
216 Content-Language: en
217
218 <!DOCTYPE p SYSTEM>
219 <p>See &lt;<a href="$euri">$euri</a>&gt;.</p>);
220 }
221 _wiki_exit ();
222 }
223
224 sub _compatible_options () {
225 (use_anchor_name => ($main::UA =~ m#Mozilla/[1-4]\.|Microsoft Internet Explorer# ? 1 : 0));
226 }
227
228
229
230 sub print_header ($;%) {
231 my ($page, %option) = @_;
232 if ($main::ENV{HTTP_IF_MODIFIED_SINCE} && $option{-last_modified}) {
233 ## TODO: use Message::Field::Date
234 if ($option{-view}->properties->{if}->{modified_since}
235 && $main::ENV{HTTP_IF_MODIFIED_SINCE} =~ /([0-9]{1,2})\s*([A-Za-z]{3})\s*([0-9]{2,4})\s*([0-9]{2}):([0-9]{2}):([0-9]{2})\s*[Gg][Mm][Tt]/) {
236 require Time::Local;
237 my ($d, $M, $y, $h, $m, $s) = ($1, $2, $3, $4, $5, $6);
238 $M = {jan=>0,feb=>1,mar=>2,apr=>3,may=>4,jun=>5,jul=>6,aug=>7,sep=>8,oct=>9,nov=>10,dec=>11}->{lc $M};
239 #$y += 1900 if $y < 100; ## BUG: don't conform HTTP spec
240 my $t = Time::Local::timegm_nocheck ($s, $m, $h, $d, $M, $y);
241 if ($option{-last_modified} <= $t) {
242 print "Status: 304 Not Modified\n\n";
243 _wiki_exit ();
244 }
245 }
246 }
247 my $UA = SuikaWiki::Plugin->user_agent_names;
248 $option{o}->{-header}->{class}->{frozen} = 1 if &main::is_frozen ($page);
249 $option{o}->{-header}->{class}->{'wiki-page-obsoleted'} = 1 if $option{-magic} =~ /obsoleted="yes"/;
250 $option{o}->{-header}->{additional_html_element} ||= SuikaWiki::Markup::XML->new (type => '#fragment');
251 print "Vary: Negotiate,User-Agent,Accept-Language,Accept\n";
252 if ($option{-goto}) {
253 if ($UA =~ m#Opera|MSIE 2\.#) {
254 ## WARNING: This code may output unsafe HTML document if $option{-goto} is unclean.
255 $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
256 print qq{Refresh: 0; url=$option{-goto}\n};
257 for ($option{o}->{-header}->{additional_html_element}->append_new_node
258 (namespace_uri => $NS_XHTML1, local_name => 'meta')) {
259 $_->set_attribute ('http-equiv' => 'refresh');
260 $_->set_attribute (content => "0; url=$option{-goto}");
261 $_->option (use_EmptyElemTag => 1);
262 }
263 } else {
264 $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
265 print qq{Refresh: 0; url="$option{-goto}"\n};
266 for ($option{o}->{-header}->{additional_html_element}->append_new_node
267 (namespace_uri => $NS_XHTML1, local_name => 'meta')) {
268 $_->set_attribute ('http-equiv' => 'refresh');
269 $_->set_attribute (content => qq(0; url="$option{-goto}"));
270 $_->option (use_EmptyElemTag => 1);
271 }
272 }
273 }
274 print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n}
275 if $option{-last_modified};
276 if ($option{-expires} != -1) {
277 if (defined $option{-expires}) { ## TODO: Don't use asctime
278 print qq{Expires: @{[scalar gmtime (time + $option{-expires})]}\n};
279 } elsif ($option{-media}->{expires} != -1) {
280 print qq{Expires: @{[scalar gmtime (time + $option{-media}->{expires})]}\n};
281 }
282 }
283 if ($option{-media}->{charset} && $UA =~ m#Mozilla/[12]\.#) {
284 ## UAs don't support official charset names but do non-official names
285 my $ct = qq{$option{-media}->{type}; charset=@{[ &main::get_charset_name ($main::kanjicode, compatible => 1) ]}};
286 print qq{Content-Type: $ct\n};
287 for ($option{o}->{-header}->{additional_html_element}->append_new_node
288 (namespace_uri => $NS_XHTML1, local_name => 'meta')) {
289 $_->set_attribute ('http-equiv' => 'content-type');
290 $_->set_attribute (content => $ct);
291 }
292 } elsif (!$option{-media}->{charset} || $UA =~ m#Infomosaic|Mozilla/0\.#) {
293 ## Media types or UAs don't support charset parameter in HTTP header
294 print qq{Content-Type: $option{-media}->{type}\n};
295 if ($option{-media}->{charset}) {
296 for ($option{o}->{-header}->{additional_html_element}->append_new_node
297 (namespace_uri => $NS_XHTML1, local_name => 'meta')) {
298 $_->set_attribute ('http-equiv' => 'content-type');
299 $_->set_attribute (content => qq($option{-media}->{type}; charset=).main::get_charset_name ($main::kanjicode, compatible => 1));
300 }
301 }
302 } else {
303 ## Modern UAs and Media types with charset parameter
304 my $type = $option{-media}->{type};
305 $type = 'application/xml' if ($type =~ m!^application/r(?:df|ss)\+xml$!) && ($UA =~ m#Gecko#);
306 print qq{Content-Type: $type; charset=@{[&main::get_charset_name ($main::kanjicode)]}\n};
307 ## meta element is not needed
308 }
309
310 print <<"EOD";
311 Content-Style-Type: text/css
312
313 EOD
314 }
315
316 sub get_charset_name ($;%) {
317 my ($charset, %option) = (lc shift, @_);
318 if ($charset =~ 'euc') {
319 $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
320 } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
321 $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
322 } elsif ($charset =~ 'jis') {
323 $charset = 'iso-2022-jp';
324 }
325 $charset;
326 }
327
328 =pod
329
330 sub _decode_argv () {
331 my $QS = $main::ENV{QUERY_STRING};
332 if ($main::ENV{PATH_INFO}) {
333 die;
334 # new format: not implemented yet
335 } else {
336 my %argv;
337 if ($QS =~ /[&;=]/) { ## ?FOO=foo;BAR=bar;BAZ=baz
338 for (split /[;&]/, $QS) {
339 if (my ($n, $v) = split /=/, $_, 2) {
340 for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'HH', $1/ge};
341 $argv{$n} = $v;
342 }
343 }
344 } else { ## ?FOO-BAR
345 $argv{page} = $QS;
346 $argv{page} =~ tr/+/ /;
347 $argv{page} =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'HH', $1/ge;
348 }
349 my $ie = $argv{ie}; ## Input coding system
350 for ([qw/mypage page/], [qw/mycmd mode/]) {
351 $argv{$_->[1]} ||= $argv{$_->[0]};
352 delete $argv{$_->[0]};
353 }
354 for (keys %argv) {
355 $argv{$_} = main::code_convert ($argv{$_}, $main::kanjicode, $ie);
356 }
357 for ([qw/mypage page/], [qw/mycmd mode/]) {
358 $argv{$_->[0]} = $argv{$_->[1]};
359 }
360 }
361 }
362
363 =cut
364
365 sub init_form {
366 ## TODO: Support multipart/form-data
367 my $query = '';
368 if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
369 if (lc ($main::ENV{CONTENT_TYPE}) eq 'application/x-www-form-urlencoded'
370 || lc ($main::ENV{CONTENT_TYPE}) eq 'application/sgml-form-urlencoded') {
371 read STDIN, $query, $main::ENV{CONTENT_LENGTH};
372 } else {
373 $main::form{mycmd} = '___unsupported_media_type___';
374 $main::form{mypage} = $main::PageName{FrontPage};
375 return;
376 }
377 }
378 $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
379 if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
380 my $query = SuikaWiki::Plugin->decode ($main::ENV{QUERY_STRING});
381 $query = &main::code_convert (\$query, $main::kanjicode);
382 $main::form{mypage} = $query;
383 $main::form{mycmd} = 'default';
384 } else {
385 for (split /[;&]/, $query) {
386 if (my ($n, $v) = split /=/, $_, 2) {
387 for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
388 $main::form{$n} = $v;
389 }
390 }
391 unless (defined $form{mypage}) {
392 $form{mypage} = $form{epage};
393 $form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g;
394 }
395 $form{mypage} = &main::code_convert (\$form{mypage}, $kanjicode);
396 }
397 $form{mypage} =~ tr/\x00-\x20\x7F//d;
398 $form{mypage} = SuikaWiki::Name::Space::normalize_name ($form{mypage}) || $PageName{FrontPage};
399 $form{mycmd} ||= $form{mode} || 'default';
400 $form{mycmd} =~ tr/-/_/;
401
402 for ('mymsg', 'myname', grep /^(?:wikiform__|pi_)/, keys %form) {
403 $form{$_} = &main::code_convert (\$form{$_}, $kanjicode);
404 }
405 }
406
407 # [move to SuikaWiki::WikiDB]
408 sub open_db {
409 if ($main::modifier_dbtype eq 'dbmopen') {
410 dbmopen(%main::database, $PathTo{WikiDataBase}, 0666) or die "(dbmopen) $main::PathTo{WikiDataBase}";
411 } elsif ($main::modifier_dbtype eq 'AnyDBM_File') {
412 eval q{use AnyDBM_File};
413 tie(%main::database, "AnyDBM_File", $main::PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or die ("(tie AnyDBM_File) $main::PathTo{WikiDataBase}");
414 } elsif ($main::modifier_dbtype eq 'Yuki::YukiWikiDB') {
415 eval q{use Yuki::YukiWikiDB};
416 tie(%main::database, "Yuki::YukiWikiDB", $main::PathTo{WikiDataBase}) or die ("(tie Yuki::YukiWikiDB) $main::PathTo{WikiDataBase}");
417 } else { ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta
418 eval qq{use $modifier_dbtype};
419 $database = tie (%database, $modifier_dbtype => $PathTo{WikiDataBase},
420 -lock => 2, -backup => $wiki::diff::UseDiff, ## TODO: new diff i/f
421 -logfile => $main::PathTo{WikiDatabaseErrorLog})
422 or die ("(tie $modifier_dbtype) $PathTo{WikiDataBase}");
423 }
424 }
425
426 # [move to SuikaWiki::WikiDB]
427 sub close_db {
428 if ($modifier_dbtype eq 'dbmopen') {
429 dbmclose(%database);
430 } else {
431 untie(%database);
432 }
433 }
434
435 # [move to SuikaWiki::Plugin::WikiEdit]
436 sub editform (@) {
437 my %option = @_;
438 my $frozen = &is_frozen ($option{page});
439 $option{content} = $database{$option{page}} unless defined $option{content};
440 $option{content} = $database{NewPageTemplate} unless length $option{content};
441 $option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified};
442 my $magic = '';
443 $magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s;
444
445 my $selected = 'default';
446 if ($form{after_edit_cmd}) {
447 $selected = $form{after_edit_cmd};
448 } elsif ($magic =~ /Const|Config|CSS/) {
449 $selected = 'edit';
450 }
451 my $afteredit = <<EOH;
452 <select name="after_edit_cmd">
453 <option value="default" label="@{[&Resource('Edit:SaveAndDefault',escape=>1)]}"@{[$selected eq 'default' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndDefault',escape=>1)]}</option>
454 <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
455 <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
456 </select>
457 EOH
458
459 =pod
460
461 my $f = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'form');
462 $f->set_attribute (action => SuikaWiki::Plugin->uri ('wiki');
463 $f->set_attribute (method => 'post');
464 if (!$option{conflict}) {
465 for ($f->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'label')) {
466 for ($_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'input')) {
467 $f->set_attribute (type => 'submit');
468 $f->set_attribute (value => SuikaWiki::Plugin->resource ('Edit:Save'));
469 }
470 #<input type=hidden name=mycmd value=write/>
471 $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'kbd', value => 'S');
472 }
473 }
474
475 =cut
476
477 my $f = <<"EOD";
478 <form action="$uri{wiki}" method="post">
479 @{[ $option{conflict} ? '' : qq(<label><input type="submit" value="@{[SuikaWiki::Plugin->resource('Edit:Save',escape=>1)]}" /><kbd>S</kbd></label>) ]}
480 @{[ $option{admin} ? qq(<label>@{[SuikaWiki::Plugin->resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10" /></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br />
481 <input type="hidden" name="myLastModified" value="$option{last_modified}" />
482 <input type="hidden" name="mycmd" value="write" />
483 <input type="hidden" name="mypage" value="@{[SuikaWiki::Plugin->escape($form{mypage})]}" />
484 <textarea cols="@{[SuikaWiki::Plugin->resource('Edit:Form:Cols')+0||35]}" rows="@{[SuikaWiki::Plugin->resource('Edit:Form:Rows')+0||15]}" name="mymsg" tabindex="1"@{[$main::UA =~ m{Mozilla/[0-4]\.} ? ' wrap="physical"':'']}>@{[SuikaWiki::Plugin->escape($option{content})]}</textarea><br />
485 @{[
486 $option{admin} ?
487 qq(
488 <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]} />@{[SuikaWiki::Plugin->resource('Edit:Freeze',escape=>1)]}</label>
489 <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]} />@{[SuikaWiki::Plugin->resource('Edit:DontFreeze',escape=>1)]}</label><br />)
490 : ""
491 ]}
492 @{[
493 $option{conflict} ? "" :
494 qq(
495 <label><input type="checkbox" name="mytouch" value="on" checked="checked" />@{[SuikaWiki::Plugin->resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br />
496 <label><input type="submit" value="@{[SuikaWiki::Plugin->resource('Edit:Save',escape=>1)]}" accesskey="S" /><kbd>S</kbd></label>
497 $afteredit
498 )
499 ]}
500 </form>
501 EOD
502 $f;
503 }
504
505 # [move to SuikaWiki::WikiDB]
506 sub is_editable {
507 my ($page) = @_;
508 return 0 unless SuikaWiki::Name::Space::validate_name ($page);
509 return 0 if $page =~ /[\x00-\x20\[\]\x7F]/;
510 1;
511 }
512
513 # [move to SuikaWiki::WikiDB]
514 sub frozen_reject {
515 my ($isfrozen) = $database->meta (IsFrozen => $form{mypage});
516 my ($willbefrozen) = $form{myfrozen};
517 if (not $isfrozen and not $willbefrozen) {
518 # You need no check.
519 return 0;
520 } elsif (valid_password($form{mypassword})) {
521 # You are admin.
522 return 0;
523 } else {
524 &_do_view_msg (-view => '-error', -page => $form{mypage},
525 error_message => SuikaWiki::Plugin->resource ('Error:PasswordIsIncorrect'));
526 exit;
527 }
528 }
529
530 # [move to SuikaWiki::WikiDB]
531 sub is_frozen ($) { SuikaWiki::Plugin->_database->meta (IsFrozen => $_[0]) ? 1 : 0 }
532
533 # [to be obsolete]
534 sub do_comment {
535 my ($content) = $database{$form{mypage}};
536 my $default_name; ## this code is not strict.
537 $default_name = $1 if $content =~ /default-name="([^"]+)"/;
538 my @time = gmtime (time);
539 my $datestr = sprintf '[WEAK[%04d-%02d-%02d %02d:%02d:%02d +00:00]]', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
540 my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
541 ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
542 if ($namestr =~ /^(?:>>)?[0-9]/) {
543 $namestr = qq( ''$namestr'': );
544 } elsif (length $namestr) {
545 $namestr = qq( ''[[$namestr]]'': );
546 }
547 my $anchor = &get_new_anchor_index ($content);
548 my $i = 1; my $o = 0;
549 $content =~ s{(\[\[\#r?comment\]\])}{
550 my $embed = $1;
551 if ($i == $form{comment_index}) {
552 if ($embed ne '[[#rcomment]]') {
553 $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1;
554 } else {
555 $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1;
556 }
557 }
558 $i++; $embed;
559 }ge;
560 unless ($o) {
561 $content = "#?SuikaWiki/0.9\n\n" unless $content;
562 $content .= "\n" unless $content =~ /\n$/s;
563 $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
564 }
565 $form{__comment_anchor_index} = $anchor;
566 if ($form{mymsg} || $form{myname}) {
567 $form{mymsg} = $content;
568 $form{mytouch} = 'on';
569 &do_write;
570 } else { ## Don't write
571 $form{mycmd} = 'default';
572 &do_view;
573 }
574 }
575
576 # [move to SuikaWiki::Plugin::WikiForm]
577 sub get_new_anchor_index ($) {
578 my $content = shift;
579 my $anchor = 0;
580 $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
581 $anchor + 1;
582 }
583
584 # [move to SuikaWiki::Plugin::WikiForm]
585 sub do_wikiform {
586 my $content = $database{$form{mypage}};
587 my $anchor = &get_new_anchor_index ($content);
588 my $write = 0;
589 my $i = 1;
590 $content =~ s{$embed_command{form}}{
591 my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
592 if (($wfname && $wfname eq $form{wikiform_targetform})
593 || $i == $form{wikiform_index}) {
594 $template =~ s/\\([\\'])/$1/g;
595 $option =~ s/\\([\\'])/$1/g;
596 my $param = bless {depth=>10}, 'SuikaWiki::Plugin';
597 $param->{page} = $form{mypage};
598 $param->{form_index} = $i;
599 $param->{form_name} = $wfname;
600 $param->{anchor_index} = $anchor;
601 $param->{argv} = \%form;
602 $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
603 $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
604 SuikaWiki::Plugin->formatter ('form_option')->replace ($option, $param);
605 my $t = 1;
606 for (keys %{$param->{require}||{}}) {
607 (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
608 }
609 $t = SuikaWiki::Plugin->formatter ('form_template')->replace ($template, $param) if $t;
610 if (length $t) {
611 if ($param->{output}->{reverse}) {
612 $embed .= "\n" . $t;
613 } else {
614 $embed = $t . "\n" . $embed;
615 }
616 $write = 1;
617 $form{__comment_anchor_index} = $anchor
618 if $param->{anchor_index_}; ## $anchor is used!
619 }
620 $form{__wikiform_anchor_index} = $i;
621 undef $form{wikiform_targetform}; ## Make sure never to match
622 undef $form{wikiform_index}; ## with WikiForm in rest of page!
623 }
624 $i++; $embed;
625 }ge;
626 unless ($write) {
627 #$content = "#?SuikaWiki/0.9\n\n" unless $content;
628 #$content .= "\n" unless $content =~ /\n$/s;
629 #
630 }
631 if ($write) {
632 $form{mymsg} = $content;
633 $form{mytouch} = 'on';
634 &do_write;
635 } else { ## Don't write!
636 $form{mycmd} = 'default';
637 &do_view;
638 }
639 }
640
641 # [to be obsolete] ->Message::MIME::Charset
642 sub code_convert {
643 require Jcode;
644 my ($contentref, $code, $srccode) = (shift, shift || $kanjicode, shift || undef);
645 if ($code =~ /euc/) { $code = 'euc' }
646 elsif ($code =~ /iso/) { $code = 'jis' }
647 elsif ($code =~ /shi/) { $code = 'sjis' }
648 elsif ($code =~ /utf/) { $code = 'utf8' }
649 $$contentref = Jcode->new ($contentref, $srccode)->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code;
650 return $$contentref;
651 }
652
653 # [to be obsolete] ->Message::Field::Date
654 sub _rfc3339_date ($) {
655 my @time = gmtime (shift);
656 sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
657 }
658
659 # [obsolete] ->SuikaWiki::SrcFormat
660 sub convert_format ($$$;%) {
661 my ($content, $d => $t, %option) = @_;
662 my $f = SuikaWiki::Plugin->format_converter ($d => $t);
663 if (ref $f) {
664 $option{content} = $content;
665 $option{from} = $d;
666 $option{to} = $t;
667 &$f ({}, bless (\%option, 'SuikaWiki::Plugin'));
668 } elsif ($option{-error_no_return}) {
669 return undef;
670 } elsif ($t =~ /HTML|xml/) {
671 if (length $content) {
672 my $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'pre');
673 $r->append_text ($content);
674 return $r;
675 } else {
676 return '';
677 }
678 } else {
679 $content;
680 }
681 }
682
683
684
685 # [obsolete] SuikaWiki::WikiDB
686 package wiki::dummy;
687 sub mtime (@) {undef}
688 sub meta (@) {undef}
689 sub Yuki::YukiWikiDB2::meta (@) {undef}
690
691 package main;
692 SuikaWiki::Plugin->import_plugins ();
693 $main::UA = $main::ENV{HTTP_USER_AGENT};
694 &open_db;
695 &init_form;
696 for (@{$SuikaWiki::Plugin::On{WikiDatabaseLoaded}||[]}) { &{$_} }
697 if ($command_do{$form{mycmd}}) {
698 &{$command_do{$form{mycmd}}}; # [to be obsolete]
699 } else {
700 &{$command_do{default}};
701 }
702 _wiki_exit ();
703
704 =head1 NAME
705
706 lib/suikawiki.pl --- SuikaWiki transitional library
707
708 =head1 AUTHOR
709
710 Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/> (YukiWiki)
711
712 Makio Tsukamoto <http://digit.que.ne.jp/> (WalWiki)
713
714 Wakaba <w@suika.fam.cx>
715
716 =head1 LICENSE
717
718 Copyright AUTHORS 2000-2003
719
720 This program is free software; you can redistribute it and/or
721 modify it under the same terms as Perl itself.
722
723 =cut
724
725 1; # $Date: 2003/07/17 23:59:12 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24