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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24