/[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.28 by wakaba, Thu Oct 17 07:56:58 2002 UTC revision 1.45 by w, Thu Jan 2 00:34:04 2003 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]]のように登録。  
 #  
 #=======================================  
6    
 # Walrus add (debug) start  
 my $walrus_log;  
 my $walrus_debugging = 0;  
 # Walrus add (debug) end  
   
 # Libraries.  
7  use strict;  use strict;
8  use lib qw(./WalWiki/lib);  use lib qw(./lib);
 use CGI qw(:standard);  
9  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
10  use Yuki::RSS;  
11    require 'wikidata/suikawiki-config.ph';
12  use Yuki::DiffText qw(difftext);  use Yuki::DiffText qw(difftext);
 use Yuki::YukiWikiDB;  
 use AnyDBM_File;  
 require 'jcode.pl';  
 # use Jcode;  
13  use Fcntl;  use Fcntl;
 my $version = '2.0.beta1.2002-05-29';  
 my $walversion;  
 ##############################  
 #  
 # You MUST modify following '$modifier_...' variables.  
 #  
 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'.  
 # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.  
 # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.  
 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.  
 my $modifier_dir_data = './wikidata'; # Your data directory.  
 my $modifier_rss_title = "SuikaWiki $walversion";  
 my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.  
 my $modifier_rss_description = 'This is SuikaWiki';  
 ##############################  
 #  
 # You MAY modify following variables.  
 #  
 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 = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'  
 my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';  
 my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';  
 my $maxrecent = 50;  
 my $cols = 80;  
 my $rows = 20;  
14  ##############################  ##############################
15  #  my %fmt;        ## formatter objects
 # You MAY, but do NOT NEED modify following variables.  
 #  
 my $dataname = "$modifier_dir_data/wiki";  
 my $infoname = "$modifier_dir_data/info";  
 my $diffname = "$modifier_dir_data/diff";  
 my $editchar = '?';  
 my $subject_delimiter = ' - ';  
 my $use_autoimg = 1; # automatically convert image URL into <img> tag.  
 my $use_exists = 0; # If you can use 'exists' method for your DB.  
 ##############################  
 my $InterWikiName = 'InterWikiName';  
 my $RecentChanges = 'RecentChanges';  
 my $AdminChangePassword = 'AdminChangePassword';  
 my $CompletedSuccessfully = 'CompletedSuccessfully';  
 my $FrontPage = 'HomePage';  
 my $IndexPage = 'IndexPage';  
 my $SearchPage = 'SearchPage';  
 my $CreatePage = 'CreatePage';  
 my $ErrorPage = 'ErrorPage';  
 my $RssPage = 'RssPage';  
 my $NAME_OF_WikiPageLicense = 'WikiPageLicense';  
 my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  
 ##############################  
 # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b';        # Walrus del (2)  
 my $wiki_name   = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b';        # Walrus add (2)  
 my $bracket_name = '\[\[(\S+?)\]\]';  
 my $embedded_name = '\[\[(#\S+?)\]\]';  
 my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  
 my $interwiki_name = 'i:([^:]+):([^:].*)';  
 ##############################  
 my $embed_comment = '[[#comment]]';  
 my $embed_rcomment = '[[#rcomment]]';  
 my $embed_comment_Name_Prompt = '名前:';  
 my $DEFAULT_embed_comment_name = '名無しさん';  
 my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  
16  my %embed_command = (  my %embed_command = (
17          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
18            form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19  );  );
20    our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21    our (%PageName,$kanjicode,$lang,%FixedPage);
22    
23  ##############################  ##############################
24  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
25  my $info_IsFrozen = 'IsFrozen';  my $info_IsFrozen = 'IsFrozen';
 my $info_AdminPassword = 'AdminPassword';  
26  ##############################  ##############################
 my $kanjicode = 'euc';  
 my $charset = 'EUC-JP';  
 my $lang = 'ja';  
 my %fixedpage = (  
     $IndexPage => 1,  
     $CreatePage => 1,  
     $ErrorPage => 1,  
     $RssPage => 1,  
     $RecentChanges => 1,  
     $SearchPage => 1,  
     $AdminChangePassword => 1,  
     $CompletedSuccessfully => 1,  
     #$FrontPage => 1,  
 );  
27  my %form;  my %form;
28  my %database;  my %database;
29  my %infobase;  my %infobase;
30  my %diffbase;  my %diffbase;
 my %resource;  
31  my %interwiki;  my %interwiki;
32  ##############################  ##############################
33  my %page_command = (  my %page_command = (
34      $IndexPage => 'index',      $PageName{IndexPage} => 'index',
35      $SearchPage => 'searchform',      $PageName{RssPage} => 'rss',
     $CreatePage => 'create',  
     $RssPage => 'rss',  
     $AdminChangePassword => 'adminchangepasswordform',  
     #$FrontPage => 'FrontPage',  
36  );  );
37  my %command_do = (  my %command_do = (
38      read => \&do_read,      read => \&do_read,
39      TEXT_CSS => \&do_output_css,      TEXT_CSS => \&do_output_css,
40      edit => \&do_edit,      edit => \&do_edit,
41      adminedit => \&do_adminedit,      adminedit => \&do_adminedit,
     adminchangepasswordform => \&do_adminchangepasswordform,  
42      adminchangepassword => \&do_adminchangepassword,      adminchangepassword => \&do_adminchangepassword,
43      write => \&do_write,      write => \&do_write,
44      index => \&do_index,      index => \&do_index,
45      searchform => \&do_searchform,      searchform => \&do_searchform,
     search => \&do_search,  
     create => \&do_create,  
     createresult => \&do_createresult,  
     FrontPage => \&do_FrontPage,  
46      comment => \&do_comment,      comment => \&do_comment,
47      RandomJump  => \&do_random_jump,      RandomJump  => \&do_random_jump,
48      rss => \&do_rss,      rss => \&do_rss,
49      diff => \&do_diff,      diff => \&do_diff,
50      interwikibox => \&do_interwiki_box, # Walrus add (5)      wikiform    => \&do_wikiform,
51        map => \&do_map,
52  );  );
53  ##############################  my $UA = '';  ## User agent name
54  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);  
55  ##############################  ##############################
56    
57  sub main {  sub main {
58      &init_resource;      $UA = $main::ENV{HTTP_USER_AGENT};
59      &open_db;      &open_db;
60      &init_form;      &init_form;
     &init_InterWikiName;  
61      if ($command_do{$form{mycmd}}) {      if ($command_do{$form{mycmd}}) {
62          &{$command_do{$form{mycmd}}};          &{$command_do{$form{mycmd}}};
63      } else {      } else {
64          &do_FrontPage;          &{$command_do{read}};
65      }      }
66      &close_db;      &close_db;
67  }  }
68    
69  sub do_read {  sub do_read {
70    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
71      #print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n";
72    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = &get_info($form{mypage}, $info_LastModified);
   &print_header($form{mypage}, -last_modified => $lm);  
73    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
74      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
75      #print gmtime."Search...\n";
76      my ($r, $c) = get_search_result ($form{mypage});
77      my $rl = wiki::referer::list_html ($form{mypage});
78      my @toc;
79      push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;
80      push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;
81      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
82      ## Should be support at least:      ## Should be support at least:
83      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
84      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
85      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
86      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
87      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
88        &print_content($content, content_format => $cf, last_modified => $lm);      #print gmtime."Header...\n";
89        print &text_to_html (q([[#comment]]));        &print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120,
90            -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
91            #print "\n". gmtime."Body...\n";
92          &print_content ($content, content_format => $cf, last_modified => $lm,
93            -toc => \@toc);
94          print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$FixedPage{$form{mypage}};
95      } else {      } else {
96          &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
97        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
98      }      }
   my ($r, $c) = get_search_result ($form{mypage});  
99      if ($c) {      if ($c) {
100        print q{<h2 id="SEE-ALSO">See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
101        print $r;        print $r;
102      }      }
103    my $r = wiki::referer::list_html ($form{mypage});      if ($rl) {
104      if ($r) {        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
       print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$r</div>\n);  
105      }      }
106            #print "\n". gmtime."Footer...\n";
107    &print_footer($form{mypage}, $lm);    &print_footer($form{mypage}, $lm);
108            #print "\n". gmtime."Fin...\n";
109  }  }
110    
111  sub do_output_css {  sub do_output_css {
112      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
113      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
114    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
115    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
116      print "Content-Type: text/css; charset=$charset\n";      my $lm = gmtime &get_info($form{mypage}, $info_LastModified);
117        print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
118        print "Last-Modified: $lm\n";
119        print "Expires: @{[scalar gmtime time+3600]}\n";    ## TODO: don't use asctime
120      print "\n";      print "\n";
121      print $content;      print $content;
122    } else {    } else {
123      print "Status: 406 Unsupported Media Type\n";      print "Status: 406 Unsupported Media Type\n";
124      &print_header('WikiPageIsNotCSS');      &print_header('WikiPageIsNotCSS', -noindex => 1);
125      &print_content($database{WikiPageIsNotCSS});      &print_content($database{WikiPageIsNotCSS});
126      &print_footer('WikiPageIsNotCSS');      &print_footer('WikiPageIsNotCSS');
127    }    }
128  }  }
129    
130    sub id_and_name ($) {
131        my $name = shift;
132        if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
133          qq{id="$name"><a name="$name"></a};
134        } else {
135            qq{id="$name"};
136        }
137    }
138    
139  sub do_edit {  sub do_edit {
140      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
     &print_header($page);  
141      if (not &is_editable($page)) {      if (not &is_editable($page)) {
142          &print_message($resource{cantchange});          &print_header($page, -noindex => 1, -expires => time+60);
143            &print_message(&Resource('Error:ThisPageIsUneditable'));
144      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
145          &print_message($resource{cantchange});          &print_header($page, -noindex => 1, -expires => time+60);
146            &print_message(&Resource('Error:ThisPageIsUneditable'));
147      } else {      } else {
148            &print_header($page, -noindex => 1, -expires => time+60);
149          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
150      }      }
151        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
152        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
153        my ($r, $c) = get_search_result ($form{mypage});
154        my $rl = wiki::referer::list_html ($form{mypage});
155        if ($c) {
156          print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
157          print $r;
158        }
159        if ($rl) {
160          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
161        }
162      &print_footer($page);      &print_footer($page);
163  }  }
164    
165  sub do_adminedit {  sub do_adminedit {
166      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
167      &print_header($page);      &print_header($page, -noindex => 1, -expires => time+60);
168      if (not &is_editable($page)) {      if (not &is_editable($page)) {
169          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
170      } else {      } else {
171          &print_message($resource{passwordneeded});          &print_message(&Resource('Error:PasswordIsNotSpecified'));
172          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
173      }      }
174      &print_footer($page);      &print_footer($page);
175  }  }
176    
 sub do_adminchangepasswordform {  
     &print_header($AdminChangePassword);  
     &print_passwordform;  
     &print_footer($AdminChangePassword);  
 }  
   
177  sub do_adminchangepassword {  sub do_adminchangepassword {
178      if ($form{mynewpassword} ne $form{mynewpassword2}) {      if ($form{mynewpassword} ne $form{mynewpassword2}) {
179          &print_error($resource{passwordmismatcherror});          &print_error(&Resource('Error:PasswordMismatch'));
180      }      }
181      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
182      if ($validpassword_crypt) {      if ($validpassword_crypt) {
183          if (not &valid_password($form{myoldpassword})) {          if (not &valid_password($form{myoldpassword})) {
184              &send_mail_to_admin(<<"EOD", "AdminChangePassword");              &print_error(&Resource('Error:PasswordIsIncorrect'));
 myoldpassword=$form{myoldpassword}  
 mynewpassword=$form{mynewpassword}  
 mynewpassword2=$form{mynewpassword2}  
 EOD  
             &print_error($resource{passworderror});  
185          }          }
186      }      }
187      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
# Line 299  EOD Line 189  EOD
189      my $salt1 = $token[(time | $$) % scalar(@token)];      my $salt1 = $token[(time | $$) % scalar(@token)];
190      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
191      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
192      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($PageName{AdminSpecialPage}, 'AdminPassword', $crypted);
193    
194        &print_header('CompletedSuccessfully', -noindex => 1);
195        &print_message(&Resource('Error:PasswordIsChanged'));
196        &print_footer('CompletedSuccessfully');
197    }
198    
199      &print_header($CompletedSuccessfully);  sub valid_password ($) {
200      &print_message($resource{passwordchanged});      my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
201      &print_footer($CompletedSuccessfully);      return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
202  }  }
203    
204  sub do_index {  sub do_index {
205      &print_header($IndexPage);    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
206      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
207        &print_header($PageName{IndexPage});
208      print qq(<ul>);      print qq(<ul>);
209      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
210          if (&is_editable($page)) {          if (&is_editable($page)) {
211              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($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>);  
212          }          }
213      }      }
214      print qq(</ul>);      print qq(</ul>);
215      &print_footer($IndexPage);      my ($r, $c) = get_search_result ($form{mypage});
216        if ($c) {
217          print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
218          print $r;
219        }
220        my $rl = wiki::referer::list_html ($form{mypage});
221        if ($rl) {
222            print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
223        }
224        &print_footer($PageName{IndexPage});
225  }  }
226    
227  sub do_write {  sub do_write {
# Line 326  sub do_write { Line 230  sub do_write {
230      }      }
231    
232      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
233          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
234          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
235          &print_footer($form{mypage});          &print_footer($form{mypage});
236          return;          return;
237      }      }
# Line 347  sub do_write { Line 251  sub do_write {
251    
252      if ($form{mymsg}) {      if ($form{mymsg}) {
253          $database{$form{mypage}} = $form{mymsg};          $database{$form{mypage}} = $form{mymsg};
         &send_mail_to_admin($form{mypage}, "Modify");  
254          if ($form{mytouch}) {          if ($form{mytouch}) {
255              &set_info($form{mypage}, $info_LastModified, '' . localtime);              &set_info($form{mypage}, $info_LastModified, time);
256              &update_recent_changes;              &update_recent_changes;
257          }          }
258          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
259          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{comment_index}?"#x-comment-$form{comment_index}":''));          my $fragment = '';
260          &print_message($resource{saved});          $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
261          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          if ($form{__comment_anchor_index}) {
262          &print_footer($CompletedSuccessfully);              $fragment .= qq(#anchor-$form{__comment_anchor_index});
263            } elsif ($form{__wikiform_anchor_index}) {
264                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
265            }
266            &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));
267            &print_message(&Resource('Error:SavedSuccessfully'));
268            &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
269            &print_footer('CompletedSuccessfully');
270      } else {      } else {
         &send_mail_to_admin($form{mypage}, "Delete");  
271          delete $database{$form{mypage}};          delete $database{$form{mypage}};
272          delete $infobase{$form{mypage}};          delete $infobase{$form{mypage}};
273          if ($form{mytouch}) {          if ($form{mytouch}) {
274              &update_recent_changes;              &update_recent_changes;
275          }          }
276          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
277          &print_message($resource{deleted});          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
278          &print_footer($form{mypage});          &print_footer($form{mypage});
279      }      }
280  }  }
281    
 sub do_searchform {  
     &print_header($SearchPage);  
     &print_searchform("");  
     &print_footer($SearchPage);  
 }  
   
 sub do_search {  
     my $word = $form{mymsg};  
     &print_header($SearchPage);  
     &print_searchform(&escape($word));  
     print scalar get_search_result ($word, -output_not_found => 1);  
     &print_footer($SearchPage);  
 }  
   
282  sub get_search_result ($;%) {  sub get_search_result ($;%) {
283    my $word = shift;    my $word = lc shift;
284    my %option = @_;    my %option = @_;
285    my $counter = 0;    my @r;
286    my $r = '';    foreach my $page (keys %database) {
287    foreach my $page (sort keys %database) {      next if !$option{-match_myself} && ($page eq $word);
288      next if $page eq $RecentChanges;      my $content = lc $database{$page};
289      my $content = $database{$page};      if (index (lc $page, $word) > -1) {
290      $content =~ s/^\#\?[^\x0A\x0D]+//s;        my $c = $content =~ s/\Q$word\E//g;
291      if (   index ($content, $word) > 0        push @r, [$page, $c+20];
292          || index ($page, $word) > 0      } elsif (index ($word, lc $page) > -1) {
293          || index ($word, $page) > 0        my $c = $content =~ s/\Q$word\E//g;
294         ) {        push @r, [$page, $c+10];
295        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);      } elsif (my $c = $content =~ s/\Q$word\E//g) {
296        $counter++;        push @r, [$page, $c];
297      }      }
298    }    }
299    $r = qq|<ul>$r</ul>| if $r;    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
300    get_message ($resource{notfound})    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;
301      if $counter == 0 && $option{-output_not_found};    $r = qq|<ul class="search-result">$r</ul>| if $r;
302    wantarray? ($r, $counter): $r;    wantarray? ($r, scalar @r): $r;
 }  
   
 sub do_create {  
     &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);  
303  }  }
304    
305  sub do_random_jump {  sub do_random_jump {
306    my @list = keys %database;    my @list = keys %database;
307    my $name = &encode ($list[rand @list]);    my $name = &encode ($list[rand @list]);
308    print "Location: $url_cgi?$name\n";    my $scheme = 'http';
309      $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
310      print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
311    print "\n";    print "\n";
312  }  }
313    
 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);  
 }  
   
314  sub print_error {  sub print_error {
315      my ($msg) = @_;      my ($msg) = @_;
316      &print_header($ErrorPage);      &print_header($PageName{ErrorPage}, -noindex => 1);
317      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
318      &print_footer($ErrorPage);      &print_footer($PageName{ErrorPage});
319      exit(0);      exit(0);
320  }  }
321    
322  sub print_header ($;%) {  sub print_header ($;%) {
323      my ($page, %option) = @_;      my ($page, %option) = @_;
324      my $bodyclass = "normal";      my @head;
325      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
326          $bodyclass = "frozen";      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
327      }      if ($option{-goto}) {
328      print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};        if ($UA =~ m#Opera|MSIE 2\.#) {
329      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};            ## WARNING: This code may output unsafe HTML document if
330      my $cookedpage = &encode($page);            ##          $option{-goto} is not clean.
331      my $escapedpage = &escape($page);            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
332              print qq{Refresh: 0; url=$option{-goto}\n};
333              push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
334          } else {
335              $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
336              print qq{Refresh: 0; url="$option{-goto}"\n};
337              push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
338          }
339        }
340        print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
341        if ($option{-expires}) {
342          print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
343        }
344        if ($UA =~ m#Mozilla/2#) {
345            my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
346            print qq{Content-Type: $ct\n};
347            push @head, qq{<meta http-equiv="content-type" content="$ct">};
348        } elsif ($UA =~ m#Infomosaic#) {
349            print qq{Content-Type: text/html\n};
350        } else {
351            print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
352        }
353        push @head, qq(<title>@{[&escape($page)]}</title>);
354        if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) {
355          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))]}");
356        }
357        push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
358        my ($Links, $links) = &make_navigate_links ($page);
359        #print $Links;      ## Link: fields
360        $links = join "\n", (@head, $links);
361      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
362  Content-Language: $lang  Content-Language: $lang
363  Content-Style-Type: text/css  Content-Style-Type: text/css
364    
365  <!--  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
366  <!DOCTYPE html  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
367      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  <html lang="$lang" class="$option{body_class}">
368      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
369  <html lang="$lang">  $links
 <head>  
     <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>  
     <link rel="index" href="$url_cgi?$IndexPage">  
     <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">  
     <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">  
     <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">  
370  </head>  </head>
371  <body class="$bodyclass">  <body class="$option{body_class}">
372  EOD  EOD
373    &print_navigate_links ($page);      &print_navigate_links ($page);
374    print <<EOD;      print <<EOD;
375  <h1 class="header">@{[&escape($page)]}  <h1 class="header">@{[&escape($page)]}</h1>
   <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></h1>  
376  EOD  EOD
377  }  }
378    
379    sub get_charset_name ($;%) {
380        my ($charset, %option) = (lc shift, @_);
381        if ($charset =~ 'euc') {
382            $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
383        } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
384            $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
385        } elsif ($charset =~ 'jis') {
386            $charset = 'iso-2022-jp';
387        }
388        $charset;
389    }
390    
391  sub print_navigate_links (@) {  sub print_navigate_links (@) {
392    my ($page) = @_;    my ($page) = @_;
393      my $editable = 0;    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
394      my $admineditable = 0;    my $cookedpage = &encode($page);
     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $editable = 0;  
         $admineditable = 1;  
     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $admineditable = 1;  
         $editable = 1;  
     } else {  
         $editable = 0;  
     }  
     my $cookedpage = &encode($page);  
395    print <<EOH;    print <<EOH;
396  <div class="tools">  <div class="tools">
     @{[ $admineditable  
         ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )  
         : qq()  
     ]}  
397      @{[ $editable      @{[ $editable
398          ? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></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> | )  
399          : qq()          : qq()
400      ]}      ]}
401      <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> |
402      <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> |
403      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
404      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
405      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |      <a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
406      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
407        <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> |
408        <a href="$url_cgi?RecentChanges" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
409  </div>  </div>
410  EOH  EOH
411  }  }
412    
413    sub make_navigate_links ($) {
414        my $page = shift;
415        my @link;
416        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);
417        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);
418        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')};
419        push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
420        push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
421        push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')};
422        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
423        push @link, {rel=>'News', href=>"$url_cgi?RecentChanges", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
424        push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
425        push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
426        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
427        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
428        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')};
429        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')};
430        push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
431        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};
432        push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'};
433        push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
434        my ($Links, $links) = ('', '');
435        for my $e (@link) {
436            $links .= qq(<link);
437            $Links .= qq(Link: <$e->{href}>);
438            for my $attr (qw/rel rev href title class type hreflang charset/) {
439                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
440            }
441            for my $attr (qw/rel rev title/) {
442                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
443            }
444            $links .= qq(>\n);
445            $Links .= qq(\n);
446        }
447        wantarray ? ($Links, $links) : $Links;
448    }
449    
450  sub print_footer {  sub print_footer {
451      my ($page, $lm) = @_;      my ($page, $lm) = @_;
452      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)      my $epage = &encode ($page);
453      # Walrus mod (1) start    my $cvslog1 = q$Revision$;
454    my $cvslog = '$Revision$ $Date$';    my $cvslog2 = q$Date$;
455    print_navigate_links ($page);    print_navigate_links ($page);
456    print <<"EOD";    print <<"EOD";
457  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
458  <div class="footer">  <div class="footer">
459  <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>
460  <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>]  
461  </div>  </div>
 </div>  
 $walrus_log  
462  </body>  </body>
463  </html>  </html>
464  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  
465  }  }
466    
467  sub escape {  sub escape {
# Line 583  sub unescape { Line 486  sub unescape {
486    
487  sub print_content ($;$) {  sub print_content ($;$) {
488      my ($rawcontent, %option) = @_;      my ($rawcontent, %option) = @_;
489      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
490  }  }
491    
492  sub text_to_html {  sub text_to_html {
493      my ($txt, %option) = @_;      my ($txt, %option) = @_;
494      my (@txt) = split(/\n/, $txt);      my @toc;
495      my (@toc);      my @toc2 = @{$option{-toc}||[]};
496      my $tocnum = 0;      my $tocnum = 0;
497        
498        ## Load constants
499        my %const;
500        if ($option{content_format} =~ /import="([^"]+)"/) {
501          for (split /\s*,\s*/, $1) {
502            my $wp = $database{$_};
503            if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
504              wiki::suikawikiconst::to_hash ($wp => \%const);
505            }
506          }
507        }
508        
509        $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
510        my (@txt) = split(/\n/, $txt);
511      my (@saved, @result);      my (@saved, @result);
512      unshift(@saved, "</p>");      unshift(@saved, "</p>");
513      push(@result, "<p>");      push(@result, "<p>");
# Line 598  sub text_to_html { Line 515  sub text_to_html {
515          chomp;          chomp;
516          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
517              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
518              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
519              $tocnum++;              $tocnum++;
520          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
521              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
522              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>');
523              $tocnum++;              $tocnum++;
524          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
525              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
526              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>');
527              $tocnum++;              $tocnum++;
528          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
529          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
530          # Walrus mod (6) end          # Walrus mod (6) end
531              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
532              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>');
533              $tocnum++;              $tocnum++;
534          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
535              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
536              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>');
537              $tocnum++;              $tocnum++;
538          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
539              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
540              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
541          } elsif (/^(-{1,6})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
542            &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
543            my ($pf, $l) = ('', $2);            my ($pf, $l) = ('', $2);
# Line 628  sub text_to_html { Line 545  sub text_to_html {
545              my $num = 0+$1;              my $num = 0+$1;
546              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
547            }            }
548            push(@result, '<li>' . $pf . &inline ($l) . '</li>');            push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
549          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
550              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
551              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
552          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
553              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
554              push(@result, &inline($2));              push @result, "<p>";
555                push(@result, &inline($2, const => \%const));
556                unshift @saved, "</p>";
557          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
558              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
559              push(@result, "<p>");              push(@result, "<p>");
560                unshift(@saved, "</p>");
561          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
562              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
563              #push(@result, &escape($1)); # Not &inline, but &escape              push(@result, &inline($1, const => \%const));
564              push(@result, &inline($1));          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
565  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)              &back_push('table', 1, \@saved, \@result);
         } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)  
             &back_push('table', 1, \@saved, \@result, ' border="1"');  
566              #######              #######
567              # 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.
568              # XXXXX              # XXXXX
# Line 659  sub text_to_html { Line 576  sub text_to_html {
576                          $colspan[$i]++;                          $colspan[$i]++;
577                      }                      }
578                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
579                      $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));
580                  } else {                  } else {
581                      $value[$i] = '';                      $value[$i] = '';
582                  }                  }
# Line 667  sub text_to_html { Line 584  sub text_to_html {
584              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
585              # XXXXX              # XXXXX
586              #######              #######
587          } elsif (/^\[(INS|DEL|PRE)\[/) {          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
588              push @result, splice (@saved), '<'.lc($1).'>';              push @result, splice (@saved), '<'.lc($1).'>';
589              unshift @saved, "</p>";              unshift @saved, "</p>";
590              push @result, "<p>";              push @result, "<p>";
591          } elsif (/^\](INS|DEL|PRE)\]/) {          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
592              push @result, splice (@saved), '</'.lc($1).'>';              push @result, splice (@saved), '</'.lc($1).'>';
593          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
594            my $num = 0+$1;            my $num = 0+$1;
595            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
596            push @result, &inline ($2);            push @result, &inline ($2, const => \%const);
597          } else {          } else {
598              push(@result, &inline($_));              push(@result, &inline($_, const => \%const));
599          }          }
600      }      }
601      push(@result, splice(@saved));      push(@result, splice(@saved));
# Line 688  sub text_to_html { Line 605  sub text_to_html {
605          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
606          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
607          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
608          foreach (@toc) {          foreach (@toc,@toc2) {
609              if (/^(-{1,6})(.*)$/) {              if (/^(-{1,6})(.*)$/) {
610                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
611                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
# Line 698  sub text_to_html { Line 615  sub text_to_html {
615          $toc = join("\n", @tocresult);          $toc = join("\n", @tocresult);
616          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
617      }      }
618      return $toc . join("\n", @result);      $toc .= join("\n", @result);
619        $toc =~ s#<p>\n</p>##g;
620        $toc =~ s#[\x0D\x0A]+</#</#g;
621        $toc =~ s#<pre>\n#<pre>#g;
622        $toc;
623  }  }
624    
625  sub back_push {  sub back_push {
# Line 715  sub back_push { Line 636  sub back_push {
636      }      }
637  }  }
638    
639  sub inline {  sub inline ($;%) {
640      my ($line) = @_;      my ($line, %option) = @_;
641      $line = &escape($line);      $line = &escape($line);
642      $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2</@{[lc $1]}>:g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
643      $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:<acronym title="$2">$1</acronym>: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;
644      $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
645      $line =~ s%\[Q\[(.+?)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
646      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $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;
647      $line =~ s|''([^']+?)''|<em>$1</em>|g;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
648      $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:\[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;
649      $line =~ s!      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
650        (      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
651          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;      $line =~ s|''([^']+)''|<em>$1</em>|g;
652        |      $line =~ s{
653          (?:$bracket_name))      # [[likethis]], [[#comment]], [[Friend:remotelink]]        (\[\[(\#\S+?)\]\])
654        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
655        |&gt;&gt;([0-9]+)        |&gt;&gt;([0-9]+)
656      !        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
657        my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);      }{
658          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
659        if ($l) {        if ($l) {
660          &make_link($l)          return &embedded_to_html($1);
661        } elsif (defined $page) {        } elsif (defined $page) {
662          &make_wikilink ($page, anchor => 0+$anchor);          &make_wikilink ($page, anchor => 0+$anchor);
663        } elsif ($anum) {        } elsif ($anum) {
664          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
665          } elsif ($uri) {
666            &make_urilink ($uri);
667        }        }
668      !gex;      }gex;
669      return $line;      return $line;
670  }  }
671    
# Line 756  sub make_wikilink ($%) { Line 680  sub make_wikilink ($%) {
680        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
681      }      }
682    } else {    } else {
683      return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>);      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>);
684    }    }
685  }  }
686    
687  sub make_link {  sub make_urilink ($;%) {
688      my $chunk = shift;    require URI;
689      # Walrus add (3) start    my $uri = shift;
690      $chunk =~ s/^&lt;(.*)&gt;$/$1/;    if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
691      my $name  = $chunk;      $uri = &unescape ($uri);
692      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {      if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
693          ($name, $chunk) = ($1, $2);        my ($site, $name) = ($1, $2);
694      } elsif ($chunk =~ /^mailto:(.*)$/) {        for ($site, $name) {
695          $name = $1;          if (s/^"//) { s/"$//; s/\\(.)/$1/g }
696      }        }
697      if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {        &init_InterWikiName () unless $interwiki{'[[]]'};
698          $name = qq(<img src="$name">) ;        if ($interwiki{$site}) {
699      }          &load_formatter ('interwiki');
700      $name = &unarmor_name($name);          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
701      # Walrus add (3) end          $site = &escape ($site); $name = &escape ($name);
702      if ($chunk =~ /^(http|https|ftp|news):/) {          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;);
703          # Walrus mod (3) start        } else {
704  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {          qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
705  #           return qq(<a href="$chunk"><img src="$chunk"></a>);        }
706  #       } else {      } else {
707  #           return qq(<a href="$chunk">$chunk</a>);        qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
 #       }  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);  
         # Walrus mod (3) end  
     } 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">@{[&escape($name)]}</a>);  # Walrus add (3)  
             } else {  
 #               return $chunk;                              # Walrus del (3)  
                 return &escape($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" class="wiki">@{[&escape($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">@{[&escape($name)]}</a>);     # Walrus add (3)  
         } else {  
             return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);  
         }  
708      }      }
709      } elsif ($uri =~ /^urn:/) {   ## URN
710        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
711        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
712      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
713        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
714        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
715      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
716        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
717        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
718      } else {      ## misc. URI
719        CGI::Carp::warningsToBrowser (0);
720        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
721        CGI::Carp::warningsToBrowser (1);
722        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
723      }
724  }  }
725    
726  sub print_message {  {my $FormIndex = 0;
727      my ($msg) = @_;  sub make_custom_form ($$$$) {
728      print qq(<p><strong>$msg</strong></p>);      my ($wfname, $definition, $template, $option) = @_;
729  }      ## $template and $option is currently not used in this procedure.
730        unless ($main::_EMBEDED) {
731            $FormIndex++;
732            if (length $definition) {
733                my $param = bless {}, 'SuikaWiki::Plugin';
734                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
735                &load_formatter (qw/form_input form_option/);
736                $definition = &unescape ($definition);
737                $definition =~ s/\\(.)/$1/g;
738                $option = &unescape ($option);
739                $option =~ s/\\(.)/$1/g;
740                $fmt{form_option}->replace ($option, $param);
741                $param->{output}->{form} = 1 unless defined $param->{output}->{form};
742                $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
743                my $target_page = $param->{output}->{page} || $form{mypage};
744                $param->{form_disabled} = 1 if $FixedPage{$target_page};
745                my $target_form = $param->{output}->{id};
746                my $r = '';
747                $r = <<EOH if $param->{output}->{form};
748    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
749      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
750      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
751      <input type="hidden" name="myLastModified" value="$lastmodified">
752      <input type="hidden" name="mytouch" value="on">
753      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
754    EOH
755                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
756                $r .= $fmt{form_input}->replace ($definition, $param);
757                $r .= "</form>\n" if $param->{output}->{form};
758                $r;
759           } else {  ## No input-interface WikiForm
760               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
761           }
762        } else {
763            qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
764        }
765    }}
766    
767  sub get_message {  sub print_message {
768      my ($msg) = @_;      my ($msg) = @_;
769      qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
770  }  }
771    
772  sub init_form {  sub init_form {
773      if (param()) {      ## TODO: Support multipart/form-data
774          foreach my $var (param()) {      my $query = '';
775              $form{$var} = param($var);      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
776          }        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
777      } else {      }
778          $ENV{QUERY_STRING} = $FrontPage;      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
779      }      if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
780          my $query = &decode($main::ENV{QUERY_STRING});
781      my $query = &decode($ENV{QUERY_STRING});        $query = &code_convert(\$query, $kanjicode);
782      if ($page_command{$query}) {        if ($page_command{$query}) {
783          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
784          $form{mypage} = $query;          $form{mypage} = $query;
785      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
786          $form{mypage} = $query;          $form{mypage} = $query;
787            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
788          }
789        } else {
790          for (split /[;&]/, $query) {
791            if (my ($n, $v) = split /=/, $_, 2) {
792              for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
793              $form{$n} = $v;
794            }
795          }
796          unless (defined $form{mypage}) {
797            $form{mypage} = $form{epage};
798            $form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g;
799          }
800          if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
801            $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
802            $form{mycmd} = $page_command{$form{mypage}};
803          }
804      }      }
805        $form{mypage} ||= 'HomePage';
806        $form{mycmd} ||= 'read';
807    
808      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
809      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 864  sub init_form { Line 815  sub init_form {
815          }          }
816      }      }
817    
818      #      #
819      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
820      #      #
821    
822        for (grep /^wikiform__/, keys %form) {
823            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
824        }
825      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
826      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
827  }  }
828    
829  sub update_recent_changes {  sub update_recent_changes {
830      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}";
831      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges});
832        shift @oldupdates; ## '#?' magic line
833      my @updates;      my @updates;
834      foreach (@oldupdates) {      foreach (@oldupdates) {
835          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;          /^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/;
836          my $name = $1;          my $name = $1;
837          if ($name ne $form{mypage}) {          if ($name ne $form{mypage}) {
838              push @updates, $_;              push @updates, $_;
# Line 886  sub update_recent_changes { Line 841  sub update_recent_changes {
841      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
842        unshift @updates, $update;        unshift @updates, $update;
843      }      }
844      splice(@updates, $maxrecent + 1);      splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1;
845      $database{$RecentChanges} = join("\n", @updates);      $database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
846      if ($file_touch) {      if ($PathTo{TouchFile}) {
847          open(FILE, "> $file_touch");          open(FILE, "> ".$PathTo{TouchFile});
848          print FILE localtime() . "\n";          print FILE localtime() . "\n";
849          close(FILE);          close(FILE);
850      }      }
851  }  }
852    
853    {my %SubjectLine;
854  sub get_subjectline {  sub get_subjectline {
855      my ($page, %option) = @_;      my ($page, %option) = @_;
856      if (not &is_editable($page)) {      unless (defined $SubjectLine{$page}) {
857          return "";        if (not &is_editable($page)) {
858            $SubjectLine{$page} = "";
859          } else {
860            $SubjectLine{$page} = $database{$page};
861            $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
862            $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
863          }
864        }
865        if (length $SubjectLine{$page}) {
866          $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
867          $option{delimiter}.$SubjectLine{$page}.$option{tail};
868      } else {      } else {
869          # 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#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;  
         $subject =~ s/\r?\n.*//s;  
         return "$delim$subject".$option{tail};  
870      }      }
871  }  }}
   
 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);  
 }  
872    
873  sub open_db {  sub open_db {
874      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
875          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");          dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}");
876          dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");          dbmopen(%infobase, $PathTo{WikiInfoBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiInfoBase}");
877      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
878          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");          eval q{use AnyDBM_File};
879          tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");          tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}");
880      } else {          tie(%infobase, "AnyDBM_File", $PathTo{WikiInfoBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiInfoBase}");
881          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");      } else {
882          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");          eval q{use Yuki::YukiWikiDB};
883            tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}");
884            tie(%infobase, "Yuki::YukiWikiDB", $PathTo{WikiInfoBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiInfoBase}");
885      }      }
886  }  }
887    
# Line 969  sub close_db { Line 900  sub close_db {
900    
901  sub open_diff {  sub open_diff {
902      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
903          dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");          dbmopen(%diffbase, $PathTo{WikiDiffBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDiffBase}");
904      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
905          tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");          tie(%diffbase, "AnyDBM_File", $PathTo{WikiDiffBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDiffBase}");
906      } else {      } else {
907          tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");          tie(%diffbase, "Yuki::YukiWikiDB", $PathTo{WikiDiffBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDiffBase}");
908      }      }
909  }  }
910    
# Line 987  sub close_diff { Line 918  sub close_diff {
918      }      }
919  }  }
920    
 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  
 }  
   
921  sub print_editform {  sub print_editform {
922      my ($mymsg, $lastmodified, %mode) = @_;      my ($mymsg, $lastmodified, %mode) = @_;
923      my $frozen = &is_frozen($form{mypage});      my $frozen = &is_frozen($form{mypage});
# Line 1005  sub print_editform { Line 925  sub print_editform {
925      if ($form{mypreview}) {      if ($form{mypreview}) {
926          if ($form{mymsg}) {          if ($form{mymsg}) {
927              unless ($mode{conflict}) {              unless ($mode{conflict}) {
928                  print qq(<h3>$resource{previewtitle}</h3>\n);                  print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);
929                  print qq($resource{previewnotice}\n);                  print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);
930                  print qq(<div class="preview">\n);                  print qq(<div class="preview">\n);
931                  &print_content($form{mymsg});                  &print_content($form{mymsg});
932                  print qq(</div>\n);                  print qq(</div>\n);
933              }              }
934          } else {          } else {
935              print qq($resource{previewempty});              print @{[&Resource('Preview:Empty',escape=>1)]};
936          }          }
937          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
938      } else {      } else {
939          $mymsg = &escape($mymsg || $database{NewPageTemplate});          $mymsg = &escape($mymsg || $database{NewPageTemplate});
940      }      }
941        my $magic = '';
942        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
943    
944      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
945      my $escapedmypage = &escape($form{mypage});      my $selected = 'read';
946      my $escapedmypassword = &escape($form{mypassword});      if ($form{after_edit_cmd}) {
947            $selected = $form{after_edit_cmd};
948        } elsif ($magic =~ /Const|Config|CSS/) {
949            $selected = 'edit';
950        }
951        my $afteredit = <<EOH;
952    <select name="after_edit_cmd">
953    <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
954    <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
955    </select>
956    EOH
957    
958      print <<"EOD";      print <<"EOD";
959  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
960      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}  <h2>@{[&Resource('Edit:Title',escape=>1)]}</h2>
961        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]}
962        @{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[do {my $n = 0;
963                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
964                   ++$n}]}]<br>
965      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
966      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
967      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$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>
968  @{[  @{[
969      $mode{admin} ?      $mode{admin} ?
970      qq(      qq(
971      <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>
972      <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>)
973      : ""      : ""
974  ]}  ]}
975  @{[  @{[
976      $mode{conflict} ? "" :      $mode{conflict} ? "" :
977      qq(      qq(
978          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br>
979          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}">
980          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>          <label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label>
981           $afteredit
982      )      )
983  ]}  ]}
984  </form>  </form>
985  EOD  EOD
986      unless ($mode{conflict}) {      unless ($mode{conflict}) {
987          # Show the format rule.          ## Show help text
988          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{WikiEditHelp};
989          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
990          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
         close(FILE);  
         print &text_to_html($content, toc=>0);  
991      }      }
992  }  }
993    
 sub print_passwordform {  
         print <<"EOD";  
 <form action="$url_cgi" method="post">  
     <input type="hidden" name="mycmd" value="adminchangepassword">  
     $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>  
     $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>  
     $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>  
     <input type="submit" value="$resource{changepasswordbutton}"><br>  
 </form>  
 EOD  
 }  
   
994  sub is_editable {  sub is_editable {
995      my ($page) = @_;      my ($page) = @_;
996      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$/) {  
997          return 0;          return 0;
998      } else {      } else {
999          return 1;          return 1;
# Line 1088  sub is_editable { Line 1003  sub is_editable {
1003  # armor_name:  # armor_name:
1004  #   WikiName -> WikiName  #   WikiName -> WikiName
1005  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1006  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     #if ($name =~ /^$wiki_name$/) {  
     #    return $name;  
     #} else {  
         return "[[$name]]";  
     #}  
 }  
1007    
1008  # unarmor_name:  # unarmor_name:
1009  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
1010  #   WikiName -> WikiName  #   WikiName -> WikiName
1011  sub unarmor_name {  sub unarmor_name {
1012      my ($name) = @_;      my ($name) = @_;
1013      if ($name =~ /^$bracket_name$/) {      if ($name =~ /^\[\[(\S+?)\]\]$/) {
1014          return $1;          return $1;
1015      } else {      } else {
1016          return $name;          return $name;
1017      }      }
1018  }  }
1019    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1020  sub decode {  sub decode {
1021      my ($s) = @_;      my ($s) = @_;
1022      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1138  sub encode { Line 1037  sub encode {
1037      return $encoded;      return $encoded;
1038  }  }
1039    
 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);  
 }  
   
1040  sub conflict {  sub conflict {
1041      my ($page, $rawmsg) = @_;      my ($page, $rawmsg) = @_;
1042      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1043          return 0;          return 0;
1044      }      }
1045      open(FILE, $file_conflict) or &print_error("(conflict)");      &print_header($page, -noindex => 1);
1046      my $content = join('', <FILE>);      &print_content(&Resource('Error:Conflict'));
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
     &print_header($page);  
     &print_content($content);  
1047      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1048      &print_footer($page);      &print_footer($page);
1049      return 1;      return 1;
1050  }  }
1051    
1052  sub get_now {  sub get_now {
1053      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
     my (@week) = qw(日 月 火 水 木 金 土);  
     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);  
1054      $year += 1900;      $year += 1900;
1055      $mon++;      $mon++;
1056      $mon = "0$mon" if $mon < 10;      $mon = "0$mon" if $mon < 10;
# Line 1176  sub get_now { Line 1058  sub get_now {
1058      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1059      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1060      #$sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1061      $weekday = $week[$weekday];      return "$year-$mon-$day $hour:$min";
     return "$year-$mon-$day ($weekday) $hour:$min";  
1062  }  }
1063    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1064  sub init_InterWikiName {  sub init_InterWikiName {
1065      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{InterWikiName};
1066      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1067          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1068          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1069      }      }
1070      }
1071      $interwiki{'[[]]'} = 1;       ## dummy
1072  }  }
1073    
 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;  
     }  
 }  
1074    
1075  sub get_info {  sub get_info {
1076      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1241  sub frozen_reject { Line 1099  sub frozen_reject {
1099          # You are admin.          # You are admin.
1100          return 0;          return 0;
1101      } else {      } else {
1102          &print_error($resource{passworderror});          &print_error(&Resource('Error:PasswordIsIncorrect'));
         return 1;  
     }  
 }  
   
 sub valid_password {  
     my ($givenpassword) = @_;  
     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);  
     if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {  
1103          return 1;          return 1;
     } else {  
         return 0;  
1104      }      }
1105  }  }
1106    
# Line 1267  sub is_frozen { Line 1115  sub is_frozen {
1115    
1116  sub do_comment {  sub do_comment {
1117      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1118      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1119      my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'': ";      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1120      my $anchor = 0;      my $datestr = '[WEAK['.&get_now.']]';
1121      $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
1122      $anchor++;      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1123        if ($namestr =~ /^(?:>>)?[0-9]/) {
1124          $namestr = qq( ''$namestr'': );
1125        } elsif (length $namestr) {
1126          $namestr = qq( ''[[$namestr]]'': );
1127        }
1128        my $anchor = &get_new_anchor_index ($content);
1129      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1130      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\[\[\#r?comment\]\])}{
1131        my $embed = $1;        my $embed = $1;
1132        if ($i == $form{comment_index}) {        if ($i == $form{comment_index}) {
1133          if ($embed eq $embed_comment) {          if ($embed ne '[[#rcomment]]') {
1134            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1135          } else {          } else {
1136            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
# Line 1285  sub do_comment { Line 1139  sub do_comment {
1139        $i++; $embed;        $i++; $embed;
1140      }ge;      }ge;
1141      unless ($o) {      unless ($o) {
1142          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1143          $content .= "\n" unless $content =~ /\n$/s;
1144        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1145      }      }
1146      if ($form{mymsg}) {      $form{__comment_anchor_index} = $anchor;
1147        if ($form{mymsg} || $form{myname}) {
1148          $form{mymsg} = $content;          $form{mymsg} = $content;
1149          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1150          &do_write;          &do_write;
# Line 1297  sub do_comment { Line 1154  sub do_comment {
1154      }      }
1155  }  }
1156    
1157    sub get_new_anchor_index ($) {
1158        my $content = shift;
1159        my $anchor = 0;
1160        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1161        $anchor + 1;
1162    }
1163    
1164  my $CommentIndex = 0;  my $CommentIndex = 0;
1165  sub embedded_to_html {  sub embedded_to_html {
1166      my ($embedded) = @_;      my ($embedded) = @_;
1167      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
1168        unless ($main::_EMBEDED) {        unless ($main::_EMBEDED) {
1169          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1170          return <<"EOD";          return <<"EOD";
1171  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1172      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1173      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1174      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1175      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1176      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
1177      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1178      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10" class="comment-name">
1179      <input type="text" name="mymsg" value="" size="60">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1180      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
1181  </form>  </p></form>
1182  EOD  EOD
1183       } else {       } else {
1184          return <<"EOD";          return <<"EOD";
1185  <del><form action="$url_cgi" method="get">  <del><form action="$url_cgi" method="get">
1186      <input type="hidden" name="mycmd" value="read">      <input type="hidden" name="mycmd" value="read">
1187      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1188      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1189      <input type="text" name="myname" value="" size="10" disabled="disabled">      <input type="text" name="myname" value="" size="10" disabled="disabled">
1190      <input type="text" name="mymsg" value="" size="60" disabled="disabled">      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
     <input type="submit" value="$resource{commentbutton}" disabled="disabled">  
1191  </form></del>  </form></del>
1192  EOD  EOD
1193      }      }
1194    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1195      return get_search_result ($1);      return get_search_result ($1, -match_myself => 1);
     # Walrus add (5) start  
     } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {  
         $_ = &make_interwiki_box($1, $2);  
         return ($_) ? $_ : $embedded;  
     # Walrus add (5) end  
1196    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1197      my ($name, $r) = ($1, '');      my ($name, $r) = ($1, '');
1198      if ($main::_EMBEDED != 1) {      if ($main::_EMBEDED != 1) {
# Line 1347  EOD Line 1205  EOD
1205        } elsif (length $content) {        } elsif (length $content) {
1206          $r = "<pre>@{[&escape ($content)]}</pre>";          $r = "<pre>@{[&escape ($content)]}</pre>";
1207        } else {        } else {
1208          $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9');          $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1209        }        }
1210      } else {    ## nested #EMBED      } else {    ## nested #EMBED
1211        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');        $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1212      }      }
1213      return qq(<blockquote title="@{[&escape($name)]}">$r</blockquote>);      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>);
1214    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1215      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1216    } else {    } else {
# Line 1360  EOD Line 1218  EOD
1218    }    }
1219  }  }
1220    
1221  # Walrus add (5) start  sub load_formatter (@) {
1222  sub do_interwiki_box {      for my $t (@_) {
1223      my $remoteurl = $interwiki{$form{'myintername'}};          unless ($fmt{$t}) {
1224      if ($remoteurl) {              require Message::Util::Formatter;
1225          $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;              $fmt{$t} = Message::Util::Formatter->new;
1226          print "Location: $remoteurl\n\n";              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1227          exit(1);                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1228      } else {              }
1229          &do_read;          }
1230      }      }
1231  }  }
 # Walrus add (5) end  
1232    
1233  # Walrus add (5) start  sub do_wikiform {
1234  sub make_interwiki_box {      my $content = $database{$form{mypage}};
1235      my ($localname, $intername) = @_;      my $anchor = &get_new_anchor_index ($content);
1236      my %ignoretype = (      &load_formatter (qw/form_template form_option/);
1237          'box'      => 'text',      my $write = 0;
1238          'text'     => 'text',      my $i = 1;
1239          'pass'     => 'password',      $content =~ s{$embed_command{form}}{
1240          'password' => 'password'          my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1241      );          if (($wfname && $wfname eq $form{wikiform_targetform})
1242      my $converted = ($ignoretype{$localname}) ? <<EOD : undef;              || $i == $form{wikiform_index}) {
1243  <form action="$url_cgi" method="post">              $template =~ s/\\(.)/$1/g;
1244      <input type="hidden" name="mycmd" value="interwikibox">              $option =~ s/\\(.)/$1/g;
1245      <input type="hidden" name="mypage" value="$form{mypage}">              my $param = bless {}, 'SuikaWiki::Plugin';
1246      <input type="hidden" name="myintername" value="$intername">              $param->{page} = $form{mypage};
1247      $intername:              $param->{form_index} = $i;
1248      <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">              $param->{form_name} = $wfname;
1249      <input type="submit" value="Submit">              $param->{anchor_index} = $anchor;
1250  </form>              $param->{argv} = \%form;
1251  EOD              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1252                $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1253                $fmt{form_option}->replace ($option, $param);
1254                my $t = 1;
1255                for (@{$param->{require}||[]}) {
1256                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1257                }
1258                $t = $fmt{form_template}->replace ($template, $param) if $t;
1259                if (length $t) {
1260                    if ($param->{output}->{reverse}) {
1261                        $embed .= "\n" . $t;
1262                    } else {
1263                        $embed = $t . "\n" . $embed;
1264                    }
1265                    $write = 1;
1266                    $form{__comment_anchor_index} = $anchor
1267                      if $param->{anchor_index_};  ## $anchor is used!
1268                }
1269                $form{__wikiform_anchor_index} = $i;
1270                undef $form{wikiform_targetform};  ## make sure never to match
1271                undef $form{wikiform_index};       ## with WikiForm in rest of page
1272            }
1273            $i++; $embed;
1274        }ge;
1275        unless ($write) {
1276          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1277          #$content .= "\n" unless $content =~ /\n$/s;
1278          #
1279        }
1280        if ($write) {
1281            $form{mymsg} = $content;
1282            $form{mytouch} = 'on';
1283            &do_write;
1284        } else {
1285            $form{mycmd} = 'read';
1286            &do_read;
1287        }
1288  }  }
 # Walrus add (5) end  
1289    
1290  sub code_convert {  sub code_convert {
1291      require Jcode;
1292      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1293  #   &Jcode::convert($contentref, $code);       # for Jcode.pm      $code = 'jis' if $code =~ /iso/;
1294      &jcode::convert($contentref, $code);       # for jcode.pl      $code = 'euc' if $code =~ /euc/;
1295        $code = 'sjis' if $code =~ /shift/;
1296        $code = 'utf8' if $code =~ /utf/;
1297        #&Jcode::convert($contentref, $code);       # for Jcode.pm
1298    #    &jcode::convert($contentref, $code);       # for jcode.pl
1299        #&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';
1300        $$contentref = Jcode->new ($contentref)->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code;
1301      return $$contentref;      return $$contentref;
1302  }  }
1303    
 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;  
 }  
   
1304  sub do_diff {  sub do_diff {
1305      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
1306          &do_read;          &do_read;
# Line 1472  sub do_diff { Line 1308  sub do_diff {
1308      }      }
1309      &open_diff;      &open_diff;
1310      my $title = $form{mypage};      my $title = $form{mypage};
1311      &print_header($title);      &print_header($title, -noindex => 1);
1312      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1313      &close_diff;      &close_diff;
1314      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>);
1315      print qq($resource{diffnotice});      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1316      print qq(<pre class="diff">);      print qq(<pre class="diff">);
1317      foreach (split(/\n/, $_)) {      foreach (split(/\n/, $_)) {
1318          if (/^\+(.*)/) {          if (/^\+(.*)/) {
1319              print qq(<b class="added">$1</b>\n);              print qq(<ins class="added">$1</ins>\n);
1320          } elsif (/^\-(.*)/) {          } elsif (/^\-(.*)/) {
1321              print qq(<s class="deleted">$1</s>\n);              print qq(<del class="deleted">$1</del>\n);
1322          } elsif (/^\=(.*)/) {          } elsif (/^\=(.*)/) {
1323              print qq(<span class="same">$1</span>\n);              print qq(<span class="same">$1</span>\n);
1324          } else {          } else {
# Line 1490  sub do_diff { Line 1326  sub do_diff {
1326          }          }
1327      }      }
1328      print qq(</pre>);      print qq(</pre>);
     print qq(<hr>);  
1329      &print_footer($title);      &print_footer($title);
1330  }  }
1331    
1332  sub do_rss {  sub do_rss {
1333        eval q{use Yuki::RSS};
1334      my $rss = new Yuki::RSS(      my $rss = new Yuki::RSS(
1335          version => '1.0',          version => '1.0',
1336          encoding => $charset,          encoding => &get_charset_name ($kanjicode),
1337        );
1338        my $scheme = 'http';
1339        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1340        my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1341        $rss->stylesheet (
1342          href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1343          type      => 'text/css',
1344      );      );
1345      $rss->channel(      $rss->channel(
1346          title => $modifier_rss_title,          title   => &Resource ('RSS:WikiTitle'),
1347          link  => $modifier_rss_link,          link    => $myuri,
1348          description => $modifier_rss_description,          description     => &Resource ('RSS:WikiDescription'),
1349            'dc:language'   => $lang,
1350      );      );
1351      my $recentchanges = $database{$RecentChanges};      my $recentchanges = $database{RecentChanges};
1352      my $count = 0;      my $count = 0;
1353      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1354          last if ($count >= 15);          last if ($count >= 15);
1355          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/;    # date format.          if (/\[\[([^]]+)\]\]/) {
1356          my $title = &unarmor_name($1);            my $title = $1;
1357          my $escaped_title = &escape($title);            $rss->add_item (
1358          my $link = $modifier_rss_link . '?' . &encode($title);              title       => &escape($title),
1359          my $description = $escaped_title . &escape(&get_subjectline($title));              link        => $myuri . '?' . &encode($title),
1360          $rss->add_item(              description => &escape(&get_subjectline($title,delimiter=>'')),
1361              title => $escaped_title,              'dc:date'   => &get_info ($title, $info_LastModified),
1362              link  => $link,            );
1363              description => $description,            $count++;
1364          );          }
         $count++;  
1365      }      }
1366      # print RSS information (as XML).      # print RSS information (as XML).
1367      print <<"EOD"      print <<"EOD"
1368  Content-type: text/xml  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1369    
1370  @{[$rss->as_string]}  @{[$rss->as_string]}
1371  EOD  EOD
1372  }  }
1373    
1374    sub _rfc3339_date ($) {
1375      my @time = gmtime (shift);
1376      sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1377    }
1378    
1379  sub is_exist_page {  sub is_exist_page {
1380      my ($name) = @_;      my ($name) = @_;
1381      if ($use_exists) {      if ($use_exists) {
# Line 1538  sub is_exist_page { Line 1386  sub is_exist_page {
1386  }  }
1387    
1388  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1389    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1390    
1391    sub do_map {
1392        my $page = $form{mypage};
1393        &print_header ($page);
1394        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
1395        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
1396        my ($r, $c) = get_search_result ($form{mypage});
1397        my $rl = wiki::referer::list_html ($form{mypage});
1398        print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n";
1399        my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {},
1400          map_from_here => &Resource('Map:FromHere'),
1401          map_from_here_description => &Resource('Map:FromHereLong'));
1402        &wiki::map::make_list ($page, %option);
1403        print &wiki::map::list_to_html ($page, $option{weight_list}, %option);
1404        if ($c) {
1405          print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
1406          print $r;
1407        }
1408        if ($rl) {
1409          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
1410        }
1411        &print_footer ($page);
1412    }
1413    
1414    my %_Resource;
1415    sub Resource ($;%) {
1416      my ($s, %o) = @_;
1417      unless (defined $_Resource{$s}) {
1418        $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1419      }
1420      $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1421    }
1422    
1423  package wiki::referer;  package wiki::referer;
1424  sub add ($$) {  sub add ($$) {
# Line 1604  sub list_html ($) { Line 1485  sub list_html ($) {
1485      }      }
1486      my $euri = main::escape ($uri);      my $euri = main::escape ($uri);
1487      if ($title) {      if ($title) {
1488        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1489      } else {      } else {
1490        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1491      }      }
# Line 1619  sub __decode ($) { Line 1500  sub __decode ($) {
1500    main::code_convert (\$s);    main::code_convert (\$s);
1501  }  }
1502    
1503    package wiki::useragent;
1504    our $UseLog;
1505    
1506    sub add ($) {
1507      my $s = shift;
1508      return unless length $s;
1509      return unless $UseLog;
1510      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge;
1511      my %ua;
1512      for (split /\n/, &main::__get_database($main::PageName{UserAgentList})) {
1513        if (/^-\[(\d+)\] (.+)$/) {
1514          my ($t, $n) = ($1, $2);
1515          $n =~ tr/\x0A\x0D//d;
1516          $ua{$n} = $t;
1517        }
1518      }
1519      $ua{$s}++;
1520      my $s = qq(#?SuikaWiki/0.9\n);
1521      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1522        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1523      }
1524      &main::__set_database ($main::PageName{UserAgentList} => $s);
1525    }
1526    
1527    package wiki::suikawikiconst;
1528    
1529    sub to_hash ($;$) {
1530      my $page = shift;
1531      my $h = shift || {};
1532      my $val;
1533      for my $line (split /\n/, $page) {
1534        $line =~ tr/\x0A\x0D//d;
1535        if ($val && $line =~ s/^\s+//) {
1536          $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1537        } elsif ($line =~ /^(.+):/) {
1538          $val = $1; $h->{$val} = '';
1539        }
1540      }
1541      $h;
1542    }
1543    
1544    package SuikaWiki::Plugin;
1545      our $plugin_directory;  # defined in top of this file.
1546      our %List;
1547    
1548    sub escape ($$) { main::escape ($_[1]) }
1549    sub unescape ($$) { main::unescape ($_[1]) }
1550    sub encode ($$) { main::encode ($_[1]) }
1551    sub decode ($$) { main::decode ($_[1]) }
1552    sub __get_datetime ($) { main::get_now () }
1553    sub resource ($$;%) { shift; &main::Resource (@_) }
1554    sub uri ($$) { $main::uri{$_[1]} }
1555    
1556    sub regist ($@) {
1557        my $pack = shift;
1558        for (@_) {
1559            push @{$List{$_}}, $pack;
1560        }
1561    }
1562    
1563    sub import_plugins () {
1564        opendir PDIR, $plugin_directory;
1565        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1566        closedir PDIR;
1567        for (@plugin) {
1568            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1569            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1570        }
1571    }
1572    
1573    &import_plugins ();
1574    
1575    package wiki::conneg;
1576    
1577    ## BUG: this parser isn't strict.
1578    sub get_accept_lang (;$) {
1579      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1580      my %alang = (ja => 0.0002, en => 0.0001);
1581      my $i = 0.1;
1582      for (split /\s*,\s*/, $alang) {
1583        tr/\x09\x0A\x0D\x20//d;
1584        if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1585          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1586          $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1587          $alang{$l} += $i unless $alang{$l} == 0;
1588          $i -= 0.001;
1589        }
1590      }
1591      \%alang;
1592    }
1593    
1594    package wiki::resource;
1595    
1596    sub get ($;\%) {
1597      my ($resname, $option) = @_;
1598      $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1599      $option->{resource} ||= {};
1600      my $v;
1601      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1602        while (length $lang) {
1603          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1604            $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1605            $v = $option->{resource}->{$lang}->{$resname};
1606            last if defined $v;
1607          }
1608          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1609        }
1610        last if defined $v;
1611      }
1612      defined $v ? $v : $resname;
1613    }
1614    
1615    package wiki::map;
1616    
1617    sub make_list ($;%) {
1618      my ($page, %option) = @_;
1619      $option{level} ||= 3;
1620      my %weight;
1621      my $content = &main::__get_database ($page);
1622      $content =~ s{^\#\?([^\x0A\x0D]+)}{
1623        if ($1 =~ /import="([^"]+)"/) {
1624          for (split /\s*,\s*/, $1) {
1625            $weight{$_} += 2;
1626          }
1627        }
1628        $&;
1629      }ges;
1630      ## Bug: this code does not support content type.
1631      $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{
1632        $weight{$1}++; $&;
1633      }ge;
1634      delete $weight{$page};        ## Delete myself
1635      for my $page (keys %weight) {
1636        my $w = ($content =~ s/\Q$page\E/$&/g);
1637        $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.
1638        ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page);
1639      }
1640      $option{weight_list}->{$page} = \%weight;
1641      if (--$option{level}) {
1642        for my $page (keys %weight) {
1643          &make_list ($page, %option) unless $option{weight_list}->{$page};
1644        }
1645      }
1646      $option{weight_list};
1647    }
1648    
1649    sub list_to_html ($$;%) {
1650      my ($Page, $wlist, %option) = @_;
1651      my $r = '';
1652      $option{outputed}->{$Page} = 1;
1653      for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {
1654        $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>);
1655        unless ($option{outputed}->{$page}) {
1656          $r .= &list_to_html ($page, $wlist, %option);
1657        }
1658        $r .= "</li>\n";
1659      }
1660      $r ? qq(<ul class="map">$r</ul>) : '';
1661    }
1662    
1663    package main;
1664    &main;
1665    exit 0;
1666    
1667  1;  1;
1668  __END__  __END__
1669  =head1 NAME  =head1 NAME
1670    
1671  wiki.cgi - This is YukiWiki, yet another Wiki clone.  wiki.cgi - This is YukiWiki, yet another Wiki clone.
1672    walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
1673    
1674  =head1 DESCRIPTION  =head1 DESCRIPTION
1675    

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.45

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24