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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24