/[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.48 by w, Fri Jan 3 08:25:31 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2  use lib "../lib";  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
3  use CGI::Carp 'fatalsToBrowser';  #
4  use Algorithm::Diff qw(traverse_sequences);  # This program is free software; you can redistribute it and/or
5  # use strict;  # modify it under the same terms as Perl itself.
6  #  
7  # yukiwiki.cgi - Yet another WikiWikiWeb clone.  use strict;
8  #  use lib qw(./lib);
9  # Copyright (C) 2000,2001 by Hiroshi Yuki.  use CGI::Carp qw(fatalsToBrowser);
10  # <hyuki@hyuki.com>  our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11  # http://www.hyuki.com/yukiwiki/  
12  #  require 'wikidata/suikawiki-config.ph';
13  # This program is free software; you can redistribute it and/or modify  use Fcntl;
14  # it under the terms of the GNU General Public License as published by  ##############################
15  # the Free Software Foundation; either version 2 of the License, or  my %fmt;        ## formatter objects
16  # (at your option) any later version.  my %embed_command = (
17  #          searched        => '^\[\[#searched:([^\]]+)\]\]$',
18  # This program is distributed in the hope that it will be useful,          form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19  # but WITHOUT ANY WARRANTY; without even the implied warranty of  );
20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21  # GNU General Public License for more details.  our (%PageName,$kanjicode,$lang,%ViewDefinition);
22  #  
23  # $Id$  ##############################
24  ##############################  my %form;
25  my $version = "1.6.6";  our %database;
26  ##############################  our $database = bless {}, 'wiki::dummy';
27  # 単独テストのときには 1 にする。  my %interwiki;
28  my $testing = 0;  ##############################
29  ##############################  my %page_command = (
30  # 漢字ライブラリ      $PageName{RssPage} => 'rss',
31  my $jcodelib = 'jcode.pl';  );
32  ##############################  my %command_do = (
33  # 保存・表示の漢字コード      read => \&do_read,
34  my $kanjicode = 'euc';     # 'sjis' 'euc'      TEXT_CSS => \&do_output_css,
35  my $charset = 'euc-jisx0213';  # 'Shift_JIS' 'EUC-JP'      edit => \&do_view,
36  ##############################      adminchangepassword => \&do_adminchangepassword,
37  # dbmopenが使えるなら1、使えないなら0      write => \&do_write,
38  my $dbmopen = 0;      searchform => \&do_searchform,
39  ##############################      comment => \&do_comment,
40  # データベース名(.pag, .dir, .dbなどは不要)      RandomJump  => \&do_random_jump,
41  # $dbmopen = 1のときはデータベース名、      rss => \&do_rss,
42  # $dbmopen = 0のときはディレクトリ名になる。      diff => \&do_diff,
43  my $dbname = './wikidata';      wikiform    => \&do_wikiform,
44  my $diffdbname = './wikidiff';      map => \&do_view,
45  ##############################  );
46  # 修正者の氏名(自由に変更してください)  my $UA = '';  ## User agent name
47  my $modifier = 'suika';  $| = 1;
48  ##############################  ##############################
49  # 修正者のWebページ(自由に変更してください)  
50  my $modifierlink = 'http://suika.fam.cx/';  sub main {
51  ##############################      $UA = $main::ENV{HTTP_USER_AGENT};
52  # このページのURL      &open_db;
53  my $thisurl = 'wiki';      &init_form;
54  ##############################      if ($command_do{$form{mycmd}}) {
55  # 開始ページ名          &{$command_do{$form{mycmd}}};
56  my $toppage = 'HomePage';      } else {
57  ##############################          &{$command_do{read}};
58  # 最終更新ページ名      }
59  my $whatsnew = 'RecentChanges';      &close_db;
60  ##############################  }
61  # 最終更新に掲載するページ数  
62  my $maxnew = 50;  sub do_read {
63  ##############################    my $content = $database{$form{mypage}};
64  # アイコンファイル名(カラー版)    my $lm = $database->mtime ($form{mypage});
65  my $iconfile = '';    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
66  ##############################    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
67  # アイコンファイル名(モノクロ版)    my @toc;
68  # my $iconfile = '';      my $cf = 'SuikaWiki/0.9';
69  ##############################      ## Should be support at least:
70  # ページを変更したときにtouchするファイル(''なら何もしない)      ## - 'SuikaWiki/0.9' CRLF
71  my $touchfile = 'touch.txt';      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
72  ##############################      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
73  # プレビュー用の背景色      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
74  my $preview_color = '#FFCCCC';      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
75  ##############################        my $expires = time;
76  # 全ページのスタイル        if ($cf =~ /interactive="yes"/) {
77  my $style = <<'EOD';          $lm = $expires;
78  pre, dl, ul, ol, p, blockquote { line-height:120%; }        } else {
79  a { text-decoration: none; }          $expires += 120;
80  a:link { color: #0000FF; background-color: #FFFFFF; }        }
81  a:visited { color: #9900CC; background-color: #FFFFFF; }        &print_header ($form{mypage}, -last_modified => $lm, -expires => $expires,
82  a:hover { text-decoration: underline; }          -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
83  EOD        &print_content ($content, content_format => $cf, last_modified => $lm,
84  ##############################          -toc => \@toc);
85  # テキスト入力部分の大きさ        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$database->meta (IsFrozen => $form{mypage});
86  my $cols = 80;      } else {
87  my $rows = 20;        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
88  ##############################        print "<pre>@{[&escape($content)]}</pre>";
89  my %form = ();      }
90  my %database = ();      &load_formatter ('view');
91  my %diffbase = ();      print $fmt{view}->replace ($ViewDefinition{read} => bless {param => \%form, page => $form{mypage}, toc => \@toc, formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
92  my $diff_text = '';      &print_footer ($form{mypage}, $lm);
93  my @diff_added = ();  }
94  my @diff_deleted = ();  
95  my $msgrefA;  sub do_output_css {
96  my $msgrefB;    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
97  ##############################    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
98  # 編集不可ページ名一覧    my $content = $database{$form{mypage}};
99  my @uneditable = ( $whatsnew );    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
100  ##############################      my $lm = gmtime $database->mtime ($form{mypage});
101  # リンク用の正規表現      print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
102  # YukiWikiのリンクは2種類ある。      print "Last-Modified: $lm\n";
103  #      print "Expires: @{[scalar gmtime time+3600]}\n";    ## TODO: don't use asctime
104  # (1) WikiName (RecentChangesとかFrontPageのようなもの)      print "\n";
105  # (2) BracketName ([[結城浩]]とか[[トラブルシュート]]のようなもの)      print $content;
106  #    } else {
107  # ※シフトJISの2バイト目には ']' が来うるので、      print "Status: 406 Unsupported Media Type\n";
108  # 文字']'を1つ多くとるようにしている。      &print_header('WikiPageIsNotCSS', -noindex => 1);
109  #      &print_content($database{WikiPageIsNotCSS});
110  my $WikiName = '([A-Z][a-z]+([A-Z][a-z]+)+)';      &print_footer('WikiPageIsNotCSS');
111  my $BracketName = '\[\[([^>\x09]+?\]?)\]\]';    }
112    }
113  # アイコン部分のタグ  
114  my $IconTag = ''; #<<"EOD";  sub id_and_name ($) {
115  #<a href="http://www.hyuki.com/yukiwiki/"><img src="$iconfile"      my $name = shift;
116  # border="0" width="80" height="80" alt="[YukiWiki]" /></a>      if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
117  #EOD        qq{id="$name"><a name="$name"></a};
118        } else {
119  require "$jcodelib";          qq{id="$name"};
120        }
121  &init_form($kanjicode);  }
122    
123  if ($testing) {  sub do_view {
124      %form = (      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
125          # 'mycmd' => 'write',      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
126          'mycmd' => 'read',      &print_header($form{mypage}, -noindex => 1, -expires => time+60);
127          #'mycmd' => 'search',      &load_formatter ('view');
128          #'mycmd' => 'edit',      my $view = $form{mycmd};
129          'mymsg' => <<"EOD",      if ($view eq 'edit') {
130  はじめまして。        $view = 'adminedit' if $form{admin};
131  これからいろいろ書き込みますね。      } elsif ($view =~ /[^0-9A-Za-z]/) {
132  LinkPageも見てください。        $view = 'view'
133  TestPageはどうでしょうか。      }
134  どうぞよろしく。      print $fmt{view}->replace ($ViewDefinition{$view} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
135  http://www.hyuki.com/      &print_footer($form{mypage});
136  [[結城浩]]  }
137  EOD  
138          'mypage' => '<結城浩>',  sub do_adminchangepassword {
139          'myword' => '結',      if ($form{mynewpassword} ne $form{mynewpassword2}) {
140          # '3C8C8B8FE98D5F3E' => '',          &print_error(&Resource('Error:PasswordMismatch'));
141          # 'TestPage' => '',      }
142      );      my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
143  }      if ($validpassword_crypt) {
144  &main;          if (not &valid_password($form{myoldpassword})) {
145  exit(0);              &print_error(&Resource('Error:PasswordIsIncorrect'));
146            }
147  # メイン      }
148  sub main {      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
149      &normalize_form;      my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
150      if ($dbmopen) {      my $salt1 = $token[(time | $$) % scalar(@token)];
151          if (!dbmopen(%database, $dbname, 0666)) {      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
152              &print_error("(dbmopen) $dbname が作れません。");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
153          }      $database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted);
154      } else {  
155          if (!tie(%database, "YukiWikiDB", $dbname)) {      &print_header('CompletedSuccessfully', -noindex => 1);
156              &print_error("(tie error)");      &print_message(&Resource('Error:PasswordIsChanged'));
157          }      &print_footer('CompletedSuccessfully');
158      }  }
159    
160      # myspecial対応  sub valid_password ($) {
161      foreach (keys %form) {      my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage});
162          if (/^myspecial_(.*)/) {      return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
163              $form{mycmd} = $1;  }
164              last;  
165          }  sub do_write {
166      }      if (&frozen_reject()) {
167            return;
168      if ($form{mycmd} eq 'read') {      }
169          &do_read;  
170      } elsif ($form{mycmd} eq 'preview') {      if (not &is_editable($form{mypage})) {
171          &do_preview;          &print_header($form{mypage}, -noindex => 1);
172      } elsif ($form{mycmd} eq 'write') {          &print_message(&Resource('Error:ThisPageIsUneditable'));
173          &do_write;          &print_footer($form{mypage});
174      } elsif ($form{mycmd} eq 'edit') {          return;
175          &do_edit;      }
176      } elsif ($form{mycmd} eq 'reedit') {  
177          &do_reedit;      ## Check confliction
178      } elsif ($form{mycmd} eq 'search') {      if ($form{myLastModified} ne $database->mtime ($page)) {
179          &do_search;        &print_header($page, -noindex => 1);
180      } elsif ($form{mycmd} eq 'list') {        &load_formatter ('view');
181          &do_list;        print $fmt{view}->replace ($ViewDefinition{-conflict} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
182      } elsif ($form{mycmd} eq 'diff') {        &print_footer($page);
183          &do_diff;        return;
184      } else {      }
185          $form{mypage} = $toppage;  
186          &do_read;      if ($form{mymsg}) {
187      }          if ($form{mytouch} || !ref $database) {
188      if ($dbmopen) {            $database{$form{mypage}} = $form{mymsg};
189          dbmclose(%database);          } else {
190      } else {            $database->STORE ($form{mypage} => $form{mymsg}, -touch => 0);
191          untie(%database);          }
192      }          $database->meta (IsFrozen => $form{mypage} => 0 + $form{myfrozen});
193  }          my $fragment = '';
194            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
195  # ページの表示          if ($form{__comment_anchor_index}) {
196  sub do_read {              $fragment .= qq(#anchor-$form{__comment_anchor_index});
197      my $page_name = $form{mypage};          } elsif ($form{__wikiform_anchor_index}) {
198      my $percent_name = &encode_percent($page_name);              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
199      &print_header($page_name);          }
200      print qq|<h1>$IconTag<a href="$thisurl?mycmd=search;myword=$percent_name">$page_name</a></h1>\n|;          &print_header('CompletedSuccessfully', -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
201      &print_toolbar($page_name);          &print_message(&Resource('Error:SavedSuccessfully'));
202      print &convert_html(&get_page($page_name));          &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
203      &print_footer;          &print_footer('CompletedSuccessfully');
204  }      } else {
205            delete $database{$form{mypage}};
206  # ページの編集          &print_header($form{mypage}, -noindex => 1);
207  sub do_edit {          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
208      if (not &is_editable($form{mypage})) {          &print_footer($form{mypage});
209          # 編集不可ページは表示のみ      }
210          &do_read;  }
211          return;  
212      }  sub _compatible_options () {
213      &editpage(&get_page($form{mypage}));    (use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0));
214  }  }
215    
216  # ページの再編集  sub get_search_result ($;%) {
217  sub do_reedit {    my $word = lc shift;
218      if (not &is_editable($form{mypage})) {    my %option = @_;
219          # 編集不可ページは表示のみ    my @r;
220          &do_read;    foreach my $page (keys %database) {
221      } else {      next if !$option{-match_myself} && ($page eq $word);
222          &editpage($form{mymsg});      my $content = lc $database{$page};
223      }      if (index (lc $page, $word) > -1) {
224  }        my $c = $content =~ s/\Q$word\E//g;
225          push @r, [$page, $c+20];
226  sub editpage {      } elsif (index ($word, lc $page) > -1) {
227      my $page_msg = shift;        my $c = $content =~ s/\Q$word\E//g;
228      my $page_name = $form{mypage};        push @r, [$page, $c+10];
229      my $digest = &calc_message_digest($page_msg);      } elsif (my $c = $content =~ s/\Q$word\E//g) {
230      &print_header($page_name);        push @r, [$page, $c];
231      print qq|<h1>$IconTag${page_name}の編集</h1>\n|;      }
232      &print_toolbar($page_name);    }
233      $page_msg = &escape($page_msg);    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
234      print <<"EOD";    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
235  <form action="$thisurl" method="post">    $r = qq|<ul class="search-result">$r</ul>| if $r;
236  <!--<input type="hidden" name="mycmd" value="preview">-->    wantarray? ($r, scalar @r): $r;
237  <input type="hidden" name="mypage" value="$page_name">  }
238  <input type="hidden" name="mydigest" value="$digest">  
239  <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$page_msg</textarea><br>  sub do_random_jump {
240  <input type="submit" name="myspecial_preview" value="確認">    my @list = keys %database;
241  <input type="submit" name="myspecial_write" value="確認せず変更">    my $name = &encode ($list[rand @list]);
242  </form>    my $scheme = 'http';
243  <hr>    $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
244  <h3>テキスト整形のルール</h3>    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
245      print "\n";
246  <p>通常は入力した文字がそのまま出力されますが、  }
247  以下のルールに従ってテキスト整形を行うことができます。</p>  
248    sub print_error {
249  <ul>      my ($msg) = @_;
250  <li>      &print_header($PageName{ErrorPage}, -noindex => 1);
251  空行は段落の区切りとなります。      print qq(<p><strong class="error">$msg</strong></p>);
252        &print_footer($PageName{ErrorPage});
253  <li>      exit(0);
254  HTMLのタグは書けません。  }
255    
256  <li>  sub print_header ($;%) {
257  ''強調''のようにシングルクォート二つではさむと、強調になります。      my ($page, %option) = @_;
258        my @head;
259  <li>      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
260  '''更に強調'''のようにシングルクォート三つではさむと、更に強調になります。      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
261        if ($option{-goto}) {
262  <li>        if ($UA =~ m#Opera|MSIE 2\.#) {
263  ----のようにマイナス4つがあると、水平線になります。            ## WARNING: This code may output unsafe HTML document if
264              ##          $option{-goto} is not clean.
265  <li>            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
266  *を行頭に書くと大見出しになります。            print qq{Refresh: 0; url=$option{-goto}\n};
267              push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
268  <li>        } else {
269  **を行頭に書くと小見出しになります。            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
270              print qq{Refresh: 0; url="$option{-goto}"\n};
271  <li>            push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
272  -を行頭に書くと箇条書きになります。- -- --- の3レベルがあります。        }
273        }
274  <li>      print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
275  :を行頭に書くと用語と解説文が作れます。      if ($option{-expires}) {
276          print qq{Expires: @{[scalar gmtime $option{-expires}]}\n};
277  <pre>      }
278      :用語1:いろいろ書いた解説文1      if ($UA =~ m#Mozilla/2#) {
279      :用語2:いろいろ書いた解説文2          my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
280      :用語3:いろいろ書いた解説文3          print qq{Content-Type: $ct\n};
281  </pre>          push @head, qq{<meta http-equiv="content-type" content="$ct">};
282        } elsif ($UA =~ m#Infomosaic#) {
283  <li>          print qq{Content-Type: text/html\n};
284  http://www.hyuki.com/ のようなURLは自動的にリンクになります。      } else {
285            print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
286  <li>      }
287  YukiWikiのように大文字小文字を混ぜた英文字列を書くと、      push @head, qq(<title>@{[&escape($page)]}</title>);
288  YukiWikiのページ名になります。      if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) {
289          push @head, qq(<link rel="stylesheet" type="text/css").
290  <li>                    qq( href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.$database->mtime ($PageName{DefaultStyleForHTML}))]}");
291  [[結城浩]]のように二重の大かっこ[[ ]]でくくった文字列を書くと、      }
292  YukiWikiのページ名になります。      push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
293  大かっこの中にはスペースを含めてはいけません。      my ($Links, $links) = &make_navigate_links ($page);
294  日本語も使えます。      #print $Links;      ## Link: fields
295        $links = join "\n", (@head, $links);
296  <li>      print <<"EOD";
297  行頭がスペースで始まっていると、  Content-Language: $lang
298  その段落は整形済み扱われます。  Content-Style-Type: text/css
299  プログラムを書き込むときに使うと便利です。  
300    <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
301  <li>  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
302  &gt; を行頭に書くと、  <html lang="$lang" class="$option{body_class}">
303  引用文が書けます。  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
304  &gt; の数が多いとインデントが深くなります(3レベルまで)。  $links
305    </head>
306  </ul>  <body class="$option{body_class}">
307  EOD  EOD
308      &print_footer;      &print_navigate_links ($page);
309  }      print <<EOD;
310    <h1 class="header">@{[&escape($page)]}</h1>
311  # ページの検索  EOD
312  sub do_search {  }
313      if ($form{myword}) {  
314          &print_header('検索結果');  sub get_charset_name ($;%) {
315          print qq|<h1>$IconTag$form{myword}の検索結果</h1>\n|;      my ($charset, %option) = (lc shift, @_);
316          &print_toolbar();      if ($charset =~ 'euc') {
317          print qq|<ul>\n|;          $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
318          my $count = 0;      } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
319          foreach my $page_name (sort keys %database) {    # sortするのは無謀かな          $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
320              if ($database{$page_name} =~ /\Q$form{'myword'}\E/) {      } elsif ($charset =~ 'jis') {
321                  my $encoded = &encode_percent($page_name);          $charset = 'iso-2022-jp';
322                  print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|;      }
323                  $count++;      $charset;
324              }  }
325          }  
326          print qq|</ul>\n|;  sub print_navigate_links (@) {
327          if ($count > 0) {    my ($page) = @_;
328              print qq|<p><strong>$form{myword}</strong>を含むページは、上に示す<strong>$count</strong> ページです。</p>\n|;    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
329          } else {    my $cookedpage = &encode($page);
330              print qq|<p><strong>$form{myword}</strong>を含むページは見つかりません。</p>\n|;    print <<EOH;
331          }  <div class="tools">
332      } else {      @{[ $editable
333          &print_header('単語検索');          ? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | )
334          print qq|<h1>$IconTag単語検索</h1>\n|;          : qq()
335          &print_toolbar();      ]}
336      }      <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd" title="@{[&Resource('ViewThisPageLong',escape=>1)]}">@{[&Resource('ViewThisPage',escape=>1)]}</a> |
337      print <<"EOD";      <a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
338  <p>      <a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
339  <form action="$thisurl" method="post">      <a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
340  <input type="hidden" name="mycmd" value="search">      <a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
341  <input type="text" name="myword" size="20" value="$form{myword}">      <a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
342  <input type="submit" value="単語検索">      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink" title="@{[&Resource('GoSomewhereLong',escape=>1)]}">@{[&Resource('GoSomewhere',escape=>1)]}</a> |
343  </form>      <a href="$url_cgi?$PageName{RecentChanges}" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
344  </p>  </div>
345  EOD  EOH
346      &print_footer;  }
347  }  
348    sub make_navigate_links ($) {
349  # ページの一覧      my $page = shift;
350  sub do_list {      my @link;
351      &print_header('ページ一覧');      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page);
352      print qq|<h1>$IconTag ページ一覧</h1>\n|;      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;admin=1;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);
353      &print_toolbar();      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')};
354      print qq|<ul>\n|;      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
355      foreach my $page_name (sort keys %database) {    # sortするのは無謀かな      push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
356          my $encoded = &encode_percent($page_name);      push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')};
357          print qq|<li><a href="$thisurl?mycmd=read;mypage=$encoded">$page_name</a>\n|      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
358      }      push @link, {rel=>'News', href=>"$url_cgi?$PageName{RecentChanges}", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
359      print qq|</ul>\n|;      push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
360      &print_footer;      push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
361  }      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
362        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
363  # プレビュー      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToLink')};
364  sub do_preview {      push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToEditLink')};
365      my $page_name = $form{mypage};      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
366      my $escapedmsg = &escape($form{mymsg});      push @link, {rel=>'history', href=>$uri{cvs_wikipage}.do{my $s=$page;$s=~s/(.)/sprintf '%02X', ord $1/ges;$s}.'.txt', title=>&Resource('ViewHistoryOfThisPageLink'),hreflang=>'en'} if $uri{cvs_wikipage};
367      &print_header($page_name);      push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'} if $wiki::diff::UseDiff;
368      print qq|<h1>$IconTag${page_name}のプレビュー</h1>\n|;      push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
369      &print_toolbar($page_name);      my ($Links, $links) = ('', '');
370      # local $percent_name = &encode_percent($page_name);      for my $e (@link) {
371      print qq|<p>以下のプレビューを確認して、よければページ下部のボタンで更新してください。</p>\n|;          $links .= qq(<link);
372      if ($form{mymsg}) {          $Links .= qq(Link: <$e->{href}>);
373          print qq|<table width="100%" bgcolor="$preview_color" ><tr><td>\n|;          for my $attr (qw/rel rev href title class type hreflang charset/) {
374          # print &convert_html($escapedmsg);              $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
375          print &convert_html($form{mymsg});          }
376          print qq|</td></tr></table>\n|;          for my $attr (qw/rel rev title/) {
377      } else {              $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
378          print qq|<p>(ページの内容は空です。更新するとこのページは<strong>削除</strong>されます。)</p>\n|;          }
379      }          $links .= qq(>\n);
380      &print_preview_buttons($page_name, $escapedmsg, $form{mydigest});          $Links .= qq(\n);
381      &print_footer;      }
382  }      wantarray ? ($Links, $links) : $Links;
383    }
384  sub print_preview_buttons {  
385      my ($page_name, $escapedmsg, $digest) = @_;  sub print_footer {
386      print <<"EOD";      my ($page, $lm) = @_;
387      <form action="$thisurl" method="post">      my $epage = &encode ($page);
388      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="virtual">$escapedmsg</textarea>    my $cvslog1 = q$Revision$;
389      <br />    my $cvslog2 = q$Date$;
390      <input type="hidden" name="mypage" value="$page_name">    print_navigate_links ($page);
391      <input type="hidden" name="mydigest" value="$digest">    print <<"EOD";
392      <input type="submit" name="myspecial_preview" value="再度プレビュー">  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
393      <input type="submit" name="myspecial_write" value="ページの更新">  <div class="footer">
394      </form>  <a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 &copy; 2000-2002 by Hiroshi Yuki">@{[&Resource('About:Name:YukiWiki',escape=>1)]}</a> <a href="http://digit.que.ne.jp/work/" title="WalWiki 2.0.beta1.wal.1 &copy; 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a>
395  EOD  <a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
396  }  </div>
397    </body>
398  # 書き込む  </html>
399  sub do_write {  EOD
400      if (not &is_editable($form{mypage})) {  }
401          # 編集不可ページは表示のみ  
402          &do_read;  sub escape {
403          return;      my $s = shift;
404      }      $s =~ s|\x0D\x0A|\x0A|g;
405        $s =~ s|&|&amp;|g;
406      my $page_name = $form{mypage};      $s =~ s|<|&lt;|g;
407        $s =~ s|>|&gt;|g;
408      # digestを使って、更新の衝突チェック      $s =~ s|"|&quot;|g;
409      my $original_digest = &calc_message_digest(&get_page($page_name));      return $s;
410      if ($form{mydigest} ne $original_digest) {  }
411          &print_header($page_name);  
412          print qq|<h1>$IconTag${page_name}で【更新の衝突】が起きました</h1>\n|;  sub unescape {
413          print <<"EOD";      my $s = shift;
414  <p>あなたがこのページを編集している間に、      # $s =~ s|\n|\r\n|g;
415  他の人が同じページを更新してしまったようです。      $s =~ s|&lt;|<|g;
416  </p><p>      $s =~ s|&gt;|>|g;
417  以下に、あなたの編集したテキストがありますので、      $s =~ s|&quot;|"|g;
418  あなたの編集内容が失われないように、      $s =~ s|&amp;|&|g;
419  いますぐ、メモ帳などにコピー&ペーストしてください。      return $s;
420  </p><p>  }
421  コピー&ペーストが済んでから、  
422  最新の内容を見て再度編集し直してください。  sub print_content ($;$) {
423  最新の内容は      my ($rawcontent, %option) = @_;
424  <a target="_blank" href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>      print &text_to_html($rawcontent, toc=>1, %option);
425  で見ることができます。  }
426  </p>  
427  EOD  sub text_to_html {
428          # &print_toolbar($page_name);      my ($txt, %option) = @_;
429          &print_preview_buttons($page_name, &escape($form{mymsg}), $form{mydigest});      my $toc = $option{-toc} || [];
430          &print_footer;      my $tocnum = 0;
431          return;      
432      }      ## Load constants
433        my %const;
434      # diff生成      if ($option{content_format} =~ /import="([^"]+)"/) {
435      {        for (split /\s*,\s*/, $1) {
436          &opendiff;          my $wp = $database{$_};
437          my @msg1 = split(/\n/, &get_page($page_name));          if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
438          my @msg2 = split(/\n/, $form{mymsg});            wiki::suikawikiconst::to_hash ($wp => \%const);
439          $msgrefA = \@msg1;          }
440          $msgrefB = \@msg2;        }
441          &diff_check;      }
442          $diffbase{$form{mypage}} = $diff_text;      
443          $diff_text = '';      $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
444          &closediff;      my (@txt) = split(/\n/, $txt);
445      }      my (@saved, @result);
446        unshift(@saved, "</p>");
447      &print_header($page_name);      push(@result, "<p>");
448      &set_page($page_name, $form{mymsg});      foreach (@txt) {
449      if ($form{mymsg}) {          chomp;
450          print qq|<h1>$IconTag${page_name}を更新しました</h1>\n|;          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
451          &print_toolbar($page_name);              push @$toc, [5, "i$tocnum" => ($1 || $tocnum)];
452          print &convert_html(&get_page($page_name));              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
453      } else {              $tocnum++;
454          print qq|<h1>$IconTag${page_name}を削除しました</h1>\n|;          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
455          &print_toolbar($page_name);              push @$toc, [4, "i$tocnum" => ($1 || $tocnum)];
456          print qq|<p>${page_name}を削除しました。</p>\n|;              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
457      }              $tocnum++;
458      &print_footer;          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
459      # 更新されたのでタッチしておく。              push @$toc, [3, "i$tocnum" => ($1 || $tocnum)];
460      if ($touchfile) {              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
461          open(FILE, "> $touchfile");              $tocnum++;
462          print FILE "\n";          } elsif (/^\*\*([^\x0D\x0A]*)/) {
463          close(FILE);          # if (/^\*\*(.*)/) {
464      }          # Walrus mod (6) end
465  }              push @$toc, [2, "i$tocnum" => ($1 || $tocnum)];
466                push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
467  # ページの変更点              $tocnum++;
468  sub do_diff {          } elsif (/^\*([^\x0D\x0A]*)/) {
469      if (not &is_editable($form{mypage})) {              push @$toc, [1, "i$tocnum" => ($1 || $tocnum)];
470          # 編集不可ページは表示のみ              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
471          &do_read;              $tocnum++;
472          return;          } elsif (/^(={1,6})(.*)/) {
473      }              &back_push('ol', length($1), \@saved, \@result);
474      &opendiff;              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
475      &print_header($form{mypage} . 'の変更点');          } elsif (/^(-{1,6})(.*)/) {
476      print qq|<h1>$IconTag <a href="$thisurl?mycmd=read&mypage=$form{mypage}">$form{mypage}</a>の変更点</h1>\n|;            &back_push('ul', length($1), \@saved, \@result);
477      &print_toolbar();            my ($pf, $l) = ('', $2);
478      $_ = &escape($diffbase{$form{mypage}});            if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
479      print <<"EOD";              my $num = 0+$1;
480  <ul>              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
481  <li>追加された行は<ins>青色</ins>です。            }
482  <li>削除された行は<del>赤色</del>です。            push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
483  <li><a href="$thisurl?mycmd=read;mypage=$form{mypage}">$form{mypage}</a>へ行く。          } elsif (/^:([^:]+):(.*)/) {
484  </ul>              &back_push('dl', 1, \@saved, \@result);
485  <hr />              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
486  EOD          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
487      print qq|<pre>\n|;              &back_push('blockquote', length($1), \@saved, \@result);
488      foreach (split(/\n/, $_)) {              push @result, "<p>";
489          if (/^\+(.*)/) {              push(@result, &inline($2, const => \%const));
490              print qq|<ins>$1</ins>\n|;              unshift @saved, "</p>";
491          } elsif (/^\-(.*)/) {          } elsif (/^\s*$/) {
492              print qq|<del>$1</del>\n|;              push(@result, splice(@saved));
493          } elsif (/^\=(.*)/) {              push(@result, "<p>");
494              print qq|$1\n|;              unshift(@saved, "</p>");
495          } else {          } elsif (/^(\s+.*)$/) {
496              print qq|??? $_\n|;              &back_push('pre', 1, \@saved, \@result);
497          }              push(@result, &inline($1, const => \%const));
498      }          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
499      print qq|</pre>\n|;              &back_push('table', 1, \@saved, \@result);
500      &print_footer;              #######
501      &closediff;              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
502  }              # XXXXX
503                my $tmp = "$1,";
504  sub opendiff {              my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
505      if ($dbmopen) {              my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
506          if (!dbmopen(%diffbase, $diffdbname, 0666)) {              my @colspan = map {($_ eq '==') ? 0 : 1} @value;
507              &print_error("(dbmopen) $diffdbname が作れません。");              for (my $i = 0; $i < @value; $i++) {
508          }                  if ($colspan[$i]) {
509      } else {                      while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
510          if (!tie(%diffbase, "YukiWikiDB", $diffdbname)) {                          $colspan[$i]++;
511              &print_error("(tie error)");                      }
512          }                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
513      }                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], const => \%const));
514  }                  } else {
515                        $value[$i] = '';
516  sub closediff {                  }
517      if ($dbmopen) {              }
518          dbmclose(%diffbase);              push(@result, join('', '<tr>', @value, '</tr>'));
519      } else {              # XXXXX
520          untie(%diffbase);              #######
521      }          } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
522  }              push @result, splice (@saved), '<'.lc($1).'>';
523                unshift @saved, "</p>";
524  # フォームからの情報を連想配列 %form に入れる              push @result, "<p>";
525  # &init_form('euc');          } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
526  sub init_form {              push @result, splice (@saved), '</'.lc($1).'>';
527      my ($charcode) = @_;          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
528      my $query;            my $num = 0+$1;
529      if ($ENV{REQUEST_METHOD} =~ /^post$/i) {            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
530          read(STDIN, $query, $ENV{CONTENT_LENGTH});            push @result, &inline ($2, const => \%const);
531      } else {          } else {
532          $query = $ENV{QUERY_STRING};              push(@result, &inline($_, const => \%const));
533      }          }
534      my @assocarray = split(/[&;]/, $query);      }
535      foreach my $assoc (@assocarray) {      push(@result, splice(@saved));
536          my ($property, $value) = split(/=/, $assoc);      
537          $value =~ tr/+/ /;      my $r = join("\n", @result);
538          $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;      $r =~ s#<p>\x0D?\x0A</p>##g;
539          &jcode::convert(\$value, $charcode);      $r =~ s#[\x0D\x0A]+</#</#g;
540          $form{$property} = $value;      $r =~ s#<pre>\x0D?\x0A#<pre>#g;
541      }      $r;
542  }  }
543    
544  # エラーページを出力する  sub back_push {
545  sub print_error {      my ($tag, $level, $savedref, $resultref, $attr) = @_;
546      my ($msg) = @_;      while (@$savedref > $level) {
547      &print_header('Error');          push(@$resultref, shift(@$savedref));
548      print "<h1>$IconTag$msg</h1></body></html>";      }
549      exit(0);      if ($savedref->[0] ne "</$tag>") {
550  }          push(@$resultref, splice(@$savedref));
551        }
552  sub escape {      while (@$savedref < $level) {
553      my ($line) = shift;          unshift(@$savedref, "</$tag>");
554      $line =~ s|<|&lt;|g;          push(@$resultref, "<$tag$attr>");
555      $line =~ s|>|&gt;|g;      }
556      $line =~ s|"|&quot;|g;  }
557      # $line =~ s|\&|&amp;|g;  
558      return $line;  sub inline ($;%) {
559  }      my ($line, %option) = @_;
560        $line = &escape($line);
561  sub inline {      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
562      my ($line) = shift;      $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;
563      $line = &escape($line);      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
564      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
565      $line =~ s|''([^']+?)''|<em>$1</em>|g;                $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;
566      $line =~ s!      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
567         (      $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;
568           (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
569         #| (?:$WikiName)                         # LocalLinkLikeThis      $line =~ s|''([^']+)''|<em>$1</em>|g;
570         | (?:$BracketName)                      # [[日本語リンク]]      $line =~ s{
571         )        (\[\[(\#\S+?)\]\])
572              !        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
573                  &make_link($1)        |&gt;&gt;([0-9]+)
574              !gex;        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
575      return $line;      }{
576  }        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
577          if ($l) {
578  # ページのタイトルからページの内容を得る          &embedded_to_html($1);
579  sub get_page {        } elsif (defined $page) {
580      my $page_name = shift;          &make_wikilink ($page, anchor => 0+$anchor);
581      return $database{$page_name};        } elsif ($anum) {
582  }          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
583          } elsif ($uri) {
584  # ページの内容を与える          &make_urilink ($uri);
585  # &set_page($title, $txt)        }
586  sub set_page {      }gex;
587      # ページを更新する      return $line;
588      my $title = $_[0];  }
589      $database{$title} = $_[1];  
590      # 空ページなら削除する  sub make_wikilink ($%) {
591      unless ($database{$title}) {    my ($ename, %option) = @_;
592          delete $database{$title};    my $name = &unescape ($ename);
593      }    if ($database{$name}) {
594      # RecentChangesを更新する      my $subject = &escape (&get_subjectline ($name, delimiter => ''));
595      my $delim = ' - ';      if ($option{anchor}) {
596      my @pages = split(/\n/, $database{$whatsnew});        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
597      my $datestr = &get_current_datestr;      } else {
598      unshift(@pages, qq|-$datestr$delim$title|);        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
599      # 同一ページの更新は最新のもののみにし、      }
600      # 存在しないページはスキップする。    } else {
601      my %count;      return qq(<a title="@{[&Resource('JumpAndEditWikiPage',escape=>1)]}" href="$url_cgi?@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</span></a>);
602      my @newpages;    }
603      foreach my $line (@pages) {  }
604          my ($prefix, $title) = split(/$delim/, $line);  
605          $count{$title}++;  sub make_urilink ($;%) {
606          if ($count{$title} == 1 and exists($database{$title})) {    require URI;
607              push(@newpages, qq|$prefix - $title|);    my $uri = shift;
608          }    if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
609      }      $uri = &unescape ($uri);
610      # ここで本当に更新      if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
611      $database{$whatsnew} = join("\n", splice(@newpages, 0, $maxnew));        my ($site, $name) = ($1, $2);
612  }        for ($site, $name) {
613            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
614  # ページのヘッダを出力        }
615  sub print_header {        &init_InterWikiName () unless $interwiki{'[[]]'};
616      my $title = shift;        if ($interwiki{$site}) {
617      print <<"EOD";          &load_formatter ('interwiki');
618  Content-type: text/html          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
619            $site = &escape ($site); $name = &escape ($name);
620  <html><head>          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;);
621  <title>$title</title>        } else {
622  <style type="text/css">          qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
623  $style        }
624  </style>      } else {
625  </head>        qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
626  <body>      }
627  EOD    } elsif ($uri =~ /^urn:/) {   ## URN
628  }      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
629        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
630  # ツールバーを出力    } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
631  sub print_toolbar {      my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
632      my $page_name = shift;      qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
633      my $percent_name = &encode_percent($page_name);    } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
634      my $editlink = '';      my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
635      if ($page_name ne '' and &is_editable($page_name)) {      qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
636          $editlink = <<"EOD";    } else {      ## misc. URI
637  <a href="$thisurl?mycmd=edit;mypage=$percent_name">編集</a> |      CGI::Carp::warningsToBrowser (0);
638  <a href="$thisurl?mycmd=diff;mypage=$percent_name">差分</a> |      my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
639  EOD      CGI::Carp::warningsToBrowser (1);
640      }      qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
641      print <<"EOD";    }
642  <p>  }
643   [  
644  <a href="$thisurl?mycmd=read;mypage=$toppage">トップ</a> |  {my $FormIndex = 0;
645  <a href="$thisurl?mycmd=list">一覧</a> |  sub make_custom_form ($$$$) {
646  $editlink      my ($wfname, $definition, $template, $option) = @_;
647  <a href="$thisurl?mycmd=search">単語検索</a> |      ## $template and $option is currently not used in this procedure.
648  <a href="$thisurl?mycmd=read;mypage=$whatsnew">最終更新</a>      unless ($main::_EMBEDED) {
649   ]          $FormIndex++;
650  </p>          if (length $definition) {
651  EOD              my $param = bless {}, 'SuikaWiki::Plugin';
652  }              my $lastmodified = $database->mtime ($form{mypage});
653                &load_formatter (qw/form_input form_option/);
654  # ページのフッタを出力              $definition = &unescape ($definition);
655  sub print_footer {              $definition =~ s/\\(.)/$1/g;
656      print <<"EOD";              $option = &unescape ($option);
657  <address>              $option =~ s/\\(.)/$1/g;
658  <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> 1.6.6 Copyright (C) 2000,2001 by <a href="http://www.hyuki.com/">Hiroshi Yuki.</a>              $fmt{form_option}->replace ($option, $param);
659  + <a href="$modifierlink">$modifier</a> ${version}.              $param->{output}->{form} = 1 unless defined $param->{output}->{form};
660  [<a href="/" title="このサーバーの首頁">/</a>              $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
661  <a href="/map" title="このサーバーの案内">地図</a>              my $target_page = $param->{output}->{page} || $form{mypage};
662  <a href="/search/" title="このサーバーの検索">検索</a>]              $param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage});
663  </address>              my $target_form = $param->{output}->{id};
664  </body></html>              my $r = '';
665  EOD              $r = <<EOH if $param->{output}->{form};
666  }  <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
667      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
668  # URLやページの名前からリンクを作る    <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
669  sub make_link {    <input type="hidden" name="myLastModified" value="$lastmodified">
670      my $name = shift;    <input type="hidden" name="mytouch" value="on">
671      $name =~ s/^&lt;(.*)&gt;$/$1/;    <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
672      $name =~ s/^\[\[(.*)\]\]$/$1/;  EOH
673      if ($name =~ /^(http|https|ftp).*?(\.png|\.jpeg|\.jpg)?$/) {              $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
674          if ($2) {              $r .= $fmt{form_input}->replace ($definition, $param);
675              return qq|<a href="$name"><img border="0" src="$name" /></a>|;              $r .= "</form>\n" if $param->{output}->{form};
676          } else {              $r;
677              return qq|&lt;<a href="$name">$name</a>&gt;|;         } else {  ## No input-interface WikiForm
678          }             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
679      } elsif ($name =~ /^mailto:(.*)/) {         }
680          my $address = $1;      } else {
681          return qq|&lt;<a href="$name">$address</a>&gt;|;          qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
682      } elsif ($name =~ /^urn:[0-9A-Za-z_:-]+/) {      }
683          return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;  }}
684      } else {  
685        my $name2 = $name; $name2 =~ tr/\x20/-/;  sub print_message {
686        if ($database{$name2}) {      my ($msg) = @_;
687          my $percent_name = &encode_percent($name2);      print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
688          return qq|<a href="$thisurl?mycmd=read;mypage=$percent_name" class="wiki">$name</a>|;  }
689        } elsif ($database{'[['.$name2.']]'}) {  
690          my $percent_name = &encode_percent('[['.$name2.']]');  sub init_form {
691          return qq|<a href="$thisurl?mycmd=read;mypage=$percent_name" class="wiki">$name</a>|;      ## TODO: Support multipart/form-data
692        } else {      my $query = '';
693          my $percent_name = &encode_percent($name2);      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
694          return qq|<a href="$thisurl?mycmd=edit;mypage=$percent_name" class="wiki newpage">$name?</a>|;        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
695        }      }
696      }      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
697  }      if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
698          my $query = &decode($main::ENV{QUERY_STRING});
699  # %xx の形式にエンコードする        $query = &code_convert(\$query, $kanjicode);
700  # これは、        if ($page_command{$query}) {
701  # http://www.hyuki.com/yukiwiki/yukiwiki.cgi?mycmd=read&mypage=%3C%8C%8B%8F%E9%8D_%3E          $form{mycmd} = $page_command{$query};
702  # という形式のために使われる。          $form{mypage} = $query;
703  # '<結城浩>' → '%3C%8C%8B%8F%E9%8D_%3E'        } else {
704  sub encode_percent {          $form{mypage} = $query;
705      my $name = shift;          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
706      my $encoded = '';        }
707      foreach my $ch (split(//, $name)) {      } else {
708          if ($ch =~ /[A-Za-z0-9_]/) {        for (split /[;&]/, $query) {
709              $encoded .= $ch;          if (my ($n, $v) = split /=/, $_, 2) {
710          } else {            for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
711              $encoded .= '%' . sprintf("%02X", ord($ch));            $form{$n} = $v;
712          }          }
713      }        }
714      return $encoded;        unless (defined $form{mypage}) {
715  }          $form{mypage} = $form{epage};
716            $form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g;
717  # テキスト本体をHTMLに変換する        }
718  sub convert_html {        if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
719      my ($txt) = shift;          $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
720      my (@txt) = split(/\n/, $txt);          $form{mycmd} = $page_command{$form{mypage}};
721      foreach (@txt) {        }
722          chomp;      }
723          if (/^\*\*(.*)/) {      $form{mypage} ||= 'HomePage';
724              push(@result, splice(@saved), '<h3>' . &inline($1) . '</h3>');      $form{mypage} =~ tr/\x00-\x1F\x7F//d;
725          } elsif (/^\*(.*)/) {      $form{mycmd} ||= 'read';
726              push(@result, splice(@saved), '<h2>' . &inline($1) . '</h2>');  
727          } elsif (/^----/) {      # mypreview_edit        -> do_edit, with preview.
728              push(@result, splice(@saved), '<hr>');      # mypreview_adminedit   -> do_adminedit, with preview.
729          } elsif (/^(-{1,3})(.*)/) {      # mypreview_write       -> do_write, without preview.
730              &back_push('ul', length($1));      foreach (keys %form) {
731              push(@result, '<li>' . &inline($2) . '</li>');          if (/^mypreview_(.*)$/) {
732          } elsif (/^:([^:]+):(.*)/) {              $form{mycmd} = $1;
733              &back_push('dl', 1);              $form{mypreview} = 1;
734              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');          }
735          } elsif (/^(>{1,3})(.*)/) {      }
736              &back_push('blockquote', length($1));  
737              push(@result, &inline($2));      #
738          } elsif (/^\s*$/) {      # $form{mycmd} is frozen here.
739              push(@result, splice(@saved));      #
740              unshift(@saved, "</p>");  
741              push(@result, "<p>");      for (grep /^wikiform__/, keys %form) {
742          } elsif (/^(\s+.*)$/) {          $form{$_} = &code_convert (\$form{$_}, $kanjicode);
743              &back_push('pre', 1);      }
744              push(@result, &escape($1)); # Not &inline, but &escape      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
745          } else {      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
746              push(@result, &inline($_));  }
747          }  
748      }  {my %SubjectLine;
749      push(@result, splice(@saved));  sub get_subjectline {
750      return join("\n", @result);      my ($page, %option) = @_;
751  }      unless (defined $SubjectLine{$page}) {
752          if (not &is_editable($page)) {
753  # &back_push($tag, $count)          $SubjectLine{$page} = "";
754  # $tagのタグを$levelレベルまで詰める。        } else {
755  sub back_push {          $SubjectLine{$page} = $database{$page};
756      my ($tag, $level) = @_;          $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
757      while (@saved > $level) {          $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
758          push(@result, shift(@saved));        }
759      }      }
760      if ($saved[0] ne "</$tag>") {      if (length $SubjectLine{$page}) {
761          push(@result, splice(@saved));        $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
762      }        $option{delimiter}.$SubjectLine{$page}.$option{tail};
763      while (@saved < $level) {      } else {
764          unshift(@saved, "</$tag>");        '';
765          push(@result, "<$tag>");      }
766      }  }}
767  }  
768    sub open_db {
769  # 編集可能ページか?      if ($modifier_dbtype eq 'dbmopen') {
770  sub is_editable {          dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}");
771      my ($pagename) = @_;      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
772      foreach (@uneditable) {          eval q{use AnyDBM_File};
773          if ($pagename eq $_) {          tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}");
774              return 0;      } elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') {
775          }          eval q{use Yuki::YukiWikiDB};
776      }          tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}");
777      if (&is_valid_name($pagename)) {      } else {    ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta
778          return 1;          eval qq{use $modifier_dbtype};
779      }          $database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or &print_error("(tie $modifier_dbtype) $PathTo{WikiDataBase}");
780      return 0;      }
781  }  }
782    
783  # Validな名前か?  sub close_db {
784  sub is_valid_name {      if ($modifier_dbtype eq 'dbmopen') {
785      my ($pagename) = @_;          dbmclose(%database);
786      if ($pagename =~ /^$WikiName$/) {      } else {
787          return 1;          untie(%database);
788      } elsif ($pagename =~ /^$BracketName$/) {      }
789          return 1;  }
790      } else {  
791          return 0;  sub editform (@) {
792      }    my %option = @_;
793  }    my $frozen = &is_frozen ($option{page});
794      $option{content} = $database{$option{page}} unless defined $option{content};
795  # 現在時刻の文字列を得る    $option{content} = $database{NewPageTemplate} unless length $option{content};
796  sub get_current_datestr {    $option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified};
797      my (@wdays) = ( "日", "月", "火", "水", "木", "金", "土" );    my $f = '';
798      my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time);    my $magic = '';
799      return sprintf("%4d-%02d-%02d (%s) %02d:%02d:%02d",    $magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s;
800          $year + 1900, $mon + 1, $mday, $wdays[$wday], $hour, $min, $sec);    
801  }    my $selected = 'read';
802      if ($form{after_edit_cmd}) {
803  # URL?SomePageや、      $selected = $form{after_edit_cmd};
804  # URL?[[結城浩]]の形式だった場合、(not yet)    } elsif ($magic =~ /Const|Config|CSS/) {
805  # 強制的にmycmdをreadにして$formの内容を設定する。      $selected = 'edit';
806  sub normalize_form {    }
807      foreach my $key (keys %form) {    my $afteredit = <<EOH;
808          if ($key =~ /^$WikiName$/) {  <select name="after_edit_cmd">
809              $form{mycmd} = 'read';  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
810              $form{mypage} = $1;  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
811              last;  </select>
812          } elsif ($key =~ /^$BracketName$/) {  EOH
813              $form{mycmd} = 'read';    $f .= <<"EOD";
814              $form{mypage} = $1;  <form action="$uri{wiki}" method="post">
815              last;      @{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd></label>) ]}
816          }      @{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br>
817      }      <input type="hidden" name="myLastModified" value="$option{last_modified}">
818  }      <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
819        <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br>
820  # 変換テストを行なうときのサンプル  @{[
821  sub print_sample {      $option{admin} ?
822      my $txt = &convert_html(<<"EOD");      qq(
823  *大見出し1      <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
824  **小見出し1-1      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)
825  -項目1      : ""
826  -項目2  ]}
827  -項目3  @{[
828  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1      $option{conflict} ? "" :
829  段落1段落1段落1段落1段落1段落''強調''1段落1段落1段落1段落1段落1      qq(
830  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1          <label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br>
831            <label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label>
832  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2         $afteredit
833  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2      )
834  段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2  ]}
835  **小見出し1-2  </form>
836  :用語1:いろいろ書いた解説文1と''強調単語''  EOD
837  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1      unless ($option{conflict}) {
838  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1          ## Show help text
839  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1          my $help = $database{WikiEditHelp};
840  :用語2:いろいろ書いた解説文2          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
841  :用語3:いろいろ書いた解説文3          $f .= &text_to_html ($help, toc => 0);
842  ----      }
843  *大見出し2      $f;
844  **小見出し2-1  }
845  &lt;http://suika.fam.cx/&gt;  
846  **小見出し2-2  sub is_editable {
847        my ($page) = @_;
848  [[結城浩]]      $page =~ /[\x00-\x1F\x7F]/ ? 0 : 1;
849    }
850  段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1段落1  
851  段落1段落1段落1段落'''強調'''1段落1段落1段落1段落1段落1段落1段落1  # armor_name:
852  段落1段落1段落1段落'''''強い強調'''''1段落1段落1段落1段落1段落1段落1段落1段落1  #   WikiName -> WikiName
853  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2  #   not_wiki_name -> [[not_wiki_name]]
854  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2  sub armor_name { qq([[$_[0]]]) }
855  >段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2段落2  
856    # unarmor_name:
857  レベル0レベル0レベル0レベル0レベル0レベル0  #   [[bracket_name]] -> bracket_name
858    #   WikiName -> WikiName
859  >レベル1  sub unarmor_name {
860  >レベル1      my ($name) = @_;
861  >レベル1      if ($name =~ /^\[\[(\S+?)\]\]$/) {
862  >>レベル2          return $1;
863  >>レベル2      } else {
864  >>レベル2          return $name;
865  >>>レベル3      }
866  -はろ1  }
867  --はろ2  
868  ろろろろ2  sub decode {
869  ---はろ3      my ($s) = @_;
870  --はろ2      $s =~ tr/+/ /;
871  ---はろ3      $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
872  --はろ2      return $s;
873  ---はろ3  }
874  >>>レベル3  
875  >>>レベル3  sub encode {
876  >>>レベル3      my ($s) = @_;
877  EOD      my $encoded = '';
878      print $txt;      foreach my $ch (split(//, $s)) {
879      exit;          if ($ch =~ /[A-Za-z0-9_]/) {
880  }              $encoded .= $ch;
881            } else {
882  sub diff_check {              $encoded .= '%' . sprintf("%02X", ord($ch));
883      traverse_sequences(          }
884              $msgrefA, $msgrefB,      }
885              {      return $encoded;
886                  MATCH => \&df_match,  }
887                  DISCARD_A => \&df_delete,  
888                  DISCARD_B => \&df_add,  sub get_now {
889              }      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
890      );      $year += 1900;
891      &diff_flush;      $mon++;
892  }      $mon = "0$mon" if $mon < 10;
893        $day = "0$day" if $day < 10;
894  sub diff_flush {      $hour = "0$hour" if $hour < 10;
895      $diff_text .= join('', map { "-$_\n" } splice(@diff_deleted));      $min = "0$min" if $min < 10;
896      $diff_text .= join('', map { "+$_\n" } splice(@diff_added));      #$sec = "0$sec" if $sec < 10;
897  }      return "$year-$mon-$day $hour:$min";
898    }
899  sub df_match {  
900      my ($a, $b) = @_;  sub init_InterWikiName {
901      &diff_flush;    my @content = split /\n/, $database{InterWikiName};
902      $diff_text .= "=$msgrefA->[$a]\n";    for (@content) {
903  }      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
904          $interwiki{$1} = $2;
905  sub df_delete {      }
906      my ($a, $b) = @_;    }
907      push(@diff_deleted, $msgrefA->[$a]);    $interwiki{'[[]]'} = 1;       ## dummy
908  }  }
909    
910  sub df_add {  sub frozen_reject {
911      my ($a, $b) = @_;      my ($isfrozen) = $database->meta (IsFrozen => $form{mypage});
912      push(@diff_added, $msgrefB->[$b]);      my ($willbefrozen) = $form{myfrozen};
913  }      if (not $isfrozen and not $willbefrozen) {
914            # You need no check.
915  sub calc_message_digest {   # You have to use MD5...          return 0;
916      my $text = shift;      } elsif (valid_password($form{mypassword})) {
917      my @text = split(//, $text);          # You are admin.
918      my $len = length($text);          return 0;
919      my $checksum = 0;      } else {
920      foreach (@text) {          &print_error(&Resource('Error:PasswordIsIncorrect'));
921          $checksum += ord($_);          return 1;
922          $checksum = ($checksum * 2) % 65536 + (($checksum & 32768) ? 1 : 0); # 16bit rotate      }
923      }  }
924      return "$len:$checksum";  
925  }  sub is_frozen ($) { $database->meta (IsFrozen => $_[0]) ? 1 : 0 }
926    
927  # Definition of YukiWikiDB  sub do_comment {
928  package YukiWikiDB;      my ($content) = $database{$form{mypage}};
929        my $default_name;   ## this code does not strict.
930  my $debug = 1;      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
931        my $datestr = '[WEAK['.&get_now.']]';
932  # Constructor      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
933  sub new {      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
934      return shift->TIEHASH(@_);      if ($namestr =~ /^(?:>>)?[0-9]/) {
935  }        $namestr = qq( ''$namestr'': );
936        } elsif (length $namestr) {
937  # tying        $namestr = qq( ''[[$namestr]]'': );
938  sub TIEHASH {      }
939      my ($class, $dbname) = @_;      my $anchor = &get_new_anchor_index ($content);
940      my $self = {      my $i = 1;  my $o = 0;
941          dir => $dbname,      $content =~ s{(\[\[\#r?comment\]\])}{
942          keys => [],        my $embed = $1;
943      };        if ($i == $form{comment_index}) {
944      if (not -d $self->{dir}) {          if ($embed ne '[[#rcomment]]') {
945          if (!mkdir($self->{dir}, 0777)) {            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
946              print "mkdir(" . $self->{dir} . ") fail\n" if ($debug);          } else {
947              return undef;            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
948          }          }
949      }        }
950      return bless($self, $class);        $i++; $embed;
951  }      }ge;
952        unless ($o) {
953  # Store        $content = "#?SuikaWiki/0.9\n\n" unless $content;
954  sub STORE {        $content .= "\n" unless $content =~ /\n$/s;
955      my ($self, $key, $val) = @_;        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
956      my $file = &make_filename($self, $key);      }
957      if (open(FILE,"> $file")) {      $form{__comment_anchor_index} = $anchor;
958          binmode(FILE);      if ($form{mymsg} || $form{myname}) {
959          print FILE $val;          $form{mymsg} = $content;
960          close(FILE);          $form{mytouch} = 'on';
961          return $self->{$key} = $val;          &do_write;
962      } else {      } else {
963          print "$file create error.";          $form{mycmd} = 'read';
964      }          &do_read;
965  }      }
966    }
967  # Fetch  
968  sub FETCH {  sub get_new_anchor_index ($) {
969      my ($self, $key) = @_;      my $content = shift;
970      my $file = &make_filename($self, $key);      my $anchor = 0;
971      if (open(FILE, $file)) {      $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
972          local $/;      $anchor + 1;
973          $self->{$key} = <FILE>;  }
974          close(FILE);  
975      }  my $CommentIndex = 0;
976      return $self->{$key};  sub embedded_to_html {
977  }      my ($embedded) = @_;
978        if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
979  # Exists        unless ($main::_EMBEDED) {
980  sub EXISTS {          my $lastmodified = $database->mtime ($form{mypage});
981      my ($self, $key) = @_;          return <<"EOD";
982      my $file = &make_filename($self, $key);  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
983      return -e($file);      <input type="hidden" name="mycmd" value="comment">
984  }      <input type="hidden" name="mypage" value="$form{mypage}">
985        <input type="hidden" name="myLastModified" value="$lastmodified">
986  # Delete      <input type="hidden" name="mytouch" value="on">
987  sub DELETE {      <input type="hidden" name="comment_index" value="$CommentIndex">
988      my ($self, $key) = @_;      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
989      my $file = &make_filename($self, $key);      <input type="text" name="myname" value="" size="10" class="comment-name">
990      unlink $file;      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
991      return delete $self->{$key};      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
992  }  </p></form>
993    EOD
994  sub FIRSTKEY {       } else {
995      my ($self) = @_;          return <<"EOD";
996      opendir(DIR, $self->{dir}) or die $self->{dir};  <del><form action="$url_cgi" method="get">
997      @{$self->{keys}} = grep /\.txt$/, readdir(DIR);      <input type="hidden" name="mycmd" value="read">
998      foreach my $name (@{$self->{keys}}) {      <input type="hidden" name="mypage" value="$form{mypage}">
999          $name =~ s/\.txt$//;      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1000          $name =~ s/[0-9A-F][0-9A-F]/pack("C", hex($&))/eg;      <input type="text" name="myname" value="" size="10" disabled="disabled">
1001      }      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1002      return shift @{$self->{keys}};  </form></del>
1003  }  EOD
1004        }
1005  sub NEXTKEY {    } elsif ($embedded =~ /$embed_command{searched}/) {
1006      my ($self) = @_;      return get_search_result ($1, -match_myself => 1);
1007      return shift @{$self->{keys}};    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1008  }      my ($name, $r) = ($1, '');
1009        if ($main::_EMBEDED != 1) {
1010  sub make_filename {        my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1011      my ($self, $key) = @_;        $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1012      my $enkey = '';        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1013      foreach my $ch (split(//, $key)) {          $main::_EMBEDED = 1;
1014          $enkey .= sprintf("%02X", ord($ch));          $r = &text_to_html ($content, content_format => $cf);
1015      }          $main::_EMBEDED = 0;
1016      return $self->{dir} . "/$enkey.txt";        } elsif (length $content) {
1017  }          $r = "<pre>@{[&escape ($content)]}</pre>";
1018  __END__        } else {
1019            $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1020  =head1 NAME        }
1021        } else {    ## nested #EMBED
1022  YukiWiki - 自由にページを追加・削除・編集できるWebページ構築CGI        $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1023        }
1024      Copyright (C) 2000,2001 by Hiroshi Yuki.      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>);
1025      結城浩 <hyuki@hyuki.com>    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1026      http://www.hyuki.com/      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1027      http://www.hyuki.com/yukiwiki/    } else {
1028        return $embedded;
1029  =head1 SYNOPSIS    }
1030    }
1031      http://www.hyuki.com/yukiwiki/yukiwiki.cgi  
1032    sub load_formatter (@) {
1033  =head1 DESCRIPTION      for my $t (@_) {
1034            unless ($fmt{$t}) {
1035  YukiWiki(結城ウィキィ)は参加者が自由にページを追加・削除・編集できる              require Message::Util::Formatter;
1036  不思議なWebページ群を作るCGIです。              $fmt{$t} = Message::Util::Formatter->new;
1037  Webで動作する掲示板とちょっと似ていますが、              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1038  Web掲示板が単にメッセージを追加するだけなのに対して、                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1039  YukiWikiは、Webページ全体を自由に変更することができます。              }
1040            }
1041  YukiWikiは、Cunningham & CunninghamのWikiWikiWebの      }
1042  仕様を参考にして独自に作られました。  }
1043    
1044  YukiWikiはPerlで書かれたCGIスクリプトとして実現されていますので、  sub do_wikiform {
1045  Perlが動作するWebサーバならば比較的容易に設置できます。      my $content = $database{$form{mypage}};
1046        my $anchor = &get_new_anchor_index ($content);
1047  あとはdbmopenが使える環境ならば設置できます(Version 1.5.0以降ならdbmopenが使えなくても設置できます)。      &load_formatter (qw/form_template form_option/);
1048        my $write = 0;
1049        my $i = 1;
1050  YukiWikiはフリーソフトです。      $content =~ s{$embed_command{form}}{
1051  ご自由にお使いください。          my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1052            if (($wfname && $wfname eq $form{wikiform_targetform})
1053  =head1 設置方法              || $i == $form{wikiform_index}) {
1054                $template =~ s/\\(.)/$1/g;
1055  =head2 入手              $option =~ s/\\(.)/$1/g;
1056                my $param = bless {}, 'SuikaWiki::Plugin';
1057  YukiWikiの最新版は、              $param->{page} = $form{mypage};
1058  http://www.hyuki.com/yukiwiki/              $param->{form_index} = $i;
1059  から入手できます。              $param->{form_name} = $wfname;
1060                $param->{anchor_index} = $anchor;
1061  =head2 ファイル一覧              $param->{argv} = \%form;
1062                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1063      readme.txt      ドキュメント              $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1064      yukiwiki.cgi    YukiWiki本体              $fmt{form_option}->replace ($option, $param);
1065      yukiwiki.gif    ロゴ(カラー版)              my $t = 1;
1066      yukimono.gif    ロゴ(モノクロ版)              for (@{$param->{require}||[]}) {
1067      jcode.pl        漢字コードライブラリ                  (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1068                }
1069  =head2 インストール              $t = $fmt{form_template}->replace ($template, $param) if $t;
1070                if (length $t) {
1071  =over 4                  if ($param->{output}->{reverse}) {
1072                        $embed .= "\n" . $t;
1073  =item 1.                  } else {
1074                        $embed = $t . "\n" . $embed;
1075  アーカイブを解く。                  }
1076                    $write = 1;
1077  =item 2.                  $form{__comment_anchor_index} = $anchor
1078                      if $param->{anchor_index_};  ## $anchor is used!
1079  yukiwiki.cgiのはじめの方にある設定を確認します。              }
1080  通常は何もしなくてよいが、              $form{__wikiform_anchor_index} = $i;
1081  はじめは$touchfileを''にした方がよいでしょう。              undef $form{wikiform_targetform};  ## make sure never to match
1082                undef $form{wikiform_index};       ## with WikiForm in rest of page
1083  =item 3.          }
1084            $i++; $embed;
1085  yukiwiki.cgiとjcode.plを同じところに設置します。      }ge;
1086        unless ($write) {
1087  =item 4.        #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1088          #$content .= "\n" unless $content =~ /\n$/s;
1089  サイズ0のyukiwiki.dbというファイルを設置します。        #
1090  (Perlシステムによってはyukiwiki.pag, yukiwiki.dir)      }
1091        if ($write) {
1092  =item 5.          $form{mymsg} = $content;
1093            $form{mytouch} = 'on';
1094  yukiwiki.cgiにブラウザからアクセスします。          &do_write;
1095        } else {
1096  =back          $form{mycmd} = 'read';
1097            &do_read;
1098  =head2 パーミッション      }
1099    }
1100          ファイル        パーミッション      転送モード  
1101          yukiwiki.cgi    755                 ASCII  sub code_convert {
1102          yukiwiki.gif    644                 BINARY    require Jcode;
1103          yukimono.gif    644                 BINARY      my ($contentref, $code) = (shift, shift || $kanjicode);
1104          jcode.pl        644                 ASCII      $code = 'jis' if $code =~ /iso/;
1105        $code = 'euc' if $code =~ /euc/;
1106      $dbmopen = 1; にした場合:      $code = 'sjis' if $code =~ /shift/;
1107          yukiwiki.db     666                 BINARY      $code = 'utf8' if $code =~ /utf/;
1108          (yukiwiki.pag, yukiwiki.dirの場合もあり)      $$contentref = Jcode->new ($contentref)->tr ("\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&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code;
1109        return $$contentref;
1110      $dbmopen = 0; にした場合: (カレントディレクトリを777にしておく)  }
1111          .               777                 (転送しない)  
1112    sub do_diff {
1113  =head1 データのバックアップ方法      my $title = $form{mypage};
1114        &print_header($title, -noindex => 1);
1115  $dbmopen = 1;の場合は、      print qq(<h2>@{[&Resource('Diff:Title',escape=>1)]}</h2>);
1116  データはすべてyukiwiki.db(.dir, .pag)に入る。      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1117  これをバックアップすればよい。      print qq(<pre class="diff">);
1118        for (split(/\n/, &escape ($database->traverse_diff ($form{mypage})))) {
1119  $dbmopen = 0;の場合は、          if (/^\+(.*)/) {
1120  yukiwikiというディレクトリができるので、              print qq(<ins class="added">$1</ins>\n);
1121  これ以下をバックアップすればよい。          } elsif (/^\-(.*)/) {
1122                print qq(<del class="deleted">$1</del>\n);
1123  =head1 新しいページの作り方          } elsif (/^\=(.*)/) {
1124                print qq(<span class="same">$1</span>\n);
1125  =over 4          } else {
1126                print qq|??? $_\n|;
1127  =item 1.          }
1128        }
1129  まず、適当なページ(例えばFrontPage)を選び、      print qq(</pre>);
1130  ページの下にある「編集」リンクをたどります。      &print_footer($title);
1131    }
1132  =item 2.  
1133    sub do_rss {
1134  するとテキスト入力ができる状態になるので、      eval q{use Yuki::RSS};
1135  そこにNewPageのような単語      my $rss = new Yuki::RSS(
1136  (大文字小文字混在している英文字列)          version => '1.0',
1137  を書いて「保存」します。          encoding => &get_charset_name ($kanjicode),
1138        );
1139  =item 3.      my $scheme = 'http';
1140        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1141  保存すると、FrontPageのページが書き換わり、      my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1142  あなたが書いたNewPageという文字列の後ろに ? というリンクが表示されます。      $rss->stylesheet (
1143  この ? はそのページがまだ存在しないことを示す印です。        href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1144          type      => 'text/css',
1145  =item 4.      );
1146        $rss->channel(
1147  その ? をクリックすると新しいページNewPageができますので、          title   => &Resource ('RSS:WikiTitle'),
1148  あなたの好きな文章をその新しいページに書いて保存します。          link    => $myuri,
1149            description     => &Resource ('RSS:WikiDescription'),
1150  =item 5.          'dc:language'   => $lang,
1151        );
1152  NewPageページができるとFrontPageの ? は消えて、リンクとなります。      my $recentchanges = $database{RecentChanges};
1153        my $count = 0;
1154  =back      foreach (split(/\n/, $recentchanges)) {
1155            last if ($count >= 15);
1156  =head1 テキスト整形のルール          if (/\[\[([^]]+)\]\]/) {
1157              my $title = $1;
1158  =over 4            $rss->add_item (
1159                title       => &escape($title),
1160  =item *              link        => $myuri . '?' . &encode($title),
1161                description => &escape(&get_subjectline($title,delimiter=>'')),
1162  連続した複数行はフィルされて表示されます。              'dc:date'   => $database->mtime ($title),
1163              );
1164  =item *            $count++;
1165            }
1166  空行は段落C<< <p> >>の区切りとなります。      }
1167        # print RSS information (as XML).
1168  =item *      print <<"EOD"
1169    Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1170  HTMLのタグは書けません。  
1171    @{[$rss->as_string]}
1172  =item *  EOD
1173    }
1174  B<''ボールド''>のようにシングルクォート二つではさむと、  
1175  ボールドC<< <b> >>になります。  sub _rfc3339_date ($) {
1176      my @time = gmtime (shift);
1177  =item *    sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1178    }
1179  B<'''イタリック'''>のようにシングルクォート三つではさむと、  
1180  イタリックC<< <i> >>になります。  sub is_exist_page {
1181        my ($name) = @_;
1182  =item *      if ($use_exists) {
1183            return exists($database{$name});
1184  B<---->のようにマイナス4つがあると、      } else {
1185  水平線C<< <hr> >>になります。          return $database{$name};
1186        }
1187  =item *  }
1188    
1189  行をB<*>ではじめると、  sub __get_database ($) { $database{ $_[0] } }
1190  大見出しC<< <h2> >>になります。  
1191    my %_Resource;
1192  =item *  sub Resource ($;%) {
1193      my ($s, %o) = @_;
1194  行をB<**>ではじめると、    unless (defined $_Resource{$s}) {
1195  小見出しC<< <h3> >>になります。      $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1196      }
1197  =item *    $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1198    }
1199  行をマイナス-ではじめると、  
1200  箇条書きC<< <ul> >>になります。  package wiki::referer;
1201  マイナスの数が増えるとレベルが下がります(3レベルまで)  sub add ($$) {
1202      my $page = shift;
1203      -項目1    my $uri = shift;
1204      --項目1-1    unless (ref $uri) {
1205      --項目1-2      require URI;
1206      -項目2      $uri = URI->new ($uri);
1207      -項目3      ## Some schemes do not have query part.
1208      --項目3-1      eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1209      ---項目3-1-1      $uri->fragment (undef);
1210      ---項目3-1-2    }
1211      --項目3-2    $uri = $uri->canonical;
1212      return unless $uri;
1213  =item *    for my $regex (&get_dont_record) {
1214        return if $uri =~ /$regex/;
1215  コロンを使うと、    }
1216  用語と解説文のリストC<< <dl> >>が書けます。    my %list = get ($page);
1217      $list{ $uri }++;
1218      :用語1:いろいろ書いた解説文1    set ($page, \%list);
1219      :用語2:いろいろ書いた解説文2  }
1220      :用語3:いろいろ書いた解説文3  sub get ($) { split /"/, $main::database->meta (Referer => $_[0]) }
1221    sub set ($%) {
1222  =item *    my $page = shift;
1223      my $list = shift;
1224  リンク    $main::database->meta (Referer => $page => join '"', %$list);
1225    }
1226  =over 4  
1227    sub get_dont_record () {
1228  =item *    map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1229      grep !/^#/,
1230  LinkToSomePageやFrontPageのように、    split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1231  英単語の最初の一文字を大文字にしたものが  }
1232  二つ以上連続したものはYukiWikiのページ名となり、  sub get_site_name () {
1233  それが文章中に含まれるとリンクになります。    my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1234      my @item;
1235  =item *    for (@lines) {
1236        next if /^#/;
1237  http://www.hyuki.com/ のようなURLは自動的にリンクになります。      my ($uri, $name) = split /\s+/, $_, 2;
1238        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1239  =item *      $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1240        push @item, [$uri, qq(q($name))];
1241  二重の大かっこ[[ ]]でくくった文字列も、    }
1242  YukiWikiのページ名になります。    @item;
1243  大かっこの中にはスペースを含めてはいけません。  }
1244  日本語も使えます。  
1245    sub list_html ($) {
1246  =back    my $page = shift;
1247      my %list = get ($page);
1248  =item *    my $r = '';
1249      my @name = get_site_name;
1250  行頭がスペースやタブで始まっていると、    for my $uri (sort keys %list) {
1251  それは整形済みの段落C<< <pre> >>として扱われます。      my $title;
1252  プログラムの表示などに使うと便利です。      for my $item (@name) {
1253          if ($uri =~ /$item->[0]/) {
1254            $title = $uri;
1255  =item *          eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1256              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1257  行を > ではじめると、          last;
1258  引用文C<< <blockquote> >>が書けます。        }
1259  >の数が多いとインデントが深くなります(3レベルまで)。      }
1260        my $euri = main::escape ($uri);
1261      >文章      if ($title) {
1262      >文章        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1263      >>さらなる引用      } else {
1264      >文章        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1265        }
1266  =back    }
1267      $r ? qq(<ul>$r</ul>\n) : '';
1268  =head1 更新履歴  }
1269    
1270  =over 4  sub __decode ($) {
1271      my $s = shift;
1272  =item *    $s =~ tr/+/ /;
1273      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1274  2001年10月20日、Version 1.6.6。    main::code_convert (\$s);
1275    }
1276  更新の衝突対策。  
1277  元ページの簡単なチェックサムを取っておき、  package wiki::useragent;
1278  更新前にチェックサムを比較する。  our $UseLog;
1279  修正個所はdigestという文字列を検索すれば分かる。  
1280  本来はMD5などでちゃんとやった方がいいのだけれど。  sub add ($) {
1281      my $s = shift;
1282  衝突時に表示されるメッセージなどは「極悪」さんのページを参考にした。    return unless length $s;
1283      return unless $UseLog;
1284  =item *    $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge;
1285      my %ua;
1286  2001年10月17日、Version 1.6.5。    for (split /\n/, &main::__get_database($main::PageName{UserAgentList})) {
1287        if (/^-\[(\d+)\] (.+)$/) {
1288  プレビュー画面で、更新ボタンを押したときに送信される        my ($t, $n) = ($1, $2);
1289  メッセージの内容をinput要素のtype="hidden"を使って埋め込むのをやめる。        $n =~ tr/\x0A\x0D//d;
1290  代わりに、textarea要素を使う。        $ua{$n} = $t;
1291  再プレビュー用にmyspecial_を導入。でもきれいな対策ではない。      }
1292      }
1293  =item *    $ua{$s}++;
1294      my $s = qq(#?SuikaWiki/0.9\n);
1295  2001年8月30日、Version 1.6.4。    for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1296        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1297  URLでダイレクトにページ名を指定しても、    }
1298  $WikiNameと$BracketName以外のページを作れないようにした。    $main::database->STORE ($main::PageName{UserAgentList} => $s, -touch => 0);
1299  (is_valid_nameとis_editable参照)。  }
1300    
1301  =item *  package wiki::suikawikiconst;
1302    
1303  2001年8月30日、Version 1.6.3。  sub to_hash ($;$) {
1304      my $page = shift;
1305  RecentChangesを編集・再編集不可とした。    my $h = shift || {};
1306  編集不可ページは@uneditableにページ名を入れる。    my $val;
1307      for my $line (split /\n/, $page) {
1308  =item *      $line =~ tr/\x0A\x0D//d;
1309        if ($val && $line =~ s/^\s+//) {
1310  2001年2月25日、Version 1.6.1, 1.6.2。        $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1311        } elsif ($line =~ /^(.+):/) {
1312  差分機能のバグ修正。        $val = $1; $h->{$val} = '';
1313  do_previewで'>'が扱えないバグを修正      }
1314  (ユーザからの指摘)。    }
1315      $h;
1316  =item *  }
1317    
1318  2001年2月22日、Version 1.6.0。  package wiki::dummy;
1319  差分機能を実装した。  sub mtime (@) {undef}
1320    sub meta (@) {undef}
1321  =item *  sub Yuki::YukiWikiDB2::meta (@) {undef}
1322    
1323  2001年2月19日、Version 1.5.4。  package SuikaWiki::Plugin;
1324  画像ファイルへのリンクは画像にしてみた。    our $plugin_directory;  # defined in top of this file.
1325      our %List;
1326  =item *    our %Index;
1327    
1328  2001年2月19日、Version 1.5.3。  sub escape ($$) { main::escape ($_[1]) }
1329  RecentChangesの中に削除したページがあるのをやめた。  sub unescape ($$) { main::unescape ($_[1]) }
1330  use strict;で引っかかる部分を少し整理(完全ではない)。  sub encode ($$) { main::encode ($_[1]) }
1331    sub decode ($$) { main::decode ($_[1]) }
1332  =item *  sub __get_datetime ($) { main::get_now () }
1333    sub resource ($$;%) { shift; &main::Resource (@_) }
1334  2001年2月16日、Version 1.5.2。  sub uri ($$) { $main::uri{$_[1]} }
1335  textareaに表示およびプレビューする前に < や > を &lt; や &gt; に変換した  sub new_index ($$) { ++$Index{$_[1]} }
1336  (do_preview, editpage, print_preview_buttons)。  
1337    sub regist ($@) {
1338  =item *      my $pack = shift;
1339        for (@_) {
1340  2000年12月27日、Version 1.5.1。          push @{$List{$_}}, $pack;
1341  プレビュー画面を整理した。      }
1342    }
1343  =item *  
1344    sub import_plugins () {
1345  2000年12月22日、Version 1.5.0。      opendir PDIR, $plugin_directory;
1346  全体的にずいぶん書き直した。      my @plugin = grep {s/\.pm$//} readdir (PDIR);
1347  一覧を別途作成するようにした(do_list)。      closedir PDIR;
1348  書き込む前に確認画面を出すようにした(do_preview)。      for (@plugin) {
1349  テキストの書き方を編集画面に入れた(do_edit, do_reedit)。          eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1350  WhatsNew→RecentChanges、TopPage→FrontPageに変更した。          push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1351        }
1352  =item *  }
1353    
1354  2000年12月20日、Version 1.1.0。  &import_plugins ();
1355  tieを利用して、dbmopenが使えない場合でも動作するように修正。  
1356  利用者の1人である「極悪」さんから  package wiki::conneg;
1357  送っていただいたコードを元にしています。  
1358    ## BUG: this parser isn't strict.
1359  =item *  sub get_accept_lang (;$) {
1360      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1361  2000年9月5日、Version 1.0.2。    my %alang = (ja => 0.0002, en => 0.0001);
1362   <body color=...> → <body bgcolor=...>    my $i = 0.1;
1363  利用者からの指摘による。感謝。    for (split /\s*,\s*/, $alang) {
1364        tr/\x09\x0A\x0D\x20//d;
1365  =item *      if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1366          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1367  2000年8月6日、Version 1.0.1を公開。        $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1368  C MAGAZINE(ソフトバンクパブリッシング)        $alang{$l} += $i unless $alang{$l} == 0;
1369  2000年10月号連載記事向け公開版。        $i -= 0.001;
1370  [[ ]] の最後が「望」のようにシフトJISで      }
1371  0x5Dになる場合の回避を行なった。    }
1372      \%alang;
1373  =item *  }
1374    
1375  2000年8月5日、Version 1.0.0を公開。  package wiki::resource;
1376    
1377  =item *  sub get ($;\%) {
1378      my ($resname, $option) = @_;
1379  2000年7月23日、Version 0.82を公開。    $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1380  編集時のリンクミス。    $option->{resource} ||= {};
1381  <textarea>の属性変更。    my $v;
1382      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1383  =item *      while (length $lang) {
1384          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1385  2000年7月22日、Version 0.81を公開。          $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1386  ロゴを組み込む。          $v = $option->{resource}->{$lang}->{$resname};
1387            last if defined $v;
1388  =item *        }
1389          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1390  2000年7月21日、Version 0.80を公開。      }
1391  PODをCGI中に書き込む。      last if defined $v;
1392      }
1393  =item *    defined $v ? $v : $resname;
1394    }
1395  2000年7月19日、Version 0.70を公開。  
1396  '''イタリック'''や、--、---、>>、>>>などを実装。  package main;
1397    &main;
1398  =item *  exit 0;
1399    
1400  2000年7月18日、Version 0.60を公開。  1;
1401  *太字*を''太字''に変更  __END__
1402    =head1 NAME
1403  =item *  
1404    wiki.cgi --- SuikaWiki: Yet yet another Wiki engine
1405  2000年7月17日、Version 0.50を公開。  
1406    =head1 AUTHORS
1407  =item *  
1408    Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/>
1409  2000年7月17日、さらにいろいろ追加する。  
1410    Makio Tsukamoto <http://digit.que.ne.jp/>
1411  =item *  
1412    Wakaba <w@suika.fam.cx>
1413  2000年7月16日、いろいろ追加。  
1414    =head1 LICENSE
1415  =item *  
1416    Copyright (C) 2000-2003 AUTHORS
1417  2000年7月15日、公開。  
1418    This program is free software; you can redistribute it and/or
1419  =back  modify it under the same terms as Perl itself.
1420    
1421  =head1 TODO  =cut
   
     - テキスト表示モード  
     - Charsetを明示。  
     - textarea中の閉じタグ対応  
     - メニューの英語表記付記  
     - プレビューのボタンで、mymsgをinputのvalueに入れているが、改行をそのままvalueにいれてはいけないのではないか。  
     - 「再編集」の機能はブラウザの back で充分ではないか。プレビューはもっとシンプルに。  
     - ページタイトル(Wikiname)が検索にかかるようにする。  
     - InterWiki風の機能「URLを隠しつつ、リンクを張る」  
   
 =head1 作者  
   
     Copyright (C) 2000 by Hiroshi Yuki.  
     結城浩 <hyuki@hyuki.com>  
     http://www.hyuki.com/  
     http://www.hyuki.com/yukiwiki/  
   
 質問、意見、バグ報告は hyuki@hyuki.com にメールしてください。  
   
 =head1 配布条件  
   
 YukiWikiは、  
 GNU General Public Licenseにて公開します。  
   
 YukiWikiはフリーソフトです。  
 ご自由にお使いください。  
 自分好みのYukiWikiが作れるようにシンプルにしてあります。  
   
 =head1 謝辞  
   
 本家のWikiWikiを作ったCunningham & Cunningham, Inc.に  
 感謝します。  
   
 YukiWikiを楽しんで使ってくださる  
 ネット上の方々に感謝します。  
   
 YukiWikiのロゴをデザインしてくださった橋本礼奈さん  
 http://city.hokkai.or.jp/~reina/  
 に感謝します。  
   
 tieを使った版の元になるコードを送ってくださった  
 「極悪」さんに感謝します。  
   
 =head1 参照リンク  
   
 =over 4  
   
 =item *  
   
 YukiWikiホームページ  
 http://www.hyuki.com/yukiwiki/  
   
 =item *  
   
 本家のWikiWiki  
 http://c2.com/cgi/wiki?WikiWikiWeb  
   
 =item *  
   
 本家のWikiWikiの作者(Cunningham & Cunningham, Inc.)  
 http://c2.com/  
   
 =item *  
   
 YukiWikiのロゴデザインをしてくださった橋本礼奈さんのページ  
 http://city.hokkai.or.jp/~reina/  
   
 =back  
   
 =cut  

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24