/[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.8 by wakaba, Sun Mar 24 00:51:52 2002 UTC revision 1.42 by wakaba, Mon Dec 30 03:20:06 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2  use lib "../lib";  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
3  use CGI::Carp 'fatalsToBrowser';  #
4  use Algorithm::Diff qw(traverse_sequences);  # This program is free software; you can redistribute it and/or
5  # use strict;  # modify it under the same terms as Perl itself.
6  #  
7  # yukiwiki.cgi - Yet another WikiWikiWeb clone.  use strict;
8  #  use lib qw(./WalWiki/lib);
9  # Copyright (C) 2000,2001 by Hiroshi Yuki.  use CGI::Carp qw(fatalsToBrowser);
10  # <hyuki@hyuki.com>  use Yuki::DiffText qw(difftext);
11  # http://www.hyuki.com/yukiwiki/  use Fcntl;
12  #  #
13  # This program is free software; you can redistribute it and/or modify  # You MUST modify following '$modifier_...' variables.
14  # it under the terms of the GNU General Public License as published by  #
15  # the Free Software Foundation; either version 2 of the License, or  # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.
16  # (at your option) any later version.  # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.
17  #  my $modifier_dbtype = 'YukiWikiDB';     # Slow, available on all environment.
18  # This program is distributed in the hope that it will be useful,  my $modifier_dir_data = './wikidata'; # Your data directory.
19  # but WITHOUT ANY WARRANTY; without even the implied warranty of  our $url_cgi = '/~wakaba/-temp/wiki/wiki';
20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          ## - MUST be started by '/'
21  # GNU General Public License for more details.          ## - MUST NOT include [&<>"] and/or non-URI characters
22  #  our %uri;
23  # $Id$  $uri{wiki} = $url_cgi;
24  ##############################  $uri{cvs_wikipage} = '/gate/cvs/wakaba/suikawiki/wiki/';
25  my $version = "1.6.6";  $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
26  ##############################  my $file_touch = "$modifier_dir_data/touched.txt";
27  # ñ�ȥƥ��ȤΤȤ��ˤ� 1 �ˤ��롣  ##############################
28  my $testing = 0;  #
29  ##############################  # You MAY, but do NOT NEED modify following variables.
30  # �����饤�֥��  #
31  my $jcodelib = 'jcode.pl';  my $dataname = "$modifier_dir_data/wiki";
32  ##############################  my $infoname = "$modifier_dir_data/info";
33  # ��¸��ɽ���δ���������  my $diffname = "$modifier_dir_data/diff";
34  my $kanjicode = 'euc';     # 'sjis' 'euc'  my $use_exists = 0; # If you can use 'exists' method for your DB.
35  my $charset = 'euc-jisx0213';  # 'Shift_JIS' 'EUC-JP'  ##############################
36  ##############################  my $FrontPage = 'HomePage';
37  # dbmopen���Ȥ���ʤ�1���Ȥ��ʤ��ʤ�0  my $IndexPage = 'IndexPage';
38  my $dbmopen = 0;  my $SearchPage = 'SearchPage';
39  ##############################  my $CreatePage = 'CreatePage';
40  # �ǡ����١���̾��.pag, .dir, .db�ʤɤ����ס�  my $ErrorPage = 'ErrorPage';
41  # $dbmopen = 1�ΤȤ��ϥǡ����١���̾��  my $RssPage = 'RssPage';
42  # $dbmopen = 0�ΤȤ��ϥǥ��쥯�ȥ�̾�ˤʤ롣  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
43  my $dbname = './wikidata';  my %PageName = (
44  my $diffdbname = './wikidiff';    DefaultStyleForHTML   => 'WikiHTMLStyle',
45  ##############################  );
46  # �����Ԥλ�̾�ʼ�ͳ���ѹ����Ƥ���������  ##############################
47  my $modifier = 'suika';  my %fmt;        ## formatter objects
48  ##############################  my %embed_command = (
49  # �����Ԥ�Web�ڡ����ʼ�ͳ���ѹ����Ƥ���������          searched        => '^\[\[#searched:([^\]]+)\]\]$',
50  my $modifierlink = 'http://suika.fam.cx/';          form    => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
51  ##############################  );
52  # ���Υڡ�����URL  ##############################
53  my $thisurl = 'wiki';  my $info_LastModified = 'LastModified';
54  ##############################  my $info_IsFrozen = 'IsFrozen';
55  # ���ϥڡ���̾  ##############################
56  my $toppage = 'HomePage';  my $kanjicode = 'euc';
57  ##############################  my $lang = 'ja';
58  # �ǽ������ڡ���̾  my %fixedpage = (
59  my $whatsnew = 'RecentChanges';      $IndexPage => 1,
60  ##############################      $ErrorPage => 1,
61  # �ǽ������˷Ǻܤ���ڡ�����      $RssPage => 1,
62  my $maxnew = 50;      RecentChanges => 1,
63  ##############################      AdminChangePassword => 1,
64  # ��������ե�����̾�ʥ��顼�ǡ�      CompletedSuccessfully => 1,
65  my $iconfile = '';      WikiUserAgentList => 1,
66  ##############################  );
67  # ��������ե�����̾�ʥ�Υ����ǡ�  my %form;
68  # my $iconfile = '';  my %database;
69  ##############################  my %infobase;
70  # �ڡ������ѹ������Ȥ���touch����ե������''�ʤ鲿�⤷�ʤ���  my %diffbase;
71  my $touchfile = 'touch.txt';  my %interwiki;
72  ##############################  ##############################
73  # �ץ�ӥ塼�Ѥ��طʿ�  my %page_command = (
74  my $preview_color = '#FFCCCC';      $IndexPage => 'index',
75  ##############################      $RssPage => 'rss',
76  # ���ڡ����Υ�������      AdminChangePassword => 'adminchangepasswordform',
77  my $style = <<'EOD';  );
78  pre, dl, ul, ol, p, blockquote { line-height:120%; }  my %command_do = (
79  a { text-decoration: none; }      read => \&do_read,
80  a:link { color: #0000FF; background-color: #FFFFFF; }      TEXT_CSS => \&do_output_css,
81  a:visited { color: #9900CC; background-color: #FFFFFF; }      edit => \&do_edit,
82  a:hover { text-decoration: underline; }      adminedit => \&do_adminedit,
83  EOD      adminchangepasswordform => \&do_adminchangepasswordform,
84  ##############################      adminchangepassword => \&do_adminchangepassword,
85  # �ƥ�����������ʬ���礭��      write => \&do_write,
86  my $cols = 80;      index => \&do_index,
87  my $rows = 20;      searchform => \&do_searchform,
88  ##############################      comment => \&do_comment,
89  my %form = ();      RandomJump  => \&do_random_jump,
90  my %database = ();      rss => \&do_rss,
91  my %diffbase = ();      diff => \&do_diff,
92  my $diff_text = '';      wikiform    => \&do_wikiform,
93  my @diff_added = ();      map => \&do_map,
94  my @diff_deleted = ();  );
95  my $msgrefA;  my $UA = '';  ## User agent name
96  my $msgrefB;  $| = 1;
97  ##############################  ##############################
98  # �Խ��Բĥڡ���̾����  
99  my @uneditable = ( $whatsnew );  sub main {
100  ##############################      $UA = $main::ENV{HTTP_USER_AGENT};
101  # ����Ѥ�����ɽ��      &open_db;
102  # YukiWiki�Υ�󥯤�2���ढ�롣      &init_form;
103  #      if ($command_do{$form{mycmd}}) {
104  # (1) WikiName (RecentChanges�Ȥ�FrontPage�Τ褦�ʤ��)          &{$command_do{$form{mycmd}}};
105  # (2) BracketName ([[����]]�Ȥ�[[�ȥ�֥륷�塼��]]�Τ褦�ʤ��)      } else {
106  #          &{$command_do{read}};
107  # �����ե�JIS��2�Х����ܤˤ� ']' ���褦��Τǡ�      }
108  # ʸ��']'��1��¿���Ȥ�褦�ˤ��Ƥ��롣      &close_db;
109  #  }
110  my $WikiName = '([A-Z][a-z]+([A-Z][a-z]+)+)';  
111  my $BracketName = '\[\[([^>\x09]+?\]?)\]\]';  sub do_read {
112      my $content = $database{$form{mypage}};
113  # ����������ʬ�Υ���    #print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n";
114  my $IconTag = ''; #<<"EOD";    my $lm = &get_info($form{mypage}, $info_LastModified);
115  #<a href="http://www.hyuki.com/yukiwiki/"><img src="$iconfile"    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
116  # border="0" width="80" height="80" alt="[YukiWiki]" /></a>    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
117  #EOD    #print gmtime."Search...\n";
118      my ($r, $c) = get_search_result ($form{mypage});
119  require "$jcodelib";    my $rl = wiki::referer::list_html ($form{mypage});
120      my @toc;
121  &init_form($kanjicode);    push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;
122      push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;
123  if ($testing) {      my $cf = 'SuikaWiki/0.9';
124      %form = (      ## Should be support at least:
125          # 'mycmd' => 'write',      ## - 'SuikaWiki/0.9' CRLF
126          'mycmd' => 'read',      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
127          #'mycmd' => 'search',      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
128          #'mycmd' => 'edit',      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
129          'mymsg' => <<"EOD",      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
130  �Ϥ���ޤ��ơ�      #print gmtime."Header...\n";
131  ���줫�餤�������񤭹��ߤޤ��͡�        &print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120,
132  LinkPage�⸫�Ƥ���������          -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
133  TestPage�Ϥɤ��Ǥ��礦����          #print "\n". gmtime."Body...\n";
134  �ɤ������������        &print_content ($content, content_format => $cf, last_modified => $lm,
135  http://www.hyuki.com/          -toc => \@toc);
136  [[����]]        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
137  EOD      } else {
138          'mypage' => '<����>',        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
139          'myword' => '��',        print "<pre>@{[&escape($content)]}</pre>";
140          # '3C8C8B8FE98D5F3E' => '',      }
141          # 'TestPage' => '',      if ($c) {
142      );        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
143  }        print $r;
144  &main;      }
145  exit(0);      if ($rl) {
146          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
147  # �ᥤ��      }
148  sub main {          #print "\n". gmtime."Footer...\n";
149      &normalize_form;    &print_footer($form{mypage}, $lm);
150      if ($dbmopen) {          #print "\n". gmtime."Fin...\n";
151          if (!dbmopen(%database, $dbname, 0666)) {  }
152              &print_error("(dbmopen) $dbname �����ޤ���");  
153          }  sub do_output_css {
154      } else {    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
155          if (!tie(%database, "YukiWikiDB", $dbname)) {    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
156              &print_error("(tie error)");    my $content = $database{$form{mypage}};
157          }    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
158      }      my $lm = gmtime &get_info($form{mypage}, $info_LastModified);
159        print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
160      # myspecial�б�      print "Last-Modified: $lm\n";
161      foreach (keys %form) {      print "Expires: @{[scalar gmtime time+3600]}\n";    ## TODO: don't use asctime
162          if (/^myspecial_(.*)/) {      print "\n";
163              $form{mycmd} = $1;      print $content;
164              last;    } else {
165          }      print "Status: 406 Unsupported Media Type\n";
166      }      &print_header('WikiPageIsNotCSS', -noindex => 1);
167        &print_content($database{WikiPageIsNotCSS});
168      if ($form{mycmd} eq 'read') {      &print_footer('WikiPageIsNotCSS');
169          &do_read;    }
170      } elsif ($form{mycmd} eq 'preview') {  }
171          &do_preview;  
172      } elsif ($form{mycmd} eq 'write') {  sub id_and_name ($) {
173          &do_write;      my $name = shift;
174      } elsif ($form{mycmd} eq 'edit') {      if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
175          &do_edit;        qq{id="$name"><a name="$name"></a};
176      } elsif ($form{mycmd} eq 'reedit') {      } else {
177          &do_reedit;          qq{id="$name"};
178      } elsif ($form{mycmd} eq 'search') {      }
179          &do_search;  }
180      } elsif ($form{mycmd} eq 'list') {  
181          &do_list;  sub do_edit {
182      } elsif ($form{mycmd} eq 'diff') {      my ($page) = &unarmor_name(&armor_name($form{mypage}));
183          &do_diff;      if (not &is_editable($page)) {
184      } else {          &print_header($page, -noindex => 1);
185          $form{mypage} = $toppage;          &print_message(&Resource('Error:ThisPageIsUneditable'));
186          &do_read;      } elsif (&is_frozen($page)) {
187      }          &print_header($page, -noindex => 1);
188      if ($dbmopen) {          &print_message(&Resource('Error:ThisPageIsUneditable'));
189          dbmclose(%database);      } else {
190      } else {          &print_header($page, -noindex => 1, -expires => time+60);
191          untie(%database);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
192      }      }
193  }      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
194        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
195  # �ڡ�����ɽ��      my ($r, $c) = get_search_result ($form{mypage});
196  sub do_read {      my $rl = wiki::referer::list_html ($form{mypage});
197      my $page_name = $form{mypage};      if ($c) {
198      my $percent_name = &encode_percent($page_name);        print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
199      &print_header($page_name);        print $r;
200      print qq|<h1>$IconTag<a href="$thisurl?mycmd=search;myword=$percent_name">$page_name</a></h1>\n|;      }
201      &print_toolbar($page_name);      if ($rl) {
202      print &convert_html(&get_page($page_name));        print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
203      &print_footer;      }
204  }      &print_footer($page);
205    }
206  # �ڡ������Խ�  
207  sub do_edit {  sub do_adminedit {
208      if (not &is_editable($form{mypage})) {      my ($page) = &unarmor_name(&armor_name($form{mypage}));
209          # �Խ��Բĥڡ�����ɽ���Τ�      &print_header($page, -noindex => 1);
210          &do_read;      if (not &is_editable($page)) {
211          return;          &print_message(&Resource('Error:ThisPageIsUneditable'));
212      }      } else {
213      &editpage(&get_page($form{mypage}));          &print_message(&Resource('Error:PasswordIsNotSpecified'));
214  }          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
215        }
216  # �ڡ����κ��Խ�      &print_footer($page);
217  sub do_reedit {  }
218      if (not &is_editable($form{mypage})) {  
219          # �Խ��Բĥڡ�����ɽ���Τ�  sub do_adminchangepasswordform {
220          &do_read;      &print_header('AdminChangePassword', -noindex => 1);
221      } else {      &print_passwordform;
222          &editpage($form{mymsg});      &print_footer('AdminChangePassword');
223      }  }
224  }  
225    sub do_adminchangepassword {
226  sub editpage {      if ($form{mynewpassword} ne $form{mynewpassword2}) {
227      my $page_msg = shift;          &print_error(&Resource('Error:PasswordMismatch'));
228      my $page_name = $form{mypage};      }
229      my $digest = &calc_message_digest($page_msg);      my ($validpassword_crypt) = &get_info($AdminSpecialPage, 'AdminPassword');
230      &print_header($page_name);      if ($validpassword_crypt) {
231      print qq|<h1>$IconTag${page_name}���Խ�</h1>\n|;          if (not &valid_password($form{myoldpassword})) {
232      &print_toolbar($page_name);  #            &send_mail_to_admin(<<"EOD", "AdminChangePassword");
233      $page_msg = &escape($page_msg);  #myoldpassword=$form{myoldpassword}
234      print <<"EOD";  #mynewpassword=$form{mynewpassword}
235  <form action="$thisurl" method="post">  #mynewpassword2=$form{mynewpassword2}
236  <!--<input type="hidden" name="mycmd" value="preview">-->  #EOD
237  <input type="hidden" name="mypage" value="$page_name">              &print_error(&Resource('Error:PasswordIsIncorrect'));
238  <input type="hidden" name="mydigest" value="$digest">          }
239  <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$page_msg</textarea><br>      }
240  <input type="submit" name="myspecial_preview" value="��ǧ">      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
241  <input type="submit" name="myspecial_write" value="��ǧ�����ѹ�">      my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
242  </form>      my $salt1 = $token[(time | $$) % scalar(@token)];
243  <hr>      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
244  <h3>�ƥ����������Υ롼��</h3>      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
245        &set_info($AdminSpecialPage, 'AdminPassword', $crypted);
246  <p>�̾�����Ϥ���ʸ�������Τޤ޽��Ϥ���ޤ�����  
247  �ʲ��Υ롼��˽��äƥƥ�����������Ԥ����Ȥ��Ǥ��ޤ���</p>      &print_header('CompletedSuccessfully', -noindex => 1);
248        &print_message(&Resource('Error:PasswordIsChanged'));
249  <ul>      &print_footer('CompletedSuccessfully');
250  <li>  }
251  ���Ԥ�����ζ��ڤ�Ȥʤ�ޤ���  
252    sub do_index {
253  <li>    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
254  HTML�Υ����Ͻ񤱤ޤ���    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
255        &print_header($IndexPage);
256  <li>      print qq(<ul>);
257  ''��Ĵ''�Τ褦�˥��󥰥륯��������ĤǤϤ���ȡ���Ĵ�ˤʤ�ޤ���      foreach my $page (sort keys %database) {
258            if (&is_editable($page)) {
259  <li>              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
260  '''���˶�Ĵ'''�Τ褦�˥��󥰥륯�����Ȼ��ĤǤϤ���ȡ����˶�Ĵ�ˤʤ�ޤ���          }
261        }
262  <li>      print qq(</ul>);
263  ----�Τ褦�˥ޥ��ʥ�4�Ĥ�����ȡ���ʿ���ˤʤ�ޤ���      my ($r, $c) = get_search_result ($form{mypage});
264        if ($c) {
265  <li>        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
266  *���Ƭ�˽񤯤��縫�Ф��ˤʤ�ޤ���        print $r;
267        }
268  <li>      my $rl = wiki::referer::list_html ($form{mypage});
269  **���Ƭ�˽񤯤Ⱦ����Ф��ˤʤ�ޤ���      if ($rl) {
270            print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
271  <li>      }
272  -���Ƭ�˽񤯤Ȳվ�񤭤ˤʤ�ޤ���- -- --- ��3��٥뤬����ޤ���      &print_footer($IndexPage);
273    }
274  <li>  
275  :���Ƭ�˽񤯤��Ѹ�Ȳ���ʸ�����ޤ���  sub do_write {
276        if (&frozen_reject()) {
277  <pre>          return;
278      :�Ѹ�1:���������񤤤�����ʸ1      }
279      :�Ѹ�2:���������񤤤�����ʸ2  
280      :�Ѹ�3:���������񤤤�����ʸ3      if (not &is_editable($form{mypage})) {
281  </pre>          &print_header($form{mypage}, -noindex => 1);
282            &print_message(&Resource('Error:ThisPageIsUneditable'));
283  <li>          &print_footer($form{mypage});
284  http://www.hyuki.com/ �Τ褦��URL�ϼ�ưŪ�˥�󥯤ˤʤ�ޤ���          return;
285        }
286  <li>  
287  YukiWiki�Τ褦����ʸ����ʸ���򺮤�����ʸ�����񤯤ȡ�      if (&conflict($form{mypage}, $form{mymsg})) {
288  YukiWiki�Υڡ���̾�ˤʤ�ޤ���          return;
289        }
290  <li>  
291  [[����]]�Τ褦����Ť��礫�ä�[[ ]]�Ǥ����ä�ʸ�����񤯤ȡ�      # Making diff
292  YukiWiki�Υڡ���̾�ˤʤ�ޤ���      {
293  �礫�ä�����ˤϥ��ڡ�����ޤ�ƤϤ����ޤ���          &open_diff;
294  ���ܸ��Ȥ��ޤ���          my @msg1 = split(/\n/, $database{$form{mypage}});
295            my @msg2 = split(/\n/, $form{mymsg});
296  <li>          $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);
297  ��Ƭ�����ڡ����ǻϤޤäƤ���ȡ�          &close_diff;
298  ��������������Ѥ߰����ޤ���      }
299  �ץ�������񤭹���Ȥ��˻Ȥ��������Ǥ���  
300        if ($form{mymsg}) {
301  <li>          $database{$form{mypage}} = $form{mymsg};
302  &gt; ���Ƭ�˽񤯤ȡ�          #&send_mail_to_admin($form{mypage}, "Modify");
303  ����ʸ���񤱤ޤ���          if ($form{mytouch}) {
304  &gt; �ο���¿���ȥ���ǥ�Ȥ������ʤ�ޤ���3��٥�ޤǡˡ�              &set_info($form{mypage}, $info_LastModified, time);
305                &update_recent_changes;
306  </ul>          }
307  EOD          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
308      &print_footer;          my $fragment = '';
309  }          $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
310            if ($form{__comment_anchor_index}) {
311  # �ڡ����θ���              $fragment .= qq(#anchor-$form{__comment_anchor_index});
312  sub do_search {          } elsif ($form{__wikiform_anchor_index}) {
313      if ($form{myword}) {              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
314          &print_header('�������');          }
315          print qq|<h1>$IconTag$form{myword}�θ������</h1>\n|;          &print_header('CompletedSuccessfully', -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
316          &print_toolbar();          &print_message(&Resource('Error:SavedSuccessfully'));
317          print qq|<ul>\n|;          &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
318          my $count = 0;          &print_footer('CompletedSuccessfully');
319          foreach my $page_name (sort keys %database) {    # sort����Τ�̵�Ť���      } else {
320              if ($database{$page_name} =~ /\Q$form{'myword'}\E/) {          #&send_mail_to_admin($form{mypage}, "Delete");
321                  my $encoded = &encode_percent($page_name);          delete $database{$form{mypage}};
322                  print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|;          delete $infobase{$form{mypage}};
323                  $count++;          if ($form{mytouch}) {
324              }              &update_recent_changes;
325          }          }
326          print qq|</ul>\n|;          &print_header($form{mypage}, -noindex => 1);
327          if ($count > 0) {          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
328              print qq|<p><strong>$form{myword}</strong>��ޤ�ڡ����ϡ���˼���<strong>$count</strong> �ڡ����Ǥ���</p>\n|;          &print_footer($form{mypage});
329          } else {      }
330              print qq|<p><strong>$form{myword}</strong>��ޤ�ڡ����ϸ��Ĥ���ޤ���</p>\n|;  }
331          }  
332      } else {  sub get_search_result ($;%) {
333          &print_header('ñ�측��');    my $word = lc shift;
334          print qq|<h1>$IconTagñ�측��</h1>\n|;    my %option = @_;
335          &print_toolbar();    my @r;
336      }    foreach my $page (keys %database) {
337      print <<"EOD";      next if !$option{-match_myself} && ($page eq $word);
338  <p>      my $content = lc $database{$page};
339  <form action="$thisurl" method="post">      if (index (lc $page, $word) > -1) {
340  <input type="hidden" name="mycmd" value="search">        my $c = $content =~ s/\Q$word\E//g;
341  <input type="text" name="myword" size="20" value="$form{myword}">        push @r, [$page, $c+20];
342  <input type="submit" value="ñ�측��">      } elsif (index ($word, lc $page) > -1) {
343  </form>        my $c = $content =~ s/\Q$word\E//g;
344  </p>        push @r, [$page, $c+10];
345  EOD      } elsif (my $c = $content =~ s/\Q$word\E//g) {
346      &print_footer;        push @r, [$page, $c];
347  }      }
348      }
349  # �ڡ����ΰ���    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
350  sub do_list {    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
351      &print_header('�ڡ�������');    $r = qq|<ul class="search-result">$r</ul>| if $r;
352      print qq|<h1>$IconTag �ڡ�������</h1>\n|;    wantarray? ($r, scalar @r): $r;
353      &print_toolbar();  }
354      print qq|<ul>\n|;  
355      foreach my $page_name (sort keys %database) {    # sort����Τ�̵�Ť���  sub do_random_jump {
356          my $encoded = &encode_percent($page_name);    my @list = keys %database;
357          print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|    my $name = &encode ($list[rand @list]);
358      }    my $scheme = 'http';
359      print qq|</ul>\n|;    $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
360      &print_footer;    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
361  }    print "\n";
362    }
363  # �ץ�ӥ塼  
364  sub do_preview {  sub print_error {
365      my $page_name = $form{mypage};      my ($msg) = @_;
366      my $escapedmsg = &escape($form{mymsg});      &print_header($ErrorPage, -noindex => 1);
367      &print_header($page_name);      print qq(<p><strong class="error">$msg</strong></p>);
368      print qq|<h1>$IconTag${page_name}�Υץ�ӥ塼</h1>\n|;      &print_footer($ErrorPage);
369      &print_toolbar($page_name);      exit(0);
370      # local $percent_name = &encode_percent($page_name);  }
371      print qq|<p>�ʲ��Υץ�ӥ塼���ǧ���ơ��褱��Хڡ��������Υܥ���ǹ������Ƥ���������</p>\n|;  
372      if ($form{mymsg}) {  sub print_header ($;%) {
373          print qq|<table width="100%" bgcolor="$preview_color" ><tr><td>\n|;      my ($page, %option) = @_;
374          # print &convert_html($escapedmsg);      my @head;
375          print &convert_html($form{mymsg});      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
376          print qq|</td></tr></table>\n|;      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
377      } else {      if ($option{-goto}) {
378          print qq|<p>�ʥڡ��������Ƥ϶��Ǥ�����������Ȥ��Υڡ�����<strong>���</strong>����ޤ�����</p>\n|;        if ($UA =~ m#Opera|MSIE 2\.#) {
379      }            ## WARNING: This code may output unsafe HTML document if
380      &print_preview_buttons($page_name, $escapedmsg, $form{mydigest});            ##          $option{-goto} is not clean.
381      &print_footer;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
382  }            print qq{Refresh: 0; url=$option{-goto}\n};
383              push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
384  sub print_preview_buttons {        } else {
385      my ($page_name, $escapedmsg, $digest) = @_;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
386      print <<"EOD";            print qq{Refresh: 0; url="$option{-goto}"\n};
387      <form action="$thisurl" method="post">            push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
388      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$escapedmsg</textarea>        }
389      <br />      }
390      <input type="hidden" name="mypage" value="$page_name">      print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
391      <input type="hidden" name="mydigest" value="$digest">      if ($option{-expires}) {
392      <input type="submit" name="myspecial_preview" value="���٥ץ�ӥ塼">        print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
393      <input type="submit" name="myspecial_write" value="�ڡ����ι���">      }
394      </form>      if ($UA =~ m#Mozilla/2#) {
395  EOD          my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
396  }          print qq{Content-Type: $ct\n};
397            push @head, qq{<meta http-equiv="content-type" content="$ct">};
398  # �񤭹���      } elsif ($UA =~ m#Infomosaic#) {
399  sub do_write {          print qq{Content-Type: text/html\n};
400      if (not &is_editable($form{mypage})) {      } else {
401          # �Խ��Բĥڡ�����ɽ���Τ�          print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
402          &do_read;      }
403          return;      push @head, qq(<title>@{[&escape($page)]}</title>);
404      }      if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) {
405          push @head, qq(<link rel="stylesheet" type="text/css" href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.&get_info($PageName{DefaultStyleForHTML}, $info_LastModified))]}");
406      my $page_name = $form{mypage};      }
407        push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
408      # digest��Ȥäơ������ξ��ͥ����å�      my ($Links, $links) = &make_navigate_links ($page);
409      my $original_digest = &calc_message_digest(&get_page($page_name));      #print $Links;      ## Link: fields
410      if ($form{mydigest} ne $original_digest) {      $links = join "\n", (@head, $links);
411          &print_header($page_name);      print <<"EOD";
412          print qq|<h1>$IconTag${page_name}�ǡڹ����ξ��ۤ͡������ޤ���</h1>\n|;  Content-Language: $lang
413          print <<"EOD";  Content-Style-Type: text/css
414  <p>���ʤ������Υڡ������Խ����Ƥ���֤ˡ�  
415  ¾�οͤ�Ʊ���ڡ����򹹿����Ƥ��ޤä��褦�Ǥ���  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
416  </p><p>  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
417  �ʲ��ˡ����ʤ����Խ������ƥ����Ȥ�����ޤ��Τǡ�  <html lang="$lang" class="$option{body_class}">
418  ���ʤ����Խ����Ƥ������ʤ��褦�ˡ�  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
419  ���ޤ��������Ģ�ʤɤ˥��ԡ����ڡ����Ȥ��Ƥ���������  $links
420  </p><p>  </head>
421  ���ԡ����ڡ����Ȥ��Ѥ�Ǥ��顢  <body class="$option{body_class}">
422  �ǿ������Ƥ򸫤ƺ����Խ���ľ���Ƥ���������  EOD
423  �ǿ������Ƥ�      &print_navigate_links ($page);
424  <a target="_blank" href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>      print <<EOD;
425  �Ǹ��뤳�Ȥ��Ǥ��ޤ���  <h1 class="header">@{[&escape($page)]}</h1>
426  </p>  EOD
427  EOD  }
428          # &print_toolbar($page_name);  
429          &print_preview_buttons($page_name, &escape($form{mymsg}), $form{mydigest});  sub get_charset_name ($;%) {
430          &print_footer;      my ($charset, %option) = (lc shift, @_);
431          return;      if ($charset =~ 'euc') {
432      }          $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
433        } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
434      # diff����          $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
435      {      } elsif ($charset =~ 'jis') {
436          &opendiff;          $charset = 'iso-2022-jp';
437          my @msg1 = split(/\n/, &get_page($page_name));      }
438          my @msg2 = split(/\n/, $form{mymsg});      $charset;
439          $msgrefA = \@msg1;  }
440          $msgrefB = \@msg2;  
441          &diff_check;  sub print_navigate_links (@) {
442          $diffbase{$form{mypage}} = $diff_text;    my ($page) = @_;
443          $diff_text = '';    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
444          &closediff;    my $cookedpage = &encode($page);
445      }    print <<EOH;
446    <div class="tools">
447      &print_header($page_name);      @{[ $editable
448      &set_page($page_name, $form{mymsg});          ? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | )
449      if ($form{mymsg}) {          : qq()
450          print qq|<h1>$IconTag${page_name}�򹹿����ޤ���</h1>\n|;      ]}
451          &print_toolbar($page_name);      <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd" title="@{[&Resource('ViewThisPageLong',escape=>1)]}">@{[&Resource('ViewThisPage',escape=>1)]}</a> |
452          print &convert_html(&get_page($page_name));      <a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
453      } else {      <a href="$url_cgi?$CreatePage" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
454          print qq|<h1>$IconTag${page_name}�������ޤ���</h1>\n|;      <a href="$url_cgi?$IndexPage" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
455          &print_toolbar($page_name);      <a href="$url_cgi?$FrontPage" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
456          print qq|<p>${page_name}�������ޤ�����</p>\n|;      <a href="$url_cgi?$SearchPage" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
457      }      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink" title="@{[&Resource('GoSomewhereLong',escape=>1)]}">@{[&Resource('GoSomewhere',escape=>1)]}</a> |
458      &print_footer;      <a href="$url_cgi?RecentChanges" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
459      # �������줿�Τǥ��å����Ƥ�����  </div>
460      if ($touchfile) {  EOH
461          open(FILE, "> $touchfile");  }
462          print FILE "\n";  
463          close(FILE);  sub make_navigate_links ($) {
464      }      my $page = shift;
465  }      my @link;
466        push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page);
467  # �ڡ������ѹ���      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);
468  sub do_diff {      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')};
469      if (not &is_editable($form{mypage})) {      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
470          # �Խ��Բĥڡ�����ɽ���Τ�      push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
471          &do_read;      push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>&Resource('GoToHomePageLink')};
472          return;      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
473      }      push @link, {rel=>'News', href=>"$url_cgi?RecentChanges", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
474      &opendiff;      push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
475      &print_header($form{mypage} . '���ѹ���');      push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
476      print qq|<h1>$IconTag <a href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>���ѹ���</h1>\n|;      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
477      &print_toolbar();      push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
478      $_ = &escape($diffbase{$form{mypage}});      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToLink')};
479      print <<"EOD";      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToEditLink')};
480  <ul>      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
481  <li>�ɲä��줿�Ԥ�<ins>�Ŀ�</ins>�Ǥ���      push @link, {rel=>'history', href=>$uri{cvs_wikipage}.do{my $s=$page;$s=~s/(.)/sprintf '%02X', ord $1/ges;$s}.'.txt', title=>&Resource('ViewHistoryOfThisPageLink'),hreflang=>'en'} if $uri{cvs_wikipage};
482  <li>������줿�Ԥ�<del>�ֿ�</del>�Ǥ���      push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'};
483  <li><a href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>�عԤ���      push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
484  </ul>      my ($Links, $links) = ('', '');
485  <hr />      for my $e (@link) {
486  EOD          $links .= qq(<link);
487      print qq|<pre>\n|;          $Links .= qq(Link: <$e->{href}>);
488      foreach (split(/\n/, $_)) {          for my $attr (qw/rel rev href title class type hreflang charset/) {
489          if (/^\+(.*)/) {              $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
490              print qq|<ins>$1</ins>\n|;          }
491          } elsif (/^\-(.*)/) {          for my $attr (qw/rel rev title/) {
492              print qq|<del>$1</del>\n|;              $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
493          } elsif (/^\=(.*)/) {          }
494              print qq|$1\n|;          $links .= qq(>\n);
495          } else {          $Links .= qq(\n);
496              print qq|??? $_\n|;      }
497          }      wantarray ? ($Links, $links) : $Links;
498      }  }
499      print qq|</pre>\n|;  
500      &print_footer;  sub print_footer {
501      &closediff;      my ($page, $lm) = @_;
502  }      my $epage = &encode ($page);
503      my $cvslog1 = q$Revision$;
504  sub opendiff {    my $cvslog2 = q$Date$;
505      if ($dbmopen) {    print_navigate_links ($page);
506          if (!dbmopen(%diffbase, $diffdbname, 0666)) {    print <<"EOD";
507              &print_error("(dbmopen) $diffdbname �����ޤ���");  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
508          }  <div class="footer">
509      } else {  <a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 &copy; 2000-2002 by Hiroshi Yuki">@{[&Resource('About:Name:YukiWiki',escape=>1)]}</a> <a href="http://digit.que.ne.jp/work/" title="WalWiki 2.0.beta1.wal.1 &copy; 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a>
510          if (!tie(%diffbase, "YukiWikiDB", $diffdbname)) {  <a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
511              &print_error("(tie error)");  </div>
512          }  </body>
513      }  </html>
514  }  EOD
515    }
516  sub closediff {  
517      if ($dbmopen) {  sub escape {
518          dbmclose(%diffbase);      my $s = shift;
519      } else {      $s =~ s|\r\n|\n|g;
520          untie(%diffbase);      $s =~ s|&|&amp;|g;
521      }      $s =~ s|<|&lt;|g;
522  }      $s =~ s|>|&gt;|g;
523        $s =~ s|"|&quot;|g;
524  # �ե����फ��ξ����Ϣ������ %form �������      return $s;
525  # &init_form('euc');  }
526  sub init_form {  
527      my ($charcode) = @_;  sub unescape {
528      my $query;      my $s = shift;
529      if ($ENV{REQUEST_METHOD} =~ /^post$/i) {      # $s =~ s|\n|\r\n|g;
530          read(STDIN, $query, $ENV{CONTENT_LENGTH});      $s =~ s|&lt;|<|g;
531      } else {      $s =~ s|&gt;|>|g;
532          $query = $ENV{QUERY_STRING};      $s =~ s|&quot;|"|g;
533      }      $s =~ s|&amp;|&|g;
534      my @assocarray = split(/[&;]/, $query);      return $s;
535      foreach my $assoc (@assocarray) {  }
536          my ($property, $value) = split(/=/, $assoc);  
537          $value =~ tr/+/ /;  sub print_content ($;$) {
538          $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;      my ($rawcontent, %option) = @_;
539          &jcode::convert(\$value, $charcode);      print &text_to_html($rawcontent, toc=>1, %option);
540          $form{$property} = $value;  }
541      }  
542  }  sub text_to_html {
543        my ($txt, %option) = @_;
544  # ���顼�ڡ�������Ϥ���      my @toc;
545  sub print_error {      my @toc2 = @{$option{-toc}||[]};
546      my ($msg) = @_;      my $tocnum = 0;
547      &print_header('Error');      
548      print "<h1>$IconTag$msg</h1></body></html>";      ## Load constants
549      exit(0);      my %const;
550  }      if ($option{content_format} =~ /import="([^"]+)"/) {
551          for (split /\s*,\s*/, $1) {
552  sub escape {          my $wp = $database{$_};
553      my ($line) = shift;          if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
554      $line =~ s|<|&lt;|g;            wiki::suikawikiconst::to_hash ($wp => \%const);
555      $line =~ s|>|&gt;|g;          }
556      $line =~ s|"|&quot;|g;        }
557      # $line =~ s|\&|&amp;|g;      }
558      return $line;      
559  }      $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
560        my (@txt) = split(/\n/, $txt);
561  sub inline {      my (@saved, @result);
562      my ($line) = shift;      unshift(@saved, "</p>");
563      $line = &escape($line);      push(@result, "<p>");
564      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      foreach (@txt) {
565      $line =~ s|''([^']+?)''|<em>$1</em>|g;                    chomp;
566      $line =~ s!          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
567         (              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
568           (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
569         #| (?:$WikiName)                         # LocalLinkLikeThis              $tocnum++;
570         | (?:$BracketName)                      # [[���ܸ���]]          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
571         )              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
572              !              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
573                  &make_link($1)              $tocnum++;
574              !gex;          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
575      return $line;              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
576  }              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
577                $tocnum++;
578  # �ڡ����Υ����ȥ뤫��ڡ��������Ƥ�����          } elsif (/^\*\*([^\x0D\x0A]*)/) {
579  sub get_page {          # if (/^\*\*(.*)/) {
580      my $page_name = shift;          # Walrus mod (6) end
581      return $database{$page_name};              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
582  }              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
583                $tocnum++;
584  # �ڡ��������Ƥ�Ϳ����          } elsif (/^\*([^\x0D\x0A]*)/) {
585  # &set_page($title, $txt)              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
586  sub set_page {              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
587      # �ڡ����򹹿�����              $tocnum++;
588      my $title = $_[0];          } elsif (/^(={1,6})(.*)/) {
589      $database{$title} = $_[1];              &back_push('ol', length($1), \@saved, \@result);
590      # ���ڡ����ʤ�������              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
591      unless ($database{$title}) {          } elsif (/^(-{1,6})(.*)/) {
592          delete $database{$title};            &back_push('ul', length($1), \@saved, \@result);
593      }            my ($pf, $l) = ('', $2);
594      # RecentChanges�򹹿�����            if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
595      my $delim = ' - ';              my $num = 0+$1;
596      my @pages = split(/\n/, $database{$whatsnew});              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
597      my $datestr = &get_current_datestr;            }
598      unshift(@pages, qq|-$datestr$delim$title|);            push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
599      # Ʊ��ڡ����ι����Ϻǿ��Τ�ΤΤߤˤ���          } elsif (/^:([^:]+):(.*)/) {
600      # ¸�ߤ��ʤ��ڡ����ϥ����åפ��롣              &back_push('dl', 1, \@saved, \@result);
601      my %count;              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
602      my @newpages;          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
603      foreach my $line (@pages) {              &back_push('blockquote', length($1), \@saved, \@result);
604          my ($prefix, $title) = split(/$delim/, $line);              push @result, "<p>";
605          $count{$title}++;              push(@result, &inline($2, const => \%const));
606          if ($count{$title} == 1 and exists($database{$title})) {              unshift @saved, "</p>";
607              push(@newpages, qq|$prefix - $title|);          } elsif (/^\s*$/) {
608          }              push(@result, splice(@saved));
609      }              push(@result, "<p>");
610      # �����������˹���              unshift(@saved, "</p>");
611      $database{$whatsnew} = join("\n", splice(@newpages, 0, $maxnew));          } elsif (/^(\s+.*)$/) {
612  }              &back_push('pre', 1, \@saved, \@result);
613                push(@result, &inline($1, const => \%const));
614  # �ڡ����Υإå������          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
615  sub print_header {              &back_push('table', 1, \@saved, \@result);
616      my $title = shift;              #######
617      print <<"EOD";              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
618  Content-type: text/html              # XXXXX
619                my $tmp = "$1,";
620  <html><head>              my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
621  <title>$title</title>              my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
622  <style type="text/css">              my @colspan = map {($_ eq '==') ? 0 : 1} @value;
623  $style              for (my $i = 0; $i < @value; $i++) {
624  </style>                  if ($colspan[$i]) {
625  </head>                      while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
626  <body>                          $colspan[$i]++;
627  EOD                      }
628  }                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
629                        $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], const => \%const));
630  # �ġ���С������                  } else {
631  sub print_toolbar {                      $value[$i] = '';
632      my $page_name = shift;                  }
633      my $percent_name = &encode_percent($page_name);              }
634      my $editlink = '';              push(@result, join('', '<tr>', @value, '</tr>'));
635      if ($page_name ne '' and &is_editable($page_name)) {              # XXXXX
636          $editlink = <<"EOD";              #######
637  <a href="$thisurl?mycmd=edit;mypage=$percent_name">�Խ�</a> |          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
638  <a href="$thisurl?mycmd=diff;mypage=$percent_name">��ʬ</a> |              push @result, splice (@saved), '<'.lc($1).'>';
639  EOD              unshift @saved, "</p>";
640      }              push @result, "<p>";
641      print <<"EOD";          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
642  <p>              push @result, splice (@saved), '</'.lc($1).'>';
643   [          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
644  <a href="$thisurl?mycmd=read;mypage=$toppage">�ȥå�</a> |            my $num = 0+$1;
645  <a href="$thisurl?mycmd=list">����</a> |            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
646  $editlink            push @result, &inline ($2, const => \%const);
647  <a href="$thisurl?mycmd=search">ñ�측��</a> |          } else {
648  <a href="$thisurl?mycmd=read;mypage=$whatsnew">�ǽ�����</a>              push(@result, &inline($_, const => \%const));
649   ]          }
650  </p>      }
651  EOD      push(@result, splice(@saved));
652  }      
653        my $toc = '';
654  # �ڡ����Υեå������      if ($option{toc}) {
655  sub print_footer {          # Convert @toc (table of contents) to HTML.
656      print <<"EOD";          # This part is taken from Makio Tsukamoto's WalWiki.
657  <address>          my (@tocsaved, @tocresult);
658  <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>          foreach (@toc,@toc2) {
659  + <a href="$modifierlink">$modifier</a> ${version}.              if (/^(-{1,6})(.*)$/) {
660  [<a href="/" title="���Υ����С��μ���">/</a>                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
661  <a href="/map" title="���Υ����С��ΰ���">�Ͽ�</a>                  push(@tocresult, '<li>' . $2 . '</li>');
662  <a href="/search/" title="���Υ����С��θ���">����</a>]              }
663  </address>          }
664  </body></html>          push(@tocresult, splice(@tocsaved));
665  EOD          $toc = join("\n", @tocresult);
666  }          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
667        }
668  # URL��ڡ�����̾�������󥯤���      $toc .= join("\n", @result);
669  sub make_link {      $toc =~ s#<p>\n</p>##g;
670      my $name = shift;      $toc =~ s#[\x0D\x0A]+</#</#g;
671      $name =~ s/^&lt;(.*)&gt;$/$1/;      $toc =~ s#<pre>\n#<pre>#g;
672      $name =~ s/^\[\[(.*)\]\]$/$1/;      $toc;
673      if ($name =~ /^(http|https|ftp).*?(\.png|\.jpeg|\.jpg)?$/) {  }
674          if ($2) {  
675              return qq|<a href="$name"><img border="0" src="$name" /></a>|;  sub back_push {
676          } else {      my ($tag, $level, $savedref, $resultref, $attr) = @_;
677              return qq|&lt;<a href="$name">$name</a>&gt;|;      while (@$savedref > $level) {
678          }          push(@$resultref, shift(@$savedref));
679      } elsif ($name =~ /^mailto:(.*)/) {      }
680          my $address = $1;      if ($savedref->[0] ne "</$tag>") {
681          return qq|&lt;<a href="$name">$address</a>&gt;|;          push(@$resultref, splice(@$savedref));
682      } elsif ($name =~ /^urn:[0-9A-Za-z_:-]+/) {      }
683          return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;      while (@$savedref < $level) {
684      } else {          unshift(@$savedref, "</$tag>");
685        my $name2 = $name; $name2 =~ tr/\x20/-/;          push(@$resultref, "<$tag$attr>");
686        if ($database{$name2}) {      }
687          my $percent_name = &encode_percent($name2);  }
688          return qq|<a href="$thisurl?mycmd=read;mypage=$percent_name" class="wiki">$name</a>|;  
689        } elsif ($database{'[['.$name2.']]'}) {  sub inline ($;%) {
690          my $percent_name = &encode_percent('[['.$name2.']]');      my ($line, %option) = @_;
691          return qq|<a href="$thisurl?mycmd=read;mypage=$percent_name" class="wiki">$name</a>|;      $line = &escape($line);
692        } else {      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
693          my $percent_name = &encode_percent($name2);      $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g;
694          return qq|<a href="$thisurl?mycmd=edit;mypage=$percent_name" class="wiki newpage">$name?</a>|;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
695        }      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
696      }      $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g;
697  }      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
698        $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g;
699  # %xx �η����˥��󥳡��ɤ���      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%��<q@{[$2?qq( cite="$2"):'']}>$1</q>��%g;
700  # ����ϡ�      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
701  # http://www.hyuki.com/yukiwiki/yukiwiki.cgi?mycmd=read&mypage=%3C%8C%8B%8F%E9%8D_%3E      $line =~ s|''([^']+)''|<em>$1</em>|g;
702  # �Ȥ��������Τ���˻Ȥ��롣      $line =~ s{
703  # '<����>' �� '%3C%8C%8B%8F%E9%8D_%3E'        (\[\[(\#\S+?)\]\])
704  sub encode_percent {        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
705      my $name = shift;        |&gt;&gt;([0-9]+)
706      my $encoded = '';        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
707      foreach my $ch (split(//, $name)) {      }{
708          if ($ch =~ /[A-Za-z0-9_]/) {        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
709              $encoded .= $ch;        if ($l) {
710          } else {          return &embedded_to_html($1);
711              $encoded .= '%' . sprintf("%02X", ord($ch));        } elsif (defined $page) {
712          }          &make_wikilink ($page, anchor => 0+$anchor);
713      }        } elsif ($anum) {
714      return $encoded;          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
715  }        } elsif ($uri) {
716            &make_urilink ($uri);
717  # �ƥ��������Τ�HTML���Ѵ�����        }
718  sub convert_html {      }gex;
719      my ($txt) = shift;      return $line;
720      my (@txt) = split(/\n/, $txt);  }
721      foreach (@txt) {  
722          chomp;  sub make_wikilink ($%) {
723          if (/^\*\*(.*)/) {    my ($ename, %option) = @_;
724              push(@result, splice(@saved), '<h3>' . &inline($1) . '</h3>');    my $name = &unescape ($ename);
725          } elsif (/^\*(.*)/) {    if ($database{$name}) {
726              push(@result, splice(@saved), '<h2>' . &inline($1) . '</h2>');      my $subject = &escape (&get_subjectline ($name, delimiter => ''));
727          } elsif (/^----/) {      if ($option{anchor}) {
728              push(@result, splice(@saved), '<hr>');        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
729          } elsif (/^(-{1,3})(.*)/) {      } else {
730              &back_push('ul', length($1));        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
731              push(@result, '<li>' . &inline($2) . '</li>');      }
732          } elsif (/^:([^:]+):(.*)/) {    } else {
733              &back_push('dl', 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>);
734              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');    }
735          } elsif (/^(>{1,3})(.*)/) {  }
736              &back_push('blockquote', length($1));  
737              push(@result, &inline($2));  sub make_urilink ($;%) {
738          } elsif (/^\s*$/) {    require URI;
739              push(@result, splice(@saved));    my $uri = shift;
740              unshift(@saved, "</p>");    if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
741              push(@result, "<p>");      $uri = &unescape ($uri);
742          } elsif (/^(\s+.*)$/) {      if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
743              &back_push('pre', 1);        my ($site, $name) = ($1, $2);
744              push(@result, &escape($1)); # Not &inline, but &escape        for ($site, $name) {
745          } else {          if (s/^"//) { s/"$//; s/\\(.)/$1/g }
746              push(@result, &inline($_));        }
747          }        &init_InterWikiName () unless $interwiki{'[[]]'};
748      }        if ($interwiki{$site}) {
749      push(@result, splice(@saved));          &load_formatter ('interwiki');
750      return join("\n", @result);          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
751  }          $site = &escape ($site); $name = &escape ($name);
752            qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>&gt;);
753  # &back_push($tag, $count)        } else {
754  # $tag�Υ�����$level��٥�ޤǵͤ�롣          qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
755  sub back_push {        }
756      my ($tag, $level) = @_;      } else {
757      while (@saved > $level) {        qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
758          push(@result, shift(@saved));      }
759      }    } elsif ($uri =~ /^urn:/) {   ## URN
760      if ($saved[0] ne "</$tag>") {      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
761          push(@result, splice(@saved));      qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
762      }    } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
763      while (@saved < $level) {      my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
764          unshift(@saved, "</$tag>");      qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
765          push(@result, "<$tag>");    } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
766      }      my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
767  }      qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
768      } else {      ## misc. URI
769  # �Խ���ǽ�ڡ�������      CGI::Carp::warningsToBrowser (0);
770  sub is_editable {      my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
771      my ($pagename) = @_;      CGI::Carp::warningsToBrowser (1);
772      foreach (@uneditable) {      qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
773          if ($pagename eq $_) {    }
774              return 0;  }
775          }  
776      }  {my $FormIndex = 0;
777      if (&is_valid_name($pagename)) {  sub make_custom_form ($$$$) {
778          return 1;      my ($wfname, $definition, $template, $option) = @_;
779      }      ## $template and $option is currently not used in this procedure.
780      return 0;      unless ($main::_EMBEDED) {
781  }          $FormIndex++;
782            if (length $definition) {
783  # Valid��̾������              my $param = bless {}, 'SuikaWiki::Plugin';
784  sub is_valid_name {              my $lastmodified = &get_info($form{mypage}, $info_LastModified);
785      my ($pagename) = @_;              &load_formatter (qw/form_input form_option/);
786      if ($pagename =~ /^$WikiName$/) {              $definition = &unescape ($definition);
787          return 1;              $definition =~ s/\\(.)/$1/g;
788      } elsif ($pagename =~ /^$BracketName$/) {              $option = &unescape ($option);
789          return 1;              $option =~ s/\\(.)/$1/g;
790      } else {              $fmt{form_option}->replace ($option, $param);
791          return 0;              $param->{output}->{form} = 1 unless defined $param->{output}->{form};
792      }              $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
793  }              my $target_page = $param->{output}->{page} || $form{mypage};
794                $param->{form_disabled} = 1 if $fixedpage{$target_page};
795  # ���߻����ʸ���������              my $target_form = $param->{output}->{id};
796  sub get_current_datestr {              my $r = '';
797      my (@wdays) = ( "��", "��", "��", "��", "��", "��", "��" );              $r = <<EOH if $param->{output}->{form};
798      my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time);  <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
799      return sprintf("%4d-%02d-%02d (%s) %02d:%02d:%02d",    <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
800          $year + 1900, $mon + 1, $mday, $wdays[$wday], $hour, $min, $sec);    <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
801  }    <input type="hidden" name="myLastModified" value="$lastmodified">
802      <input type="hidden" name="mytouch" value="on">
803  # URL?SomePage�䡢    <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
804  # URL?[[����]]�η������ä���硢(not yet)  EOH
805  # ����Ū��mycmd��read�ˤ���$form�����Ƥ����ꤹ�롣              $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
806  sub normalize_form {              $r .= $fmt{form_input}->replace ($definition, $param);
807      foreach my $key (keys %form) {              $r .= "</form>\n" if $param->{output}->{form};
808          if ($key =~ /^$WikiName$/) {              $r;
809              $form{mycmd} = 'read';         } else {  ## No input-interface WikiForm
810              $form{mypage} = $1;             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
811              last;         }
812          } elsif ($key =~ /^$BracketName$/) {      } else {
813              $form{mycmd} = 'read';          qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
814              $form{mypage} = $1;      }
815              last;  }}
816          }  
817      }  sub print_message {
818  }      my ($msg) = @_;
819        print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
820  # �Ѵ��ƥ��Ȥ�Ԥʤ��Ȥ��Υ���ץ�  }
821  sub print_sample {  
822      my $txt = &convert_html(<<"EOD");  sub init_form {
823  *�縫�Ф�1      ## TODO: Support multipart/form-data
824  **�����Ф�1-1      my $query = '';
825  -����1      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
826  -����2        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
827  -����3      }
828  ����1����1����1����1����1����1����1����1����1����1����1����1      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
829  ����1����1����1����1����1����''��Ĵ''1����1����1����1����1����1      if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
830  ����1����1����1����1����1����1����1����1����1����1����1����1        my $query = &decode($main::ENV{QUERY_STRING});
831          $query = &code_convert(\$query, $kanjicode);
832  ����2����2����2����2����2����2����2����2����2����2����2����2        if ($page_command{$query}) {
833  ����2����2����2����2����2����2����2����2����2����2����2����2          $form{mycmd} = $page_command{$query};
834  ����2����2����2����2����2����2����2����2����2����2����2����2          $form{mypage} = $query;
835  **�����Ф�1-2        } else {
836  :�Ѹ�1:���������񤤤�����ʸ1��''��Ĵñ��''          $form{mypage} = $query;
837  ����1����1����1����1����1����1����1����1����1����1����1����1          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
838  ����1����1����1����1����1����1����1����1����1����1����1����1        }
839  ����1����1����1����1����1����1����1����1����1����1����1����1      } else {
840  :�Ѹ�2:���������񤤤�����ʸ2        for (split /[;&]/, $query) {
841  :�Ѹ�3:���������񤤤�����ʸ3          if (my ($n, $v) = split /=/, $_, 2) {
842  ----            for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
843  *�縫�Ф�2            $form{$n} = $v;
844  **�����Ф�2-1          }
845  &lt;http://suika.fam.cx/&gt;        }
846  **�����Ф�2-2        if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
847            $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
848  [[����]]          $form{mycmd} = $page_command{$form{mypage}};
849          }
850  ����1����1����1����1����1����1����1����1����1����1����1����1      }
851  ����1����1����1����'''��Ĵ'''1����1����1����1����1����1����1����1      $form{mypage} ||= 'HomePage';
852  ����1����1����1����'''''������Ĵ'''''1����1����1����1����1����1����1����1����1      $form{mycmd} ||= 'read';
853  >����2����2����2����2����2����2����2����2����2����2����2����2  
854  >����2����2����2����2����2����2����2����2����2����2����2����2      # mypreview_edit        -> do_edit, with preview.
855  >����2����2����2����2����2����2����2����2����2����2����2����2      # mypreview_adminedit   -> do_adminedit, with preview.
856        # mypreview_write       -> do_write, without preview.
857  ��٥�0��٥�0��٥�0��٥�0��٥�0��٥�0      foreach (keys %form) {
858            if (/^mypreview_(.*)$/) {
859  >��٥�1              $form{mycmd} = $1;
860  >��٥�1              $form{mypreview} = 1;
861  >��٥�1          }
862  >>��٥�2      }
863  >>��٥�2  
864  >>��٥�2      #
865  >>>��٥�3      # $form{mycmd} is frozen here.
866  -�Ϥ�1      #
867  --�Ϥ�2  
868  ��������2      for (grep /^wikiform__/, keys %form) {
869  ---�Ϥ�3          $form{$_} = &code_convert (\$form{$_}, $kanjicode);
870  --�Ϥ�2      }
871  ---�Ϥ�3      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
872  --�Ϥ�2      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
873  ---�Ϥ�3  }
874  >>>��٥�3  
875  >>>��٥�3  sub update_recent_changes {
876  >>>��٥�3      my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}";
877  EOD      my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges});
878      print $txt;      shift @oldupdates; ## '#?' magic line
879      exit;      my @updates;
880  }      foreach (@oldupdates) {
881            /^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/;
882  sub diff_check {          my $name = $1;
883      traverse_sequences(          if ($name ne $form{mypage}) {
884              $msgrefA, $msgrefB,              push @updates, $_;
885              {          }
886                  MATCH => \&df_match,      }
887                  DISCARD_A => \&df_delete,      if (&is_exist_page($form{mypage})) {
888                  DISCARD_B => \&df_add,        unshift @updates, $update;
889              }      }
890      );      splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1;
891      &diff_flush;      $database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
892  }      if ($file_touch) {
893            open(FILE, "> $file_touch");
894  sub diff_flush {          print FILE localtime() . "\n";
895      $diff_text .= join('', map { "-$_\n" } splice(@diff_deleted));          close(FILE);
896      $diff_text .= join('', map { "+$_\n" } splice(@diff_added));      }
897  }  }
898    
899  sub df_match {  {my %SubjectLine;
900      my ($a, $b) = @_;  sub get_subjectline {
901      &diff_flush;      my ($page, %option) = @_;
902      $diff_text .= "=$msgrefA->[$a]\n";      unless (defined $SubjectLine{$page}) {
903  }        if (not &is_editable($page)) {
904            $SubjectLine{$page} = "";
905  sub df_delete {        } else {
906      my ($a, $b) = @_;          $SubjectLine{$page} = $database{$page};
907      push(@diff_deleted, $msgrefA->[$a]);          $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
908  }          $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
909          }
910  sub df_add {      }
911      my ($a, $b) = @_;      if (length $SubjectLine{$page}) {
912      push(@diff_added, $msgrefB->[$b]);        $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
913  }        $option{delimiter}.$SubjectLine{$page}.$option{tail};
914        } else {
915  sub calc_message_digest {   # You have to use MD5...        '';
916      my $text = shift;      }
917      my @text = split(//, $text);  }}
918      my $len = length($text);  
919      my $checksum = 0;  sub open_db {
920      foreach (@text) {      if ($modifier_dbtype eq 'dbmopen') {
921          $checksum += ord($_);          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");
922          $checksum = ($checksum * 2) % 65536 + (($checksum & 32768) ? 1 : 0); # 16bit rotate          dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");
923      }      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
924      return "$len:$checksum";          eval q{use AnyDBM_File};
925  }          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");
926            tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");
927  # Definition of YukiWikiDB      } else {
928  package YukiWikiDB;          eval q{use Yuki::YukiWikiDB};
929            tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");
930  my $debug = 1;          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");
931        }
932  # Constructor  }
933  sub new {  
934      return shift->TIEHASH(@_);  sub close_db {
935  }      if ($modifier_dbtype eq 'dbmopen') {
936            dbmclose(%database);
937  # tying          dbmclose(%infobase);
938  sub TIEHASH {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
939      my ($class, $dbname) = @_;          untie(%database);
940      my $self = {          untie(%infobase);
941          dir => $dbname,      } else {
942          keys => [],          untie(%database);
943      };          untie(%infobase);
944      if (not -d $self->{dir}) {      }
945          if (!mkdir($self->{dir}, 0777)) {  }
946              print "mkdir(" . $self->{dir} . ") fail\n" if ($debug);  
947              return undef;  sub open_diff {
948          }      if ($modifier_dbtype eq 'dbmopen') {
949      }          dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");
950      return bless($self, $class);      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
951  }          tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");
952        } else {
953  # Store          tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");
954  sub STORE {      }
955      my ($self, $key, $val) = @_;  }
956      my $file = &make_filename($self, $key);  
957      if (open(FILE,"> $file")) {  sub close_diff {
958          binmode(FILE);      if ($modifier_dbtype eq 'dbmopen') {
959          print FILE $val;          dbmclose(%diffbase);
960          close(FILE);      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
961          return $self->{$key} = $val;          untie(%diffbase);
962      } else {      } else {
963          print "$file create error.";          untie(%diffbase);
964      }      }
965  }  }
966    
967  # Fetch  sub print_editform {
968  sub FETCH {      my ($mymsg, $lastmodified, %mode) = @_;
969      my ($self, $key) = @_;      my $frozen = &is_frozen($form{mypage});
970      my $file = &make_filename($self, $key);  
971      if (open(FILE, $file)) {      if ($form{mypreview}) {
972          local $/;          if ($form{mymsg}) {
973          $self->{$key} = <FILE>;              unless ($mode{conflict}) {
974          close(FILE);                  print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);
975      }                  print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);
976      return $self->{$key};                  print qq(<div class="preview">\n);
977  }                  &print_content($form{mymsg});
978                    print qq(</div>\n);
979  # Exists              }
980  sub EXISTS {          } else {
981      my ($self, $key) = @_;              print @{[&Resource('Preview:Empty',escape=>1)]};
982      my $file = &make_filename($self, $key);          }
983      return -e($file);          $mymsg = &escape($form{mymsg});
984  }      } else {
985            $mymsg = &escape($mymsg || $database{NewPageTemplate});
986  # Delete      }
987  sub DELETE {      my $magic = '';
988      my ($self, $key) = @_;      $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
989      my $file = &make_filename($self, $key);  
990      unlink $file;      my $edit = $mode{admin} ? 'adminedit' : 'edit';
991      return delete $self->{$key};      my $escapedmypage = &escape($form{mypage});
992  }      my $escapedmypassword = &escape($form{mypassword});
993        my $selected = 'read';
994  sub FIRSTKEY {      if ($form{after_edit_cmd}) {
995      my ($self) = @_;          $selected = $form{after_edit_cmd};
996      opendir(DIR, $self->{dir}) or die $self->{dir};      } elsif ($magic =~ /Const|Config|CSS/) {
997      @{$self->{keys}} = grep /\.txt$/, readdir(DIR);          $selected = 'edit';
998      foreach my $name (@{$self->{keys}}) {      }
999          $name =~ s/\.txt$//;      my $afteredit = <<EOH;
1000          $name =~ s/[0-9A-F][0-9A-F]/pack("C", hex($&))/eg;  <select name="after_edit_cmd">
1001      }  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
1002      return shift @{$self->{keys}};  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
1003  }  </select>
1004    EOH
1005  sub NEXTKEY {  
1006      my ($self) = @_;      print <<"EOD";
1007      return shift @{$self->{keys}};  <form action="$url_cgi" method="post">
1008  }  <h2>@{[&Resource('Edit:Title',escape=>1)]}</h2>
1009        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]}
1010  sub make_filename {      @{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="$escapedmypassword" size="10"></label>) : "" ]} [@{[do {my $n = 0;
1011      my ($self, $key) = @_;                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1012      my $enkey = '';                 ++$n}]}]<br>
1013      foreach my $ch (split(//, $key)) {      <input type="hidden" name="myLastModified" value="$lastmodified">
1014          $enkey .= sprintf("%02X", ord($ch));      <input type="hidden" name="mypage" value="$escapedmypage">
1015      }      <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">$mymsg</textarea><br>
1016      return $self->{dir} . "/$enkey.txt";  @{[
1017  }      $mode{admin} ?
1018  __END__      qq(
1019        <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
1020  =head1 NAME      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)
1021        : ""
1022  YukiWiki - ��ͳ�˥ڡ������ɲá�������Խ��Ǥ���Web�ڡ�������CGI  ]}
1023    @{[
1024      Copyright (C) 2000,2001 by Hiroshi Yuki.      $mode{conflict} ? "" :
1025      ���� <hyuki@hyuki.com>      qq(
1026      http://www.hyuki.com/          <input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}<br>
1027      http://www.hyuki.com/yukiwiki/          <input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}">
1028            <input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd>
1029  =head1 SYNOPSIS         $afteredit
1030           <br>
1031      http://www.hyuki.com/yukiwiki/yukiwiki.cgi      )
1032    ]}
1033  =head1 DESCRIPTION  </form>
1034    EOD
1035  YukiWiki�ʷ�륦�������ˤϻ��üԤ���ͳ�˥ڡ������ɲá�������Խ��Ǥ���      unless ($mode{conflict}) {
1036  �Ի׵Ĥ�Web�ڡ���������CGI�Ǥ���          ## Show help text
1037  Web��ư���Ǽ��ĤȤ���äȻ��Ƥ��ޤ�����          my $help = $database{WikiEditHelp};
1038  Web�Ǽ��Ĥ�ñ�˥�å��������ɲä�������ʤΤ��Ф��ơ�          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1039  YukiWiki�ϡ�Web�ڡ������Τ�ͳ���ѹ����뤳�Ȥ��Ǥ��ޤ���          print &text_to_html ($help, toc => 0);
1040        }
1041  YukiWiki�ϡ�Cunningham & Cunningham��WikiWikiWeb��  }
1042  ���ͤ򻲹ͤˤ����ȼ��˺���ޤ�����  
1043    sub print_passwordform {
1044  YukiWiki��Perl�ǽ񤫤줿CGI������ץȤȤ��Ƽ¸�����Ƥ��ޤ��Τǡ�          print <<"EOD";
1045  Perl��ư���Web�����Фʤ�����Ū�ưפ����֤Ǥ��ޤ���  <form action="$url_cgi" method="post">
1046        <input type="hidden" name="mycmd" value="adminchangepassword">
1047  ���Ȥ�dbmopen���Ȥ���Ķ��ʤ�����֤Ǥ��ޤ�(Version 1.5.0�ʹߤʤ�dbmopen���Ȥ��ʤ��Ƥ����֤Ǥ��ޤ�)��      <label>@{[&Resource('Password:Old=',escape=>1)]}<input type="password" name="myoldpassword" size="10"></label><br>
1048        <label>@{[&Resource('Password:New1=',escape=>1)]}<input type="password" name="mynewpassword" size="10"></label><br>
1049        <label>@{[&Resource('Password:New2=',escape=>1)]}<input type="password" name="mynewpassword2" size="10"></label><br>
1050  YukiWiki�ϥե꡼���եȤǤ���      <input type="submit" value="@{[&Resource('WikiForm:Change',escape=>1)]}"><br>
1051  ����ͳ�ˤ��Ȥ�����������  </form>
1052    EOD
1053  =head1 ������ˡ  }
1054    
1055  =head2 ����  sub is_editable {
1056        my ($page) = @_;
1057  YukiWiki�κǿ��Ǥϡ�      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
1058  http://www.hyuki.com/yukiwiki/          return 0;
1059  ��������Ǥ��ޤ���      } else {
1060            return 1;
1061  =head2 �ե��������      }
1062    }
1063      readme.txt      �ɥ������  
1064      yukiwiki.cgi    YukiWiki����  # armor_name:
1065      yukiwiki.gif    �����ʥ��顼�ǡ�  #   WikiName -> WikiName
1066      yukimono.gif    �����ʥ�Υ����ǡ�  #   not_wiki_name -> [[not_wiki_name]]
1067      jcode.pl        ���������ɥ饤�֥��  sub armor_name { qq([[$_[0]]]) }
1068    
1069  =head2 ���󥹥ȡ���  # unarmor_name:
1070    #   [[bracket_name]] -> bracket_name
1071  =over 4  #   WikiName -> WikiName
1072    sub unarmor_name {
1073  =item 1.      my ($name) = @_;
1074        if ($name =~ /^\[\[(\S+?)\]\]$/) {
1075  ���������֤�򤯡�          return $1;
1076        } else {
1077  =item 2.          return $name;
1078        }
1079  yukiwiki.cgi�ΤϤ�������ˤ���������ǧ���ޤ���  }
1080  �̾�ϲ��⤷�ʤ��Ƥ褤����  
1081  �Ϥ����$touchfile��''�ˤ��������褤�Ǥ��礦��  sub decode {
1082        my ($s) = @_;
1083  =item 3.      $s =~ tr/+/ /;
1084        $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
1085  yukiwiki.cgi��jcode.pl��Ʊ���Ȥ��������֤��ޤ���      return $s;
1086    }
1087  =item 4.  
1088    sub encode {
1089  ������0��yukiwiki.db�Ȥ����ե���������֤��ޤ���      my ($s) = @_;
1090  ��Perl�����ƥ�ˤ�äƤ�yukiwiki.pag, yukiwiki.dir��      my $encoded = '';
1091        foreach my $ch (split(//, $s)) {
1092  =item 5.          if ($ch =~ /[A-Za-z0-9_]/) {
1093                $encoded .= $ch;
1094  yukiwiki.cgi�˥֥饦�����饢���������ޤ���          } else {
1095                $encoded .= '%' . sprintf("%02X", ord($ch));
1096  =back          }
1097        }
1098  =head2 �ѡ��ߥå����      return $encoded;
1099    }
1100          �ե�����        �ѡ��ߥå����      ž���⡼��  
1101          yukiwiki.cgi    755                 ASCII  sub conflict {
1102          yukiwiki.gif    644                 BINARY      my ($page, $rawmsg) = @_;
1103          yukimono.gif    644                 BINARY      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1104          jcode.pl        644                 ASCII          return 0;
1105        }
1106      $dbmopen = 1; �ˤ������:      &print_header($page, -noindex => 1);
1107          yukiwiki.db     666                 BINARY      &print_content(&Resource('Error:Conflict'));
1108          (yukiwiki.pag, yukiwiki.dir�ξ��⤢���      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1109        &print_footer($page);
1110      $dbmopen = 0; �ˤ������: (�����ȥǥ��쥯�ȥ��777�ˤ��Ƥ���)      return 1;
1111          .               777                 (ž�����ʤ�)  }
1112    
1113  =head1 �ǡ����ΥХå����å���ˡ  sub get_now {
1114        my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
1115  $dbmopen = 1;�ξ��ϡ�      $year += 1900;
1116  �ǡ����Ϥ��٤�yukiwiki.db(.dir, .pag)�����롣      $mon++;
1117  �����Хå����åפ���Ф褤��      $mon = "0$mon" if $mon < 10;
1118        $day = "0$day" if $day < 10;
1119  $dbmopen = 0;�ξ��ϡ�      $hour = "0$hour" if $hour < 10;
1120  yukiwiki�Ȥ����ǥ��쥯�ȥ꤬�Ǥ���Τǡ�      $min = "0$min" if $min < 10;
1121  ����ʲ���Хå����åפ���Ф褤��      #$sec = "0$sec" if $sec < 10;
1122        return "$year-$mon-$day $hour:$min";
1123  =head1 �������ڡ����κ����  }
1124    
1125  =over 4  sub init_InterWikiName {
1126      my @content = split /\n/, $database{InterWikiName};
1127  =item 1.    for (@content) {
1128        if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1129  �ޤ���Ŭ���ʥڡ������㤨��FrontPage�ˤ����ӡ�        $interwiki{$1} = $2;
1130  �ڡ����β��ˤ�����Խ��ץ�󥯤򤿤ɤ�ޤ���      }
1131      }
1132  =item 2.    $interwiki{'[[]]'} = 1;       ## dummy
1133    }
1134  ����ȥƥ��������Ϥ��Ǥ�����֤ˤʤ�Τǡ�  
1135  ������NewPage�Τ褦��ñ��  
1136  ����ʸ����ʸ�����ߤ��Ƥ����ʸ�����  sub get_info {
1137  ��񤤤ơ���¸�פ��ޤ���      my ($page, $key) = @_;
1138        my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1139  =item 3.      return $info{$key};
1140    }
1141  ��¸����ȡ�FrontPage�Υڡ������񤭴���ꡢ  
1142  ���ʤ����񤤤�NewPage�Ȥ���ʸ����θ���� ? �Ȥ�����󥯤�ɽ������ޤ���  sub set_info {
1143  ���� ? �Ϥ��Υڡ������ޤ�¸�ߤ��ʤ����Ȥ򼨤����Ǥ���      my ($page, $key, $value) = @_;
1144        my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1145  =item 4.      $info{$key} = $value;
1146        my $s = '';
1147  ���� ? �򥯥�å�����ȿ������ڡ���NewPage���Ǥ��ޤ��Τǡ�      for (keys %info) {
1148  ���ʤ��ι�����ʸ�Ϥ򤽤ο������ڡ����˽񤤤���¸���ޤ���          $s .= "$_=$info{$_}\n";
1149        }
1150  =item 5.      $infobase{$page} = $s;
1151    }
1152  NewPage�ڡ������Ǥ����FrontPage�� ? �Ͼä��ơ���󥯤Ȥʤ�ޤ���  
1153    sub frozen_reject {
1154  =back      my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);
1155        my ($willbefrozen) = $form{myfrozen};
1156  =head1 �ƥ����������Υ롼��      if (not $isfrozen and not $willbefrozen) {
1157            # You need no check.
1158  =over 4          return 0;
1159        } elsif (valid_password($form{mypassword})) {
1160  =item *          # You are admin.
1161            return 0;
1162  Ϣ³����ʣ���Ԥϥե��뤵���ɽ������ޤ���      } else {
1163            &print_error(&Resource('Error:PasswordIsIncorrect'));
1164  =item *          return 1;
1165        }
1166  ���Ԥ�����C<< <p> >>�ζ��ڤ�Ȥʤ�ޤ���  }
1167    
1168  =item *  sub valid_password {
1169        my ($givenpassword) = @_;
1170  HTML�Υ����Ͻ񤱤ޤ���      my ($validpassword_crypt) = &get_info($AdminSpecialPage, 'AdminPassword');
1171        if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1172  =item *          return 1;
1173        } else {
1174  B<''�ܡ����''>�Τ褦�˥��󥰥륯��������ĤǤϤ���ȡ�          return 0;
1175  �ܡ����C<< <b> >>�ˤʤ�ޤ���      }
1176    }
1177  =item *  
1178    sub is_frozen {
1179  B<'''������å�'''>�Τ褦�˥��󥰥륯�����Ȼ��ĤǤϤ���ȡ�      my ($page) = @_;
1180  ������å�C<< <i> >>�ˤʤ�ޤ���      if (&get_info($page, $info_IsFrozen)) {
1181            return 1;
1182  =item *      } else {
1183            return 0;
1184  B<---->�Τ褦�˥ޥ��ʥ�4�Ĥ�����ȡ�      }
1185  ��ʿ��C<< <hr> >>�ˤʤ�ޤ���  }
1186    
1187  =item *  sub do_comment {
1188        my ($content) = $database{$form{mypage}};
1189  �Ԥ�B<*>�ǤϤ����ȡ�      my $default_name;   ## this code does not strict.
1190  �縫�Ф�C<< <h2> >>�ˤʤ�ޤ���      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1191        my $datestr = '[WEAK['.&get_now.']]';
1192  =item *      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
1193        ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1194  �Ԥ�B<**>�ǤϤ����ȡ�      if ($namestr =~ /^(?:>>)?[0-9]/) {
1195  �����Ф�C<< <h3> >>�ˤʤ�ޤ���        $namestr = qq( ''$namestr'': );
1196        } elsif (length $namestr) {
1197  =item *        $namestr = qq( ''[[$namestr]]'': );
1198        }
1199  �Ԥ�ޥ��ʥ�-�ǤϤ����ȡ�      my $anchor = &get_new_anchor_index ($content);
1200  �վ��C<< <ul> >>�ˤʤ�ޤ���      my $i = 1;  my $o = 0;
1201  �ޥ��ʥ��ο���������ȥ�٥뤬������ޤ���3��٥�ޤǡ�      $content =~ s{(\[\[\#r?comment\]\])}{
1202          my $embed = $1;
1203      -����1        if ($i == $form{comment_index}) {
1204      --����1-1          if ($embed ne '[[#rcomment]]') {
1205      --����1-2            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1206      -����2          } else {
1207      -����3            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1208      --����3-1          }
1209      ---����3-1-1        }
1210      ---����3-1-2        $i++; $embed;
1211      --����3-2      }ge;
1212        unless ($o) {
1213  =item *        $content = "#?SuikaWiki/0.9\n\n" unless $content;
1214          $content .= "\n" unless $content =~ /\n$/s;
1215  �������Ȥ��ȡ�        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1216  �Ѹ�Ȳ���ʸ�Υꥹ��C<< <dl> >>���񤱤ޤ���      }
1217        $form{__comment_anchor_index} = $anchor;
1218      :�Ѹ�1:���������񤤤�����ʸ1      if ($form{mymsg} || $form{myname}) {
1219      :�Ѹ�2:���������񤤤�����ʸ2          $form{mymsg} = $content;
1220      :�Ѹ�3:���������񤤤�����ʸ3          $form{mytouch} = 'on';
1221            &do_write;
1222  =item *      } else {
1223            $form{mycmd} = 'read';
1224  ���          &do_read;
1225        }
1226  =over 4  }
1227    
1228  =item *  sub get_new_anchor_index ($) {
1229        my $content = shift;
1230  LinkToSomePage��FrontPage�Τ褦�ˡ�      my $anchor = 0;
1231  ��ñ��κǽ�ΰ�ʸ������ʸ���ˤ�����Τ�      $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1232  ��İʾ�Ϣ³������Τ�YukiWiki�Υڡ���̾�Ȥʤꡢ      $anchor + 1;
1233  ���줬ʸ����˴ޤޤ��ȥ�󥯤ˤʤ�ޤ���  }
1234    
1235  =item *  my $CommentIndex = 0;
1236    sub embedded_to_html {
1237  http://www.hyuki.com/ �Τ褦��URL�ϼ�ưŪ�˥�󥯤ˤʤ�ޤ���      my ($embedded) = @_;
1238        if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
1239  =item *        unless ($main::_EMBEDED) {
1240            my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1241  ��Ť��礫�ä�[[ ]]�Ǥ����ä�ʸ����⡢          return <<"EOD";
1242  YukiWiki�Υڡ���̾�ˤʤ�ޤ���  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1243  �礫�ä�����ˤϥ��ڡ�����ޤ�ƤϤ����ޤ���      <input type="hidden" name="mycmd" value="comment">
1244  ���ܸ��Ȥ��ޤ���      <input type="hidden" name="mypage" value="$form{mypage}">
1245        <input type="hidden" name="myLastModified" value="$lastmodified">
1246  =back      <input type="hidden" name="mytouch" value="on">
1247        <input type="hidden" name="comment_index" value="$CommentIndex">
1248  =item *      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1249        <input type="text" name="myname" value="" size="10" class="comment-name">
1250  ��Ƭ�����ڡ����䥿�֤ǻϤޤäƤ���ȡ�      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1251  ����������Ѥߤ�����C<< <pre> >>�Ȥ��ư����ޤ���      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
1252  �ץ�������ɽ���ʤɤ˻Ȥ��������Ǥ���  </p></form>
1253    EOD
1254         } else {
1255  =item *          return <<"EOD";
1256    <del><form action="$url_cgi" method="get">
1257  �Ԥ� > �ǤϤ����ȡ�      <input type="hidden" name="mycmd" value="read">
1258  ����ʸC<< <blockquote> >>���񤱤ޤ���      <input type="hidden" name="mypage" value="$form{mypage}">
1259  >�ο���¿���ȥ���ǥ�Ȥ������ʤ�ޤ���3��٥�ޤǡˡ�      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1260        <input type="text" name="myname" value="" size="10" disabled="disabled">
1261      >ʸ��      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1262      >ʸ��  </form></del>
1263      >>����ʤ����  EOD
1264      >ʸ��      }
1265      } elsif ($embedded =~ /$embed_command{searched}/) {
1266  =back      return get_search_result ($1, -match_myself => 1);
1267      } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1268  =head1 ��������      my ($name, $r) = ($1, '');
1269        if ($main::_EMBEDED != 1) {
1270  =over 4        my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1271          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1272  =item *        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1273            $main::_EMBEDED = 1;
1274  2001ǯ10��20����Version 1.6.6��          $r = &text_to_html ($content, content_format => $cf);
1275            $main::_EMBEDED = 0;
1276  �����ξ����к���        } elsif (length $content) {
1277  ���ڡ����δ�ñ�ʥ����å�������äƤ�����          $r = "<pre>@{[&escape ($content)]}</pre>";
1278  �������˥����å��������Ӥ��롣        } else {
1279  �����Ľ��digest�Ȥ���ʸ����򸡺������ʬ���롣          $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1280  �����MD5�ʤɤǤ����Ȥ�ä����������Τ�����ɡ�        }
1281        } else {    ## nested #EMBED
1282  ���ͻ���ɽ��������å������ʤɤϡֶ˰��פ���Υڡ����򻲹ͤˤ�����        $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1283        }
1284  =item *      return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">��<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>��</div></blockquote>);
1285      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1286  2001ǯ10��17����Version 1.6.5��      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1287      } else {
1288  �ץ�ӥ塼���̤ǡ������ܥ���򲡤����Ȥ������������      return $embedded;
1289  ��å����������Ƥ�input���Ǥ�type="hidden"��Ȥä�������Τ���롣    }
1290  ����ˡ�textarea���Ǥ�Ȥ���  }
1291  �ƥץ�ӥ塼�Ѥ�myspecial_��Ƴ�����Ǥ⤭�줤���к��ǤϤʤ���  
1292    sub load_formatter (@) {
1293  =item *      for my $t (@_) {
1294            unless ($fmt{$t}) {
1295  2001ǯ8��30����Version 1.6.4��              require Message::Util::Formatter;
1296                $fmt{$t} = Message::Util::Formatter->new;
1297  URL�ǥ����쥯�Ȥ˥ڡ���̾����ꤷ�Ƥ⡢              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1298  $WikiName��$BracketName�ʳ��Υڡ�������ʤ��褦�ˤ�����                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1299  (is_valid_name��is_editable����)��              }
1300            }
1301  =item *      }
1302    }
1303  2001ǯ8��30����Version 1.6.3��  
1304    sub do_wikiform {
1305  RecentChanges���Խ������Խ��ԲĤȤ�����      my $content = $database{$form{mypage}};
1306  �Խ��Բĥڡ�����@uneditable�˥ڡ���̾������롣      my $anchor = &get_new_anchor_index ($content);
1307        &load_formatter (qw/form_template form_option/);
1308  =item *      my $write = 0;
1309        my $i = 1;
1310  2001ǯ2��25����Version 1.6.1, 1.6.2��      $content =~ s{$embed_command{form}}{
1311            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1312  ��ʬ��ǽ�ΥХ�������          if (($wfname && $wfname eq $form{wikiform_targetform})
1313  do_preview��'>'�������ʤ��Х�����              || $i == $form{wikiform_index}) {
1314  �ʥ桼������λ�Ŧ�ˡ�              $template =~ s/\\(.)/$1/g;
1315                $option =~ s/\\(.)/$1/g;
1316  =item *              my $param = bless {}, 'SuikaWiki::Plugin';
1317                $param->{page} = $form{mypage};
1318  2001ǯ2��22����Version 1.6.0��              $param->{form_index} = $i;
1319  ��ʬ��ǽ�����������              $param->{form_name} = $wfname;
1320                $param->{anchor_index} = $anchor;
1321  =item *              $param->{argv} = \%form;
1322                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1323  2001ǯ2��19����Version 1.5.4��              $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1324  �����ե�����ؤΥ�󥯤ϲ����ˤ��Ƥߤ���              $fmt{form_option}->replace ($option, $param);
1325                my $t = 1;
1326  =item *              for (@{$param->{require}||[]}) {
1327                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1328  2001ǯ2��19����Version 1.5.3��              }
1329  RecentChanges����˺�������ڡ���������Τ��᤿��              $t = $fmt{form_template}->replace ($template, $param) if $t;
1330  use strict;�ǰ��ä�������ʬ�򾯤�����(�����ǤϤʤ�)��              if (length $t) {
1331                    if ($param->{output}->{reverse}) {
1332  =item *                      $embed .= "\n" . $t;
1333                    } else {
1334  2001ǯ2��16����Version 1.5.2��                      $embed = $t . "\n" . $embed;
1335  textarea��ɽ������ӥץ�ӥ塼�������� < �� > �� &lt; �� &gt; ���Ѵ�����                  }
1336  (do_preview, editpage, print_preview_buttons)��                  $write = 1;
1337                    $form{__comment_anchor_index} = $anchor
1338  =item *                    if $param->{anchor_index_};  ## $anchor is used!
1339                }
1340  2000ǯ12��27����Version 1.5.1��              $form{__wikiform_anchor_index} = $i;
1341  �ץ�ӥ塼���̤�����������              undef $form{wikiform_targetform};  ## make sure never to match
1342                undef $form{wikiform_index};       ## with WikiForm in rest of page
1343  =item *          }
1344            $i++; $embed;
1345  2000ǯ12��22����Version 1.5.0��      }ge;
1346  ����Ū�ˤ����֤��ľ������      unless ($write) {
1347  ���������Ӻ�������褦�ˤ���(do_list)��        #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1348  �񤭹������˳�ǧ���̤�Ф��褦�ˤ���(do_preview)��        #$content .= "\n" unless $content =~ /\n$/s;
1349  �ƥ����Ȥν������Խ����̤����줿(do_edit, do_reedit)��        #
1350  WhatsNew��RecentChanges��TopPage��FrontPage���ѹ�������      }
1351        if ($write) {
1352  =item *          $form{mymsg} = $content;
1353            $form{mytouch} = 'on';
1354  2000ǯ12��20����Version 1.1.0��          &do_write;
1355  tie�����Ѥ��ơ�dbmopen���Ȥ��ʤ����Ǥ�ư���褦�˽�����      } else {
1356  ���ѼԤ�1�ͤǤ���ֶ˰��פ��󤫤�          $form{mycmd} = 'read';
1357  ���äƤ��������������ɤ򸵤ˤ��Ƥ��ޤ���          &do_read;
1358        }
1359  =item *  }
1360    
1361  2000ǯ9��5����Version 1.0.2��  sub code_convert {
1362   <body color=...> �� <body bgcolor=...>    require Jcode;
1363  ���ѼԤ���λ�Ŧ�ˤ�롣���ա�      my ($contentref, $code) = (shift, shift || $kanjicode);
1364        $code = 'jis' if $code =~ /iso/;
1365  =item *      $code = 'euc' if $code =~ /euc/;
1366        $code = 'sjis' if $code =~ /shift/;
1367  2000ǯ8��6����Version 1.0.1�������      $code = 'utf8' if $code =~ /utf/;
1368  C MAGAZINE�ʥ��եȥХ󥯥ѥ֥�å��󥰡�      #&Jcode::convert($contentref, $code);       # for Jcode.pm
1369  2000ǯ10���Ϣ�ܵ������������ǡ�  #    &jcode::convert($contentref, $code);       # for jcode.pl
1370  [[ ]] �κǸ夬��˾�פΤ褦�˥��ե�JIS��      #&Jcode::tr ($contentref, "\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ )) if $code eq 'euc';
1371  0x5D�ˤʤ���β����Ԥʤä���      Jcode->new ($contentref)->h2z->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code;
1372        return $$contentref;
1373  =item *  }
1374    
1375  2000ǯ8��5����Version 1.0.0�������  sub do_diff {
1376        if (not &is_editable($form{mypage})) {
1377  =item *          &do_read;
1378            return;
1379  2000ǯ7��23����Version 0.82�������      }
1380  �Խ����Υ�󥯥ߥ���      &open_diff;
1381  <textarea>��°���ѹ���      my $title = $form{mypage};
1382        &print_header($title, -noindex => 1);
1383  =item *      $_ = &escape($diffbase{$form{mypage}});
1384        &close_diff;
1385  2000ǯ7��22����Version 0.81�������      print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>);
1386  �������Ȥ߹��ࡣ      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1387        print qq(<pre class="diff">);
1388  =item *      foreach (split(/\n/, $_)) {
1389            if (/^\+(.*)/) {
1390  2000ǯ7��21����Version 0.80�������              print qq(<ins class="added">$1</ins>\n);
1391  POD��CGI��˽񤭹��ࡣ          } elsif (/^\-(.*)/) {
1392                print qq(<del class="deleted">$1</del>\n);
1393  =item *          } elsif (/^\=(.*)/) {
1394                print qq(<span class="same">$1</span>\n);
1395  2000ǯ7��19����Version 0.70�������          } else {
1396  '''������å�'''�䡢--��---��>>��>>>�ʤɤ������              print qq|??? $_\n|;
1397            }
1398  =item *      }
1399        print qq(</pre>);
1400  2000ǯ7��18����Version 0.60�������      &print_footer($title);
1401  *����*��''����''���ѹ�  }
1402    
1403  =item *  sub do_rss {
1404        eval q{use Yuki::RSS};
1405  2000ǯ7��17����Version 0.50�������      my $rss = new Yuki::RSS(
1406            version => '1.0',
1407  =item *          encoding => &get_charset_name ($kanjicode),
1408        );
1409  2000ǯ7��17��������ˤ��������ɲä��롣      my $scheme = 'http';
1410        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1411  =item *      my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1412        $rss->stylesheet (
1413  2000ǯ7��16�������������ɲá�        href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1414          type      => 'text/css',
1415  =item *      );
1416        $rss->channel(
1417  2000ǯ7��15����������          title   => &Resource ('RSS:WikiTitle'),
1418            link    => $myuri,
1419  =back          description     => &Resource ('RSS:WikiDescription'),
1420            'dc:language'   => $lang,
1421  =head1 TODO      );
1422        my $recentchanges = $database{RecentChanges};
1423      - �ƥ�����ɽ���⡼��      my $count = 0;
1424      - Charset��������      foreach (split(/\n/, $recentchanges)) {
1425      - textarea����Ĥ������б�          last if ($count >= 15);
1426      - ��˥塼�αѸ�ɽ���յ�          if (/\[\[([^]]+)\]\]/) {
1427      - �ץ�ӥ塼�Υܥ���ǡ�mymsg��input��value������Ƥ��뤬�����Ԥ򤽤Τޤ�value�ˤ���ƤϤ����ʤ��ΤǤϤʤ�����            my $title = $1;
1428      - �ֺ��Խ��פε�ǽ�ϥ֥饦���� back �ǽ�ʬ�ǤϤʤ������ץ�ӥ塼�Ϥ�äȥ���ץ�ˡ�            $rss->add_item (
1429      - �ڡ��������ȥ��Wikiname�ˤ������ˤ�����褦�ˤ��롣              title       => &escape($title),
1430      - InterWiki���ε�ǽ��URL�򱣤��Ĥġ���󥯤�ĥ���              link        => $myuri . '?' . &encode($title),
1431                description => &escape(&get_subjectline($title,delimiter=>'')),
1432  =head1 ���              'dc:date'   => &get_info ($title, $info_LastModified),
1433              );
1434      Copyright (C) 2000 by Hiroshi Yuki.            $count++;
1435      ���� <hyuki@hyuki.com>          }
1436      http://www.hyuki.com/      }
1437      http://www.hyuki.com/yukiwiki/      # print RSS information (as XML).
1438        print <<"EOD"
1439  ���䡢�ո����Х����� hyuki@hyuki.com �˥᡼�뤷�Ƥ���������  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1440    
1441  =head1 ���۾��  @{[$rss->as_string]}
1442    EOD
1443  YukiWiki�ϡ�  }
1444  GNU General Public License�ˤƸ������ޤ���  
1445    sub _rfc3339_date ($) {
1446  YukiWiki�ϥե꡼���եȤǤ���    my @time = gmtime (shift);
1447  ����ͳ�ˤ��Ȥ�����������    sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1448  ��ʬ���ߤ�YukiWiki������褦�˥���ץ�ˤ��Ƥ���ޤ���  }
1449    
1450  =head1 �ռ�  sub is_exist_page {
1451        my ($name) = @_;
1452  �ܲȤ�WikiWiki���ä�Cunningham & Cunningham, Inc.��      if ($use_exists) {
1453  ���դ��ޤ���          return exists($database{$name});
1454        } else {
1455  YukiWiki��ڤ���ǻȤäƤ�������          return $database{$name};
1456  �ͥåȾ�������˴��դ��ޤ���      }
1457    }
1458  YukiWiki�Υ�����ǥ����󤷤Ƥ������ä��������व��  
1459  http://city.hokkai.or.jp/~reina/  sub __get_database ($) { $database{ $_[0] } }
1460  �˴��դ��ޤ���  sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1461    
1462  tie��Ȥä��Ǥθ��ˤʤ륳���ɤ����äƤ������ä�  sub do_map {
1463  �ֶ˰��פ���˴��դ��ޤ���      my $page = $form{mypage};
1464        &print_header ($page);
1465  =head1 ���ȥ��      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
1466        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
1467  =over 4      my ($r, $c) = get_search_result ($form{mypage});
1468        my $rl = wiki::referer::list_html ($form{mypage});
1469  =item *      print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n";
1470        my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {},
1471  YukiWiki�ۡ���ڡ���        map_from_here => &Resource('Map:FromHere'),
1472  http://www.hyuki.com/yukiwiki/        map_from_here_description => &Resource('Map:FromHereLong'));
1473        &wiki::map::make_list ($page, %option);
1474  =item *      print &wiki::map::list_to_html ($page, $option{weight_list}, %option);
1475        if ($c) {
1476  �ܲȤ�WikiWiki        print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
1477  http://c2.com/cgi/wiki?WikiWikiWeb        print $r;
1478        }
1479  =item *      if ($rl) {
1480          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
1481  �ܲȤ�WikiWiki�κ��(Cunningham & Cunningham, Inc.)      }
1482  http://c2.com/      &print_footer ($page);
1483    }
1484  =item *  
1485    my %_Resource;
1486  YukiWiki�Υ����ǥ�����򤷤Ƥ������ä��������व��Υڡ���  sub Resource ($;%) {
1487  http://city.hokkai.or.jp/~reina/    my ($s, %o) = @_;
1488      unless (defined $_Resource{$s}) {
1489  =back      $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1490      }
1491  =cut    $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1492    }
1493    
1494    package wiki::referer;
1495    sub add ($$) {
1496      my $page = shift;
1497      my $uri = shift;
1498      unless (ref $uri) {
1499        require URI;
1500        $uri = URI->new ($uri);
1501        ## Some schemes do not have query part.
1502        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1503        $uri->fragment (undef);
1504      }
1505      $uri = $uri->canonical;
1506      return unless $uri;
1507      for my $regex (&get_dont_record) {
1508        return if $uri =~ /$regex/;
1509      }
1510      my %list = get ($page);
1511      $list{ $uri }++;
1512      set ($page, \%list);
1513    }
1514    sub get ($) {
1515      my $page = shift;
1516      split /"/, main::get_info ($page, 'Referer');
1517    }
1518    sub set ($%) {
1519      my $page = shift;
1520      my $list = shift;
1521      main::set_info ($page, Referer => join '"', %$list);
1522    }
1523    
1524    sub get_dont_record () {
1525      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1526      grep !/^#/,
1527      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1528    }
1529    sub get_site_name () {
1530      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1531      my @item;
1532      for (@lines) {
1533        next if /^#/;
1534        my ($uri, $name) = split /\s+/, $_, 2;
1535        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1536        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1537        push @item, [$uri, qq(q($name))];
1538      }
1539      @item;
1540    }
1541    
1542    sub list_html ($) {
1543      my $page = shift;
1544      my %list = get ($page);
1545      my $r = '';
1546      my @name = get_site_name;
1547      for my $uri (sort keys %list) {
1548        my $title;
1549        for my $item (@name) {
1550          if ($uri =~ /$item->[0]/) {
1551            $title = $uri;
1552            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1553              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1554            last;
1555          }
1556        }
1557        my $euri = main::escape ($uri);
1558        if ($title) {
1559          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1560        } else {
1561          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1562        }
1563      }
1564      $r ? qq(<ul>$r</ul>\n) : '';
1565    }
1566    
1567    sub __decode ($) {
1568      my $s = shift;
1569      $s =~ tr/+/ /;
1570      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1571      main::code_convert (\$s);
1572    }
1573    
1574    package wiki::useragent;
1575    
1576    sub add ($) {
1577      my $s = shift;
1578      return unless length $s;
1579      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge;
1580      my %ua;
1581      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1582        if (/^-\[(\d+)\] (.+)$/) {
1583          my ($t, $n) = ($1, $2);
1584          $n =~ tr/\x0A\x0D//d;
1585          $ua{$n} = $t;
1586        }
1587      }
1588      $ua{$s}++;
1589      my $s = qq(#?SuikaWiki/0.9\n);
1590      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1591        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1592      }
1593      &main::__set_database ('WikiUserAgentList' => $s);
1594    }
1595    
1596    package wiki::suikawikiconst;
1597    
1598    sub to_hash ($;$) {
1599      my $page = shift;
1600      my $h = shift || {};
1601      my $val;
1602      for my $line (split /\n/, $page) {
1603        $line =~ tr/\x0A\x0D//d;
1604        if ($val && $line =~ s/^\s+//) {
1605          $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1606        } elsif ($line =~ /^(.+):/) {
1607          $val = $1; $h->{$val} = '';
1608        }
1609      }
1610      $h;
1611    }
1612    
1613    package SuikaWiki::Plugin;
1614      our $plugin_directory;  # defined in top of this file.
1615      our %List;
1616    
1617    sub escape ($$) { main::escape ($_[1]) }
1618    sub unescape ($$) { main::unescape ($_[1]) }
1619    sub encode ($$) { main::encode ($_[1]) }
1620    sub decode ($$) { main::decode ($_[1]) }
1621    sub __get_datetime ($) { main::get_now () }
1622    sub resource ($$;%) { shift; &main::Resource (@_) }
1623    sub uri ($$) { $main::uri{$_[1]} }
1624    
1625    sub regist ($@) {
1626        my $pack = shift;
1627        for (@_) {
1628            push @{$List{$_}}, $pack;
1629        }
1630    }
1631    
1632    sub import_plugins () {
1633        opendir PDIR, $plugin_directory;
1634        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1635        closedir PDIR;
1636        for (@plugin) {
1637            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1638            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1639        }
1640    }
1641    
1642    &import_plugins ();
1643    
1644    package wiki::conneg;
1645    
1646    ## BUG: this parser isn't strict.
1647    sub get_accept_lang (;$) {
1648      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1649      my %alang = (ja => 0.0002, en => 0.0001);
1650      my $i = 0.1;
1651      for (split /\s*,\s*/, $alang) {
1652        tr/\x09\x0A\x0D\x20//d;
1653        if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1654          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1655          $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1656          $alang{$l} += $i unless $alang{$l} == 0;
1657          $i -= 0.001;
1658        }
1659      }
1660      \%alang;
1661    }
1662    
1663    package wiki::resource;
1664    
1665    sub get ($;\%) {
1666      my ($resname, $option) = @_;
1667      $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1668      $option->{resource} ||= {};
1669      my $v;
1670      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1671        while (length $lang) {
1672          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1673            $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1674            $v = $option->{resource}->{$lang}->{$resname};
1675            last if defined $v;
1676          }
1677          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1678        }
1679        last if defined $v;
1680      }
1681      defined $v ? $v : $resname;
1682    }
1683    
1684    package wiki::map;
1685    
1686    sub make_list ($;%) {
1687      my ($page, %option) = @_;
1688      $option{level} ||= 3;
1689      my %weight;
1690      my $content = &main::__get_database ($page);
1691      $content =~ s{^\#\?([^\x0A\x0D]+)}{
1692        if ($1 =~ /import="([^"]+)"/) {
1693          for (split /\s*,\s*/, $1) {
1694            $weight{$_} += 2;
1695          }
1696        }
1697        $&;
1698      }ges;
1699      ## Bug: this code does not support content type.
1700      $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{
1701        $weight{$1}++; $&;
1702      }ge;
1703      delete $weight{$page};        ## Delete myself
1704      for my $page (keys %weight) {
1705        my $w = ($content =~ s/\Q$page\E/$&/g);
1706        $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.
1707        ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page);
1708      }
1709      $option{weight_list}->{$page} = \%weight;
1710      if (--$option{level}) {
1711        for my $page (keys %weight) {
1712          &make_list ($page, %option) unless $option{weight_list}->{$page};
1713        }
1714      }
1715      $option{weight_list};
1716    }
1717    
1718    sub list_to_html ($$;%) {
1719      my ($Page, $wlist, %option) = @_;
1720      my $r = '';
1721      $option{outputed}->{$Page} = 1;
1722      for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {
1723        $r .= qq(<li><span class="weight">[@{[0+$wlist->{$Page}->{$page}]}]</span> <a href="$main::url_cgi?@{[&main::encode($page)]}" class="wiki@{[$option{not_exist}->{$page}?' not-exist':'']}">@{[&main::escape ($page).($option{not_exist}->{$page}?qq(<span class="mark">@{[&main::Resource('JumpAndEditWikiPageMark',escape=>1)]}</span>):'')]}</a> <a href="$main::url_cgi?mycmd=map;mypage=@{[&main::encode($page)]}" class="wiki-cmd map-from-here" title="@{[&main::escape($option{map_from_here_description})]}">@{[&main::escape($option{map_from_here})]}</a> <span class="summary">@{[&main::escape(&main::get_subjectline($page))]}</span>);
1724        unless ($option{outputed}->{$page}) {
1725          $r .= &list_to_html ($page, $wlist, %option);
1726        }
1727        $r .= "</li>\n";
1728      }
1729      $r ? qq(<ul class="map">$r</ul>) : '';
1730    }
1731    
1732    package main;
1733    &main;
1734    exit 0;
1735    
1736    1;
1737    __END__
1738    =head1 NAME
1739    
1740    wiki.cgi - This is YukiWiki, yet another Wiki clone.
1741    walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
1742    
1743    =head1 DESCRIPTION
1744    
1745    YukiWiki is yet another Wiki clone.
1746    
1747    YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).
1748    YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),
1749    and some embedded commands (such as [[#comment]] to add comments).
1750    
1751    Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.
1752    
1753    =head1 AUTHOR
1754    
1755    Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/
1756    
1757    =head1 LICENSE
1758    
1759    Copyright (C) 2000-2002 by Hiroshi Yuki.
1760    
1761    This program is free software; you can redistribute it and/or
1762    modify it under the same terms as Perl itself.
1763    
1764    =cut

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

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.