/[pub]/suikawiki/script/wiki.cgi
Suika

Diff of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Mon Feb 4 13:19:08 2002 UTC revision 1.34 by wakaba, Wed Dec 4 12:00:42 2002 UTC
# Line 1  Line 1 
1  #!/usr/local/bin/perl  #!/usr/bin/perl
2  use lib "../lib";  #
3  use CGI::Carp 'fatalsToBrowser';  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
4  use Algorithm::Diff qw(traverse_sequences);  #
5  # use strict;  # Copyright (C) 2000-2002 by Hiroshi Yuki.
6  #  # <hyuki@hyuki.com>
7  # yukiwiki.cgi - Yet another WikiWikiWeb clone.  # http://www.hyuki.com/yukiwiki/
8  #  #
9  # Copyright (C) 2000,2001 by Hiroshi Yuki.  # This program is free software; you can redistribute it and/or
10  # <hyuki@hyuki.com>  # modify it under the same terms as Perl itself.
11  # http://www.hyuki.com/yukiwiki/  #
12  #  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
13  # This program is free software; you can redistribute it and/or modify  
14  # it under the terms of the GNU General Public License as published by  # Walrus add (debug) start
15  # the Free Software Foundation; either version 2 of the License, or  my $walrus_log;
16  # (at your option) any later version.  my $walrus_debugging = 0;
17  #  # Walrus add (debug) end
18  # This program is distributed in the hope that it will be useful,  
19  # but WITHOUT ANY WARRANTY; without even the implied warranty of  # Libraries.
20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  use strict;
21  # GNU General Public License for more details.  use lib qw(./WalWiki/lib);
22  #  use CGI qw(:standard);
23  # $Id$  use CGI::Carp qw(fatalsToBrowser);
24  ##############################  use Yuki::RSS;
25  my $version = "1.6.6";  use Yuki::DiffText qw(difftext);
26  ##############################  use Yuki::YukiWikiDB;
27  # 単独テストのときには 1 にする。  use AnyDBM_File;
28  my $testing = 0;  require 'jcode.pl';
29  ##############################  require Jcode;
30  # 漢字ライブラリ  use Fcntl;
31  my $jcodelib = 'jcode.pl';  my $version = '2.0.beta1.2002-05-29';
32  ##############################  my $walversion;
33  # 保存・表示の漢字コード  ##############################
34  my $kanjicode = 'sjis';     # 'sjis' 'euc'  #
35  my $charset = 'Shift_JIS';  # 'Shift_JIS' 'EUC-JP'  # You MUST modify following '$modifier_...' variables.
36  ##############################  #
37  # dbmopenが使えるなら1、使えないなら0  my $modifier_mail = 'w@suika.fam.cx';   # Your mail address, like 'walrus@digit.que.ne.jp'.
38  my $dbmopen = 0;  my $modifier_url  = 'http://suika.fam.cx/~wakaba/';     # Your web page, like 'http://digit.que.ne.jp/work/'.
39  ##############################  my $modifier_name = 'マツ';       # Your name, like 'Makio Tsukamoto'.
40  # データベース名(.pag, .dir, .dbなどは不要)  # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.
41  # $dbmopen = 1のときはデータベース名、  # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.
42  # $dbmopen = 0のときはディレクトリ名になる。  my $modifier_dbtype = 'YukiWikiDB';     # Slow, available on all environment.
43  my $dbname = './yukiwiki';  # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.
44  my $diffdbname = './yukidiff';  my $modifier_sendmail = ''; # If you don't need mail notification.
45  ##############################  my $modifier_dir_data = './wikidata'; # Your data directory.
46  # 修正者の氏名(自由に変更してください)  my $modifier_rss_title = "SuikaWiki $walversion";
47  my $modifier = 'Hiroshi Yuki';  my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.
48  ##############################  my $modifier_rss_description = 'This is SuikaWiki';
49  # 修正者のWebページ(自由に変更してください)  ##############################
50  my $modifierlink = 'http://www.hyuki.com/';  #
51  ##############################  # You MAY modify following variables.
52  # このページのURL  #
53  my $thisurl = 'yukiwiki.cgi';  my $file_touch = "$modifier_dir_data/touched.txt";
54  ##############################  my $file_resource = "$modifier_dir_data/resource.txt";
55  # 開始ページ名  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
56  my $toppage = 'FrontPage';  my $file_conflict = "$modifier_dir_data/conflict.txt";
57  ##############################  my $file_format = "$modifier_dir_data/format.txt";
58  # 最終更新ページ名  my $url_cgi = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'
59  my $whatsnew = 'RecentChanges';  my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
60  ##############################  my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';
61  # 最終更新に掲載するページ数  my $maxrecent = 50;
62  my $maxnew = 50;  my $cols = 80;
63  ##############################  my $rows = 20;
64  # アイコンファイル名(カラー版)  ##############################
65  my $iconfile = 'yukiwiki.gif';  #
66  ##############################  # You MAY, but do NOT NEED modify following variables.
67  # アイコンファイル名(モノクロ版)  #
68  # my $iconfile = 'yukimono.gif';  my $dataname = "$modifier_dir_data/wiki";
69  ##############################  my $infoname = "$modifier_dir_data/info";
70  # ページを変更したときにtouchするファイル(''なら何もしない)  my $diffname = "$modifier_dir_data/diff";
71  my $touchfile = 'touch.txt';  my $editchar = '?';
72  ##############################  my $subject_delimiter = ' - ';
73  # プレビュー用の背景色  my $use_autoimg = 1; # automatically convert image URL into <img> tag.
74  my $preview_color = '#FFCCCC';  my $use_exists = 0; # If you can use 'exists' method for your DB.
75  ##############################  ##############################
76  # 全ページのスタイル  my $InterWikiName = 'InterWikiName';
77  my $style = <<'EOD';  my $RecentChanges = 'RecentChanges';
78  pre, dl, ul, ol, p, blockquote { line-height:120%; }  my $AdminChangePassword = 'AdminChangePassword';
79  a { text-decoration: none; }  my $CompletedSuccessfully = 'CompletedSuccessfully';
80  a:link { color: #0000FF; background-color: #FFFFFF; }  my $FrontPage = 'HomePage';
81  a:visited { color: #9900CC; background-color: #FFFFFF; }  my $IndexPage = 'IndexPage';
82  a:hover { text-decoration: underline; }  my $SearchPage = 'SearchPage';
83  EOD  my $CreatePage = 'CreatePage';
84  ##############################  my $ErrorPage = 'ErrorPage';
85  # テキスト入力部分の大きさ  my $RssPage = 'RssPage';
86  my $cols = 80;  my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
87  my $rows = 20;  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
88  ##############################  ##############################
89  my %form = ();  my $bracket_name = '\[\[(\S+?)\]\]';
90  my %database = ();  my $embedded_name = '\[\[(#\S+?)\]\]';
91  my %diffbase = ();  my %fmt;        ## formatter objects
92  my $diff_text = '';  ##############################
93  my @diff_added = ();  my $embed_comment = '[[#comment]]';
94  my @diff_deleted = ();  my $embed_rcomment = '[[#rcomment]]';
95  my $msgrefA;  my $embed_comment_Name_Prompt = 'フセチー:';
96  my $msgrefB;  my $DEFAULT_embed_comment_name = 'フセフオ、キ、オ、';
97  ##############################  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)
98  # 編集不可ページ名一覧  my %embed_command = (
99  my @uneditable = ( $whatsnew );          searched        => '^\[\[#searched:([^\]]+)\]\]$',
100  ##############################      form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
101  # リンク用の正規表現  );
102  # YukiWikiのリンクは2種類ある。  ##############################
103  #  my $info_LastModified = 'LastModified';
104  # (1) WikiName (RecentChangesとかFrontPageのようなもの)  my $info_IsFrozen = 'IsFrozen';
105  # (2) BracketName ([[結城浩]]とか[[トラブルシュート]]のようなもの)  my $info_AdminPassword = 'AdminPassword';
106  #  ##############################
107  # ※シフトJISの2バイト目には ']' が来うるので、  my $kanjicode = 'euc';
108  # 文字']'を1つ多くとるようにしている。  my $charset = 'EUC-JP';
109  #  my $lang = 'ja';
110  my $WikiName = '([A-Z][a-z]+([A-Z][a-z]+)+)';  my %fixedpage = (
111  my $BracketName = '\[\[([^>\s]+?\]?)\]\]';      $IndexPage => 1,
112        $CreatePage => 1,
113  # アイコン部分のタグ      $ErrorPage => 1,
114  my $IconTag = <<"EOD";      $RssPage => 1,
115  <a href="http://www.hyuki.com/yukiwiki/"><img src="$iconfile"      $RecentChanges => 1,
116   border="0" width="80" height="80" alt="[YukiWiki]" /></a>      $SearchPage => 1,
117  EOD      $AdminChangePassword => 1,
118        $CompletedSuccessfully => 1,
119  require "$jcodelib";      #$FrontPage => 1,
120        WikiUserAgentList => 1,
121  &init_form($kanjicode);  );
122    my %form;
123  if ($testing) {  my %database;
124      %form = (  my %infobase;
125          # 'mycmd' => 'write',  my %diffbase;
126          'mycmd' => 'read',  my %resource;
127          #'mycmd' => 'search',  my %interwiki;
128          #'mycmd' => 'edit',  ##############################
129          'mymsg' => <<"EOD",  my %page_command = (
130  はじめまして。      $IndexPage => 'index',
131  これからいろいろ書き込みますね。      $SearchPage => 'searchform',
132  LinkPageも見てください。      $CreatePage => 'create',
133  TestPageはどうでしょうか。      $RssPage => 'rss',
134  どうぞよろしく。      $AdminChangePassword => 'adminchangepasswordform',
135  http://www.hyuki.com/      #$FrontPage => 'FrontPage',
136  [[結城浩]]  );
137  EOD  my %command_do = (
138          'mypage' => '<結城浩>',      read => \&do_read,
139          'myword' => '結',      TEXT_CSS => \&do_output_css,
140          # '3C8C8B8FE98D5F3E' => '',      edit => \&do_edit,
141          # 'TestPage' => '',      adminedit => \&do_adminedit,
142      );      adminchangepasswordform => \&do_adminchangepasswordform,
143  }      adminchangepassword => \&do_adminchangepassword,
144  &main;      write => \&do_write,
145  exit(0);      index => \&do_index,
146        searchform => \&do_searchform,
147  # メイン      search => \&do_search,
148  sub main {      create => \&do_create,
149      &normalize_form;      createresult => \&do_createresult,
150      if ($dbmopen) {      FrontPage => \&do_FrontPage,
151          if (!dbmopen(%database, $dbname, 0666)) {      comment => \&do_comment,
152              &print_error("(dbmopen) $dbname が作れません。");      RandomJump  => \&do_random_jump,
153          }      rss => \&do_rss,
154      } else {      diff => \&do_diff,
155          if (!tie(%database, "YukiWikiDB", $dbname)) {      interwikibox => \&do_interwiki_box, # Walrus add (5)
156              &print_error("(tie error)");      wikiform => \&do_wikiform,
157          }  );
158      }  ##############################
159    my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)
160      # myspecial対応  ##############################
161      foreach (keys %form) {  # &test_convert;
162          if (/^myspecial_(.*)/) {  my $UA = '';  ## User agent name
163              $form{mycmd} = $1;  &main;
164              last;  exit(0);
165          }  ##############################
166      }  
167    sub main {
168      if ($form{mycmd} eq 'read') {      $UA = $main::ENV{HTTP_USER_AGENT};
169          &do_read;      &init_resource;
170      } elsif ($form{mycmd} eq 'preview') {      &open_db;
171          &do_preview;      &init_form;
172      } elsif ($form{mycmd} eq 'write') {      &init_InterWikiName;
173          &do_write;      if ($command_do{$form{mycmd}}) {
174      } elsif ($form{mycmd} eq 'edit') {          &{$command_do{$form{mycmd}}};
175          &do_edit;      } else {
176      } elsif ($form{mycmd} eq 'reedit') {          &do_FrontPage;
177          &do_reedit;      }
178      } elsif ($form{mycmd} eq 'search') {      &close_db;
179          &do_search;  }
180      } elsif ($form{mycmd} eq 'list') {  
181          &do_list;  sub do_read {
182      } elsif ($form{mycmd} eq 'diff') {    my $content = $database{$form{mypage}};
183          &do_diff;    my $lm = &get_info($form{mypage}, $info_LastModified);
184      } else {    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
185          $form{mypage} = $toppage;    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
186          &do_read;    my ($r, $c) = get_search_result ($form{mypage});
187      }    my $rl = wiki::referer::list_html ($form{mypage});
188      if ($dbmopen) {    my @toc;
189          dbmclose(%database);    push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;
190      } else {    push @toc, qq(-<a href="#wikipage-referer">サイセネクオ</a>) if $rl;
191          untie(%database);      my $cf = 'SuikaWiki/0.9';
192      }      ## Should be support at least:
193  }      ## - 'SuikaWiki/0.9' CRLF
194        ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
195  # ページの表示      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
196  sub do_read {      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
197      my $page_name = $form{mypage};      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
198      my $percent_name = &encode_percent($page_name);        &print_header ($form{mypage}, -last_modified => $lm,
199      &print_header($page_name);          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
200      print qq|<h1>$IconTag<a href="$thisurl?mycmd=search&myword=$percent_name">$page_name</a></h1>\n|;        &print_content ($content, content_format => $cf, last_modified => $lm,
201      &print_toolbar($page_name);          -toc => \@toc);
202      print &convert_html(&get_page($page_name));        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
203      &print_footer;      } else {
204  }        &print_header($form{mypage}, -last_modified => $lm);
205          print "<pre>@{[&escape($content)]}</pre>";
206  # ページの編集      }
207  sub do_edit {      if ($c) {
208      if (not &is_editable($form{mypage})) {        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
209          # 編集不可ページは表示のみ        print $r;
210          &do_read;      }
211          return;      if ($rl) {
212      }        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>サイセネクオ</h2>\n$rl</div>\n);
213      &editpage(&get_page($form{mypage}));      }
214  }    &print_footer($form{mypage}, $lm);
215    }
216  # ページの再編集  
217  sub do_reedit {  sub do_output_css {
218      if (not &is_editable($form{mypage})) {    my $content = $database{$form{mypage}};
219          # 編集不可ページは表示のみ    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
220          &do_read;      my $lm = &get_info($form{mypage}, $info_LastModified);
221      } else {      print "Content-Type: text/css; charset=$charset\n";
222          &editpage($form{mymsg});      print "Last-Modified: $lm\n";
223      }      print "\n";
224  }      print $content;
225      } else {
226  sub editpage {      print "Status: 406 Unsupported Media Type\n";
227      my $page_msg = shift;      &print_header('WikiPageIsNotCSS', -noindex => 1);
228      my $page_name = $form{mypage};      &print_content($database{WikiPageIsNotCSS});
229      my $digest = &calc_message_digest($page_msg);      &print_footer('WikiPageIsNotCSS');
230      &print_header($page_name);    }
231      print qq|<h1>$IconTag${page_name}の編集</h1>\n|;  }
232      &print_toolbar($page_name);  
233      $page_msg = &escape($page_msg);  sub id_and_name ($) {
234      print <<"EOD";      my $name = shift;
235  <form action="$thisurl" method="post">      if ($UA =~ m#Mozilla/[12]\.#) {
236  <input type="hidden" name="mycmd" value="preview">        qq{id="$name"><a name="$name"></a};
237  <input type="hidden" name="mypage" value="$page_name">      } else {
238  <input type="hidden" name="mydigest" value="$digest">          qq{id="$name"};
239  <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$page_msg</textarea><br>      }
240  <input type="submit" value="プレビュー">  }
241  </form>  
242  <hr>  sub do_edit {
243  <h3>テキスト整形のルール</h3>      my ($page) = &unarmor_name(&armor_name($form{mypage}));
244        &print_header($page, -noindex => 1);
245  <p>通常は入力した文字がそのまま出力されますが、      if (not &is_editable($page)) {
246  以下のルールに従ってテキスト整形を行うことができます。</p>          &print_message($resource{cantchange});
247        } elsif (&is_frozen($page)) {
248  <ul>          &print_message($resource{cantchange});
249  <li>      } else {
250  空行は段落の区切りとなります。          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
251        }
252  <li>      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
253  HTMLのタグは書けません。      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
254        my ($r, $c) = get_search_result ($form{mypage});
255  <li>      my $rl = wiki::referer::list_html ($form{mypage});
256  ''ボールド''のようにシングルクォート二つではさむと、ボールドになります。      if ($c) {
257          print q{<h2 id="wikipage-see-also">See also</h2>};
258  <li>        print $r;
259  '''イタリック'''のようにシングルクォート三つではさむと、イタリックになります。      }
260        if ($rl) {
261  <li>        print qq(<div id="wikipage-referer"><h2>サイセネクオ</h2>\n$rl</div>\n);
262  ----のようにマイナス4つがあると、水平線になります。      }
263        &print_footer($page);
264  <li>  }
265  *を行頭に書くと大見出しになります。  
266    sub do_adminedit {
267  <li>      my ($page) = &unarmor_name(&armor_name($form{mypage}));
268  **を行頭に書くと小見出しになります。      &print_header($page, -noindex => 1);
269        if (not &is_editable($page)) {
270  <li>          &print_message($resource{cantchange});
271  -を行頭に書くと箇条書きになります。- -- --- の3レベルがあります。      } else {
272            &print_message($resource{passwordneeded});
273  <li>          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
274  :を行頭に書くと用語と解説文が作れます。      }
275        &print_footer($page);
276  <pre>  }
277      :用語1:いろいろ書いた解説文1  
278      :用語2:いろいろ書いた解説文2  sub do_adminchangepasswordform {
279      :用語3:いろいろ書いた解説文3      &print_header($AdminChangePassword, -noindex => 1);
280  </pre>      &print_passwordform;
281        &print_footer($AdminChangePassword);
282  <li>  }
283  http://www.hyuki.com/ のようなURLは自動的にリンクになります。  
284    sub do_adminchangepassword {
285  <li>      if ($form{mynewpassword} ne $form{mynewpassword2}) {
286  YukiWikiのように大文字小文字を混ぜた英文字列を書くと、          &print_error($resource{passwordmismatcherror});
287  YukiWikiのページ名になります。      }
288        my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
289  <li>      if ($validpassword_crypt) {
290  [[結城浩]]のように二重の大かっこ[[ ]]でくくった文字列を書くと、          if (not &valid_password($form{myoldpassword})) {
291  YukiWikiのページ名になります。              &send_mail_to_admin(<<"EOD", "AdminChangePassword");
292  大かっこの中にはスペースを含めてはいけません。  myoldpassword=$form{myoldpassword}
293  日本語も使えます。  mynewpassword=$form{mynewpassword}
294    mynewpassword2=$form{mynewpassword2}
295  <li>  EOD
296  行頭がスペースで始まっていると、              &print_error($resource{passworderror});
297  その段落は整形済み扱われます。          }
298  プログラムを書き込むときに使うと便利です。      }
299        my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
300  <li>      my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
301  > を行頭に書くと、      my $salt1 = $token[(time | $$) % scalar(@token)];
302  引用文が書けます。      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
303  >の数が多いとインデントが深くなります(3レベルまで)。      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
304        &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
305  </ul>  
306  EOD      &print_header($CompletedSuccessfully, -noindex => 1);
307      &print_footer;      &print_message($resource{passwordchanged});
308  }      &print_footer($CompletedSuccessfully);
309    }
310  # ページの検索  
311  sub do_search {  sub do_index {
312      if ($form{myword}) {      &print_header($IndexPage);
313          &print_header('検索結果');      print qq(<ul>);
314          print qq|<h1>$IconTag$form{myword}の検索結果</h1>\n|;      foreach my $page (sort keys %database) {
315          &print_toolbar();          if (&is_editable($page)) {
316          print qq|<ul>\n|;              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
317          my $count = 0;              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
318          foreach my $page_name (sort keys %database) {    # sortするのは無謀かな              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
319              if ($database{$page_name} =~ /\Q$form{'myword'}\E/) {          }
320                  my $encoded = &encode_percent($page_name);      }
321                  print qq|<li><a href="$thisurl?mycmd=read&mypage=$encoded">$page_name</a>\n|;      print qq(</ul>);
322                  $count++;      &print_footer($IndexPage);
323              }  }
324          }  
325          print qq|</ul>\n|;  sub do_write {
326          if ($count > 0) {      if (&frozen_reject()) {
327              print qq|<p><b>$form{myword}</b>を含むページは、上に示す<b>$count</b>ページです。</p>\n|;          return;
328          } else {      }
329              print qq|<p><b>$form{myword}</b>を含むページは見つかりません。</p>\n|;  
330          }      if (not &is_editable($form{mypage})) {
331      } else {          &print_header($form{mypage}, -noindex => 1);
332          &print_header('単語検索');          &print_message($resource{cantchange});
333          print qq|<h1>$IconTag単語検索</h1>\n|;          &print_footer($form{mypage});
334          &print_toolbar();          return;
335      }      }
336      print <<"EOD";  
337  <p>      if (&conflict($form{mypage}, $form{mymsg})) {
338  <form action="$thisurl" method="post">          return;
339  <input type="hidden" name="mycmd" value="search">      }
340  <input type="text" name="myword" size="20" value="$form{myword}">  
341  <input type="submit" value="単語検索">      # Making diff
342  </form>      {
343  </p>          &open_diff;
344  EOD          my @msg1 = split(/\n/, $database{$form{mypage}});
345      &print_footer;          my @msg2 = split(/\n/, $form{mymsg});
346  }          $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);
347            &close_diff;
348  # ページの一覧      }
349  sub do_list {  
350      &print_header('ページ一覧');      if ($form{mymsg}) {
351      print qq|<h1>$IconTag ページ一覧</h1>\n|;          $database{$form{mypage}} = $form{mymsg};
352      &print_toolbar();          &send_mail_to_admin($form{mypage}, "Modify");
353      print qq|<ul>\n|;          if ($form{mytouch}) {
354      foreach my $page_name (sort keys %database) {    # sortするのは無謀かな              &set_info($form{mypage}, $info_LastModified, '' . localtime);
355          my $encoded = &encode_percent($page_name);              &update_recent_changes;
356          print qq|<li><a href="$thisurl?mycmd=read&mypage=$encoded">$page_name</a>\n|          }
357      }          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
358      print qq|</ul>\n|;          my $fragment;
359      &print_footer;          if ($form{__comment_anchor_index}) {
360  }              $fragment = qq(anchor-$form{__comment_anchor_index});
361            } elsif ($form{__wikiform_anchor_index}) {
362  # プレビュー              $fragment = qq(wikiform-$form{__wikiform_anchor_index});
363  sub do_preview {          }
364      my $page_name = $form{mypage};          &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($fragment?'#'.$fragment:''));
365      my $escapedmsg = &escape($form{mymsg});          &print_message($resource{saved});
366      &print_header($page_name);          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
367      print qq|<h1>$IconTag${page_name}のプレビュー</h1>\n|;          &print_footer($CompletedSuccessfully);
368      &print_toolbar($page_name);      } else {
369      # local $percent_name = &encode_percent($page_name);          &send_mail_to_admin($form{mypage}, "Delete");
370      print qq|<p>以下のプレビューを確認して、よければページ下部のボタンで更新してください。</p>\n|;          delete $database{$form{mypage}};
371      if ($form{mymsg}) {          delete $infobase{$form{mypage}};
372          print qq|<table width="100%" bgcolor="$preview_color" ><tr><td>\n|;          if ($form{mytouch}) {
373          # print &convert_html($escapedmsg);              &update_recent_changes;
374          print &convert_html($form{mymsg});          }
375          print qq|</td></tr></table>\n|;          &print_header($form{mypage}, -noindex => 1);
376      } else {          &print_message($resource{deleted});
377          print qq|<p>(ページの内容は空です。更新するとこのページは<b>削除</b>されます。)</p>\n|;          &print_footer($form{mypage});
378      }      }
379      &print_preview_buttons($page_name, $escapedmsg, $form{mydigest});  }
380      &print_footer;  
381  }  sub do_searchform {
382        &print_header($SearchPage);
383  sub print_preview_buttons {      &print_searchform("");
384      my ($page_name, $escapedmsg, $digest) = @_;      &print_footer($SearchPage);
385      print <<"EOD";  }
386      <form action="$thisurl" method="post">  
387      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$escapedmsg</textarea>  sub do_search {
388      <br />      my $word = $form{mymsg};
389      <input type="hidden" name="mypage" value="$page_name">      &print_header($SearchPage);
390      <input type="hidden" name="mydigest" value="$digest">      &print_searchform(&escape($word));
391      <input type="submit" name="myspecial_preview" value="再度プレビュー">      print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);
392      <input type="submit" name="myspecial_write" value="ページの更新">      &print_footer($SearchPage);
393      </form>  }
394  EOD  
395  }  sub get_search_result ($;%) {
396      my $word = lc shift;
397  # 書き込む    my %option = @_;
398  sub do_write {    my @r;
399      if (not &is_editable($form{mypage})) {    foreach my $page (keys %database) {
400          # 編集不可ページは表示のみ      next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
401          &do_read;      my $content = $database{$page};
402          return;      my $cf = 'SuikaWiki/0.9';
403      }      $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
404        next if $cf =~ /obsoleted="yes"/;
405      my $page_name = $form{mypage};      if (index (lc $page, $word) > -1) {
406          my $c = $content =~ s/\Q$word\E//gi;
407      # digestを使って、更新の衝突チェック        push @r, [$page, $c+20];
408      my $original_digest = &calc_message_digest(&get_page($page_name));      } elsif (index ($word, lc $page) > -1) {
409      if ($form{mydigest} ne $original_digest) {        my $c = $content =~ s/\Q$word\E//gi;
410          &print_header($page_name);        push @r, [$page, $c+10];
411          print qq|<h1>$IconTag${page_name}で【更新の衝突】が起きました</h1>\n|;      } elsif (my $c = $content =~ s/\Q$word\E//gi) {
412          print <<"EOD";        push @r, [$page, $c];
413  <p>あなたがこのページを編集している間に、      }
414  他の人が同じページを更新してしまったようです。    }
415  </p><p>    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
416  以下に、あなたの編集したテキストがありますので、    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
417  あなたの編集内容が失われないように、    $r = qq|<ul class="search-result">$r</ul>| if $r;
418  いますぐ、メモ帳などにコピー&ペーストしてください。    get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
419  </p><p>    wantarray? ($r, scalar @r): $r;
420  コピー&ペーストが済んでから、  }
421  最新の内容を見て再度編集し直してください。  
422  最新の内容は  sub do_create {
423  <a target="_blank" href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>      &print_header($CreatePage);
424  で見ることができます。      print <<"EOD";
425  </p>  <form action="$url_cgi" method="post">
426  EOD      <input type="hidden" name="mycmd" value="edit">
427          # &print_toolbar($page_name);      <strong>$resource{newpagename}</strong><br>
428          &print_preview_buttons($page_name, &escape($form{mymsg}), $form{mydigest});      <input type="text" name="mypage" value="" size="20">
429          &print_footer;      <input type="submit" value="$resource{createbutton}"><br>
430          return;  </form>
431      }  EOD
432        &print_footer($CreatePage);
433      # diff生成  }
434      {  
435          &opendiff;  sub do_random_jump {
436          my @msg1 = split(/\n/, &get_page($page_name));    my @list = keys %database;
437          my @msg2 = split(/\n/, $form{mymsg});    my $name = &encode ($list[rand @list]);
438          $msgrefA = \@msg1;    my ($scheme) = 'http';
439          $msgrefB = \@msg2;    $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
440          &diff_check;    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
441          $diffbase{$form{mypage}} = $diff_text;    print "\n";
442          $diff_text = '';  }
443          &closediff;  
444      }  sub do_FrontPage {
445        open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
446      &print_header($page_name);      my $content = join('', <FILE>);
447      &set_page($page_name, $form{mymsg});      &code_convert(\$content, $kanjicode);
448      if ($form{mymsg}) {      close(FILE);
449          print qq|<h1>$IconTag${page_name}を更新しました</h1>\n|;      &print_header($FrontPage);
450          &print_toolbar($page_name);      &print_content($content);
451          print &convert_html(&get_page($page_name));      &print_footer($FrontPage);
452      } else {  }
453          print qq|<h1>$IconTag${page_name}を削除しました</h1>\n|;  
454          &print_toolbar($page_name);  sub print_error {
455          print qq|<p>${page_name}を削除しました。</p>\n|;      my ($msg) = @_;
456      }      &print_header($ErrorPage, -noindex => 1);
457      &print_footer;      print qq(<p><strong class="error">$msg</strong></p>);
458      # 更新されたのでタッチしておく。      &print_footer($ErrorPage);
459      if ($touchfile) {      exit(0);
460          open(FILE, "> $touchfile");  }
461          print FILE "\n";  
462          close(FILE);  sub print_header ($;%) {
463      }      my ($page, %option) = @_;
464  }      my $bodyclass = "normal";
465        if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
466  # ページの変更点          $bodyclass = "frozen";
467  sub do_diff {      }
468      if (not &is_editable($form{mypage})) {      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
469          # 編集不可ページは表示のみ      if ($option{-goto}) {
470          &do_read;        if ($UA =~ m#Mozilla/[12]\.|Opera#) {
471          return;            $option{-goto} =~ tr/;/&/;
472      }            print qq{Refresh: 0; url=$option{-goto}\n};
473      &opendiff;            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
474      &print_header($form{mypage} . 'の変更点');        } else {
475      print qq|<h1>$IconTag <a href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>の変更点</h1>\n|;            print qq{Refresh: 0; url="$option{-goto}"\n};
476      &print_toolbar();            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
477      $_ = &escape($diffbase{$form{mypage}});        }
478      print <<"EOD";      }
479  <ul>      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
480  <li>追加された行は<font color="blue">青色</font>です。      my $meta_ct = '';
481  <li>削除された行は<font color="red">赤色</font>です。      if ($UA =~ m#Mozilla/2#) {
482  <li><a href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>へ行く。          $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
483  </ul>          print qq{Content-Type: $meta_ct\n};
484  <hr />          $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
485  EOD      } else {
486      print qq|<pre>\n|;          print qq{Content-Type: text/html; charset=$charset\n};
487      foreach (split(/\n/, $_)) {      }
488          if (/^\+(.*)/) {      my $cookedpage = &encode($page);
489              print qq|<font color="blue">$1</font>\n|;      my $escapedpage = &escape($page);
490          } elsif (/^\-(.*)/) {      print <<"EOD";
491              print qq|<font color="red">$1</font>\n|;  Content-Language: $lang
492          } elsif (/^\=(.*)/) {  Content-Style-Type: text/css
493              print qq|$1\n|;  
494          } else {  <!--
495              print qq|??? $_\n|;  <!DOCTYPE html
496          }      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
497      }      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
498      print qq|</pre>\n|;  <html lang="$lang">
499      &print_footer;  <head>
500      &closediff;      $meta_ct$option{-goto}
501  }      <title>$escapedpage</title>
502        <link rel="index" href="$url_cgi?$IndexPage">
503  sub opendiff {      <link rel="help" href="$url_cgi?WikiHelp">
504      if ($dbmopen) {      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
505          if (!dbmopen(%diffbase, $diffdbname, 0666)) {      <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
506              &print_error("(dbmopen) $diffdbname が作れません。");      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
507          }  </head>
508      } else {  <body class="$bodyclass">
509          if (!tie(%diffbase, "YukiWikiDB", $diffdbname)) {  EOD
510              &print_error("(tie error)");    &print_navigate_links ($page);
511          }    print <<EOD;
512      }  <h1 class="header">@{[&escape($page)]}</h1>
513  }  EOD
514    }
515  sub closediff {  
516      if ($dbmopen) {  sub x_charset ($) {
517          dbmclose(%diffbase);      my $charset = lc shift;
518      } else {      if ($charset eq 'euc-jp') {
519          untie(%diffbase);          $charset = 'x-euc-jp';
520      }      } elsif ($charset eq 'shift_jis') {
521  }          $charset = 'x-sjis';
522        }
523  # フォームからの情報を連想配列 %form に入れる      $charset;
524  # &init_form('euc');  }
525  sub init_form {  
526      my ($charcode) = @_;  sub print_navigate_links (@) {
527      my $query;    my ($page) = @_;
528      if ($ENV{REQUEST_METHOD} =~ /^post$/i) {      my $editable = 0;
529          read(STDIN, $query, $ENV{CONTENT_LENGTH});      my $admineditable = 0;
530      } else {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
531          $query = $ENV{QUERY_STRING};          $editable = 0;
532      }          #$admineditable = 1;
533      my @assocarray = split(/&/, $query);      } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
534      foreach my $assoc (@assocarray) {          #$admineditable = 1;
535          my ($property, $value) = split(/=/, $assoc);          $editable = 1;
536          $value =~ tr/+/ /;      } else {
537          $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;          $editable = 0;
538          &jcode::convert(\$value, $charcode);      }
539          $form{$property} = $value;      my $cookedpage = &encode($page);
540      }    print <<EOH;
541  }  <div class="tools">
542        @{[ $admineditable
543  # エラーページを出力する          ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )
544  sub print_error {          : qq()
545      my ($msg) = @_;      ]}
546      &print_header('Error');      @{[ $editable
547      print "<h1>$IconTag$msg</h1></body></html>";          ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )
548      exit(0);          qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">ハヤスク</a> | )
549  }          : qq()
550        ]}
551  sub escape {      <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">ノスシィ</a> |
552      my ($line) = shift;      @{[ $admineditable
553      $line =~ s|<|&lt;|g;          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
554      $line =~ s|>|&gt;|g;          : qq()
555      $line =~ s|"|&quot;|g;      ]}
556      # $line =~ s|\&|&amp;|g;      <a href="$url_cgi?$CreatePage" class="wiki">ソキオャ</a> |
557      return $line;      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
558  }      <a href="$url_cgi?$FrontPage" class="wiki">シハヌ</a> |
559        <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
560  sub inline {      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">、ノ、ウ、ォ</a> |
561      my ($line) = shift;      <a href="$url_cgi?$RecentChanges" class="wiki">コヌソキ</a>
562      $line = &escape($line);  </div>
563      $line =~ s|'''([^']+?)'''|<i>$1</i>|g;              # Italic  EOH
564      $line =~ s|''([^']+?)''|<b>$1</b>|g;                # Bold  <<EOH;  ## temp
565      $line =~ s!      <a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> |
566                  (      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
567                      ((mailto|http|https|ftp):[\x21-\x7E]*) # Direct http://...  <!--    <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | -->
568                          |      <a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> |
569                      ($WikiName)                         # LocalLinkLikeThis      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
570                          |      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">、ノ、ウ、ォ</a> |
571                      ($BracketName)                      # [[日本語リンク]]      <a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a>
572                  )  </div>
573              !  EOH
574                  &make_link($1)  }
575              !gex;  
576      return $line;  sub print_footer {
577  }      my ($page, $lm) = @_;
578        my $epage = &encode ($page);
579  # ページのタイトルからページの内容を得る      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)
580  sub get_page {      # Walrus mod (1) start
581      my $page_name = shift;    my $cvslog1 = q$Revision$;
582      return $database{$page_name};    my $cvslog2 = q$Date$;
583  }    print_navigate_links ($page);
584      print <<"EOD";
585  # ページの内容を与える  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
586  # &set_page($title, $txt)  <div class="footer">
587  sub set_page {  <a href="http://www.hyuki.com/yukiwiki/" title="$version &copy; 2000-2002 by Hiroshi Yuki">YukiWiki</a> <a href="http://digit.que.ne.jp/work/" title="$walversion &copy; 2000-2002 by Makio Tsukamoto">WalWiki</a>
588      # ページを更新する  <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>
589      my $title = $_[0];  <div class="navigation">
590      $database{$title} = $_[1];  [<a href="/" title="、ウ、ホ・オ。シ・ミ。シ、ホシハヌ">/</a>
591      # 空ページなら削除する  <a href="/map" title="、ウ、ホ・オ。シ・ミ。シ、ホーニニ">テマゾ</a>
592      unless ($database{$title}) {  <a href="/search/" title="、ウ、ホ・オ。シ・ミ。シ、ホク。コ">ク。コ</a>]
593          delete $database{$title};  </div>
594      }  <div class="myuri">
595      # RecentChangesを更新する      &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
596      my $delim = ' - ';  </div>
597      my @pages = split(/\n/, $database{$whatsnew});  </div>
598      my $datestr = &get_current_datestr;  $walrus_log
599      unshift(@pages, qq|-$datestr$delim$title|);  </body>
600      # 同一ページの更新は最新のもののみにし、  </html>
601      # 存在しないページはスキップする。  EOD
602      my %count;  }
603      my @newpages;  
604      foreach my $line (@pages) {  sub escape {
605          my ($prefix, $title) = split(/$delim/, $line);      my $s = shift;
606          $count{$title}++;      $s =~ s|\r\n|\n|g;
607          if ($count{$title} == 1 and exists($database{$title})) {      $s =~ s|&|&amp;|g;
608              push(@newpages, qq|$prefix - $title|);      $s =~ s|<|&lt;|g;
609          }      $s =~ s|>|&gt;|g;
610      }      $s =~ s|"|&quot;|g;
611      # ここで本当に更新      return $s;
612      $database{$whatsnew} = join("\n", splice(@newpages, 0, $maxnew));  }
613  }  
614    sub unescape {
615  # ページのヘッダを出力      my $s = shift;
616  sub print_header {      # $s =~ s|\n|\r\n|g;
617      my $title = shift;      $s =~ s|&lt;|<|g;
618      print <<"EOD";      $s =~ s|&gt;|>|g;
619  Content-type: text/html      $s =~ s|&quot;|"|g;
620        $s =~ s|&amp;|&|g;
621  <html><head>      return $s;
622  <title>$title</title>  }
623  <style type="text/css">  
624  <!--  sub print_content ($;$) {
625  $style      my ($rawcontent, %option) = @_;
626  -->      print &text_to_html($rawcontent, toc=>1, %option);
627  </style>  }
628  </head>  
629  <body bgcolor="white">  sub text_to_html {
630  EOD      my ($txt, %option) = @_;
631  }      my (@txt) = split(/\n/, $txt);
632        my @toc;
633  # ツールバーを出力      my @toc2 = @{$option{-toc}||[]};
634  sub print_toolbar {      my $tocnum = 0;
635      my $page_name = shift;      my (@saved, @result);
636      my $percent_name = &encode_percent($page_name);      unshift(@saved, "</p>");
637      my $editlink = '';      push(@result, "<p>");
638      if ($page_name ne '' and &is_editable($page_name)) {      foreach (@txt) {
639          $editlink = <<"EOD";          chomp;
640  <a href="$thisurl?mycmd=edit&mypage=$percent_name">編集</a> |          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
641  <a href="$thisurl?mycmd=diff&mypage=$percent_name">差分</a> |              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
642  EOD              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
643      }              $tocnum++;
644      print <<"EOD";          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
645  <p>              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
646   [              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
647  <a href="$thisurl?mycmd=read&mypage=$toppage">トップ</a> |              $tocnum++;
648  <a href="$thisurl?mycmd=list">一覧</a> |          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
649  $editlink              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
650  <a href="$thisurl?mycmd=search">単語検索</a> |              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
651  <a href="$thisurl?mycmd=read&mypage=$whatsnew">最終更新</a>              $tocnum++;
652   ]          } elsif (/^\*\*([^\x0D\x0A]*)/) {
653  </p>          # if (/^\*\*(.*)/) {
654  EOD          # Walrus mod (6) end
655  }              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
656                push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');
657  # ページのフッタを出力              $tocnum++;
658  sub print_footer {          } elsif (/^\*([^\x0D\x0A]*)/) {
659      print <<"EOD";              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
660  <hr>              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');
661  <p>              $tocnum++;
662  <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version Copyright (C) 2000,2001 by <a href="http://www.hyuki.com/">Hiroshi Yuki.</a><br />          } elsif (/^(={1,6})(.*)/) {
663  Modified by <a href="$modifierlink">$modifier</a>.<br/>              &back_push('ol', length($1), \@saved, \@result);
664  </p>              push(@result, '<li>' . &inline($2) . '</li>');
665  </body></html>          } elsif (/^(-{1,6})(.*)/) {
666  EOD            &back_push('ul', length($1), \@saved, \@result);
667  }            my ($pf, $l) = ('', $2);
668              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
669  # URLやページの名前からリンクを作る              my $num = 0+$1;
670  sub make_link {              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
671      my $name = shift;            }
672      if ($name =~ /^(http|https|ftp).*?(\.gif|\.png|\.jpeg|\.jpg)?$/) {            push(@result, '<li>' . $pf . &inline ($l) . '</li>');
673          if ($2) {          } elsif (/^:([^:]+):(.*)/) {
674              return qq|<a href="$name"><img border="0" src="$name" /></a>|;              &back_push('dl', 1, \@saved, \@result);
675          } else {              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
676              return qq|<a href="$name">$name</a>|;          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
677          }              &back_push('blockquote', length($1), \@saved, \@result);
678      } elsif ($name =~ /^mailto:(.*)/) {              push @result, "<p>";
679          my $address = $1;              push(@result, &inline($2));
680          return qq|<a href="$name">$address</a>|;              unshift @saved, "</p>";
681      } elsif ($database{$name}) {          } elsif (/^\s*$/) {
682          my $percent_name = &encode_percent($name);              push(@result, splice(@saved));
683          return qq|<a href="$thisurl?mycmd=read&mypage=$percent_name">$name</a>|;              push(@result, "<p>");
684      } else {              unshift(@saved, "</p>");
685          my $percent_name = &encode_percent($name);          } elsif (/^(\s+.*)$/) {
686          return qq|$name<a href="$thisurl?mycmd=edit&mypage=$percent_name">?</a>|;              &back_push('pre', 1, \@saved, \@result);
687      }              #push(@result, &escape($1)); # Not &inline, but &escape
688  }              push(@result, &inline($1));
689    #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
690  # %xx の形式にエンコードする          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
691  # これは、              &back_push('table', 1, \@saved, \@result, ' border="1"');
692  # http://www.hyuki.com/yukiwiki/yukiwiki.cgi?mycmd=read&mypage=%3C%8C%8B%8F%E9%8D_%3E              #######
693  # という形式のために使われる。              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
694  # '<結城浩>' → '%3C%8C%8B%8F%E9%8D_%3E'              # XXXXX
695  sub encode_percent {              my $tmp = "$1,";
696      my $name = shift;              my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
697      my $encoded = '';              my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
698      foreach my $ch (split(//, $name)) {              my @colspan = map {($_ eq '==') ? 0 : 1} @value;
699          if ($ch =~ /[A-Za-z0-9_]/) {              for (my $i = 0; $i < @value; $i++) {
700              $encoded .= $ch;                  if ($colspan[$i]) {
701          } else {                      while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
702              $encoded .= '%' . sprintf("%02X", ord($ch));                          $colspan[$i]++;
703          }                      }
704      }                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
705      return $encoded;                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i]));
706  }                  } else {
707                        $value[$i] = '';
708  # テキスト本体をHTMLに変換する                  }
709  sub convert_html {              }
710      my ($txt) = shift;              push(@result, join('', '<tr>', @value, '</tr>'));
711      my (@txt) = split(/\n/, $txt);              # XXXXX
712      foreach (@txt) {              #######
713          chomp;          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
714          if (/^\*\*(.*)/) {              push @result, splice (@saved), '<'.lc($1).'>';
715              push(@result, splice(@saved), '<h3>' . &inline($1) . '</h3>');              unshift @saved, "</p>";
716          } elsif (/^\*(.*)/) {              push @result, "<p>";
717              push(@result, splice(@saved), '<h2>' . &inline($1) . '</h2>');          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
718          } elsif (/^----/) {              push @result, splice (@saved), '</'.lc($1).'>';
719              push(@result, splice(@saved), '<hr>');          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
720          } elsif (/^(-{1,3})(.*)/) {            my $num = 0+$1;
721              &back_push('ul', length($1));            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
722              push(@result, '<li>' . &inline($2) . '</li>');            push @result, &inline ($2);
723          } elsif (/^:([^:]+):(.*)/) {          } else {
724              &back_push('dl', 1);              push(@result, &inline($_));
725              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');          }
726          } elsif (/^(>{1,3})(.*)/) {      }
727              &back_push('blockquote', length($1));      push(@result, splice(@saved));
728              push(@result, &inline($2));      
729          } elsif (/^\s*$/) {      my $toc = '';
730              push(@result, splice(@saved));      if ($option{toc}) {
731              unshift(@saved, "</p>");          # Convert @toc (table of contents) to HTML.
732              push(@result, "<p>");          # This part is taken from Makio Tsukamoto's WalWiki.
733          } elsif (/^(\s+.*)$/) {          my (@tocsaved, @tocresult);
734              &back_push('pre', 1);          foreach (@toc,@toc2) {
735              push(@result, &escape($1)); # Not &inline, but &escape              if (/^(-{1,6})(.*)$/) {
736          } else {                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
737              push(@result, &inline($_));                  push(@tocresult, '<li>' . $2 . '</li>');
738          }              }
739      }          }
740      push(@result, splice(@saved));          push(@tocresult, splice(@tocsaved));
741      return join("\n", @result);          $toc = join("\n", @tocresult);
742  }          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
743        }
744  # &back_push($tag, $count)      $toc .= join("\n", @result);
745  # $tagのタグを$levelレベルまで詰める。      $toc =~ s#<p>\n</p>##g;
746  sub back_push {      $toc =~ s#[\x0D\x0A]+</#</#g;
747      my ($tag, $level) = @_;      $toc =~ s#<pre>\n#<pre>#g;
748      while (@saved > $level) {      $toc;
749          push(@result, shift(@saved));  }
750      }  
751      if ($saved[0] ne "</$tag>") {  sub back_push {
752          push(@result, splice(@saved));      my ($tag, $level, $savedref, $resultref, $attr) = @_;
753      }      while (@$savedref > $level) {
754      while (@saved < $level) {          push(@$resultref, shift(@$savedref));
755          unshift(@saved, "</$tag>");      }
756          push(@result, "<$tag>");      if ($savedref->[0] ne "</$tag>") {
757      }          push(@$resultref, splice(@$savedref));
758  }      }
759        while (@$savedref < $level) {
760  # 編集可能ページか?          unshift(@$savedref, "</$tag>");
761  sub is_editable {          push(@$resultref, "<$tag$attr>");
762      my ($pagename) = @_;      }
763      foreach (@uneditable) {  }
764          if ($pagename eq $_) {  
765              return 0;  sub inline {
766          }      my ($line) = @_;
767      }      $line = &escape($line);
768      if (&is_valid_name($pagename)) {      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
769          return 1;      $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;
770      }      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
771      return 0;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
772  }      $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;
773        $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
774  # Validな名前か?      $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;
775  sub is_valid_name {      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%。ヨ<q@{[$2?qq( cite="$2"):'']}>$1</q>。ラ%g;
776      my ($pagename) = @_;      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
777      if ($pagename =~ /^$WikiName$/) {      $line =~ s|''([^']+)''|<em>$1</em>|g;
778          return 1;      $line =~ s{
779      } elsif ($pagename =~ /^$BracketName$/) {        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]
780          return 1;        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]
781      } else {        |&gt;&gt;([0-9]+)
782          return 0;        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
783      }      }{
784  }        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
785          if ($l) {
786  # 現在時刻の文字列を得る          &make_link($l)
787  sub get_current_datestr {        } elsif (defined $page) {
788      my (@wdays) = ( "日", "月", "火", "水", "木", "金", "土" );          &make_wikilink ($page, anchor => 0+$anchor);
789      my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time);        } elsif ($anum) {
790      return sprintf("%4d-%02d-%02d (%s) %02d:%02d:%02d",          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
791          $year + 1900, $mon + 1, $mday, $wdays[$wday], $hour, $min, $sec);        } elsif ($uri) {
792  }          &make_urilink ($uri);
793          }
794  # URL?SomePageや、      }gex;
795  # URL?[[結城浩]]の形式だった場合、(not yet)      return $line;
796  # 強制的にmycmdをreadにして$formの内容を設定する。  }
797  sub normalize_form {  
798      foreach my $key (keys %form) {  sub make_wikilink ($%) {
799          if ($key =~ /^$WikiName$/) {    my ($ename, %option) = @_;
800              $form{mycmd} = 'read';    my $name = &unescape ($ename);
801              $form{mypage} = $1;    if ($database{$name}) {
802              last;      my $subject = &escape (&get_subjectline ($name, delimiter => ''));
803          } elsif ($key =~ /^$BracketName$/) {      if ($option{anchor}) {
804              $form{mycmd} = 'read';        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
805              $form{mypage} = $1;      } else {
806              last;        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
807          }      }
808      }    } else {
809  }      return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>);
810      }
811  # 変換テストを行なうときのサンプル  }
812  sub print_sample {  
813      my $txt = &convert_html(<<"EOD");  sub make_urilink ($;%) {
814  *大見出し1    require URI;
815  **小見出し1-1    my $uri = shift;
816  -項目1    if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
817  -項目2      $uri = &unescape ($uri);
818  -項目3      if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
819  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1        my ($site, $name) = ($1, $2);
820  段落1段落1段落1段落1段落1段落''強調''1段落1段落1段落1段落1段落1        for ($site, $name) {
821  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1          if (s/^"//) { s/"$//; s/\\(.)/$1/g }
822          }
823  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2        if ($interwiki{$site}) {
824  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
825  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2          $site = &escape ($site); $name = &escape ($name);
826  **小見出し1-2          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;);
827  :用語1:いろいろ書いた解説文1と''強調単語''        } else {
828  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1          qq(&lt;フ、ナミマソ、ホ <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
829  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1        }
830  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1      } else {
831  :用語2:いろいろ書いた解説文2        qq(&lt;ノヤタオ、ハ <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
832  :用語3:いろいろ書いた解説文3      }
833  ----    } elsif ($uri =~ /^urn:/) {   ## URN
834  *大見出し2      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
835  **小見出し2-1      qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
836  http://www.hyuki.com/    } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
837  **小見出し2-2      my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
838        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
839  [[結城浩]]    } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
840        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
841  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1      qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
842  段落1段落1段落1段落'''イタリック'''1段落1段落1段落1段落1段落1段落1段落1    } else {      ## misc. URI
843  段落1段落1段落1段落'''''イタボールド'''''1段落1段落1段落1段落1段落1段落1段落1段落1      CGI::Carp::warningsToBrowser (0);
844  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2      my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
845  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2      CGI::Carp::warningsToBrowser (1);
846  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2      qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
847      }
848  レベル0レベル0レベル0レベル0レベル0レベル0  }
849    
850  >レベル1  my $FormIndex = 0;
851  >レベル1  sub make_custom_form ($$$) {
852  >レベル1      my ($wfname, $definition, $template, $option) = @_;
853  >>レベル2      ## $template and $option is currently not used in this procedure.
854  >>レベル2      unless ($main::_EMBEDED) {
855  >>レベル2          $FormIndex++;
856  >>>レベル3          if (length $definition) {
857  -はろ1              my $param = bless {}, 'SuikaWiki::Plugin';
858  --はろ2              my $lastmodified = &get_info($form{mypage}, $info_LastModified);
859  ろろろろ2              $definition =~ s/\\(.)/$1/g;
860  ---はろ3              $definition .= ' %submit;' if $definition !~ /%submit/;
861  --はろ2              unless ($fmt{form_option}) {
862  ---はろ3                  $fmt{form_option} = Message::Util::Formatter->new;
863  --はろ2                  for (@{$SuikaWiki::Plugin::List{wikiform_option}||[]}) {
864  ---はろ3                      $_->load_formatter ($fmt{form_option}, type => 'wikiform_option');
865  >>>レベル3                  }
866  >>>レベル3              }
867  >>>レベル3              $option = &unescape ($option);
868  EOD              $option =~ s/\\(.)/$1/g;
869      print $txt;              $fmt{form_option}->replace ($option, $param);
870      exit;              my $target_form = $param->{output}->{id};
871  }              my $r = <<EOH;
872    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
873  sub diff_check {    <input type="hidden" name="mycmd" value="wikiform">
874      traverse_sequences(    <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
875              $msgrefA, $msgrefB,    <input type="hidden" name="myLastModified" value="$lastmodified">
876              {    <input type="hidden" name="mytouch" value="on">
877                  MATCH => \&df_match,    <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
878                  DISCARD_A => \&df_delete,  EOH
879                  DISCARD_B => \&df_add,              $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
880              }              $r .= $fmt{form_input}->replace (&unescape ($definition), $param);
881      );              $r .= <<EOH;
882      &diff_flush;  </form>
883  }  EOH
884                $r;
885  sub diff_flush {         } else {  ## No input-interface WikiForm
886      $diff_text .= join('', map { "-$_\n" } splice(@diff_deleted));             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
887      $diff_text .= join('', map { "+$_\n" } splice(@diff_added));         }
888  }      } else {
889            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
890  sub df_match {      }
891      my ($a, $b) = @_;  }
892      &diff_flush;  
893      $diff_text .= "=$msgrefA->[$a]\n";  ## to be obsoleted
894  }  sub make_link {
895        my $chunk = shift;
896  sub df_delete {      # Walrus add (3) start
897      my ($a, $b) = @_;      $chunk =~ s/^&lt;(.*)&gt;$/$1/;
898      push(@diff_deleted, $msgrefA->[$a]);      my $name  = $chunk;
899  }      $name = &unarmor_name($name);
900        # Walrus add (3) end
901  sub df_add {      if ($chunk =~ /^$embedded_name$/) {
902      my ($a, $b) = @_;          return &embedded_to_html($chunk);
903      push(@diff_added, $msgrefB->[$b]);      } else {
904  }          $chunk = &unarmor_name($chunk);
905            $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
906  sub calc_message_digest {   # You have to use MD5...          my $cookedchunk = &encode($chunk);
907      my $text = shift;          if ($database{$chunk}) {
908      my @text = split(//, $text);              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
909      my $len = length($text);  #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)
910      my $checksum = 0;              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)
911      foreach (@text) {          } elsif ($page_command{$chunk}) {
912          $checksum += ord($_);  #           return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>);    # Walrus del (3)
913          $checksum = ($checksum * 2) % 65536 + (($checksum & 32768) ? 1 : 0); # 16bit rotate              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)
914      }          } else {
915      return "$len:$checksum";              return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
916  }          }
917        }
918  # Definition of YukiWikiDB  }
919  package YukiWikiDB;  
920    sub print_message {
921  my $debug = 1;      my ($msg) = @_;
922        print qq(<p><strong>$msg</strong></p>);
923  # Constructor  }
924  sub new {  
925      return shift->TIEHASH(@_);  sub get_message {
926  }      my ($msg) = @_;
927        qq(<p><strong>$msg</strong></p>);
928  # tying  }
929  sub TIEHASH {  
930      my ($class, $dbname) = @_;  sub init_form {
931      my $self = {      if (param()) {
932          dir => $dbname,          foreach my $var (param()) {
933          keys => [],              $form{$var} = param($var);
934      };        }
935      if (not -d $self->{dir}) {      }
936          if (!mkdir($self->{dir}, 0777)) {      $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
937              print "mkdir(" . $self->{dir} . ") fail\n" if ($debug);      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
938              return undef;        my $query = &decode($main::ENV{QUERY_STRING});
939          }        $query = &code_convert(\$query, $kanjicode);
940      }        if ($page_command{$query}) {
941      return bless($self, $class);          $form{mycmd} = $page_command{$query};
942  }          $form{mypage} = $query;
943          } else {
944  # Store          $form{mypage} = $query;
945  sub STORE {          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
946      my ($self, $key, $val) = @_;        }
947      my $file = &make_filename($self, $key);      }
948      if (open(FILE,"> $file")) {      $form{mypage} ||= 'HomePage';
949          binmode(FILE);      $form{mycmd} ||= 'read';
950          print FILE $val;  
951          close(FILE);      # mypreview_edit        -> do_edit, with preview.
952          return $self->{$key} = $val;      # mypreview_adminedit   -> do_adminedit, with preview.
953      } else {      # mypreview_write       -> do_write, without preview.
954          print "$file create error.";      foreach (keys %form) {
955      }          if (/^mypreview_(.*)$/) {
956  }              $form{mycmd} = $1;
957                $form{mypreview} = 1;
958  # Fetch          }
959  sub FETCH {      }
960      my ($self, $key) = @_;  
961      my $file = &make_filename($self, $key);      #
962      if (open(FILE, $file)) {      # $form{mycmd} is frozen here.
963          local $/;      #
964          $self->{$key} = <FILE>;  
965          close(FILE);      for (grep /^wikiform__/, keys %form) {
966      }          $form{$_} = &code_convert (\$form{$_}, $kanjicode);
967      return $self->{$key};      }
968  }      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
969        $form{myname} = &code_convert(\$form{myname}, $kanjicode);
970  # Exists  }
971  sub EXISTS {  
972      my ($self, $key) = @_;  sub update_recent_changes {
973      my $file = &make_filename($self, $key);      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
974      return -e($file);      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
975  }      shift (@oldupdates); ## '#?' magic line
976        my @updates;
977  # Delete      foreach (@oldupdates) {
978  sub DELETE {          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;
979      my ($self, $key) = @_;          my $name = $1;
980      my $file = &make_filename($self, $key);          if ($name ne $form{mypage}) {
981      unlink $file;              push @updates, $_;
982      return delete $self->{$key};          }
983  }      }
984        if (&is_exist_page($form{mypage})) {
985  sub FIRSTKEY {        unshift @updates, $update;
986      my ($self) = @_;      }
987      opendir(DIR, $self->{dir}) or die $self->{dir};      splice(@updates, $maxrecent + 1);
988      @{$self->{keys}} = grep /\.txt$/, readdir(DIR);      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
989      foreach my $name (@{$self->{keys}}) {      if ($file_touch) {
990          $name =~ s/\.txt$//;          open(FILE, "> $file_touch");
991          $name =~ s/[0-9A-F][0-9A-F]/pack("C", hex($&))/eg;          print FILE localtime() . "\n";
992      }          close(FILE);
993      return shift @{$self->{keys}};      }
994  }  }
995    
996  sub NEXTKEY {  sub get_subjectline {
997      my ($self) = @_;      my ($page, %option) = @_;
998      return shift @{$self->{keys}};      if (not &is_editable($page)) {
999  }          return "";
1000        } else {
1001  sub make_filename {          # Delimiter check.
1002      my ($self, $key) = @_;          my $delim = $subject_delimiter;
1003      my $enkey = '';          if (defined($option{delimiter})) {
1004      foreach my $ch (split(//, $key)) {              $delim = $option{delimiter};
1005          $enkey .= sprintf("%02X", ord($ch));          }
1006      }  
1007      return $self->{dir} . "/$enkey.txt";          # Get the subject of the page.
1008  }          my $subject = $database{$page};
1009  __END__          $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
1010            $subject =~ s/\r?\n.*//s;
1011  =head1 NAME          return "$delim$subject".$option{tail};
1012        }
1013  YukiWiki - 自由にページを追加・削除・編集できるWebページ構築CGI  }
1014    
1015      Copyright (C) 2000,2001 by Hiroshi Yuki.  sub send_mail_to_admin {
1016      結城浩 <hyuki@hyuki.com>      my ($page, $mode) = @_;
1017      http://www.hyuki.com/      return unless $modifier_sendmail;
1018      http://www.hyuki.com/yukiwiki/      my $message = <<"EOD";
1019    To: $modifier_mail
1020  =head1 SYNOPSIS  From: $modifier_mail
1021    Subject: [Wiki]
1022      http://www.hyuki.com/yukiwiki/yukiwiki.cgi  MIME-Version: 1.0
1023    Content-Type: text/plain; charset=ISO-2022-JP
1024  =head1 DESCRIPTION  Content-Transfer-Encoding: 7bit
1025    
1026  YukiWiki(結城ウィキィ)は参加者が自由にページを追加・削除・編集できる  --------
1027  不思議なWebページ群を作るCGIです。  MODE = $mode
1028  Webで動作する掲示板とちょっと似ていますが、  REMOTE_ADDR = $ENV{REMOTE_ADDR}
1029  Web掲示板が単にメッセージを追加するだけなのに対して、  REMOTE_HOST = $ENV{REMOTE_HOST}
1030  YukiWikiは、Webページ全体を自由に変更することができます。  --------
1031    $page
1032  YukiWikiは、Cunningham & CunninghamのWikiWikiWebの  --------
1033  仕様を参考にして独自に作られました。  $database{$page}
1034    --------
1035  YukiWikiはPerlで書かれたCGIスクリプトとして実現されていますので、  EOD
1036  Perlが動作するWebサーバならば比較的容易に設置できます。      &code_convert(\$message, 'jis');
1037        open(MAIL, "| $modifier_sendmail");
1038  あとはdbmopenが使える環境ならば設置できます(Version 1.5.0以降ならdbmopenが使えなくても設置できます)。      print MAIL $message;
1039        close(MAIL);
1040    }
1041  YukiWikiはフリーソフトです。  
1042  ご自由にお使いください。  sub open_db {
1043        if ($modifier_dbtype eq 'dbmopen') {
1044  =head1 設置方法          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");
1045            dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");
1046  =head2 入手      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1047            tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");
1048  YukiWikiの最新版は、          tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");
1049  http://www.hyuki.com/yukiwiki/      } else {
1050  から入手できます。          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");
1051            tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");
1052  =head2 ファイル一覧      }
1053    }
1054      readme.txt      ドキュメント  
1055      yukiwiki.cgi    YukiWiki本体  sub close_db {
1056      yukiwiki.gif    ロゴ(カラー版)      if ($modifier_dbtype eq 'dbmopen') {
1057      yukimono.gif    ロゴ(モノクロ版)          dbmclose(%database);
1058      jcode.pl        漢字コードライブラリ          dbmclose(%infobase);
1059        } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1060  =head2 インストール          untie(%database);
1061            untie(%infobase);
1062  =over 4      } else {
1063            untie(%database);
1064  =item 1.          untie(%infobase);
1065        }
1066  アーカイブを解く。  }
1067    
1068  =item 2.  sub open_diff {
1069        if ($modifier_dbtype eq 'dbmopen') {
1070  yukiwiki.cgiのはじめの方にある設定を確認します。          dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");
1071  通常は何もしなくてよいが、      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1072  はじめは$touchfileを''にした方がよいでしょう。          tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");
1073        } else {
1074  =item 3.          tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");
1075        }
1076  yukiwiki.cgiとjcode.plを同じところに設置します。  }
1077    
1078  =item 4.  sub close_diff {
1079        if ($modifier_dbtype eq 'dbmopen') {
1080  サイズ0のyukiwiki.dbというファイルを設置します。          dbmclose(%diffbase);
1081  (Perlシステムによってはyukiwiki.pag, yukiwiki.dir)      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
1082            untie(%diffbase);
1083  =item 5.      } else {
1084            untie(%diffbase);
1085  yukiwiki.cgiにブラウザからアクセスします。      }
1086    }
1087  =back  
1088    sub print_searchform {
1089  =head2 パーミッション      my ($word) = @_;
1090        print <<"EOD";
1091          ファイル        パーミッション      転送モード  <form action="$url_cgi" method="get">
1092          yukiwiki.cgi    755                 ASCII      <input type="hidden" name="mycmd" value="read">
1093          yukiwiki.gif    644                 BINARY      <input type="text" name="mypage" value="$word" size="20">
1094          yukimono.gif    644                 BINARY      <input type="submit" value="$resource{searchbutton}">
1095          jcode.pl        644                 ASCII  </form>
1096    EOD
1097      $dbmopen = 1; にした場合:  }
1098          yukiwiki.db     666                 BINARY  
1099          (yukiwiki.pag, yukiwiki.dirの場合もあり)  sub print_editform {
1100        my ($mymsg, $lastmodified, %mode) = @_;
1101      $dbmopen = 0; にした場合: (カレントディレクトリを777にしておく)      my $frozen = &is_frozen($form{mypage});
1102          .               777                 (転送しない)  
1103        if ($form{mypreview}) {
1104  =head1 データのバックアップ方法          if ($form{mymsg}) {
1105                unless ($mode{conflict}) {
1106  $dbmopen = 1;の場合は、                  print qq(<h3>$resource{previewtitle}</h3>\n);
1107  データはすべてyukiwiki.db(.dir, .pag)に入る。                  print qq($resource{previewnotice}\n);
1108  これをバックアップすればよい。                  print qq(<div class="preview">\n);
1109                    &print_content($form{mymsg});
1110  $dbmopen = 0;の場合は、                  print qq(</div>\n);
1111  yukiwikiというディレクトリができるので、              }
1112  これ以下をバックアップすればよい。          } else {
1113                print qq($resource{previewempty});
1114  =head1 新しいページの作り方          }
1115            $mymsg = &escape($form{mymsg});
1116  =over 4      } else {
1117            $mymsg = &escape($mymsg || $database{NewPageTemplate});
1118  =item 1.      }
1119    
1120  まず、適当なページ(例えばFrontPage)を選び、      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1121  ページの下にある「編集」リンクをたどります。      my $escapedmypage = &escape($form{mypage});
1122        my $escapedmypassword = &escape($form{mypassword});
1123  =item 2.  
1124        print <<"EOD";
1125  するとテキスト入力ができる状態になるので、  <form action="$url_cgi" method="post">
1126  そこにNewPageのような単語  <h2>$escapedmypage、ホハヤスク</h2>
1127  (大文字小文字混在している英文字列)      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}
1128  を書いて「保存」します。      <input type="hidden" name="myLastModified" value="$lastmodified">
1129        <input type="hidden" name="mypage" value="$escapedmypage">
1130  =item 3.      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1131    @{[
1132  保存すると、FrontPageのページが書き換わり、      $mode{admin} ?
1133  あなたが書いたNewPageという文字列の後ろに ? というリンクが表示されます。      qq(
1134  この ? はそのページがまだ存在しないことを示す印です。      <input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton}
1135        <input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>)
1136  =item 4.      : ""
1137    ]}
1138  その ? をクリックすると新しいページNewPageができますので、  @{[
1139  あなたの好きな文章をその新しいページに書いて保存します。      $mode{conflict} ? "" :
1140        qq(
1141  =item 5.          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1142            <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1143  NewPageページができるとFrontPageの ? は消えて、リンクとなります。          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1144            [@{[do {my $n = 0;
1145  =back                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1146                   ++$n}]}]<br>
1147  =head1 テキスト整形のルール      )
1148    ]}
1149  =over 4  </form>
1150    EOD
1151  =item *      unless ($mode{conflict}) {
1152            # Show the format rule.
1153  連続した複数行はフィルされて表示されます。          my $help = $database{'WikiEditHelp'};
1154            $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1155  =item *          print &text_to_html ($help, toc => 0);
1156        #    open(FILE, $file_format) or &print_error("($file_format)");
1157  空行は段落C<< <p> >>の区切りとなります。      #    my $content = join('', <FILE>);
1158        #    &code_convert(\$content, $kanjicode);
1159  =item *      #    close(FILE);
1160        #    print &text_to_html($content, toc=>0);
1161  HTMLのタグは書けません。      }
1162    }
1163  =item *  
1164    sub print_passwordform {
1165  B<''ボールド''>のようにシングルクォート二つではさむと、          print <<"EOD";
1166  ボールドC<< <b> >>になります。  <form action="$url_cgi" method="post">
1167        <input type="hidden" name="mycmd" value="adminchangepassword">
1168  =item *      $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>
1169        $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>
1170  B<'''イタリック'''>のようにシングルクォート三つではさむと、      $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>
1171  イタリックC<< <i> >>になります。      <input type="submit" value="$resource{changepasswordbutton}"><br>
1172    </form>
1173  =item *  EOD
1174    }
1175  B<---->のようにマイナス4つがあると、  
1176  水平線C<< <hr> >>になります。  sub is_editable {
1177        my ($page) = @_;
1178  =item *      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
1179            return 0;
1180  行をB<*>ではじめると、      } else {
1181  大見出しC<< <h2> >>になります。          return 1;
1182        }
1183  =item *  }
1184    
1185  行をB<**>ではじめると、  # armor_name:
1186  小見出しC<< <h3> >>になります。  #   WikiName -> WikiName
1187    #   not_wiki_name -> [[not_wiki_name]]
1188  =item *  sub armor_name { qq([[$_[0]]]) }
1189    
1190  行をマイナス-ではじめると、  # unarmor_name:
1191  箇条書きC<< <ul> >>になります。  #   [[bracket_name]] -> bracket_name
1192  マイナスの数が増えるとレベルが下がります(3レベルまで)  #   WikiName -> WikiName
1193    sub unarmor_name {
1194      -項目1      my ($name) = @_;
1195      --項目1-1      if ($name =~ /^$bracket_name$/) {
1196      --項目1-2          return $1;
1197      -項目2      } else {
1198      -項目3          return $name;
1199      --項目3-1      }
1200      ---項目3-1-1  }
1201      ---項目3-1-2  
1202      --項目3-2  sub decode {
1203        my ($s) = @_;
1204  =item *      $s =~ tr/+/ /;
1205        $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
1206  コロンを使うと、      return $s;
1207  用語と解説文のリストC<< <dl> >>が書けます。  }
1208    
1209      :用語1:いろいろ書いた解説文1  sub encode {
1210      :用語2:いろいろ書いた解説文2      my ($s) = @_;
1211      :用語3:いろいろ書いた解説文3      my $encoded = '';
1212        foreach my $ch (split(//, $s)) {
1213  =item *          if ($ch =~ /[A-Za-z0-9_]/) {
1214                $encoded .= $ch;
1215  リンク          } else {
1216                $encoded .= '%' . sprintf("%02X", ord($ch));
1217  =over 4          }
1218        }
1219  =item *      return $encoded;
1220    }
1221  LinkToSomePageやFrontPageのように、  
1222  英単語の最初の一文字を大文字にしたものが  sub init_resource {
1223  二つ以上連続したものはYukiWikiのページ名となり、      open(FILE, $file_resource) or &print_error("(resource)");
1224  それが文章中に含まれるとリンクになります。      while (<FILE>) {
1225            chomp;
1226  =item *          next if /^#/;
1227            my ($key, $value) = split(/=/, $_, 2);
1228  http://www.hyuki.com/ のようなURLは自動的にリンクになります。          $resource{$key} = &code_convert(\$value, $kanjicode);
1229        }
1230  =item *      close(FILE);
1231    }
1232  二重の大かっこ[[ ]]でくくった文字列も、  
1233  YukiWikiのページ名になります。  sub conflict {
1234  大かっこの中にはスペースを含めてはいけません。      my ($page, $rawmsg) = @_;
1235  日本語も使えます。      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1236            return 0;
1237  =back      }
1238        open(FILE, $file_conflict) or &print_error("(conflict)");
1239  =item *      my $content = join('', <FILE>);
1240        &code_convert(\$content, $kanjicode);
1241  行頭がスペースやタブで始まっていると、      close(FILE);
1242  それは整形済みの段落C<< <pre> >>として扱われます。      &print_header($page, -noindex => 1);
1243  プログラムの表示などに使うと便利です。      &print_content($content);
1244        &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1245        &print_footer($page);
1246  =item *      return 1;
1247    }
1248  行を > ではじめると、  
1249  引用文C<< <blockquote> >>が書けます。  sub get_now {
1250  >の数が多いとインデントが深くなります(3レベルまで)。      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1251        my (@week) = qw(ニ キ イミ ソ フレ カ ナレ);
1252      >文章      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1253      >文章      $year += 1900;
1254      >>さらなる引用      $mon++;
1255      >文章      $mon = "0$mon" if $mon < 10;
1256        $day = "0$day" if $day < 10;
1257  =back      $hour = "0$hour" if $hour < 10;
1258        $min = "0$min" if $min < 10;
1259  =head1 更新履歴      #$sec = "0$sec" if $sec < 10;
1260        $weekday = $week[$weekday];
1261  =over 4      return "$year-$mon-$day ($weekday) $hour:$min";
1262    }
1263  =item *  
1264    sub init_InterWikiName {
1265  2001年10月20日、Version 1.6.6。    my @content = split /\n/, $database{$InterWikiName};
1266      for (@content) {
1267  更新の衝突対策。      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1268  元ページの簡単なチェックサムを取っておき、        $interwiki{$1} = $2;
1269  更新前にチェックサムを比較する。      }
1270  修正個所はdigestという文字列を検索すれば分かる。    }
1271  本来はMD5などでちゃんとやった方がいいのだけれど。    require Message::Util::Formatter;
1272      $fmt{interwiki} = Message::Util::Formatter->new;
1273  衝突時に表示されるメッセージなどは「極悪」さんのページを参考にした。    $fmt{interwiki}->{encoded} = sub {
1274        my ($o, $p) = @_;
1275  =item *      if ($o->{except}) {
1276          $o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1277  2001年10月17日、Version 1.6.5。      }
1278        my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1279  プレビュー画面で、更新ボタンを押したときに送信される      $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1280  メッセージの内容をinput要素のtype="hidden"を使って埋め込むのをやめる。      $s;
1281  代わりに、textarea要素を使う。    };
1282  再プレビュー用にmyspecial_を導入。でもきれいな対策ではない。    $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
1283        my ($o, $p) = @_;
1284  =item *      my $s = $p->{name};
1285        $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1286  2001年8月30日、Version 1.6.4。      &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1287      };
1288  URLでダイレクトにページ名を指定しても、  
1289  $WikiNameと$BracketName以外のページを作れないようにした。    $fmt{form_input} = Message::Util::Formatter->new;
1290  (is_valid_nameとis_editable参照)。    for (@{$SuikaWiki::Plugin::List{wikiform_input}||[]}) {
1291        $_->load_formatter ($fmt{form_input}, type => 'wikiform_input');
1292  =item *    }
1293    }
1294  2001年8月30日、Version 1.6.3。  
1295    
1296  RecentChangesを編集・再編集不可とした。  sub get_info {
1297  編集不可ページは@uneditableにページ名を入れる。      my ($page, $key) = @_;
1298        my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1299  =item *      return $info{$key};
1300    }
1301  2001年2月25日、Version 1.6.1, 1.6.2。  
1302    sub set_info {
1303  差分機能のバグ修正。      my ($page, $key, $value) = @_;
1304  do_previewで'>'が扱えないバグを修正      my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1305  (ユーザからの指摘)。      $info{$key} = $value;
1306        my $s = '';
1307  =item *      for (keys %info) {
1308            $s .= "$_=$info{$_}\n";
1309  2001年2月22日、Version 1.6.0。      }
1310  差分機能を実装した。      $infobase{$page} = $s;
1311    }
1312  =item *  
1313    sub frozen_reject {
1314  2001年2月19日、Version 1.5.4。      my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);
1315  画像ファイルへのリンクは画像にしてみた。      my ($willbefrozen) = $form{myfrozen};
1316        if (not $isfrozen and not $willbefrozen) {
1317  =item *          # You need no check.
1318            return 0;
1319  2001年2月19日、Version 1.5.3。      } elsif (valid_password($form{mypassword})) {
1320  RecentChangesの中に削除したページがあるのをやめた。          # You are admin.
1321  use strict;で引っかかる部分を少し整理(完全ではない)。          return 0;
1322        } else {
1323  =item *          &print_error($resource{passworderror});
1324            return 1;
1325  2001年2月16日、Version 1.5.2。      }
1326  textareaに表示およびプレビューする前に < や > を &lt; や &gt; に変換した  }
1327  (do_preview, editpage, print_preview_buttons)。  
1328    sub valid_password {
1329  =item *      my ($givenpassword) = @_;
1330        my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
1331  2000年12月27日、Version 1.5.1。      if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1332  プレビュー画面を整理した。          return 1;
1333        } else {
1334  =item *          return 0;
1335        }
1336  2000年12月22日、Version 1.5.0。  }
1337  全体的にずいぶん書き直した。  
1338  一覧を別途作成するようにした(do_list)。  sub is_frozen {
1339  書き込む前に確認画面を出すようにした(do_preview)。      my ($page) = @_;
1340  テキストの書き方を編集画面に入れた(do_edit, do_reedit)。      if (&get_info($page, $info_IsFrozen)) {
1341  WhatsNew→RecentChanges、TopPage→FrontPageに変更した。          return 1;
1342        } else {
1343  =item *          return 0;
1344        }
1345  2000年12月20日、Version 1.1.0。  }
1346  tieを利用して、dbmopenが使えない場合でも動作するように修正。  
1347  利用者の1人である「極悪」さんから  sub do_comment {
1348  送っていただいたコードを元にしています。      my ($content) = $database{$form{mypage}};
1349        my $default_name;   ## this code does not strict.
1350  =item *      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1351        my $datestr = '[WEAK['.&get_now.']]';
1352  2000年9月5日、Version 1.0.2。      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1353   <body color=...> → <body bgcolor=...>      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1354  利用者からの指摘による。感謝。      if ($namestr =~ /^(?:>>)?[0-9]/) {
1355          $namestr = qq( ''$namestr'': );
1356  =item *      } elsif (length $namestr) {
1357          $namestr = qq( ''[[$namestr]]'': );
1358  2000年8月6日、Version 1.0.1を公開。      }
1359  C MAGAZINE(ソフトバンクパブリッシング)      my $anchor = &get_new_anchor_index ($content);
1360  2000年10月号連載記事向け公開版。      my $i = 1;  my $o = 0;
1361  [[ ]] の最後が「望」のようにシフトJISで      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1362  0x5Dになる場合の回避を行なった。        my $embed = $1;
1363          if ($i == $form{comment_index}) {
1364  =item *          if ($embed eq $embed_comment) {
1365              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1366  2000年8月5日、Version 1.0.0を公開。          } else {
1367              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1368  =item *          }
1369          }
1370  2000年7月23日、Version 0.82を公開。        $i++; $embed;
1371  編集時のリンクミス。      }ge;
1372  <textarea>の属性変更。      unless ($o) {
1373          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1374  =item *        $content .= "\n" unless $content =~ /\n$/s;
1375          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1376  2000年7月22日、Version 0.81を公開。      }
1377  ロゴを組み込む。      $form{__comment_anchor_index} = $anchor;
1378        if ($form{mymsg} || $form{myname}) {
1379  =item *          $form{mymsg} = $content;
1380            $form{mytouch} = 'on';
1381  2000年7月21日、Version 0.80を公開。          &do_write;
1382  PODをCGI中に書き込む。      } else {
1383            $form{mycmd} = 'read';
1384  =item *          &do_read;
1385        }
1386  2000年7月19日、Version 0.70を公開。  }
1387  '''イタリック'''や、--、---、>>、>>>などを実装。  
1388    sub get_new_anchor_index ($) {
1389  =item *      my $content = shift;
1390        my $anchor = 0;
1391  2000年7月18日、Version 0.60を公開。      $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1392  *太字*を''太字''に変更      $anchor + 1;
1393    }
1394  =item *  
1395    my $CommentIndex = 0;
1396  2000年7月17日、Version 0.50を公開。  sub embedded_to_html {
1397        my ($embedded) = @_;
1398  =item *      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1399          unless ($main::_EMBEDED) {
1400  2000年7月17日、さらにいろいろ追加する。          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1401            return <<"EOD";
1402  =item *  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1403        <input type="hidden" name="mycmd" value="comment">
1404  2000年7月16日、いろいろ追加。      <input type="hidden" name="mypage" value="$form{mypage}">
1405        <input type="hidden" name="myLastModified" value="$lastmodified">
1406  =item *      <input type="hidden" name="mytouch" value="on">
1407        <input type="hidden" name="comment_index" value="$CommentIndex">
1408  2000年7月15日、公開。      $embed_comment_Name_Prompt
1409        <input type="text" name="myname" value="" size="10" class="comment-name">
1410  =back      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1411        <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1412  =head1 TODO  </p></form>
1413    EOD
1414      - テキスト表示モード       } else {
1415      - Charsetを明示。          return <<"EOD";
1416      - textarea中の閉じタグ対応  <del><form action="$url_cgi" method="get">
1417      - メニューの英語表記付記      <input type="hidden" name="mycmd" value="read">
1418      - プレビューのボタンで、mymsgをinputのvalueに入れているが、改行をそのままvalueにいれてはいけないのではないか。      <input type="hidden" name="mypage" value="$form{mypage}">
1419      - 「再編集」の機能はブラウザの back で充分ではないか。プレビューはもっとシンプルに。      $embed_comment_Name_Prompt
1420      - ページタイトル(Wikiname)が検索にかかるようにする。      <input type="text" name="myname" value="" size="10" disabled="disabled">
1421      - InterWiki風の機能「URLを隠しつつ、リンクを張る」      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1422        <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1423  =head1 作者  </form></del>
1424    EOD
1425      Copyright (C) 2000 by Hiroshi Yuki.      }
1426      結城浩 <hyuki@hyuki.com>    } elsif ($embedded =~ /$embed_command{searched}/) {
1427      http://www.hyuki.com/      return get_search_result ($1, -match_myself => 1);
1428      http://www.hyuki.com/yukiwiki/      # Walrus add (5) start
1429        } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1430  質問、意見、バグ報告は hyuki@hyuki.com にメールしてください。          $_ = &make_interwiki_box($1, $2);
1431            return ($_) ? $_ : $embedded;
1432  =head1 配布条件      # Walrus add (5) end
1433      } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1434  YukiWikiは、      my ($name, $r) = ($1, '');
1435  GNU General Public Licenseにて公開します。      if ($main::_EMBEDED != 1) {
1436          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1437  YukiWikiはフリーソフトです。        $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1438  ご自由にお使いください。        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1439  自分好みのYukiWikiが作れるようにシンプルにしてあります。          $main::_EMBEDED = 1;
1440            $r = &text_to_html ($content, content_format => $cf);
1441  =head1 謝辞          $main::_EMBEDED = 0;
1442          } elsif (length $content) {
1443  本家のWikiWikiを作ったCunningham & Cunningham, Inc.に          $r = "<pre>@{[&escape ($content)]}</pre>";
1444  感謝します。        } else {
1445            $r = &text_to_html ("[INS[\nヒ荀盪、゙、、ニ、、、 [[$name]] 、マ、゙、タス、ォ、、ニ、、、゙、サ、。」\n]INS]\n", content_format => 'SuikaWiki/0.9');
1446  YukiWikiを楽しんで使ってくださる        }
1447  ネット上の方々に感謝します。      } else {    ## nested #EMBED
1448          $r = &text_to_html ("[INS[\n[[$name]] 、ホヒ荀盪、゚、マ (ニ、チネ、、ヌ、、、、ホ、ヌ) イキ隍オ、、゙、サ、、ヌ、キ、ソ。」\n]INS]\n", content_format => 'SuikaWiki/0.9');
1449  YukiWikiのロゴをデザインしてくださった橋本礼奈さん      }
1450  http://city.hokkai.or.jp/~reina/      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>);
1451  に感謝します。    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1452        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1453  tieを使った版の元になるコードを送ってくださった    } else {
1454  「極悪」さんに感謝します。      return $embedded;
1455      }
1456  =head1 参照リンク  }
1457    
1458  =over 4  sub do_wikiform {
1459        my $content = $database{$form{mypage}};
1460  =item *      my $anchor = &get_new_anchor_index ($content);
1461        for my $t (qw/form_template form_option/) {
1462  YukiWikiホームページ          unless ($fmt{$t}) {
1463  http://www.hyuki.com/yukiwiki/              $fmt{$t} = Message::Util::Formatter->new;
1464                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1465  =item *                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1466                }
1467  本家のWikiWiki          }
1468  http://c2.com/cgi/wiki?WikiWikiWeb      }
1469        my $write = 0;
1470  =item *      my $i = 1;
1471        $content =~ s{$embed_command{form}}{
1472  本家のWikiWikiの作者(Cunningham & Cunningham, Inc.)          my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1473  http://c2.com/          if (($wfname && $wfname eq $form{wikiform_targetform})
1474                || $i == $form{wikiform_index}) {
1475  =item *              $template =~ s/\\(.)/$1/g;
1476                $option =~ s/\\(.)/$1/g;
1477  YukiWikiのロゴデザインをしてくださった橋本礼奈さんのページ              my $param = bless {}, 'SuikaWiki::Plugin';
1478  http://city.hokkai.or.jp/~reina/              $param->{page} = $form{mypage};
1479                $param->{form_index} = $i;
1480  =back              $param->{form_name} = $wfname;
1481                $param->{anchor_index} = $anchor;
1482  =cut              $param->{argv} = \%form;
1483                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1484                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1485                $fmt{form_option}->replace ($option, $param);
1486                my $t = 1;
1487                for (@{$param->{require}||[]}) {
1488                  (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1489                }
1490                $t = $fmt{form_template}->replace ($template, $param) if $t;
1491                if (length $t) {
1492                    if ($param->{output}->{reverse}) {
1493                        $embed .= "\n" . $t;
1494                    } else {
1495                        $embed = $t . "\n" . $embed;
1496                    }
1497                    $write = 1;
1498                    $form{__comment_anchor_index} = $anchor
1499                      if $param->{anchor_index_};  ## $anchor is used!
1500                }
1501                $form{__wikiform_anchor_index} = $i;
1502                undef $form{wikiform_targetform};  ## make sure never to match
1503                undef $form{wikiform_index};       ## with WikiForm in rest of page
1504            }
1505            $i++; $embed;
1506        }ge;
1507        unless ($write) {
1508          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1509          #$content .= "\n" unless $content =~ /\n$/s;
1510          #
1511        }
1512        if ($write) {
1513            $form{mymsg} = $content;
1514            $form{mytouch} = 'on';
1515            &do_write;
1516        } else {
1517            $form{mycmd} = 'read';
1518            &do_read;
1519        }
1520    }
1521    
1522    
1523    # Walrus add (5) start
1524    sub do_interwiki_box {
1525        my $remoteurl = $interwiki{$form{'myintername'}};
1526        if ($remoteurl) {
1527            $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;
1528            print "Location: $remoteurl\n\n";
1529            exit(1);
1530        } else {
1531            &do_read;
1532        }
1533    }
1534    # Walrus add (5) end
1535    
1536    # Walrus add (5) start
1537    sub make_interwiki_box {
1538        my ($localname, $intername) = @_;
1539        my %ignoretype = (
1540            'box'      => 'text',
1541            'text'     => 'text',
1542            'pass'     => 'password',
1543            'password' => 'password'
1544        );
1545        my $converted = ($ignoretype{$localname}) ? <<EOD : undef;
1546    <form action="$url_cgi" method="post">
1547        <input type="hidden" name="mycmd" value="interwikibox">
1548        <input type="hidden" name="mypage" value="$form{mypage}">
1549        <input type="hidden" name="myintername" value="$intername">
1550        $intername:
1551        <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">
1552        <input type="submit" value="Submit">
1553    </form>
1554    EOD
1555    }
1556    # Walrus add (5) end
1557    
1558    sub code_convert {
1559        my ($contentref, $code) = (shift, shift || $kanjicode);
1560        $code = 'jis' if $code =~ /iso/;
1561        $code = 'euc' if $code =~ /euc/;
1562        $code = 'sjis' if $code =~ /shift/;
1563        $code = 'utf8' if $code =~ /utf/;
1564        &Jcode::convert($contentref, $code);       # for Jcode.pm
1565    #    &jcode::convert($contentref, $code);       # for jcode.pl
1566        &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';
1567        return $$contentref;
1568    }
1569    
1570    sub test_convert {
1571        my $txt = &text_to_html(<<"EOD", toc=>1);
1572    *HEADER1
1573    **HEADER1-1
1574    -ITEM1
1575    -ITEM2
1576    -ITEM3
1577    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1578    PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1579    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1580    
1581    PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1582    PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1583    PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1584    **HEADER1-2
1585    :TERM1:DESCRIPTION1 AND ''BOLD''
1586    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1587    PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1588    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1589    :TERM2:DESCRIPTION2
1590    :TERM3:DESCRIPTION3
1591    ----
1592    *HEADER2
1593    **HEADER2-1
1594    http://www.hyuki.com/
1595    **HEADER2-2
1596    
1597    [[YukiWiki2]]
1598    
1599    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1600    PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1
1601    PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1602    >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1603    >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1604    >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1605    
1606    LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0
1607    
1608    >LEVEL1
1609    >LEVEL1
1610    >LEVEL1
1611    >>LEVEL2
1612    >>LEVEL2
1613    >>LEVEL2
1614    >>>LEVEL3
1615    -HELLO-1
1616    --HELLO-2
1617    (HELLO-2, HELLO-2, HELLO-2)
1618    ---HELLO-3
1619    (HELLO-3, HELLO-3, HELLO-3)
1620    --HELLO-2
1621    ---HELLO-3
1622    --HELLO-2
1623    ---HELLO-3
1624    >>>LEVEL3
1625    >>>LEVEL3
1626    >>>LEVEL3
1627    >>>LEVEL3
1628    EOD
1629        print $txt;
1630        exit;
1631    }
1632    
1633    sub do_diff {
1634        if (not &is_editable($form{mypage})) {
1635            &do_read;
1636            return;
1637        }
1638        &open_diff;
1639        my $title = $form{mypage};
1640        &print_header($title, -noindex => 1);
1641        $_ = &escape($diffbase{$form{mypage}});
1642        &close_diff;
1643        print qq(<h3>$resource{difftitle}</h3>);
1644        print qq($resource{diffnotice});
1645        print qq(<pre class="diff">);
1646        foreach (split(/\n/, $_)) {
1647            if (/^\+(.*)/) {
1648                print qq(<b class="added">$1</b>\n);
1649            } elsif (/^\-(.*)/) {
1650                print qq(<s class="deleted">$1</s>\n);
1651            } elsif (/^\=(.*)/) {
1652                print qq(<span class="same">$1</span>\n);
1653            } else {
1654                print qq|??? $_\n|;
1655            }
1656        }
1657        print qq(</pre>);
1658        print qq(<hr>);
1659        &print_footer($title);
1660    }
1661    
1662    sub do_rss {
1663        my $rss = new Yuki::RSS(
1664            version => '1.0',
1665            encoding => $charset,
1666        );
1667        $rss->channel(
1668            title => $modifier_rss_title,
1669            link  => $modifier_rss_link,
1670            description => $modifier_rss_description,
1671        );
1672        my $recentchanges = $database{$RecentChanges};
1673        my $count = 0;
1674        foreach (split(/\n/, $recentchanges)) {
1675            last if ($count >= 15);
1676            /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/;    # date format.
1677            my $title = &unarmor_name($1);
1678            my $escaped_title = &escape($title);
1679            my $link = $modifier_rss_link . '?' . &encode($title);
1680            my $description = $escaped_title . &escape(&get_subjectline($title));
1681            $rss->add_item(
1682                title => $escaped_title,
1683                link  => $link,
1684                description => $description,
1685            );
1686            $count++;
1687        }
1688        # print RSS information (as XML).
1689        print <<"EOD"
1690    Content-type: text/xml
1691    
1692    @{[$rss->as_string]}
1693    EOD
1694    }
1695    
1696    sub is_exist_page {
1697        my ($name) = @_;
1698        if ($use_exists) {
1699            return exists($database{$name});
1700        } else {
1701            return $database{$name};
1702        }
1703    }
1704    
1705    sub __get_database ($) { $database{ $_[0] } }
1706    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1707    
1708    package wiki::referer;
1709    sub add ($$) {
1710      my $page = shift;
1711      my $uri = shift;
1712      unless (ref $uri) {
1713        require URI;
1714        $uri = URI->new ($uri);
1715        ## Some schemes do not have query part.
1716        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1717        $uri->fragment (undef);
1718      }
1719      $uri = $uri->canonical;
1720      return unless $uri;
1721      for my $regex (&get_dont_record) {
1722        return if $uri =~ /$regex/;
1723      }
1724      my %list = get ($page);
1725      $list{ $uri }++;
1726      set ($page, \%list);
1727    }
1728    sub get ($) {
1729      my $page = shift;
1730      split /"/, main::get_info ($page, 'Referer');
1731    }
1732    sub set ($%) {
1733      my $page = shift;
1734      my $list = shift;
1735      main::set_info ($page, Referer => join '"', %$list);
1736    }
1737    
1738    sub get_dont_record () {
1739      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1740      grep !/^#/,
1741      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1742    }
1743    sub get_site_name () {
1744      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1745      my @item;
1746      for (@lines) {
1747        next if /^#/;
1748        my ($uri, $name) = split /\s+/, $_, 2;
1749        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1750        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1751        push @item, [$uri, qq(q($name))];
1752      }
1753      @item;
1754    }
1755    
1756    sub list_html ($) {
1757      my $page = shift;
1758      my %list = get ($page);
1759      my $r = '';
1760      my @name = get_site_name;
1761      for my $uri (sort keys %list) {
1762        my $title;
1763        for my $item (@name) {
1764          if ($uri =~ /$item->[0]/) {
1765            $title = $uri;
1766            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1767              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1768            last;
1769          }
1770        }
1771        my $euri = main::escape ($uri);
1772        if ($title) {
1773          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);
1774        } else {
1775          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1776        }
1777      }
1778      $r ? qq(<ul>$r</ul>\n) : '';
1779    }
1780    
1781    sub __decode ($) {
1782      my $s = shift;
1783      $s =~ tr/+/ /;
1784      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1785      main::code_convert (\$s);
1786    }
1787    
1788    package wiki::useragent;
1789    
1790    sub add ($) {
1791      my $s = shift;
1792      return unless length $s;
1793      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1794      my %ua;
1795      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1796        if (/^-\[(\d+)\] (.+)$/) {
1797          my ($t, $n) = ($1, $2);
1798          $n =~ tr/\x0A\x0D//d;
1799          $ua{$n} = $t;
1800        }
1801      }
1802      $ua{$s}++;
1803      my $s = qq(#?SuikaWiki/0.9\n);
1804      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1805        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1806      }
1807      &main::__set_database ('WikiUserAgentList' => $s);
1808    }
1809    
1810    package SuikaWiki::Plugin;
1811      our %List;
1812    
1813    sub escape ($$) { main::escape ($_[1]) }
1814    sub unescape ($$) { main::unescape ($_[1]) }
1815    sub encode ($$) { main::encode ($_[1]) }
1816    sub decode ($$) { main::decode ($_[1]) }
1817    sub __get_datetime ($) { main::get_now () }
1818    
1819    sub regist ($@) {
1820        my $pack = shift;
1821        for (@_) {
1822            push @{$List{$_}}, $pack;
1823        }
1824    }
1825    
1826    use SuikaWiki::Plugin::WikiFormBasic;
1827    
1828    1;
1829    __END__
1830    =head1 NAME
1831    
1832    wiki.cgi - This is YukiWiki, yet another Wiki clone.
1833    
1834    =head1 DESCRIPTION
1835    
1836    YukiWiki is yet another Wiki clone.
1837    
1838    YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).
1839    YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),
1840    and some embedded commands (such as [[#comment]] to add comments).
1841    
1842    Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.
1843    
1844    =head1 AUTHOR
1845    
1846    Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/
1847    
1848    =head1 LICENSE
1849    
1850    Copyright (C) 2000-2002 by Hiroshi Yuki.
1851    
1852    This program is free software; you can redistribute it and/or
1853    modify it under the same terms as Perl itself.
1854    
1855    =cut

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.34

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24