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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24