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

Diff of /suikawiki/script/wiki.cgi

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

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24