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

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.45

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24