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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24