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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24