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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24