/[pub]/suikawiki/script/wiki.cgi
Suika

Contents of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (hide annotations) (download)
Thu Dec 5 04:32:27 2002 UTC (21 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.34: +74 -24 lines
*** empty log message ***

1 wakaba 1.9 #!/usr/bin/perl
2     #
3 wakaba 1.16 # wiki.cgi - This is YukiWiki, yet another Wiki clone.
4 wakaba 1.9 #
5 wakaba 1.16 # Copyright (C) 2000-2002 by Hiroshi Yuki.
6 wakaba 1.9 # <hyuki@hyuki.com>
7     # http://www.hyuki.com/yukiwiki/
8     #
9 wakaba 1.16 # This program is free software; you can redistribute it and/or
10     # modify it under the same terms as Perl itself.
11 wakaba 1.9 #
12 wakaba 1.16 # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
13    
14     # Walrus add (debug) start
15     my $walrus_log;
16     my $walrus_debugging = 0;
17     # Walrus add (debug) end
18    
19     # Libraries.
20     use strict;
21     use lib qw(./WalWiki/lib);
22     use CGI qw(:standard);
23     use CGI::Carp qw(fatalsToBrowser);
24     use Yuki::RSS;
25     use Yuki::DiffText qw(difftext);
26     use Yuki::YukiWikiDB;
27     use AnyDBM_File;
28     require 'jcode.pl';
29 wakaba 1.32 require Jcode;
30 wakaba 1.16 use Fcntl;
31     my $version = '2.0.beta1.2002-05-29';
32 wakaba 1.17 my $walversion;
33 wakaba 1.9 ##############################
34 wakaba 1.16 #
35     # You MUST modify following '$modifier_...' variables.
36     #
37     my $modifier_mail = 'w@suika.fam.cx'; # Your mail address, like 'walrus@digit.que.ne.jp'.
38     my $modifier_url = 'http://suika.fam.cx/~wakaba/'; # Your web page, like 'http://digit.que.ne.jp/work/'.
39     my $modifier_name = '和'; # Your name, like 'Makio Tsukamoto'.
40     # my $modifier_dbtype = 'AnyDBM_File'; # Fast, not available on some server, page size limited.
41     # my $modifier_dbtype = 'dbmopen'; # Fast, not available on some server, page size limited.
42     my $modifier_dbtype = 'YukiWikiDB'; # Slow, available on all environment.
43     # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.
44     my $modifier_sendmail = ''; # If you don't need mail notification.
45 wakaba 1.17 my $modifier_dir_data = './wikidata'; # Your data directory.
46 wakaba 1.27 my $modifier_rss_title = "SuikaWiki $walversion";
47 wakaba 1.16 my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.
48 wakaba 1.27 my $modifier_rss_description = 'This is SuikaWiki';
49 wakaba 1.9 ##############################
50 wakaba 1.16 #
51     # You MAY modify following variables.
52     #
53 wakaba 1.35 $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
54 wakaba 1.16 my $file_touch = "$modifier_dir_data/touched.txt";
55     my $file_resource = "$modifier_dir_data/resource.txt";
56     my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
57     my $file_conflict = "$modifier_dir_data/conflict.txt";
58     my $file_format = "$modifier_dir_data/format.txt";
59 wakaba 1.28 my $url_cgi = '/~wakaba/-temp/wiki/wiki'; ## MUST be started from '/'
60 wakaba 1.25 my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
61 wakaba 1.16 my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';
62     my $maxrecent = 50;
63 wakaba 1.9 my $cols = 80;
64     my $rows = 20;
65     ##############################
66 wakaba 1.16 #
67     # You MAY, but do NOT NEED modify following variables.
68     #
69     my $dataname = "$modifier_dir_data/wiki";
70     my $infoname = "$modifier_dir_data/info";
71     my $diffname = "$modifier_dir_data/diff";
72     my $editchar = '?';
73     my $subject_delimiter = ' - ';
74     my $use_autoimg = 1; # automatically convert image URL into <img> tag.
75     my $use_exists = 0; # If you can use 'exists' method for your DB.
76     ##############################
77     my $InterWikiName = 'InterWikiName';
78     my $RecentChanges = 'RecentChanges';
79     my $AdminChangePassword = 'AdminChangePassword';
80     my $CompletedSuccessfully = 'CompletedSuccessfully';
81 wakaba 1.18 my $FrontPage = 'HomePage';
82 wakaba 1.16 my $IndexPage = 'IndexPage';
83     my $SearchPage = 'SearchPage';
84     my $CreatePage = 'CreatePage';
85     my $ErrorPage = 'ErrorPage';
86     my $RssPage = 'RssPage';
87 wakaba 1.26 my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
88 wakaba 1.16 my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
89     ##############################
90     my $bracket_name = '\[\[(\S+?)\]\]';
91     my $embedded_name = '\[\[(#\S+?)\]\]';
92 wakaba 1.31 my %fmt; ## formatter objects
93 wakaba 1.16 ##############################
94     my $embed_comment = '[[#comment]]';
95     my $embed_rcomment = '[[#rcomment]]';
96 wakaba 1.25 my $embed_comment_Name_Prompt = '名前:';
97     my $DEFAULT_embed_comment_name = '名無しさん';
98 wakaba 1.16 my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5)
99 wakaba 1.22 my %embed_command = (
100     searched => '^\[\[#searched:([^\]]+)\]\]$',
101 wakaba 1.34 form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
102 wakaba 1.22 );
103 wakaba 1.16 ##############################
104     my $info_LastModified = 'LastModified';
105     my $info_IsFrozen = 'IsFrozen';
106     my $info_AdminPassword = 'AdminPassword';
107     ##############################
108     my $kanjicode = 'euc';
109     my $charset = 'EUC-JP';
110     my $lang = 'ja';
111     my %fixedpage = (
112     $IndexPage => 1,
113     $CreatePage => 1,
114     $ErrorPage => 1,
115     $RssPage => 1,
116     $RecentChanges => 1,
117     $SearchPage => 1,
118     $AdminChangePassword => 1,
119     $CompletedSuccessfully => 1,
120 wakaba 1.18 #$FrontPage => 1,
121 wakaba 1.32 WikiUserAgentList => 1,
122 wakaba 1.35 WikiPluginInfo => 1,
123 wakaba 1.16 );
124     my %form;
125     my %database;
126     my %infobase;
127     my %diffbase;
128     my %resource;
129     my %interwiki;
130     ##############################
131     my %page_command = (
132     $IndexPage => 'index',
133     $SearchPage => 'searchform',
134     $CreatePage => 'create',
135     $RssPage => 'rss',
136     $AdminChangePassword => 'adminchangepasswordform',
137 wakaba 1.18 #$FrontPage => 'FrontPage',
138 wakaba 1.35 WikiPluginInfo => 'x_WikiPluginInfo',
139 wakaba 1.16 );
140     my %command_do = (
141     read => \&do_read,
142 wakaba 1.25 TEXT_CSS => \&do_output_css,
143 wakaba 1.16 edit => \&do_edit,
144     adminedit => \&do_adminedit,
145     adminchangepasswordform => \&do_adminchangepasswordform,
146     adminchangepassword => \&do_adminchangepassword,
147     write => \&do_write,
148     index => \&do_index,
149     searchform => \&do_searchform,
150     search => \&do_search,
151     create => \&do_create,
152     createresult => \&do_createresult,
153     FrontPage => \&do_FrontPage,
154     comment => \&do_comment,
155 wakaba 1.28 RandomJump => \&do_random_jump,
156 wakaba 1.16 rss => \&do_rss,
157     diff => \&do_diff,
158     interwikibox => \&do_interwiki_box, # Walrus add (5)
159 wakaba 1.33 wikiform => \&do_wikiform,
160 wakaba 1.35 x_WikiPluginInfo => \&do_wikiplugininfo,
161 wakaba 1.16 );
162     ##############################
163     my $walversion = '2.0.beta1.wal.1'; # Walrus add (1)
164 wakaba 1.9 ##############################
165 wakaba 1.16 # &test_convert;
166 wakaba 1.33 my $UA = ''; ## User agent name
167 wakaba 1.16 ##############################
168 wakaba 1.9
169     sub main {
170 wakaba 1.32 $UA = $main::ENV{HTTP_USER_AGENT};
171 wakaba 1.16 &init_resource;
172     &open_db;
173     &init_form;
174     &init_InterWikiName;
175     if ($command_do{$form{mycmd}}) {
176     &{$command_do{$form{mycmd}}};
177 wakaba 1.9 } else {
178 wakaba 1.16 &do_FrontPage;
179 wakaba 1.9 }
180 wakaba 1.16 &close_db;
181 wakaba 1.9 }
182    
183     sub do_read {
184 wakaba 1.26 my $content = $database{$form{mypage}};
185 wakaba 1.27 my $lm = &get_info($form{mypage}, $info_LastModified);
186     wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
187 wakaba 1.32 wiki::useragent::add ($ENV{HTTP_USER_AGENT});
188 wakaba 1.29 my ($r, $c) = get_search_result ($form{mypage});
189     my $rl = wiki::referer::list_html ($form{mypage});
190     my @toc;
191     push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;
192     push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl;
193 wakaba 1.26 my $cf = 'SuikaWiki/0.9';
194 wakaba 1.27 ## Should be support at least:
195     ## - 'SuikaWiki/0.9' CRLF
196     ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
197     ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
198 wakaba 1.32 $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
199 wakaba 1.28 if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
200 wakaba 1.29 &print_header ($form{mypage}, -last_modified => $lm,
201     -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
202     &print_content ($content, content_format => $cf, last_modified => $lm,
203     -toc => \@toc);
204 wakaba 1.32 print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
205 wakaba 1.26 } else {
206 wakaba 1.29 &print_header($form{mypage}, -last_modified => $lm);
207 wakaba 1.26 print "<pre>@{[&escape($content)]}</pre>";
208     }
209 wakaba 1.22 if ($c) {
210 wakaba 1.32 print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
211 wakaba 1.22 print $r;
212     }
213 wakaba 1.29 if ($rl) {
214 wakaba 1.32 print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);
215 wakaba 1.27 }
216     &print_footer($form{mypage}, $lm);
217 wakaba 1.9 }
218    
219 wakaba 1.25 sub do_output_css {
220     my $content = $database{$form{mypage}};
221     if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
222 wakaba 1.29 my $lm = &get_info($form{mypage}, $info_LastModified);
223 wakaba 1.25 print "Content-Type: text/css; charset=$charset\n";
224 wakaba 1.29 print "Last-Modified: $lm\n";
225 wakaba 1.25 print "\n";
226     print $content;
227     } else {
228     print "Status: 406 Unsupported Media Type\n";
229 wakaba 1.29 &print_header('WikiPageIsNotCSS', -noindex => 1);
230 wakaba 1.25 &print_content($database{WikiPageIsNotCSS});
231     &print_footer('WikiPageIsNotCSS');
232     }
233     }
234    
235 wakaba 1.32 sub id_and_name ($) {
236     my $name = shift;
237 wakaba 1.33 if ($UA =~ m#Mozilla/[12]\.#) {
238 wakaba 1.32 qq{id="$name"><a name="$name"></a};
239     } else {
240     qq{id="$name"};
241     }
242     }
243    
244 wakaba 1.9 sub do_edit {
245 wakaba 1.16 my ($page) = &unarmor_name(&armor_name($form{mypage}));
246 wakaba 1.29 &print_header($page, -noindex => 1);
247 wakaba 1.16 if (not &is_editable($page)) {
248     &print_message($resource{cantchange});
249     } elsif (&is_frozen($page)) {
250     &print_message($resource{cantchange});
251     } else {
252     &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
253 wakaba 1.9 }
254 wakaba 1.30 wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
255 wakaba 1.32 wiki::useragent::add ($ENV{HTTP_USER_AGENT});
256 wakaba 1.30 my ($r, $c) = get_search_result ($form{mypage});
257     my $rl = wiki::referer::list_html ($form{mypage});
258     if ($c) {
259     print q{<h2 id="wikipage-see-also">See also</h2>};
260     print $r;
261     }
262     if ($rl) {
263     print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
264     }
265 wakaba 1.16 &print_footer($page);
266 wakaba 1.9 }
267    
268 wakaba 1.16 sub do_adminedit {
269     my ($page) = &unarmor_name(&armor_name($form{mypage}));
270 wakaba 1.29 &print_header($page, -noindex => 1);
271 wakaba 1.16 if (not &is_editable($page)) {
272     &print_message($resource{cantchange});
273 wakaba 1.9 } else {
274 wakaba 1.16 &print_message($resource{passwordneeded});
275     &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
276 wakaba 1.9 }
277 wakaba 1.16 &print_footer($page);
278 wakaba 1.9 }
279    
280 wakaba 1.16 sub do_adminchangepasswordform {
281 wakaba 1.29 &print_header($AdminChangePassword, -noindex => 1);
282 wakaba 1.16 &print_passwordform;
283     &print_footer($AdminChangePassword);
284     }
285 wakaba 1.9
286 wakaba 1.16 sub do_adminchangepassword {
287     if ($form{mynewpassword} ne $form{mynewpassword2}) {
288     &print_error($resource{passwordmismatcherror});
289     }
290     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
291     if ($validpassword_crypt) {
292     if (not &valid_password($form{myoldpassword})) {
293     &send_mail_to_admin(<<"EOD", "AdminChangePassword");
294     myoldpassword=$form{myoldpassword}
295     mynewpassword=$form{mynewpassword}
296     mynewpassword2=$form{mynewpassword2}
297 wakaba 1.9 EOD
298 wakaba 1.16 &print_error($resource{passworderror});
299 wakaba 1.9 }
300 wakaba 1.16 }
301     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
302     my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
303     my $salt1 = $token[(time | $$) % scalar(@token)];
304     my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
305     my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
306     &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
307    
308 wakaba 1.29 &print_header($CompletedSuccessfully, -noindex => 1);
309 wakaba 1.16 &print_message($resource{passwordchanged});
310     &print_footer($CompletedSuccessfully);
311     }
312    
313     sub do_index {
314     &print_header($IndexPage);
315     print qq(<ul>);
316     foreach my $page (sort keys %database) {
317     if (&is_editable($page)) {
318 wakaba 1.24 print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
319 wakaba 1.16 # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
320     # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
321 wakaba 1.9 }
322     }
323 wakaba 1.16 print qq(</ul>);
324     &print_footer($IndexPage);
325 wakaba 1.9 }
326    
327 wakaba 1.16 sub do_write {
328     if (&frozen_reject()) {
329     return;
330 wakaba 1.9 }
331    
332     if (not &is_editable($form{mypage})) {
333 wakaba 1.29 &print_header($form{mypage}, -noindex => 1);
334 wakaba 1.16 &print_message($resource{cantchange});
335     &print_footer($form{mypage});
336 wakaba 1.9 return;
337     }
338    
339 wakaba 1.16 if (&conflict($form{mypage}, $form{mymsg})) {
340 wakaba 1.9 return;
341     }
342    
343 wakaba 1.16 # Making diff
344 wakaba 1.9 {
345 wakaba 1.16 &open_diff;
346     my @msg1 = split(/\n/, $database{$form{mypage}});
347 wakaba 1.9 my @msg2 = split(/\n/, $form{mymsg});
348 wakaba 1.16 $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);
349     &close_diff;
350 wakaba 1.9 }
351    
352     if ($form{mymsg}) {
353 wakaba 1.16 $database{$form{mypage}} = $form{mymsg};
354     &send_mail_to_admin($form{mypage}, "Modify");
355     if ($form{mytouch}) {
356     &set_info($form{mypage}, $info_LastModified, '' . localtime);
357     &update_recent_changes;
358     }
359     &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
360 wakaba 1.33 my $fragment;
361     if ($form{__comment_anchor_index}) {
362     $fragment = qq(anchor-$form{__comment_anchor_index});
363     } elsif ($form{__wikiform_anchor_index}) {
364     $fragment = qq(wikiform-$form{__wikiform_anchor_index});
365     }
366     &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($fragment?'#'.$fragment:''));
367 wakaba 1.16 &print_message($resource{saved});
368     &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
369     &print_footer($CompletedSuccessfully);
370     } else {
371     &send_mail_to_admin($form{mypage}, "Delete");
372     delete $database{$form{mypage}};
373     delete $infobase{$form{mypage}};
374     if ($form{mytouch}) {
375     &update_recent_changes;
376     }
377 wakaba 1.29 &print_header($form{mypage}, -noindex => 1);
378 wakaba 1.16 &print_message($resource{deleted});
379     &print_footer($form{mypage});
380 wakaba 1.9 }
381     }
382    
383 wakaba 1.16 sub do_searchform {
384     &print_header($SearchPage);
385     &print_searchform("");
386     &print_footer($SearchPage);
387 wakaba 1.9 }
388    
389 wakaba 1.16 sub do_search {
390 wakaba 1.22 my $word = $form{mymsg};
391 wakaba 1.16 &print_header($SearchPage);
392 wakaba 1.22 &print_searchform(&escape($word));
393 wakaba 1.30 print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);
394 wakaba 1.16 &print_footer($SearchPage);
395 wakaba 1.9 }
396    
397 wakaba 1.22 sub get_search_result ($;%) {
398 wakaba 1.32 my $word = lc shift;
399 wakaba 1.22 my %option = @_;
400 wakaba 1.30 my @r;
401     foreach my $page (keys %database) {
402     next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
403 wakaba 1.28 my $content = $database{$page};
404 wakaba 1.30 my $cf = 'SuikaWiki/0.9';
405     $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
406     next if $cf =~ /obsoleted="yes"/;
407 wakaba 1.32 if (index (lc $page, $word) > -1) {
408     my $c = $content =~ s/\Q$word\E//gi;
409 wakaba 1.30 push @r, [$page, $c+20];
410 wakaba 1.32 } elsif (index ($word, lc $page) > -1) {
411     my $c = $content =~ s/\Q$word\E//gi;
412 wakaba 1.30 push @r, [$page, $c+10];
413 wakaba 1.32 } elsif (my $c = $content =~ s/\Q$word\E//gi) {
414 wakaba 1.30 push @r, [$page, $c];
415 wakaba 1.22 }
416     }
417 wakaba 1.32 my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
418 wakaba 1.30 my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
419     $r = qq|<ul class="search-result">$r</ul>| if $r;
420     get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
421     wantarray? ($r, scalar @r): $r;
422 wakaba 1.22 }
423    
424 wakaba 1.16 sub do_create {
425     &print_header($CreatePage);
426     print <<"EOD";
427     <form action="$url_cgi" method="post">
428     <input type="hidden" name="mycmd" value="edit">
429     <strong>$resource{newpagename}</strong><br>
430     <input type="text" name="mypage" value="" size="20">
431     <input type="submit" value="$resource{createbutton}"><br>
432     </form>
433     EOD
434     &print_footer($CreatePage);
435 wakaba 1.9 }
436    
437 wakaba 1.28 sub do_random_jump {
438     my @list = keys %database;
439     my $name = &encode ($list[rand @list]);
440 wakaba 1.29 my ($scheme) = 'http';
441     $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
442     print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
443 wakaba 1.28 print "\n";
444     }
445    
446 wakaba 1.16 sub do_FrontPage {
447     open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
448     my $content = join('', <FILE>);
449     &code_convert(\$content, $kanjicode);
450     close(FILE);
451     &print_header($FrontPage);
452     &print_content($content);
453     &print_footer($FrontPage);
454 wakaba 1.9 }
455    
456     sub print_error {
457     my ($msg) = @_;
458 wakaba 1.29 &print_header($ErrorPage, -noindex => 1);
459 wakaba 1.16 print qq(<p><strong class="error">$msg</strong></p>);
460     &print_footer($ErrorPage);
461 wakaba 1.9 exit(0);
462     }
463    
464 wakaba 1.27 sub print_header ($;%) {
465     my ($page, %option) = @_;
466 wakaba 1.16 my $bodyclass = "normal";
467     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
468     $bodyclass = "frozen";
469 wakaba 1.22 }
470 wakaba 1.29 $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
471 wakaba 1.32 if ($option{-goto}) {
472 wakaba 1.33 if ($UA =~ m#Mozilla/[12]\.|Opera#) {
473 wakaba 1.32 $option{-goto} =~ tr/;/&/;
474 wakaba 1.33 print qq{Refresh: 0; url=$option{-goto}\n};
475     $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
476 wakaba 1.32 } else {
477 wakaba 1.33 print qq{Refresh: 0; url="$option{-goto}"\n};
478     $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
479 wakaba 1.32 }
480     }
481 wakaba 1.27 print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
482 wakaba 1.32 my $meta_ct = '';
483     if ($UA =~ m#Mozilla/2#) {
484     $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
485     print qq{Content-Type: $meta_ct\n};
486     $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
487     } else {
488     print qq{Content-Type: text/html; charset=$charset\n};
489     }
490 wakaba 1.16 my $cookedpage = &encode($page);
491 wakaba 1.24 my $escapedpage = &escape($page);
492 wakaba 1.9 print <<"EOD";
493 wakaba 1.18 Content-Language: $lang
494     Content-Style-Type: text/css
495 wakaba 1.9
496 wakaba 1.28 <!--
497 wakaba 1.16 <!DOCTYPE html
498     PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
499 wakaba 1.28 "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
500 wakaba 1.16 <html lang="$lang">
501     <head>
502 wakaba 1.33 $meta_ct$option{-goto}
503 wakaba 1.29 <title>$escapedpage</title>
504 wakaba 1.16 <link rel="index" href="$url_cgi?$IndexPage">
505 wakaba 1.30 <link rel="help" href="$url_cgi?WikiHelp">
506 wakaba 1.26 <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
507 wakaba 1.24 <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
508 wakaba 1.29 @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
509 wakaba 1.9 </head>
510 wakaba 1.16 <body class="$bodyclass">
511 wakaba 1.22 EOD
512     &print_navigate_links ($page);
513     print <<EOD;
514 wakaba 1.29 <h1 class="header">@{[&escape($page)]}</h1>
515 wakaba 1.22 EOD
516     }
517    
518 wakaba 1.32 sub x_charset ($) {
519     my $charset = lc shift;
520     if ($charset eq 'euc-jp') {
521     $charset = 'x-euc-jp';
522     } elsif ($charset eq 'shift_jis') {
523     $charset = 'x-sjis';
524     }
525     $charset;
526     }
527    
528 wakaba 1.22 sub print_navigate_links (@) {
529     my ($page) = @_;
530     my $editable = 0;
531     my $admineditable = 0;
532     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
533     $editable = 0;
534 wakaba 1.29 #$admineditable = 1;
535 wakaba 1.22 } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
536 wakaba 1.29 #$admineditable = 1;
537 wakaba 1.22 $editable = 1;
538     } else {
539     $editable = 0;
540     }
541     my $cookedpage = &encode($page);
542     print <<EOH;
543 wakaba 1.16 <div class="tools">
544     @{[ $admineditable
545     ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )
546     : qq()
547     ]}
548     @{[ $editable
549 wakaba 1.29 ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )
550     qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )
551 wakaba 1.16 : qq()
552     ]}
553 wakaba 1.32 <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">表示</a> |
554 wakaba 1.16 @{[ $admineditable
555     ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
556     : qq()
557     ]}
558 wakaba 1.29 <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |
559     <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
560     <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |
561     <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
562     <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |
563     <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
564     </div>
565     EOH
566     <<EOH; ## temp
567     <a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> |
568     <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
569     <!-- <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | -->
570     <a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> |
571     <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
572     <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |
573     <a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a>
574 wakaba 1.16 </div>
575 wakaba 1.22 EOH
576 wakaba 1.9 }
577    
578 wakaba 1.16 sub print_footer {
579 wakaba 1.27 my ($page, $lm) = @_;
580 wakaba 1.33 my $epage = &encode ($page);
581 wakaba 1.16 $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug)
582     # Walrus mod (1) start
583 wakaba 1.35 my $cvslog1 = q$Revision: 1.34 $;
584     my $cvslog2 = q$Date: 2002/12/04 12:00:42 $;
585 wakaba 1.22 print_navigate_links ($page);
586     print <<"EOD";
587 wakaba 1.27 @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
588 wakaba 1.16 <div class="footer">
589 wakaba 1.29 <a href="http://www.hyuki.com/yukiwiki/" title="$version &copy; 2000-2002 by Hiroshi Yuki">YukiWiki</a> <a href="http://digit.que.ne.jp/work/" title="$walversion &copy; 2000-2002 by Makio Tsukamoto">WalWiki</a>
590     <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>
591 wakaba 1.18 <div class="navigation">
592     [<a href="/" title="このサーバーの首頁">/</a>
593     <a href="/map" title="このサーバーの案内">地図</a>
594     <a href="/search/" title="このサーバーの検索">検索</a>]
595     </div>
596 wakaba 1.33 <div class="myuri">
597     &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
598     </div>
599 wakaba 1.10 </div>
600 wakaba 1.19 $walrus_log
601 wakaba 1.16 </body>
602     </html>
603 wakaba 1.12 EOD
604 wakaba 1.9 }
605    
606 wakaba 1.16 sub escape {
607     my $s = shift;
608     $s =~ s|\r\n|\n|g;
609 wakaba 1.23 $s =~ s|&|&amp;|g;
610 wakaba 1.16 $s =~ s|<|&lt;|g;
611     $s =~ s|>|&gt;|g;
612     $s =~ s|"|&quot;|g;
613     return $s;
614     }
615    
616     sub unescape {
617     my $s = shift;
618     # $s =~ s|\n|\r\n|g;
619 wakaba 1.23 $s =~ s|&lt;|<|g;
620     $s =~ s|&gt;|>|g;
621     $s =~ s|&quot;|"|g;
622     $s =~ s|&amp;|&|g;
623 wakaba 1.16 return $s;
624     }
625    
626 wakaba 1.26 sub print_content ($;$) {
627 wakaba 1.27 my ($rawcontent, %option) = @_;
628 wakaba 1.29 print &text_to_html($rawcontent, toc=>1, %option);
629 wakaba 1.9 }
630    
631 wakaba 1.16 sub text_to_html {
632     my ($txt, %option) = @_;
633 wakaba 1.9 my (@txt) = split(/\n/, $txt);
634 wakaba 1.29 my @toc;
635     my @toc2 = @{$option{-toc}||[]};
636 wakaba 1.16 my $tocnum = 0;
637     my (@saved, @result);
638     unshift(@saved, "</p>");
639     push(@result, "<p>");
640 wakaba 1.9 foreach (@txt) {
641     chomp;
642 wakaba 1.25 if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
643     push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
644 wakaba 1.18 push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
645     $tocnum++;
646 wakaba 1.25 } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
647     push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
648 wakaba 1.18 push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
649     $tocnum++;
650 wakaba 1.25 } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
651     push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
652 wakaba 1.18 push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
653     $tocnum++;
654 wakaba 1.25 } elsif (/^\*\*([^\x0D\x0A]*)/) {
655 wakaba 1.16 # if (/^\*\*(.*)/) {
656     # Walrus mod (6) end
657 wakaba 1.25 push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
658 wakaba 1.16 push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');
659     $tocnum++;
660 wakaba 1.25 } elsif (/^\*([^\x0D\x0A]*)/) {
661     push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
662 wakaba 1.16 push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');
663     $tocnum++;
664 wakaba 1.25 } elsif (/^(={1,6})(.*)/) {
665 wakaba 1.18 &back_push('ol', length($1), \@saved, \@result);
666     push(@result, '<li>' . &inline($2) . '</li>');
667 wakaba 1.25 } elsif (/^(-{1,6})(.*)/) {
668 wakaba 1.28 &back_push('ul', length($1), \@saved, \@result);
669     my ($pf, $l) = ('', $2);
670     if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
671     my $num = 0+$1;
672     $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
673     }
674     push(@result, '<li>' . $pf . &inline ($l) . '</li>');
675 wakaba 1.9 } elsif (/^:([^:]+):(.*)/) {
676 wakaba 1.16 &back_push('dl', 1, \@saved, \@result);
677 wakaba 1.9 push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
678 wakaba 1.30 } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
679 wakaba 1.16 &back_push('blockquote', length($1), \@saved, \@result);
680 wakaba 1.30 push @result, "<p>";
681 wakaba 1.9 push(@result, &inline($2));
682 wakaba 1.30 unshift @saved, "</p>";
683 wakaba 1.9 } elsif (/^\s*$/) {
684     push(@result, splice(@saved));
685 wakaba 1.30 push(@result, "<p>");
686 wakaba 1.9 unshift(@saved, "</p>");
687     } elsif (/^(\s+.*)$/) {
688 wakaba 1.16 &back_push('pre', 1, \@saved, \@result);
689 wakaba 1.18 #push(@result, &escape($1)); # Not &inline, but &escape
690 wakaba 1.26 push(@result, &inline($1));
691 wakaba 1.16 # } elsif (/^\,(.*)$/) { # Walrus del (BF)
692     } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
693     &back_push('table', 1, \@saved, \@result, ' border="1"');
694     #######
695     # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
696     # XXXXX
697     my $tmp = "$1,";
698     my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
699     my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
700     my @colspan = map {($_ eq '==') ? 0 : 1} @value;
701     for (my $i = 0; $i < @value; $i++) {
702     if ($colspan[$i]) {
703     while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
704     $colspan[$i]++;
705     }
706     $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
707     $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i]));
708     } else {
709     $value[$i] = '';
710     }
711     }
712     push(@result, join('', '<tr>', @value, '</tr>'));
713     # XXXXX
714     #######
715 wakaba 1.29 } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
716 wakaba 1.28 push @result, splice (@saved), '<'.lc($1).'>';
717     unshift @saved, "</p>";
718     push @result, "<p>";
719 wakaba 1.29 } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
720 wakaba 1.28 push @result, splice (@saved), '</'.lc($1).'>';
721     } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
722     my $num = 0+$1;
723     push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
724     push @result, &inline ($2);
725 wakaba 1.9 } else {
726     push(@result, &inline($_));
727     }
728     }
729     push(@result, splice(@saved));
730 wakaba 1.27
731     my $toc = '';
732 wakaba 1.16 if ($option{toc}) {
733     # Convert @toc (table of contents) to HTML.
734     # This part is taken from Makio Tsukamoto's WalWiki.
735     my (@tocsaved, @tocresult);
736 wakaba 1.29 foreach (@toc,@toc2) {
737 wakaba 1.25 if (/^(-{1,6})(.*)$/) {
738 wakaba 1.16 &back_push('ul', length($1), \@tocsaved, \@tocresult);
739     push(@tocresult, '<li>' . $2 . '</li>');
740     }
741     }
742     push(@tocresult, splice(@tocsaved));
743 wakaba 1.27 $toc = join("\n", @tocresult);
744     $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
745 wakaba 1.16 }
746 wakaba 1.30 $toc .= join("\n", @result);
747     $toc =~ s#<p>\n</p>##g;
748     $toc =~ s#[\x0D\x0A]+</#</#g;
749     $toc =~ s#<pre>\n#<pre>#g;
750     $toc;
751 wakaba 1.9 }
752    
753     sub back_push {
754 wakaba 1.16 my ($tag, $level, $savedref, $resultref, $attr) = @_;
755     while (@$savedref > $level) {
756     push(@$resultref, shift(@$savedref));
757     }
758     if ($savedref->[0] ne "</$tag>") {
759     push(@$resultref, splice(@$savedref));
760     }
761     while (@$savedref < $level) {
762     unshift(@$savedref, "</$tag>");
763     push(@$resultref, "<$tag$attr>");
764 wakaba 1.9 }
765     }
766    
767 wakaba 1.16 sub inline {
768     my ($line) = @_;
769     $line = &escape($line);
770 wakaba 1.34 $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
771 wakaba 1.32 $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g;
772 wakaba 1.30 $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
773     $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
774     $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g;
775     $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
776     $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g;
777     $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
778     $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
779     $line =~ s|''([^']+)''|<em>$1</em>|g;
780 wakaba 1.31 $line =~ s{
781     ((?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]]
782 wakaba 1.30 |\[\[([^[]+?)]&gt;&gt;([0-9]+)] # [[WikiName]>>1]
783 wakaba 1.28 |&gt;&gt;([0-9]+)
784 wakaba 1.31 |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
785     }{
786     my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
787 wakaba 1.28 if ($l) {
788     &make_link($l)
789     } elsif (defined $page) {
790     &make_wikilink ($page, anchor => 0+$anchor);
791     } elsif ($anum) {
792     qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
793 wakaba 1.31 } elsif ($uri) {
794     &make_urilink ($uri);
795 wakaba 1.28 }
796 wakaba 1.31 }gex;
797 wakaba 1.16 return $line;
798     }
799    
800 wakaba 1.28 sub make_wikilink ($%) {
801     my ($ename, %option) = @_;
802     my $name = &unescape ($ename);
803     if ($database{$name}) {
804     my $subject = &escape (&get_subjectline ($name, delimiter => ''));
805     if ($option{anchor}) {
806     return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
807     } else {
808     return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
809     }
810     } else {
811     return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>);
812     }
813     }
814    
815 wakaba 1.31 sub make_urilink ($;%) {
816     require URI;
817     my $uri = shift;
818     if ($uri =~ s/^IW://) { ## InterWiki (not URI)
819     $uri = &unescape ($uri);
820     if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
821     my ($site, $name) = ($1, $2);
822     for ($site, $name) {
823     if (s/^"//) { s/"$//; s/\\(.)/$1/g }
824     }
825     if ($interwiki{$site}) {
826     my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
827     $site = &escape ($site); $name = &escape ($name);
828 wakaba 1.32 qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>&gt;);
829 wakaba 1.31 } else {
830     qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
831     }
832     } else {
833     qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
834     }
835     } elsif ($uri =~ /^urn:/) { ## URN
836     my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
837     qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
838     } elsif ($uri =~ s/^MAIL://) { ## mail address (not URI)
839     my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
840     qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
841     } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself)
842     my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
843     qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
844     } else { ## misc. URI
845     CGI::Carp::warningsToBrowser (0);
846     my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
847     CGI::Carp::warningsToBrowser (1);
848     qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
849     }
850     }
851    
852 wakaba 1.33 my $FormIndex = 0;
853 wakaba 1.35 sub make_custom_form ($$$$) {
854 wakaba 1.34 my ($wfname, $definition, $template, $option) = @_;
855 wakaba 1.33 ## $template and $option is currently not used in this procedure.
856     unless ($main::_EMBEDED) {
857     $FormIndex++;
858 wakaba 1.34 if (length $definition) {
859     my $param = bless {}, 'SuikaWiki::Plugin';
860     my $lastmodified = &get_info($form{mypage}, $info_LastModified);
861 wakaba 1.35 &load_formatter (qw/form_input form_option/);
862     $definition = &unescape ($definition);
863 wakaba 1.34 $definition =~ s/\\(.)/$1/g;
864     $definition .= ' %submit;' if $definition !~ /%submit/;
865     $option = &unescape ($option);
866     $option =~ s/\\(.)/$1/g;
867     $fmt{form_option}->replace ($option, $param);
868 wakaba 1.35 my $target_page = $param->{output}->{page} || $form{mypage};
869     $param->{form_disabled} = 1 if $fixedpage{$target_page};
870 wakaba 1.34 my $target_form = $param->{output}->{id};
871     my $r = <<EOH;
872 wakaba 1.33 <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
873 wakaba 1.35 <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
874     <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
875 wakaba 1.33 <input type="hidden" name="myLastModified" value="$lastmodified">
876     <input type="hidden" name="mytouch" value="on">
877 wakaba 1.34 <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
878 wakaba 1.33 EOH
879 wakaba 1.34 $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
880 wakaba 1.35 $r .= $fmt{form_input}->replace ($definition, $param);
881 wakaba 1.34 $r .= <<EOH;
882 wakaba 1.33 </form>
883     EOH
884 wakaba 1.34 $r;
885     } else { ## No input-interface WikiForm
886     qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
887     }
888 wakaba 1.33 } else {
889     q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
890     }
891     }
892    
893 wakaba 1.31 ## to be obsoleted
894 wakaba 1.16 sub make_link {
895     my $chunk = shift;
896     # Walrus add (3) start
897 wakaba 1.21 $chunk =~ s/^&lt;(.*)&gt;$/$1/;
898 wakaba 1.16 my $name = $chunk;
899     $name = &unarmor_name($name);
900     # Walrus add (3) end
901 wakaba 1.31 if ($chunk =~ /^$embedded_name$/) {
902 wakaba 1.16 return &embedded_to_html($chunk);
903     } else {
904     $chunk = &unarmor_name($chunk);
905     $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
906     my $cookedchunk = &encode($chunk);
907 wakaba 1.31 if ($database{$chunk}) {
908 wakaba 1.16 my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
909     # return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3)
910 wakaba 1.26 return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3)
911 wakaba 1.16 } elsif ($page_command{$chunk}) {
912     # return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3)
913 wakaba 1.24 return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3)
914 wakaba 1.16 } else {
915 wakaba 1.24 return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
916 wakaba 1.9 }
917     }
918     }
919    
920 wakaba 1.16 sub print_message {
921     my ($msg) = @_;
922     print qq(<p><strong>$msg</strong></p>);
923 wakaba 1.9 }
924    
925 wakaba 1.22 sub get_message {
926     my ($msg) = @_;
927     qq(<p><strong>$msg</strong></p>);
928     }
929    
930 wakaba 1.16 sub init_form {
931     if (param()) {
932     foreach my $var (param()) {
933     $form{$var} = param($var);
934 wakaba 1.30 }
935 wakaba 1.16 }
936 wakaba 1.32 $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
937     if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
938 wakaba 1.30 my $query = &decode($main::ENV{QUERY_STRING});
939 wakaba 1.32 $query = &code_convert(\$query, $kanjicode);
940 wakaba 1.30 if ($page_command{$query}) {
941 wakaba 1.16 $form{mycmd} = $page_command{$query};
942     $form{mypage} = $query;
943 wakaba 1.30 } else {
944 wakaba 1.16 $form{mypage} = $query;
945 wakaba 1.30 $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
946     }
947 wakaba 1.16 }
948 wakaba 1.30 $form{mypage} ||= 'HomePage';
949 wakaba 1.32 $form{mycmd} ||= 'read';
950 wakaba 1.16
951     # mypreview_edit -> do_edit, with preview.
952     # mypreview_adminedit -> do_adminedit, with preview.
953     # mypreview_write -> do_write, without preview.
954     foreach (keys %form) {
955     if (/^mypreview_(.*)$/) {
956     $form{mycmd} = $1;
957     $form{mypreview} = 1;
958     }
959     }
960 wakaba 1.9
961 wakaba 1.30 #
962 wakaba 1.16 # $form{mycmd} is frozen here.
963 wakaba 1.30 #
964 wakaba 1.16
965 wakaba 1.33 for (grep /^wikiform__/, keys %form) {
966     $form{$_} = &code_convert (\$form{$_}, $kanjicode);
967     }
968 wakaba 1.16 $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
969     $form{myname} = &code_convert(\$form{myname}, $kanjicode);
970     }
971    
972     sub update_recent_changes {
973 wakaba 1.28 my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
974 wakaba 1.16 my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
975 wakaba 1.33 shift (@oldupdates); ## '#?' magic line
976 wakaba 1.16 my @updates;
977     foreach (@oldupdates) {
978 wakaba 1.28 /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;
979     my $name = $1;
980     if ($name ne $form{mypage}) {
981     push @updates, $_;
982 wakaba 1.16 }
983     }
984     if (&is_exist_page($form{mypage})) {
985 wakaba 1.28 unshift @updates, $update;
986 wakaba 1.16 }
987     splice(@updates, $maxrecent + 1);
988 wakaba 1.32 $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
989 wakaba 1.16 if ($file_touch) {
990     open(FILE, "> $file_touch");
991     print FILE localtime() . "\n";
992     close(FILE);
993     }
994 wakaba 1.9 }
995    
996 wakaba 1.16 sub get_subjectline {
997     my ($page, %option) = @_;
998     if (not &is_editable($page)) {
999     return "";
1000     } else {
1001     # Delimiter check.
1002     my $delim = $subject_delimiter;
1003     if (defined($option{delimiter})) {
1004     $delim = $option{delimiter};
1005     }
1006 wakaba 1.9
1007 wakaba 1.16 # Get the subject of the page.
1008     my $subject = $database{$page};
1009 wakaba 1.28 $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
1010 wakaba 1.16 $subject =~ s/\r?\n.*//s;
1011 wakaba 1.27 return "$delim$subject".$option{tail};
1012 wakaba 1.16 }
1013 wakaba 1.9 }
1014    
1015 wakaba 1.16 sub send_mail_to_admin {
1016     my ($page, $mode) = @_;
1017     return unless $modifier_sendmail;
1018     my $message = <<"EOD";
1019     To: $modifier_mail
1020     From: $modifier_mail
1021     Subject: [Wiki]
1022     MIME-Version: 1.0
1023     Content-Type: text/plain; charset=ISO-2022-JP
1024     Content-Transfer-Encoding: 7bit
1025    
1026     --------
1027     MODE = $mode
1028     REMOTE_ADDR = $ENV{REMOTE_ADDR}
1029     REMOTE_HOST = $ENV{REMOTE_HOST}
1030     --------
1031     $page
1032     --------
1033     $database{$page}
1034     --------
1035     EOD
1036     &code_convert(\$message, 'jis');
1037     open(MAIL, "| $modifier_sendmail");
1038     print MAIL $message;
1039     close(MAIL);
1040 wakaba 1.9 }
1041    
1042 wakaba 1.16 sub open_db {
1043     if ($modifier_dbtype eq 'dbmopen') {
1044     dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");
1045     dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");
1046     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1047     tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");
1048     tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");
1049     } else {
1050     tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");
1051     tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");
1052 wakaba 1.9 }
1053     }
1054    
1055 wakaba 1.16 sub close_db {
1056     if ($modifier_dbtype eq 'dbmopen') {
1057     dbmclose(%database);
1058     dbmclose(%infobase);
1059     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1060     untie(%database);
1061     untie(%infobase);
1062     } else {
1063     untie(%database);
1064     untie(%infobase);
1065     }
1066     }
1067 wakaba 1.9
1068 wakaba 1.16 sub open_diff {
1069     if ($modifier_dbtype eq 'dbmopen') {
1070     dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");
1071     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1072     tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");
1073     } else {
1074     tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");
1075     }
1076     }
1077 wakaba 1.9
1078 wakaba 1.16 sub close_diff {
1079     if ($modifier_dbtype eq 'dbmopen') {
1080     dbmclose(%diffbase);
1081     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1082     untie(%diffbase);
1083     } else {
1084     untie(%diffbase);
1085     }
1086 wakaba 1.9 }
1087    
1088 wakaba 1.16 sub print_searchform {
1089     my ($word) = @_;
1090     print <<"EOD";
1091     <form action="$url_cgi" method="get">
1092 wakaba 1.31 <input type="hidden" name="mycmd" value="read">
1093     <input type="text" name="mypage" value="$word" size="20">
1094 wakaba 1.16 <input type="submit" value="$resource{searchbutton}">
1095     </form>
1096     EOD
1097 wakaba 1.9 }
1098    
1099 wakaba 1.16 sub print_editform {
1100     my ($mymsg, $lastmodified, %mode) = @_;
1101     my $frozen = &is_frozen($form{mypage});
1102    
1103     if ($form{mypreview}) {
1104     if ($form{mymsg}) {
1105     unless ($mode{conflict}) {
1106     print qq(<h3>$resource{previewtitle}</h3>\n);
1107     print qq($resource{previewnotice}\n);
1108     print qq(<div class="preview">\n);
1109     &print_content($form{mymsg});
1110     print qq(</div>\n);
1111     }
1112     } else {
1113     print qq($resource{previewempty});
1114     }
1115     $mymsg = &escape($form{mymsg});
1116 wakaba 1.9 } else {
1117 wakaba 1.25 $mymsg = &escape($mymsg || $database{NewPageTemplate});
1118 wakaba 1.9 }
1119    
1120 wakaba 1.16 my $edit = $mode{admin} ? 'adminedit' : 'edit';
1121 wakaba 1.24 my $escapedmypage = &escape($form{mypage});
1122     my $escapedmypassword = &escape($form{mypassword});
1123 wakaba 1.16
1124     print <<"EOD";
1125     <form action="$url_cgi" method="post">
1126 wakaba 1.30 <h2>$escapedmypageの編集</h2>
1127 wakaba 1.24 @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}
1128 wakaba 1.16 <input type="hidden" name="myLastModified" value="$lastmodified">
1129 wakaba 1.24 <input type="hidden" name="mypage" value="$escapedmypage">
1130 wakaba 1.25 <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1131 wakaba 1.16 @{[
1132     $mode{admin} ?
1133     qq(
1134     <input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton}
1135     <input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>)
1136     : ""
1137     ]}
1138     @{[
1139     $mode{conflict} ? "" :
1140     qq(
1141     <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1142     <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1143 wakaba 1.30 <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1144     [@{[do {my $n = 0;
1145     $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1146     ++$n}]}]<br>
1147 wakaba 1.16 )
1148     ]}
1149     </form>
1150     EOD
1151     unless ($mode{conflict}) {
1152     # Show the format rule.
1153 wakaba 1.30 my $help = $database{'WikiEditHelp'};
1154     $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1155     print &text_to_html ($help, toc => 0);
1156     # open(FILE, $file_format) or &print_error("($file_format)");
1157     # my $content = join('', <FILE>);
1158     # &code_convert(\$content, $kanjicode);
1159     # close(FILE);
1160     # print &text_to_html($content, toc=>0);
1161 wakaba 1.9 }
1162     }
1163    
1164 wakaba 1.16 sub print_passwordform {
1165     print <<"EOD";
1166     <form action="$url_cgi" method="post">
1167     <input type="hidden" name="mycmd" value="adminchangepassword">
1168     $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>
1169     $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>
1170     $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>
1171     <input type="submit" value="$resource{changepasswordbutton}"><br>
1172     </form>
1173     EOD
1174 wakaba 1.9 }
1175    
1176 wakaba 1.16 sub is_editable {
1177     my ($page) = @_;
1178 wakaba 1.31 if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
1179 wakaba 1.16 return 0;
1180     } else {
1181     return 1;
1182     }
1183 wakaba 1.9 }
1184    
1185 wakaba 1.16 # armor_name:
1186     # WikiName -> WikiName
1187     # not_wiki_name -> [[not_wiki_name]]
1188 wakaba 1.31 sub armor_name { qq([[$_[0]]]) }
1189 wakaba 1.9
1190 wakaba 1.16 # unarmor_name:
1191     # [[bracket_name]] -> bracket_name
1192     # WikiName -> WikiName
1193     sub unarmor_name {
1194     my ($name) = @_;
1195     if ($name =~ /^$bracket_name$/) {
1196     return $1;
1197     } else {
1198     return $name;
1199     }
1200 wakaba 1.9 }
1201    
1202 wakaba 1.16 sub decode {
1203     my ($s) = @_;
1204     $s =~ tr/+/ /;
1205     $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
1206     return $s;
1207     }
1208 wakaba 1.9
1209 wakaba 1.16 sub encode {
1210     my ($s) = @_;
1211     my $encoded = '';
1212     foreach my $ch (split(//, $s)) {
1213     if ($ch =~ /[A-Za-z0-9_]/) {
1214     $encoded .= $ch;
1215     } else {
1216     $encoded .= '%' . sprintf("%02X", ord($ch));
1217     }
1218     }
1219     return $encoded;
1220     }
1221 wakaba 1.9
1222 wakaba 1.16 sub init_resource {
1223     open(FILE, $file_resource) or &print_error("(resource)");
1224     while (<FILE>) {
1225     chomp;
1226     next if /^#/;
1227     my ($key, $value) = split(/=/, $_, 2);
1228     $resource{$key} = &code_convert(\$value, $kanjicode);
1229     }
1230     close(FILE);
1231     }
1232 wakaba 1.9
1233 wakaba 1.16 sub conflict {
1234     my ($page, $rawmsg) = @_;
1235     if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1236     return 0;
1237     }
1238     open(FILE, $file_conflict) or &print_error("(conflict)");
1239     my $content = join('', <FILE>);
1240     &code_convert(\$content, $kanjicode);
1241     close(FILE);
1242 wakaba 1.29 &print_header($page, -noindex => 1);
1243 wakaba 1.16 &print_content($content);
1244     &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1245     &print_footer($page);
1246     return 1;
1247     }
1248    
1249     sub get_now {
1250     my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1251 wakaba 1.28 my (@week) = qw(日 月 火 水 木 金 土);
1252 wakaba 1.16 my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1253     $year += 1900;
1254     $mon++;
1255     $mon = "0$mon" if $mon < 10;
1256     $day = "0$day" if $day < 10;
1257     $hour = "0$hour" if $hour < 10;
1258     $min = "0$min" if $min < 10;
1259 wakaba 1.28 #$sec = "0$sec" if $sec < 10;
1260 wakaba 1.16 $weekday = $week[$weekday];
1261 wakaba 1.28 return "$year-$mon-$day ($weekday) $hour:$min";
1262 wakaba 1.16 }
1263    
1264     sub init_InterWikiName {
1265 wakaba 1.31 my @content = split /\n/, $database{$InterWikiName};
1266     for (@content) {
1267     if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1268     $interwiki{$1} = $2;
1269 wakaba 1.16 }
1270 wakaba 1.31 }
1271     require Message::Util::Formatter;
1272     $fmt{interwiki} = Message::Util::Formatter->new;
1273     $fmt{interwiki}->{encoded} = sub {
1274     my ($o, $p) = @_;
1275     if ($o->{except}) {
1276 wakaba 1.32 $o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1277 wakaba 1.31 }
1278     my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1279 wakaba 1.32 $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1280 wakaba 1.31 $s;
1281     };
1282     $fmt{interwiki}->{ykwk} = sub { ## YukiWiki1
1283     my ($o, $p) = @_;
1284     my $s = $p->{name};
1285     $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1286     &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1287     };
1288 wakaba 1.16 }
1289 wakaba 1.9
1290    
1291 wakaba 1.16 sub get_info {
1292     my ($page, $key) = @_;
1293     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1294     return $info{$key};
1295     }
1296 wakaba 1.9
1297 wakaba 1.16 sub set_info {
1298     my ($page, $key, $value) = @_;
1299     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1300     $info{$key} = $value;
1301     my $s = '';
1302     for (keys %info) {
1303     $s .= "$_=$info{$_}\n";
1304     }
1305     $infobase{$page} = $s;
1306     }
1307 wakaba 1.9
1308 wakaba 1.16 sub frozen_reject {
1309     my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);
1310     my ($willbefrozen) = $form{myfrozen};
1311     if (not $isfrozen and not $willbefrozen) {
1312     # You need no check.
1313     return 0;
1314     } elsif (valid_password($form{mypassword})) {
1315     # You are admin.
1316     return 0;
1317     } else {
1318     &print_error($resource{passworderror});
1319     return 1;
1320     }
1321     }
1322 wakaba 1.9
1323 wakaba 1.16 sub valid_password {
1324     my ($givenpassword) = @_;
1325     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
1326     if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1327     return 1;
1328     } else {
1329     return 0;
1330     }
1331     }
1332 wakaba 1.9
1333 wakaba 1.16 sub is_frozen {
1334     my ($page) = @_;
1335     if (&get_info($page, $info_IsFrozen)) {
1336     return 1;
1337     } else {
1338     return 0;
1339     }
1340     }
1341 wakaba 1.9
1342 wakaba 1.16 sub do_comment {
1343     my ($content) = $database{$form{mypage}};
1344 wakaba 1.30 my $default_name; ## this code does not strict.
1345     $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1346     my $datestr = '[WEAK['.&get_now.']]';
1347     my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1348     ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1349 wakaba 1.29 if ($namestr =~ /^(?:>>)?[0-9]/) {
1350     $namestr = qq( ''$namestr'': );
1351 wakaba 1.30 } elsif (length $namestr) {
1352 wakaba 1.29 $namestr = qq( ''[[$namestr]]'': );
1353     }
1354 wakaba 1.33 my $anchor = &get_new_anchor_index ($content);
1355 wakaba 1.27 my $i = 1; my $o = 0;
1356 wakaba 1.25 $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1357     my $embed = $1;
1358     if ($i == $form{comment_index}) {
1359     if ($embed eq $embed_comment) {
1360 wakaba 1.28 $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1;
1361 wakaba 1.25 } else {
1362 wakaba 1.28 $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1;
1363 wakaba 1.25 }
1364     }
1365     $i++; $embed;
1366     }ge;
1367     unless ($o) {
1368 wakaba 1.30 $content = "#?SuikaWiki/0.9\n\n" unless $content;
1369     $content .= "\n" unless $content =~ /\n$/s;
1370 wakaba 1.28 $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1371 wakaba 1.16 }
1372 wakaba 1.29 $form{__comment_anchor_index} = $anchor;
1373 wakaba 1.30 if ($form{mymsg} || $form{myname}) {
1374 wakaba 1.16 $form{mymsg} = $content;
1375     $form{mytouch} = 'on';
1376     &do_write;
1377     } else {
1378     $form{mycmd} = 'read';
1379     &do_read;
1380     }
1381     }
1382 wakaba 1.9
1383 wakaba 1.33 sub get_new_anchor_index ($) {
1384     my $content = shift;
1385     my $anchor = 0;
1386     $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1387     $anchor + 1;
1388     }
1389    
1390 wakaba 1.27 my $CommentIndex = 0;
1391 wakaba 1.16 sub embedded_to_html {
1392     my ($embedded) = @_;
1393     if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1394 wakaba 1.28 unless ($main::_EMBEDED) {
1395 wakaba 1.16 my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1396     return <<"EOD";
1397 wakaba 1.30 <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1398 wakaba 1.16 <input type="hidden" name="mycmd" value="comment">
1399     <input type="hidden" name="mypage" value="$form{mypage}">
1400     <input type="hidden" name="myLastModified" value="$lastmodified">
1401     <input type="hidden" name="mytouch" value="on">
1402 wakaba 1.27 <input type="hidden" name="comment_index" value="$CommentIndex">
1403 wakaba 1.25 $embed_comment_Name_Prompt
1404 wakaba 1.30 <input type="text" name="myname" value="" size="10" class="comment-name">
1405     <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1406     <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1407     </p></form>
1408 wakaba 1.16 EOD
1409 wakaba 1.28 } else {
1410     return <<"EOD";
1411     <del><form action="$url_cgi" method="get">
1412     <input type="hidden" name="mycmd" value="read">
1413     <input type="hidden" name="mypage" value="$form{mypage}">
1414     $embed_comment_Name_Prompt
1415     <input type="text" name="myname" value="" size="10" disabled="disabled">
1416     <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1417     <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1418     </form></del>
1419     EOD
1420     }
1421 wakaba 1.22 } elsif ($embedded =~ /$embed_command{searched}/) {
1422 wakaba 1.30 return get_search_result ($1, -match_myself => 1);
1423 wakaba 1.16 # Walrus add (5) start
1424     } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1425     $_ = &make_interwiki_box($1, $2);
1426     return ($_) ? $_ : $embedded;
1427     # Walrus add (5) end
1428 wakaba 1.28 } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1429     my ($name, $r) = ($1, '');
1430     if ($main::_EMBEDED != 1) {
1431     my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1432     $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1433     if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1434     $main::_EMBEDED = 1;
1435     $r = &text_to_html ($content, content_format => $cf);
1436     $main::_EMBEDED = 0;
1437     } elsif (length $content) {
1438     $r = "<pre>@{[&escape ($content)]}</pre>";
1439     } else {
1440 wakaba 1.30 $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1441 wakaba 1.28 }
1442     } else { ## nested #EMBED
1443     $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1444 wakaba 1.16 }
1445 wakaba 1.31 return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>);
1446 wakaba 1.28 } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1447     return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1448     } else {
1449     return $embedded;
1450     }
1451 wakaba 1.16 }
1452 wakaba 1.9
1453 wakaba 1.35 sub load_formatter (@) {
1454     for my $t (@_) {
1455 wakaba 1.33 unless ($fmt{$t}) {
1456     $fmt{$t} = Message::Util::Formatter->new;
1457     for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1458     $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1459     }
1460     }
1461     }
1462 wakaba 1.35 }
1463    
1464     sub do_wikiform {
1465     my $content = $database{$form{mypage}};
1466     my $anchor = &get_new_anchor_index ($content);
1467     &load_formatter (qw/form_template form_option/);
1468 wakaba 1.33 my $write = 0;
1469     my $i = 1;
1470     $content =~ s{$embed_command{form}}{
1471 wakaba 1.34 my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1472     if (($wfname && $wfname eq $form{wikiform_targetform})
1473     || $i == $form{wikiform_index}) {
1474     $template =~ s/\\(.)/$1/g;
1475     $option =~ s/\\(.)/$1/g;
1476 wakaba 1.33 my $param = bless {}, 'SuikaWiki::Plugin';
1477     $param->{page} = $form{mypage};
1478     $param->{form_index} = $i;
1479 wakaba 1.34 $param->{form_name} = $wfname;
1480 wakaba 1.33 $param->{anchor_index} = $anchor;
1481     $param->{argv} = \%form;
1482     $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1483 wakaba 1.34 $param->{default_name} ||= $DEFAULT_embed_comment_name;
1484 wakaba 1.33 $fmt{form_option}->replace ($option, $param);
1485 wakaba 1.34 my $t = 1;
1486     for (@{$param->{require}||[]}) {
1487     (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1488     }
1489     $t = $fmt{form_template}->replace ($template, $param) if $t;
1490 wakaba 1.33 if (length $t) {
1491     if ($param->{output}->{reverse}) {
1492 wakaba 1.34 $embed .= "\n" . $t;
1493     } else {
1494 wakaba 1.33 $embed = $t . "\n" . $embed;
1495     }
1496     $write = 1;
1497     $form{__comment_anchor_index} = $anchor
1498 wakaba 1.34 if $param->{anchor_index_}; ## $anchor is used!
1499 wakaba 1.33 }
1500 wakaba 1.34 $form{__wikiform_anchor_index} = $i;
1501     undef $form{wikiform_targetform}; ## make sure never to match
1502     undef $form{wikiform_index}; ## with WikiForm in rest of page
1503 wakaba 1.33 }
1504     $i++; $embed;
1505     }ge;
1506     unless ($write) {
1507     #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1508     #$content .= "\n" unless $content =~ /\n$/s;
1509     #
1510     }
1511     if ($write) {
1512     $form{mymsg} = $content;
1513     $form{mytouch} = 'on';
1514     &do_write;
1515     } else {
1516     $form{mycmd} = 'read';
1517     &do_read;
1518     }
1519     }
1520    
1521    
1522 wakaba 1.16 # Walrus add (5) start
1523     sub do_interwiki_box {
1524     my $remoteurl = $interwiki{$form{'myintername'}};
1525     if ($remoteurl) {
1526     $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;
1527     print "Location: $remoteurl\n\n";
1528     exit(1);
1529     } else {
1530     &do_read;
1531     }
1532     }
1533     # Walrus add (5) end
1534 wakaba 1.9
1535 wakaba 1.16 # Walrus add (5) start
1536     sub make_interwiki_box {
1537     my ($localname, $intername) = @_;
1538     my %ignoretype = (
1539     'box' => 'text',
1540     'text' => 'text',
1541     'pass' => 'password',
1542     'password' => 'password'
1543     );
1544     my $converted = ($ignoretype{$localname}) ? <<EOD : undef;
1545     <form action="$url_cgi" method="post">
1546     <input type="hidden" name="mycmd" value="interwikibox">
1547     <input type="hidden" name="mypage" value="$form{mypage}">
1548     <input type="hidden" name="myintername" value="$intername">
1549     $intername:
1550     <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">
1551     <input type="submit" value="Submit">
1552     </form>
1553     EOD
1554     }
1555     # Walrus add (5) end
1556 wakaba 1.9
1557 wakaba 1.16 sub code_convert {
1558 wakaba 1.27 my ($contentref, $code) = (shift, shift || $kanjicode);
1559 wakaba 1.31 $code = 'jis' if $code =~ /iso/;
1560     $code = 'euc' if $code =~ /euc/;
1561     $code = 'sjis' if $code =~ /shift/;
1562     $code = 'utf8' if $code =~ /utf/;
1563 wakaba 1.32 &Jcode::convert($contentref, $code); # for Jcode.pm
1564     # &jcode::convert($contentref, $code); # for jcode.pl
1565     &jcode::tr ($contentref, "\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&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ )) if $code eq 'euc';
1566 wakaba 1.16 return $$contentref;
1567     }
1568    
1569     sub test_convert {
1570     my $txt = &text_to_html(<<"EOD", toc=>1);
1571     *HEADER1
1572     **HEADER1-1
1573     -ITEM1
1574     -ITEM2
1575     -ITEM3
1576     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1577     PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1578     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1579    
1580     PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1581     PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1582     PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1583     **HEADER1-2
1584     :TERM1:DESCRIPTION1 AND ''BOLD''
1585     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1586     PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1587     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1588     :TERM2:DESCRIPTION2
1589     :TERM3:DESCRIPTION3
1590     ----
1591     *HEADER2
1592     **HEADER2-1
1593     http://www.hyuki.com/
1594     **HEADER2-2
1595 wakaba 1.9
1596 wakaba 1.16 [[YukiWiki2]]
1597 wakaba 1.9
1598 wakaba 1.16 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1599     PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1
1600     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1601     >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1602     >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1603     >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1604    
1605     LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0
1606    
1607     >LEVEL1
1608     >LEVEL1
1609     >LEVEL1
1610     >>LEVEL2
1611     >>LEVEL2
1612     >>LEVEL2
1613     >>>LEVEL3
1614     -HELLO-1
1615     --HELLO-2
1616     (HELLO-2, HELLO-2, HELLO-2)
1617     ---HELLO-3
1618     (HELLO-3, HELLO-3, HELLO-3)
1619     --HELLO-2
1620     ---HELLO-3
1621     --HELLO-2
1622     ---HELLO-3
1623     >>>LEVEL3
1624     >>>LEVEL3
1625     >>>LEVEL3
1626     >>>LEVEL3
1627     EOD
1628     print $txt;
1629     exit;
1630     }
1631 wakaba 1.9
1632 wakaba 1.16 sub do_diff {
1633     if (not &is_editable($form{mypage})) {
1634     &do_read;
1635     return;
1636     }
1637     &open_diff;
1638     my $title = $form{mypage};
1639 wakaba 1.29 &print_header($title, -noindex => 1);
1640 wakaba 1.16 $_ = &escape($diffbase{$form{mypage}});
1641     &close_diff;
1642     print qq(<h3>$resource{difftitle}</h3>);
1643     print qq($resource{diffnotice});
1644     print qq(<pre class="diff">);
1645     foreach (split(/\n/, $_)) {
1646     if (/^\+(.*)/) {
1647     print qq(<b class="added">$1</b>\n);
1648     } elsif (/^\-(.*)/) {
1649     print qq(<s class="deleted">$1</s>\n);
1650     } elsif (/^\=(.*)/) {
1651     print qq(<span class="same">$1</span>\n);
1652     } else {
1653     print qq|??? $_\n|;
1654     }
1655     }
1656     print qq(</pre>);
1657     print qq(<hr>);
1658     &print_footer($title);
1659     }
1660 wakaba 1.9
1661 wakaba 1.16 sub do_rss {
1662     my $rss = new Yuki::RSS(
1663     version => '1.0',
1664     encoding => $charset,
1665     );
1666     $rss->channel(
1667     title => $modifier_rss_title,
1668     link => $modifier_rss_link,
1669     description => $modifier_rss_description,
1670     );
1671     my $recentchanges = $database{$RecentChanges};
1672     my $count = 0;
1673     foreach (split(/\n/, $recentchanges)) {
1674     last if ($count >= 15);
1675 wakaba 1.28 /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format.
1676 wakaba 1.16 my $title = &unarmor_name($1);
1677     my $escaped_title = &escape($title);
1678     my $link = $modifier_rss_link . '?' . &encode($title);
1679     my $description = $escaped_title . &escape(&get_subjectline($title));
1680     $rss->add_item(
1681     title => $escaped_title,
1682     link => $link,
1683     description => $description,
1684     );
1685     $count++;
1686     }
1687     # print RSS information (as XML).
1688     print <<"EOD"
1689     Content-type: text/xml
1690 wakaba 1.9
1691 wakaba 1.16 @{[$rss->as_string]}
1692     EOD
1693     }
1694 wakaba 1.9
1695 wakaba 1.16 sub is_exist_page {
1696     my ($name) = @_;
1697     if ($use_exists) {
1698     return exists($database{$name});
1699     } else {
1700     return $database{$name};
1701     }
1702 wakaba 1.27 }
1703    
1704     sub __get_database ($) { $database{ $_[0] } }
1705 wakaba 1.32 sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1706 wakaba 1.27
1707 wakaba 1.35 sub do_wikiplugininfo {
1708     &print_header (q(WikiPluginInfo));
1709     print text_to_html (&SuikaWiki::Plugin::make_info_page);
1710     &print_footer (q(WikiPluginInfo));
1711     }
1712    
1713 wakaba 1.27 package wiki::referer;
1714     sub add ($$) {
1715     my $page = shift;
1716     my $uri = shift;
1717     unless (ref $uri) {
1718     require URI;
1719     $uri = URI->new ($uri);
1720     ## Some schemes do not have query part.
1721     eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1722     $uri->fragment (undef);
1723     }
1724     $uri = $uri->canonical;
1725     return unless $uri;
1726     for my $regex (&get_dont_record) {
1727     return if $uri =~ /$regex/;
1728     }
1729     my %list = get ($page);
1730     $list{ $uri }++;
1731     set ($page, \%list);
1732     }
1733     sub get ($) {
1734     my $page = shift;
1735     split /"/, main::get_info ($page, 'Referer');
1736     }
1737     sub set ($%) {
1738     my $page = shift;
1739     my $list = shift;
1740     main::set_info ($page, Referer => join '"', %$list);
1741     }
1742    
1743     sub get_dont_record () {
1744     map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1745     grep !/^#/,
1746     split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1747     }
1748     sub get_site_name () {
1749     my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1750 wakaba 1.28 my @item;
1751 wakaba 1.27 for (@lines) {
1752     next if /^#/;
1753     my ($uri, $name) = split /\s+/, $_, 2;
1754     $uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g;
1755 wakaba 1.28 $name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1756     push @item, [$uri, qq(q($name))];
1757 wakaba 1.27 }
1758 wakaba 1.28 @item;
1759 wakaba 1.27 }
1760    
1761     sub list_html ($) {
1762     my $page = shift;
1763     my %list = get ($page);
1764     my $r = '';
1765 wakaba 1.28 my @name = get_site_name;
1766 wakaba 1.27 for my $uri (sort keys %list) {
1767     my $title;
1768 wakaba 1.28 for my $item (@name) {
1769     if ($uri =~ /$item->[0]/) {
1770 wakaba 1.27 $title = $uri;
1771 wakaba 1.28 eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1772     or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1773 wakaba 1.27 last;
1774     }
1775     }
1776     my $euri = main::escape ($uri);
1777     if ($title) {
1778     $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);
1779     } else {
1780     $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1781     }
1782     }
1783     $r ? qq(<ul>$r</ul>\n) : '';
1784     }
1785    
1786     sub __decode ($) {
1787     my $s = shift;
1788     $s =~ tr/+/ /;
1789     $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1790     main::code_convert (\$s);
1791 wakaba 1.32 }
1792    
1793     package wiki::useragent;
1794    
1795     sub add ($) {
1796     my $s = shift;
1797     return unless length $s;
1798     $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1799     my %ua;
1800     for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1801     if (/^-\[(\d+)\] (.+)$/) {
1802     my ($t, $n) = ($1, $2);
1803     $n =~ tr/\x0A\x0D//d;
1804     $ua{$n} = $t;
1805     }
1806     }
1807     $ua{$s}++;
1808     my $s = qq(#?SuikaWiki/0.9\n);
1809     for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1810     $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1811     }
1812     &main::__set_database ('WikiUserAgentList' => $s);
1813 wakaba 1.16 }
1814 wakaba 1.33
1815     package SuikaWiki::Plugin;
1816 wakaba 1.35 our $plugin_directory; # defined in top of this file.
1817 wakaba 1.33 our %List;
1818    
1819     sub escape ($$) { main::escape ($_[1]) }
1820     sub unescape ($$) { main::unescape ($_[1]) }
1821     sub encode ($$) { main::encode ($_[1]) }
1822     sub decode ($$) { main::decode ($_[1]) }
1823     sub __get_datetime ($) { main::get_now () }
1824    
1825     sub regist ($@) {
1826     my $pack = shift;
1827     for (@_) {
1828     push @{$List{$_}}, $pack;
1829     }
1830     }
1831    
1832 wakaba 1.35 sub import_plugins () {
1833     opendir PDIR, $plugin_directory;
1834     my @plugin = grep {s/\.pm$//} readdir (PDIR);
1835     closedir PDIR;
1836     for (@plugin) {
1837     eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1838     push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1839     }
1840     }
1841    
1842     sub make_info_page () {
1843     my $r = <<EOH;
1844     EOH
1845     unless ($List{_all}) {
1846     $r .= qq('''No plugin is installed!'''\n);
1847     } else {
1848     my $index = 0;
1849     for my $package (sort @{$List{_all}}) {
1850     $index++;
1851     my $prop = $package->property ();
1852     $r .= <<EOH;
1853     *$package
1854    
1855     [$index] '''$prop->{name}''' (Version $prop->{version})
1856     <$prop->{uri}>
1857    
1858     Provide:
1859     @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1860     $t .= qq(-''$f''\n);
1861     for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1862     $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1863     }
1864     }$t}]}
1865    
1866     EOH
1867     }
1868     }
1869     $r;
1870     }
1871    
1872     &import_plugins ();
1873    
1874     package main;
1875     &main;
1876     exit 0;
1877 wakaba 1.9
1878 wakaba 1.16 1;
1879     __END__
1880     =head1 NAME
1881 wakaba 1.9
1882 wakaba 1.16 wiki.cgi - This is YukiWiki, yet another Wiki clone.
1883 wakaba 1.9
1884 wakaba 1.16 =head1 DESCRIPTION
1885 wakaba 1.9
1886 wakaba 1.16 YukiWiki is yet another Wiki clone.
1887 wakaba 1.9
1888 wakaba 1.16 YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).
1889     YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),
1890     and some embedded commands (such as [[#comment]] to add comments).
1891 wakaba 1.9
1892 wakaba 1.16 Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.
1893 wakaba 1.9
1894 wakaba 1.16 =head1 AUTHOR
1895 wakaba 1.9
1896 wakaba 1.16 Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/
1897 wakaba 1.9
1898 wakaba 1.16 =head1 LICENSE
1899 wakaba 1.9
1900 wakaba 1.16 Copyright (C) 2000-2002 by Hiroshi Yuki.
1901 wakaba 1.9
1902 wakaba 1.16 This program is free software; you can redistribute it and/or
1903     modify it under the same terms as Perl itself.
1904 wakaba 1.9
1905     =cut

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24