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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24