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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24