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

Diff of /suikawiki/script/wiki.cgi

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

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24