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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24