1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
|
#!perl |
|
2 |
# |
# |
3 |
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
4 |
# |
# |
9 |
# This program is free software; you can redistribute it and/or |
# This program is free software; you can redistribute it and/or |
10 |
# modify it under the same terms as Perl itself. |
# modify it under the same terms as Perl itself. |
11 |
# |
# |
|
############################## |
|
|
# |
|
12 |
# walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
# walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
|
# |
|
|
# WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。 |
|
|
# |
|
|
# * 更新内容 |
|
|
# |
|
|
# 2.0.beta1.wal.1 on 2002/05/19,22:32:19 |
|
|
# (1) Footerの変更 |
|
|
# (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない |
|
|
# (3) 別名リンク([別名 URL])に対応。 |
|
|
# (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。 |
|
|
# (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成 |
|
|
# (6) HTMLモード対応。 |
|
|
# |
|
|
# 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。 |
|
|
# ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。 |
|
|
# - インラインの画像変換 |
|
|
# - YukiWikiDB対応 |
|
|
# - テーブル |
|
|
# - DB関連モジュールuseのeval化 |
|
|
# - BracketNameによるキーからブラケットを排除 |
|
|
# ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。 |
|
|
# [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。 |
|
|
# |
|
|
#======================================= |
|
13 |
|
|
14 |
# Walrus add (debug) start |
# Walrus add (debug) start |
15 |
my $walrus_log; |
my $walrus_log; |
26 |
use Yuki::YukiWikiDB; |
use Yuki::YukiWikiDB; |
27 |
use AnyDBM_File; |
use AnyDBM_File; |
28 |
require 'jcode.pl'; |
require 'jcode.pl'; |
29 |
# use Jcode; |
require Jcode; |
30 |
use Fcntl; |
use Fcntl; |
31 |
my $version = '2.0.beta1.2002-05-29'; |
my $version = '2.0.beta1.2002-05-29'; |
32 |
my $walversion; |
my $walversion; |
43 |
# my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail. |
# my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail. |
44 |
my $modifier_sendmail = ''; # If you don't need mail notification. |
my $modifier_sendmail = ''; # If you don't need mail notification. |
45 |
my $modifier_dir_data = './wikidata'; # Your data directory. |
my $modifier_dir_data = './wikidata'; # Your data directory. |
46 |
my $modifier_rss_title = "WalWiki $walversion"; |
my $modifier_rss_title = "SuikaWiki $walversion"; |
47 |
my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed. |
my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed. |
48 |
my $modifier_rss_description = 'This is WalWiki, yet another Wiki clone based on YukiWiki'; |
my $modifier_rss_description = 'This is SuikaWiki'; |
49 |
############################## |
############################## |
50 |
# |
# |
51 |
# You MAY modify following variables. |
# You MAY modify following variables. |
55 |
my $file_FrontPage = "$modifier_dir_data/frontpage.txt"; |
my $file_FrontPage = "$modifier_dir_data/frontpage.txt"; |
56 |
my $file_conflict = "$modifier_dir_data/conflict.txt"; |
my $file_conflict = "$modifier_dir_data/conflict.txt"; |
57 |
my $file_format = "$modifier_dir_data/format.txt"; |
my $file_format = "$modifier_dir_data/format.txt"; |
58 |
my $url_cgi = 'wiki'; |
my $url_cgi = '/~wakaba/-temp/wiki/wiki'; ## MUST be started from '/' |
59 |
my $url_stylesheet = 'wiki-style.css'; |
my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle'; |
60 |
my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />'; |
my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />'; |
61 |
my $maxrecent = 50; |
my $maxrecent = 50; |
62 |
my $cols = 80; |
my $cols = 80; |
83 |
my $CreatePage = 'CreatePage'; |
my $CreatePage = 'CreatePage'; |
84 |
my $ErrorPage = 'ErrorPage'; |
my $ErrorPage = 'ErrorPage'; |
85 |
my $RssPage = 'RssPage'; |
my $RssPage = 'RssPage'; |
86 |
|
my $NAME_OF_WikiPageLicense = 'WikiPageLicense'; |
87 |
my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. |
my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. |
88 |
############################## |
############################## |
|
# my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b'; # Walrus del (2) |
|
|
my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b'; # Walrus add (2) |
|
89 |
my $bracket_name = '\[\[(\S+?)\]\]'; |
my $bracket_name = '\[\[(\S+?)\]\]'; |
90 |
my $embedded_name = '\[\[(#\S+?)\]\]'; |
my $embedded_name = '\[\[(#\S+?)\]\]'; |
91 |
my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]'; |
my %fmt; ## formatter objects |
|
my $interwiki_name = '([^:]+):([^:].*)'; |
|
92 |
############################## |
############################## |
93 |
my $embed_comment = '[[#comment]]'; |
my $embed_comment = '[[#comment]]'; |
94 |
my $embed_rcomment = '[[#rcomment]]'; |
my $embed_rcomment = '[[#rcomment]]'; |
95 |
|
my $embed_comment_Name_Prompt = '名前:'; |
96 |
|
my $DEFAULT_embed_comment_name = '名無しさん'; |
97 |
my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5) |
my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5) |
98 |
|
my %embed_command = ( |
99 |
|
searched => '^\[\[#searched:([^\]]+)\]\]$', |
100 |
|
form => qw/\[\[\#form:'((?:[^'\\]|\\.)+)':'((?:[^'\\]|\\.)+)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
101 |
|
); |
102 |
############################## |
############################## |
103 |
my $info_LastModified = 'LastModified'; |
my $info_LastModified = 'LastModified'; |
104 |
my $info_IsFrozen = 'IsFrozen'; |
my $info_IsFrozen = 'IsFrozen'; |
117 |
$AdminChangePassword => 1, |
$AdminChangePassword => 1, |
118 |
$CompletedSuccessfully => 1, |
$CompletedSuccessfully => 1, |
119 |
#$FrontPage => 1, |
#$FrontPage => 1, |
120 |
|
WikiUserAgentList => 1, |
121 |
); |
); |
122 |
my %form; |
my %form; |
123 |
my %database; |
my %database; |
136 |
); |
); |
137 |
my %command_do = ( |
my %command_do = ( |
138 |
read => \&do_read, |
read => \&do_read, |
139 |
|
TEXT_CSS => \&do_output_css, |
140 |
edit => \&do_edit, |
edit => \&do_edit, |
141 |
adminedit => \&do_adminedit, |
adminedit => \&do_adminedit, |
142 |
adminchangepasswordform => \&do_adminchangepasswordform, |
adminchangepasswordform => \&do_adminchangepasswordform, |
149 |
createresult => \&do_createresult, |
createresult => \&do_createresult, |
150 |
FrontPage => \&do_FrontPage, |
FrontPage => \&do_FrontPage, |
151 |
comment => \&do_comment, |
comment => \&do_comment, |
152 |
|
RandomJump => \&do_random_jump, |
153 |
rss => \&do_rss, |
rss => \&do_rss, |
154 |
diff => \&do_diff, |
diff => \&do_diff, |
155 |
interwikibox => \&do_interwiki_box, # Walrus add (5) |
interwikibox => \&do_interwiki_box, # Walrus add (5) |
156 |
|
wikiform => \&do_wikiform, |
157 |
); |
); |
158 |
############################## |
############################## |
|
my @ignore_html_page = ('FrontPage'); # Walrus add (6) |
|
|
my @ignore_html_tags = ('a', 'br', 'img'); # Walrus add (6) |
|
159 |
my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) |
my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) |
160 |
############################## |
############################## |
161 |
# &test_convert; |
# &test_convert; |
162 |
|
my $UA = ''; ## User agent name |
163 |
&main; |
&main; |
164 |
exit(0); |
exit(0); |
165 |
############################## |
############################## |
166 |
|
|
167 |
sub main { |
sub main { |
168 |
|
$UA = $main::ENV{HTTP_USER_AGENT}; |
169 |
&init_resource; |
&init_resource; |
170 |
&open_db; |
&open_db; |
171 |
&init_form; |
&init_form; |
179 |
} |
} |
180 |
|
|
181 |
sub do_read { |
sub do_read { |
182 |
&print_header($form{mypage}); |
my $content = $database{$form{mypage}}; |
183 |
&print_content($database{$form{mypage}}); |
my $lm = &get_info($form{mypage}, $info_LastModified); |
184 |
&print_footer($form{mypage}); |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
185 |
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
186 |
|
my ($r, $c) = get_search_result ($form{mypage}); |
187 |
|
my $rl = wiki::referer::list_html ($form{mypage}); |
188 |
|
my @toc; |
189 |
|
push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c; |
190 |
|
push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl; |
191 |
|
my $cf = 'SuikaWiki/0.9'; |
192 |
|
## Should be support at least: |
193 |
|
## - 'SuikaWiki/0.9' CRLF |
194 |
|
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
195 |
|
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
196 |
|
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
197 |
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
198 |
|
&print_header ($form{mypage}, -last_modified => $lm, |
199 |
|
-content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/); |
200 |
|
&print_content ($content, content_format => $cf, last_modified => $lm, |
201 |
|
-toc => \@toc); |
202 |
|
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}}; |
203 |
|
} else { |
204 |
|
&print_header($form{mypage}, -last_modified => $lm); |
205 |
|
print "<pre>@{[&escape($content)]}</pre>"; |
206 |
|
} |
207 |
|
if ($c) { |
208 |
|
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>}; |
209 |
|
print $r; |
210 |
|
} |
211 |
|
if ($rl) { |
212 |
|
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n); |
213 |
|
} |
214 |
|
&print_footer($form{mypage}, $lm); |
215 |
|
} |
216 |
|
|
217 |
|
sub do_output_css { |
218 |
|
my $content = $database{$form{mypage}}; |
219 |
|
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
220 |
|
my $lm = &get_info($form{mypage}, $info_LastModified); |
221 |
|
print "Content-Type: text/css; charset=$charset\n"; |
222 |
|
print "Last-Modified: $lm\n"; |
223 |
|
print "\n"; |
224 |
|
print $content; |
225 |
|
} else { |
226 |
|
print "Status: 406 Unsupported Media Type\n"; |
227 |
|
&print_header('WikiPageIsNotCSS', -noindex => 1); |
228 |
|
&print_content($database{WikiPageIsNotCSS}); |
229 |
|
&print_footer('WikiPageIsNotCSS'); |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
|
sub id_and_name ($) { |
234 |
|
my $name = shift; |
235 |
|
if ($UA =~ m#Mozilla/[12]\.#) { |
236 |
|
qq{id="$name"><a name="$name"></a}; |
237 |
|
} else { |
238 |
|
qq{id="$name"}; |
239 |
|
} |
240 |
} |
} |
241 |
|
|
242 |
sub do_edit { |
sub do_edit { |
243 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
244 |
&print_header($page); |
&print_header($page, -noindex => 1); |
245 |
if (not &is_editable($page)) { |
if (not &is_editable($page)) { |
246 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
247 |
} elsif (&is_frozen($page)) { |
} elsif (&is_frozen($page)) { |
249 |
} else { |
} else { |
250 |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
251 |
} |
} |
252 |
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
253 |
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
254 |
|
my ($r, $c) = get_search_result ($form{mypage}); |
255 |
|
my $rl = wiki::referer::list_html ($form{mypage}); |
256 |
|
if ($c) { |
257 |
|
print q{<h2 id="wikipage-see-also">See also</h2>}; |
258 |
|
print $r; |
259 |
|
} |
260 |
|
if ($rl) { |
261 |
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
262 |
|
} |
263 |
&print_footer($page); |
&print_footer($page); |
264 |
} |
} |
265 |
|
|
266 |
sub do_adminedit { |
sub do_adminedit { |
267 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
268 |
&print_header($page); |
&print_header($page, -noindex => 1); |
269 |
if (not &is_editable($page)) { |
if (not &is_editable($page)) { |
270 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
271 |
} else { |
} else { |
276 |
} |
} |
277 |
|
|
278 |
sub do_adminchangepasswordform { |
sub do_adminchangepasswordform { |
279 |
&print_header($AdminChangePassword); |
&print_header($AdminChangePassword, -noindex => 1); |
280 |
&print_passwordform; |
&print_passwordform; |
281 |
&print_footer($AdminChangePassword); |
&print_footer($AdminChangePassword); |
282 |
} |
} |
303 |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
304 |
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
305 |
|
|
306 |
&print_header($CompletedSuccessfully); |
&print_header($CompletedSuccessfully, -noindex => 1); |
307 |
&print_message($resource{passwordchanged}); |
&print_message($resource{passwordchanged}); |
308 |
&print_footer($CompletedSuccessfully); |
&print_footer($CompletedSuccessfully); |
309 |
} |
} |
313 |
print qq(<ul>); |
print qq(<ul>); |
314 |
foreach my $page (sort keys %database) { |
foreach my $page (sort keys %database) { |
315 |
if (&is_editable($page)) { |
if (&is_editable($page)) { |
316 |
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">$page</a>@{[&escape(&get_subjectline($page))]}</li>); |
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
317 |
# print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>); |
# print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>); |
318 |
# print qq(<li>@{[0 + &is_frozen($page)]}</li>); |
# print qq(<li>@{[0 + &is_frozen($page)]}</li>); |
319 |
} |
} |
328 |
} |
} |
329 |
|
|
330 |
if (not &is_editable($form{mypage})) { |
if (not &is_editable($form{mypage})) { |
331 |
&print_header($form{mypage}); |
&print_header($form{mypage}, -noindex => 1); |
332 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
333 |
&print_footer($form{mypage}); |
&print_footer($form{mypage}); |
334 |
return; |
return; |
355 |
&update_recent_changes; |
&update_recent_changes; |
356 |
} |
} |
357 |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
358 |
&print_header($CompletedSuccessfully); |
my $fragment; |
359 |
|
if ($form{__comment_anchor_index}) { |
360 |
|
$fragment = qq(anchor-$form{__comment_anchor_index}); |
361 |
|
} elsif ($form{__wikiform_anchor_index}) { |
362 |
|
$fragment = qq(wikiform-$form{__wikiform_anchor_index}); |
363 |
|
} |
364 |
|
&print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($fragment?'#'.$fragment:'')); |
365 |
&print_message($resource{saved}); |
&print_message($resource{saved}); |
366 |
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
367 |
&print_footer($CompletedSuccessfully); |
&print_footer($CompletedSuccessfully); |
372 |
if ($form{mytouch}) { |
if ($form{mytouch}) { |
373 |
&update_recent_changes; |
&update_recent_changes; |
374 |
} |
} |
375 |
&print_header($form{mypage}); |
&print_header($form{mypage}, -noindex => 1); |
376 |
&print_message($resource{deleted}); |
&print_message($resource{deleted}); |
377 |
&print_footer($form{mypage}); |
&print_footer($form{mypage}); |
378 |
} |
} |
385 |
} |
} |
386 |
|
|
387 |
sub do_search { |
sub do_search { |
388 |
my $word = &escape($form{mymsg}); |
my $word = $form{mymsg}; |
389 |
&print_header($SearchPage); |
&print_header($SearchPage); |
390 |
&print_searchform($word); |
&print_searchform(&escape($word)); |
391 |
my $counter = 0; |
print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1); |
|
foreach my $page (sort keys %database) { |
|
|
next if $page =~ /^$RecentChanges$/; |
|
|
if ($database{$page} =~ /\Q$form{mymsg}\E/ or $page =~ /\Q$form{mymsg}\E/) { |
|
|
if ($counter == 0) { |
|
|
print qq|<ul>|; |
|
|
} |
|
|
print qq(<li><a href ="$url_cgi?@{[&encode($page)]}">$page</a>@{[&escape(&get_subjectline($page))]}</li>); |
|
|
$counter++; |
|
|
} |
|
|
} |
|
|
if ($counter == 0) { |
|
|
&print_message($resource{notfound}); |
|
|
} else { |
|
|
print qq|</ul>|; |
|
|
} |
|
392 |
&print_footer($SearchPage); |
&print_footer($SearchPage); |
393 |
} |
} |
394 |
|
|
395 |
|
sub get_search_result ($;%) { |
396 |
|
my $word = lc shift; |
397 |
|
my %option = @_; |
398 |
|
my @r; |
399 |
|
foreach my $page (keys %database) { |
400 |
|
next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself}); |
401 |
|
my $content = $database{$page}; |
402 |
|
my $cf = 'SuikaWiki/0.9'; |
403 |
|
$cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s; |
404 |
|
next if $cf =~ /obsoleted="yes"/; |
405 |
|
if (index (lc $page, $word) > -1) { |
406 |
|
my $c = $content =~ s/\Q$word\E//gi; |
407 |
|
push @r, [$page, $c+20]; |
408 |
|
} elsif (index ($word, lc $page) > -1) { |
409 |
|
my $c = $content =~ s/\Q$word\E//gi; |
410 |
|
push @r, [$page, $c+10]; |
411 |
|
} elsif (my $c = $content =~ s/\Q$word\E//gi) { |
412 |
|
push @r, [$page, $c]; |
413 |
|
} |
414 |
|
} |
415 |
|
my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s }; |
416 |
|
my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
417 |
|
$r = qq|<ul class="search-result">$r</ul>| if $r; |
418 |
|
get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found}; |
419 |
|
wantarray? ($r, scalar @r): $r; |
420 |
|
} |
421 |
|
|
422 |
sub do_create { |
sub do_create { |
423 |
&print_header($CreatePage); |
&print_header($CreatePage); |
424 |
print <<"EOD"; |
print <<"EOD"; |
432 |
&print_footer($CreatePage); |
&print_footer($CreatePage); |
433 |
} |
} |
434 |
|
|
435 |
|
sub do_random_jump { |
436 |
|
my @list = keys %database; |
437 |
|
my $name = &encode ($list[rand @list]); |
438 |
|
my ($scheme) = 'http'; |
439 |
|
$scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
440 |
|
print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n"; |
441 |
|
print "\n"; |
442 |
|
} |
443 |
|
|
444 |
sub do_FrontPage { |
sub do_FrontPage { |
445 |
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
446 |
my $content = join('', <FILE>); |
my $content = join('', <FILE>); |
453 |
|
|
454 |
sub print_error { |
sub print_error { |
455 |
my ($msg) = @_; |
my ($msg) = @_; |
456 |
&print_header($ErrorPage); |
&print_header($ErrorPage, -noindex => 1); |
457 |
print qq(<p><strong class="error">$msg</strong></p>); |
print qq(<p><strong class="error">$msg</strong></p>); |
458 |
&print_footer($ErrorPage); |
&print_footer($ErrorPage); |
459 |
exit(0); |
exit(0); |
460 |
} |
} |
461 |
|
|
462 |
sub print_header { |
sub print_header ($;%) { |
463 |
my ($page) = @_; |
my ($page, %option) = @_; |
464 |
my $bodyclass = "normal"; |
my $bodyclass = "normal"; |
|
my $editable = 0; |
|
|
my $admineditable = 0; |
|
465 |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
|
$editable = 0; |
|
|
$admineditable = 1; |
|
466 |
$bodyclass = "frozen"; |
$bodyclass = "frozen"; |
467 |
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
} |
468 |
$admineditable = 1; |
$bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
469 |
$editable = 1; |
if ($option{-goto}) { |
470 |
|
if ($UA =~ m#Mozilla/[12]\.|Opera#) { |
471 |
|
$option{-goto} =~ tr/;/&/; |
472 |
|
print qq{Refresh: 0; url=$option{-goto}\n}; |
473 |
|
$option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">); |
474 |
|
} else { |
475 |
|
print qq{Refresh: 0; url="$option{-goto}"\n}; |
476 |
|
$option{-goto} = qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"">); |
477 |
|
} |
478 |
|
} |
479 |
|
print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; |
480 |
|
my $meta_ct = ''; |
481 |
|
if ($UA =~ m#Mozilla/2#) { |
482 |
|
$meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}}; |
483 |
|
print qq{Content-Type: $meta_ct\n}; |
484 |
|
$meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">}; |
485 |
} else { |
} else { |
486 |
$editable = 0; |
print qq{Content-Type: text/html; charset=$charset\n}; |
487 |
} |
} |
488 |
my $cookedpage = &encode($page); |
my $cookedpage = &encode($page); |
489 |
|
my $escapedpage = &escape($page); |
490 |
print <<"EOD"; |
print <<"EOD"; |
|
Content-type: text/html; charset=$charset |
|
491 |
Content-Language: $lang |
Content-Language: $lang |
492 |
Content-Style-Type: text/css |
Content-Style-Type: text/css |
493 |
|
|
494 |
|
<!-- |
495 |
<!DOCTYPE html |
<!DOCTYPE html |
496 |
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
497 |
"http://www.w3.org/TR/html4/loose.dtd"> |
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
498 |
<html lang="$lang"> |
<html lang="$lang"> |
499 |
<head> |
<head> |
500 |
<title>$page @{[&escape(&get_subjectline($page))]}</title> |
$meta_ct$option{-goto} |
501 |
|
<title>$escapedpage</title> |
502 |
<link rel="index" href="$url_cgi?$IndexPage"> |
<link rel="index" href="$url_cgi?$IndexPage"> |
503 |
<link rev="made" href="mailto:$modifier_mail"> |
<link rel="help" href="$url_cgi?WikiHelp"> |
504 |
<link rel="stylesheet" type="text/css" href="$url_stylesheet"> |
<link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense"> |
505 |
|
<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}"> |
506 |
|
@{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']} |
507 |
</head> |
</head> |
508 |
<body class="$bodyclass"> |
<body class="$bodyclass"> |
509 |
|
EOD |
510 |
|
&print_navigate_links ($page); |
511 |
|
print <<EOD; |
512 |
|
<h1 class="header">@{[&escape($page)]}</h1> |
513 |
|
EOD |
514 |
|
} |
515 |
|
|
516 |
|
sub x_charset ($) { |
517 |
|
my $charset = lc shift; |
518 |
|
if ($charset eq 'euc-jp') { |
519 |
|
$charset = 'x-euc-jp'; |
520 |
|
} elsif ($charset eq 'shift_jis') { |
521 |
|
$charset = 'x-sjis'; |
522 |
|
} |
523 |
|
$charset; |
524 |
|
} |
525 |
|
|
526 |
|
sub print_navigate_links (@) { |
527 |
|
my ($page) = @_; |
528 |
|
my $editable = 0; |
529 |
|
my $admineditable = 0; |
530 |
|
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
531 |
|
$editable = 0; |
532 |
|
#$admineditable = 1; |
533 |
|
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
534 |
|
#$admineditable = 1; |
535 |
|
$editable = 1; |
536 |
|
} else { |
537 |
|
$editable = 0; |
538 |
|
} |
539 |
|
my $cookedpage = &encode($page); |
540 |
|
print <<EOH; |
541 |
<div class="tools"> |
<div class="tools"> |
542 |
@{[ $admineditable |
@{[ $admineditable |
543 |
? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | ) |
? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | ) |
544 |
: qq() |
: qq() |
545 |
]} |
]} |
546 |
@{[ $editable |
@{[ $editable |
547 |
? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage">$resource{editbutton}</a> | ) |
? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | ) |
548 |
|
qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | ) |
549 |
: qq() |
: qq() |
550 |
]} |
]} |
551 |
|
<a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">表示</a> | |
552 |
@{[ $admineditable |
@{[ $admineditable |
553 |
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
554 |
: qq() |
: qq() |
555 |
]} |
]} |
556 |
<a href="$url_cgi?$CreatePage">$resource{createbutton}</a> | |
<a href="$url_cgi?$CreatePage" class="wiki">新規</a> | |
557 |
<a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> | |
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
558 |
<a href="$url_cgi?$RssPage">$resource{rssbutton}</a> | |
<a href="$url_cgi?$FrontPage" class="wiki">首頁</a> | |
559 |
<a href="$url_cgi?$FrontPage">$FrontPage</a> | |
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
560 |
<a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> | |
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
561 |
<a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a> |
<a href="$url_cgi?$RecentChanges" class="wiki">最新</a> |
562 |
</div> |
</div> |
563 |
<h1 class="header"><a |
EOH |
564 |
title="$resource{searchthispage}" |
<<EOH; ## temp |
565 |
href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1> |
<a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> | |
566 |
EOD |
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
567 |
|
<!-- <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | --> |
568 |
|
<a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> | |
569 |
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
570 |
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
571 |
|
<a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a> |
572 |
|
</div> |
573 |
|
EOH |
574 |
} |
} |
575 |
|
|
576 |
sub print_footer { |
sub print_footer { |
577 |
my ($page) = @_; |
my ($page, $lm) = @_; |
578 |
|
my $epage = &encode ($page); |
579 |
$walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) |
$walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) |
580 |
# Walrus mod (1) start |
# Walrus mod (1) start |
581 |
my $cvslog = '$Revision$ $Date$'; |
my $cvslog1 = q$Revision$; |
582 |
print <<"EOD"; |
my $cvslog2 = q$Date$; |
583 |
|
print_navigate_links ($page); |
584 |
|
print <<"EOD"; |
585 |
|
@{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]} |
586 |
<div class="footer"> |
<div class="footer"> |
587 |
<p> |
<a href="http://www.hyuki.com/yukiwiki/" title="$version © 2000-2002 by Hiroshi Yuki">YukiWiki</a> <a href="http://digit.que.ne.jp/work/" title="$walversion © 2000-2002 by Makio Tsukamoto">WalWiki</a> |
588 |
<a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion © 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br /> |
<a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a> |
|
based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version © 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br /> |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="CVS Repository"> |
|
|
$cvslog |
|
|
</a> |
|
|
</p> |
|
589 |
<div class="navigation"> |
<div class="navigation"> |
590 |
[<a href="/" title="このサーバーの首頁">/</a> |
[<a href="/" title="このサーバーの首頁">/</a> |
591 |
<a href="/map" title="このサーバーの案内">地図</a> |
<a href="/map" title="このサーバーの案内">地図</a> |
592 |
<a href="/search/" title="このサーバーの検索">検索</a>] |
<a href="/search/" title="このサーバーの検索">検索</a>] |
593 |
</div> |
</div> |
594 |
|
<div class="myuri"> |
595 |
|
<<a href="$url_cgi?$epage">$url_cgi?$epage</a>> |
596 |
|
</div> |
597 |
</div> |
</div> |
598 |
$walrus_log |
$walrus_log |
599 |
</body> |
</body> |
600 |
</html> |
</html> |
601 |
EOD |
EOD |
|
# print <<"EOD"; |
|
|
# <hr> |
|
|
# <address class="footer"> |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version |
|
|
# © 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br /> |
|
|
# Modified by <a href="$modifier_url">$modifier_name</a>. |
|
|
# </address> |
|
|
# <p class="footer"> |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">$icontag</a> |
|
|
# </p> |
|
|
# </body> |
|
|
# </html> |
|
|
# EOD |
|
|
# Walrus mod (1) end |
|
602 |
} |
} |
603 |
|
|
604 |
sub escape { |
sub escape { |
605 |
my $s = shift; |
my $s = shift; |
606 |
$s =~ s|\r\n|\n|g; |
$s =~ s|\r\n|\n|g; |
607 |
$s =~ s|\&|&|g; |
$s =~ s|&|&|g; |
608 |
$s =~ s|<|<|g; |
$s =~ s|<|<|g; |
609 |
$s =~ s|>|>|g; |
$s =~ s|>|>|g; |
610 |
$s =~ s|"|"|g; |
$s =~ s|"|"|g; |
614 |
sub unescape { |
sub unescape { |
615 |
my $s = shift; |
my $s = shift; |
616 |
# $s =~ s|\n|\r\n|g; |
# $s =~ s|\n|\r\n|g; |
617 |
$s =~ s|\&|\&|g; |
$s =~ s|<|<|g; |
618 |
$s =~ s|\<|\<|g; |
$s =~ s|>|>|g; |
619 |
$s =~ s|\>|\>|g; |
$s =~ s|"|"|g; |
620 |
$s =~ s|\"|\"|g; |
$s =~ s|&|&|g; |
621 |
return $s; |
return $s; |
622 |
} |
} |
623 |
|
|
624 |
sub print_content { |
sub print_content ($;$) { |
625 |
my ($rawcontent) = @_; |
my ($rawcontent, %option) = @_; |
626 |
print &text_to_html($rawcontent, toc=>1); |
print &text_to_html($rawcontent, toc=>1, %option); |
627 |
} |
} |
628 |
|
|
629 |
sub text_to_html { |
sub text_to_html { |
630 |
my ($txt, %option) = @_; |
my ($txt, %option) = @_; |
631 |
my (@txt) = split(/\n/, $txt); |
my (@txt) = split(/\n/, $txt); |
632 |
my (@toc); |
my @toc; |
633 |
|
my @toc2 = @{$option{-toc}||[]}; |
634 |
my $tocnum = 0; |
my $tocnum = 0; |
635 |
my (@saved, @result); |
my (@saved, @result); |
636 |
unshift(@saved, "</p>"); |
unshift(@saved, "</p>"); |
637 |
push(@result, "<p>"); |
push(@result, "<p>"); |
638 |
foreach (@txt) { |
foreach (@txt) { |
639 |
chomp; |
chomp; |
640 |
# Walrus mod (6) start |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
641 |
#if ($saved[0] eq '</html>') { |
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
# if (/<\/html>/i) { splice(@saved); } |
|
|
# else { push (@result, &html_to_ignored_html($_)); } |
|
|
#} elsif (/^<html>/i and &is_ignore_html($form{mypage})) { |
|
|
# push(@result, splice(@saved)); |
|
|
# push(@saved, '</html>'); |
|
|
#} els |
|
|
if (/^\*\*\*\*\*(.*)/) { |
|
|
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
|
642 |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
643 |
$tocnum++; |
$tocnum++; |
644 |
} elsif (/^\*\*\*\*(.*)/) { |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
645 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
646 |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
647 |
$tocnum++; |
$tocnum++; |
648 |
} elsif (/^\*\*\*(.*)/) { |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
649 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
650 |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
651 |
$tocnum++; |
$tocnum++; |
652 |
} elsif (/^\*\*(.*)/) { |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
653 |
# if (/^\*\*(.*)/) { |
# if (/^\*\*(.*)/) { |
654 |
# Walrus mod (6) end |
# Walrus mod (6) end |
655 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
656 |
push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>'); |
push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>'); |
657 |
$tocnum++; |
$tocnum++; |
658 |
} elsif (/^\*(.*)/) { |
} elsif (/^\*([^\x0D\x0A]*)/) { |
659 |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
660 |
push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>'); |
push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>'); |
661 |
$tocnum++; |
$tocnum++; |
662 |
#} elsif (/^----/) { |
} elsif (/^(={1,6})(.*)/) { |
|
# push(@result, splice(@saved), '<hr>'); |
|
|
} elsif (/^(={1,5})(.*)/) { |
|
663 |
&back_push('ol', length($1), \@saved, \@result); |
&back_push('ol', length($1), \@saved, \@result); |
664 |
push(@result, '<li>' . &inline($2) . '</li>'); |
push(@result, '<li>' . &inline($2) . '</li>'); |
665 |
} elsif (/^(-{1,5})(.*)/) { |
} elsif (/^(-{1,6})(.*)/) { |
666 |
&back_push('ul', length($1), \@saved, \@result); |
&back_push('ul', length($1), \@saved, \@result); |
667 |
push(@result, '<li>' . &inline($2) . '</li>'); |
my ($pf, $l) = ('', $2); |
668 |
|
if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { |
669 |
|
my $num = 0+$1; |
670 |
|
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
671 |
|
} |
672 |
|
push(@result, '<li>' . $pf . &inline ($l) . '</li>'); |
673 |
} elsif (/^:([^:]+):(.*)/) { |
} elsif (/^:([^:]+):(.*)/) { |
674 |
&back_push('dl', 1, \@saved, \@result); |
&back_push('dl', 1, \@saved, \@result); |
675 |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
676 |
} elsif (/^(>{1,5})(.*)/) { |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
677 |
&back_push('blockquote', length($1), \@saved, \@result); |
&back_push('blockquote', length($1), \@saved, \@result); |
678 |
|
push @result, "<p>"; |
679 |
push(@result, &inline($2)); |
push(@result, &inline($2)); |
680 |
|
unshift @saved, "</p>"; |
681 |
} elsif (/^\s*$/) { |
} elsif (/^\s*$/) { |
682 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
|
unshift(@saved, "</p>"); |
|
683 |
push(@result, "<p>"); |
push(@result, "<p>"); |
684 |
|
unshift(@saved, "</p>"); |
685 |
} elsif (/^(\s+.*)$/) { |
} elsif (/^(\s+.*)$/) { |
686 |
&back_push('pre', 1, \@saved, \@result); |
&back_push('pre', 1, \@saved, \@result); |
687 |
#push(@result, &escape($1)); # Not &inline, but &escape |
#push(@result, &escape($1)); # Not &inline, but &escape |
688 |
push(@result, &inline($1)); # Not &inline, but &escape |
push(@result, &inline($1)); |
689 |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
690 |
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
691 |
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
710 |
push(@result, join('', '<tr>', @value, '</tr>')); |
push(@result, join('', '<tr>', @value, '</tr>')); |
711 |
# XXXXX |
# XXXXX |
712 |
####### |
####### |
713 |
|
} elsif (/^\[(INS|DEL|PRE)\[\s*$/) { |
714 |
|
push @result, splice (@saved), '<'.lc($1).'>'; |
715 |
|
unshift @saved, "</p>"; |
716 |
|
push @result, "<p>"; |
717 |
|
} elsif (/^\](INS|DEL|PRE)\]\s*$/) { |
718 |
|
push @result, splice (@saved), '</'.lc($1).'>'; |
719 |
|
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
720 |
|
my $num = 0+$1; |
721 |
|
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
722 |
|
push @result, &inline ($2); |
723 |
} else { |
} else { |
724 |
push(@result, &inline($_)); |
push(@result, &inline($_)); |
725 |
} |
} |
726 |
} |
} |
727 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
728 |
|
|
729 |
|
my $toc = ''; |
730 |
if ($option{toc}) { |
if ($option{toc}) { |
731 |
# Convert @toc (table of contents) to HTML. |
# Convert @toc (table of contents) to HTML. |
732 |
# This part is taken from Makio Tsukamoto's WalWiki. |
# This part is taken from Makio Tsukamoto's WalWiki. |
733 |
my (@tocsaved, @tocresult); |
my (@tocsaved, @tocresult); |
734 |
foreach (@toc) { |
foreach (@toc,@toc2) { |
735 |
if (/^(-{1,3})(.*)/) { |
if (/^(-{1,6})(.*)$/) { |
736 |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
737 |
push(@tocresult, '<li>' . $2 . '</li>'); |
push(@tocresult, '<li>' . $2 . '</li>'); |
738 |
} |
} |
739 |
} |
} |
740 |
push(@tocresult, splice(@tocsaved)); |
push(@tocresult, splice(@tocsaved)); |
741 |
return join("\n", @tocresult, @result); |
$toc = join("\n", @tocresult); |
742 |
} else { |
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
|
return join("\n", @result); |
|
743 |
} |
} |
744 |
|
$toc .= join("\n", @result); |
745 |
|
$toc =~ s#<p>\n</p>##g; |
746 |
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
747 |
|
$toc =~ s#<pre>\n#<pre>#g; |
748 |
|
$toc; |
749 |
} |
} |
750 |
|
|
751 |
sub back_push { |
sub back_push { |
765 |
sub inline { |
sub inline { |
766 |
my ($line) = @_; |
my ($line) = @_; |
767 |
$line = &escape($line); |
$line = &escape($line); |
768 |
$line =~ s|'''([^']+?)'''|<strong>$1</strong>|g; |
$line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3)}ge; |
769 |
$line =~ s|''([^']+?)''|<em>$1</em>|g; |
$line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g; |
770 |
$line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g; # Date |
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
771 |
$line =~ s! |
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
772 |
( |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g; |
773 |
(?:<(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)> |
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
774 |
| |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g; |
775 |
($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g; |
776 |
| |
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
777 |
($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]] |
$line =~ s|''([^']+)''|<em>$1</em>|g; |
778 |
#| |
$line =~ s{ |
779 |
# ($wiki_name) |
((?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
780 |
) |
|\[\[([^[]+?)]>>([0-9]+)] # [[WikiName]>>1] |
781 |
! |
|>>([0-9]+) |
782 |
&make_link($1) |
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
783 |
!gex; |
}{ |
784 |
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
785 |
|
if ($l) { |
786 |
|
&make_link($l) |
787 |
|
} elsif (defined $page) { |
788 |
|
&make_wikilink ($page, anchor => 0+$anchor); |
789 |
|
} elsif ($anum) { |
790 |
|
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
791 |
|
} elsif ($uri) { |
792 |
|
&make_urilink ($uri); |
793 |
|
} |
794 |
|
}gex; |
795 |
return $line; |
return $line; |
796 |
} |
} |
797 |
|
|
798 |
|
sub make_wikilink ($%) { |
799 |
|
my ($ename, %option) = @_; |
800 |
|
my $name = &unescape ($ename); |
801 |
|
if ($database{$name}) { |
802 |
|
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
803 |
|
if ($option{anchor}) { |
804 |
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
805 |
|
} else { |
806 |
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
807 |
|
} |
808 |
|
} else { |
809 |
|
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>); |
810 |
|
} |
811 |
|
} |
812 |
|
|
813 |
|
sub make_urilink ($;%) { |
814 |
|
require URI; |
815 |
|
my $uri = shift; |
816 |
|
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
817 |
|
$uri = &unescape ($uri); |
818 |
|
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
819 |
|
my ($site, $name) = ($1, $2); |
820 |
|
for ($site, $name) { |
821 |
|
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
822 |
|
} |
823 |
|
if ($interwiki{$site}) { |
824 |
|
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
825 |
|
$site = &escape ($site); $name = &escape ($name); |
826 |
|
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>>); |
827 |
|
} else { |
828 |
|
qq(<未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>); |
829 |
|
} |
830 |
|
} else { |
831 |
|
qq(<不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>); |
832 |
|
} |
833 |
|
} elsif ($uri =~ /^urn:/) { ## URN |
834 |
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
835 |
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
836 |
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
837 |
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
838 |
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
839 |
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
840 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
841 |
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
842 |
|
} else { ## misc. URI |
843 |
|
CGI::Carp::warningsToBrowser (0); |
844 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
845 |
|
CGI::Carp::warningsToBrowser (1); |
846 |
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
847 |
|
} |
848 |
|
} |
849 |
|
|
850 |
|
my $FormIndex = 0; |
851 |
|
sub make_custom_form ($$$) { |
852 |
|
my ($definition, $template, $option) = @_; |
853 |
|
$definition =~ s/\\(.)/$1/g; |
854 |
|
## $template and $option is currently not used in this procedure. |
855 |
|
unless ($main::_EMBEDED) { |
856 |
|
$FormIndex++; |
857 |
|
my $param = bless {}, 'SuikaWiki::Plugin'; |
858 |
|
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
859 |
|
my $r = <<EOH; |
860 |
|
<form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform"> |
861 |
|
<input type="hidden" name="mycmd" value="wikiform"> |
862 |
|
<input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}"> |
863 |
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
864 |
|
<input type="hidden" name="mytouch" value="on"> |
865 |
|
<input type="hidden" name="wikiform_index" value="$FormIndex"> |
866 |
|
EOH |
867 |
|
$r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#; |
868 |
|
$r .= $fmt{form_input}->replace (&unescape ($definition), $param); |
869 |
|
$r .= <<EOH; |
870 |
|
</form> |
871 |
|
EOH |
872 |
|
} else { |
873 |
|
q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>); |
874 |
|
} |
875 |
|
} |
876 |
|
|
877 |
|
## to be obsoleted |
878 |
sub make_link { |
sub make_link { |
879 |
my $chunk = shift; |
my $chunk = shift; |
880 |
# Walrus add (3) start |
# Walrus add (3) start |
881 |
$chunk =~ s/^<(.*)>$/$1/; |
$chunk =~ s/^<(.*)>$/$1/; |
882 |
my $name = $chunk; |
my $name = $chunk; |
|
if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) { |
|
|
($name, $chunk) = ($1, $2); |
|
|
} elsif ($chunk =~ /^mailto:(.*)$/) { |
|
|
$name = $1; |
|
|
} |
|
|
if ($use_autoimg and $name =~ /^(http|https|ftp|):.+\.(png|gif|jpe?g)/) { |
|
|
$name = qq(<img src="$name">) ; |
|
|
} |
|
883 |
$name = &unarmor_name($name); |
$name = &unarmor_name($name); |
884 |
# Walrus add (3) end |
# Walrus add (3) end |
885 |
if ($chunk =~ /^(http|https|ftp):/) { |
if ($chunk =~ /^$embedded_name$/) { |
|
# Walrus mod (3) start |
|
|
# if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) { |
|
|
# return qq(<a href="$chunk"><img src="$chunk"></a>); |
|
|
# } else { |
|
|
# return qq(<a href="$chunk">$chunk</a>); |
|
|
# } |
|
|
return qq(<<a href="$chunk">$name</a>>); |
|
|
# Walrus mod (3) end |
|
|
} elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) { |
|
|
return qq|<<a href="/uri-res/N2L?${name}">$name</a>>|; |
|
|
} elsif ($chunk =~ /^mailto:(.*)/) { |
|
|
# return qq(<a href="$chunk">$2</a>); # Walrus del (3) |
|
|
return qq(<<a href="$chunk">$name</a>>); # Walrus add (3) |
|
|
} elsif ($chunk =~ /^$interwiki_definition$/) { |
|
|
# return qq(<span class="InterWiki">$chunk</span>); # Walrus del (3) |
|
|
return qq(<span class="InterWiki">$name</span>); # Walrus add (3) |
|
|
} elsif ($chunk =~ /^$embedded_name$/) { |
|
886 |
return &embedded_to_html($chunk); |
return &embedded_to_html($chunk); |
887 |
} else { |
} else { |
888 |
$chunk = &unarmor_name($chunk); |
$chunk = &unarmor_name($chunk); |
889 |
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
890 |
my $cookedchunk = &encode($chunk); |
my $cookedchunk = &encode($chunk); |
891 |
if ($chunk =~ /^$interwiki_name$/) { |
if ($database{$chunk}) { |
|
my ($intername, $localname) = ($1, $2); |
|
|
my $remoteurl = $interwiki{$intername}; |
|
|
if ($remoteurl) { |
|
|
# $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus del (4) |
|
|
$remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4) |
|
|
# return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a href="$remoteurl">$name</a>); # Walrus add (3) |
|
|
} else { |
|
|
# return $chunk; # Walrus del (3) |
|
|
return $name; # Walrus add (3) |
|
|
} |
|
|
} elsif ($database{$chunk}) { |
|
892 |
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
893 |
# return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
# return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
894 |
return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$name</a>); # Walrus add (3) |
return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
895 |
} elsif ($page_command{$chunk}) { |
} elsif ($page_command{$chunk}) { |
896 |
# return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
# return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
897 |
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">$name</a>); # Walrus add (3) |
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
898 |
} else { |
} else { |
899 |
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">$name<span class="mark">$editchar</span></a>); |
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>); |
900 |
} |
} |
901 |
} |
} |
902 |
} |
} |
903 |
|
|
|
# Walrus add (6) start |
|
|
sub is_ignore_html { |
|
|
my ($pagename) = @_; |
|
|
foreach (@ignore_html_page) { |
|
|
return 1 if ($pagename eq $_); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
# Walrus add (6) end |
|
|
|
|
|
# Walrus add (6) start |
|
|
sub html_to_ignored_html { |
|
|
my $str = shift(@_); |
|
|
my $text_regex = q{[^<]*}; |
|
|
my $tag_regex_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}} |
|
|
my $comment_tag_regex = '<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)'; |
|
|
my $tag_regex = qq{$comment_tag_regex|<$tag_regex_}; |
|
|
my $ignored = join('|', @ignore_html_tags); |
|
|
my $result = ''; |
|
|
while ($str =~ /($text_regex)($tag_regex)?/gso) { |
|
|
last if $1 eq '' and $2 eq ''; |
|
|
$result .= $1; |
|
|
my $tag_tmp = $2; |
|
|
$result .= ($tag_tmp =~ /^<\/?($ignored)(?![0-9A-Za-z])/i) ? $tag_tmp : &escape($tag_tmp); |
|
|
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) { |
|
|
$str =~ /(.*?)(?:<\/$1(?![0-9A-Za-z])$tag_regex_|$)/gsi; |
|
|
$result .= &escape($1); |
|
|
} |
|
|
} |
|
|
return $result; |
|
|
} |
|
|
# Walrus add (6) end |
|
|
|
|
904 |
sub print_message { |
sub print_message { |
905 |
my ($msg) = @_; |
my ($msg) = @_; |
906 |
print qq(<p><strong>$msg</strong></p>); |
print qq(<p><strong>$msg</strong></p>); |
907 |
} |
} |
908 |
|
|
909 |
|
sub get_message { |
910 |
|
my ($msg) = @_; |
911 |
|
qq(<p><strong>$msg</strong></p>); |
912 |
|
} |
913 |
|
|
914 |
sub init_form { |
sub init_form { |
915 |
if (param()) { |
if (param()) { |
916 |
foreach my $var (param()) { |
foreach my $var (param()) { |
917 |
$form{$var} = param($var); |
$form{$var} = param($var); |
918 |
} |
} |
|
} else { |
|
|
$ENV{QUERY_STRING} = $FrontPage; |
|
919 |
} |
} |
920 |
|
$form{mypage} = &code_convert(\$form{mypage}, $kanjicode); |
921 |
my $query = &decode($ENV{QUERY_STRING}); |
if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) { |
922 |
if ($page_command{$query}) { |
my $query = &decode($main::ENV{QUERY_STRING}); |
923 |
|
$query = &code_convert(\$query, $kanjicode); |
924 |
|
if ($page_command{$query}) { |
925 |
$form{mycmd} = $page_command{$query}; |
$form{mycmd} = $page_command{$query}; |
926 |
$form{mypage} = $query; |
$form{mypage} = $query; |
927 |
} elsif ($query =~ /^($wiki_name)$/) { |
} else { |
|
$form{mycmd} = 'read'; |
|
|
$form{mypage} = $1; |
|
|
} elsif ($database{$query}) { |
|
|
$form{mycmd} = 'read'; |
|
928 |
$form{mypage} = $query; |
$form{mypage} = $query; |
929 |
|
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
930 |
|
} |
931 |
} |
} |
932 |
|
$form{mypage} ||= 'HomePage'; |
933 |
|
$form{mycmd} ||= 'read'; |
934 |
|
|
935 |
# mypreview_edit -> do_edit, with preview. |
# mypreview_edit -> do_edit, with preview. |
936 |
# mypreview_adminedit -> do_adminedit, with preview. |
# mypreview_adminedit -> do_adminedit, with preview. |
942 |
} |
} |
943 |
} |
} |
944 |
|
|
945 |
# |
# |
946 |
# $form{mycmd} is frozen here. |
# $form{mycmd} is frozen here. |
947 |
# |
# |
948 |
|
|
949 |
|
for (grep /^wikiform__/, keys %form) { |
950 |
|
$form{$_} = &code_convert (\$form{$_}, $kanjicode); |
951 |
|
} |
952 |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
953 |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
954 |
} |
} |
955 |
|
|
956 |
sub update_recent_changes { |
sub update_recent_changes { |
957 |
my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}"; |
my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; |
958 |
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
959 |
|
shift (@oldupdates); ## '#?' magic line |
960 |
my @updates; |
my @updates; |
961 |
foreach (@oldupdates) { |
foreach (@oldupdates) { |
962 |
/^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format. |
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/; |
963 |
my $name = &unarmor_name($1); |
my $name = $1; |
964 |
if (&is_exist_page($name) and ($name ne $form{mypage})) { |
if ($name ne $form{mypage}) { |
965 |
push(@updates, $_); |
push @updates, $_; |
966 |
} |
} |
967 |
} |
} |
968 |
if (&is_exist_page($form{mypage})) { |
if (&is_exist_page($form{mypage})) { |
969 |
unshift(@updates, $update); |
unshift @updates, $update; |
970 |
} |
} |
971 |
splice(@updates, $maxrecent + 1); |
splice(@updates, $maxrecent + 1); |
972 |
$database{$RecentChanges} = join("\n", @updates); |
$database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates); |
973 |
if ($file_touch) { |
if ($file_touch) { |
974 |
open(FILE, "> $file_touch"); |
open(FILE, "> $file_touch"); |
975 |
print FILE localtime() . "\n"; |
print FILE localtime() . "\n"; |
990 |
|
|
991 |
# Get the subject of the page. |
# Get the subject of the page. |
992 |
my $subject = $database{$page}; |
my $subject = $database{$page}; |
993 |
|
$subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; |
994 |
$subject =~ s/\r?\n.*//s; |
$subject =~ s/\r?\n.*//s; |
995 |
return "$delim$subject"; |
return "$delim$subject".$option{tail}; |
996 |
} |
} |
997 |
} |
} |
998 |
|
|
1073 |
my ($word) = @_; |
my ($word) = @_; |
1074 |
print <<"EOD"; |
print <<"EOD"; |
1075 |
<form action="$url_cgi" method="get"> |
<form action="$url_cgi" method="get"> |
1076 |
<input type="hidden" name="mycmd" value="search"> |
<input type="hidden" name="mycmd" value="read"> |
1077 |
<input type="text" name="mymsg" value="$word" size="20"> |
<input type="text" name="mypage" value="$word" size="20"> |
1078 |
<input type="submit" value="$resource{searchbutton}"> |
<input type="submit" value="$resource{searchbutton}"> |
1079 |
</form> |
</form> |
1080 |
EOD |
EOD |
1098 |
} |
} |
1099 |
$mymsg = &escape($form{mymsg}); |
$mymsg = &escape($form{mymsg}); |
1100 |
} else { |
} else { |
1101 |
$mymsg = &escape($mymsg); |
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
1102 |
} |
} |
1103 |
|
|
1104 |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
1105 |
|
my $escapedmypage = &escape($form{mypage}); |
1106 |
|
my $escapedmypassword = &escape($form{mypassword}); |
1107 |
|
|
1108 |
print <<"EOD"; |
print <<"EOD"; |
1109 |
<form action="$url_cgi" method="post"> |
<form action="$url_cgi" method="post"> |
1110 |
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$form{mypassword}" size="10"><br>) : "" ]} |
<h2>$escapedmypageの編集</h2> |
1111 |
|
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]} |
1112 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1113 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
<input type="hidden" name="mypage" value="$escapedmypage"> |
1114 |
<textarea cols="$cols" rows="$rows" name="mymsg" wrap="off">$mymsg</textarea><br> |
<textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br> |
1115 |
@{[ |
@{[ |
1116 |
$mode{admin} ? |
$mode{admin} ? |
1117 |
qq( |
qq( |
1124 |
qq( |
qq( |
1125 |
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
1126 |
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
1127 |
<input type="submit" name="mypreview_write" value="$resource{savebutton}"><br> |
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd> |
1128 |
|
[@{[do {my $n = 0; |
1129 |
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
1130 |
|
++$n}]}]<br> |
1131 |
) |
) |
1132 |
]} |
]} |
1133 |
</form> |
</form> |
1134 |
EOD |
EOD |
1135 |
unless ($mode{conflict}) { |
unless ($mode{conflict}) { |
1136 |
# Show the format rule. |
# Show the format rule. |
1137 |
open(FILE, $file_format) or &print_error("($file_format)"); |
my $help = $database{'WikiEditHelp'}; |
1138 |
my $content = join('', <FILE>); |
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1139 |
&code_convert(\$content, $kanjicode); |
print &text_to_html ($help, toc => 0); |
1140 |
close(FILE); |
# open(FILE, $file_format) or &print_error("($file_format)"); |
1141 |
print &text_to_html($content, toc=>0); |
# my $content = join('', <FILE>); |
1142 |
|
# &code_convert(\$content, $kanjicode); |
1143 |
|
# close(FILE); |
1144 |
|
# print &text_to_html($content, toc=>0); |
1145 |
} |
} |
1146 |
} |
} |
1147 |
|
|
1159 |
|
|
1160 |
sub is_editable { |
sub is_editable { |
1161 |
my ($page) = @_; |
my ($page) = @_; |
1162 |
if (&is_bracket_name($page)) { |
if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) { |
|
return 0; |
|
|
} elsif ($fixedpage{$page}) { |
|
|
return 0; |
|
|
} elsif ($page =~ /\s/) { |
|
|
return 0; |
|
|
} elsif ($page =~ /^\#/) { |
|
|
return 0; |
|
|
} elsif ($page =~ /^$interwiki_name$/) { |
|
1163 |
return 0; |
return 0; |
1164 |
} else { |
} else { |
1165 |
return 1; |
return 1; |
1169 |
# armor_name: |
# armor_name: |
1170 |
# WikiName -> WikiName |
# WikiName -> WikiName |
1171 |
# not_wiki_name -> [[not_wiki_name]] |
# not_wiki_name -> [[not_wiki_name]] |
1172 |
sub armor_name { |
sub armor_name { qq([[$_[0]]]) } |
|
my ($name) = @_; |
|
|
if ($name =~ /^$wiki_name$/) { |
|
|
return $name; |
|
|
} else { |
|
|
return "[[$name]]"; |
|
|
} |
|
|
} |
|
1173 |
|
|
1174 |
# unarmor_name: |
# unarmor_name: |
1175 |
# [[bracket_name]] -> bracket_name |
# [[bracket_name]] -> bracket_name |
1183 |
} |
} |
1184 |
} |
} |
1185 |
|
|
|
sub is_bracket_name { |
|
|
my ($name) = @_; |
|
|
if ($name =~ /^$bracket_name$/) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
1186 |
sub decode { |
sub decode { |
1187 |
my ($s) = @_; |
my ($s) = @_; |
1188 |
$s =~ tr/+/ /; |
$s =~ tr/+/ /; |
1223 |
my $content = join('', <FILE>); |
my $content = join('', <FILE>); |
1224 |
&code_convert(\$content, $kanjicode); |
&code_convert(\$content, $kanjicode); |
1225 |
close(FILE); |
close(FILE); |
1226 |
&print_header($page); |
&print_header($page, -noindex => 1); |
1227 |
&print_content($content); |
&print_content($content); |
1228 |
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
1229 |
&print_footer($page); |
&print_footer($page); |
1232 |
|
|
1233 |
sub get_now { |
sub get_now { |
1234 |
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
1235 |
|
my (@week) = qw(日 月 火 水 木 金 土); |
1236 |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
1237 |
$year += 1900; |
$year += 1900; |
1238 |
$mon++; |
$mon++; |
1240 |
$day = "0$day" if $day < 10; |
$day = "0$day" if $day < 10; |
1241 |
$hour = "0$hour" if $hour < 10; |
$hour = "0$hour" if $hour < 10; |
1242 |
$min = "0$min" if $min < 10; |
$min = "0$min" if $min < 10; |
1243 |
$sec = "0$sec" if $sec < 10; |
#$sec = "0$sec" if $sec < 10; |
1244 |
$weekday = $week[$weekday]; |
$weekday = $week[$weekday]; |
1245 |
return "$year-$mon-$day ($weekday) $hour:$min:$sec"; |
return "$year-$mon-$day ($weekday) $hour:$min"; |
1246 |
} |
} |
1247 |
|
|
|
# [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]] |
|
1248 |
sub init_InterWikiName { |
sub init_InterWikiName { |
1249 |
my $content = $database{$InterWikiName}; |
my @content = split /\n/, $database{$InterWikiName}; |
1250 |
while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) { |
for (@content) { |
1251 |
my ($name, $url) = ($1, $2); |
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
1252 |
$interwiki{$name} = $url; |
$interwiki{$1} = $2; |
1253 |
} |
} |
1254 |
|
} |
1255 |
|
require Message::Util::Formatter; |
1256 |
|
$fmt{interwiki} = Message::Util::Formatter->new; |
1257 |
|
$fmt{interwiki}->{encoded} = sub { |
1258 |
|
my ($o, $p) = @_; |
1259 |
|
if ($o->{except}) { |
1260 |
|
$o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d; |
1261 |
|
} |
1262 |
|
my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit'); |
1263 |
|
$s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge; |
1264 |
|
$s; |
1265 |
|
}; |
1266 |
|
$fmt{interwiki}->{ykwk} = sub { ## YukiWiki1 |
1267 |
|
my ($o, $p) = @_; |
1268 |
|
my $s = $p->{name}; |
1269 |
|
$s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/; |
1270 |
|
&encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis')); |
1271 |
|
}; |
1272 |
|
|
1273 |
|
$fmt{form_input} = Message::Util::Formatter->new; |
1274 |
|
for (@{$SuikaWiki::Plugin::List{wikiform_input}||[]}) { |
1275 |
|
$_->load_formatter ($fmt{form_input}, type => 'wikiform_input'); |
1276 |
|
} |
1277 |
} |
} |
1278 |
|
|
|
sub interwiki_convert { |
|
|
my ($type, $localname) = @_; |
|
|
if ($type eq 'sjis' or $type eq 'euc') { |
|
|
&code_convert(\$localname, $type); |
|
|
return &encode($localname); |
|
|
} elsif ($type eq 'ykwk') { |
|
|
# for YukiWiki1 |
|
|
if ($localname =~ /^$wiki_name$/) { |
|
|
return $localname; |
|
|
} else { |
|
|
&code_convert(\$localname, 'sjis'); |
|
|
return &encode("[[" . $localname . "]]"); |
|
|
} |
|
|
} elsif ($type eq 'asis') { |
|
|
return $localname; |
|
|
# Walrus add (4) start |
|
|
} elsif ($type eq 'isbn') { |
|
|
$localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/); |
|
|
return $localname; |
|
|
# Walrus add (4) end |
|
|
} else { |
|
|
return $localname; |
|
|
} |
|
|
} |
|
1279 |
|
|
1280 |
sub get_info { |
sub get_info { |
1281 |
my ($page, $key) = @_; |
my ($page, $key) = @_; |
1330 |
|
|
1331 |
sub do_comment { |
sub do_comment { |
1332 |
my ($content) = $database{$form{mypage}}; |
my ($content) = $database{$form{mypage}}; |
1333 |
my $datestr = &get_now; |
my $default_name; ## this code does not strict. |
1334 |
my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " "; |
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
1335 |
if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) { |
my $datestr = '[WEAK['.&get_now.']]'; |
1336 |
; |
my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; |
1337 |
} else { |
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
1338 |
$content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/; |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
1339 |
|
$namestr = qq( ''$namestr'': ); |
1340 |
|
} elsif (length $namestr) { |
1341 |
|
$namestr = qq( ''[[$namestr]]'': ); |
1342 |
|
} |
1343 |
|
my $anchor = &get_new_anchor_index ($content); |
1344 |
|
|
1345 |
|
# $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
1346 |
|
# $anchor++; |
1347 |
|
my $i = 1; my $o = 0; |
1348 |
|
$content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ |
1349 |
|
my $embed = $1; |
1350 |
|
if ($i == $form{comment_index}) { |
1351 |
|
if ($embed eq $embed_comment) { |
1352 |
|
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
1353 |
|
} else { |
1354 |
|
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
1355 |
|
} |
1356 |
|
} |
1357 |
|
$i++; $embed; |
1358 |
|
}ge; |
1359 |
|
unless ($o) { |
1360 |
|
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1361 |
|
$content .= "\n" unless $content =~ /\n$/s; |
1362 |
|
$content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; |
1363 |
} |
} |
1364 |
if ($form{mymsg}) { |
$form{__comment_anchor_index} = $anchor; |
1365 |
|
if ($form{mymsg} || $form{myname}) { |
1366 |
$form{mymsg} = $content; |
$form{mymsg} = $content; |
1367 |
$form{mytouch} = 'on'; |
$form{mytouch} = 'on'; |
1368 |
&do_write; |
&do_write; |
1372 |
} |
} |
1373 |
} |
} |
1374 |
|
|
1375 |
|
sub get_new_anchor_index ($) { |
1376 |
|
my $content = shift; |
1377 |
|
my $anchor = 0; |
1378 |
|
$content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
1379 |
|
$anchor + 1; |
1380 |
|
} |
1381 |
|
|
1382 |
|
my $CommentIndex = 0; |
1383 |
sub embedded_to_html { |
sub embedded_to_html { |
1384 |
my ($embedded) = @_; |
my ($embedded) = @_; |
1385 |
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
1386 |
|
unless ($main::_EMBEDED) { |
1387 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
1388 |
return <<"EOD"; |
return <<"EOD"; |
1389 |
<form action="$url_cgi" method="post"> |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
1390 |
<input type="hidden" name="mycmd" value="comment"> |
<input type="hidden" name="mycmd" value="comment"> |
1391 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
<input type="hidden" name="mypage" value="$form{mypage}"> |
1392 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1393 |
<input type="hidden" name="mytouch" value="on"> |
<input type="hidden" name="mytouch" value="on"> |
1394 |
$resource{yourname} |
<input type="hidden" name="comment_index" value="$CommentIndex"> |
1395 |
<input type="text" name="myname" value="" size="10"> |
$embed_comment_Name_Prompt |
1396 |
<input type="text" name="mymsg" value="" size="40"> |
<input type="text" name="myname" value="" size="10" class="comment-name"> |
1397 |
<input type="submit" value="$resource{commentbutton}"> |
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
1398 |
</form> |
<input type="submit" value="$resource{commentbutton}" class="comment-submit"> |
1399 |
|
</p></form> |
1400 |
EOD |
EOD |
1401 |
|
} else { |
1402 |
|
return <<"EOD"; |
1403 |
|
<del><form action="$url_cgi" method="get"> |
1404 |
|
<input type="hidden" name="mycmd" value="read"> |
1405 |
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1406 |
|
$embed_comment_Name_Prompt |
1407 |
|
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
1408 |
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
1409 |
|
<input type="submit" value="$resource{commentbutton}" disabled="disabled"> |
1410 |
|
</form></del> |
1411 |
|
EOD |
1412 |
|
} |
1413 |
|
} elsif ($embedded =~ /$embed_command{searched}/) { |
1414 |
|
return get_search_result ($1, -match_myself => 1); |
1415 |
# Walrus add (5) start |
# Walrus add (5) start |
1416 |
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
1417 |
$_ = &make_interwiki_box($1, $2); |
$_ = &make_interwiki_box($1, $2); |
1418 |
return ($_) ? $_ : $embedded; |
return ($_) ? $_ : $embedded; |
1419 |
# Walrus add (5) end |
# Walrus add (5) end |
1420 |
|
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
1421 |
|
my ($name, $r) = ($1, ''); |
1422 |
|
if ($main::_EMBEDED != 1) { |
1423 |
|
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
1424 |
|
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1425 |
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
1426 |
|
$main::_EMBEDED = 1; |
1427 |
|
$r = &text_to_html ($content, content_format => $cf); |
1428 |
|
$main::_EMBEDED = 0; |
1429 |
|
} elsif (length $content) { |
1430 |
|
$r = "<pre>@{[&escape ($content)]}</pre>"; |
1431 |
|
} else { |
1432 |
|
$r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1433 |
|
} |
1434 |
|
} else { ## nested #EMBED |
1435 |
|
$r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1436 |
|
} |
1437 |
|
return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>); |
1438 |
|
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
1439 |
|
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
1440 |
|
} else { |
1441 |
|
return $embedded; |
1442 |
|
} |
1443 |
|
} |
1444 |
|
|
1445 |
|
sub do_wikiform { |
1446 |
|
my $content = $database{$form{mypage}}; |
1447 |
|
my $anchor = &get_new_anchor_index ($content); |
1448 |
|
for my $t (qw/form_template form_option/) { |
1449 |
|
unless ($fmt{$t}) { |
1450 |
|
$fmt{$t} = Message::Util::Formatter->new; |
1451 |
|
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
1452 |
|
$_->load_formatter ($fmt{$t}, type => 'wiki'.$t); |
1453 |
|
} |
1454 |
|
} |
1455 |
|
} |
1456 |
|
my $write = 0; |
1457 |
|
my $i = 1; |
1458 |
|
$content =~ s{$embed_command{form}}{ |
1459 |
|
my ($embed, $template, $option) = ($&, $2, $3); |
1460 |
|
$template =~ s/\\(.)/$1/g; |
1461 |
|
$option =~ s/\\(.)/$1/g; |
1462 |
|
if ($i == $form{wikiform_index}) { |
1463 |
|
my $param = bless {}, 'SuikaWiki::Plugin'; |
1464 |
|
$param->{page} = $form{mypage}; |
1465 |
|
$param->{form_index} = $i; |
1466 |
|
$param->{anchor_index} = $anchor; |
1467 |
|
$param->{argv} = \%form; |
1468 |
|
$param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; |
1469 |
|
$fmt{form_option}->replace ($option, $param); |
1470 |
|
my $t = $fmt{form_template}->replace ($template, $param); |
1471 |
|
if (length $t) { |
1472 |
|
if ($param->{output}->{reverse}) { |
1473 |
|
$embed = $t . "\n" . $embed; |
1474 |
|
} else { |
1475 |
|
$embed .= "\n" . $t; |
1476 |
|
} |
1477 |
|
$write = 1; |
1478 |
|
$form{__comment_anchor_index} = $anchor |
1479 |
|
unless $param->{anchor_index}; ## $anchor is used! |
1480 |
|
} |
1481 |
|
} |
1482 |
|
$i++; $embed; |
1483 |
|
}ge; |
1484 |
|
unless ($write) { |
1485 |
|
#$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1486 |
|
#$content .= "\n" unless $content =~ /\n$/s; |
1487 |
|
# |
1488 |
|
} |
1489 |
|
$form{__wikiform_anchor_index} = $form{wikiform_index}; |
1490 |
|
if ($write) { |
1491 |
|
$form{mymsg} = $content; |
1492 |
|
$form{mytouch} = 'on'; |
1493 |
|
&do_write; |
1494 |
} else { |
} else { |
1495 |
return $embedded; |
$form{mycmd} = 'read'; |
1496 |
|
&do_read; |
1497 |
} |
} |
1498 |
} |
} |
1499 |
|
|
1500 |
|
|
1501 |
# Walrus add (5) start |
# Walrus add (5) start |
1502 |
sub do_interwiki_box { |
sub do_interwiki_box { |
1503 |
my $remoteurl = $interwiki{$form{'myintername'}}; |
my $remoteurl = $interwiki{$form{'myintername'}}; |
1534 |
# Walrus add (5) end |
# Walrus add (5) end |
1535 |
|
|
1536 |
sub code_convert { |
sub code_convert { |
1537 |
my ($contentref, $kanjicode) = @_; |
my ($contentref, $code) = (shift, shift || $kanjicode); |
1538 |
# &Jcode::convert($contentref, $kanjicode); # for Jcode.pm |
$code = 'jis' if $code =~ /iso/; |
1539 |
&jcode::convert($contentref, $kanjicode); # for jcode.pl |
$code = 'euc' if $code =~ /euc/; |
1540 |
|
$code = 'sjis' if $code =~ /shift/; |
1541 |
|
$code = 'utf8' if $code =~ /utf/; |
1542 |
|
&Jcode::convert($contentref, $code); # for Jcode.pm |
1543 |
|
# &jcode::convert($contentref, $code); # for jcode.pl |
1544 |
|
&jcode::tr ($contentref, "\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ )) if $code eq 'euc'; |
1545 |
return $$contentref; |
return $$contentref; |
1546 |
} |
} |
1547 |
|
|
1615 |
} |
} |
1616 |
&open_diff; |
&open_diff; |
1617 |
my $title = $form{mypage}; |
my $title = $form{mypage}; |
1618 |
&print_header($title); |
&print_header($title, -noindex => 1); |
1619 |
$_ = &escape($diffbase{$form{mypage}}); |
$_ = &escape($diffbase{$form{mypage}}); |
1620 |
&close_diff; |
&close_diff; |
1621 |
print qq(<h3>$resource{difftitle}</h3>); |
print qq(<h3>$resource{difftitle}</h3>); |
1651 |
my $count = 0; |
my $count = 0; |
1652 |
foreach (split(/\n/, $recentchanges)) { |
foreach (split(/\n/, $recentchanges)) { |
1653 |
last if ($count >= 15); |
last if ($count >= 15); |
1654 |
/^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format. |
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format. |
1655 |
my $title = &unarmor_name($1); |
my $title = &unarmor_name($1); |
1656 |
my $escaped_title = &escape($title); |
my $escaped_title = &escape($title); |
1657 |
my $link = $modifier_rss_link . '?' . &encode($title); |
my $link = $modifier_rss_link . '?' . &encode($title); |
1680 |
} |
} |
1681 |
} |
} |
1682 |
|
|
1683 |
|
sub __get_database ($) { $database{ $_[0] } } |
1684 |
|
sub __set_database ($$) { $database{ $_[0] } = $_[1] } |
1685 |
|
|
1686 |
|
package wiki::referer; |
1687 |
|
sub add ($$) { |
1688 |
|
my $page = shift; |
1689 |
|
my $uri = shift; |
1690 |
|
unless (ref $uri) { |
1691 |
|
require URI; |
1692 |
|
$uri = URI->new ($uri); |
1693 |
|
## Some schemes do not have query part. |
1694 |
|
eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ }; |
1695 |
|
$uri->fragment (undef); |
1696 |
|
} |
1697 |
|
$uri = $uri->canonical; |
1698 |
|
return unless $uri; |
1699 |
|
for my $regex (&get_dont_record) { |
1700 |
|
return if $uri =~ /$regex/; |
1701 |
|
} |
1702 |
|
my %list = get ($page); |
1703 |
|
$list{ $uri }++; |
1704 |
|
set ($page, \%list); |
1705 |
|
} |
1706 |
|
sub get ($) { |
1707 |
|
my $page = shift; |
1708 |
|
split /"/, main::get_info ($page, 'Referer'); |
1709 |
|
} |
1710 |
|
sub set ($%) { |
1711 |
|
my $page = shift; |
1712 |
|
my $list = shift; |
1713 |
|
main::set_info ($page, Referer => join '"', %$list); |
1714 |
|
} |
1715 |
|
|
1716 |
|
sub get_dont_record () { |
1717 |
|
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
1718 |
|
grep !/^#/, |
1719 |
|
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
1720 |
|
} |
1721 |
|
sub get_site_name () { |
1722 |
|
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
1723 |
|
my @item; |
1724 |
|
for (@lines) { |
1725 |
|
next if /^#/; |
1726 |
|
my ($uri, $name) = split /\s+/, $_, 2; |
1727 |
|
$uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; |
1728 |
|
$name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; |
1729 |
|
push @item, [$uri, qq(q($name))]; |
1730 |
|
} |
1731 |
|
@item; |
1732 |
|
} |
1733 |
|
|
1734 |
|
sub list_html ($) { |
1735 |
|
my $page = shift; |
1736 |
|
my %list = get ($page); |
1737 |
|
my $r = ''; |
1738 |
|
my @name = get_site_name; |
1739 |
|
for my $uri (sort keys %list) { |
1740 |
|
my $title; |
1741 |
|
for my $item (@name) { |
1742 |
|
if ($uri =~ /$item->[0]/) { |
1743 |
|
$title = $uri; |
1744 |
|
eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} |
1745 |
|
or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; |
1746 |
|
last; |
1747 |
|
} |
1748 |
|
} |
1749 |
|
my $euri = main::escape ($uri); |
1750 |
|
if ($title) { |
1751 |
|
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
1752 |
|
} else { |
1753 |
|
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
1754 |
|
} |
1755 |
|
} |
1756 |
|
$r ? qq(<ul>$r</ul>\n) : ''; |
1757 |
|
} |
1758 |
|
|
1759 |
|
sub __decode ($) { |
1760 |
|
my $s = shift; |
1761 |
|
$s =~ tr/+/ /; |
1762 |
|
$s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge; |
1763 |
|
main::code_convert (\$s); |
1764 |
|
} |
1765 |
|
|
1766 |
|
package wiki::useragent; |
1767 |
|
|
1768 |
|
sub add ($) { |
1769 |
|
my $s = shift; |
1770 |
|
return unless length $s; |
1771 |
|
$s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g; |
1772 |
|
my %ua; |
1773 |
|
for (split /\n/, &main::__get_database('WikiUserAgentList')) { |
1774 |
|
if (/^-\[(\d+)\] (.+)$/) { |
1775 |
|
my ($t, $n) = ($1, $2); |
1776 |
|
$n =~ tr/\x0A\x0D//d; |
1777 |
|
$ua{$n} = $t; |
1778 |
|
} |
1779 |
|
} |
1780 |
|
$ua{$s}++; |
1781 |
|
my $s = qq(#?SuikaWiki/0.9\n); |
1782 |
|
for (sort {$ua{$a} <=> $ua{$b}} keys %ua) { |
1783 |
|
$s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_; |
1784 |
|
} |
1785 |
|
&main::__set_database ('WikiUserAgentList' => $s); |
1786 |
|
} |
1787 |
|
|
1788 |
|
package SuikaWiki::Plugin; |
1789 |
|
our %List; |
1790 |
|
|
1791 |
|
sub escape ($$) { main::escape ($_[1]) } |
1792 |
|
sub unescape ($$) { main::unescape ($_[1]) } |
1793 |
|
sub encode ($$) { main::encode ($_[1]) } |
1794 |
|
sub decode ($$) { main::decode ($_[1]) } |
1795 |
|
sub __get_datetime ($) { main::get_now () } |
1796 |
|
|
1797 |
|
sub regist ($@) { |
1798 |
|
my $pack = shift; |
1799 |
|
for (@_) { |
1800 |
|
push @{$List{$_}}, $pack; |
1801 |
|
} |
1802 |
|
} |
1803 |
|
|
1804 |
|
use SuikaWiki::Plugin::WikiFormBasic; |
1805 |
|
|
1806 |
1; |
1; |
1807 |
__END__ |
__END__ |
1808 |
=head1 NAME |
=head1 NAME |