/[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.27 by wakaba, Mon Oct 7 12:50:51 2002 UTC revision 1.44 by w, Wed Jan 1 12:30:24 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #!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.  
 #  
 # WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。  
 #  
 # * 更新内容  
 #  
 # 2.0.beta1.wal.1 on 2002/05/19,22:32:19  
 # (1) Footerの変更  
 # (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない  
 # (3) 別名リンク([別名 URL])に対応。  
 # (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。  
 # (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成  
 # (6) HTMLモード対応。  
 #  
 # 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。  
 # ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。  
 #   - インラインの画像変換  
 #   - YukiWikiDB対応  
 #   - テーブル  
 #   - DB関連モジュールuseのeval化  
 #   - BracketNameによるキーからブラケットを排除  
 # ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。  
 #   [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。  
 #  
 #=======================================  
6    
 # Walrus add (debug) start  
 my $walrus_log;  
 my $walrus_debugging = 0;  
 # Walrus add (debug) end  
   
 # 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;  
11    require 'wikidata/suikawiki-config.ph';
12  use Yuki::DiffText qw(difftext);  use Yuki::DiffText qw(difftext);
 use Yuki::YukiWikiDB;  
 use AnyDBM_File;  
 require 'jcode.pl';  
 # use 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.  
 #  
 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 = 'wiki';  
 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;  
14  ##############################  ##############################
15  #  my %fmt;        ## formatter objects
 # 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.  
 ##############################  
 # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b';        # Walrus del (2)  
 my $wiki_name   = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b';        # Walrus add (2)  
 my $bracket_name = '\[\[(\S+?)\]\]';  
 my $embedded_name = '\[\[(#\S+?)\]\]';  
 my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  
 my $interwiki_name = 'i:([^:]+):([^:].*)';  
 ##############################  
 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    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19  );  );
20    our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21    our (%PageName,$kanjicode,$lang,%fixedpage);
22    
23  ##############################  ##############################
24  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
25  my $info_IsFrozen = 'IsFrozen';  my $info_IsFrozen = 'IsFrozen';
 my $info_AdminPassword = 'AdminPassword';  
26  ##############################  ##############################
 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,  
 );  
27  my %form;  my %form;
28  my %database;  my %database;
29  my %infobase;  my %infobase;
30  my %diffbase;  my %diffbase;
 my %resource;  
31  my %interwiki;  my %interwiki;
32  ##############################  ##############################
33  my %page_command = (  my %page_command = (
34      $IndexPage => 'index',      $PageName{IndexPage} => 'index',
35      $SearchPage => 'searchform',      $PageName{RssPage} => 'rss',
36      $CreatePage => 'create',      AdminChangePassword => 'adminchangepasswordform',
     $RssPage => 'rss',  
     $AdminChangePassword => 'adminchangepasswordform',  
     #$FrontPage => 'FrontPage',  
37  );  );
38  my %command_do = (  my %command_do = (
39      read => \&do_read,      read => \&do_read,
# Line 172  my %command_do = ( Line 45  my %command_do = (
45      write => \&do_write,      write => \&do_write,
46      index => \&do_index,      index => \&do_index,
47      searchform => \&do_searchform,      searchform => \&do_searchform,
     search => \&do_search,  
     create => \&do_create,  
     createresult => \&do_createresult,  
     FrontPage => \&do_FrontPage,  
48      comment => \&do_comment,      comment => \&do_comment,
49        RandomJump  => \&do_random_jump,
50      rss => \&do_rss,      rss => \&do_rss,
51      diff => \&do_diff,      diff => \&do_diff,
52      interwikibox => \&do_interwiki_box, # Walrus add (5)      wikiform    => \&do_wikiform,
53        map => \&do_map,
54  );  );
55  ##############################  my $UA = '';  ## User agent name
56  my @ignore_html_page = ('FrontPage');        # Walrus add (6)  $| = 1;
 my @ignore_html_tags = ('a', 'br', 'img');   # Walrus add (6)  
 my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  
 ##############################  
 # &test_convert;  
 &main;  
 exit(0);  
57  ##############################  ##############################
58    
59  sub main {  sub main {
60      &init_resource;      $UA = $main::ENV{HTTP_USER_AGENT};
61      &open_db;      &open_db;
62      &init_form;      &init_form;
     &init_InterWikiName;  
63      if ($command_do{$form{mycmd}}) {      if ($command_do{$form{mycmd}}) {
64          &{$command_do{$form{mycmd}}};          &{$command_do{$form{mycmd}}};
65      } else {      } else {
66          &do_FrontPage;          &{$command_do{read}};
67      }      }
68      &close_db;      &close_db;
69  }  }
70    
71  sub do_read {  sub do_read {
72    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
73      #print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n";
74    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = &get_info($form{mypage}, $info_LastModified);
   &print_header($form{mypage}, -last_modified => $lm);  
75    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
76      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
77      #print gmtime."Search...\n";
78      my ($r, $c) = get_search_result ($form{mypage});
79      my $rl = wiki::referer::list_html ($form{mypage});
80      my @toc;
81      push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;
82      push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;
83      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
84      ## Should be support at least:      ## Should be support at least:
85      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
86      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
87      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
88      $cf = $1 if $content =~ s#^(?:/\*\s*|\#\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
89      if ($cf =~ m#^SuikaWiki/0.9(?:$|\s)#) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
90        &print_content($content, content_format => $cf, last_modified => $lm);      #print gmtime."Header...\n";
91        print &text_to_html (q([[#comment]]));        &print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120,
92            -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
93            #print "\n". gmtime."Body...\n";
94          &print_content ($content, content_format => $cf, last_modified => $lm,
95            -toc => \@toc);
96          print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
97      } else {      } else {
98          &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
99        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
100      }      }
   my ($r, $c) = get_search_result ($form{mypage});  
101      if ($c) {      if ($c) {
102        print q{<h2 id="SEE-ALSO">See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
103        print $r;        print $r;
104      }      }
105    my $r = wiki::referer::list_html ($form{mypage});      if ($rl) {
106      if ($r) {        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
       print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$r</div>\n);  
107      }      }
108            #print "\n". gmtime."Footer...\n";
109    &print_footer($form{mypage}, $lm);    &print_footer($form{mypage}, $lm);
110            #print "\n". gmtime."Fin...\n";
111  }  }
112    
113  sub do_output_css {  sub do_output_css {
114      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
115      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
116    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
117    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
118      print "Content-Type: text/css; charset=$charset\n";      my $lm = gmtime &get_info($form{mypage}, $info_LastModified);
119        print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
120        print "Last-Modified: $lm\n";
121        print "Expires: @{[scalar gmtime time+3600]}\n";    ## TODO: don't use asctime
122      print "\n";      print "\n";
123      print $content;      print $content;
124    } else {    } else {
125      print "Status: 406 Unsupported Media Type\n";      print "Status: 406 Unsupported Media Type\n";
126      &print_header('WikiPageIsNotCSS');      &print_header('WikiPageIsNotCSS', -noindex => 1);
127      &print_content($database{WikiPageIsNotCSS});      &print_content($database{WikiPageIsNotCSS});
128      &print_footer('WikiPageIsNotCSS');      &print_footer('WikiPageIsNotCSS');
129    }    }
130  }  }
131    
132    sub id_and_name ($) {
133        my $name = shift;
134        if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
135          qq{id="$name"><a name="$name"></a};
136        } else {
137            qq{id="$name"};
138        }
139    }
140    
141  sub do_edit {  sub do_edit {
142      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
     &print_header($page);  
143      if (not &is_editable($page)) {      if (not &is_editable($page)) {
144          &print_message($resource{cantchange});          &print_header($page, -noindex => 1);
145            &print_message(&Resource('Error:ThisPageIsUneditable'));
146      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
147          &print_message($resource{cantchange});          &print_header($page, -noindex => 1);
148            &print_message(&Resource('Error:ThisPageIsUneditable'));
149      } else {      } else {
150            &print_header($page, -noindex => 1, -expires => time+60);
151          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
152      }      }
153        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
154        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
155        my ($r, $c) = get_search_result ($form{mypage});
156        my $rl = wiki::referer::list_html ($form{mypage});
157        if ($c) {
158          print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
159          print $r;
160        }
161        if ($rl) {
162          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
163        }
164      &print_footer($page);      &print_footer($page);
165  }  }
166    
167  sub do_adminedit {  sub do_adminedit {
168      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
169      &print_header($page);      &print_header($page, -noindex => 1);
170      if (not &is_editable($page)) {      if (not &is_editable($page)) {
171          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
172      } else {      } else {
173          &print_message($resource{passwordneeded});          &print_message(&Resource('Error:PasswordIsNotSpecified'));
174          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
175      }      }
176      &print_footer($page);      &print_footer($page);
177  }  }
178    
179  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
180      &print_header($AdminChangePassword);      &print_header('AdminChangePassword', -noindex => 1);
181      &print_passwordform;      &print_passwordform;
182      &print_footer($AdminChangePassword);      &print_footer('AdminChangePassword');
183  }  }
184    
185  sub do_adminchangepassword {  sub do_adminchangepassword {
186      if ($form{mynewpassword} ne $form{mynewpassword2}) {      if ($form{mynewpassword} ne $form{mynewpassword2}) {
187          &print_error($resource{passwordmismatcherror});          &print_error(&Resource('Error:PasswordMismatch'));
188      }      }
189      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
190      if ($validpassword_crypt) {      if ($validpassword_crypt) {
191          if (not &valid_password($form{myoldpassword})) {          if (not &valid_password($form{myoldpassword})) {
192              &send_mail_to_admin(<<"EOD", "AdminChangePassword");  #            &send_mail_to_admin(<<"EOD", "AdminChangePassword");
193  myoldpassword=$form{myoldpassword}  #myoldpassword=$form{myoldpassword}
194  mynewpassword=$form{mynewpassword}  #mynewpassword=$form{mynewpassword}
195  mynewpassword2=$form{mynewpassword2}  #mynewpassword2=$form{mynewpassword2}
196  EOD  #EOD
197              &print_error($resource{passworderror});              &print_error(&Resource('Error:PasswordIsIncorrect'));
198          }          }
199      }      }
200      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
# Line 298  EOD Line 202  EOD
202      my $salt1 = $token[(time | $$) % scalar(@token)];      my $salt1 = $token[(time | $$) % scalar(@token)];
203      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
204      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
205      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($PageName{AdminSpecialPage}, 'AdminPassword', $crypted);
206    
207      &print_header($CompletedSuccessfully);      &print_header('CompletedSuccessfully', -noindex => 1);
208      &print_message($resource{passwordchanged});      &print_message(&Resource('Error:PasswordIsChanged'));
209      &print_footer($CompletedSuccessfully);      &print_footer('CompletedSuccessfully');
210  }  }
211    
212  sub do_index {  sub do_index {
213      &print_header($IndexPage);    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
214      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
215        &print_header($PageName{IndexPage});
216      print qq(<ul>);      print qq(<ul>);
217      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
218          if (&is_editable($page)) {          if (&is_editable($page)) {
219              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);              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>);  
220          }          }
221      }      }
222      print qq(</ul>);      print qq(</ul>);
223      &print_footer($IndexPage);      my ($r, $c) = get_search_result ($form{mypage});
224        if ($c) {
225          print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
226          print $r;
227        }
228        my $rl = wiki::referer::list_html ($form{mypage});
229        if ($rl) {
230            print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
231        }
232        &print_footer($PageName{IndexPage});
233  }  }
234    
235  sub do_write {  sub do_write {
# Line 325  sub do_write { Line 238  sub do_write {
238      }      }
239    
240      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
241          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
242          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
243          &print_footer($form{mypage});          &print_footer($form{mypage});
244          return;          return;
245      }      }
# Line 346  sub do_write { Line 259  sub do_write {
259    
260      if ($form{mymsg}) {      if ($form{mymsg}) {
261          $database{$form{mypage}} = $form{mymsg};          $database{$form{mypage}} = $form{mymsg};
262          &send_mail_to_admin($form{mypage}, "Modify");          #&send_mail_to_admin($form{mypage}, "Modify");
263          if ($form{mytouch}) {          if ($form{mytouch}) {
264              &set_info($form{mypage}, $info_LastModified, '' . localtime);              &set_info($form{mypage}, $info_LastModified, time);
265              &update_recent_changes;              &update_recent_changes;
266          }          }
267          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
268          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{comment_index}?"#x-comment-$form{comment_index}":''));          my $fragment = '';
269          &print_message($resource{saved});          $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
270          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          if ($form{__comment_anchor_index}) {
271          &print_footer($CompletedSuccessfully);              $fragment .= qq(#anchor-$form{__comment_anchor_index});
272            } elsif ($form{__wikiform_anchor_index}) {
273                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
274            }
275            &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));
276            &print_message(&Resource('Error:SavedSuccessfully'));
277            &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
278            &print_footer('CompletedSuccessfully');
279      } else {      } else {
280          &send_mail_to_admin($form{mypage}, "Delete");          #&send_mail_to_admin($form{mypage}, "Delete");
281          delete $database{$form{mypage}};          delete $database{$form{mypage}};
282          delete $infobase{$form{mypage}};          delete $infobase{$form{mypage}};
283          if ($form{mytouch}) {          if ($form{mytouch}) {
284              &update_recent_changes;              &update_recent_changes;
285          }          }
286          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
287          &print_message($resource{deleted});          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
288          &print_footer($form{mypage});          &print_footer($form{mypage});
289      }      }
290  }  }
291    
 sub do_searchform {  
     &print_header($SearchPage);  
     &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);  
     &print_footer($SearchPage);  
 }  
   
292  sub get_search_result ($;%) {  sub get_search_result ($;%) {
293    my $word = shift;    my $word = lc shift;
294    my %option = @_;    my %option = @_;
295    my $counter = 0;    my @r;
296    my $r = '';    foreach my $page (keys %database) {
297    foreach my $page (sort keys %database) {      next if !$option{-match_myself} && ($page eq $word);
298      next if $page eq $RecentChanges;      my $content = lc $database{$page};
299      if (   index ($database{$page}, $word) > 0      if (index (lc $page, $word) > -1) {
300          || index ($page, $word) > 0        my $c = $content =~ s/\Q$word\E//g;
301          || index ($word, $page) > 0        push @r, [$page, $c+20];
302         ) {      } elsif (index ($word, lc $page) > -1) {
303        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);        my $c = $content =~ s/\Q$word\E//g;
304        $counter++;        push @r, [$page, $c+10];
305        } elsif (my $c = $content =~ s/\Q$word\E//g) {
306          push @r, [$page, $c];
307      }      }
308    }    }
309    $r = qq|<ul>$r</ul>| if $r;    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
310    get_message ($resource{notfound})    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;
311      if $counter == 0 && $option{-output_not_found};    $r = qq|<ul class="search-result">$r</ul>| if $r;
312    wantarray? ($r, $counter): $r;    wantarray? ($r, scalar @r): $r;
 }  
   
 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);  
313  }  }
314    
315  sub do_FrontPage {  sub do_random_jump {
316      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");    my @list = keys %database;
317      my $content = join('', <FILE>);    my $name = &encode ($list[rand @list]);
318      &code_convert(\$content, $kanjicode);    my $scheme = 'http';
319      close(FILE);    $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
320      &print_header($FrontPage);    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
321      &print_content($content);    print "\n";
     &print_footer($FrontPage);  
322  }  }
323    
324  sub print_error {  sub print_error {
325      my ($msg) = @_;      my ($msg) = @_;
326      &print_header($ErrorPage);      &print_header($PageName{ErrorPage}, -noindex => 1);
327      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
328      &print_footer($ErrorPage);      &print_footer($PageName{ErrorPage});
329      exit(0);      exit(0);
330  }  }
331    
332  sub print_header ($;%) {  sub print_header ($;%) {
333      my ($page, %option) = @_;      my ($page, %option) = @_;
334      my $bodyclass = "normal";      my @head;
335      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
336          $bodyclass = "frozen";      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
337      }      if ($option{-goto}) {
338      print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};        if ($UA =~ m#Opera|MSIE 2\.#) {
339      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};            ## WARNING: This code may output unsafe HTML document if
340      my $cookedpage = &encode($page);            ##          $option{-goto} is not clean.
341      my $escapedpage = &escape($page);            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
342              print qq{Refresh: 0; url=$option{-goto}\n};
343              push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
344          } else {
345              $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
346              print qq{Refresh: 0; url="$option{-goto}"\n};
347              push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
348          }
349        }
350        print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
351        if ($option{-expires}) {
352          print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
353        }
354        if ($UA =~ m#Mozilla/2#) {
355            my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
356            print qq{Content-Type: $ct\n};
357            push @head, qq{<meta http-equiv="content-type" content="$ct">};
358        } elsif ($UA =~ m#Infomosaic#) {
359            print qq{Content-Type: text/html\n};
360        } else {
361            print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
362        }
363        push @head, qq(<title>@{[&escape($page)]}</title>);
364        if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) {
365          push @head, qq(<link rel="stylesheet" type="text/css" href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.&get_info($PageName{DefaultStyleForHTML}, $info_LastModified))]}");
366        }
367        push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
368        my ($Links, $links) = &make_navigate_links ($page);
369        #print $Links;      ## Link: fields
370        $links = join "\n", (@head, $links);
371      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
372  Content-Language: $lang  Content-Language: $lang
373  Content-Style-Type: text/css  Content-Style-Type: text/css
374    
375  <!DOCTYPE html  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
376      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
377      "http://www.w3.org/TR/html4/loose.dtd">  <html lang="$lang" class="$option{body_class}">
378  <html lang="$lang">  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
379  <head>  $links
     <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>  
     <link rel="index" href="$url_cgi?$IndexPage">  
     <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">  
     <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">  
     <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">  
380  </head>  </head>
381  <body class="$bodyclass">  <body class="$option{body_class}">
382  EOD  EOD
383    &print_navigate_links ($page);      &print_navigate_links ($page);
384    print <<EOD;      print <<EOD;
385  <h1 class="header">@{[&escape($page)]}  <h1 class="header">@{[&escape($page)]}</h1>
   <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></h1>  
386  EOD  EOD
387  }  }
388    
389    sub get_charset_name ($;%) {
390        my ($charset, %option) = (lc shift, @_);
391        if ($charset =~ 'euc') {
392            $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
393        } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
394            $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
395        } elsif ($charset =~ 'jis') {
396            $charset = 'iso-2022-jp';
397        }
398        $charset;
399    }
400    
401  sub print_navigate_links (@) {  sub print_navigate_links (@) {
402    my ($page) = @_;    my ($page) = @_;
403      my $editable = 0;    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
404      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);  
405    print <<EOH;    print <<EOH;
406  <div class="tools">  <div class="tools">
     @{[ $admineditable  
         ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )  
         : qq()  
     ]}  
407      @{[ $editable      @{[ $editable
408          ? 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()  
     ]}  
     @{[ $admineditable  
         ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )  
409          : qq()          : qq()
410      ]}      ]}
411      <a href="$url_cgi?$CreatePage">$resource{createbutton}</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> |
412      <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |      <a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
413      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
414      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
415      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |      <a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
416      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
417        <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> |
418        <a href="$url_cgi?RecentChanges" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
419  </div>  </div>
420  EOH  EOH
421  }  }
422    
423    sub make_navigate_links ($) {
424        my $page = shift;
425        my @link;
426        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);
427        push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);
428        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')};
429        push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
430        push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
431        push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')};
432        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
433        push @link, {rel=>'News', href=>"$url_cgi?RecentChanges", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
434        push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
435        push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
436        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
437        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
438        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')};
439        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')};
440        push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
441        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};
442        push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'};
443        push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
444        my ($Links, $links) = ('', '');
445        for my $e (@link) {
446            $links .= qq(<link);
447            $Links .= qq(Link: <$e->{href}>);
448            for my $attr (qw/rel rev href title class type hreflang charset/) {
449                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
450            }
451            for my $attr (qw/rel rev title/) {
452                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
453            }
454            $links .= qq(>\n);
455            $Links .= qq(\n);
456        }
457        wantarray ? ($Links, $links) : $Links;
458    }
459    
460  sub print_footer {  sub print_footer {
461      my ($page, $lm) = @_;      my ($page, $lm) = @_;
462      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)      my $epage = &encode ($page);
463      # Walrus mod (1) start    my $cvslog1 = q$Revision$;
464    my $cvslog = '$Revision$ $Date$';    my $cvslog2 = q$Date$;
465    print_navigate_links ($page);    print_navigate_links ($page);
466    print <<"EOD";    print <<"EOD";
467  @{[ $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>) : '' ]}
468  <div class="footer">  <div class="footer">
469  <p>  <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>
470  <a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />  <a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
 based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository">  
 $cvslog  
 </a>  
 </p>  
 <div class="navigation">  
 [<a href="/" title="このサーバーの首頁">/</a>  
 <a href="/map" title="このサーバーの案内">地図</a>  
 <a href="/search/" title="このサーバーの検索">検索</a>]  
471  </div>  </div>
 </div>  
 $walrus_log  
472  </body>  </body>
473  </html>  </html>
474  EOD  EOD
 #       print <<"EOD";  
 #   <hr>  
 #   <address class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version  
 #       &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 #       Modified by <a href="$modifier_url">$modifier_name</a>.  
 #   </address>  
 #   <p class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">$icontag</a>  
 #   </p>  
 #   </body>  
 #   </html>  
 #   EOD  
     # Walrus mod (1) end  
475  }  }
476    
477  sub escape {  sub escape {
# Line 572  sub unescape { Line 496  sub unescape {
496    
497  sub print_content ($;$) {  sub print_content ($;$) {
498      my ($rawcontent, %option) = @_;      my ($rawcontent, %option) = @_;
499      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
500  }  }
501    
502  sub text_to_html {  sub text_to_html {
503      my ($txt, %option) = @_;      my ($txt, %option) = @_;
504      my (@txt) = split(/\n/, $txt);      my @toc;
505      my (@toc);      my @toc2 = @{$option{-toc}||[]};
506      my $tocnum = 0;      my $tocnum = 0;
507        
508        ## Load constants
509        my %const;
510        if ($option{content_format} =~ /import="([^"]+)"/) {
511          for (split /\s*,\s*/, $1) {
512            my $wp = $database{$_};
513            if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
514              wiki::suikawikiconst::to_hash ($wp => \%const);
515            }
516          }
517        }
518        
519        $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
520        my (@txt) = split(/\n/, $txt);
521      my (@saved, @result);      my (@saved, @result);
522      unshift(@saved, "</p>");      unshift(@saved, "</p>");
523      push(@result, "<p>");      push(@result, "<p>");
# Line 587  sub text_to_html { Line 525  sub text_to_html {
525          chomp;          chomp;
526          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
527              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
528              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
529              $tocnum++;              $tocnum++;
530          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
531              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
532              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
533              $tocnum++;              $tocnum++;
534          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
535              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
536              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
537              $tocnum++;              $tocnum++;
538          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
539          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
540          # Walrus mod (6) end          # Walrus mod (6) end
541              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
542              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
543              $tocnum++;              $tocnum++;
544          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
545              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
546              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
547              $tocnum++;              $tocnum++;
548          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
549              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
550              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
551          } elsif (/^(-{1,6})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
552              &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
553              push(@result, '<li>' . &inline($2) . '</li>');            my ($pf, $l) = ('', $2);
554              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
555                my $num = 0+$1;
556                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
557              }
558              push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
559          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
560              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
561              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
562          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
563              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
564              push(@result, &inline($2));              push @result, "<p>";
565                push(@result, &inline($2, const => \%const));
566                unshift @saved, "</p>";
567          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
568              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
569              push(@result, "<p>");              push(@result, "<p>");
570                unshift(@saved, "</p>");
571          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
572              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
573              #push(@result, &escape($1)); # Not &inline, but &escape              push(@result, &inline($1, const => \%const));
574              push(@result, &inline($1));          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
575  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)              &back_push('table', 1, \@saved, \@result);
         } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)  
             &back_push('table', 1, \@saved, \@result, ' border="1"');  
576              #######              #######
577              # 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.
578              # XXXXX              # XXXXX
# Line 643  sub text_to_html { Line 586  sub text_to_html {
586                          $colspan[$i]++;                          $colspan[$i]++;
587                      }                      }
588                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
589                      $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));
590                  } else {                  } else {
591                      $value[$i] = '';                      $value[$i] = '';
592                  }                  }
# Line 651  sub text_to_html { Line 594  sub text_to_html {
594              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
595              # XXXXX              # XXXXX
596              #######              #######
597          } elsif (/^\[INS\[/) {          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
598              push(@result, "<ins>");              push @result, splice (@saved), '<'.lc($1).'>';
599          } elsif (/^\]INS\]/) {              unshift @saved, "</p>";
600              push(@result, "</ins>");              push @result, "<p>";
601          } elsif (/^\[DEL\[/) {          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
602              push(@result, "<del>");              push @result, splice (@saved), '</'.lc($1).'>';
603          } elsif (/^\]DEL\]/) {          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
604              push(@result, "</del>");            my $num = 0+$1;
605          } elsif (/^\[PRE\[/) {            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
606              push(@result, "<pre>");            push @result, &inline ($2, const => \%const);
         } elsif (/^\]PRE\]/) {  
             push(@result, "</pre>");  
607          } else {          } else {
608              push(@result, &inline($_));              push(@result, &inline($_, const => \%const));
609          }          }
610      }      }
611      push(@result, splice(@saved));      push(@result, splice(@saved));
# Line 674  sub text_to_html { Line 615  sub text_to_html {
615          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
616          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
617          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
618          foreach (@toc) {          foreach (@toc,@toc2) {
619              if (/^(-{1,6})(.*)$/) {              if (/^(-{1,6})(.*)$/) {
620                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
621                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
# Line 684  sub text_to_html { Line 625  sub text_to_html {
625          $toc = join("\n", @tocresult);          $toc = join("\n", @tocresult);
626          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
627      }      }
628      return $toc . join("\n", @result);      $toc .= join("\n", @result);
629        $toc =~ s#<p>\n</p>##g;
630        $toc =~ s#[\x0D\x0A]+</#</#g;
631        $toc =~ s#<pre>\n#<pre>#g;
632        $toc;
633  }  }
634    
635  sub back_push {  sub back_push {
# Line 701  sub back_push { Line 646  sub back_push {
646      }      }
647  }  }
648    
649  sub inline {  sub inline ($;%) {
650      my ($line) = @_;      my ($line, %option) = @_;
651      $line = &escape($line);      $line = &escape($line);
652      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
653      $line =~ s|''([^']+?)''|<em>$1</em>|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;
654      $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g;   # Date      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
655      $line =~ s!      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
656        (      $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;
657          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
658        |      $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;
659          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
660        |      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
661          ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]      $line =~ s|''([^']+)''|<em>$1</em>|g;
662        #|      $line =~ s{
663        #  ($wiki_name)        (\[\[(\#\S+?)\]\])
664        )        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
665              !        |&gt;&gt;([0-9]+)
666                  &make_link($1)        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
667              !gex;      }{
668          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
669          if ($l) {
670            return &embedded_to_html($1);
671          } elsif (defined $page) {
672            &make_wikilink ($page, anchor => 0+$anchor);
673          } elsif ($anum) {
674            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
675          } elsif ($uri) {
676            &make_urilink ($uri);
677          }
678        }gex;
679      return $line;      return $line;
680  }  }
681    
682  sub make_link {  sub make_wikilink ($%) {
683      my $chunk = shift;    my ($ename, %option) = @_;
684      # Walrus add (3) start    my $name = &unescape ($ename);
685      $chunk =~ s/^&lt;(.*)&gt;$/$1/;    if ($database{$name}) {
686      my $name  = $chunk;      my $subject = &escape (&get_subjectline ($name, delimiter => ''));
687      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {      if ($option{anchor}) {
688          ($name, $chunk) = ($1, $2);        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
689      } elsif ($chunk =~ /^mailto:(.*)$/) {      } else {
690          $name = $1;        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
     }  
     if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {  
         $name = qq(<img src="$name">) ;  
     }  
     $name = &unarmor_name($name);  
     # Walrus add (3) end  
     if ($chunk =~ /^(http|https|ftp|news):/) {  
         # Walrus mod (3) start  
 #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  
 #           return qq(<a href="$chunk"><img src="$chunk"></a>);  
 #       } else {  
 #           return qq(<a href="$chunk">$chunk</a>);  
 #       }  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);  
         # Walrus mod (3) end  
     } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {  
         return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;  
     } elsif ($chunk =~ /^mailto:(.*)/) {  
 #       return qq(<a href="$chunk">$2</a>);                 # Walrus del (3)  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);              # Walrus add (3)  
     } elsif ($chunk =~ /^$interwiki_definition$/) {  
 #       return qq(<span class="InterWiki">$chunk</span>);   # Walrus del (3)  
         return qq(<span class="InterWiki">$name</span>);    # Walrus add (3)  
     } elsif ($chunk =~ /^$embedded_name$/) {  
         return &embedded_to_html($chunk);  
     } else {  
         $chunk = &unarmor_name($chunk);  
         $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.  
         my $cookedchunk = &encode($chunk);  
         if ($chunk =~ /^$interwiki_name$/) {  
             my ($intername, $localname) = ($1, $2);  
             my $remoteurl = $interwiki{$intername};  
             if ($remoteurl) {  
 #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)  
                 $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)  
 #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  
                 return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)  
             } else {  
 #               return $chunk;                              # Walrus del (3)  
                 return &escape($name);                               # Walrus add (3)  
             }  
         } elsif ($database{$chunk}) {  
             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>);  
         }  
691      }      }
692      } else {
693        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>);
694      }
695  }  }
696    
697  sub print_message {  sub make_urilink ($;%) {
698      my ($msg) = @_;    require URI;
699      print qq(<p><strong>$msg</strong></p>);    my $uri = shift;
700      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
701        $uri = &unescape ($uri);
702        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
703          my ($site, $name) = ($1, $2);
704          for ($site, $name) {
705            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
706          }
707          &init_InterWikiName () unless $interwiki{'[[]]'};
708          if ($interwiki{$site}) {
709            &load_formatter ('interwiki');
710            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
711            $site = &escape ($site); $name = &escape ($name);
712            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;);
713          } else {
714            qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
715          }
716        } else {
717          qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
718        }
719      } elsif ($uri =~ /^urn:/) {   ## URN
720        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
721        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
722      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
723        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
724        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
725      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
726        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
727        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
728      } else {      ## misc. URI
729        CGI::Carp::warningsToBrowser (0);
730        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
731        CGI::Carp::warningsToBrowser (1);
732        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
733      }
734  }  }
735    
736  sub get_message {  {my $FormIndex = 0;
737    sub make_custom_form ($$$$) {
738        my ($wfname, $definition, $template, $option) = @_;
739        ## $template and $option is currently not used in this procedure.
740        unless ($main::_EMBEDED) {
741            $FormIndex++;
742            if (length $definition) {
743                my $param = bless {}, 'SuikaWiki::Plugin';
744                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
745                &load_formatter (qw/form_input form_option/);
746                $definition = &unescape ($definition);
747                $definition =~ s/\\(.)/$1/g;
748                $option = &unescape ($option);
749                $option =~ s/\\(.)/$1/g;
750                $fmt{form_option}->replace ($option, $param);
751                $param->{output}->{form} = 1 unless defined $param->{output}->{form};
752                $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
753                my $target_page = $param->{output}->{page} || $form{mypage};
754                $param->{form_disabled} = 1 if $fixedpage{$target_page};
755                my $target_form = $param->{output}->{id};
756                my $r = '';
757                $r = <<EOH if $param->{output}->{form};
758    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
759      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
760      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
761      <input type="hidden" name="myLastModified" value="$lastmodified">
762      <input type="hidden" name="mytouch" value="on">
763      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
764    EOH
765                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
766                $r .= $fmt{form_input}->replace ($definition, $param);
767                $r .= "</form>\n" if $param->{output}->{form};
768                $r;
769           } else {  ## No input-interface WikiForm
770               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
771           }
772        } else {
773            qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
774        }
775    }}
776    
777    sub print_message {
778      my ($msg) = @_;      my ($msg) = @_;
779      qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
780  }  }
781    
782  sub init_form {  sub init_form {
783      if (param()) {      ## TODO: Support multipart/form-data
784          foreach my $var (param()) {      my $query = '';
785              $form{$var} = param($var);      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
786          }        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
787      } else {      }
788          $ENV{QUERY_STRING} = $FrontPage;      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
789      }      if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
790          my $query = &decode($main::ENV{QUERY_STRING});
791      my $query = &decode($ENV{QUERY_STRING});        $query = &code_convert(\$query, $kanjicode);
792      if ($page_command{$query}) {        if ($page_command{$query}) {
793          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
794          $form{mypage} = $query;          $form{mypage} = $query;
795      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
796          $form{mypage} = $query;          $form{mypage} = $query;
797            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
798          }
799        } else {
800          for (split /[;&]/, $query) {
801            if (my ($n, $v) = split /=/, $_, 2) {
802              for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
803              $form{$n} = $v;
804            }
805          }
806          unless (defined $form{mypage}) {
807            $form{mypage} = $form{epage};
808            $form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g;
809          }
810          if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
811            $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
812            $form{mycmd} = $page_command{$form{mypage}};
813          }
814      }      }
815        $form{mypage} ||= 'HomePage';
816        $form{mycmd} ||= 'read';
817    
818      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
819      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 827  sub init_form { Line 825  sub init_form {
825          }          }
826      }      }
827    
828      #      #
829      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
830      #      #
831    
832        for (grep /^wikiform__/, keys %form) {
833            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
834        }
835      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
836      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
837  }  }
838    
839  sub update_recent_changes {  sub update_recent_changes {
840      my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}";
841      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges});
842        shift @oldupdates; ## '#?' magic line
843      my @updates;      my @updates;
844      foreach (@oldupdates) {      foreach (@oldupdates) {
845          /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/;    # date format.          /^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/;
846          my $name = &unarmor_name($1);          my $name = $1;
847          if (&is_exist_page($name) and ($name ne $form{mypage})) {          if ($name ne $form{mypage}) {
848              push(@updates, $_);              push @updates, $_;
849          }          }
850      }      }
851      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
852          unshift(@updates, $update);        unshift @updates, $update;
853      }      }
854      splice(@updates, $maxrecent + 1);      splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1;
855      $database{$RecentChanges} = join("\n", @updates);      $database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
856      if ($file_touch) {      if ($PathTo{TouchFile}) {
857          open(FILE, "> $file_touch");          open(FILE, "> ".$PathTo{TouchFile});
858          print FILE localtime() . "\n";          print FILE localtime() . "\n";
859          close(FILE);          close(FILE);
860      }      }
861  }  }
862    
863    {my %SubjectLine;
864  sub get_subjectline {  sub get_subjectline {
865      my ($page, %option) = @_;      my ($page, %option) = @_;
866      if (not &is_editable($page)) {      unless (defined $SubjectLine{$page}) {
867          return "";        if (not &is_editable($page)) {
868            $SubjectLine{$page} = "";
869          } else {
870            $SubjectLine{$page} = $database{$page};
871            $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
872            $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
873          }
874        }
875        if (length $SubjectLine{$page}) {
876          $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
877          $option{delimiter}.$SubjectLine{$page}.$option{tail};
878      } else {      } else {
879          # 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};  
880      }      }
881  }  }}
   
 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);  
 }  
882    
883  sub open_db {  sub open_db {
884      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
885          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");          dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}");
886          dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");          dbmopen(%infobase, $PathTo{WikiInfoBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiInfoBase}");
887      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
888          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");          eval q{use AnyDBM_File};
889          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}");
890      } else {          tie(%infobase, "AnyDBM_File", $PathTo{WikiInfoBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiInfoBase}");
891          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");      } else {
892          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");          eval q{use Yuki::YukiWikiDB};
893            tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}");
894            tie(%infobase, "Yuki::YukiWikiDB", $PathTo{WikiInfoBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiInfoBase}");
895      }      }
896  }  }
897    
# Line 932  sub close_db { Line 910  sub close_db {
910    
911  sub open_diff {  sub open_diff {
912      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
913          dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");          dbmopen(%diffbase, $PathTo{WikiDiffBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDiffBase}");
914      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
915          tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");          tie(%diffbase, "AnyDBM_File", $PathTo{WikiDiffBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDiffBase}");
916      } else {      } else {
917          tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");          tie(%diffbase, "Yuki::YukiWikiDB", $PathTo{WikiDiffBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDiffBase}");
918      }      }
919  }  }
920    
# Line 950  sub close_diff { Line 928  sub close_diff {
928      }      }
929  }  }
930    
 sub print_searchform {  
     my ($word) = @_;  
     print <<"EOD";  
 <form action="$url_cgi" method="get">  
     <input type="hidden" name="mycmd" value="search">  
     <input type="text" name="mymsg" value="$word" size="20">  
     <input type="submit" value="$resource{searchbutton}">  
 </form>  
 EOD  
 }  
   
931  sub print_editform {  sub print_editform {
932      my ($mymsg, $lastmodified, %mode) = @_;      my ($mymsg, $lastmodified, %mode) = @_;
933      my $frozen = &is_frozen($form{mypage});      my $frozen = &is_frozen($form{mypage});
# Line 968  sub print_editform { Line 935  sub print_editform {
935      if ($form{mypreview}) {      if ($form{mypreview}) {
936          if ($form{mymsg}) {          if ($form{mymsg}) {
937              unless ($mode{conflict}) {              unless ($mode{conflict}) {
938                  print qq(<h3>$resource{previewtitle}</h3>\n);                  print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);
939                  print qq($resource{previewnotice}\n);                  print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);
940                  print qq(<div class="preview">\n);                  print qq(<div class="preview">\n);
941                  &print_content($form{mymsg});                  &print_content($form{mymsg});
942                  print qq(</div>\n);                  print qq(</div>\n);
943              }              }
944          } else {          } else {
945              print qq($resource{previewempty});              print @{[&Resource('Preview:Empty',escape=>1)]};
946          }          }
947          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
948      } else {      } else {
949          $mymsg = &escape($mymsg || $database{NewPageTemplate});          $mymsg = &escape($mymsg || $database{NewPageTemplate});
950      }      }
951        my $magic = '';
952        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
953    
954      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
955      my $escapedmypage = &escape($form{mypage});      my $escapedmypage = &escape($form{mypage});
956      my $escapedmypassword = &escape($form{mypassword});      my $escapedmypassword = &escape($form{mypassword});
957        my $selected = 'read';
958        if ($form{after_edit_cmd}) {
959            $selected = $form{after_edit_cmd};
960        } elsif ($magic =~ /Const|Config|CSS/) {
961            $selected = 'edit';
962        }
963        my $afteredit = <<EOH;
964    <select name="after_edit_cmd">
965    <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
966    <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
967    </select>
968    EOH
969    
970      print <<"EOD";      print <<"EOD";
971  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
972      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}  <h2>@{[&Resource('Edit:Title',escape=>1)]}</h2>
973        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]}
974        @{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="$escapedmypassword" size="10"></label>) : "" ]} [@{[do {my $n = 0;
975                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
976                   ++$n}]}]<br>
977      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
978      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="$escapedmypage">
979      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>      <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">$mymsg</textarea><br>
980  @{[  @{[
981      $mode{admin} ?      $mode{admin} ?
982      qq(      qq(
983      <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>
984      <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>)
985      : ""      : ""
986  ]}  ]}
987  @{[  @{[
988      $mode{conflict} ? "" :      $mode{conflict} ? "" :
989      qq(      qq(
990          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}<br>
991          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}">
992          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>          <input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd>
993           $afteredit
994           <br>
995      )      )
996  ]}  ]}
997  </form>  </form>
998  EOD  EOD
999      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1000          # Show the format rule.          ## Show help text
1001          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{WikiEditHelp};
1002          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1003          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
         close(FILE);  
         print &text_to_html($content, toc=>0);  
1004      }      }
1005  }  }
1006    
# Line 1023  sub print_passwordform { Line 1008  sub print_passwordform {
1008          print <<"EOD";          print <<"EOD";
1009  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1010      <input type="hidden" name="mycmd" value="adminchangepassword">      <input type="hidden" name="mycmd" value="adminchangepassword">
1011      $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>      <label>@{[&Resource('Password:Old=',escape=>1)]}<input type="password" name="myoldpassword" size="10"></label><br>
1012      $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>      <label>@{[&Resource('Password:New1=',escape=>1)]}<input type="password" name="mynewpassword" size="10"></label><br>
1013      $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>      <label>@{[&Resource('Password:New2=',escape=>1)]}<input type="password" name="mynewpassword2" size="10"></label><br>
1014      <input type="submit" value="$resource{changepasswordbutton}"><br>      <input type="submit" value="@{[&Resource('WikiForm:Change',escape=>1)]}"><br>
1015  </form>  </form>
1016  EOD  EOD
1017  }  }
1018    
1019  sub is_editable {  sub is_editable {
1020      my ($page) = @_;      my ($page) = @_;
1021      if (&is_bracket_name($page)) {      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
         return 0;  
     } elsif ($fixedpage{$page}) {  
         return 0;  
     } elsif ($page =~ /\s/) {  
         return 0;  
     } elsif ($page =~ /^\#/) {  
         return 0;  
     } elsif ($page =~ /^$interwiki_name$/) {  
1022          return 0;          return 0;
1023      } else {      } else {
1024          return 1;          return 1;
# Line 1051  sub is_editable { Line 1028  sub is_editable {
1028  # armor_name:  # armor_name:
1029  #   WikiName -> WikiName  #   WikiName -> WikiName
1030  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1031  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     #if ($name =~ /^$wiki_name$/) {  
     #    return $name;  
     #} else {  
         return "[[$name]]";  
     #}  
 }  
1032    
1033  # unarmor_name:  # unarmor_name:
1034  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
1035  #   WikiName -> WikiName  #   WikiName -> WikiName
1036  sub unarmor_name {  sub unarmor_name {
1037      my ($name) = @_;      my ($name) = @_;
1038      if ($name =~ /^$bracket_name$/) {      if ($name =~ /^\[\[(\S+?)\]\]$/) {
1039          return $1;          return $1;
1040      } else {      } else {
1041          return $name;          return $name;
1042      }      }
1043  }  }
1044    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1045  sub decode {  sub decode {
1046      my ($s) = @_;      my ($s) = @_;
1047      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1101  sub encode { Line 1062  sub encode {
1062      return $encoded;      return $encoded;
1063  }  }
1064    
 sub init_resource {  
     open(FILE, $file_resource) or &print_error("(resource)");  
     while (<FILE>) {  
         chomp;  
         next if /^#/;  
         my ($key, $value) = split(/=/, $_, 2);  
         $resource{$key} = &code_convert(\$value, $kanjicode);  
     }  
     close(FILE);  
 }  
   
1065  sub conflict {  sub conflict {
1066      my ($page, $rawmsg) = @_;      my ($page, $rawmsg) = @_;
1067      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1068          return 0;          return 0;
1069      }      }
1070      open(FILE, $file_conflict) or &print_error("(conflict)");      &print_header($page, -noindex => 1);
1071      my $content = join('', <FILE>);      &print_content(&Resource('Error:Conflict'));
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
     &print_header($page);  
     &print_content($content);  
1072      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1073      &print_footer($page);      &print_footer($page);
1074      return 1;      return 1;
1075  }  }
1076    
1077  sub get_now {  sub get_now {
1078      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);  
1079      $year += 1900;      $year += 1900;
1080      $mon++;      $mon++;
1081      $mon = "0$mon" if $mon < 10;      $mon = "0$mon" if $mon < 10;
1082      $day = "0$day" if $day < 10;      $day = "0$day" if $day < 10;
1083      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1084      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1085      $sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1086      $weekday = $week[$weekday];      return "$year-$mon-$day $hour:$min";
     return "$year-$mon-$day ($weekday) $hour:$min:$sec";  
1087  }  }
1088    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1089  sub init_InterWikiName {  sub init_InterWikiName {
1090      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{InterWikiName};
1091      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1092          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1093          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1094      }      }
1095      }
1096      $interwiki{'[[]]'} = 1;       ## dummy
1097  }  }
1098    
 sub interwiki_convert {  
     my ($type, $localname) = @_;  
     if ($type eq 'sjis' or $type eq 'euc') {  
         &code_convert(\$localname, $type);  
         return &encode($localname);  
     } elsif ($type eq 'ykwk') {  
         # for YukiWiki1  
         if ($localname =~ /^$wiki_name$/) {  
             return $localname;  
         } else {  
             &code_convert(\$localname, 'sjis');  
             return &encode("[[" . $localname . "]]");  
         }  
     } elsif ($type eq 'asis') {  
         return $localname;  
     # Walrus add (4) start  
     } elsif ($type eq 'isbn') {  
         $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/);  
         return $localname;  
     # Walrus add (4) end  
     } else {  
         return $localname;  
     }  
 }  
1099    
1100  sub get_info {  sub get_info {
1101      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1203  sub frozen_reject { Line 1124  sub frozen_reject {
1124          # You are admin.          # You are admin.
1125          return 0;          return 0;
1126      } else {      } else {
1127          &print_error($resource{passworderror});          &print_error(&Resource('Error:PasswordIsIncorrect'));
1128          return 1;          return 1;
1129      }      }
1130  }  }
1131    
1132  sub valid_password {  sub valid_password {
1133      my ($givenpassword) = @_;      my ($givenpassword) = @_;
1134      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
1135      if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {      if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1136          return 1;          return 1;
1137      } else {      } else {
# Line 1229  sub is_frozen { Line 1150  sub is_frozen {
1150    
1151  sub do_comment {  sub do_comment {
1152      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1153      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1154      my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'' : ";      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1155      #if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      my $datestr = '[WEAK['.&get_now.']]';
1156      #  ;      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
1157      #} else {      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1158      #  $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;      if ($namestr =~ /^(?:>>)?[0-9]/) {
1159      #}        $namestr = qq( ''$namestr'': );
1160        } elsif (length $namestr) {
1161          $namestr = qq( ''[[$namestr]]'': );
1162        }
1163        my $anchor = &get_new_anchor_index ($content);
1164      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1165      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\[\[\#r?comment\]\])}{
1166        my $embed = $1;        my $embed = $1;
1167        if ($i == $form{comment_index}) {        if ($i == $form{comment_index}) {
1168          if ($embed eq $embed_comment) {          if ($embed ne '[[#rcomment]]') {
1169            $embed = "- $datestr$namestr$form{mymsg}\n$embed";  $o = 1;            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1170          } else {          } else {
1171            $embed .= "\n- $datestr$namestr$form{mymsg}";  $o = 1;            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1172          }          }
1173        }        }
1174        $i++; $embed;        $i++; $embed;
1175      }ge;      }ge;
1176      unless ($o) {      unless ($o) {
1177        $content .= "- $datestr$namestr$form{mymsg}\n";        $content = "#?SuikaWiki/0.9\n\n" unless $content;
1178          $content .= "\n" unless $content =~ /\n$/s;
1179          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1180      }      }
1181      if ($form{mymsg}) {      $form{__comment_anchor_index} = $anchor;
1182        if ($form{mymsg} || $form{myname}) {
1183          $form{mymsg} = $content;          $form{mymsg} = $content;
1184          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1185          &do_write;          &do_write;
# Line 1261  sub do_comment { Line 1189  sub do_comment {
1189      }      }
1190  }  }
1191    
1192    sub get_new_anchor_index ($) {
1193        my $content = shift;
1194        my $anchor = 0;
1195        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1196        $anchor + 1;
1197    }
1198    
1199  my $CommentIndex = 0;  my $CommentIndex = 0;
1200  sub embedded_to_html {  sub embedded_to_html {
1201      my ($embedded) = @_;      my ($embedded) = @_;
1202      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
1203          unless ($main::_EMBEDED) {
1204          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1205          return <<"EOD";          return <<"EOD";
1206  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1207      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1208      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1209      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1210      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1211      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
1212      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1213      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10" class="comment-name">
1214      <input type="text" name="mymsg" value="" size="60">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1215      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
1216  </form>  </p></form>
1217    EOD
1218         } else {
1219            return <<"EOD";
1220    <del><form action="$url_cgi" method="get">
1221        <input type="hidden" name="mycmd" value="read">
1222        <input type="hidden" name="mypage" value="$form{mypage}">
1223        @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1224        <input type="text" name="myname" value="" size="10" disabled="disabled">
1225        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1226    </form></del>
1227  EOD  EOD
1228        }
1229    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1230      return get_search_result ($1);      return get_search_result ($1, -match_myself => 1);
1231      # Walrus add (5) start    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1232      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      my ($name, $r) = ($1, '');
1233          $_ = &make_interwiki_box($1, $2);      if ($main::_EMBEDED != 1) {
1234          return ($_) ? $_ : $embedded;        my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1235      # Walrus add (5) end        $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1236      } else {        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1237          return $embedded;          $main::_EMBEDED = 1;
1238            $r = &text_to_html ($content, content_format => $cf);
1239            $main::_EMBEDED = 0;
1240          } elsif (length $content) {
1241            $r = "<pre>@{[&escape ($content)]}</pre>";
1242          } else {
1243            $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1244          }
1245        } else {    ## nested #EMBED
1246          $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1247      }      }
1248        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>);
1249      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1250        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1251      } else {
1252        return $embedded;
1253      }
1254  }  }
1255    
1256  # Walrus add (5) start  sub load_formatter (@) {
1257  sub do_interwiki_box {      for my $t (@_) {
1258      my $remoteurl = $interwiki{$form{'myintername'}};          unless ($fmt{$t}) {
1259      if ($remoteurl) {              require Message::Util::Formatter;
1260          $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;              $fmt{$t} = Message::Util::Formatter->new;
1261          print "Location: $remoteurl\n\n";              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1262          exit(1);                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1263      } else {              }
1264          &do_read;          }
1265      }      }
1266  }  }
 # Walrus add (5) end  
1267    
1268  # Walrus add (5) start  sub do_wikiform {
1269  sub make_interwiki_box {      my $content = $database{$form{mypage}};
1270      my ($localname, $intername) = @_;      my $anchor = &get_new_anchor_index ($content);
1271      my %ignoretype = (      &load_formatter (qw/form_template form_option/);
1272          'box'      => 'text',      my $write = 0;
1273          'text'     => 'text',      my $i = 1;
1274          'pass'     => 'password',      $content =~ s{$embed_command{form}}{
1275          'password' => 'password'          my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1276      );          if (($wfname && $wfname eq $form{wikiform_targetform})
1277      my $converted = ($ignoretype{$localname}) ? <<EOD : undef;              || $i == $form{wikiform_index}) {
1278  <form action="$url_cgi" method="post">              $template =~ s/\\(.)/$1/g;
1279      <input type="hidden" name="mycmd" value="interwikibox">              $option =~ s/\\(.)/$1/g;
1280      <input type="hidden" name="mypage" value="$form{mypage}">              my $param = bless {}, 'SuikaWiki::Plugin';
1281      <input type="hidden" name="myintername" value="$intername">              $param->{page} = $form{mypage};
1282      $intername:              $param->{form_index} = $i;
1283      <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">              $param->{form_name} = $wfname;
1284      <input type="submit" value="Submit">              $param->{anchor_index} = $anchor;
1285  </form>              $param->{argv} = \%form;
1286  EOD              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1287                $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1288                $fmt{form_option}->replace ($option, $param);
1289                my $t = 1;
1290                for (@{$param->{require}||[]}) {
1291                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1292                }
1293                $t = $fmt{form_template}->replace ($template, $param) if $t;
1294                if (length $t) {
1295                    if ($param->{output}->{reverse}) {
1296                        $embed .= "\n" . $t;
1297                    } else {
1298                        $embed = $t . "\n" . $embed;
1299                    }
1300                    $write = 1;
1301                    $form{__comment_anchor_index} = $anchor
1302                      if $param->{anchor_index_};  ## $anchor is used!
1303                }
1304                $form{__wikiform_anchor_index} = $i;
1305                undef $form{wikiform_targetform};  ## make sure never to match
1306                undef $form{wikiform_index};       ## with WikiForm in rest of page
1307            }
1308            $i++; $embed;
1309        }ge;
1310        unless ($write) {
1311          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1312          #$content .= "\n" unless $content =~ /\n$/s;
1313          #
1314        }
1315        if ($write) {
1316            $form{mymsg} = $content;
1317            $form{mytouch} = 'on';
1318            &do_write;
1319        } else {
1320            $form{mycmd} = 'read';
1321            &do_read;
1322        }
1323  }  }
 # Walrus add (5) end  
1324    
1325  sub code_convert {  sub code_convert {
1326      require Jcode;
1327      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1328  #   &Jcode::convert($contentref, $code);       # for Jcode.pm      $code = 'jis' if $code =~ /iso/;
1329      &jcode::convert($contentref, $code);       # for jcode.pl      $code = 'euc' if $code =~ /euc/;
1330        $code = 'sjis' if $code =~ /shift/;
1331        $code = 'utf8' if $code =~ /utf/;
1332        #&Jcode::convert($contentref, $code);       # for Jcode.pm
1333    #    &jcode::convert($contentref, $code);       # for jcode.pl
1334        #&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';
1335        $$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;
1336      return $$contentref;      return $$contentref;
1337  }  }
1338    
 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;  
 }  
   
1339  sub do_diff {  sub do_diff {
1340      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
1341          &do_read;          &do_read;
# Line 1403  sub do_diff { Line 1343  sub do_diff {
1343      }      }
1344      &open_diff;      &open_diff;
1345      my $title = $form{mypage};      my $title = $form{mypage};
1346      &print_header($title);      &print_header($title, -noindex => 1);
1347      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1348      &close_diff;      &close_diff;
1349      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>);
1350      print qq($resource{diffnotice});      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1351      print qq(<pre class="diff">);      print qq(<pre class="diff">);
1352      foreach (split(/\n/, $_)) {      foreach (split(/\n/, $_)) {
1353          if (/^\+(.*)/) {          if (/^\+(.*)/) {
1354              print qq(<b class="added">$1</b>\n);              print qq(<ins class="added">$1</ins>\n);
1355          } elsif (/^\-(.*)/) {          } elsif (/^\-(.*)/) {
1356              print qq(<s class="deleted">$1</s>\n);              print qq(<del class="deleted">$1</del>\n);
1357          } elsif (/^\=(.*)/) {          } elsif (/^\=(.*)/) {
1358              print qq(<span class="same">$1</span>\n);              print qq(<span class="same">$1</span>\n);
1359          } else {          } else {
# Line 1421  sub do_diff { Line 1361  sub do_diff {
1361          }          }
1362      }      }
1363      print qq(</pre>);      print qq(</pre>);
     print qq(<hr>);  
1364      &print_footer($title);      &print_footer($title);
1365  }  }
1366    
1367  sub do_rss {  sub do_rss {
1368        eval q{use Yuki::RSS};
1369      my $rss = new Yuki::RSS(      my $rss = new Yuki::RSS(
1370          version => '1.0',          version => '1.0',
1371          encoding => $charset,          encoding => &get_charset_name ($kanjicode),
1372        );
1373        my $scheme = 'http';
1374        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1375        my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1376        $rss->stylesheet (
1377          href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1378          type      => 'text/css',
1379      );      );
1380      $rss->channel(      $rss->channel(
1381          title => $modifier_rss_title,          title   => &Resource ('RSS:WikiTitle'),
1382          link  => $modifier_rss_link,          link    => $myuri,
1383          description => $modifier_rss_description,          description     => &Resource ('RSS:WikiDescription'),
1384            'dc:language'   => $lang,
1385      );      );
1386      my $recentchanges = $database{$RecentChanges};      my $recentchanges = $database{RecentChanges};
1387      my $count = 0;      my $count = 0;
1388      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1389          last if ($count >= 15);          last if ($count >= 15);
1390          /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/;    # date format.          if (/\[\[([^]]+)\]\]/) {
1391          my $title = &unarmor_name($1);            my $title = $1;
1392          my $escaped_title = &escape($title);            $rss->add_item (
1393          my $link = $modifier_rss_link . '?' . &encode($title);              title       => &escape($title),
1394          my $description = $escaped_title . &escape(&get_subjectline($title));              link        => $myuri . '?' . &encode($title),
1395          $rss->add_item(              description => &escape(&get_subjectline($title,delimiter=>'')),
1396              title => $escaped_title,              'dc:date'   => &get_info ($title, $info_LastModified),
1397              link  => $link,            );
1398              description => $description,            $count++;
1399          );          }
         $count++;  
1400      }      }
1401      # print RSS information (as XML).      # print RSS information (as XML).
1402      print <<"EOD"      print <<"EOD"
1403  Content-type: text/xml  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1404    
1405  @{[$rss->as_string]}  @{[$rss->as_string]}
1406  EOD  EOD
1407  }  }
1408    
1409    sub _rfc3339_date ($) {
1410      my @time = gmtime (shift);
1411      sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1412    }
1413    
1414  sub is_exist_page {  sub is_exist_page {
1415      my ($name) = @_;      my ($name) = @_;
1416      if ($use_exists) {      if ($use_exists) {
# Line 1469  sub is_exist_page { Line 1421  sub is_exist_page {
1421  }  }
1422    
1423  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1424    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1425    
1426    sub do_map {
1427        my $page = $form{mypage};
1428        &print_header ($page);
1429        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
1430        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
1431        my ($r, $c) = get_search_result ($form{mypage});
1432        my $rl = wiki::referer::list_html ($form{mypage});
1433        print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n";
1434        my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {},
1435          map_from_here => &Resource('Map:FromHere'),
1436          map_from_here_description => &Resource('Map:FromHereLong'));
1437        &wiki::map::make_list ($page, %option);
1438        print &wiki::map::list_to_html ($page, $option{weight_list}, %option);
1439        if ($c) {
1440          print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
1441          print $r;
1442        }
1443        if ($rl) {
1444          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
1445        }
1446        &print_footer ($page);
1447    }
1448    
1449    my %_Resource;
1450    sub Resource ($;%) {
1451      my ($s, %o) = @_;
1452      unless (defined $_Resource{$s}) {
1453        $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1454      }
1455      $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1456    }
1457    
1458  package wiki::referer;  package wiki::referer;
1459  sub add ($$) {  sub add ($$) {
# Line 1507  sub get_dont_record () { Line 1492  sub get_dont_record () {
1492  }  }
1493  sub get_site_name () {  sub get_site_name () {
1494    my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');    my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1495    my %item;    my @item;
1496    for (@lines) {    for (@lines) {
1497      next if /^#/;      next if /^#/;
1498      my ($uri, $name) = split /\s+/, $_, 2;      my ($uri, $name) = split /\s+/, $_, 2;
1499      $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;      $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1500      $name =~ s![()/\\]!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;      $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1501      $item{$uri} = qq(q($name));      push @item, [$uri, qq(q($name))];
1502    }    }
1503    %item;    @item;
1504  }  }
1505    
1506  sub list_html ($) {  sub list_html ($) {
1507    my $page = shift;    my $page = shift;
1508    my %list = get ($page);    my %list = get ($page);
1509    my $r = '';    my $r = '';
1510    my %name = get_site_name;    my @name = get_site_name;
1511    for my $uri (sort keys %list) {    for my $uri (sort keys %list) {
1512      my $title;      my $title;
1513      for my $regex (keys %name) {      for my $item (@name) {
1514        if ($uri =~ /$regex/) {        if ($uri =~ /$item->[0]/) {
1515          $title = $uri;          $title = $uri;
1516          eval qq{\$title =~ s/^.*$regex.*\$/$name{$regex}/e} or die $@;          eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1517              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1518          last;          last;
1519        }        }
1520      }      }
1521      my $euri = main::escape ($uri);      my $euri = main::escape ($uri);
1522      if ($title) {      if ($title) {
1523        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1524      } else {      } else {
1525        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1526      }      }
# Line 1549  sub __decode ($) { Line 1535  sub __decode ($) {
1535    main::code_convert (\$s);    main::code_convert (\$s);
1536  }  }
1537    
1538    package wiki::useragent;
1539    
1540    sub add ($) {
1541      my $s = shift;
1542      return unless length $s;
1543      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge;
1544      my %ua;
1545      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1546        if (/^-\[(\d+)\] (.+)$/) {
1547          my ($t, $n) = ($1, $2);
1548          $n =~ tr/\x0A\x0D//d;
1549          $ua{$n} = $t;
1550        }
1551      }
1552      $ua{$s}++;
1553      my $s = qq(#?SuikaWiki/0.9\n);
1554      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1555        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1556      }
1557      &main::__set_database ('WikiUserAgentList' => $s);
1558    }
1559    
1560    package wiki::suikawikiconst;
1561    
1562    sub to_hash ($;$) {
1563      my $page = shift;
1564      my $h = shift || {};
1565      my $val;
1566      for my $line (split /\n/, $page) {
1567        $line =~ tr/\x0A\x0D//d;
1568        if ($val && $line =~ s/^\s+//) {
1569          $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1570        } elsif ($line =~ /^(.+):/) {
1571          $val = $1; $h->{$val} = '';
1572        }
1573      }
1574      $h;
1575    }
1576    
1577    package SuikaWiki::Plugin;
1578      our $plugin_directory;  # defined in top of this file.
1579      our %List;
1580    
1581    sub escape ($$) { main::escape ($_[1]) }
1582    sub unescape ($$) { main::unescape ($_[1]) }
1583    sub encode ($$) { main::encode ($_[1]) }
1584    sub decode ($$) { main::decode ($_[1]) }
1585    sub __get_datetime ($) { main::get_now () }
1586    sub resource ($$;%) { shift; &main::Resource (@_) }
1587    sub uri ($$) { $main::uri{$_[1]} }
1588    
1589    sub regist ($@) {
1590        my $pack = shift;
1591        for (@_) {
1592            push @{$List{$_}}, $pack;
1593        }
1594    }
1595    
1596    sub import_plugins () {
1597        opendir PDIR, $plugin_directory;
1598        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1599        closedir PDIR;
1600        for (@plugin) {
1601            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1602            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1603        }
1604    }
1605    
1606    &import_plugins ();
1607    
1608    package wiki::conneg;
1609    
1610    ## BUG: this parser isn't strict.
1611    sub get_accept_lang (;$) {
1612      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1613      my %alang = (ja => 0.0002, en => 0.0001);
1614      my $i = 0.1;
1615      for (split /\s*,\s*/, $alang) {
1616        tr/\x09\x0A\x0D\x20//d;
1617        if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1618          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1619          $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1620          $alang{$l} += $i unless $alang{$l} == 0;
1621          $i -= 0.001;
1622        }
1623      }
1624      \%alang;
1625    }
1626    
1627    package wiki::resource;
1628    
1629    sub get ($;\%) {
1630      my ($resname, $option) = @_;
1631      $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1632      $option->{resource} ||= {};
1633      my $v;
1634      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1635        while (length $lang) {
1636          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1637            $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1638            $v = $option->{resource}->{$lang}->{$resname};
1639            last if defined $v;
1640          }
1641          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1642        }
1643        last if defined $v;
1644      }
1645      defined $v ? $v : $resname;
1646    }
1647    
1648    package wiki::map;
1649    
1650    sub make_list ($;%) {
1651      my ($page, %option) = @_;
1652      $option{level} ||= 3;
1653      my %weight;
1654      my $content = &main::__get_database ($page);
1655      $content =~ s{^\#\?([^\x0A\x0D]+)}{
1656        if ($1 =~ /import="([^"]+)"/) {
1657          for (split /\s*,\s*/, $1) {
1658            $weight{$_} += 2;
1659          }
1660        }
1661        $&;
1662      }ges;
1663      ## Bug: this code does not support content type.
1664      $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{
1665        $weight{$1}++; $&;
1666      }ge;
1667      delete $weight{$page};        ## Delete myself
1668      for my $page (keys %weight) {
1669        my $w = ($content =~ s/\Q$page\E/$&/g);
1670        $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.
1671        ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page);
1672      }
1673      $option{weight_list}->{$page} = \%weight;
1674      if (--$option{level}) {
1675        for my $page (keys %weight) {
1676          &make_list ($page, %option) unless $option{weight_list}->{$page};
1677        }
1678      }
1679      $option{weight_list};
1680    }
1681    
1682    sub list_to_html ($$;%) {
1683      my ($Page, $wlist, %option) = @_;
1684      my $r = '';
1685      $option{outputed}->{$Page} = 1;
1686      for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {
1687        $r .= qq(<li><span class="weight">[@{[0+$wlist->{$Page}->{$page}]}]</span> <a href="$main::url_cgi?@{[&main::encode($page)]}" class="wiki@{[$option{not_exist}->{$page}?' not-exist':'']}">@{[&main::escape ($page).($option{not_exist}->{$page}?qq(<span class="mark">@{[&main::Resource('JumpAndEditWikiPageMark',escape=>1)]}</span>):'')]}</a> <a href="$main::url_cgi?mycmd=map;mypage=@{[&main::encode($page)]}" class="wiki-cmd map-from-here" title="@{[&main::escape($option{map_from_here_description})]}">@{[&main::escape($option{map_from_here})]}</a> <span class="summary">@{[&main::escape(&main::get_subjectline($page))]}</span>);
1688        unless ($option{outputed}->{$page}) {
1689          $r .= &list_to_html ($page, $wlist, %option);
1690        }
1691        $r .= "</li>\n";
1692      }
1693      $r ? qq(<ul class="map">$r</ul>) : '';
1694    }
1695    
1696    package main;
1697    &main;
1698    exit 0;
1699    
1700  1;  1;
1701  __END__  __END__
1702  =head1 NAME  =head1 NAME
1703    
1704  wiki.cgi - This is YukiWiki, yet another Wiki clone.  wiki.cgi - This is YukiWiki, yet another Wiki clone.
1705    walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
1706    
1707  =head1 DESCRIPTION  =head1 DESCRIPTION
1708    

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.44

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24