/[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.38 by wakaba, Sun Dec 15 06:08:33 2002 UTC revision 1.48 by w, Fri Jan 3 08:25:31 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #  
2  # wiki.cgi - This is YukiWiki, yet another Wiki clone.  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
3  #  #
 # Copyright (C) 2000-2002 by Hiroshi Yuki.  
 # <hyuki@hyuki.com>  
 # http://www.hyuki.com/yukiwiki/  
 #  
4  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
5  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
 #  
 # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.  
   
 # Walrus add (debug) start  
 my $walrus_log;  
 my $walrus_debugging = 0;  
 # Walrus add (debug) end  
6    
 # Libraries.  
7  use strict;  use strict;
8  use lib qw(./WalWiki/lib);  use lib qw(./lib);
 use CGI qw(:standard);  
9  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
10  use Yuki::RSS;  our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11  use Yuki::DiffText qw(difftext);  
12  use Yuki::YukiWikiDB;  require 'wikidata/suikawiki-config.ph';
 use AnyDBM_File;  
 require 'jcode.pl';  
 require Jcode;  
13  use Fcntl;  use Fcntl;
 my $version = '2.0.beta1.2002-05-29';  
 my $walversion;  
 ##############################  
 #  
 # You MUST modify following '$modifier_...' variables.  
 #  
 my $modifier_mail = 'w@suika.fam.cx';   # Your mail address, like 'walrus@digit.que.ne.jp'.  
 my $modifier_url  = 'http://suika.fam.cx/~wakaba/';     # Your web page, like 'http://digit.que.ne.jp/work/'.  
 my $modifier_name = '和';       # Your name, like 'Makio Tsukamoto'.  
 # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.  
 # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.  
 my $modifier_dbtype = 'YukiWikiDB';     # Slow, available on all environment.  
 # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.  
 my $modifier_sendmail = ''; # If you don't need mail notification.  
 my $modifier_dir_data = './wikidata'; # Your data directory.  
 my $modifier_rss_title = "SuikaWiki $walversion";  
 my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.  
 my $modifier_rss_description = 'This is SuikaWiki';  
 ##############################  
 #  
 # You MAY modify following variables.  
 #  
 $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);  
 my $file_touch = "$modifier_dir_data/touched.txt";  
 my $file_resource = "$modifier_dir_data/resource.txt";  
 my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  
 my $file_conflict = "$modifier_dir_data/conflict.txt";  
 my $file_format = "$modifier_dir_data/format.txt";  
 my $url_cgi = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'  
 my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';  
 my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';  
 my $maxrecent = 50;  
 my $cols = 80;  
 my $rows = 20;  
 ##############################  
 #  
 # You MAY, but do NOT NEED modify following variables.  
 #  
 my $dataname = "$modifier_dir_data/wiki";  
 my $infoname = "$modifier_dir_data/info";  
 my $diffname = "$modifier_dir_data/diff";  
 my $editchar = '?';  
 my $subject_delimiter = ' - ';  
 my $use_autoimg = 1; # automatically convert image URL into <img> tag.  
 my $use_exists = 0; # If you can use 'exists' method for your DB.  
 ##############################  
 my $InterWikiName = 'InterWikiName';  
 my $RecentChanges = 'RecentChanges';  
 my $AdminChangePassword = 'AdminChangePassword';  
 my $CompletedSuccessfully = 'CompletedSuccessfully';  
 my $FrontPage = 'HomePage';  
 my $IndexPage = 'IndexPage';  
 my $SearchPage = 'SearchPage';  
 my $CreatePage = 'CreatePage';  
 my $ErrorPage = 'ErrorPage';  
 my $RssPage = 'RssPage';  
 my $NAME_OF_WikiPageLicense = 'WikiPageLicense';  
 my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  
14  ##############################  ##############################
 my $bracket_name = '\[\[(\S+?)\]\]';  
 my $embedded_name = '\[\[(#\S+?)\]\]';  
15  my %fmt;        ## formatter objects  my %fmt;        ## formatter objects
 ##############################  
 my $embed_comment = '[[#comment]]';  
 my $embed_rcomment = '[[#rcomment]]';  
 my $embed_comment_Name_Prompt = '名前:';  
 my $DEFAULT_embed_comment_name = '名無しさん';  
 my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  
16  my %embed_command = (  my %embed_command = (
17          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
18      form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,          form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19  );  );
20    our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21    our (%PageName,$kanjicode,$lang,%ViewDefinition);
22    
23  ##############################  ##############################
 my $info_LastModified = 'LastModified';  
 my $info_IsFrozen = 'IsFrozen';  
 my $info_AdminPassword = 'AdminPassword';  
 ##############################  
 my $kanjicode = 'euc';  
 my $charset = 'EUC-JP';  
 my $lang = 'ja';  
 my %fixedpage = (  
     $IndexPage => 1,  
     $CreatePage => 1,  
     $ErrorPage => 1,  
     $RssPage => 1,  
     $RecentChanges => 1,  
     $SearchPage => 1,  
     $AdminChangePassword => 1,  
     $CompletedSuccessfully => 1,  
     #$FrontPage => 1,  
     WikiUserAgentList => 1,  
     WikiPluginInfo    => 1,  
 );  
24  my %form;  my %form;
25  my %database;  our %database;
26  my %infobase;  our $database = bless {}, 'wiki::dummy';
 my %diffbase;  
 my %resource;  
27  my %interwiki;  my %interwiki;
28  ##############################  ##############################
29  my %page_command = (  my %page_command = (
30      $IndexPage => 'index',      $PageName{RssPage} => 'rss',
     $SearchPage => 'searchform',  
     $CreatePage => 'create',  
     $RssPage => 'rss',  
     $AdminChangePassword => 'adminchangepasswordform',  
     #$FrontPage => 'FrontPage',  
     WikiPluginInfo       => 'x_WikiPluginInfo',  
31  );  );
32  my %command_do = (  my %command_do = (
33      read => \&do_read,      read => \&do_read,
34      TEXT_CSS => \&do_output_css,      TEXT_CSS => \&do_output_css,
35      edit => \&do_edit,      edit => \&do_view,
     adminedit => \&do_adminedit,  
     adminchangepasswordform => \&do_adminchangepasswordform,  
36      adminchangepassword => \&do_adminchangepassword,      adminchangepassword => \&do_adminchangepassword,
37      write => \&do_write,      write => \&do_write,
     index => \&do_index,  
38      searchform => \&do_searchform,      searchform => \&do_searchform,
     search => \&do_search,  
     create => \&do_create,  
     createresult => \&do_createresult,  
     FrontPage => \&do_FrontPage,  
39      comment => \&do_comment,      comment => \&do_comment,
40      RandomJump  => \&do_random_jump,      RandomJump  => \&do_random_jump,
41      rss => \&do_rss,      rss => \&do_rss,
42      diff => \&do_diff,      diff => \&do_diff,
43      interwikibox => \&do_interwiki_box, # Walrus add (5)      wikiform    => \&do_wikiform,
44      wikiform => \&do_wikiform,      map => \&do_view,
     x_WikiPluginInfo  => \&do_wikiplugininfo,  
45  );  );
 ##############################  
 my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  
 ##############################  
 # &test_convert;  
46  my $UA = '';  ## User agent name  my $UA = '';  ## User agent name
47    $| = 1;
48  ##############################  ##############################
49    
50  sub main {  sub main {
51      $UA = $main::ENV{HTTP_USER_AGENT};      $UA = $main::ENV{HTTP_USER_AGENT};
     &init_resource;  
52      &open_db;      &open_db;
53      &init_form;      &init_form;
     &init_InterWikiName;  
54      if ($command_do{$form{mycmd}}) {      if ($command_do{$form{mycmd}}) {
55          &{$command_do{$form{mycmd}}};          &{$command_do{$form{mycmd}}};
56      } else {      } else {
57          &do_FrontPage;          &{$command_do{read}};
58      }      }
59      &close_db;      &close_db;
60  }  }
61    
62  sub do_read {  sub do_read {
63    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
64    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = $database->mtime ($form{mypage});
65    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
66    wiki::useragent::add ($ENV{HTTP_USER_AGENT});    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
   my ($r, $c) = get_search_result ($form{mypage});  
   my $rl = wiki::referer::list_html ($form{mypage});  
67    my @toc;    my @toc;
   push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;  
   push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl;  
68      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
69      ## Should be support at least:      ## Should be support at least:
70      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
# Line 197  sub do_read { Line 72  sub do_read {
72      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
73      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\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;
74      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
75        &print_header ($form{mypage}, -last_modified => $lm,        my $expires = time;
76          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);        if ($cf =~ /interactive="yes"/) {
77            $lm = $expires;
78          } else {
79            $expires += 120;
80          }
81          &print_header ($form{mypage}, -last_modified => $lm, -expires => $expires,
82            -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
83        &print_content ($content, content_format => $cf, last_modified => $lm,        &print_content ($content, content_format => $cf, last_modified => $lm,
84          -toc => \@toc);          -toc => \@toc);
85        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$database->meta (IsFrozen => $form{mypage});
86      } else {      } else {
87        &print_header($form{mypage}, -last_modified => $lm);        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
88        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
89      }      }
90      if ($c) {      &load_formatter ('view');
91        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};      print $fmt{view}->replace ($ViewDefinition{read} => bless {param => \%form, page => $form{mypage}, toc => \@toc, formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
92        print $r;      &print_footer ($form{mypage}, $lm);
     }  
     if ($rl) {  
       print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);  
     }  
   &print_footer($form{mypage}, $lm);  
93  }  }
94    
95  sub do_output_css {  sub do_output_css {
# Line 221  sub do_output_css { Line 97  sub do_output_css {
97    wiki::useragent::add ($ENV{HTTP_USER_AGENT});    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
98    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
99    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
100      my $lm = &get_info($form{mypage}, $info_LastModified);      my $lm = gmtime $database->mtime ($form{mypage});
101        print scalar make_navigate_links ($form{mypage});      print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
     print "Content-Type: text/css; charset=$charset\n";  
102      print "Last-Modified: $lm\n";      print "Last-Modified: $lm\n";
103        print "Expires: @{[scalar gmtime time+3600]}\n";    ## TODO: don't use asctime
104      print "\n";      print "\n";
105      print $content;      print $content;
106    } else {    } else {
# Line 244  sub id_and_name ($) { Line 120  sub id_and_name ($) {
120      }      }
121  }  }
122    
123  sub do_edit {  sub do_view {
     my ($page) = &unarmor_name(&armor_name($form{mypage}));  
     &print_header($page, -noindex => 1);  
     if (not &is_editable($page)) {  
         &print_message($resource{cantchange});  
     } elsif (&is_frozen($page)) {  
         &print_message($resource{cantchange});  
     } else {  
         &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);  
     }  
124      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
125      wiki::useragent::add ($ENV{HTTP_USER_AGENT});      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
126      my ($r, $c) = get_search_result ($form{mypage});      &print_header($form{mypage}, -noindex => 1, -expires => time+60);
127      my $rl = wiki::referer::list_html ($form{mypage});      &load_formatter ('view');
128      if ($c) {      my $view = $form{mycmd};
129        print q{<h2 id="wikipage-see-also">See also</h2>};      if ($view eq 'edit') {
130        print $r;        $view = 'adminedit' if $form{admin};
131      }      } elsif ($view =~ /[^0-9A-Za-z]/) {
132      if ($rl) {        $view = 'view'
       print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);  
     }  
     &print_footer($page);  
 }  
   
 sub do_adminedit {  
     my ($page) = &unarmor_name(&armor_name($form{mypage}));  
     &print_header($page, -noindex => 1);  
     if (not &is_editable($page)) {  
         &print_message($resource{cantchange});  
     } else {  
         &print_message($resource{passwordneeded});  
         &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);  
133      }      }
134      &print_footer($page);      print $fmt{view}->replace ($ViewDefinition{$view} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
135  }      &print_footer($form{mypage});
   
 sub do_adminchangepasswordform {  
     &print_header($AdminChangePassword, -noindex => 1);  
     &print_passwordform;  
     &print_footer($AdminChangePassword);  
136  }  }
137    
138  sub do_adminchangepassword {  sub do_adminchangepassword {
139      if ($form{mynewpassword} ne $form{mynewpassword2}) {      if ($form{mynewpassword} ne $form{mynewpassword2}) {
140          &print_error($resource{passwordmismatcherror});          &print_error(&Resource('Error:PasswordMismatch'));
141      }      }
142      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
143      if ($validpassword_crypt) {      if ($validpassword_crypt) {
144          if (not &valid_password($form{myoldpassword})) {          if (not &valid_password($form{myoldpassword})) {
145              &send_mail_to_admin(<<"EOD", "AdminChangePassword");              &print_error(&Resource('Error:PasswordIsIncorrect'));
 myoldpassword=$form{myoldpassword}  
 mynewpassword=$form{mynewpassword}  
 mynewpassword2=$form{mynewpassword2}  
 EOD  
             &print_error($resource{passworderror});  
146          }          }
147      }      }
148      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
# Line 306  EOD Line 150  EOD
150      my $salt1 = $token[(time | $$) % scalar(@token)];      my $salt1 = $token[(time | $$) % scalar(@token)];
151      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
152      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
153      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      $database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted);
154    
155      &print_header($CompletedSuccessfully, -noindex => 1);      &print_header('CompletedSuccessfully', -noindex => 1);
156      &print_message($resource{passwordchanged});      &print_message(&Resource('Error:PasswordIsChanged'));
157      &print_footer($CompletedSuccessfully);      &print_footer('CompletedSuccessfully');
158  }  }
159    
160  sub do_index {  sub valid_password ($) {
161    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});      my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
162    wiki::useragent::add ($ENV{HTTP_USER_AGENT});      return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
     &print_header($IndexPage);  
     print qq(<ul>);  
     foreach my $page (sort keys %database) {  
         if (&is_editable($page)) {  
             print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);  
             # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);  
             # print qq(<li>@{[0 + &is_frozen($page)]}</li>);  
         }  
     }  
     print qq(</ul>);  
     my ($r, $c) = get_search_result ($form{mypage});  
     if ($c) {  
       print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};  
       print $r;  
     }  
     my $rl = wiki::referer::list_html ($form{mypage});  
     if ($rl) {  
         print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>??????</h2>\n$rl</div>\n);  
     }  
     &print_footer($IndexPage);  
163  }  }
164    
165  sub do_write {  sub do_write {
# Line 345  sub do_write { Line 169  sub do_write {
169    
170      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
171          &print_header($form{mypage}, -noindex => 1);          &print_header($form{mypage}, -noindex => 1);
172          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
173          &print_footer($form{mypage});          &print_footer($form{mypage});
174          return;          return;
175      }      }
176    
177      if (&conflict($form{mypage}, $form{mymsg})) {      ## Check confliction
178          return;      if ($form{myLastModified} ne $database->mtime ($page)) {
179      }        &print_header($page, -noindex => 1);
180          &load_formatter ('view');
181      # Making diff        print $fmt{view}->replace ($ViewDefinition{-conflict} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
182      {        &print_footer($page);
183          &open_diff;        return;
         my @msg1 = split(/\n/, $database{$form{mypage}});  
         my @msg2 = split(/\n/, $form{mymsg});  
         $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);  
         &close_diff;  
184      }      }
185    
186      if ($form{mymsg}) {      if ($form{mymsg}) {
187          $database{$form{mypage}} = $form{mymsg};          if ($form{mytouch} || !ref $database) {
188          &send_mail_to_admin($form{mypage}, "Modify");            $database{$form{mypage}} = $form{mymsg};
189          if ($form{mytouch}) {          } else {
190              &set_info($form{mypage}, $info_LastModified, '' . localtime);            $database->STORE ($form{mypage} => $form{mymsg}, -touch => 0);
             &update_recent_changes;  
191          }          }
192          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          $database->meta (IsFrozen => $form{mypage} => 0 + $form{myfrozen});
193          my $fragment = '';          my $fragment = '';
194          $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};          $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
195          if ($form{__comment_anchor_index}) {          if ($form{__comment_anchor_index}) {
# Line 378  sub do_write { Line 197  sub do_write {
197          } elsif ($form{__wikiform_anchor_index}) {          } elsif ($form{__wikiform_anchor_index}) {
198              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
199          }          }
200          &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));          &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));
201          &print_message($resource{saved});          &print_message(&Resource('Error:SavedSuccessfully'));
202          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
203          &print_footer($CompletedSuccessfully);          &print_footer('CompletedSuccessfully');
204      } else {      } else {
         &send_mail_to_admin($form{mypage}, "Delete");  
205          delete $database{$form{mypage}};          delete $database{$form{mypage}};
         delete $infobase{$form{mypage}};  
         if ($form{mytouch}) {  
             &update_recent_changes;  
         }  
206          &print_header($form{mypage}, -noindex => 1);          &print_header($form{mypage}, -noindex => 1);
207          &print_message($resource{deleted});          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
208          &print_footer($form{mypage});          &print_footer($form{mypage});
209      }      }
210  }  }
211    
212  sub do_searchform {  sub _compatible_options () {
213      &print_header($SearchPage);    (use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0));
     &print_searchform("");  
     &print_footer($SearchPage);  
 }  
   
 sub do_search {  
     my $word = $form{mymsg};  
     &print_header($SearchPage);  
     &print_searchform(&escape($word));  
     print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);  
     &print_footer($SearchPage);  
214  }  }
215    
216  sub get_search_result ($;%) {  sub get_search_result ($;%) {
# Line 414  sub get_search_result ($;%) { Line 218  sub get_search_result ($;%) {
218    my %option = @_;    my %option = @_;
219    my @r;    my @r;
220    foreach my $page (keys %database) {    foreach my $page (keys %database) {
221      next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});      next if !$option{-match_myself} && ($page eq $word);
222      my $content = $database{$page};      my $content = lc $database{$page};
     my $cf = 'SuikaWiki/0.9';  
     $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;  
     next if $cf =~ /obsoleted="yes"/;  
223      if (index (lc $page, $word) > -1) {      if (index (lc $page, $word) > -1) {
224        my $c = $content =~ s/\Q$word\E//gi;        my $c = $content =~ s/\Q$word\E//g;
225        push @r, [$page, $c+20];        push @r, [$page, $c+20];
226      } elsif (index ($word, lc $page) > -1) {      } elsif (index ($word, lc $page) > -1) {
227        my $c = $content =~ s/\Q$word\E//gi;        my $c = $content =~ s/\Q$word\E//g;
228        push @r, [$page, $c+10];        push @r, [$page, $c+10];
229      } elsif (my $c = $content =~ s/\Q$word\E//gi) {      } elsif (my $c = $content =~ s/\Q$word\E//g) {
230        push @r, [$page, $c];        push @r, [$page, $c];
231      }      }
232    }    }
233    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
234    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;    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
235    $r = qq|<ul class="search-result">$r</ul>| if $r;    $r = qq|<ul class="search-result">$r</ul>| if $r;
   get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};  
236    wantarray? ($r, scalar @r): $r;    wantarray? ($r, scalar @r): $r;
237  }  }
238    
 sub do_create {  
     &print_header($CreatePage);  
     print <<"EOD";  
 <form action="$url_cgi" method="post">  
     <input type="hidden" name="mycmd" value="edit">  
     <strong>$resource{newpagename}</strong><br>  
     <input type="text" name="mypage" value="" size="20">  
     <input type="submit" value="$resource{createbutton}"><br>  
 </form>  
 EOD  
     &print_footer($CreatePage);  
 }  
   
239  sub do_random_jump {  sub do_random_jump {
240    my @list = keys %database;    my @list = keys %database;
241    my $name = &encode ($list[rand @list]);    my $name = &encode ($list[rand @list]);
242    my ($scheme) = 'http';    my $scheme = 'http';
243    $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;    $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
244    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
245    print "\n";    print "\n";
246  }  }
247    
 sub do_FrontPage {  
     open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");  
     my $content = join('', <FILE>);  
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
     &print_header($FrontPage);  
     &print_content($content);  
     &print_footer($FrontPage);  
 }  
   
248  sub print_error {  sub print_error {
249      my ($msg) = @_;      my ($msg) = @_;
250      &print_header($ErrorPage, -noindex => 1);      &print_header($PageName{ErrorPage}, -noindex => 1);
251      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
252      &print_footer($ErrorPage);      &print_footer($PageName{ErrorPage});
253      exit(0);      exit(0);
254  }  }
255    
256  sub print_header ($;%) {  sub print_header ($;%) {
257      my ($page, %option) = @_;      my ($page, %option) = @_;
258      my $bodyclass = "normal";      my @head;
259      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
260          $bodyclass = "frozen";      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
     }  
     $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;  
261      if ($option{-goto}) {      if ($option{-goto}) {
262        if ($UA =~ m#Opera|MSIE 2\.#) {        if ($UA =~ m#Opera|MSIE 2\.#) {
263              ## WARNING: This code may output unsafe HTML document if
264              ##          $option{-goto} is not clean.
265            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
266            print qq{Refresh: 0; url=$option{-goto}\n};            print qq{Refresh: 0; url=$option{-goto}\n};
267            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);            push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
268        } else {        } else {
269            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
270            print qq{Refresh: 0; url="$option{-goto}"\n};            print qq{Refresh: 0; url="$option{-goto}"\n};
271            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);            push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
272        }        }
273      }      }
274      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};      print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
275      my $meta_ct = '';      if ($option{-expires}) {
276          print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
277        }
278      if ($UA =~ m#Mozilla/2#) {      if ($UA =~ m#Mozilla/2#) {
279          $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};          my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
280          print qq{Content-Type: $meta_ct\n};          print qq{Content-Type: $ct\n};
281          $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};          push @head, qq{<meta http-equiv="content-type" content="$ct">};
282      } elsif ($UA =~ m#Infomosaic#) {      } elsif ($UA =~ m#Infomosaic#) {
283          print qq{Content-Type: text/html\n};          print qq{Content-Type: text/html\n};
284      } else {      } else {
285          print qq{Content-Type: text/html; charset=$charset\n};          print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
286      }      }
287      my $cookedpage = &encode($page);      push @head, qq(<title>@{[&escape($page)]}</title>);
288      my $escapedpage = &escape($page);      if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) {
289          push @head, qq(<link rel="stylesheet" type="text/css").
290                      qq( href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.$database->mtime ($PageName{DefaultStyleForHTML}))]}");
291        }
292        push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
293      my ($Links, $links) = &make_navigate_links ($page);      my ($Links, $links) = &make_navigate_links ($page);
294      print $Links;      #print $Links;      ## Link: fields
295        $links = join "\n", (@head, $links);
296      print <<"EOD";      print <<"EOD";
297  Content-Language: $lang  Content-Language: $lang
298  Content-Style-Type: text/css  Content-Style-Type: text/css
299    
300  <!--  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
301  <!DOCTYPE html  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
302      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  <html lang="$lang" class="$option{body_class}">
     "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->  
 <html lang="$lang">  
303  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
     $meta_ct$option{-goto}  
     <title>$escapedpage</title>  
     @{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']}  
     @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}  
304  $links  $links
305  </head>  </head>
306  <body class="$bodyclass">  <body class="$option{body_class}">
307  EOD  EOD
308    &print_navigate_links ($page);      &print_navigate_links ($page);
309    print <<EOD;      print <<EOD;
310  <h1 class="header">@{[&escape($page)]}</h1>  <h1 class="header">@{[&escape($page)]}</h1>
311  EOD  EOD
312  }  }
313    
314  sub x_charset ($) {  sub get_charset_name ($;%) {
315      my $charset = lc shift;      my ($charset, %option) = (lc shift, @_);
316      if ($charset eq 'euc-jp') {      if ($charset =~ 'euc') {
317          $charset = 'x-euc-jp';          $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
318      } elsif ($charset eq 'shift_jis') {      } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
319          $charset = 'x-sjis';          $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
320        } elsif ($charset =~ 'jis') {
321            $charset = 'iso-2022-jp';
322      }      }
323      $charset;      $charset;
324  }  }
325    
326  sub print_navigate_links (@) {  sub print_navigate_links (@) {
327    my ($page) = @_;    my ($page) = @_;
328      my $editable = 0;    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
329      my $admineditable = 0;    my $cookedpage = &encode($page);
     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $editable = 0;  
         #$admineditable = 1;  
     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {  
         #$admineditable = 1;  
         $editable = 1;  
     } else {  
         $editable = 0;  
     }  
     my $cookedpage = &encode($page);  
330    print <<EOH;    print <<EOH;
331  <div class="tools">  <div class="tools">
     @{[ $admineditable  
         ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage" class="wiki-cmd">$resource{admineditbutton}</a> | )  
         : qq()  
     ]}  
332      @{[ $editable      @{[ $editable
333          ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )          ? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | )
         qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">編集</a> | )  
         : qq()  
     ]}  
     <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd">表示</a> |  
     @{[ $admineditable  
         ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage" class="wiki-cmd">$resource{diffbutton}</a> | )  
334          : qq()          : qq()
335      ]}      ]}
336      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |      <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd" title="@{[&Resource('ViewThisPageLong',escape=>1)]}">@{[&Resource('ViewThisPage',escape=>1)]}</a> |
337      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |      <a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
338      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |      <a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
339      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |      <a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
340      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |      <a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
341      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>      <a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
342        <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink" title="@{[&Resource('GoSomewhereLong',escape=>1)]}">@{[&Resource('GoSomewhere',escape=>1)]}</a> |
343        <a href="$url_cgi?$PageName{RecentChanges}" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
344  </div>  </div>
345  EOH  EOH
346  }  }
# Line 586  EOH Line 348  EOH
348  sub make_navigate_links ($) {  sub make_navigate_links ($) {
349      my $page = shift;      my $page = shift;
350      my @link;      my @link;
351      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);      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page);
352      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);      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;admin=1;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);
353      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'};      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')};
354      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
355      push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};      push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
356      push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};      push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')};
357      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
358      push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};      push @link, {rel=>'News', href=>"$url_cgi?$PageName{RecentChanges}", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
359      push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};      push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
360      push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};      push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
361      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
362      push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};      push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
363      push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to...'};      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToLink')};
364      push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to (edit)...'};      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToEditLink')};
365      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>'Somewhere'};      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
366        push @link, {rel=>'history', href=>$uri{cvs_wikipage}.do{my $s=$page;$s=~s/(.)/sprintf '%02X', ord $1/ges;$s}.'.txt', title=>&Resource('ViewHistoryOfThisPageLink'),hreflang=>'en'} if $uri{cvs_wikipage};
367        push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'} if $wiki::diff::UseDiff;
368        push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
369      my ($Links, $links) = ('', '');      my ($Links, $links) = ('', '');
370      for my $e (@link) {      for my $e (@link) {
371          $links .= qq(<link);          $links .= qq(<link);
# Line 620  sub make_navigate_links ($) { Line 385  sub make_navigate_links ($) {
385  sub print_footer {  sub print_footer {
386      my ($page, $lm) = @_;      my ($page, $lm) = @_;
387      my $epage = &encode ($page);      my $epage = &encode ($page);
     $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)  
     # Walrus mod (1) start  
388    my $cvslog1 = q$Revision$;    my $cvslog1 = q$Revision$;
389    my $cvslog2 = q$Date$;    my $cvslog2 = q$Date$;
390    print_navigate_links ($page);    print_navigate_links ($page);
391    print <<"EOD";    print <<"EOD";
392  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
393  <div class="footer">  <div class="footer">
394  <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>  <a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 &copy; 2000-2002 by Hiroshi Yuki">@{[&Resource('About:Name:YukiWiki',escape=>1)]}</a> <a href="http://digit.que.ne.jp/work/" title="WalWiki 2.0.beta1.wal.1 &copy; 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a>
395  <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>  <a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
 <div class="navigation">  
 [<a href="/" title="このサーバーの首頁">/</a>  
 <a href="/map" title="このサーバーの案内">地図</a>  
 <a href="/search/" title="このサーバーの検索">検索</a>]  
396  </div>  </div>
 <div class="myuri">  
     &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;  
 </div>  
 </div>  
 $walrus_log  
397  </body>  </body>
398  </html>  </html>
399  EOD  EOD
# Line 647  EOD Line 401  EOD
401    
402  sub escape {  sub escape {
403      my $s = shift;      my $s = shift;
404      $s =~ s|\r\n|\n|g;      $s =~ s|\x0D\x0A|\x0A|g;
405      $s =~ s|&|&amp;|g;      $s =~ s|&|&amp;|g;
406      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
407      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
# Line 672  sub print_content ($;$) { Line 426  sub print_content ($;$) {
426    
427  sub text_to_html {  sub text_to_html {
428      my ($txt, %option) = @_;      my ($txt, %option) = @_;
429      my (@txt) = split(/\n/, $txt);      my $toc = $option{-toc} || [];
     my @toc;  
     my @toc2 = @{$option{-toc}||[]};  
430      my $tocnum = 0;      my $tocnum = 0;
431        
432        ## Load constants
433        my %const;
434        if ($option{content_format} =~ /import="([^"]+)"/) {
435          for (split /\s*,\s*/, $1) {
436            my $wp = $database{$_};
437            if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
438              wiki::suikawikiconst::to_hash ($wp => \%const);
439            }
440          }
441        }
442        
443        $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
444        my (@txt) = split(/\n/, $txt);
445      my (@saved, @result);      my (@saved, @result);
446      unshift(@saved, "</p>");      unshift(@saved, "</p>");
447      push(@result, "<p>");      push(@result, "<p>");
448      foreach (@txt) {      foreach (@txt) {
449          chomp;          chomp;
450          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
451              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [5, "i$tocnum" => ($1 || $tocnum)];
452              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
453              $tocnum++;              $tocnum++;
454          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
455              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [4, "i$tocnum" => ($1 || $tocnum)];
456              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
457              $tocnum++;              $tocnum++;
458          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
459              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [3, "i$tocnum" => ($1 || $tocnum)];
460              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
461              $tocnum++;              $tocnum++;
462          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
463          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
464          # Walrus mod (6) end          # Walrus mod (6) end
465              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [2, "i$tocnum" => ($1 || $tocnum)];
466              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
467              $tocnum++;              $tocnum++;
468          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
469              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [1, "i$tocnum" => ($1 || $tocnum)];
470              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
471              $tocnum++;              $tocnum++;
472          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
473              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
474              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
475          } elsif (/^(-{1,6})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
476            &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
477            my ($pf, $l) = ('', $2);            my ($pf, $l) = ('', $2);
# Line 713  sub text_to_html { Line 479  sub text_to_html {
479              my $num = 0+$1;              my $num = 0+$1;
480              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
481            }            }
482            push(@result, '<li>' . $pf . &inline ($l) . '</li>');            push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
483          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
484              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
485              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
486          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
487              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
488              push @result, "<p>";              push @result, "<p>";
489              push(@result, &inline($2));              push(@result, &inline($2, const => \%const));
490              unshift @saved, "</p>";              unshift @saved, "</p>";
491          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
492              push(@result, splice(@saved));              push(@result, splice(@saved));
# Line 728  sub text_to_html { Line 494  sub text_to_html {
494              unshift(@saved, "</p>");              unshift(@saved, "</p>");
495          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
496              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
497              #push(@result, &escape($1)); # Not &inline, but &escape              push(@result, &inline($1, const => \%const));
498              push(@result, &inline($1));          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
499  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)              &back_push('table', 1, \@saved, \@result);
         } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)  
             &back_push('table', 1, \@saved, \@result, ' border="1"');  
500              #######              #######
501              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
502              # XXXXX              # XXXXX
# Line 746  sub text_to_html { Line 510  sub text_to_html {
510                          $colspan[$i]++;                          $colspan[$i]++;
511                      }                      }
512                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
513                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i]));                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], const => \%const));
514                  } else {                  } else {
515                      $value[$i] = '';                      $value[$i] = '';
516                  }                  }
# Line 763  sub text_to_html { Line 527  sub text_to_html {
527          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
528            my $num = 0+$1;            my $num = 0+$1;
529            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
530            push @result, &inline ($2);            push @result, &inline ($2, const => \%const);
531          } else {          } else {
532              push(@result, &inline($_));              push(@result, &inline($_, const => \%const));
533          }          }
534      }      }
535      push(@result, splice(@saved));      push(@result, splice(@saved));
536            
537      my $toc = '';      my $r = join("\n", @result);
538      if ($option{toc}) {      $r =~ s#<p>\x0D?\x0A</p>##g;
539          # Convert @toc (table of contents) to HTML.      $r =~ s#[\x0D\x0A]+</#</#g;
540          # This part is taken from Makio Tsukamoto's WalWiki.      $r =~ s#<pre>\x0D?\x0A#<pre>#g;
541          my (@tocsaved, @tocresult);      $r;
         foreach (@toc,@toc2) {  
             if (/^(-{1,6})(.*)$/) {  
                 &back_push('ul', length($1), \@tocsaved, \@tocresult);  
                 push(@tocresult, '<li>' . $2 . '</li>');  
             }  
         }  
         push(@tocresult, splice(@tocsaved));  
         $toc = join("\n", @tocresult);  
         $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';  
     }  
     $toc .= join("\n", @result);  
     $toc =~ s#<p>\n</p>##g;  
     $toc =~ s#[\x0D\x0A]+</#</#g;  
     $toc =~ s#<pre>\n#<pre>#g;  
     $toc;  
542  }  }
543    
544  sub back_push {  sub back_push {
# Line 806  sub back_push { Line 555  sub back_push {
555      }      }
556  }  }
557    
558  sub inline {  sub inline ($;%) {
559      my ($line) = @_;      my ($line, %option) = @_;
560      $line = &escape($line);      $line = &escape($line);
561      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
562      $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;      $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;
# Line 816  sub inline { Line 565  sub inline {
565      $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;      $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;
566      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
567      $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;      $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;
     $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;  
568      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
569      $line =~ s|''([^']+)''|<em>$1</em>|g;      $line =~ s|''([^']+)''|<em>$1</em>|g;
570      $line =~ s{      $line =~ s{
571        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]        (\[\[(\#\S+?)\]\])
572        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
573        |&gt;&gt;([0-9]+)        |&gt;&gt;([0-9]+)
574        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
575      }{      }{
576        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
577        if ($l) {        if ($l) {
578          &make_link($l)          &embedded_to_html($1);
579        } elsif (defined $page) {        } elsif (defined $page) {
580          &make_wikilink ($page, anchor => 0+$anchor);          &make_wikilink ($page, anchor => 0+$anchor);
581        } elsif ($anum) {        } elsif ($anum) {
# Line 850  sub make_wikilink ($%) { Line 598  sub make_wikilink ($%) {
598        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
599      }      }
600    } else {    } else {
601      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>);      return qq(<a title="@{[&Resource('JumpAndEditWikiPage',escape=>1)]}" href="$url_cgi?@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</span></a>);
602    }    }
603  }  }
604    
# Line 864  sub make_urilink ($;%) { Line 612  sub make_urilink ($;%) {
612        for ($site, $name) {        for ($site, $name) {
613          if (s/^"//) { s/"$//; s/\\(.)/$1/g }          if (s/^"//) { s/"$//; s/\\(.)/$1/g }
614        }        }
615          &init_InterWikiName () unless $interwiki{'[[]]'};
616        if ($interwiki{$site}) {        if ($interwiki{$site}) {
617            &load_formatter ('interwiki');
618          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
619          $site = &escape ($site); $name = &escape ($name);          $site = &escape ($site); $name = &escape ($name);
620          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;);          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;);
621        } else {        } else {
622          qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);          qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
623        }        }
624      } else {      } else {
625        qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);        qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
626      }      }
627    } elsif ($uri =~ /^urn:/) {   ## URN    } elsif ($uri =~ /^urn:/) {   ## URN
628      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
# Line 891  sub make_urilink ($;%) { Line 641  sub make_urilink ($;%) {
641    }    }
642  }  }
643    
644  my $FormIndex = 0;  {my $FormIndex = 0;
645  sub make_custom_form ($$$$) {  sub make_custom_form ($$$$) {
646      my ($wfname, $definition, $template, $option) = @_;      my ($wfname, $definition, $template, $option) = @_;
647      ## $template and $option is currently not used in this procedure.      ## $template and $option is currently not used in this procedure.
# Line 899  sub make_custom_form ($$$$) { Line 649  sub make_custom_form ($$$$) {
649          $FormIndex++;          $FormIndex++;
650          if (length $definition) {          if (length $definition) {
651              my $param = bless {}, 'SuikaWiki::Plugin';              my $param = bless {}, 'SuikaWiki::Plugin';
652              my $lastmodified = &get_info($form{mypage}, $info_LastModified);              my $lastmodified = $database->mtime ($form{mypage});
653              &load_formatter (qw/form_input form_option/);              &load_formatter (qw/form_input form_option/);
654              $definition = &unescape ($definition);              $definition = &unescape ($definition);
655              $definition =~ s/\\(.)/$1/g;              $definition =~ s/\\(.)/$1/g;
             $definition .= ' %submit;' if $definition !~ /%submit/;  
656              $option = &unescape ($option);              $option = &unescape ($option);
657              $option =~ s/\\(.)/$1/g;              $option =~ s/\\(.)/$1/g;
658              $fmt{form_option}->replace ($option, $param);              $fmt{form_option}->replace ($option, $param);
659                $param->{output}->{form} = 1 unless defined $param->{output}->{form};
660                $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
661              my $target_page = $param->{output}->{page} || $form{mypage};              my $target_page = $param->{output}->{page} || $form{mypage};
662              $param->{form_disabled} = 1 if $fixedpage{$target_page};              $param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage});
663              my $target_form = $param->{output}->{id};              my $target_form = $param->{output}->{id};
664              my $r = <<EOH;              my $r = '';
665                $r = <<EOH if $param->{output}->{form};
666  <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">  <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
667    <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">    <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
668    <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">    <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
# Line 920  sub make_custom_form ($$$$) { Line 672  sub make_custom_form ($$$$) {
672  EOH  EOH
673              $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;              $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
674              $r .= $fmt{form_input}->replace ($definition, $param);              $r .= $fmt{form_input}->replace ($definition, $param);
675              $r .= <<EOH;              $r .= "</form>\n" if $param->{output}->{form};
 </form>  
 EOH  
676              $r;              $r;
677         } else {  ## No input-interface WikiForm         } else {  ## No input-interface WikiForm
678             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
679         }         }
680      } else {      } else {
681          q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);          qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
682      }      }
683  }  }}
   
 ## to be obsoleted  
 sub make_link {  
     my $chunk = shift;  
     # Walrus add (3) start  
     $chunk =~ s/^&lt;(.*)&gt;$/$1/;  
     my $name  = $chunk;  
     $name = &unarmor_name($name);  
     # Walrus add (3) end  
     if ($chunk =~ /^$embedded_name$/) {  
         return &embedded_to_html($chunk);  
     } else {  
         $chunk = &unarmor_name($chunk);  
         $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.  
         my $cookedchunk = &encode($chunk);  
         if ($database{$chunk}) {  
             my $subject = &escape(&get_subjectline($chunk, delimiter => ''));  
 #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)  
             return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)  
         } elsif ($page_command{$chunk}) {  
 #           return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>);    # Walrus del (3)  
             return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)  
         } else {  
             return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);  
         }  
     }  
 }  
684    
685  sub print_message {  sub print_message {
686      my ($msg) = @_;      my ($msg) = @_;
687      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
 }  
   
 sub get_message {  
     my ($msg) = @_;  
     qq(<p><strong>$msg</strong></p>);  
688  }  }
689    
690  sub init_form {  sub init_form {
691      if (param()) {      ## TODO: Support multipart/form-data
692          foreach my $var (param()) {      my $query = '';
693              $form{$var} = param($var);      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
694        }        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
695      }      }
696      $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
697      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {      if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
698        my $query = &decode($main::ENV{QUERY_STRING});        my $query = &decode($main::ENV{QUERY_STRING});
699        $query = &code_convert(\$query, $kanjicode);        $query = &code_convert(\$query, $kanjicode);
700        if ($page_command{$query}) {        if ($page_command{$query}) {
# Line 986  sub init_form { Line 704  sub init_form {
704          $form{mypage} = $query;          $form{mypage} = $query;
705          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
706        }        }
707        } else {
708          for (split /[;&]/, $query) {
709            if (my ($n, $v) = split /=/, $_, 2) {
710              for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
711              $form{$n} = $v;
712            }
713          }
714          unless (defined $form{mypage}) {
715            $form{mypage} = $form{epage};
716            $form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g;
717          }
718          if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
719            $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
720            $form{mycmd} = $page_command{$form{mypage}};
721          }
722      }      }
723      $form{mypage} ||= 'HomePage';      $form{mypage} ||= 'HomePage';
724        $form{mypage} =~ tr/\x00-\x1F\x7F//d;
725      $form{mycmd} ||= 'read';      $form{mycmd} ||= 'read';
726    
727      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
# Line 1011  sub init_form { Line 745  sub init_form {
745      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
746  }  }
747    
748  sub update_recent_changes {  {my %SubjectLine;
     my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";  
     my @oldupdates = split(/\r?\n/, $database{$RecentChanges});  
     shift (@oldupdates); ## '#?' magic line  
     my @updates;  
     foreach (@oldupdates) {  
         /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;  
         my $name = $1;  
         if ($name ne $form{mypage}) {  
             push @updates, $_;  
         }  
     }  
     if (&is_exist_page($form{mypage})) {  
       unshift @updates, $update;  
     }  
     splice(@updates, $maxrecent + 1);  
     $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);  
     if ($file_touch) {  
         open(FILE, "> $file_touch");  
         print FILE localtime() . "\n";  
         close(FILE);  
     }  
 }  
   
749  sub get_subjectline {  sub get_subjectline {
750      my ($page, %option) = @_;      my ($page, %option) = @_;
751      if (not &is_editable($page)) {      unless (defined $SubjectLine{$page}) {
752          return "";        if (not &is_editable($page)) {
753            $SubjectLine{$page} = "";
754          } else {
755            $SubjectLine{$page} = $database{$page};
756            $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
757            $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
758          }
759        }
760        if (length $SubjectLine{$page}) {
761          $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
762          $option{delimiter}.$SubjectLine{$page}.$option{tail};
763      } else {      } else {
764          # Delimiter check.        '';
         my $delim = $subject_delimiter;  
         if (defined($option{delimiter})) {  
             $delim = $option{delimiter};  
         }  
   
         # Get the subject of the page.  
         my $subject = $database{$page};  
         $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;  
         $subject =~ s/\r?\n.*//s;  
         return "$delim$subject".$option{tail};  
765      }      }
766  }  }}
   
 sub send_mail_to_admin {  
     my ($page, $mode) = @_;  
     return unless $modifier_sendmail;  
     my $message = <<"EOD";  
 To: $modifier_mail  
 From: $modifier_mail  
 Subject: [Wiki]  
 MIME-Version: 1.0  
 Content-Type: text/plain; charset=ISO-2022-JP  
 Content-Transfer-Encoding: 7bit  
   
 --------  
 MODE = $mode  
 REMOTE_ADDR = $ENV{REMOTE_ADDR}  
 REMOTE_HOST = $ENV{REMOTE_HOST}  
 --------  
 $page  
 --------  
 $database{$page}  
 --------  
 EOD  
     &code_convert(\$message, 'jis');  
     open(MAIL, "| $modifier_sendmail");  
     print MAIL $message;  
     close(MAIL);  
 }  
767    
768  sub open_db {  sub open_db {
769      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
770          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");          dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}");
         dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");  
771      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
772          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");          eval q{use AnyDBM_File};
773          tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");          tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}");
774      } else {      } elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') {
775          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");          eval q{use Yuki::YukiWikiDB};
776          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");          tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}");
777        } else {    ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta
778            eval qq{use $modifier_dbtype};
779            $database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or &print_error("(tie $modifier_dbtype) $PathTo{WikiDataBase}");
780      }      }
781  }  }
782    
783  sub close_db {  sub close_db {
784      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
785          dbmclose(%database);          dbmclose(%database);
         dbmclose(%infobase);  
     } elsif ($modifier_dbtype eq 'AnyDBM_File') {  
         untie(%database);  
         untie(%infobase);  
786      } else {      } else {
787          untie(%database);          untie(%database);
         untie(%infobase);  
     }  
 }  
   
 sub open_diff {  
     if ($modifier_dbtype eq 'dbmopen') {  
         dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");  
     } elsif ($modifier_dbtype eq 'AnyDBM_File') {  
         tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");  
     } else {  
         tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");  
     }  
 }  
   
 sub close_diff {  
     if ($modifier_dbtype eq 'dbmopen') {  
         dbmclose(%diffbase);  
     } elsif ($modifier_dbtype eq 'AnyDBM_File') {  
         untie(%diffbase);  
     } else {  
         untie(%diffbase);  
788      }      }
789  }  }
790    
791  sub print_searchform {  sub editform (@) {
792      my ($word) = @_;    my %option = @_;
793      print <<"EOD";    my $frozen = &is_frozen ($option{page});
794  <form action="$url_cgi" method="get">    $option{content} = $database{$option{page}} unless defined $option{content};
795      <input type="hidden" name="mycmd" value="read">    $option{content} = $database{NewPageTemplate} unless length $option{content};
796      <input type="text" name="mypage" value="$word" size="20">    $option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified};
797      <input type="submit" value="$resource{searchbutton}">    my $f = '';
798  </form>    my $magic = '';
799  EOD    $magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s;
800  }    
801      my $selected = 'read';
802  sub print_editform {    if ($form{after_edit_cmd}) {
803      my ($mymsg, $lastmodified, %mode) = @_;      $selected = $form{after_edit_cmd};
804      my $frozen = &is_frozen($form{mypage});    } elsif ($magic =~ /Const|Config|CSS/) {
805        $selected = 'edit';
806      if ($form{mypreview}) {    }
807          if ($form{mymsg}) {    my $afteredit = <<EOH;
             unless ($mode{conflict}) {  
                 print qq(<h3>$resource{previewtitle}</h3>\n);  
                 print qq($resource{previewnotice}\n);  
                 print qq(<div class="preview">\n);  
                 &print_content($form{mymsg});  
                 print qq(</div>\n);  
             }  
         } else {  
             print qq($resource{previewempty});  
         }  
         $mymsg = &escape($form{mymsg});  
     } else {  
         $mymsg = &escape($mymsg || $database{NewPageTemplate});  
     }  
     my $magic = '';  
     $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;  
   
     my $edit = $mode{admin} ? 'adminedit' : 'edit';  
     my $escapedmypage = &escape($form{mypage});  
     my $escapedmypassword = &escape($form{mypassword});  
     my $selected = 'read';  
     if ($form{after_edit_cmd}) {  
         $selected = $form{after_edit_cmd};  
     } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {  
         $selected = 'edit';  
     }  
     my $afteredit = <<EOH;  
808  <select name="after_edit_cmd">  <select name="after_edit_cmd">
809  <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
810  <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
811  </select>  </select>
812  EOH  EOH
813      $f .= <<"EOD";
814      print <<"EOD";  <form action="$uri{wiki}" method="post">
815  <form action="$url_cgi" method="post">      @{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd></label>) ]}
816  <h2>$escapedmypageの編集</h2>      @{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br>
817      @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}      <input type="hidden" name="myLastModified" value="$option{last_modified}">
818      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;      <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
819                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;      <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br>
                ++$n}]}]<br>  
     <input type="hidden" name="myLastModified" value="$lastmodified">  
     <input type="hidden" name="mypage" value="$escapedmypage">  
     <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>  
820  @{[  @{[
821      $mode{admin} ?      $option{admin} ?
822      qq(      qq(
823      <input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton}      <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
824      <input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>)      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)
825      : ""      : ""
826  ]}  ]}
827  @{[  @{[
828      $mode{conflict} ? "" :      $option{conflict} ? "" :
829      qq(      qq(
830          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br>
831          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label>
         <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>  
832         $afteredit         $afteredit
        <br>  
833      )      )
834  ]}  ]}
835  </form>  </form>
836  EOD  EOD
837      unless ($mode{conflict}) {      unless ($option{conflict}) {
838          # Show the format rule.          ## Show help text
839          my $help = $database{'WikiEditHelp'};          my $help = $database{WikiEditHelp};
840          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
841          print &text_to_html ($help, toc => 0);          $f .= &text_to_html ($help, toc => 0);
     #    open(FILE, $file_format) or &print_error("($file_format)");  
     #    my $content = join('', <FILE>);  
     #    &code_convert(\$content, $kanjicode);  
     #    close(FILE);  
     #    print &text_to_html($content, toc=>0);  
842      }      }
843  }      $f;
   
 sub print_passwordform {  
         print <<"EOD";  
 <form action="$url_cgi" method="post">  
     <input type="hidden" name="mycmd" value="adminchangepassword">  
     $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>  
     $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>  
     $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>  
     <input type="submit" value="$resource{changepasswordbutton}"><br>  
 </form>  
 EOD  
844  }  }
845    
846  sub is_editable {  sub is_editable {
847      my ($page) = @_;      my ($page) = @_;
848      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {      $page =~ /[\x00-\x1F\x7F]/ ? 0 : 1;
         return 0;  
     } else {  
         return 1;  
     }  
849  }  }
850    
851  # armor_name:  # armor_name:
# Line 1250  sub armor_name { qq([[$_[0]]]) } Line 858  sub armor_name { qq([[$_[0]]]) }
858  #   WikiName -> WikiName  #   WikiName -> WikiName
859  sub unarmor_name {  sub unarmor_name {
860      my ($name) = @_;      my ($name) = @_;
861      if ($name =~ /^$bracket_name$/) {      if ($name =~ /^\[\[(\S+?)\]\]$/) {
862          return $1;          return $1;
863      } else {      } else {
864          return $name;          return $name;
# Line 1277  sub encode { Line 885  sub encode {
885      return $encoded;      return $encoded;
886  }  }
887    
 sub init_resource {  
     open(FILE, $file_resource) or &print_error("(resource)");  
     while (<FILE>) {  
         s/[\x0A\x0D]+$//g;  
         next if /^#/;  
         my ($key, $value) = split(/=/, $_, 2);  
         $resource{$key} = &code_convert(\$value, $kanjicode);  
     }  
     close(FILE);  
 }  
   
 sub conflict {  
     my ($page, $rawmsg) = @_;  
     if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {  
         return 0;  
     }  
     open(FILE, $file_conflict) or &print_error("(conflict)");  
     my $content = join('', <FILE>);  
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
     &print_header($page, -noindex => 1);  
     &print_content($content);  
     &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);  
     &print_footer($page);  
     return 1;  
 }  
   
888  sub get_now {  sub get_now {
889      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
     my (@week) = qw(日 月 火 水 木 金 土);  
     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);  
890      $year += 1900;      $year += 1900;
891      $mon++;      $mon++;
892      $mon = "0$mon" if $mon < 10;      $mon = "0$mon" if $mon < 10;
# Line 1315  sub get_now { Line 894  sub get_now {
894      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
895      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
896      #$sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
897      $weekday = $week[$weekday];      return "$year-$mon-$day $hour:$min";
     return "$year-$mon-$day ($weekday) $hour:$min";  
898  }  }
899    
900  sub init_InterWikiName {  sub init_InterWikiName {
901    my @content = split /\n/, $database{$InterWikiName};    my @content = split /\n/, $database{InterWikiName};
902    for (@content) {    for (@content) {
903      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
904        $interwiki{$1} = $2;        $interwiki{$1} = $2;
905      }      }
906    }    }
907    require Message::Util::Formatter;    $interwiki{'[[]]'} = 1;       ## dummy
   $fmt{interwiki} = Message::Util::Formatter->new;  
   $fmt{interwiki}->{encoded} = sub {  
     my ($o, $p) = @_;  
     if ($o->{except}) {  
       $o->{except} =~ tr/\x00-\x20\x22%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;  
     }  
     my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');  
     $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;  
     $s;  
   };  
   $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1  
     my ($o, $p) = @_;  
     my $s = $p->{name};  
     $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;  
     &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));  
   };  
 }  
   
   
 sub get_info {  
     my ($page, $key) = @_;  
     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});  
     return $info{$key};  
 }  
   
 sub set_info {  
     my ($page, $key, $value) = @_;  
     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});  
     $info{$key} = $value;  
     my $s = '';  
     for (keys %info) {  
         $s .= "$_=$info{$_}\n";  
     }  
     $infobase{$page} = $s;  
908  }  }
909    
910  sub frozen_reject {  sub frozen_reject {
911      my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);      my ($isfrozen) = $database->meta (IsFrozen => $form{mypage});
912      my ($willbefrozen) = $form{myfrozen};      my ($willbefrozen) = $form{myfrozen};
913      if (not $isfrozen and not $willbefrozen) {      if (not $isfrozen and not $willbefrozen) {
914          # You need no check.          # You need no check.
# Line 1373  sub frozen_reject { Line 917  sub frozen_reject {
917          # You are admin.          # You are admin.
918          return 0;          return 0;
919      } else {      } else {
920          &print_error($resource{passworderror});          &print_error(&Resource('Error:PasswordIsIncorrect'));
921          return 1;          return 1;
922      }      }
923  }  }
924    
925  sub valid_password {  sub is_frozen ($) { $database->meta (IsFrozen => $_[0]) ? 1 : 0 }
     my ($givenpassword) = @_;  
     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);  
     if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
 sub is_frozen {  
     my ($page) = @_;  
     if (&get_info($page, $info_IsFrozen)) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
926    
927  sub do_comment {  sub do_comment {
928      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
929      my $default_name;   ## this code does not strict.      my $default_name;   ## this code does not strict.
930      $default_name = $1 if $content =~ /default-name="([^"]+)"/;      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
931      my $datestr = '[WEAK['.&get_now.']]';      my $datestr = '[WEAK['.&get_now.']]';
932      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
933      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
934      if ($namestr =~ /^(?:>>)?[0-9]/) {      if ($namestr =~ /^(?:>>)?[0-9]/) {
935        $namestr = qq( ''$namestr'': );        $namestr = qq( ''$namestr'': );
# Line 1411  sub do_comment { Line 938  sub do_comment {
938      }      }
939      my $anchor = &get_new_anchor_index ($content);      my $anchor = &get_new_anchor_index ($content);
940      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
941      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\[\[\#r?comment\]\])}{
942        my $embed = $1;        my $embed = $1;
943        if ($i == $form{comment_index}) {        if ($i == $form{comment_index}) {
944          if ($embed eq $embed_comment) {          if ($embed ne '[[#rcomment]]') {
945            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
946          } else {          } else {
947            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
# Line 1448  sub get_new_anchor_index ($) { Line 975  sub get_new_anchor_index ($) {
975  my $CommentIndex = 0;  my $CommentIndex = 0;
976  sub embedded_to_html {  sub embedded_to_html {
977      my ($embedded) = @_;      my ($embedded) = @_;
978      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
979        unless ($main::_EMBEDED) {        unless ($main::_EMBEDED) {
980          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = $database->mtime ($form{mypage});
981          return <<"EOD";          return <<"EOD";
982  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
983      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
# Line 1458  sub embedded_to_html { Line 985  sub embedded_to_html {
985      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
986      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
987      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
988      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
989      <input type="text" name="myname" value="" size="10" class="comment-name">      <input type="text" name="myname" value="" size="10" class="comment-name">
990      <input type="text" name="mymsg" value="" size="60" class="comment-msg">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
991      <input type="submit" value="$resource{commentbutton}" class="comment-submit">      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
992  </p></form>  </p></form>
993  EOD  EOD
994       } else {       } else {
# Line 1469  EOD Line 996  EOD
996  <del><form action="$url_cgi" method="get">  <del><form action="$url_cgi" method="get">
997      <input type="hidden" name="mycmd" value="read">      <input type="hidden" name="mycmd" value="read">
998      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
999      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1000      <input type="text" name="myname" value="" size="10" disabled="disabled">      <input type="text" name="myname" value="" size="10" disabled="disabled">
1001      <input type="text" name="mymsg" value="" size="60" disabled="disabled">      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
     <input type="submit" value="$resource{commentbutton}" disabled="disabled">  
1002  </form></del>  </form></del>
1003  EOD  EOD
1004      }      }
1005    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1006      return get_search_result ($1, -match_myself => 1);      return get_search_result ($1, -match_myself => 1);
     # Walrus add (5) start  
     } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {  
         $_ = &make_interwiki_box($1, $2);  
         return ($_) ? $_ : $embedded;  
     # Walrus add (5) end  
1007    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1008      my ($name, $r) = ($1, '');      my ($name, $r) = ($1, '');
1009      if ($main::_EMBEDED != 1) {      if ($main::_EMBEDED != 1) {
# Line 1495  EOD Line 1016  EOD
1016        } elsif (length $content) {        } elsif (length $content) {
1017          $r = "<pre>@{[&escape ($content)]}</pre>";          $r = "<pre>@{[&escape ($content)]}</pre>";
1018        } else {        } else {
1019          $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');          $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1020        }        }
1021      } else {    ## nested #EMBED      } else {    ## nested #EMBED
1022        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');        $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1023      }      }
1024      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>);      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>);
1025    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
# Line 1511  EOD Line 1032  EOD
1032  sub load_formatter (@) {  sub load_formatter (@) {
1033      for my $t (@_) {      for my $t (@_) {
1034          unless ($fmt{$t}) {          unless ($fmt{$t}) {
1035                require Message::Util::Formatter;
1036              $fmt{$t} = Message::Util::Formatter->new;              $fmt{$t} = Message::Util::Formatter->new;
1037              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1038                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
# Line 1538  sub do_wikiform { Line 1060  sub do_wikiform {
1060              $param->{anchor_index} = $anchor;              $param->{anchor_index} = $anchor;
1061              $param->{argv} = \%form;              $param->{argv} = \%form;
1062              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1063              $param->{default_name} ||= $DEFAULT_embed_comment_name;              $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1064              $fmt{form_option}->replace ($option, $param);              $fmt{form_option}->replace ($option, $param);
1065              my $t = 1;              my $t = 1;
1066              for (@{$param->{require}||[]}) {              for (@{$param->{require}||[]}) {
# Line 1576  sub do_wikiform { Line 1098  sub do_wikiform {
1098      }      }
1099  }  }
1100    
   
 # Walrus add (5) start  
 sub do_interwiki_box {  
     my $remoteurl = $interwiki{$form{'myintername'}};  
     if ($remoteurl) {  
         $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;  
         print "Location: $remoteurl\n\n";  
         exit(1);  
     } else {  
         &do_read;  
     }  
 }  
 # Walrus add (5) end  
   
 # Walrus add (5) start  
 sub make_interwiki_box {  
     my ($localname, $intername) = @_;  
     my %ignoretype = (  
         'box'      => 'text',  
         'text'     => 'text',  
         'pass'     => 'password',  
         'password' => 'password'  
     );  
     my $converted = ($ignoretype{$localname}) ? <<EOD : undef;  
 <form action="$url_cgi" method="post">  
     <input type="hidden" name="mycmd" value="interwikibox">  
     <input type="hidden" name="mypage" value="$form{mypage}">  
     <input type="hidden" name="myintername" value="$intername">  
     $intername:  
     <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">  
     <input type="submit" value="Submit">  
 </form>  
 EOD  
 }  
 # Walrus add (5) end  
   
1101  sub code_convert {  sub code_convert {
1102      require Jcode;
1103      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1104      $code = 'jis' if $code =~ /iso/;      $code = 'jis' if $code =~ /iso/;
1105      $code = 'euc' if $code =~ /euc/;      $code = 'euc' if $code =~ /euc/;
1106      $code = 'sjis' if $code =~ /shift/;      $code = 'sjis' if $code =~ /shift/;
1107      $code = 'utf8' if $code =~ /utf/;      $code = 'utf8' if $code =~ /utf/;
1108      &Jcode::convert($contentref, $code);       # for Jcode.pm      $$contentref = Jcode->new ($contentref)->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code;
 #    &jcode::convert($contentref, $code);       # for jcode.pl  
     &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';  
1109      return $$contentref;      return $$contentref;
1110  }  }
1111    
 sub test_convert {  
     my $txt = &text_to_html(<<"EOD", toc=>1);  
 *HEADER1  
 **HEADER1-1  
 -ITEM1  
 -ITEM2  
 -ITEM3  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
   
 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 **HEADER1-2  
 :TERM1:DESCRIPTION1 AND ''BOLD''  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 :TERM2:DESCRIPTION2  
 :TERM3:DESCRIPTION3  
 ----  
 *HEADER2  
 **HEADER2-1  
 http://www.hyuki.com/  
 **HEADER2-2  
   
 [[YukiWiki2]]  
   
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
   
 LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0  
   
 >LEVEL1  
 >LEVEL1  
 >LEVEL1  
 >>LEVEL2  
 >>LEVEL2  
 >>LEVEL2  
 >>>LEVEL3  
 -HELLO-1  
 --HELLO-2  
 (HELLO-2, HELLO-2, HELLO-2)  
 ---HELLO-3  
 (HELLO-3, HELLO-3, HELLO-3)  
 --HELLO-2  
 ---HELLO-3  
 --HELLO-2  
 ---HELLO-3  
 >>>LEVEL3  
 >>>LEVEL3  
 >>>LEVEL3  
 >>>LEVEL3  
 EOD  
     print $txt;  
     exit;  
 }  
   
1112  sub do_diff {  sub do_diff {
     if (not &is_editable($form{mypage})) {  
         &do_read;  
         return;  
     }  
     &open_diff;  
1113      my $title = $form{mypage};      my $title = $form{mypage};
1114      &print_header($title, -noindex => 1);      &print_header($title, -noindex => 1);
1115      $_ = &escape($diffbase{$form{mypage}});      print qq(<h2>@{[&Resource('Diff:Title',escape=>1)]}</h2>);
1116      &close_diff;      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
     print qq(<h3>$resource{difftitle}</h3>);  
     print qq($resource{diffnotice});  
1117      print qq(<pre class="diff">);      print qq(<pre class="diff">);
1118      foreach (split(/\n/, $_)) {      for (split(/\n/, &escape ($database->traverse_diff ($form{mypage})))) {
1119          if (/^\+(.*)/) {          if (/^\+(.*)/) {
1120              print qq(<b class="added">$1</b>\n);              print qq(<ins class="added">$1</ins>\n);
1121          } elsif (/^\-(.*)/) {          } elsif (/^\-(.*)/) {
1122              print qq(<s class="deleted">$1</s>\n);              print qq(<del class="deleted">$1</del>\n);
1123          } elsif (/^\=(.*)/) {          } elsif (/^\=(.*)/) {
1124              print qq(<span class="same">$1</span>\n);              print qq(<span class="same">$1</span>\n);
1125          } else {          } else {
# Line 1712  sub do_diff { Line 1127  sub do_diff {
1127          }          }
1128      }      }
1129      print qq(</pre>);      print qq(</pre>);
     print qq(<hr>);  
1130      &print_footer($title);      &print_footer($title);
1131  }  }
1132    
1133  sub do_rss {  sub do_rss {
1134        eval q{use Yuki::RSS};
1135      my $rss = new Yuki::RSS(      my $rss = new Yuki::RSS(
1136          version => '1.0',          version => '1.0',
1137          encoding => $charset,          encoding => &get_charset_name ($kanjicode),
1138        );
1139        my $scheme = 'http';
1140        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1141        my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1142        $rss->stylesheet (
1143          href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1144          type      => 'text/css',
1145      );      );
1146      $rss->channel(      $rss->channel(
1147          title => $modifier_rss_title,          title   => &Resource ('RSS:WikiTitle'),
1148          link  => $modifier_rss_link,          link    => $myuri,
1149          description => $modifier_rss_description,          description     => &Resource ('RSS:WikiDescription'),
1150            'dc:language'   => $lang,
1151      );      );
1152      my $recentchanges = $database{$RecentChanges};      my $recentchanges = $database{RecentChanges};
1153      my $count = 0;      my $count = 0;
1154      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1155          last if ($count >= 15);          last if ($count >= 15);
1156          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/;    # date format.          if (/\[\[([^]]+)\]\]/) {
1157          my $title = &unarmor_name($1);            my $title = $1;
1158          my $escaped_title = &escape($title);            $rss->add_item (
1159          my $link = $modifier_rss_link . '?' . &encode($title);              title       => &escape($title),
1160          my $description = $escaped_title . &escape(&get_subjectline($title));              link        => $myuri . '?' . &encode($title),
1161          $rss->add_item(              description => &escape(&get_subjectline($title,delimiter=>'')),
1162              title => $escaped_title,              'dc:date'   => $database->mtime ($title),
1163              link  => $link,            );
1164              description => $description,            $count++;
1165          );          }
         $count++;  
1166      }      }
1167      # print RSS information (as XML).      # print RSS information (as XML).
 print scalar &make_navigate_links ('RssPage');  
1168      print <<"EOD"      print <<"EOD"
1169  Content-type: application/xml  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1170    
1171  @{[$rss->as_string]}  @{[$rss->as_string]}
1172  EOD  EOD
1173  }  }
1174    
1175    sub _rfc3339_date ($) {
1176      my @time = gmtime (shift);
1177      sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1178    }
1179    
1180  sub is_exist_page {  sub is_exist_page {
1181      my ($name) = @_;      my ($name) = @_;
1182      if ($use_exists) {      if ($use_exists) {
# Line 1761  sub is_exist_page { Line 1187  sub is_exist_page {
1187  }  }
1188    
1189  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
 sub __set_database ($$) { $database{ $_[0] } = $_[1] }  
1190    
1191  sub do_wikiplugininfo {  my %_Resource;
1192      &print_header (q(WikiPluginInfo));  sub Resource ($;%) {
1193      print text_to_html (&SuikaWiki::Plugin::make_info_page);    my ($s, %o) = @_;
1194      &print_footer (q(WikiPluginInfo));    unless (defined $_Resource{$s}) {
1195        $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1196      }
1197      $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1198  }  }
1199    
1200  package wiki::referer;  package wiki::referer;
# Line 1789  sub add ($$) { Line 1217  sub add ($$) {
1217    $list{ $uri }++;    $list{ $uri }++;
1218    set ($page, \%list);    set ($page, \%list);
1219  }  }
1220  sub get ($) {  sub get ($) { split /"/, $main::database->meta (Referer => $_[0]) }
   my $page = shift;  
   split /"/, main::get_info ($page, 'Referer');  
 }  
1221  sub set ($%) {  sub set ($%) {
1222    my $page = shift;    my $page = shift;
1223    my $list = shift;    my $list = shift;
1224    main::set_info ($page, Referer => join '"', %$list);    $main::database->meta (Referer => $page => join '"', %$list);
1225  }  }
1226    
1227  sub get_dont_record () {  sub get_dont_record () {
# Line 1850  sub __decode ($) { Line 1275  sub __decode ($) {
1275  }  }
1276    
1277  package wiki::useragent;  package wiki::useragent;
1278    our $UseLog;
1279    
1280  sub add ($) {  sub add ($) {
1281    my $s = shift;    my $s = shift;
1282    return unless length $s;    return unless length $s;
1283    $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;    return unless $UseLog;
1284      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge;
1285    my %ua;    my %ua;
1286    for (split /\n/, &main::__get_database('WikiUserAgentList')) {    for (split /\n/, &main::__get_database($main::PageName{UserAgentList})) {
1287      if (/^-\[(\d+)\] (.+)$/) {      if (/^-\[(\d+)\] (.+)$/) {
1288        my ($t, $n) = ($1, $2);        my ($t, $n) = ($1, $2);
1289        $n =~ tr/\x0A\x0D//d;        $n =~ tr/\x0A\x0D//d;
# Line 1868  sub add ($) { Line 1295  sub add ($) {
1295    for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {    for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1296      $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;      $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1297    }    }
1298    &main::__set_database ('WikiUserAgentList' => $s);    $main::database->STORE ($main::PageName{UserAgentList} => $s, -touch => 0);
1299    }
1300    
1301    package wiki::suikawikiconst;
1302    
1303    sub to_hash ($;$) {
1304      my $page = shift;
1305      my $h = shift || {};
1306      my $val;
1307      for my $line (split /\n/, $page) {
1308        $line =~ tr/\x0A\x0D//d;
1309        if ($val && $line =~ s/^\s+//) {
1310          $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1311        } elsif ($line =~ /^(.+):/) {
1312          $val = $1; $h->{$val} = '';
1313        }
1314      }
1315      $h;
1316  }  }
1317    
1318    package wiki::dummy;
1319    sub mtime (@) {undef}
1320    sub meta (@) {undef}
1321    sub Yuki::YukiWikiDB2::meta (@) {undef}
1322    
1323  package SuikaWiki::Plugin;  package SuikaWiki::Plugin;
1324    our $plugin_directory;  # defined in top of this file.    our $plugin_directory;  # defined in top of this file.
1325    our %List;    our %List;
1326      our %Index;
1327    
1328  sub escape ($$) { main::escape ($_[1]) }  sub escape ($$) { main::escape ($_[1]) }
1329  sub unescape ($$) { main::unescape ($_[1]) }  sub unescape ($$) { main::unescape ($_[1]) }
1330  sub encode ($$) { main::encode ($_[1]) }  sub encode ($$) { main::encode ($_[1]) }
1331  sub decode ($$) { main::decode ($_[1]) }  sub decode ($$) { main::decode ($_[1]) }
1332  sub __get_datetime ($) { main::get_now () }  sub __get_datetime ($) { main::get_now () }
1333    sub resource ($$;%) { shift; &main::Resource (@_) }
1334    sub uri ($$) { $main::uri{$_[1]} }
1335    sub new_index ($$) { ++$Index{$_[1]} }
1336    
1337  sub regist ($@) {  sub regist ($@) {
1338      my $pack = shift;      my $pack = shift;
# Line 1898  sub import_plugins () { Line 1351  sub import_plugins () {
1351      }      }
1352  }  }
1353    
1354  sub make_info_page () {  &import_plugins ();
     my $r = <<EOH;  
 EOH  
     unless ($List{_all}) {  
         $r .= qq('''No plugin is installed!'''\n);  
     } else {  
         my $index = 0;  
         for my $package (sort @{$List{_all}}) {  
             $index++;  
             my $prop = $package->property ();  
             $r .= <<EOH;  
 *$package  
   
 [$index] '''$prop->{name}''' (Version $prop->{version})  
 <$prop->{uri}>  
   
 Provide:  
 @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {  
     $t .= qq(-''$f''\n);  
     for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {  
          $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);  
     }  
 }$t}]}  
1355    
1356  EOH  package wiki::conneg;
1357          }  
1358    ## BUG: this parser isn't strict.
1359    sub get_accept_lang (;$) {
1360      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1361      my %alang = (ja => 0.0002, en => 0.0001);
1362      my $i = 0.1;
1363      for (split /\s*,\s*/, $alang) {
1364        tr/\x09\x0A\x0D\x20//d;
1365        if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1366          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1367          $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1368          $alang{$l} += $i unless $alang{$l} == 0;
1369          $i -= 0.001;
1370      }      }
1371      $r;    }
1372      \%alang;
1373  }  }
1374    
1375  &import_plugins ();  package wiki::resource;
1376    
1377    sub get ($;\%) {
1378      my ($resname, $option) = @_;
1379      $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1380      $option->{resource} ||= {};
1381      my $v;
1382      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1383        while (length $lang) {
1384          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1385            $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1386            $v = $option->{resource}->{$lang}->{$resname};
1387            last if defined $v;
1388          }
1389          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1390        }
1391        last if defined $v;
1392      }
1393      defined $v ? $v : $resname;
1394    }
1395    
1396  package main;  package main;
1397  &main;  &main;
# Line 1938  exit 0; Line 1401  exit 0;
1401  __END__  __END__
1402  =head1 NAME  =head1 NAME
1403    
1404  wiki.cgi - This is YukiWiki, yet another Wiki clone.  wiki.cgi --- SuikaWiki: Yet yet another Wiki engine
   
 =head1 DESCRIPTION  
   
 YukiWiki is yet another Wiki clone.  
1405    
1406  YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).  =head1 AUTHORS
 YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),  
 and some embedded commands (such as [[#comment]] to add comments).  
1407    
1408  Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.  Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/>
1409    
1410  =head1 AUTHOR  Makio Tsukamoto <http://digit.que.ne.jp/>
1411    
1412  Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/  Wakaba <w@suika.fam.cx>
1413    
1414  =head1 LICENSE  =head1 LICENSE
1415    
1416  Copyright (C) 2000-2002 by Hiroshi Yuki.  Copyright (C) 2000-2003 AUTHORS
1417    
1418  This program is free software; you can redistribute it and/or  This program is free software; you can redistribute it and/or
1419  modify it under the same terms as Perl itself.  modify it under the same terms as Perl itself.

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.48

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24