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

Diff of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by wakaba, Thu Oct 17 07:56:58 2002 UTC revision 1.36 by wakaba, Tue Dec 10 07:27:38 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #!perl  
2  #  #
3  # wiki.cgi - This is YukiWiki, yet another Wiki clone.  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
4  #  #
# Line 10  Line 9 
9  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
10  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
11  #  #
 ##############################  
 #  
12  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
 #  
 # WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。  
 #  
 # * 更新内容  
 #  
 # 2.0.beta1.wal.1 on 2002/05/19,22:32:19  
 # (1) Footerの変更  
 # (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない  
 # (3) 別名リンク([別名 URL])に対応。  
 # (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。  
 # (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成  
 # (6) HTMLモード対応。  
 #  
 # 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。  
 # ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。  
 #   - インラインの画像変換  
 #   - YukiWikiDB対応  
 #   - テーブル  
 #   - DB関連モジュールuseのeval化  
 #   - BracketNameによるキーからブラケットを排除  
 # ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。  
 #   [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。  
 #  
 #=======================================  
13    
14  # Walrus add (debug) start  # Walrus add (debug) start
15  my $walrus_log;  my $walrus_log;
# Line 53  use Yuki::DiffText qw(difftext); Line 26  use Yuki::DiffText qw(difftext);
26  use Yuki::YukiWikiDB;  use Yuki::YukiWikiDB;
27  use AnyDBM_File;  use AnyDBM_File;
28  require 'jcode.pl';  require 'jcode.pl';
29  # use Jcode;  require Jcode;
30  use Fcntl;  use Fcntl;
31  my $version = '2.0.beta1.2002-05-29';  my $version = '2.0.beta1.2002-05-29';
32  my $walversion;  my $walversion;
# Line 77  my $modifier_rss_description = 'This is Line 50  my $modifier_rss_description = 'This is
50  #  #
51  # You MAY modify following variables.  # You MAY modify following variables.
52  #  #
53    $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
54  my $file_touch = "$modifier_dir_data/touched.txt";  my $file_touch = "$modifier_dir_data/touched.txt";
55  my $file_resource = "$modifier_dir_data/resource.txt";  my $file_resource = "$modifier_dir_data/resource.txt";
56  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
# Line 113  my $RssPage = 'RssPage'; Line 87  my $RssPage = 'RssPage';
87  my $NAME_OF_WikiPageLicense = 'WikiPageLicense';  my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
88  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
89  ##############################  ##############################
 # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b';        # Walrus del (2)  
 my $wiki_name   = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b';        # Walrus add (2)  
90  my $bracket_name = '\[\[(\S+?)\]\]';  my $bracket_name = '\[\[(\S+?)\]\]';
91  my $embedded_name = '\[\[(#\S+?)\]\]';  my $embedded_name = '\[\[(#\S+?)\]\]';
92  my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  my %fmt;        ## formatter objects
 my $interwiki_name = 'i:([^:]+):([^:].*)';  
93  ##############################  ##############################
94  my $embed_comment = '[[#comment]]';  my $embed_comment = '[[#comment]]';
95  my $embed_rcomment = '[[#rcomment]]';  my $embed_rcomment = '[[#rcomment]]';
# Line 127  my $DEFAULT_embed_comment_name = '名無し Line 98  my $DEFAULT_embed_comment_name = '名無し
98  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)
99  my %embed_command = (  my %embed_command = (
100          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
101        form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
102  );  );
103  ##############################  ##############################
104  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
# Line 146  my %fixedpage = ( Line 118  my %fixedpage = (
118      $AdminChangePassword => 1,      $AdminChangePassword => 1,
119      $CompletedSuccessfully => 1,      $CompletedSuccessfully => 1,
120      #$FrontPage => 1,      #$FrontPage => 1,
121        WikiUserAgentList => 1,
122        WikiPluginInfo    => 1,
123  );  );
124  my %form;  my %form;
125  my %database;  my %database;
# Line 161  my %page_command = ( Line 135  my %page_command = (
135      $RssPage => 'rss',      $RssPage => 'rss',
136      $AdminChangePassword => 'adminchangepasswordform',      $AdminChangePassword => 'adminchangepasswordform',
137      #$FrontPage => 'FrontPage',      #$FrontPage => 'FrontPage',
138        WikiPluginInfo       => 'x_WikiPluginInfo',
139  );  );
140  my %command_do = (  my %command_do = (
141      read => \&do_read,      read => \&do_read,
# Line 181  my %command_do = ( Line 156  my %command_do = (
156      rss => \&do_rss,      rss => \&do_rss,
157      diff => \&do_diff,      diff => \&do_diff,
158      interwikibox => \&do_interwiki_box, # Walrus add (5)      interwikibox => \&do_interwiki_box, # Walrus add (5)
159        wikiform => \&do_wikiform,
160        x_WikiPluginInfo  => \&do_wikiplugininfo,
161  );  );
162  ##############################  ##############################
 my @ignore_html_page = ('FrontPage');        # Walrus add (6)  
 my @ignore_html_tags = ('a', 'br', 'img');   # Walrus add (6)  
163  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)
164  ##############################  ##############################
165  # &test_convert;  # &test_convert;
166  &main;  my $UA = '';  ## User agent name
 exit(0);  
167  ##############################  ##############################
168    
169  sub main {  sub main {
170        $UA = $main::ENV{HTTP_USER_AGENT};
171      &init_resource;      &init_resource;
172      &open_db;      &open_db;
173      &init_form;      &init_form;
# Line 208  sub main { Line 183  sub main {
183  sub do_read {  sub do_read {
184    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
185    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = &get_info($form{mypage}, $info_LastModified);
   &print_header($form{mypage}, -last_modified => $lm);  
186    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
187      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
188      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      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
194      ## Should be support at least:      ## Should be support at least:
195      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
196      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
197      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
198      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
199      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
200        &print_content($content, content_format => $cf, last_modified => $lm);        &print_header ($form{mypage}, -last_modified => $lm,
201        print &text_to_html (q([[#comment]]));          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
202          &print_content ($content, content_format => $cf, last_modified => $lm,
203            -toc => \@toc);
204          print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
205      } else {      } else {
206          &print_header($form{mypage}, -last_modified => $lm);
207        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
208      }      }
   my ($r, $c) = get_search_result ($form{mypage});  
209      if ($c) {      if ($c) {
210        print q{<h2 id="SEE-ALSO">See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
211        print $r;        print $r;
212      }      }
213    my $r = wiki::referer::list_html ($form{mypage});      if ($rl) {
214      if ($r) {        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);
       print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$r</div>\n);  
215      }      }
216    &print_footer($form{mypage}, $lm);    &print_footer($form{mypage}, $lm);
217  }  }
# Line 237  sub do_read { Line 219  sub do_read {
219  sub do_output_css {  sub do_output_css {
220    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
221    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
222        my $lm = &get_info($form{mypage}, $info_LastModified);
223          print scalar make_navigate_links ($form{mypage});
224      print "Content-Type: text/css; charset=$charset\n";      print "Content-Type: text/css; charset=$charset\n";
225        print "Last-Modified: $lm\n";
226      print "\n";      print "\n";
227      print $content;      print $content;
228    } else {    } else {
229      print "Status: 406 Unsupported Media Type\n";      print "Status: 406 Unsupported Media Type\n";
230      &print_header('WikiPageIsNotCSS');      &print_header('WikiPageIsNotCSS', -noindex => 1);
231      &print_content($database{WikiPageIsNotCSS});      &print_content($database{WikiPageIsNotCSS});
232      &print_footer('WikiPageIsNotCSS');      &print_footer('WikiPageIsNotCSS');
233    }    }
234  }  }
235    
236    sub id_and_name ($) {
237        my $name = shift;
238        if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
239          qq{id="$name"><a name="$name"></a};
240        } else {
241            qq{id="$name"};
242        }
243    }
244    
245  sub do_edit {  sub do_edit {
246      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
247      &print_header($page);      &print_header($page, -noindex => 1);
248      if (not &is_editable($page)) {      if (not &is_editable($page)) {
249          &print_message($resource{cantchange});          &print_message($resource{cantchange});
250      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
# Line 258  sub do_edit { Line 252  sub do_edit {
252      } else {      } else {
253          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
254      }      }
255        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
256        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
257        my ($r, $c) = get_search_result ($form{mypage});
258        my $rl = wiki::referer::list_html ($form{mypage});
259        if ($c) {
260          print q{<h2 id="wikipage-see-also">See also</h2>};
261          print $r;
262        }
263        if ($rl) {
264          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
265        }
266      &print_footer($page);      &print_footer($page);
267  }  }
268    
269  sub do_adminedit {  sub do_adminedit {
270      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
271      &print_header($page);      &print_header($page, -noindex => 1);
272      if (not &is_editable($page)) {      if (not &is_editable($page)) {
273          &print_message($resource{cantchange});          &print_message($resource{cantchange});
274      } else {      } else {
# Line 274  sub do_adminedit { Line 279  sub do_adminedit {
279  }  }
280    
281  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
282      &print_header($AdminChangePassword);      &print_header($AdminChangePassword, -noindex => 1);
283      &print_passwordform;      &print_passwordform;
284      &print_footer($AdminChangePassword);      &print_footer($AdminChangePassword);
285  }  }
# Line 301  EOD Line 306  EOD
306      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
307      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
308    
309      &print_header($CompletedSuccessfully);      &print_header($CompletedSuccessfully, -noindex => 1);
310      &print_message($resource{passwordchanged});      &print_message($resource{passwordchanged});
311      &print_footer($CompletedSuccessfully);      &print_footer($CompletedSuccessfully);
312  }  }
# Line 326  sub do_write { Line 331  sub do_write {
331      }      }
332    
333      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
334          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
335          &print_message($resource{cantchange});          &print_message($resource{cantchange});
336          &print_footer($form{mypage});          &print_footer($form{mypage});
337          return;          return;
# Line 353  sub do_write { Line 358  sub do_write {
358              &update_recent_changes;              &update_recent_changes;
359          }          }
360          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
361          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{comment_index}?"#x-comment-$form{comment_index}":''));          my $fragment = '';
362            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
363            if ($form{__comment_anchor_index}) {
364                $fragment .= qq(#anchor-$form{__comment_anchor_index});
365            } elsif ($form{__wikiform_anchor_index}) {
366                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
367            }
368            &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
369          &print_message($resource{saved});          &print_message($resource{saved});
370          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
371          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 364  sub do_write { Line 376  sub do_write {
376          if ($form{mytouch}) {          if ($form{mytouch}) {
377              &update_recent_changes;              &update_recent_changes;
378          }          }
379          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
380          &print_message($resource{deleted});          &print_message($resource{deleted});
381          &print_footer($form{mypage});          &print_footer($form{mypage});
382      }      }
# Line 380  sub do_search { Line 392  sub do_search {
392      my $word = $form{mymsg};      my $word = $form{mymsg};
393      &print_header($SearchPage);      &print_header($SearchPage);
394      &print_searchform(&escape($word));      &print_searchform(&escape($word));
395      print scalar get_search_result ($word, -output_not_found => 1);      print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);
396      &print_footer($SearchPage);      &print_footer($SearchPage);
397  }  }
398    
399  sub get_search_result ($;%) {  sub get_search_result ($;%) {
400    my $word = shift;    my $word = lc shift;
401    my %option = @_;    my %option = @_;
402    my $counter = 0;    my @r;
403    my $r = '';    foreach my $page (keys %database) {
404    foreach my $page (sort keys %database) {      next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
     next if $page eq $RecentChanges;  
405      my $content = $database{$page};      my $content = $database{$page};
406      $content =~ s/^\#\?[^\x0A\x0D]+//s;      my $cf = 'SuikaWiki/0.9';
407      if (   index ($content, $word) > 0      $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
408          || index ($page, $word) > 0      next if $cf =~ /obsoleted="yes"/;
409          || index ($word, $page) > 0      if (index (lc $page, $word) > -1) {
410         ) {        my $c = $content =~ s/\Q$word\E//gi;
411        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);        push @r, [$page, $c+20];
412        $counter++;      } elsif (index ($word, lc $page) > -1) {
413          my $c = $content =~ s/\Q$word\E//gi;
414          push @r, [$page, $c+10];
415        } elsif (my $c = $content =~ s/\Q$word\E//gi) {
416          push @r, [$page, $c];
417      }      }
418    }    }
419    $r = qq|<ul>$r</ul>| if $r;    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
420    get_message ($resource{notfound})    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;
421      if $counter == 0 && $option{-output_not_found};    $r = qq|<ul class="search-result">$r</ul>| if $r;
422    wantarray? ($r, $counter): $r;    get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
423      wantarray? ($r, scalar @r): $r;
424  }  }
425    
426  sub do_create {  sub do_create {
# Line 423  EOD Line 439  EOD
439  sub do_random_jump {  sub do_random_jump {
440    my @list = keys %database;    my @list = keys %database;
441    my $name = &encode ($list[rand @list]);    my $name = &encode ($list[rand @list]);
442    print "Location: $url_cgi?$name\n";    my ($scheme) = 'http';
443      $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
444      print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
445    print "\n";    print "\n";
446  }  }
447    
# Line 439  sub do_FrontPage { Line 457  sub do_FrontPage {
457    
458  sub print_error {  sub print_error {
459      my ($msg) = @_;      my ($msg) = @_;
460      &print_header($ErrorPage);      &print_header($ErrorPage, -noindex => 1);
461      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
462      &print_footer($ErrorPage);      &print_footer($ErrorPage);
463      exit(0);      exit(0);
# Line 451  sub print_header ($;%) { Line 469  sub print_header ($;%) {
469      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
470          $bodyclass = "frozen";          $bodyclass = "frozen";
471      }      }
472      print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
473        if ($option{-goto}) {
474          if ($UA =~ m#Opera|MSIE 2\.#) {
475              $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
476              print qq{Refresh: 0; url=$option{-goto}\n};
477              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
478          } else {
479              $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
480              print qq{Refresh: 0; url="$option{-goto}"\n};
481              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
482          }
483        }
484      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
485        my $meta_ct = '';
486        if ($UA =~ m#Mozilla/2#) {
487            $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
488            print qq{Content-Type: $meta_ct\n};
489            $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
490        } elsif ($UA =~ m#Infomosaic#) {
491            print qq{Content-Type: text/html\n};
492        } else {
493            print qq{Content-Type: text/html; charset=$charset\n};
494        }
495      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
496      my $escapedpage = &escape($page);      my $escapedpage = &escape($page);
497        my ($Links, $links) = &make_navigate_links ($page);
498        print $Links;
499      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
500  Content-Language: $lang  Content-Language: $lang
501  Content-Style-Type: text/css  Content-Style-Type: text/css
502    
# Line 465  Content-Style-Type: text/css Line 505  Content-Style-Type: text/css
505      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
506      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
507  <html lang="$lang">  <html lang="$lang">
508  <head>  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
509      <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>      $meta_ct$option{-goto}
510      <link rel="index" href="$url_cgi?$IndexPage">      <title>$escapedpage</title>
511      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">      @{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']}
512      <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
513      <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">  $links
514  </head>  </head>
515  <body class="$bodyclass">  <body class="$bodyclass">
516  EOD  EOD
517    &print_navigate_links ($page);    &print_navigate_links ($page);
518    print <<EOD;    print <<EOD;
519  <h1 class="header">@{[&escape($page)]}  <h1 class="header">@{[&escape($page)]}</h1>
   <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></h1>  
520  EOD  EOD
521  }  }
522    
523    sub x_charset ($) {
524        my $charset = lc shift;
525        if ($charset eq 'euc-jp') {
526            $charset = 'x-euc-jp';
527        } elsif ($charset eq 'shift_jis') {
528            $charset = 'x-sjis';
529        }
530        $charset;
531    }
532    
533  sub print_navigate_links (@) {  sub print_navigate_links (@) {
534    my ($page) = @_;    my ($page) = @_;
535      my $editable = 0;      my $editable = 0;
536      my $admineditable = 0;      my $admineditable = 0;
537      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
538          $editable = 0;          $editable = 0;
539          $admineditable = 1;          #$admineditable = 1;
540      } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {      } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
541          $admineditable = 1;          #$admineditable = 1;
542          $editable = 1;          $editable = 1;
543      } else {      } else {
544          $editable = 0;          $editable = 0;
# Line 502  sub print_navigate_links (@) { Line 551  sub print_navigate_links (@) {
551          : qq()          : qq()
552      ]}      ]}
553      @{[ $editable      @{[ $editable
554          ? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )          ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )
555            qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )
556          : qq()          : qq()
557      ]}      ]}
558        <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">表示</a> |
559      @{[ $admineditable      @{[ $admineditable
560          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
561          : qq()          : qq()
562      ]}      ]}
563      <a href="$url_cgi?$CreatePage">$resource{createbutton}</a> |      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |
564      <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
565      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |
566      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
567      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |
568      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
569  </div>  </div>
570  EOH  EOH
571  }  }
572    
573    sub make_navigate_links ($) {
574        my $page = shift;
575        my @link;
576        push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{editbutton}} if &is_editable ($page) && !&is_frozen ($page);
577        push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{admineditbutton}} if &is_editable ($page) || &is_frozen ($page);
578        push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>'View latest version of this page'};
579        push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};
580        push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};
581        push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};
582        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};
583        push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};
584        push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};
585        push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};
586        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};
587        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};
588        my ($Links, $links) = ('', '');
589        for my $e (@link) {
590            $links .= qq(<link);
591            $Links .= qq(Link: <$e->{href}>);
592            for my $attr (qw/rel rev href title class type hreflang charset/) {
593                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
594            }
595            for my $attr (qw/rel rev title/) {
596                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
597            }
598            $links .= qq(>\n);
599            $Links .= qq(\n);
600        }
601        wantarray ? ($Links, $links) : $Links;
602    }
603    
604  sub print_footer {  sub print_footer {
605      my ($page, $lm) = @_;      my ($page, $lm) = @_;
606        my $epage = &encode ($page);
607      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)
608      # Walrus mod (1) start      # Walrus mod (1) start
609    my $cvslog = '$Revision$ $Date$';    my $cvslog1 = q$Revision$;
610      my $cvslog2 = q$Date$;
611    print_navigate_links ($page);    print_navigate_links ($page);
612    print <<"EOD";    print <<"EOD";
613  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
614  <div class="footer">  <div class="footer">
615  <p>  <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>
616  <a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />  <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>
 based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository">  
 $cvslog  
 </a>  
 </p>  
617  <div class="navigation">  <div class="navigation">
618  [<a href="/" title="このサーバーの首頁">/</a>  [<a href="/" title="このサーバーの首頁">/</a>
619  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
620  <a href="/search/" title="このサーバーの検索">検索</a>]  <a href="/search/" title="このサーバーの検索">検索</a>]
621  </div>  </div>
622    <div class="myuri">
623        &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
624    </div>
625  </div>  </div>
626  $walrus_log  $walrus_log
627  </body>  </body>
628  </html>  </html>
629  EOD  EOD
 #       print <<"EOD";  
 #   <hr>  
 #   <address class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version  
 #       &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 #       Modified by <a href="$modifier_url">$modifier_name</a>.  
 #   </address>  
 #   <p class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">$icontag</a>  
 #   </p>  
 #   </body>  
 #   </html>  
 #   EOD  
     # Walrus mod (1) end  
630  }  }
631    
632  sub escape {  sub escape {
# Line 583  sub unescape { Line 651  sub unescape {
651    
652  sub print_content ($;$) {  sub print_content ($;$) {
653      my ($rawcontent, %option) = @_;      my ($rawcontent, %option) = @_;
654      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
655  }  }
656    
657  sub text_to_html {  sub text_to_html {
658      my ($txt, %option) = @_;      my ($txt, %option) = @_;
659      my (@txt) = split(/\n/, $txt);      my (@txt) = split(/\n/, $txt);
660      my (@toc);      my @toc;
661        my @toc2 = @{$option{-toc}||[]};
662      my $tocnum = 0;      my $tocnum = 0;
663      my (@saved, @result);      my (@saved, @result);
664      unshift(@saved, "</p>");      unshift(@saved, "</p>");
# Line 598  sub text_to_html { Line 667  sub text_to_html {
667          chomp;          chomp;
668          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
669              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
670              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>');
671              $tocnum++;              $tocnum++;
672          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
673              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
674              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>');
675              $tocnum++;              $tocnum++;
676          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
677              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
678              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>');
679              $tocnum++;              $tocnum++;
680          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
681          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
682          # Walrus mod (6) end          # Walrus mod (6) end
683              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
684              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>');
685              $tocnum++;              $tocnum++;
686          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
687              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
688              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>');
689              $tocnum++;              $tocnum++;
690          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
691              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
# Line 632  sub text_to_html { Line 701  sub text_to_html {
701          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
702              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
703              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
704          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
705              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
706                push @result, "<p>";
707              push(@result, &inline($2));              push(@result, &inline($2));
708                unshift @saved, "</p>";
709          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
710              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
711              push(@result, "<p>");              push(@result, "<p>");
712                unshift(@saved, "</p>");
713          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
714              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
715              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
# Line 667  sub text_to_html { Line 738  sub text_to_html {
738              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
739              # XXXXX              # XXXXX
740              #######              #######
741          } elsif (/^\[(INS|DEL|PRE)\[/) {          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
742              push @result, splice (@saved), '<'.lc($1).'>';              push @result, splice (@saved), '<'.lc($1).'>';
743              unshift @saved, "</p>";              unshift @saved, "</p>";
744              push @result, "<p>";              push @result, "<p>";
745          } elsif (/^\](INS|DEL|PRE)\]/) {          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
746              push @result, splice (@saved), '</'.lc($1).'>';              push @result, splice (@saved), '</'.lc($1).'>';
747          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
748            my $num = 0+$1;            my $num = 0+$1;
# Line 688  sub text_to_html { Line 759  sub text_to_html {
759          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
760          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
761          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
762          foreach (@toc) {          foreach (@toc,@toc2) {
763              if (/^(-{1,6})(.*)$/) {              if (/^(-{1,6})(.*)$/) {
764                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
765                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
# Line 698  sub text_to_html { Line 769  sub text_to_html {
769          $toc = join("\n", @tocresult);          $toc = join("\n", @tocresult);
770          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
771      }      }
772      return $toc . join("\n", @result);      $toc .= join("\n", @result);
773        $toc =~ s#<p>\n</p>##g;
774        $toc =~ s#[\x0D\x0A]+</#</#g;
775        $toc =~ s#<pre>\n#<pre>#g;
776        $toc;
777  }  }
778    
779  sub back_push {  sub back_push {
# Line 718  sub back_push { Line 793  sub back_push {
793  sub inline {  sub inline {
794      my ($line) = @_;      my ($line) = @_;
795      $line = &escape($line);      $line = &escape($line);
796      $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2</@{[lc $1]}>:g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
797      $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:<acronym title="$2">$1</acronym>:g;      $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;
798      $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
799      $line =~ s%\[Q\[(.+?)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
800      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $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;
801      $line =~ s|''([^']+?)''|<em>$1</em>|g;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
802      $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g;   # Date      $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;
803      $line =~ s!      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
804        (      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
805          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;      $line =~ s|''([^']+)''|<em>$1</em>|g;
806        |      $line =~ s{
807          (?:$bracket_name))      # [[likethis]], [[#comment]], [[Friend:remotelink]]        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]
808        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]
809        |&gt;&gt;([0-9]+)        |&gt;&gt;([0-9]+)
810      !        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
811        my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);      }{
812          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
813        if ($l) {        if ($l) {
814          &make_link($l)          &make_link($l)
815        } elsif (defined $page) {        } elsif (defined $page) {
816          &make_wikilink ($page, anchor => 0+$anchor);          &make_wikilink ($page, anchor => 0+$anchor);
817        } elsif ($anum) {        } elsif ($anum) {
818          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
819          } elsif ($uri) {
820            &make_urilink ($uri);
821        }        }
822      !gex;      }gex;
823      return $line;      return $line;
824  }  }
825    
# Line 760  sub make_wikilink ($%) { Line 838  sub make_wikilink ($%) {
838    }    }
839  }  }
840    
841    sub make_urilink ($;%) {
842      require URI;
843      my $uri = shift;
844      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
845        $uri = &unescape ($uri);
846        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
847          my ($site, $name) = ($1, $2);
848          for ($site, $name) {
849            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
850          }
851          if ($interwiki{$site}) {
852            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
853            $site = &escape ($site); $name = &escape ($name);
854            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;);
855          } else {
856            qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
857          }
858        } else {
859          qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
860        }
861      } elsif ($uri =~ /^urn:/) {   ## URN
862        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
863        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
864      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
865        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
866        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
867      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
868        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
869        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
870      } else {      ## misc. URI
871        CGI::Carp::warningsToBrowser (0);
872        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
873        CGI::Carp::warningsToBrowser (1);
874        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
875      }
876    }
877    
878    my $FormIndex = 0;
879    sub make_custom_form ($$$$) {
880        my ($wfname, $definition, $template, $option) = @_;
881        ## $template and $option is currently not used in this procedure.
882        unless ($main::_EMBEDED) {
883            $FormIndex++;
884            if (length $definition) {
885                my $param = bless {}, 'SuikaWiki::Plugin';
886                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
887                &load_formatter (qw/form_input form_option/);
888                $definition = &unescape ($definition);
889                $definition =~ s/\\(.)/$1/g;
890                $definition .= ' %submit;' if $definition !~ /%submit/;
891                $option = &unescape ($option);
892                $option =~ s/\\(.)/$1/g;
893                $fmt{form_option}->replace ($option, $param);
894                my $target_page = $param->{output}->{page} || $form{mypage};
895                $param->{form_disabled} = 1 if $fixedpage{$target_page};
896                my $target_form = $param->{output}->{id};
897                my $r = <<EOH;
898    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
899      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
900      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
901      <input type="hidden" name="myLastModified" value="$lastmodified">
902      <input type="hidden" name="mytouch" value="on">
903      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
904    EOH
905                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
906                $r .= $fmt{form_input}->replace ($definition, $param);
907                $r .= <<EOH;
908    </form>
909    EOH
910                $r;
911           } else {  ## No input-interface WikiForm
912               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
913           }
914        } else {
915            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
916        }
917    }
918    
919    ## to be obsoleted
920  sub make_link {  sub make_link {
921      my $chunk = shift;      my $chunk = shift;
922      # Walrus add (3) start      # Walrus add (3) start
923      $chunk =~ s/^&lt;(.*)&gt;$/$1/;      $chunk =~ s/^&lt;(.*)&gt;$/$1/;
924      my $name  = $chunk;      my $name  = $chunk;
     if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {  
         ($name, $chunk) = ($1, $2);  
     } elsif ($chunk =~ /^mailto:(.*)$/) {  
         $name = $1;  
     }  
     if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {  
         $name = qq(<img src="$name">) ;  
     }  
925      $name = &unarmor_name($name);      $name = &unarmor_name($name);
926      # Walrus add (3) end      # Walrus add (3) end
927      if ($chunk =~ /^(http|https|ftp|news):/) {      if ($chunk =~ /^$embedded_name$/) {
         # Walrus mod (3) start  
 #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  
 #           return qq(<a href="$chunk"><img src="$chunk"></a>);  
 #       } else {  
 #           return qq(<a href="$chunk">$chunk</a>);  
 #       }  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);  
         # Walrus mod (3) end  
     } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {  
         return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;  
     } elsif ($chunk =~ /^mailto:(.*)/) {  
 #       return qq(<a href="$chunk">$2</a>);                 # Walrus del (3)  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);              # Walrus add (3)  
     } elsif ($chunk =~ /^$interwiki_definition$/) {  
 #       return qq(<span class="InterWiki">$chunk</span>);   # Walrus del (3)  
         return qq(<span class="InterWiki">$name</span>);    # Walrus add (3)  
     } elsif ($chunk =~ /^$embedded_name$/) {  
928          return &embedded_to_html($chunk);          return &embedded_to_html($chunk);
929      } else {      } else {
930          $chunk = &unarmor_name($chunk);          $chunk = &unarmor_name($chunk);
931          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
932          my $cookedchunk = &encode($chunk);          my $cookedchunk = &encode($chunk);
933          if ($chunk =~ /^$interwiki_name$/) {          if ($database{$chunk}) {
             my ($intername, $localname) = ($1, $2);  
             my $remoteurl = $interwiki{$intername};  
             if ($remoteurl) {  
 #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)  
                 $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)  
 #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  
                 return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)  
             } else {  
 #               return $chunk;                              # Walrus del (3)  
                 return &escape($name);                               # Walrus add (3)  
             }  
         } elsif ($database{$chunk}) {  
934              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
935  #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)  #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)
936              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)
# Line 837  sub init_form { Line 957  sub init_form {
957      if (param()) {      if (param()) {
958          foreach my $var (param()) {          foreach my $var (param()) {
959              $form{$var} = param($var);              $form{$var} = param($var);
960          }        }
     } else {  
         $ENV{QUERY_STRING} = $FrontPage;  
961      }      }
962        $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
963      my $query = &decode($ENV{QUERY_STRING});      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
964      if ($page_command{$query}) {        my $query = &decode($main::ENV{QUERY_STRING});
965          $query = &code_convert(\$query, $kanjicode);
966          if ($page_command{$query}) {
967          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
968          $form{mypage} = $query;          $form{mypage} = $query;
969      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
970          $form{mypage} = $query;          $form{mypage} = $query;
971            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
972          }
973      }      }
974        $form{mypage} ||= 'HomePage';
975        $form{mycmd} ||= 'read';
976    
977      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
978      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 864  sub init_form { Line 984  sub init_form {
984          }          }
985      }      }
986    
987      #      #
988      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
989      #      #
990    
991        for (grep /^wikiform__/, keys %form) {
992            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
993        }
994      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
995      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
996  }  }
# Line 875  sub init_form { Line 998  sub init_form {
998  sub update_recent_changes {  sub update_recent_changes {
999      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
1000      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
1001        shift (@oldupdates); ## '#?' magic line
1002      my @updates;      my @updates;
1003      foreach (@oldupdates) {      foreach (@oldupdates) {
1004          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;
# Line 887  sub update_recent_changes { Line 1011  sub update_recent_changes {
1011        unshift @updates, $update;        unshift @updates, $update;
1012      }      }
1013      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
1014      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
1015      if ($file_touch) {      if ($file_touch) {
1016          open(FILE, "> $file_touch");          open(FILE, "> $file_touch");
1017          print FILE localtime() . "\n";          print FILE localtime() . "\n";
# Line 991  sub print_searchform { Line 1115  sub print_searchform {
1115      my ($word) = @_;      my ($word) = @_;
1116      print <<"EOD";      print <<"EOD";
1117  <form action="$url_cgi" method="get">  <form action="$url_cgi" method="get">
1118      <input type="hidden" name="mycmd" value="search">      <input type="hidden" name="mycmd" value="read">
1119      <input type="text" name="mymsg" value="$word" size="20">      <input type="text" name="mypage" value="$word" size="20">
1120      <input type="submit" value="$resource{searchbutton}">      <input type="submit" value="$resource{searchbutton}">
1121  </form>  </form>
1122  EOD  EOD
# Line 1018  sub print_editform { Line 1142  sub print_editform {
1142      } else {      } else {
1143          $mymsg = &escape($mymsg || $database{NewPageTemplate});          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1144      }      }
1145        my $magic = '';
1146        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
1147    
1148      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1149      my $escapedmypage = &escape($form{mypage});      my $escapedmypage = &escape($form{mypage});
1150      my $escapedmypassword = &escape($form{mypassword});      my $escapedmypassword = &escape($form{mypassword});
1151        my $selected = 'read';
1152        if ($form{after_edit_cmd}) {
1153            $selected = $form{after_edit_cmd};
1154        } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {
1155            $selected = 'edit';
1156        }
1157        my $afteredit = <<EOH;
1158    <select name="after_edit_cmd">
1159    <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>
1160    <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>
1161    </select>
1162    EOH
1163    
1164      print <<"EOD";      print <<"EOD";
1165  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1166      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}  <h2>$escapedmypageの編集</h2>
1167        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}
1168        @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;
1169                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1170                   ++$n}]}]<br>
1171      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1172      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="$escapedmypage">
1173      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
# Line 1041  sub print_editform { Line 1183  sub print_editform {
1183      qq(      qq(
1184          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1185          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1186          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1187           $afteredit
1188           <br>
1189      )      )
1190  ]}  ]}
1191  </form>  </form>
1192  EOD  EOD
1193      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1194          # Show the format rule.          # Show the format rule.
1195          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{'WikiEditHelp'};
1196          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1197          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
1198          close(FILE);      #    open(FILE, $file_format) or &print_error("($file_format)");
1199          print &text_to_html($content, toc=>0);      #    my $content = join('', <FILE>);
1200        #    &code_convert(\$content, $kanjicode);
1201        #    close(FILE);
1202        #    print &text_to_html($content, toc=>0);
1203      }      }
1204  }  }
1205    
# Line 1070  EOD Line 1217  EOD
1217    
1218  sub is_editable {  sub is_editable {
1219      my ($page) = @_;      my ($page) = @_;
1220      if (&is_bracket_name($page)) {      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
         return 0;  
     } elsif ($fixedpage{$page}) {  
         return 0;  
     } elsif ($page =~ /\s/) {  
         return 0;  
     } elsif ($page =~ /^\#/) {  
         return 0;  
     } elsif ($page =~ /^$interwiki_name$/) {  
1221          return 0;          return 0;
1222      } else {      } else {
1223          return 1;          return 1;
# Line 1088  sub is_editable { Line 1227  sub is_editable {
1227  # armor_name:  # armor_name:
1228  #   WikiName -> WikiName  #   WikiName -> WikiName
1229  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1230  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     #if ($name =~ /^$wiki_name$/) {  
     #    return $name;  
     #} else {  
         return "[[$name]]";  
     #}  
 }  
1231    
1232  # unarmor_name:  # unarmor_name:
1233  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
# Line 1109  sub unarmor_name { Line 1241  sub unarmor_name {
1241      }      }
1242  }  }
1243    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1244  sub decode {  sub decode {
1245      my ($s) = @_;      my ($s) = @_;
1246      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1141  sub encode { Line 1264  sub encode {
1264  sub init_resource {  sub init_resource {
1265      open(FILE, $file_resource) or &print_error("(resource)");      open(FILE, $file_resource) or &print_error("(resource)");
1266      while (<FILE>) {      while (<FILE>) {
1267          chomp;          s/[\x0A\x0D]+$//g;
1268          next if /^#/;          next if /^#/;
1269          my ($key, $value) = split(/=/, $_, 2);          my ($key, $value) = split(/=/, $_, 2);
1270          $resource{$key} = &code_convert(\$value, $kanjicode);          $resource{$key} = &code_convert(\$value, $kanjicode);
# Line 1158  sub conflict { Line 1281  sub conflict {
1281      my $content = join('', <FILE>);      my $content = join('', <FILE>);
1282      &code_convert(\$content, $kanjicode);      &code_convert(\$content, $kanjicode);
1283      close(FILE);      close(FILE);
1284      &print_header($page);      &print_header($page, -noindex => 1);
1285      &print_content($content);      &print_content($content);
1286      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1287      &print_footer($page);      &print_footer($page);
# Line 1180  sub get_now { Line 1303  sub get_now {
1303      return "$year-$mon-$day ($weekday) $hour:$min";      return "$year-$mon-$day ($weekday) $hour:$min";
1304  }  }
1305    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1306  sub init_InterWikiName {  sub init_InterWikiName {
1307      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{$InterWikiName};
1308      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1309          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1310          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1311      }      }
1312      }
1313      require Message::Util::Formatter;
1314      $fmt{interwiki} = Message::Util::Formatter->new;
1315      $fmt{interwiki}->{encoded} = sub {
1316        my ($o, $p) = @_;
1317        if ($o->{except}) {
1318          $o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1319        }
1320        my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1321        $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1322        $s;
1323      };
1324      $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
1325        my ($o, $p) = @_;
1326        my $s = $p->{name};
1327        $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1328        &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1329      };
1330  }  }
1331    
 sub interwiki_convert {  
     my ($type, $localname) = @_;  
     if ($type eq 'sjis' or $type eq 'euc') {  
         &code_convert(\$localname, $type);  
         return &encode($localname);  
     } elsif ($type eq 'ykwk') {  
         # for YukiWiki1  
         if ($localname =~ /^$wiki_name$/) {  
             return $localname;  
         } else {  
             &code_convert(\$localname, 'sjis');  
             return &encode("[[" . $localname . "]]");  
         }  
     } elsif ($type eq 'asis') {  
         return $localname;  
     # Walrus add (4) start  
     } elsif ($type eq 'isbn') {  
         $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/);  
         return $localname;  
     # Walrus add (4) end  
     } else {  
         return $localname;  
     }  
 }  
1332    
1333  sub get_info {  sub get_info {
1334      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1267  sub is_frozen { Line 1383  sub is_frozen {
1383    
1384  sub do_comment {  sub do_comment {
1385      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1386      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1387      my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'': ";      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1388      my $anchor = 0;      my $datestr = '[WEAK['.&get_now.']]';
1389      $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1390      $anchor++;      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1391        if ($namestr =~ /^(?:>>)?[0-9]/) {
1392          $namestr = qq( ''$namestr'': );
1393        } elsif (length $namestr) {
1394          $namestr = qq( ''[[$namestr]]'': );
1395        }
1396        my $anchor = &get_new_anchor_index ($content);
1397      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1398      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1399        my $embed = $1;        my $embed = $1;
# Line 1285  sub do_comment { Line 1407  sub do_comment {
1407        $i++; $embed;        $i++; $embed;
1408      }ge;      }ge;
1409      unless ($o) {      unless ($o) {
1410          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1411          $content .= "\n" unless $content =~ /\n$/s;
1412        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1413      }      }
1414      if ($form{mymsg}) {      $form{__comment_anchor_index} = $anchor;
1415        if ($form{mymsg} || $form{myname}) {
1416          $form{mymsg} = $content;          $form{mymsg} = $content;
1417          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1418          &do_write;          &do_write;
# Line 1297  sub do_comment { Line 1422  sub do_comment {
1422      }      }
1423  }  }
1424    
1425    sub get_new_anchor_index ($) {
1426        my $content = shift;
1427        my $anchor = 0;
1428        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1429        $anchor + 1;
1430    }
1431    
1432  my $CommentIndex = 0;  my $CommentIndex = 0;
1433  sub embedded_to_html {  sub embedded_to_html {
1434      my ($embedded) = @_;      my ($embedded) = @_;
# Line 1304  sub embedded_to_html { Line 1436  sub embedded_to_html {
1436        unless ($main::_EMBEDED) {        unless ($main::_EMBEDED) {
1437          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1438          return <<"EOD";          return <<"EOD";
1439  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1440      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1441      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1442      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1443      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1444      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
1445      $embed_comment_Name_Prompt      $embed_comment_Name_Prompt
1446      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10" class="comment-name">
1447      <input type="text" name="mymsg" value="" size="60">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1448      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1449  </form>  </p></form>
1450  EOD  EOD
1451       } else {       } else {
1452          return <<"EOD";          return <<"EOD";
# Line 1329  EOD Line 1461  EOD
1461  EOD  EOD
1462      }      }
1463    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1464      return get_search_result ($1);      return get_search_result ($1, -match_myself => 1);
1465      # Walrus add (5) start      # Walrus add (5) start
1466      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1467          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
# Line 1347  EOD Line 1479  EOD
1479        } elsif (length $content) {        } elsif (length $content) {
1480          $r = "<pre>@{[&escape ($content)]}</pre>";          $r = "<pre>@{[&escape ($content)]}</pre>";
1481        } else {        } else {
1482          $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9');          $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1483        }        }
1484      } else {    ## nested #EMBED      } else {    ## nested #EMBED
1485        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1486      }      }
1487      return qq(<blockquote title="@{[&escape($name)]}">$r</blockquote>);      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>);
1488    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1489      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1490    } else {    } else {
# Line 1360  EOD Line 1492  EOD
1492    }    }
1493  }  }
1494    
1495    sub load_formatter (@) {
1496        for my $t (@_) {
1497            unless ($fmt{$t}) {
1498                $fmt{$t} = Message::Util::Formatter->new;
1499                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1500                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1501                }
1502            }
1503        }
1504    }
1505    
1506    sub do_wikiform {
1507        my $content = $database{$form{mypage}};
1508        my $anchor = &get_new_anchor_index ($content);
1509        &load_formatter (qw/form_template form_option/);
1510        my $write = 0;
1511        my $i = 1;
1512        $content =~ s{$embed_command{form}}{
1513            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1514            if (($wfname && $wfname eq $form{wikiform_targetform})
1515                || $i == $form{wikiform_index}) {
1516                $template =~ s/\\(.)/$1/g;
1517                $option =~ s/\\(.)/$1/g;
1518                my $param = bless {}, 'SuikaWiki::Plugin';
1519                $param->{page} = $form{mypage};
1520                $param->{form_index} = $i;
1521                $param->{form_name} = $wfname;
1522                $param->{anchor_index} = $anchor;
1523                $param->{argv} = \%form;
1524                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1525                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1526                $fmt{form_option}->replace ($option, $param);
1527                my $t = 1;
1528                for (@{$param->{require}||[]}) {
1529                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1530                }
1531                $t = $fmt{form_template}->replace ($template, $param) if $t;
1532                if (length $t) {
1533                    if ($param->{output}->{reverse}) {
1534                        $embed .= "\n" . $t;
1535                    } else {
1536                        $embed = $t . "\n" . $embed;
1537                    }
1538                    $write = 1;
1539                    $form{__comment_anchor_index} = $anchor
1540                      if $param->{anchor_index_};  ## $anchor is used!
1541                }
1542                $form{__wikiform_anchor_index} = $i;
1543                undef $form{wikiform_targetform};  ## make sure never to match
1544                undef $form{wikiform_index};       ## with WikiForm in rest of page
1545            }
1546            $i++; $embed;
1547        }ge;
1548        unless ($write) {
1549          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1550          #$content .= "\n" unless $content =~ /\n$/s;
1551          #
1552        }
1553        if ($write) {
1554            $form{mymsg} = $content;
1555            $form{mytouch} = 'on';
1556            &do_write;
1557        } else {
1558            $form{mycmd} = 'read';
1559            &do_read;
1560        }
1561    }
1562    
1563    
1564  # Walrus add (5) start  # Walrus add (5) start
1565  sub do_interwiki_box {  sub do_interwiki_box {
1566      my $remoteurl = $interwiki{$form{'myintername'}};      my $remoteurl = $interwiki{$form{'myintername'}};
# Line 1397  EOD Line 1598  EOD
1598    
1599  sub code_convert {  sub code_convert {
1600      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1601  #   &Jcode::convert($contentref, $code);       # for Jcode.pm      $code = 'jis' if $code =~ /iso/;
1602      &jcode::convert($contentref, $code);       # for jcode.pl      $code = 'euc' if $code =~ /euc/;
1603        $code = 'sjis' if $code =~ /shift/;
1604        $code = 'utf8' if $code =~ /utf/;
1605        &Jcode::convert($contentref, $code);       # for Jcode.pm
1606    #    &jcode::convert($contentref, $code);       # for jcode.pl
1607        &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';
1608      return $$contentref;      return $$contentref;
1609  }  }
1610    
# Line 1472  sub do_diff { Line 1678  sub do_diff {
1678      }      }
1679      &open_diff;      &open_diff;
1680      my $title = $form{mypage};      my $title = $form{mypage};
1681      &print_header($title);      &print_header($title, -noindex => 1);
1682      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1683      &close_diff;      &close_diff;
1684      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>$resource{difftitle}</h3>);
# Line 1521  sub do_rss { Line 1727  sub do_rss {
1727          $count++;          $count++;
1728      }      }
1729      # print RSS information (as XML).      # print RSS information (as XML).
1730    print scalar &make_navigate_links ('RssPage');
1731      print <<"EOD"      print <<"EOD"
1732  Content-type: text/xml  Content-type: application/xml
1733    
1734  @{[$rss->as_string]}  @{[$rss->as_string]}
1735  EOD  EOD
# Line 1538  sub is_exist_page { Line 1745  sub is_exist_page {
1745  }  }
1746    
1747  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1748    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1749    
1750    sub do_wikiplugininfo {
1751        &print_header (q(WikiPluginInfo));
1752        print text_to_html (&SuikaWiki::Plugin::make_info_page);
1753        &print_footer (q(WikiPluginInfo));
1754    }
1755    
1756  package wiki::referer;  package wiki::referer;
1757  sub add ($$) {  sub add ($$) {
# Line 1604  sub list_html ($) { Line 1818  sub list_html ($) {
1818      }      }
1819      my $euri = main::escape ($uri);      my $euri = main::escape ($uri);
1820      if ($title) {      if ($title) {
1821        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1822      } else {      } else {
1823        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1824      }      }
# Line 1619  sub __decode ($) { Line 1833  sub __decode ($) {
1833    main::code_convert (\$s);    main::code_convert (\$s);
1834  }  }
1835    
1836    package wiki::useragent;
1837    
1838    sub add ($) {
1839      my $s = shift;
1840      return unless length $s;
1841      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1842      my %ua;
1843      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1844        if (/^-\[(\d+)\] (.+)$/) {
1845          my ($t, $n) = ($1, $2);
1846          $n =~ tr/\x0A\x0D//d;
1847          $ua{$n} = $t;
1848        }
1849      }
1850      $ua{$s}++;
1851      my $s = qq(#?SuikaWiki/0.9\n);
1852      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1853        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1854      }
1855      &main::__set_database ('WikiUserAgentList' => $s);
1856    }
1857    
1858    package SuikaWiki::Plugin;
1859      our $plugin_directory;  # defined in top of this file.
1860      our %List;
1861    
1862    sub escape ($$) { main::escape ($_[1]) }
1863    sub unescape ($$) { main::unescape ($_[1]) }
1864    sub encode ($$) { main::encode ($_[1]) }
1865    sub decode ($$) { main::decode ($_[1]) }
1866    sub __get_datetime ($) { main::get_now () }
1867    
1868    sub regist ($@) {
1869        my $pack = shift;
1870        for (@_) {
1871            push @{$List{$_}}, $pack;
1872        }
1873    }
1874    
1875    sub import_plugins () {
1876        opendir PDIR, $plugin_directory;
1877        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1878        closedir PDIR;
1879        for (@plugin) {
1880            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1881            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1882        }
1883    }
1884    
1885    sub make_info_page () {
1886        my $r = <<EOH;
1887    EOH
1888        unless ($List{_all}) {
1889            $r .= qq('''No plugin is installed!'''\n);
1890        } else {
1891            my $index = 0;
1892            for my $package (sort @{$List{_all}}) {
1893                $index++;
1894                my $prop = $package->property ();
1895                $r .= <<EOH;
1896    *$package
1897    
1898    [$index] '''$prop->{name}''' (Version $prop->{version})
1899    <$prop->{uri}>
1900    
1901    Provide:
1902    @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1903        $t .= qq(-''$f''\n);
1904        for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1905             $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1906        }
1907    }$t}]}
1908    
1909    EOH
1910            }
1911        }
1912        $r;
1913    }
1914    
1915    &import_plugins ();
1916    
1917    package main;
1918    &main;
1919    exit 0;
1920    
1921  1;  1;
1922  __END__  __END__
1923  =head1 NAME  =head1 NAME

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.36

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24