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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24