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