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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24