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

Diff of /suikawiki/script/wiki.cgi

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

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24