/[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.6 by wakaba, Mon Feb 4 15:23: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
2  use lib "../lib";  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
 use CGI::Carp 'fatalsToBrowser';  
 use Algorithm::Diff qw(traverse_sequences);  
 # use strict;  
3  #  #
4  # yukiwiki.cgi - Yet another WikiWikiWeb clone.  # This program is free software; you can redistribute it and/or
5  #  # modify it under the same terms as Perl itself.
 # Copyright (C) 2000,2001 by Hiroshi Yuki.  
 # <hyuki@hyuki.com>  
 # http://www.hyuki.com/yukiwiki/  
 #  
 # This program is free software; you can redistribute it and/or modify  
 # it under the terms of the GNU General Public License as published by  
 # the Free Software Foundation; either version 2 of the License, or  
 # (at your option) any later version.  
 #  
 # This program is distributed in the hope that it will be useful,  
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 # GNU General Public License for more details.  
 #  
 # $Id$  
 ##############################  
 my $version = "1.6.6";  
 ##############################  
 # ñ�ȥƥ��ȤΤȤ��ˤ� 1 �ˤ��롣  
 my $testing = 0;  
 ##############################  
 # �����饤�֥��  
 my $jcodelib = 'jcode.pl';  
 ##############################  
 # ��¸��ɽ���δ���������  
 my $kanjicode = 'euc';     # 'sjis' 'euc'  
 my $charset = 'euc-jisx0213';  # 'Shift_JIS' 'EUC-JP'  
 ##############################  
 # dbmopen���Ȥ���ʤ�1���Ȥ��ʤ��ʤ�0  
 my $dbmopen = 0;  
 ##############################  
 # �ǡ����١���̾��.pag, .dir, .db�ʤɤ����ס�  
 # $dbmopen = 1�ΤȤ��ϥǡ����١���̾��  
 # $dbmopen = 0�ΤȤ��ϥǥ��쥯�ȥ�̾�ˤʤ롣  
 my $dbname = './wikidata';  
 my $diffdbname = './wikidiff';  
 ##############################  
 # �����Ԥλ�̾�ʼ�ͳ���ѹ����Ƥ���������  
 my $modifier = 'suika';  
 ##############################  
 # �����Ԥ�Web�ڡ����ʼ�ͳ���ѹ����Ƥ���������  
 my $modifierlink = 'http://suika.fam.cx/';  
 ##############################  
 # ���Υڡ�����URL  
 my $thisurl = 'wiki';  
 ##############################  
 # ���ϥڡ���̾  
 my $toppage = 'HomePage';  
 ##############################  
 # �ǽ������ڡ���̾  
 my $whatsnew = 'RecentChanges';  
 ##############################  
 # �ǽ������˷Ǻܤ���ڡ�����  
 my $maxnew = 50;  
 ##############################  
 # ��������ե�����̾�ʥ��顼�ǡ�  
 my $iconfile = '';  
 ##############################  
 # ��������ե�����̾�ʥ�Υ����ǡ�  
 # my $iconfile = '';  
 ##############################  
 # �ڡ������ѹ������Ȥ���touch����ե������''�ʤ鲿�⤷�ʤ���  
 my $touchfile = 'touch.txt';  
 ##############################  
 # �ץ�ӥ塼�Ѥ��طʿ�  
 my $preview_color = '#FFCCCC';  
 ##############################  
 # ���ڡ����Υ�������  
 my $style = <<'EOD';  
 pre, dl, ul, ol, p, blockquote { line-height:120%; }  
 a { text-decoration: none; }  
 a:link { color: #0000FF; background-color: #FFFFFF; }  
 a:visited { color: #9900CC; background-color: #FFFFFF; }  
 a:hover { text-decoration: underline; }  
 EOD  
 ##############################  
 # �ƥ�����������ʬ���礭��  
 my $cols = 80;  
 my $rows = 20;  
 ##############################  
 my %form = ();  
 my %database = ();  
 my %diffbase = ();  
 my $diff_text = '';  
 my @diff_added = ();  
 my @diff_deleted = ();  
 my $msgrefA;  
 my $msgrefB;  
 ##############################  
 # �Խ��Բĥڡ���̾����  
 my @uneditable = ( $whatsnew );  
 ##############################  
 # ����Ѥ�����ɽ��  
 # YukiWiki�Υ�󥯤�2���ढ�롣  
 #  
 # (1) WikiName (RecentChanges�Ȥ�FrontPage�Τ褦�ʤ��)  
 # (2) BracketName ([[����]]�Ȥ�[[�ȥ�֥륷�塼��]]�Τ褦�ʤ��)  
 #  
 # �����ե�JIS��2�Х����ܤˤ� ']' ���褦��Τǡ�  
 # ʸ��']'��1��¿���Ȥ�褦�ˤ��Ƥ��롣  
 #  
 my $WikiName = '([A-Z][a-z]+([A-Z][a-z]+)+)';  
 my $BracketName = '\[\[([^>\s]+?\]?)\]\]';  
6    
7  # ����������ʬ�Υ���  use strict;
8  my $IconTag = ''; #<<"EOD";  use lib qw(./lib);
9  #<a href="http://www.hyuki.com/yukiwiki/"><img src="$iconfile"  use CGI::Carp qw(fatalsToBrowser);
10  # border="0" width="80" height="80" alt="[YukiWiki]" /></a>  
11  #EOD  require 'wikidata/suikawiki-config.ph';
12    use Yuki::DiffText qw(difftext);
13  require "$jcodelib";  use Fcntl;
14    ##############################
15  &init_form($kanjicode);  my %fmt;        ## formatter objects
16    my %embed_command = (
17  if ($testing) {          searched        => '^\[\[#searched:([^\]]+)\]\]$',
18      %form = (          form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19          # 'mycmd' => 'write',  );
20          'mycmd' => 'read',  our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21          #'mycmd' => 'search',  our (%PageName,$kanjicode,$lang,%FixedPage);
22          #'mycmd' => 'edit',  
23          'mymsg' => <<"EOD",  ##############################
24  �Ϥ���ޤ��ơ�  my $info_LastModified = 'LastModified';
25  ���줫�餤�������񤭹��ߤޤ��͡�  my $info_IsFrozen = 'IsFrozen';
26  LinkPage�⸫�Ƥ���������  ##############################
27  TestPage�Ϥɤ��Ǥ��礦����  my %form;
28  �ɤ������������  my %database;
29  http://www.hyuki.com/  my %infobase;
30  [[����]]  my %diffbase;
31  EOD  my %interwiki;
32          'mypage' => '<����>',  ##############################
33          'myword' => '��',  my %page_command = (
34          # '3C8C8B8FE98D5F3E' => '',      $PageName{IndexPage} => 'index',
35          # 'TestPage' => '',      $PageName{RssPage} => 'rss',
36      );  );
37  }  my %command_do = (
38  &main;      read => \&do_read,
39  exit(0);      TEXT_CSS => \&do_output_css,
40        edit => \&do_edit,
41        adminedit => \&do_adminedit,
42        adminchangepassword => \&do_adminchangepassword,
43        write => \&do_write,
44        index => \&do_index,
45        searchform => \&do_searchform,
46        comment => \&do_comment,
47        RandomJump  => \&do_random_jump,
48        rss => \&do_rss,
49        diff => \&do_diff,
50        wikiform    => \&do_wikiform,
51        map => \&do_map,
52    );
53    my $UA = '';  ## User agent name
54    $| = 1;
55    ##############################
56    
 # �ᥤ��  
57  sub main {  sub main {
58      &normalize_form;      $UA = $main::ENV{HTTP_USER_AGENT};
59      if ($dbmopen) {      &open_db;
60          if (!dbmopen(%database, $dbname, 0666)) {      &init_form;
61              &print_error("(dbmopen) $dbname �����ޤ���");      if ($command_do{$form{mycmd}}) {
62          }          &{$command_do{$form{mycmd}}};
63      } else {      } else {
64          if (!tie(%database, "YukiWikiDB", $dbname)) {          &{$command_do{read}};
             &print_error("(tie error)");  
         }  
     }  
   
     # myspecial�б�  
     foreach (keys %form) {  
         if (/^myspecial_(.*)/) {  
             $form{mycmd} = $1;  
             last;  
         }  
65      }      }
66        &close_db;
67    }
68    
69      if ($form{mycmd} eq 'read') {  sub do_read {
70          &do_read;    my $content = $database{$form{mypage}};
71      } elsif ($form{mycmd} eq 'preview') {    #print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n";
72          &do_preview;    my $lm = &get_info($form{mypage}, $info_LastModified);
73      } elsif ($form{mycmd} eq 'write') {    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
74          &do_write;    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
75      } elsif ($form{mycmd} eq 'edit') {    #print gmtime."Search...\n";
76          &do_edit;    my ($r, $c) = get_search_result ($form{mypage});
77      } elsif ($form{mycmd} eq 'reedit') {    my $rl = wiki::referer::list_html ($form{mypage});
78          &do_reedit;    my @toc;
79      } elsif ($form{mycmd} eq 'search') {    push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;
80          &do_search;    push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;
81      } elsif ($form{mycmd} eq 'list') {      my $cf = 'SuikaWiki/0.9';
82          &do_list;      ## Should be support at least:
83      } elsif ($form{mycmd} eq 'diff') {      ## - 'SuikaWiki/0.9' CRLF
84          &do_diff;      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
85      } else {      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
86          $form{mypage} = $toppage;      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
87          &do_read;      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
88      }      #print gmtime."Header...\n";
89      if ($dbmopen) {        &print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120,
90          dbmclose(%database);          -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          untie(%database);        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
97          print "<pre>@{[&escape($content)]}</pre>";
98      }      }
99        if ($c) {
100          print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
101          print $r;
102        }
103        if ($rl) {
104          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
105        }
106            #print "\n". gmtime."Footer...\n";
107      &print_footer($form{mypage}, $lm);
108            #print "\n". gmtime."Fin...\n";
109    }
110    
111    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}};
115      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
116        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";
121        print $content;
122      } else {
123        print "Status: 406 Unsupported Media Type\n";
124        &print_header('WikiPageIsNotCSS', -noindex => 1);
125        &print_content($database{WikiPageIsNotCSS});
126        &print_footer('WikiPageIsNotCSS');
127      }
128  }  }
129    
130  # �ڡ�����ɽ��  sub id_and_name ($) {
131  sub do_read {      my $name = shift;
132      my $page_name = $form{mypage};      if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
133      my $percent_name = &encode_percent($page_name);        qq{id="$name"><a name="$name"></a};
134      &print_header($page_name);      } else {
135      print qq|<h1>$IconTag<a href="$thisurl?mycmd=search;myword=$percent_name">$page_name</a></h1>\n|;          qq{id="$name"};
136      &print_toolbar($page_name);      }
     print &convert_html(&get_page($page_name));  
     &print_footer;  
137  }  }
138    
 # �ڡ������Խ�  
139  sub do_edit {  sub do_edit {
140      if (not &is_editable($form{mypage})) {      my ($page) = &unarmor_name(&armor_name($form{mypage}));
141          # �Խ��Բĥڡ�����ɽ���Τ�      if (not &is_editable($page)) {
142          &do_read;          &print_header($page, -noindex => 1, -expires => time+60);
143          return;          &print_message(&Resource('Error:ThisPageIsUneditable'));
144        } elsif (&is_frozen($page)) {
145            &print_header($page, -noindex => 1, -expires => time+60);
146            &print_message(&Resource('Error:ThisPageIsUneditable'));
147        } else {
148            &print_header($page, -noindex => 1, -expires => time+60);
149            &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
150      }      }
151      &editpage(&get_page($form{mypage}));      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  sub do_reedit {      if ($c) {
156      if (not &is_editable($form{mypage})) {        print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
157          # �Խ��Բĥڡ�����ɽ���Τ�        print $r;
158          &do_read;      }
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);
163    }
164    
165    sub do_adminedit {
166        my ($page) = &unarmor_name(&armor_name($form{mypage}));
167        &print_header($page, -noindex => 1, -expires => time+60);
168        if (not &is_editable($page)) {
169            &print_message(&Resource('Error:ThisPageIsUneditable'));
170      } else {      } else {
171          &editpage($form{mymsg});          &print_message(&Resource('Error:PasswordIsNotSpecified'));
172            &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
173      }      }
174        &print_footer($page);
175  }  }
176    
177  sub editpage {  sub do_adminchangepassword {
178      my $page_msg = shift;      if ($form{mynewpassword} ne $form{mynewpassword2}) {
179      my $page_name = $form{mypage};          &print_error(&Resource('Error:PasswordMismatch'));
180      my $digest = &calc_message_digest($page_msg);      }
181      &print_header($page_name);      my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
182      print qq|<h1>$IconTag${page_name}���Խ�</h1>\n|;      if ($validpassword_crypt) {
183      &print_toolbar($page_name);          if (not &valid_password($form{myoldpassword})) {
184      $page_msg = &escape($page_msg);              &print_error(&Resource('Error:PasswordIsIncorrect'));
     print <<"EOD";  
 <form action="$thisurl" method="post">  
 <!--<input type="hidden" name="mycmd" value="preview">-->  
 <input type="hidden" name="mypage" value="$page_name">  
 <input type="hidden" name="mydigest" value="$digest">  
 <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$page_msg</textarea><br>  
 <input type="submit" name="myspecial_preview" value="��ǧ">  
 <input type="submit" name="myspecial_write" value="��ǧ�����ѹ�">  
 </form>  
 <hr>  
 <h3>�ƥ����������Υ롼��</h3>  
   
 <p>�̾�����Ϥ���ʸ�������Τޤ޽��Ϥ���ޤ�����  
 �ʲ��Υ롼��˽��äƥƥ�����������Ԥ����Ȥ��Ǥ��ޤ���</p>  
   
 <ul>  
 <li>  
 ���Ԥ�����ζ��ڤ�Ȥʤ�ޤ���  
   
 <li>  
 HTML�Υ����Ͻ񤱤ޤ���  
   
 <li>  
 ''��Ĵ''�Τ褦�˥��󥰥륯��������ĤǤϤ���ȡ���Ĵ�ˤʤ�ޤ���  
   
 <li>  
 '''���˶�Ĵ'''�Τ褦�˥��󥰥륯�����Ȼ��ĤǤϤ���ȡ����˶�Ĵ�ˤʤ�ޤ���  
   
 <li>  
 ----�Τ褦�˥ޥ��ʥ�4�Ĥ�����ȡ���ʿ���ˤʤ�ޤ���  
   
 <li>  
 *���Ƭ�˽񤯤��縫�Ф��ˤʤ�ޤ���  
   
 <li>  
 **���Ƭ�˽񤯤Ⱦ����Ф��ˤʤ�ޤ���  
   
 <li>  
 -���Ƭ�˽񤯤Ȳվ�񤭤ˤʤ�ޤ���- -- --- ��3��٥뤬����ޤ���  
   
 <li>  
 :���Ƭ�˽񤯤��Ѹ�Ȳ���ʸ�����ޤ���  
   
 <pre>  
     :�Ѹ�1:���������񤤤�����ʸ1  
     :�Ѹ�2:���������񤤤�����ʸ2  
     :�Ѹ�3:���������񤤤�����ʸ3  
 </pre>  
   
 <li>  
 http://www.hyuki.com/ �Τ褦��URL�ϼ�ưŪ�˥�󥯤ˤʤ�ޤ���  
   
 <li>  
 YukiWiki�Τ褦����ʸ����ʸ���򺮤�����ʸ�����񤯤ȡ�  
 YukiWiki�Υڡ���̾�ˤʤ�ޤ���  
   
 <li>  
 [[����]]�Τ褦����Ť��礫�ä�[[ ]]�Ǥ����ä�ʸ�����񤯤ȡ�  
 YukiWiki�Υڡ���̾�ˤʤ�ޤ���  
 �礫�ä�����ˤϥ��ڡ�����ޤ�ƤϤ����ޤ���  
 ���ܸ��Ȥ��ޤ���  
   
 <li>  
 ��Ƭ�����ڡ����ǻϤޤäƤ���ȡ�  
 ��������������Ѥ߰����ޤ���  
 �ץ�������񤭹���Ȥ��˻Ȥ��������Ǥ���  
   
 <li>  
 &gt; ���Ƭ�˽񤯤ȡ�  
 ����ʸ���񤱤ޤ���  
 &gt; �ο���¿���ȥ���ǥ�Ȥ������ʤ�ޤ���3��٥�ޤǡˡ�  
   
 </ul>  
 EOD  
     &print_footer;  
 }  
   
 # �ڡ����θ���  
 sub do_search {  
     if ($form{myword}) {  
         &print_header('�������');  
         print qq|<h1>$IconTag$form{myword}�θ������</h1>\n|;  
         &print_toolbar();  
         print qq|<ul>\n|;  
         my $count = 0;  
         foreach my $page_name (sort keys %database) {    # sort����Τ�̵�Ť���  
             if ($database{$page_name} =~ /\Q$form{'myword'}\E/) {  
                 my $encoded = &encode_percent($page_name);  
                 print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|;  
                 $count++;  
             }  
185          }          }
186          print qq|</ul>\n|;      }
187          if ($count > 0) {      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
188              print qq|<p><strong>$form{myword}</strong>��ޤ�ڡ����ϡ���˼���<strong>$count</strong> �ڡ����Ǥ���</p>\n|;      my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
189          } else {      my $salt1 = $token[(time | $$) % scalar(@token)];
190              print qq|<p><strong>$form{myword}</strong>��ޤ�ڡ����ϸ��Ĥ���ޤ���</p>\n|;      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
191        my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
192        &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    sub valid_password ($) {
200        my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword');
201        return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
202    }
203    
204    sub do_index {
205      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>);
209        foreach my $page (sort keys %database) {
210            if (&is_editable($page)) {
211                print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
212          }          }
     } else {  
         &print_header('ñ�측��');  
         print qq|<h1>$IconTagñ�측��</h1>\n|;  
         &print_toolbar();  
213      }      }
214      print <<"EOD";      print qq(</ul>);
215  <p>      my ($r, $c) = get_search_result ($form{mypage});
216  <form action="$thisurl" method="post">      if ($c) {
217  <input type="hidden" name="mycmd" value="search">        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
218  <input type="text" name="myword" size="20" value="$form{myword}">        print $r;
219  <input type="submit" value="ñ�측��">      }
220  </form>      my $rl = wiki::referer::list_html ($form{mypage});
221  </p>      if ($rl) {
222  EOD          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
     &print_footer;  
 }  
   
 # �ڡ����ΰ���  
 sub do_list {  
     &print_header('�ڡ�������');  
     print qq|<h1>$IconTag �ڡ�������</h1>\n|;  
     &print_toolbar();  
     print qq|<ul>\n|;  
     foreach my $page_name (sort keys %database) {    # sort����Τ�̵�Ť���  
         my $encoded = &encode_percent($page_name);  
         print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|  
     }  
     print qq|</ul>\n|;  
     &print_footer;  
 }  
   
 # �ץ�ӥ塼  
 sub do_preview {  
     my $page_name = $form{mypage};  
     my $escapedmsg = &escape($form{mymsg});  
     &print_header($page_name);  
     print qq|<h1>$IconTag${page_name}�Υץ�ӥ塼</h1>\n|;  
     &print_toolbar($page_name);  
     # local $percent_name = &encode_percent($page_name);  
     print qq|<p>�ʲ��Υץ�ӥ塼���ǧ���ơ��褱��Хڡ��������Υܥ���ǹ������Ƥ���������</p>\n|;  
     if ($form{mymsg}) {  
         print qq|<table width="100%" bgcolor="$preview_color" ><tr><td>\n|;  
         # print &convert_html($escapedmsg);  
         print &convert_html($form{mymsg});  
         print qq|</td></tr></table>\n|;  
     } else {  
         print qq|<p>�ʥڡ��������Ƥ϶��Ǥ�����������Ȥ��Υڡ�����<strong>���</strong>����ޤ�����</p>\n|;  
223      }      }
224      &print_preview_buttons($page_name, $escapedmsg, $form{mydigest});      &print_footer($PageName{IndexPage});
     &print_footer;  
225  }  }
226    
 sub print_preview_buttons {  
     my ($page_name, $escapedmsg, $digest) = @_;  
     print <<"EOD";  
     <form action="$thisurl" method="post">  
     <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$escapedmsg</textarea>  
     <br />  
     <input type="hidden" name="mypage" value="$page_name">  
     <input type="hidden" name="mydigest" value="$digest">  
     <input type="submit" name="myspecial_preview" value="���٥ץ�ӥ塼">  
     <input type="submit" name="myspecial_write" value="�ڡ����ι���">  
     </form>  
 EOD  
 }  
   
 # �񤭹���  
227  sub do_write {  sub do_write {
228      if (not &is_editable($form{mypage})) {      if (&frozen_reject()) {
         # �Խ��Բĥڡ�����ɽ���Τ�  
         &do_read;  
229          return;          return;
230      }      }
231    
232      my $page_name = $form{mypage};      if (not &is_editable($form{mypage})) {
233            &print_header($form{mypage}, -noindex => 1);
234            &print_message(&Resource('Error:ThisPageIsUneditable'));
235            &print_footer($form{mypage});
236            return;
237        }
238    
239      # digest��Ȥäơ������ξ��ͥ����å�      if (&conflict($form{mypage}, $form{mymsg})) {
     my $original_digest = &calc_message_digest(&get_page($page_name));  
     if ($form{mydigest} ne $original_digest) {  
         &print_header($page_name);  
         print qq|<h1>$IconTag${page_name}�ǡڹ����ξ��ۤ͡������ޤ���</h1>\n|;  
         print <<"EOD";  
 <p>���ʤ������Υڡ������Խ����Ƥ���֤ˡ�  
 ¾�οͤ�Ʊ���ڡ����򹹿����Ƥ��ޤä��褦�Ǥ���  
 </p><p>  
 �ʲ��ˡ����ʤ����Խ������ƥ����Ȥ�����ޤ��Τǡ�  
 ���ʤ����Խ����Ƥ������ʤ��褦�ˡ�  
 ���ޤ��������Ģ�ʤɤ˥��ԡ����ڡ����Ȥ��Ƥ���������  
 </p><p>  
 ���ԡ����ڡ����Ȥ��Ѥ�Ǥ��顢  
 �ǿ������Ƥ򸫤ƺ����Խ���ľ���Ƥ���������  
 �ǿ������Ƥ�  
 <a target="_blank" href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>  
 �Ǹ��뤳�Ȥ��Ǥ��ޤ���  
 </p>  
 EOD  
         # &print_toolbar($page_name);  
         &print_preview_buttons($page_name, &escape($form{mymsg}), $form{mydigest});  
         &print_footer;  
240          return;          return;
241      }      }
242    
243      # diff����      # Making diff
244      {      {
245          &opendiff;          &open_diff;
246          my @msg1 = split(/\n/, &get_page($page_name));          my @msg1 = split(/\n/, $database{$form{mypage}});
247          my @msg2 = split(/\n/, $form{mymsg});          my @msg2 = split(/\n/, $form{mymsg});
248          $msgrefA = \@msg1;          $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);
249          $msgrefB = \@msg2;          &close_diff;
         &diff_check;  
         $diffbase{$form{mypage}} = $diff_text;  
         $diff_text = '';  
         &closediff;  
250      }      }
251    
     &print_header($page_name);  
     &set_page($page_name, $form{mymsg});  
252      if ($form{mymsg}) {      if ($form{mymsg}) {
253          print qq|<h1>$IconTag${page_name}�򹹿����ޤ���</h1>\n|;          $database{$form{mypage}} = $form{mymsg};
254          &print_toolbar($page_name);          if ($form{mytouch}) {
255          print &convert_html(&get_page($page_name));              &set_info($form{mypage}, $info_LastModified, time);
256      } else {              &update_recent_changes;
         print qq|<h1>$IconTag${page_name}�������ޤ���</h1>\n|;  
         &print_toolbar($page_name);  
         print qq|<p>${page_name}�������ޤ�����</p>\n|;  
     }  
     &print_footer;  
     # �������줿�Τǥ��å����Ƥ�����  
     if ($touchfile) {  
         open(FILE, "> $touchfile");  
         print FILE "\n";  
         close(FILE);  
     }  
 }  
   
 # �ڡ������ѹ���  
 sub do_diff {  
     if (not &is_editable($form{mypage})) {  
         # �Խ��Բĥڡ�����ɽ���Τ�  
         &do_read;  
         return;  
     }  
     &opendiff;  
     &print_header($form{mypage} . '���ѹ���');  
     print qq|<h1>$IconTag <a href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>���ѹ���</h1>\n|;  
     &print_toolbar();  
     $_ = &escape($diffbase{$form{mypage}});  
     print <<"EOD";  
 <ul>  
 <li>�ɲä��줿�Ԥ�<ins>�Ŀ�</ins>�Ǥ���  
 <li>������줿�Ԥ�<del>�ֿ�</del>�Ǥ���  
 <li><a href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>�عԤ���  
 </ul>  
 <hr />  
 EOD  
     print qq|<pre>\n|;  
     foreach (split(/\n/, $_)) {  
         if (/^\+(.*)/) {  
             print qq|<ins>$1</ins>\n|;  
         } elsif (/^\-(.*)/) {  
             print qq|<del>$1</del>\n|;  
         } elsif (/^\=(.*)/) {  
             print qq|$1\n|;  
         } else {  
             print qq|??? $_\n|;  
         }  
     }  
     print qq|</pre>\n|;  
     &print_footer;  
     &closediff;  
 }  
   
 sub opendiff {  
     if ($dbmopen) {  
         if (!dbmopen(%diffbase, $diffdbname, 0666)) {  
             &print_error("(dbmopen) $diffdbname �����ޤ���");  
257          }          }
258            &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
259            my $fragment = '';
260            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
261            if ($form{__comment_anchor_index}) {
262                $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 {
271          if (!tie(%diffbase, "YukiWikiDB", $diffdbname)) {          delete $database{$form{mypage}};
272              &print_error("(tie error)");          delete $infobase{$form{mypage}};
273            if ($form{mytouch}) {
274                &update_recent_changes;
275          }          }
276            &print_header($form{mypage}, -noindex => 1);
277            &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
278            &print_footer($form{mypage});
279      }      }
280  }  }
281    
282  sub closediff {  sub get_search_result ($;%) {
283      if ($dbmopen) {    my $word = lc shift;
284          dbmclose(%diffbase);    my %option = @_;
285      } else {    my @r;
286          untie(%diffbase);    foreach my $page (keys %database) {
287      }      next if !$option{-match_myself} && ($page eq $word);
288        my $content = lc $database{$page};
289        if (index (lc $page, $word) > -1) {
290          my $c = $content =~ s/\Q$word\E//g;
291          push @r, [$page, $c+20];
292        } elsif (index ($word, lc $page) > -1) {
293          my $c = $content =~ s/\Q$word\E//g;
294          push @r, [$page, $c+10];
295        } elsif (my $c = $content =~ s/\Q$word\E//g) {
296          push @r, [$page, $c];
297        }
298      }
299      #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
300      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      $r = qq|<ul class="search-result">$r</ul>| if $r;
302      wantarray? ($r, scalar @r): $r;
303    }
304    
305    sub do_random_jump {
306      my @list = keys %database;
307      my $name = &encode ($list[rand @list]);
308      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";
312  }  }
313    
 # �ե����फ��ξ����Ϣ������ %form �������  
 # &init_form('euc');  
 sub init_form {  
     my ($charcode) = @_;  
     my $query;  
     if ($ENV{REQUEST_METHOD} =~ /^post$/i) {  
         read(STDIN, $query, $ENV{CONTENT_LENGTH});  
     } else {  
         $query = $ENV{QUERY_STRING};  
     }  
     my @assocarray = split(/[&;]/, $query);  
     foreach my $assoc (@assocarray) {  
         my ($property, $value) = split(/=/, $assoc);  
         $value =~ tr/+/ /;  
         $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;  
         &jcode::convert(\$value, $charcode);  
         $form{$property} = $value;  
     }  
 }  
   
 # ���顼�ڡ�������Ϥ���  
314  sub print_error {  sub print_error {
315      my ($msg) = @_;      my ($msg) = @_;
316      &print_header('Error');      &print_header($PageName{ErrorPage}, -noindex => 1);
317      print "<h1>$IconTag$msg</h1></body></html>";      print qq(<p><strong class="error">$msg</strong></p>);
318        &print_footer($PageName{ErrorPage});
319      exit(0);      exit(0);
320  }  }
321    
322  sub escape {  sub print_header ($;%) {
323      my ($line) = shift;      my ($page, %option) = @_;
324      $line =~ s|<|&lt;|g;      my @head;
325      $line =~ s|>|&gt;|g;      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
326      $line =~ s|"|&quot;|g;      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
327      # $line =~ s|\&|&amp;|g;      if ($option{-goto}) {
328      return $line;        if ($UA =~ m#Opera|MSIE 2\.#) {
329  }            ## WARNING: This code may output unsafe HTML document if
330              ##          $option{-goto} is not clean.
331  sub inline {            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
332      my ($line) = shift;            print qq{Refresh: 0; url=$option{-goto}\n};
333      $line = &escape($line);            push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
334      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;        } else {
335      $line =~ s|''([^']+?)''|<em>$1</em>|g;                      $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
336      $line =~ s!            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                      (&lt;(mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt; # Direct http://...        }
339                          |      }
340                      ($WikiName)                         # LocalLinkLikeThis      print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
341                          |      if ($option{-expires}) {
342                      ($BracketName)                      # [[���ܸ���]]        print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
343                  )      }
344              !      if ($UA =~ m#Mozilla/2#) {
345                  &make_link($1)          my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
346              !gex;          print qq{Content-Type: $ct\n};
347      return $line;          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  sub get_page {          print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
     my $page_name = shift;  
     return $database{$page_name};  
 }  
   
 # �ڡ��������Ƥ�Ϳ����  
 # &set_page($title, $txt)  
 sub set_page {  
     # �ڡ����򹹿�����  
     my $title = $_[0];  
     $database{$title} = $_[1];  
     # ���ڡ����ʤ�������  
     unless ($database{$title}) {  
         delete $database{$title};  
     }  
     # RecentChanges�򹹿�����  
     my $delim = ' - ';  
     my @pages = split(/\n/, $database{$whatsnew});  
     my $datestr = &get_current_datestr;  
     unshift(@pages, qq|-$datestr$delim$title|);  
     # Ʊ��ڡ����ι����Ϻǿ��Τ�ΤΤߤˤ���  
     # ¸�ߤ��ʤ��ڡ����ϥ����åפ��롣  
     my %count;  
     my @newpages;  
     foreach my $line (@pages) {  
         my ($prefix, $title) = split(/$delim/, $line);  
         $count{$title}++;  
         if ($count{$title} == 1 and exists($database{$title})) {  
             push(@newpages, qq|$prefix - $title|);  
         }  
352      }      }
353      # �����������˹���      push @head, qq(<title>@{[&escape($page)]}</title>);
354      $database{$whatsnew} = join("\n", splice(@newpages, 0, $maxnew));      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  sub print_header {      my ($Links, $links) = &make_navigate_links ($page);
359      my $title = shift;      #print $Links;      ## Link: fields
360        $links = join "\n", (@head, $links);
361      print <<"EOD";      print <<"EOD";
362  Content-type: text/html  Content-Language: $lang
363    Content-Style-Type: text/css
364    
365  <html><head>  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
366  <title>$title</title>  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
367  <style type="text/css">  <html lang="$lang" class="$option{body_class}">
368  $style  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
369  </style>  $links
370  </head>  </head>
371  <body>  <body class="$option{body_class}">
372    EOD
373        &print_navigate_links ($page);
374        print <<EOD;
375    <h1 class="header">@{[&escape($page)]}</h1>
376  EOD  EOD
377  }  }
378    
379  # �ġ���С������  sub get_charset_name ($;%) {
380  sub print_toolbar {      my ($charset, %option) = (lc shift, @_);
381      my $page_name = shift;      if ($charset =~ 'euc') {
382      my $percent_name = &encode_percent($page_name);          $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
383      my $editlink = '';      } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
384      if ($page_name ne '' and &is_editable($page_name)) {          $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
385          $editlink = <<"EOD";      } elsif ($charset =~ 'jis') {
386  <a href="$thisurl?mycmd=edit;mypage=$percent_name">�Խ�</a> |          $charset = 'iso-2022-jp';
387  <a href="$thisurl?mycmd=diff;mypage=$percent_name">��ʬ</a> |      }
388  EOD      $charset;
389    }
390    
391    sub print_navigate_links (@) {
392      my ($page) = @_;
393      my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
394      my $cookedpage = &encode($page);
395      print <<EOH;
396    <div class="tools">
397        @{[ $editable
398            ? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | )
399            : qq()
400        ]}
401        <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?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
403        <a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
404        <a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
405        <a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
406        <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>
410    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      print <<"EOD";      wantarray ? ($Links, $links) : $Links;
 <p>  
  [  
 <a href="$thisurl?mycmd=read;mypage=$toppage">�ȥå�</a> |  
 <a href="$thisurl?mycmd=list">����</a> |  
 $editlink  
 <a href="$thisurl?mycmd=search">ñ�측��</a> |  
 <a href="$thisurl?mycmd=read;mypage=$whatsnew">�ǽ�����</a>  
  ]  
 </p>  
 EOD  
448  }  }
449    
 # �ڡ����Υեå������  
450  sub print_footer {  sub print_footer {
451      print <<"EOD";      my ($page, $lm) = @_;
452  <address>      my $epage = &encode ($page);
453  <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> 1.6.6 Copyright (C) 2000,2001 by <a href="http://www.hyuki.com/">Hiroshi Yuki.</a>    my $cvslog1 = q$Revision$;
454  + <a href="$modifierlink">$modifier</a> ${version}.    my $cvslog2 = q$Date$;
455  [<a href="/" title="���Υ����С��μ���">/</a>    print_navigate_links ($page);
456  <a href="/map" title="���Υ����С��ΰ���">�Ͽ�</a>    print <<"EOD";
457  <a href="/search/" title="���Υ����С��θ���">����</a>]  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
458  </address>  <div class="footer">
459  </body></html>  <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="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
461    </div>
462    </body>
463    </html>
464  EOD  EOD
465  }  }
466    
467  # URL��ڡ�����̾�������󥯤���  sub escape {
468  sub make_link {      my $s = shift;
469      my $name = shift;      $s =~ s|\r\n|\n|g;
470      if ($name =~ /^(http|https|ftp).*?(\.png|\.jpeg|\.jpg)?$/) {      $s =~ s|&|&amp;|g;
471          if ($2) {      $s =~ s|<|&lt;|g;
472              return qq|<a href="$name"><img border="0" src="$name" /></a>|;      $s =~ s|>|&gt;|g;
473          } else {      $s =~ s|"|&quot;|g;
474              return qq|&lt;<a href="$name">$name</a>&gt;|;      return $s;
475          }  }
476      } elsif ($name =~ /^mailto:(.*)/) {  
477          my $address = $1;  sub unescape {
478          return qq|&lt;<a href="$name">$address</a>&gt;|;      my $s = shift;
479      } elsif ($name =~ /^urn:[0-9A-Za-z_:-]+/) {      # $s =~ s|\n|\r\n|g;
480          return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;      $s =~ s|&lt;|<|g;
481      } elsif ($database{$name}) {      $s =~ s|&gt;|>|g;
482          my $percent_name = &encode_percent($name);      $s =~ s|&quot;|"|g;
483          return qq|<a href="$thisurl?mycmd=read;mypage=$percent_name">$name</a>|;      $s =~ s|&amp;|&|g;
484      } else {      return $s;
485          my $percent_name = &encode_percent($name);  }
486          return qq|$name<a href="$thisurl?mycmd=edit;mypage=$percent_name">?</a>|;  
487      }  sub print_content ($;$) {
488  }      my ($rawcontent, %option) = @_;
489        print &text_to_html($rawcontent, toc=>1, %option);
490  # %xx �η����˥��󥳡��ɤ���  }
491  # ����ϡ�  
492  # http://www.hyuki.com/yukiwiki/yukiwiki.cgi?mycmd=read&mypage=%3C%8C%8B%8F%E9%8D_%3E  sub text_to_html {
493  # �Ȥ��������Τ���˻Ȥ��롣      my ($txt, %option) = @_;
494  # '<����>' �� '%3C%8C%8B%8F%E9%8D_%3E'      my @toc;
495  sub encode_percent {      my @toc2 = @{$option{-toc}||[]};
496      my $name = shift;      my $tocnum = 0;
497      my $encoded = '';      
498      foreach my $ch (split(//, $name)) {      ## Load constants
499          if ($ch =~ /[A-Za-z0-9_]/) {      my %const;
500              $encoded .= $ch;      if ($option{content_format} =~ /import="([^"]+)"/) {
501          } else {        for (split /\s*,\s*/, $1) {
502              $encoded .= '%' . sprintf("%02X", ord($ch));          my $wp = $database{$_};
503            if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
504              wiki::suikawikiconst::to_hash ($wp => \%const);
505          }          }
506          }
507      }      }
508      return $encoded;      
509  }      $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
   
 # �ƥ��������Τ�HTML���Ѵ�����  
 sub convert_html {  
     my ($txt) = shift;  
510      my (@txt) = split(/\n/, $txt);      my (@txt) = split(/\n/, $txt);
511        my (@saved, @result);
512        unshift(@saved, "</p>");
513        push(@result, "<p>");
514      foreach (@txt) {      foreach (@txt) {
515          chomp;          chomp;
516          if (/^\*\*(.*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
517              push(@result, splice(@saved), '<h3>' . &inline($1) . '</h3>');              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
518          } elsif (/^\*(.*)/) {              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
519              push(@result, splice(@saved), '<h2>' . &inline($1) . '</h2>');              $tocnum++;
520          } elsif (/^----/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
521              push(@result, splice(@saved), '<hr>');              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
522          } elsif (/^(-{1,3})(.*)/) {              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
523              &back_push('ul', length($1));              $tocnum++;
524              push(@result, '<li>' . &inline($2) . '</li>');          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
525                push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
526                push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
527                $tocnum++;
528            } elsif (/^\*\*([^\x0D\x0A]*)/) {
529            # if (/^\*\*(.*)/) {
530            # Walrus mod (6) end
531                push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
532                push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
533                $tocnum++;
534            } elsif (/^\*([^\x0D\x0A]*)/) {
535                push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
536                push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
537                $tocnum++;
538            } elsif (/^(={1,6})(.*)/) {
539                &back_push('ol', length($1), \@saved, \@result);
540                push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
541            } elsif (/^(-{1,6})(.*)/) {
542              &back_push('ul', length($1), \@saved, \@result);
543              my ($pf, $l) = ('', $2);
544              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
545                my $num = 0+$1;
546                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
547              }
548              push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
549          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
550              &back_push('dl', 1);              &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,3})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
553              &back_push('blockquote', length($1));              &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);              &back_push('pre', 1, \@saved, \@result);
563              push(@result, &escape($1)); # Not &inline, but &escape              push(@result, &inline($1, const => \%const));
564            } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
565                &back_push('table', 1, \@saved, \@result);
566                #######
567                # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
568                # XXXXX
569                my $tmp = "$1,";
570                my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
571                my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
572                my @colspan = map {($_ eq '==') ? 0 : 1} @value;
573                for (my $i = 0; $i < @value; $i++) {
574                    if ($colspan[$i]) {
575                        while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
576                            $colspan[$i]++;
577                        }
578                        $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], const => \%const));
580                    } else {
581                        $value[$i] = '';
582                    }
583                }
584                push(@result, join('', '<tr>', @value, '</tr>'));
585                # XXXXX
586                #######
587            } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
588                push @result, splice (@saved), '<'.lc($1).'>';
589                unshift @saved, "</p>";
590                push @result, "<p>";
591            } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
592                push @result, splice (@saved), '</'.lc($1).'>';
593            } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
594              my $num = 0+$1;
595              push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
596              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));
602      return join("\n", @result);      
603        my $toc = '';
604        if ($option{toc}) {
605            # Convert @toc (table of contents) to HTML.
606            # This part is taken from Makio Tsukamoto's WalWiki.
607            my (@tocsaved, @tocresult);
608            foreach (@toc,@toc2) {
609                if (/^(-{1,6})(.*)$/) {
610                    &back_push('ul', length($1), \@tocsaved, \@tocresult);
611                    push(@tocresult, '<li>' . $2 . '</li>');
612                }
613            }
614            push(@tocresult, splice(@tocsaved));
615            $toc = join("\n", @tocresult);
616            $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
617        }
618        $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    
 # &back_push($tag, $count)  
 # $tag�Υ�����$level��٥�ޤǵͤ�롣  
625  sub back_push {  sub back_push {
626      my ($tag, $level) = @_;      my ($tag, $level, $savedref, $resultref, $attr) = @_;
627      while (@saved > $level) {      while (@$savedref > $level) {
628          push(@result, shift(@saved));          push(@$resultref, shift(@$savedref));
629      }      }
630      if ($saved[0] ne "</$tag>") {      if ($savedref->[0] ne "</$tag>") {
631          push(@result, splice(@saved));          push(@$resultref, splice(@$savedref));
632      }      }
633      while (@saved < $level) {      while (@$savedref < $level) {
634          unshift(@saved, "</$tag>");          unshift(@$savedref, "</$tag>");
635          push(@result, "<$tag>");          push(@$resultref, "<$tag$attr>");
636      }      }
637  }  }
638    
639  # �Խ���ǽ�ڡ�������  sub inline ($;%) {
640  sub is_editable {      my ($line, %option) = @_;
641      my ($pagename) = @_;      $line = &escape($line);
642      foreach (@uneditable) {      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
643          if ($pagename eq $_) {      $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              return 0;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
645          }      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
646        $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:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
648        $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%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%��<q@{[$2?qq( cite="$2"):'']}>$1</q>��%g;
650        $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
651        $line =~ s|''([^']+)''|<em>$1</em>|g;
652        $line =~ s{
653          (\[\[(\#\S+?)\]\])
654          |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
655          |&gt;&gt;([0-9]+)
656          |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
657        }{
658          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
659          if ($l) {
660            return &embedded_to_html($1);
661          } elsif (defined $page) {
662            &make_wikilink ($page, anchor => 0+$anchor);
663          } elsif ($anum) {
664            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
665          } elsif ($uri) {
666            &make_urilink ($uri);
667          }
668        }gex;
669        return $line;
670    }
671    
672    sub make_wikilink ($%) {
673      my ($ename, %option) = @_;
674      my $name = &unescape ($ename);
675      if ($database{$name}) {
676        my $subject = &escape (&get_subjectline ($name, delimiter => ''));
677        if ($option{anchor}) {
678          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
679        } else {
680          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
681      }      }
682      if (&is_valid_name($pagename)) {    } else {
683          return 1;      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_urilink ($;%) {
688      require URI;
689      my $uri = shift;
690      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
691        $uri = &unescape ($uri);
692        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
693          my ($site, $name) = ($1, $2);
694          for ($site, $name) {
695            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
696          }
697          &init_InterWikiName () unless $interwiki{'[[]]'};
698          if ($interwiki{$site}) {
699            &load_formatter ('interwiki');
700            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
701            $site = &escape ($site); $name = &escape ($name);
702            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          } else {
704            qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
705          }
706        } else {
707          qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
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    {my $FormIndex = 0;
727    sub make_custom_form ($$$$) {
728        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      return 0;  }}
766    
767    sub print_message {
768        my ($msg) = @_;
769        print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
770  }  }
771    
772  # Valid��̾������  sub init_form {
773  sub is_valid_name {      ## TODO: Support multipart/form-data
774      my ($pagename) = @_;      my $query = '';
775      if ($pagename =~ /^$WikiName$/) {      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
776          return 1;        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
777      } elsif ($pagename =~ /^$BracketName$/) {      }
778          return 1;      $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          $query = &code_convert(\$query, $kanjicode);
782          if ($page_command{$query}) {
783            $form{mycmd} = $page_command{$query};
784            $form{mypage} = $query;
785          } else {
786            $form{mypage} = $query;
787            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
788          }
789      } else {      } else {
790          return 0;        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.
809        # mypreview_adminedit   -> do_adminedit, with preview.
810        # mypreview_write       -> do_write, without preview.
811        foreach (keys %form) {
812            if (/^mypreview_(.*)$/) {
813                $form{mycmd} = $1;
814                $form{mypreview} = 1;
815            }
816      }      }
 }  
817    
818  # ���߻����ʸ���������      #
819  sub get_current_datestr {      # $form{mycmd} is frozen here.
820      my (@wdays) = ( "��", "��", "��", "��", "��", "��", "��" );      #
821      my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time);  
822      return sprintf("%4d-%02d-%02d (%s) %02d:%02d:%02d",      for (grep /^wikiform__/, keys %form) {
823          $year + 1900, $mon + 1, $mday, $wdays[$wday], $hour, $min, $sec);          $form{$_} = &code_convert (\$form{$_}, $kanjicode);
824  }      }
825        $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
826  # URL?SomePage�䡢      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
827  # URL?[[����]]�η������ä���硢(not yet)  }
828  # ����Ū��mycmd��read�ˤ���$form�����Ƥ����ꤹ�롣  
829  sub normalize_form {  sub update_recent_changes {
830      foreach my $key (keys %form) {      my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}";
831          if ($key =~ /^$WikiName$/) {      my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges});
832              $form{mycmd} = 'read';      shift @oldupdates; ## '#?' magic line
833              $form{mypage} = $1;      my @updates;
834              last;      foreach (@oldupdates) {
835          } elsif ($key =~ /^$BracketName$/) {          /^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/;
836              $form{mycmd} = 'read';          my $name = $1;
837              $form{mypage} = $1;          if ($name ne $form{mypage}) {
838              last;              push @updates, $_;
839          }          }
840      }      }
841        if (&is_exist_page($form{mypage})) {
842          unshift @updates, $update;
843        }
844        splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1;
845        $database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
846        if ($PathTo{TouchFile}) {
847            open(FILE, "> ".$PathTo{TouchFile});
848            print FILE localtime() . "\n";
849            close(FILE);
850        }
851  }  }
852    
853  # �Ѵ��ƥ��Ȥ�Ԥʤ��Ȥ��Υ���ץ�  {my %SubjectLine;
854  sub print_sample {  sub get_subjectline {
855      my $txt = &convert_html(<<"EOD");      my ($page, %option) = @_;
856  *�縫�Ф�1      unless (defined $SubjectLine{$page}) {
857  **�����Ф�1-1        if (not &is_editable($page)) {
858  -����1          $SubjectLine{$page} = "";
859  -����2        } else {
860  -����3          $SubjectLine{$page} = $database{$page};
861  ����1����1����1����1����1����1����1����1����1����1����1����1          $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
862  ����1����1����1����1����1����''��Ĵ''1����1����1����1����1����1          $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
863  ����1����1����1����1����1����1����1����1����1����1����1����1        }
864        }
865  ����2����2����2����2����2����2����2����2����2����2����2����2      if (length $SubjectLine{$page}) {
866  ����2����2����2����2����2����2����2����2����2����2����2����2        $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
867  ����2����2����2����2����2����2����2����2����2����2����2����2        $option{delimiter}.$SubjectLine{$page}.$option{tail};
868  **�����Ф�1-2      } else {
869  :�Ѹ�1:���������񤤤�����ʸ1��''��Ĵñ��''        '';
870  ����1����1����1����1����1����1����1����1����1����1����1����1      }
871  ����1����1����1����1����1����1����1����1����1����1����1����1  }}
 ����1����1����1����1����1����1����1����1����1����1����1����1  
 :�Ѹ�2:���������񤤤�����ʸ2  
 :�Ѹ�3:���������񤤤�����ʸ3  
 ----  
 *�縫�Ф�2  
 **�����Ф�2-1  
 &lt;http://suika.fam.cx/&gt;  
 **�����Ф�2-2  
   
 [[����]]  
   
 ����1����1����1����1����1����1����1����1����1����1����1����1  
 ����1����1����1����'''��Ĵ'''1����1����1����1����1����1����1����1  
 ����1����1����1����'''''������Ĵ'''''1����1����1����1����1����1����1����1����1  
 >����2����2����2����2����2����2����2����2����2����2����2����2  
 >����2����2����2����2����2����2����2����2����2����2����2����2  
 >����2����2����2����2����2����2����2����2����2����2����2����2  
   
 ��٥�0��٥�0��٥�0��٥�0��٥�0��٥�0  
   
 >��٥�1  
 >��٥�1  
 >��٥�1  
 >>��٥�2  
 >>��٥�2  
 >>��٥�2  
 >>>��٥�3  
 -�Ϥ�1  
 --�Ϥ�2  
 ��������2  
 ---�Ϥ�3  
 --�Ϥ�2  
 ---�Ϥ�3  
 --�Ϥ�2  
 ---�Ϥ�3  
 >>>��٥�3  
 >>>��٥�3  
 >>>��٥�3  
 EOD  
     print $txt;  
     exit;  
 }  
872    
873  sub diff_check {  sub open_db {
874      traverse_sequences(      if ($modifier_dbtype eq 'dbmopen') {
875              $msgrefA, $msgrefB,          dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}");
876              {          dbmopen(%infobase, $PathTo{WikiInfoBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiInfoBase}");
877                  MATCH => \&df_match,      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
878                  DISCARD_A => \&df_delete,          eval q{use AnyDBM_File};
879                  DISCARD_B => \&df_add,          tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}");
880              }          tie(%infobase, "AnyDBM_File", $PathTo{WikiInfoBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiInfoBase}");
881      );      } else {
882      &diff_flush;          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    
888  sub diff_flush {  sub close_db {
889      $diff_text .= join('', map { "-$_\n" } splice(@diff_deleted));      if ($modifier_dbtype eq 'dbmopen') {
890      $diff_text .= join('', map { "+$_\n" } splice(@diff_added));          dbmclose(%database);
891            dbmclose(%infobase);
892        } elsif ($modifier_dbtype eq 'AnyDBM_File') {
893            untie(%database);
894            untie(%infobase);
895        } else {
896            untie(%database);
897            untie(%infobase);
898        }
899  }  }
900    
901  sub df_match {  sub open_diff {
902      my ($a, $b) = @_;      if ($modifier_dbtype eq 'dbmopen') {
903      &diff_flush;          dbmopen(%diffbase, $PathTo{WikiDiffBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDiffBase}");
904      $diff_text .= "=$msgrefA->[$a]\n";      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
905            tie(%diffbase, "AnyDBM_File", $PathTo{WikiDiffBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDiffBase}");
906        } else {
907            tie(%diffbase, "Yuki::YukiWikiDB", $PathTo{WikiDiffBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDiffBase}");
908        }
909  }  }
910    
911  sub df_delete {  sub close_diff {
912      my ($a, $b) = @_;      if ($modifier_dbtype eq 'dbmopen') {
913      push(@diff_deleted, $msgrefA->[$a]);          dbmclose(%diffbase);
914        } elsif ($modifier_dbtype eq 'AnyDBM_File') {
915            untie(%diffbase);
916        } else {
917            untie(%diffbase);
918        }
919  }  }
920    
921  sub df_add {  sub print_editform {
922      my ($a, $b) = @_;      my ($mymsg, $lastmodified, %mode) = @_;
923      push(@diff_added, $msgrefB->[$b]);      my $frozen = &is_frozen($form{mypage});
924  }  
925        if ($form{mypreview}) {
926            if ($form{mymsg}) {
927                unless ($mode{conflict}) {
928                    print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);
929                    print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);
930                    print qq(<div class="preview">\n);
931                    &print_content($form{mymsg});
932                    print qq(</div>\n);
933                }
934            } else {
935                print @{[&Resource('Preview:Empty',escape=>1)]};
936            }
937            $mymsg = &escape($form{mymsg});
938        } else {
939            $mymsg = &escape($mymsg || $database{NewPageTemplate});
940        }
941        my $magic = '';
942        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
943    
944  sub calc_message_digest {   # You have to use MD5...      my $edit = $mode{admin} ? 'adminedit' : 'edit';
945      my $text = shift;      my $selected = 'read';
946      my @text = split(//, $text);      if ($form{after_edit_cmd}) {
947      my $len = length($text);          $selected = $form{after_edit_cmd};
948      my $checksum = 0;      } elsif ($magic =~ /Const|Config|CSS/) {
949      foreach (@text) {          $selected = 'edit';
950          $checksum += ord($_);      }
951          $checksum = ($checksum * 2) % 65536 + (($checksum & 32768) ? 1 : 0); # 16bit rotate      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";
959    <form action="$url_cgi" method="post">
960    <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">
966        <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
967        <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} ?
970        qq(
971        <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
972        <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} ? "" :
977        qq(
978            <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('Edit:Preview',escape=>1)]}">
980            <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>
985    EOD
986        unless ($mode{conflict}) {
987            ## Show help text
988            my $help = $database{WikiEditHelp};
989            $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
990            print &text_to_html ($help, toc => 0);
991      }      }
     return "$len:$checksum";  
992  }  }
993    
994  # Definition of YukiWikiDB  sub is_editable {
995  package YukiWikiDB;      my ($page) = @_;
996        if ($FixedPage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
997            return 0;
998        } else {
999            return 1;
1000        }
1001    }
1002    
1003  my $debug = 1;  # armor_name:
1004    #   WikiName -> WikiName
1005    #   not_wiki_name -> [[not_wiki_name]]
1006    sub armor_name { qq([[$_[0]]]) }
1007    
1008    # unarmor_name:
1009    #   [[bracket_name]] -> bracket_name
1010    #   WikiName -> WikiName
1011    sub unarmor_name {
1012        my ($name) = @_;
1013        if ($name =~ /^\[\[(\S+?)\]\]$/) {
1014            return $1;
1015        } else {
1016            return $name;
1017        }
1018    }
1019    
1020  # Constructor  sub decode {
1021  sub new {      my ($s) = @_;
1022      return shift->TIEHASH(@_);      $s =~ tr/+/ /;
1023        $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
1024        return $s;
1025  }  }
1026    
1027  # tying  sub encode {
1028  sub TIEHASH {      my ($s) = @_;
1029      my ($class, $dbname) = @_;      my $encoded = '';
1030      my $self = {      foreach my $ch (split(//, $s)) {
1031          dir => $dbname,          if ($ch =~ /[A-Za-z0-9_]/) {
1032          keys => [],              $encoded .= $ch;
1033      };          } else {
1034      if (not -d $self->{dir}) {              $encoded .= '%' . sprintf("%02X", ord($ch));
         if (!mkdir($self->{dir}, 0777)) {  
             print "mkdir(" . $self->{dir} . ") fail\n" if ($debug);  
             return undef;  
1035          }          }
1036      }      }
1037      return bless($self, $class);      return $encoded;
1038  }  }
1039    
1040  # Store  sub conflict {
1041  sub STORE {      my ($page, $rawmsg) = @_;
1042      my ($self, $key, $val) = @_;      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1043      my $file = &make_filename($self, $key);          return 0;
1044      if (open(FILE,"> $file")) {      }
1045          binmode(FILE);      &print_header($page, -noindex => 1);
1046          print FILE $val;      &print_content(&Resource('Error:Conflict'));
1047          close(FILE);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1048          return $self->{$key} = $val;      &print_footer($page);
1049        return 1;
1050    }
1051    
1052    sub get_now {
1053        my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
1054        $year += 1900;
1055        $mon++;
1056        $mon = "0$mon" if $mon < 10;
1057        $day = "0$day" if $day < 10;
1058        $hour = "0$hour" if $hour < 10;
1059        $min = "0$min" if $min < 10;
1060        #$sec = "0$sec" if $sec < 10;
1061        return "$year-$mon-$day $hour:$min";
1062    }
1063    
1064    sub init_InterWikiName {
1065      my @content = split /\n/, $database{InterWikiName};
1066      for (@content) {
1067        if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1068          $interwiki{$1} = $2;
1069        }
1070      }
1071      $interwiki{'[[]]'} = 1;       ## dummy
1072    }
1073    
1074    
1075    sub get_info {
1076        my ($page, $key) = @_;
1077        my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1078        return $info{$key};
1079    }
1080    
1081    sub set_info {
1082        my ($page, $key, $value) = @_;
1083        my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1084        $info{$key} = $value;
1085        my $s = '';
1086        for (keys %info) {
1087            $s .= "$_=$info{$_}\n";
1088        }
1089        $infobase{$page} = $s;
1090    }
1091    
1092    sub frozen_reject {
1093        my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);
1094        my ($willbefrozen) = $form{myfrozen};
1095        if (not $isfrozen and not $willbefrozen) {
1096            # You need no check.
1097            return 0;
1098        } elsif (valid_password($form{mypassword})) {
1099            # You are admin.
1100            return 0;
1101      } else {      } else {
1102          print "$file create error.";          &print_error(&Resource('Error:PasswordIsIncorrect'));
1103            return 1;
1104      }      }
1105  }  }
1106    
1107  # Fetch  sub is_frozen {
1108  sub FETCH {      my ($page) = @_;
1109      my ($self, $key) = @_;      if (&get_info($page, $info_IsFrozen)) {
1110      my $file = &make_filename($self, $key);          return 1;
1111      if (open(FILE, $file)) {      } else {
1112          local $/;          return 0;
         $self->{$key} = <FILE>;  
         close(FILE);  
1113      }      }
     return $self->{$key};  
1114  }  }
1115    
1116  # Exists  sub do_comment {
1117  sub EXISTS {      my ($content) = $database{$form{mypage}};
1118      my ($self, $key) = @_;      my $default_name;   ## this code does not strict.
1119      my $file = &make_filename($self, $key);      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1120      return -e($file);      my $datestr = '[WEAK['.&get_now.']]';
1121        my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
1122        ($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;
1130        $content =~ s{(\[\[\#r?comment\]\])}{
1131          my $embed = $1;
1132          if ($i == $form{comment_index}) {
1133            if ($embed ne '[[#rcomment]]') {
1134              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1135            } else {
1136              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1137            }
1138          }
1139          $i++; $embed;
1140        }ge;
1141        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";
1145        }
1146        $form{__comment_anchor_index} = $anchor;
1147        if ($form{mymsg} || $form{myname}) {
1148            $form{mymsg} = $content;
1149            $form{mytouch} = 'on';
1150            &do_write;
1151        } else {
1152            $form{mycmd} = 'read';
1153            &do_read;
1154        }
1155  }  }
1156    
1157  # Delete  sub get_new_anchor_index ($) {
1158  sub DELETE {      my $content = shift;
1159      my ($self, $key) = @_;      my $anchor = 0;
1160      my $file = &make_filename($self, $key);      $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1161      unlink $file;      $anchor + 1;
1162      return delete $self->{$key};  }
1163    
1164    my $CommentIndex = 0;
1165    sub embedded_to_html {
1166        my ($embedded) = @_;
1167        if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
1168          unless ($main::_EMBEDED) {
1169            my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1170            return <<"EOD";
1171    <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1172        <input type="hidden" name="mycmd" value="comment">
1173        <input type="hidden" name="mypage" value="$form{mypage}">
1174        <input type="hidden" name="myLastModified" value="$lastmodified">
1175        <input type="hidden" name="mytouch" value="on">
1176        <input type="hidden" name="comment_index" value="$CommentIndex">
1177        @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1178        <input type="text" name="myname" value="" size="10" class="comment-name">
1179        <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1180        <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
1181    </p></form>
1182    EOD
1183         } else {
1184            return <<"EOD";
1185    <del><form action="$url_cgi" method="get">
1186        <input type="hidden" name="mycmd" value="read">
1187        <input type="hidden" name="mypage" value="$form{mypage}">
1188        @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1189        <input type="text" name="myname" value="" size="10" disabled="disabled">
1190        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1191    </form></del>
1192    EOD
1193        }
1194      } elsif ($embedded =~ /$embed_command{searched}/) {
1195        return get_search_result ($1, -match_myself => 1);
1196      } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1197        my ($name, $r) = ($1, '');
1198        if ($main::_EMBEDED != 1) {
1199          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1200          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1201          if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1202            $main::_EMBEDED = 1;
1203            $r = &text_to_html ($content, content_format => $cf);
1204            $main::_EMBEDED = 0;
1205          } elsif (length $content) {
1206            $r = "<pre>@{[&escape ($content)]}</pre>";
1207          } else {
1208            $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1209          }
1210        } else {    ## nested #EMBED
1211          $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)]}" 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:(.+)\]\]$/) {
1215        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1216      } else {
1217        return $embedded;
1218      }
1219    }
1220    
1221    sub load_formatter (@) {
1222        for my $t (@_) {
1223            unless ($fmt{$t}) {
1224                require Message::Util::Formatter;
1225                $fmt{$t} = Message::Util::Formatter->new;
1226                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1227                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1228                }
1229            }
1230        }
1231  }  }
1232    
1233  sub FIRSTKEY {  sub do_wikiform {
1234      my ($self) = @_;      my $content = $database{$form{mypage}};
1235      opendir(DIR, $self->{dir}) or die $self->{dir};      my $anchor = &get_new_anchor_index ($content);
1236      @{$self->{keys}} = grep /\.txt$/, readdir(DIR);      &load_formatter (qw/form_template form_option/);
1237      foreach my $name (@{$self->{keys}}) {      my $write = 0;
1238          $name =~ s/\.txt$//;      my $i = 1;
1239          $name =~ s/[0-9A-F][0-9A-F]/pack("C", hex($&))/eg;      $content =~ s{$embed_command{form}}{
1240            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1241            if (($wfname && $wfname eq $form{wikiform_targetform})
1242                || $i == $form{wikiform_index}) {
1243                $template =~ s/\\(.)/$1/g;
1244                $option =~ s/\\(.)/$1/g;
1245                my $param = bless {}, 'SuikaWiki::Plugin';
1246                $param->{page} = $form{mypage};
1247                $param->{form_index} = $i;
1248                $param->{form_name} = $wfname;
1249                $param->{anchor_index} = $anchor;
1250                $param->{argv} = \%form;
1251                $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      }      }
     return shift @{$self->{keys}};  
1288  }  }
1289    
1290  sub NEXTKEY {  sub code_convert {
1291      my ($self) = @_;    require Jcode;
1292      return shift @{$self->{keys}};      my ($contentref, $code) = (shift, shift || $kanjicode);
1293        $code = 'jis' if $code =~ /iso/;
1294        $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;
1302  }  }
1303    
1304  sub make_filename {  sub do_diff {
1305      my ($self, $key) = @_;      if (not &is_editable($form{mypage})) {
1306      my $enkey = '';          &do_read;
1307      foreach my $ch (split(//, $key)) {          return;
1308          $enkey .= sprintf("%02X", ord($ch));      }
1309        &open_diff;
1310        my $title = $form{mypage};
1311        &print_header($title, -noindex => 1);
1312        $_ = &escape($diffbase{$form{mypage}});
1313        &close_diff;
1314        print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>);
1315        print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1316        print qq(<pre class="diff">);
1317        foreach (split(/\n/, $_)) {
1318            if (/^\+(.*)/) {
1319                print qq(<ins class="added">$1</ins>\n);
1320            } elsif (/^\-(.*)/) {
1321                print qq(<del class="deleted">$1</del>\n);
1322            } elsif (/^\=(.*)/) {
1323                print qq(<span class="same">$1</span>\n);
1324            } else {
1325                print qq|??? $_\n|;
1326            }
1327      }      }
1328      return $self->{dir} . "/$enkey.txt";      print qq(</pre>);
1329        &print_footer($title);
1330  }  }
 __END__  
   
 =head1 NAME  
   
 YukiWiki - ��ͳ�˥ڡ������ɲá�������Խ��Ǥ���Web�ڡ�������CGI  
   
     Copyright (C) 2000,2001 by Hiroshi Yuki.  
     ���� <hyuki@hyuki.com>  
     http://www.hyuki.com/  
     http://www.hyuki.com/yukiwiki/  
   
 =head1 SYNOPSIS  
   
     http://www.hyuki.com/yukiwiki/yukiwiki.cgi  
   
 =head1 DESCRIPTION  
   
 YukiWiki�ʷ�륦�������ˤϻ��üԤ���ͳ�˥ڡ������ɲá�������Խ��Ǥ���  
 �Ի׵Ĥ�Web�ڡ���������CGI�Ǥ���  
 Web��ư���Ǽ��ĤȤ���äȻ��Ƥ��ޤ�����  
 Web�Ǽ��Ĥ�ñ�˥�å��������ɲä�������ʤΤ��Ф��ơ�  
 YukiWiki�ϡ�Web�ڡ������Τ�ͳ���ѹ����뤳�Ȥ��Ǥ��ޤ���  
   
 YukiWiki�ϡ�Cunningham & Cunningham��WikiWikiWeb��  
 ���ͤ򻲹ͤˤ����ȼ��˺���ޤ�����  
   
 YukiWiki��Perl�ǽ񤫤줿CGI������ץȤȤ��Ƽ¸�����Ƥ��ޤ��Τǡ�  
 Perl��ư���Web�����Фʤ�����Ū�ưפ����֤Ǥ��ޤ���  
   
 ���Ȥ�dbmopen���Ȥ���Ķ��ʤ�����֤Ǥ��ޤ�(Version 1.5.0�ʹߤʤ�dbmopen���Ȥ��ʤ��Ƥ����֤Ǥ��ޤ�)��  
   
   
 YukiWiki�ϥե꡼���եȤǤ���  
 ����ͳ�ˤ��Ȥ�����������  
   
 =head1 ������ˡ  
   
 =head2 ����  
   
 YukiWiki�κǿ��Ǥϡ�  
 http://www.hyuki.com/yukiwiki/  
 ��������Ǥ��ޤ���  
   
 =head2 �ե��������  
   
     readme.txt      �ɥ������  
     yukiwiki.cgi    YukiWiki����  
     yukiwiki.gif    �����ʥ��顼�ǡ�  
     yukimono.gif    �����ʥ�Υ����ǡ�  
     jcode.pl        ���������ɥ饤�֥��  
   
 =head2 ���󥹥ȡ���  
   
 =over 4  
   
 =item 1.  
   
 ���������֤�򤯡�  
   
 =item 2.  
   
 yukiwiki.cgi�ΤϤ�������ˤ���������ǧ���ޤ���  
 �̾�ϲ��⤷�ʤ��Ƥ褤����  
 �Ϥ����$touchfile��''�ˤ��������褤�Ǥ��礦��  
   
 =item 3.  
   
 yukiwiki.cgi��jcode.pl��Ʊ���Ȥ��������֤��ޤ���  
   
 =item 4.  
   
 ������0��yukiwiki.db�Ȥ����ե���������֤��ޤ���  
 ��Perl�����ƥ�ˤ�äƤ�yukiwiki.pag, yukiwiki.dir��  
   
 =item 5.  
   
 yukiwiki.cgi�˥֥饦�����饢���������ޤ���  
   
 =back  
   
 =head2 �ѡ��ߥå����  
   
         �ե�����        �ѡ��ߥå����      ž���⡼��  
         yukiwiki.cgi    755                 ASCII  
         yukiwiki.gif    644                 BINARY  
         yukimono.gif    644                 BINARY  
         jcode.pl        644                 ASCII  
   
     $dbmopen = 1; �ˤ������:  
         yukiwiki.db     666                 BINARY  
         (yukiwiki.pag, yukiwiki.dir�ξ��⤢���  
   
     $dbmopen = 0; �ˤ������: (�����ȥǥ��쥯�ȥ��777�ˤ��Ƥ���)  
         .               777                 (ž�����ʤ�)  
   
 =head1 �ǡ����ΥХå����å���ˡ  
   
 $dbmopen = 1;�ξ��ϡ�  
 �ǡ����Ϥ��٤�yukiwiki.db(.dir, .pag)�����롣  
 �����Хå����åפ���Ф褤��  
   
 $dbmopen = 0;�ξ��ϡ�  
 yukiwiki�Ȥ����ǥ��쥯�ȥ꤬�Ǥ���Τǡ�  
 ����ʲ���Хå����åפ���Ф褤��  
   
 =head1 �������ڡ����κ����  
   
 =over 4  
   
 =item 1.  
   
 �ޤ���Ŭ���ʥڡ������㤨��FrontPage�ˤ����ӡ�  
 �ڡ����β��ˤ�����Խ��ץ�󥯤򤿤ɤ�ޤ���  
   
 =item 2.  
   
 ����ȥƥ��������Ϥ��Ǥ�����֤ˤʤ�Τǡ�  
 ������NewPage�Τ褦��ñ��  
 ����ʸ����ʸ�����ߤ��Ƥ����ʸ�����  
 ��񤤤ơ���¸�פ��ޤ���  
   
 =item 3.  
   
 ��¸����ȡ�FrontPage�Υڡ������񤭴���ꡢ  
 ���ʤ����񤤤�NewPage�Ȥ���ʸ����θ���� ? �Ȥ�����󥯤�ɽ������ޤ���  
 ���� ? �Ϥ��Υڡ������ޤ�¸�ߤ��ʤ����Ȥ򼨤����Ǥ���  
   
 =item 4.  
   
 ���� ? �򥯥�å�����ȿ������ڡ���NewPage���Ǥ��ޤ��Τǡ�  
 ���ʤ��ι�����ʸ�Ϥ򤽤ο������ڡ����˽񤤤���¸���ޤ���  
   
 =item 5.  
   
 NewPage�ڡ������Ǥ����FrontPage�� ? �Ͼä��ơ���󥯤Ȥʤ�ޤ���  
   
 =back  
   
 =head1 �ƥ����������Υ롼��  
   
 =over 4  
   
 =item *  
   
 Ϣ³����ʣ���Ԥϥե��뤵���ɽ������ޤ���  
   
 =item *  
   
 ���Ԥ�����C<< <p> >>�ζ��ڤ�Ȥʤ�ޤ���  
   
 =item *  
1331    
1332  HTML�Υ����Ͻ񤱤ޤ���  sub do_rss {
1333        eval q{use Yuki::RSS};
1334  =item *      my $rss = new Yuki::RSS(
1335            version => '1.0',
1336  B<''�ܡ����''>�Τ褦�˥��󥰥륯��������ĤǤϤ���ȡ�          encoding => &get_charset_name ($kanjicode),
1337  �ܡ����C<< <b> >>�ˤʤ�ޤ���      );
1338        my $scheme = 'http';
1339  =item *      $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  B<'''������å�'''>�Τ褦�˥��󥰥륯�����Ȼ��ĤǤϤ���ȡ�      $rss->stylesheet (
1342  ������å�C<< <i> >>�ˤʤ�ޤ���        href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1343          type      => 'text/css',
1344  =item *      );
1345        $rss->channel(
1346  B<---->�Τ褦�˥ޥ��ʥ�4�Ĥ�����ȡ�          title   => &Resource ('RSS:WikiTitle'),
1347  ��ʿ��C<< <hr> >>�ˤʤ�ޤ���          link    => $myuri,
1348            description     => &Resource ('RSS:WikiDescription'),
1349  =item *          'dc:language'   => $lang,
1350        );
1351  �Ԥ�B<*>�ǤϤ����ȡ�      my $recentchanges = $database{RecentChanges};
1352  �縫�Ф�C<< <h2> >>�ˤʤ�ޤ���      my $count = 0;
1353        foreach (split(/\n/, $recentchanges)) {
1354  =item *          last if ($count >= 15);
1355            if (/\[\[([^]]+)\]\]/) {
1356  �Ԥ�B<**>�ǤϤ����ȡ�            my $title = $1;
1357  �����Ф�C<< <h3> >>�ˤʤ�ޤ���            $rss->add_item (
1358                title       => &escape($title),
1359  =item *              link        => $myuri . '?' . &encode($title),
1360                description => &escape(&get_subjectline($title,delimiter=>'')),
1361  �Ԥ�ޥ��ʥ�-�ǤϤ����ȡ�              'dc:date'   => &get_info ($title, $info_LastModified),
1362  �վ��C<< <ul> >>�ˤʤ�ޤ���            );
1363  �ޥ��ʥ��ο���������ȥ�٥뤬������ޤ���3��٥�ޤǡ�            $count++;
1364            }
1365      -����1      }
1366      --����1-1      # print RSS information (as XML).
1367      --����1-2      print <<"EOD"
1368      -����2  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
     -����3  
     --����3-1  
     ---����3-1-1  
     ---����3-1-2  
     --����3-2  
   
 =item *  
   
 �������Ȥ��ȡ�  
 �Ѹ�Ȳ���ʸ�Υꥹ��C<< <dl> >>���񤱤ޤ���  
   
     :�Ѹ�1:���������񤤤�����ʸ1  
     :�Ѹ�2:���������񤤤�����ʸ2  
     :�Ѹ�3:���������񤤤�����ʸ3  
   
 =item *  
   
 ���  
   
 =over 4  
   
 =item *  
   
 LinkToSomePage��FrontPage�Τ褦�ˡ�  
 ��ñ��κǽ�ΰ�ʸ������ʸ���ˤ�����Τ�  
 ��İʾ�Ϣ³������Τ�YukiWiki�Υڡ���̾�Ȥʤꡢ  
 ���줬ʸ����˴ޤޤ��ȥ�󥯤ˤʤ�ޤ���  
   
 =item *  
   
 http://www.hyuki.com/ �Τ褦��URL�ϼ�ưŪ�˥�󥯤ˤʤ�ޤ���  
   
 =item *  
   
 ��Ť��礫�ä�[[ ]]�Ǥ����ä�ʸ����⡢  
 YukiWiki�Υڡ���̾�ˤʤ�ޤ���  
 �礫�ä�����ˤϥ��ڡ�����ޤ�ƤϤ����ޤ���  
 ���ܸ��Ȥ��ޤ���  
   
 =back  
   
 =item *  
   
 ��Ƭ�����ڡ����䥿�֤ǻϤޤäƤ���ȡ�  
 ����������Ѥߤ�����C<< <pre> >>�Ȥ��ư����ޤ���  
 �ץ�������ɽ���ʤɤ˻Ȥ��������Ǥ���  
   
   
 =item *  
   
 �Ԥ� > �ǤϤ����ȡ�  
 ����ʸC<< <blockquote> >>���񤱤ޤ���  
 >�ο���¿���ȥ���ǥ�Ȥ������ʤ�ޤ���3��٥�ޤǡˡ�  
   
     >ʸ��  
     >ʸ��  
     >>����ʤ����  
     >ʸ��  
   
 =back  
   
 =head1 ��������  
   
 =over 4  
   
 =item *  
   
 2001ǯ10��20����Version 1.6.6��  
   
 �����ξ����к���  
 ���ڡ����δ�ñ�ʥ����å�������äƤ�����  
 �������˥����å��������Ӥ��롣  
 �����Ľ��digest�Ȥ���ʸ����򸡺������ʬ���롣  
 �����MD5�ʤɤǤ����Ȥ�ä����������Τ�����ɡ�  
   
 ���ͻ���ɽ��������å������ʤɤϡֶ˰��פ���Υڡ����򻲹ͤˤ�����  
   
 =item *  
   
 2001ǯ10��17����Version 1.6.5��  
   
 �ץ�ӥ塼���̤ǡ������ܥ���򲡤����Ȥ������������  
 ��å����������Ƥ�input���Ǥ�type="hidden"��Ȥä�������Τ���롣  
 ����ˡ�textarea���Ǥ�Ȥ���  
 �ƥץ�ӥ塼�Ѥ�myspecial_��Ƴ�����Ǥ⤭�줤���к��ǤϤʤ���  
   
 =item *  
   
 2001ǯ8��30����Version 1.6.4��  
   
 URL�ǥ����쥯�Ȥ˥ڡ���̾����ꤷ�Ƥ⡢  
 $WikiName��$BracketName�ʳ��Υڡ�������ʤ��褦�ˤ�����  
 (is_valid_name��is_editable����)��  
   
 =item *  
   
 2001ǯ8��30����Version 1.6.3��  
   
 RecentChanges���Խ������Խ��ԲĤȤ�����  
 �Խ��Բĥڡ�����@uneditable�˥ڡ���̾������롣  
   
 =item *  
   
 2001ǯ2��25����Version 1.6.1, 1.6.2��  
   
 ��ʬ��ǽ�ΥХ�������  
 do_preview��'>'�������ʤ��Х�����  
 �ʥ桼������λ�Ŧ�ˡ�  
   
 =item *  
   
 2001ǯ2��22����Version 1.6.0��  
 ��ʬ��ǽ�����������  
   
 =item *  
   
 2001ǯ2��19����Version 1.5.4��  
 �����ե�����ؤΥ�󥯤ϲ����ˤ��Ƥߤ���  
   
 =item *  
   
 2001ǯ2��19����Version 1.5.3��  
 RecentChanges����˺�������ڡ���������Τ��᤿��  
 use strict;�ǰ��ä�������ʬ�򾯤�����(�����ǤϤʤ�)��  
   
 =item *  
   
 2001ǯ2��16����Version 1.5.2��  
 textarea��ɽ������ӥץ�ӥ塼�������� < �� > �� &lt; �� &gt; ���Ѵ�����  
 (do_preview, editpage, print_preview_buttons)��  
   
 =item *  
   
 2000ǯ12��27����Version 1.5.1��  
 �ץ�ӥ塼���̤�����������  
   
 =item *  
   
 2000ǯ12��22����Version 1.5.0��  
 ����Ū�ˤ����֤��ľ������  
 ���������Ӻ�������褦�ˤ���(do_list)��  
 �񤭹������˳�ǧ���̤�Ф��褦�ˤ���(do_preview)��  
 �ƥ����Ȥν������Խ����̤����줿(do_edit, do_reedit)��  
 WhatsNew��RecentChanges��TopPage��FrontPage���ѹ�������  
   
 =item *  
   
 2000ǯ12��20����Version 1.1.0��  
 tie�����Ѥ��ơ�dbmopen���Ȥ��ʤ����Ǥ�ư���褦�˽�����  
 ���ѼԤ�1�ͤǤ���ֶ˰��פ��󤫤�  
 ���äƤ��������������ɤ򸵤ˤ��Ƥ��ޤ���  
   
 =item *  
   
 2000ǯ9��5����Version 1.0.2��  
  <body color=...> �� <body bgcolor=...>  
 ���ѼԤ���λ�Ŧ�ˤ�롣���ա�  
   
 =item *  
   
 2000ǯ8��6����Version 1.0.1�������  
 C MAGAZINE�ʥ��եȥХ󥯥ѥ֥�å��󥰡�  
 2000ǯ10���Ϣ�ܵ������������ǡ�  
 [[ ]] �κǸ夬��˾�פΤ褦�˥��ե�JIS��  
 0x5D�ˤʤ���β����Ԥʤä���  
   
 =item *  
   
 2000ǯ8��5����Version 1.0.0�������  
   
 =item *  
   
 2000ǯ7��23����Version 0.82�������  
 �Խ����Υ�󥯥ߥ���  
 <textarea>��°���ѹ���  
   
 =item *  
   
 2000ǯ7��22����Version 0.81�������  
 �������Ȥ߹��ࡣ  
   
 =item *  
   
 2000ǯ7��21����Version 0.80�������  
 POD��CGI��˽񤭹��ࡣ  
   
 =item *  
   
 2000ǯ7��19����Version 0.70�������  
 '''������å�'''�䡢--��---��>>��>>>�ʤɤ������  
   
 =item *  
   
 2000ǯ7��18����Version 0.60�������  
 *����*��''����''���ѹ�  
   
 =item *  
   
 2000ǯ7��17����Version 0.50�������  
   
 =item *  
   
 2000ǯ7��17��������ˤ��������ɲä��롣  
   
 =item *  
   
 2000ǯ7��16�������������ɲá�  
   
 =item *  
   
 2000ǯ7��15����������  
   
 =back  
   
 =head1 TODO  
   
     - �ƥ�����ɽ���⡼��  
     - Charset��������  
     - textarea����Ĥ������б�  
     - ��˥塼�αѸ�ɽ���յ�  
     - �ץ�ӥ塼�Υܥ���ǡ�mymsg��input��value������Ƥ��뤬�����Ԥ򤽤Τޤ�value�ˤ���ƤϤ����ʤ��ΤǤϤʤ�����  
     - �ֺ��Խ��פε�ǽ�ϥ֥饦���� back �ǽ�ʬ�ǤϤʤ������ץ�ӥ塼�Ϥ�äȥ���ץ�ˡ�  
     - �ڡ��������ȥ��Wikiname�ˤ������ˤ�����褦�ˤ��롣  
     - InterWiki���ε�ǽ��URL�򱣤��Ĥġ���󥯤�ĥ���  
   
 =head1 ���  
   
     Copyright (C) 2000 by Hiroshi Yuki.  
     ���� <hyuki@hyuki.com>  
     http://www.hyuki.com/  
     http://www.hyuki.com/yukiwiki/  
   
 ���䡢�ո����Х����� hyuki@hyuki.com �˥᡼�뤷�Ƥ���������  
   
 =head1 ���۾��  
1369    
1370  YukiWiki�ϡ�  @{[$rss->as_string]}
1371  GNU General Public License�ˤƸ������ޤ���  EOD
1372    }
1373    
1374  YukiWiki�ϥե꡼���եȤǤ���  sub _rfc3339_date ($) {
1375  ����ͳ�ˤ��Ȥ�����������    my @time = gmtime (shift);
1376  ��ʬ���ߤ�YukiWiki������褦�˥���ץ�ˤ��Ƥ���ޤ���    sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1377    }
1378    
1379  =head1 �ռ�  sub is_exist_page {
1380        my ($name) = @_;
1381        if ($use_exists) {
1382            return exists($database{$name});
1383        } else {
1384            return $database{$name};
1385        }
1386    }
1387    
1388  �ܲȤ�WikiWiki���ä�Cunningham & Cunningham, Inc.��  sub __get_database ($) { $database{ $_[0] } }
1389  ���դ��ޤ���  sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1390    
1391  YukiWiki��ڤ���ǻȤäƤ�������  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;
1424    sub add ($$) {
1425      my $page = shift;
1426      my $uri = shift;
1427      unless (ref $uri) {
1428        require URI;
1429        $uri = URI->new ($uri);
1430        ## Some schemes do not have query part.
1431        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1432        $uri->fragment (undef);
1433      }
1434      $uri = $uri->canonical;
1435      return unless $uri;
1436      for my $regex (&get_dont_record) {
1437        return if $uri =~ /$regex/;
1438      }
1439      my %list = get ($page);
1440      $list{ $uri }++;
1441      set ($page, \%list);
1442    }
1443    sub get ($) {
1444      my $page = shift;
1445      split /"/, main::get_info ($page, 'Referer');
1446    }
1447    sub set ($%) {
1448      my $page = shift;
1449      my $list = shift;
1450      main::set_info ($page, Referer => join '"', %$list);
1451    }
1452    
1453    sub get_dont_record () {
1454      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1455      grep !/^#/,
1456      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1457    }
1458    sub get_site_name () {
1459      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1460      my @item;
1461      for (@lines) {
1462        next if /^#/;
1463        my ($uri, $name) = split /\s+/, $_, 2;
1464        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1465        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1466        push @item, [$uri, qq(q($name))];
1467      }
1468      @item;
1469    }
1470    
1471    sub list_html ($) {
1472      my $page = shift;
1473      my %list = get ($page);
1474      my $r = '';
1475      my @name = get_site_name;
1476      for my $uri (sort keys %list) {
1477        my $title;
1478        for my $item (@name) {
1479          if ($uri =~ /$item->[0]/) {
1480            $title = $uri;
1481            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1482              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1483            last;
1484          }
1485        }
1486        my $euri = main::escape ($uri);
1487        if ($title) {
1488          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1489        } else {
1490          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1491        }
1492      }
1493      $r ? qq(<ul>$r</ul>\n) : '';
1494    }
1495    
1496  YukiWiki�Υ�����ǥ����󤷤Ƥ������ä��������व��  sub __decode ($) {
1497  http://city.hokkai.or.jp/~reina/    my $s = shift;
1498  �˴��դ��ޤ���    $s =~ tr/+/ /;
1499      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1500      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  tie��Ȥä��Ǥθ��ˤʤ륳���ɤ����äƤ������ä�  package main;
1664  �ֶ˰��פ���˴��դ��ޤ���  &main;
1665    exit 0;
1666    
1667  =head1 ���ȥ��  1;
1668    __END__
1669    =head1 NAME
1670    
1671  =over 4  wiki.cgi - This is YukiWiki, yet another Wiki clone.
1672    walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
1673    
1674  =item *  =head1 DESCRIPTION
1675    
1676  YukiWiki�ۡ���ڡ���  YukiWiki is yet another Wiki clone.
 http://www.hyuki.com/yukiwiki/  
1677    
1678  =item *  YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).
1679    YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),
1680    and some embedded commands (such as [[#comment]] to add comments).
1681    
1682  �ܲȤ�WikiWiki  Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.
 http://c2.com/cgi/wiki?WikiWikiWeb  
1683    
1684  =item *  =head1 AUTHOR
1685    
1686  �ܲȤ�WikiWiki�κ��(Cunningham & Cunningham, Inc.)  Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/
 http://c2.com/  
1687    
1688  =item *  =head1 LICENSE
1689    
1690  YukiWiki�Υ����ǥ�����򤷤Ƥ������ä��������व��Υڡ���  Copyright (C) 2000-2002 by Hiroshi Yuki.
 http://city.hokkai.or.jp/~reina/  
1691    
1692  =back  This program is free software; you can redistribute it and/or
1693    modify it under the same terms as Perl itself.
1694    
1695  =cut  =cut

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24  
Google Analytics is used in this page; Cookies are used. 忍者AdMax is used in this page; Cookies are used. Privacy policy.