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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24