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

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.42

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24