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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24