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; |
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 = '([^:]+):i:([^:].*)'; |
|
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 = ( |
my %embed_command = ( |
99 |
searched => '^\[\[#searched:([^\]]+)\]\]$', |
searched => '^\[\[#searched:([^\]]+)\]\]$', |
134 |
); |
); |
135 |
my %command_do = ( |
my %command_do = ( |
136 |
read => \&do_read, |
read => \&do_read, |
137 |
|
TEXT_CSS => \&do_output_css, |
138 |
edit => \&do_edit, |
edit => \&do_edit, |
139 |
adminedit => \&do_adminedit, |
adminedit => \&do_adminedit, |
140 |
adminchangepasswordform => \&do_adminchangepasswordform, |
adminchangepasswordform => \&do_adminchangepasswordform, |
147 |
createresult => \&do_createresult, |
createresult => \&do_createresult, |
148 |
FrontPage => \&do_FrontPage, |
FrontPage => \&do_FrontPage, |
149 |
comment => \&do_comment, |
comment => \&do_comment, |
150 |
|
RandomJump => \&do_random_jump, |
151 |
rss => \&do_rss, |
rss => \&do_rss, |
152 |
diff => \&do_diff, |
diff => \&do_diff, |
153 |
interwikibox => \&do_interwiki_box, # Walrus add (5) |
interwikibox => \&do_interwiki_box, # Walrus add (5) |
176 |
} |
} |
177 |
|
|
178 |
sub do_read { |
sub do_read { |
179 |
&print_header($form{mypage}); |
my $content = $database{$form{mypage}}; |
180 |
&print_content($database{$form{mypage}}); |
my $lm = &get_info($form{mypage}, $info_LastModified); |
181 |
my ($r, $c) = get_search_result ($form{mypage}); |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
182 |
|
my ($r, $c) = get_search_result ($form{mypage}); |
183 |
|
my $rl = wiki::referer::list_html ($form{mypage}); |
184 |
|
my @toc; |
185 |
|
push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c; |
186 |
|
push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl; |
187 |
|
my $cf = 'SuikaWiki/0.9'; |
188 |
|
## Should be support at least: |
189 |
|
## - 'SuikaWiki/0.9' CRLF |
190 |
|
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
191 |
|
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
192 |
|
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
193 |
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
194 |
|
&print_header ($form{mypage}, -last_modified => $lm, |
195 |
|
-content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/); |
196 |
|
&print_content ($content, content_format => $cf, last_modified => $lm, |
197 |
|
-toc => \@toc); |
198 |
|
print &text_to_html (q([[#comment]])) unless $cf =~ /obsoleted="yes"/; |
199 |
|
} else { |
200 |
|
&print_header($form{mypage}, -last_modified => $lm); |
201 |
|
print "<pre>@{[&escape($content)]}</pre>"; |
202 |
|
} |
203 |
if ($c) { |
if ($c) { |
204 |
print q{<h2>See also</h2>}; |
print q{<h2 id="wikipage-see-also">See also</h2>}; |
205 |
print $r; |
print $r; |
206 |
} |
} |
207 |
&print_footer($form{mypage}); |
if ($rl) { |
208 |
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
209 |
|
} |
210 |
|
&print_footer($form{mypage}, $lm); |
211 |
|
} |
212 |
|
|
213 |
|
sub do_output_css { |
214 |
|
my $content = $database{$form{mypage}}; |
215 |
|
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
216 |
|
my $lm = &get_info($form{mypage}, $info_LastModified); |
217 |
|
print "Content-Type: text/css; charset=$charset\n"; |
218 |
|
print "Last-Modified: $lm\n"; |
219 |
|
print "\n"; |
220 |
|
print $content; |
221 |
|
} else { |
222 |
|
print "Status: 406 Unsupported Media Type\n"; |
223 |
|
&print_header('WikiPageIsNotCSS', -noindex => 1); |
224 |
|
&print_content($database{WikiPageIsNotCSS}); |
225 |
|
&print_footer('WikiPageIsNotCSS'); |
226 |
|
} |
227 |
} |
} |
228 |
|
|
229 |
sub do_edit { |
sub do_edit { |
230 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
231 |
&print_header($page); |
&print_header($page, -noindex => 1); |
232 |
if (not &is_editable($page)) { |
if (not &is_editable($page)) { |
233 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
234 |
} elsif (&is_frozen($page)) { |
} elsif (&is_frozen($page)) { |
236 |
} else { |
} else { |
237 |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
238 |
} |
} |
239 |
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
240 |
|
my ($r, $c) = get_search_result ($form{mypage}); |
241 |
|
my $rl = wiki::referer::list_html ($form{mypage}); |
242 |
|
if ($c) { |
243 |
|
print q{<h2 id="wikipage-see-also">See also</h2>}; |
244 |
|
print $r; |
245 |
|
} |
246 |
|
if ($rl) { |
247 |
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
248 |
|
} |
249 |
&print_footer($page); |
&print_footer($page); |
250 |
} |
} |
251 |
|
|
252 |
sub do_adminedit { |
sub do_adminedit { |
253 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
254 |
&print_header($page); |
&print_header($page, -noindex => 1); |
255 |
if (not &is_editable($page)) { |
if (not &is_editable($page)) { |
256 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
257 |
} else { |
} else { |
262 |
} |
} |
263 |
|
|
264 |
sub do_adminchangepasswordform { |
sub do_adminchangepasswordform { |
265 |
&print_header($AdminChangePassword); |
&print_header($AdminChangePassword, -noindex => 1); |
266 |
&print_passwordform; |
&print_passwordform; |
267 |
&print_footer($AdminChangePassword); |
&print_footer($AdminChangePassword); |
268 |
} |
} |
289 |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
290 |
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
291 |
|
|
292 |
&print_header($CompletedSuccessfully); |
&print_header($CompletedSuccessfully, -noindex => 1); |
293 |
&print_message($resource{passwordchanged}); |
&print_message($resource{passwordchanged}); |
294 |
&print_footer($CompletedSuccessfully); |
&print_footer($CompletedSuccessfully); |
295 |
} |
} |
314 |
} |
} |
315 |
|
|
316 |
if (not &is_editable($form{mypage})) { |
if (not &is_editable($form{mypage})) { |
317 |
&print_header($form{mypage}); |
&print_header($form{mypage}, -noindex => 1); |
318 |
&print_message($resource{cantchange}); |
&print_message($resource{cantchange}); |
319 |
&print_footer($form{mypage}); |
&print_footer($form{mypage}); |
320 |
return; |
return; |
341 |
&update_recent_changes; |
&update_recent_changes; |
342 |
} |
} |
343 |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
344 |
&print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage})); |
&print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":'')); |
345 |
&print_message($resource{saved}); |
&print_message($resource{saved}); |
346 |
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
347 |
&print_footer($CompletedSuccessfully); |
&print_footer($CompletedSuccessfully); |
352 |
if ($form{mytouch}) { |
if ($form{mytouch}) { |
353 |
&update_recent_changes; |
&update_recent_changes; |
354 |
} |
} |
355 |
&print_header($form{mypage}); |
&print_header($form{mypage}, -noindex => 1); |
356 |
&print_message($resource{deleted}); |
&print_message($resource{deleted}); |
357 |
&print_footer($form{mypage}); |
&print_footer($form{mypage}); |
358 |
} |
} |
368 |
my $word = $form{mymsg}; |
my $word = $form{mymsg}; |
369 |
&print_header($SearchPage); |
&print_header($SearchPage); |
370 |
&print_searchform(&escape($word)); |
&print_searchform(&escape($word)); |
371 |
print scalar get_search_result ($word, -output_not_found => 1); |
print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1); |
372 |
&print_footer($SearchPage); |
&print_footer($SearchPage); |
373 |
} |
} |
374 |
|
|
375 |
sub get_search_result ($;%) { |
sub get_search_result ($;%) { |
376 |
my $word = shift; |
my $word = shift; |
377 |
my %option = @_; |
my %option = @_; |
378 |
my $counter = 0; |
my @r; |
379 |
my $r = ''; |
foreach my $page (keys %database) { |
380 |
foreach my $page (sort keys %database) { |
next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself}); |
381 |
next if $page eq $RecentChanges; |
my $content = $database{$page}; |
382 |
if ( index ($database{$page}, $word) > 0 |
my $cf = 'SuikaWiki/0.9'; |
383 |
|| index ($page, $word) > 0 |
$cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s; |
384 |
|| index ($word, $page) > 0 |
next if $cf =~ /obsoleted="yes"/; |
385 |
) { |
if (index ($page, $word) > -1) { |
386 |
$r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
my $c = $content =~ s/\Q$word\E/$word/g; |
387 |
$counter++; |
push @r, [$page, $c+20]; |
388 |
|
} elsif (index ($word, $page) > -1) { |
389 |
|
my $c = $content =~ s/\Q$word\E/$word/g; |
390 |
|
push @r, [$page, $c+10]; |
391 |
|
} elsif (my $c = $content =~ s/\Q$word\E/$word/g) { |
392 |
|
push @r, [$page, $c]; |
393 |
} |
} |
394 |
} |
} |
395 |
$r = qq|<ul>$r</ul>| if $r; |
my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#g; $s }; |
396 |
get_message ($resource{notfound}) |
my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
397 |
if $counter == 0 && $option{-output_not_found}; |
$r = qq|<ul class="search-result">$r</ul>| if $r; |
398 |
wantarray? ($r, $counter): $r; |
get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found}; |
399 |
|
wantarray? ($r, scalar @r): $r; |
400 |
} |
} |
401 |
|
|
402 |
sub do_create { |
sub do_create { |
412 |
&print_footer($CreatePage); |
&print_footer($CreatePage); |
413 |
} |
} |
414 |
|
|
415 |
|
sub do_random_jump { |
416 |
|
my @list = keys %database; |
417 |
|
my $name = &encode ($list[rand @list]); |
418 |
|
my ($scheme) = 'http'; |
419 |
|
$scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
420 |
|
print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n"; |
421 |
|
print "\n"; |
422 |
|
} |
423 |
|
|
424 |
sub do_FrontPage { |
sub do_FrontPage { |
425 |
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
426 |
my $content = join('', <FILE>); |
my $content = join('', <FILE>); |
433 |
|
|
434 |
sub print_error { |
sub print_error { |
435 |
my ($msg) = @_; |
my ($msg) = @_; |
436 |
&print_header($ErrorPage); |
&print_header($ErrorPage, -noindex => 1); |
437 |
print qq(<p><strong class="error">$msg</strong></p>); |
print qq(<p><strong class="error">$msg</strong></p>); |
438 |
&print_footer($ErrorPage); |
&print_footer($ErrorPage); |
439 |
exit(0); |
exit(0); |
440 |
} |
} |
441 |
|
|
442 |
sub print_header { |
sub print_header ($;%) { |
443 |
my ($page,%option) = @_; |
my ($page, %option) = @_; |
444 |
my $bodyclass = "normal"; |
my $bodyclass = "normal"; |
445 |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
446 |
$bodyclass = "frozen"; |
$bodyclass = "frozen"; |
447 |
} |
} |
448 |
if ($option{-goto}) { |
$bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
449 |
print qq{Refresh: 0; url="$option{-goto}"\n}; |
print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto}; |
450 |
} |
print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; |
451 |
my $cookedpage = &encode($page); |
my $cookedpage = &encode($page); |
452 |
my $escapedpage = &escape($page); |
my $escapedpage = &escape($page); |
453 |
print <<"EOD"; |
print <<"EOD"; |
455 |
Content-Language: $lang |
Content-Language: $lang |
456 |
Content-Style-Type: text/css |
Content-Style-Type: text/css |
457 |
|
|
458 |
|
<!-- |
459 |
<!DOCTYPE html |
<!DOCTYPE html |
460 |
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
461 |
"http://www.w3.org/TR/html4/loose.dtd"> |
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
462 |
<html lang="$lang"> |
<html lang="$lang"> |
463 |
<head> |
<head> |
464 |
<title>$escapedpage @{[&escape(&get_subjectline($page))]}</title> |
<title>$escapedpage</title> |
465 |
<link rel="index" href="$url_cgi?$IndexPage"> |
<link rel="index" href="$url_cgi?$IndexPage"> |
466 |
<link rev="made" href="mailto:@{[&escape($modifier_mail)]}"> |
<link rel="help" href="$url_cgi?WikiHelp"> |
467 |
|
<link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense"> |
468 |
<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}"> |
<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}"> |
469 |
|
@{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']} |
470 |
</head> |
</head> |
471 |
<body class="$bodyclass"> |
<body class="$bodyclass"> |
472 |
EOD |
EOD |
473 |
&print_navigate_links ($page); |
&print_navigate_links ($page); |
474 |
print <<EOD; |
print <<EOD; |
475 |
<h1 class="header"><a |
<h1 class="header">@{[&escape($page)]}</h1> |
|
title="$resource{searchthispage}" |
|
|
href="$url_cgi?mycmd=search;mymsg=$cookedpage">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</h1> |
|
476 |
EOD |
EOD |
477 |
} |
} |
478 |
|
|
482 |
my $admineditable = 0; |
my $admineditable = 0; |
483 |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
484 |
$editable = 0; |
$editable = 0; |
485 |
$admineditable = 1; |
#$admineditable = 1; |
486 |
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
487 |
$admineditable = 1; |
#$admineditable = 1; |
488 |
$editable = 1; |
$editable = 1; |
489 |
} else { |
} else { |
490 |
$editable = 0; |
$editable = 0; |
497 |
: qq() |
: qq() |
498 |
]} |
]} |
499 |
@{[ $editable |
@{[ $editable |
500 |
? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | ) |
? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | ) |
501 |
|
qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | ) |
502 |
: qq() |
: qq() |
503 |
]} |
]} |
504 |
@{[ $admineditable |
@{[ $admineditable |
505 |
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
506 |
: qq() |
: qq() |
507 |
]} |
]} |
508 |
<a href="$url_cgi?$CreatePage">$resource{createbutton}</a> | |
<a href="$url_cgi?$CreatePage" class="wiki">新規</a> | |
509 |
<a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> | |
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
510 |
<a href="$url_cgi?$RssPage">$resource{rssbutton}</a> | |
<a href="$url_cgi?$FrontPage" class="wiki">首頁</a> | |
511 |
<a href="$url_cgi?$FrontPage">$FrontPage</a> | |
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
512 |
<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> | |
513 |
<a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a> |
<a href="$url_cgi?$RecentChanges" class="wiki">最新</a> |
514 |
|
</div> |
515 |
|
EOH |
516 |
|
<<EOH; ## temp |
517 |
|
<a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> | |
518 |
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
519 |
|
<!-- <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | --> |
520 |
|
<a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> | |
521 |
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
522 |
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
523 |
|
<a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a> |
524 |
</div> |
</div> |
525 |
EOH |
EOH |
526 |
} |
} |
527 |
|
|
528 |
sub print_footer { |
sub print_footer { |
529 |
my ($page) = @_; |
my ($page, $lm) = @_; |
530 |
$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) |
531 |
# Walrus mod (1) start |
# Walrus mod (1) start |
532 |
my $cvslog = '$Revision$ $Date$'; |
my $cvslog1 = q$Revision$; |
533 |
|
my $cvslog2 = q$Date$; |
534 |
print_navigate_links ($page); |
print_navigate_links ($page); |
535 |
print <<"EOD"; |
print <<"EOD"; |
536 |
|
@{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]} |
537 |
<div class="footer"> |
<div class="footer"> |
538 |
<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> |
539 |
<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> |
|
540 |
<div class="navigation"> |
<div class="navigation"> |
541 |
[<a href="/" title="このサーバーの首頁">/</a> |
[<a href="/" title="このサーバーの首頁">/</a> |
542 |
<a href="/map" title="このサーバーの案内">地図</a> |
<a href="/map" title="このサーバーの案内">地図</a> |
583 |
return $s; |
return $s; |
584 |
} |
} |
585 |
|
|
586 |
sub print_content { |
sub print_content ($;$) { |
587 |
my ($rawcontent) = @_; |
my ($rawcontent, %option) = @_; |
588 |
print &text_to_html($rawcontent, toc=>1); |
print &text_to_html($rawcontent, toc=>1, %option); |
589 |
} |
} |
590 |
|
|
591 |
sub text_to_html { |
sub text_to_html { |
592 |
my ($txt, %option) = @_; |
my ($txt, %option) = @_; |
593 |
my (@txt) = split(/\n/, $txt); |
my (@txt) = split(/\n/, $txt); |
594 |
my (@toc); |
my @toc; |
595 |
|
my @toc2 = @{$option{-toc}||[]}; |
596 |
my $tocnum = 0; |
my $tocnum = 0; |
597 |
my (@saved, @result); |
my (@saved, @result); |
598 |
unshift(@saved, "</p>"); |
unshift(@saved, "</p>"); |
599 |
push(@result, "<p>"); |
push(@result, "<p>"); |
600 |
foreach (@txt) { |
foreach (@txt) { |
601 |
chomp; |
chomp; |
602 |
if (/^\*\*\*\*\*(.*)/) { |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
603 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
604 |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
605 |
$tocnum++; |
$tocnum++; |
606 |
} elsif (/^\*\*\*\*(.*)/) { |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
607 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
608 |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
609 |
$tocnum++; |
$tocnum++; |
610 |
} elsif (/^\*\*\*(.*)/) { |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
611 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
612 |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
613 |
$tocnum++; |
$tocnum++; |
614 |
} elsif (/^\*\*(.*)/) { |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
615 |
# if (/^\*\*(.*)/) { |
# if (/^\*\*(.*)/) { |
616 |
# Walrus mod (6) end |
# Walrus mod (6) end |
617 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
618 |
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>'); |
619 |
$tocnum++; |
$tocnum++; |
620 |
} elsif (/^\*(.*)/) { |
} elsif (/^\*([^\x0D\x0A]*)/) { |
621 |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n)); |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
622 |
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>'); |
623 |
$tocnum++; |
$tocnum++; |
624 |
#} elsif (/^----/) { |
} elsif (/^(={1,6})(.*)/) { |
|
# push(@result, splice(@saved), '<hr>'); |
|
|
} elsif (/^(={1,5})(.*)/) { |
|
625 |
&back_push('ol', length($1), \@saved, \@result); |
&back_push('ol', length($1), \@saved, \@result); |
626 |
push(@result, '<li>' . &inline($2) . '</li>'); |
push(@result, '<li>' . &inline($2) . '</li>'); |
627 |
} elsif (/^(-{1,5})(.*)/) { |
} elsif (/^(-{1,6})(.*)/) { |
628 |
&back_push('ul', length($1), \@saved, \@result); |
&back_push('ul', length($1), \@saved, \@result); |
629 |
push(@result, '<li>' . &inline($2) . '</li>'); |
my ($pf, $l) = ('', $2); |
630 |
|
if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { |
631 |
|
my $num = 0+$1; |
632 |
|
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
633 |
|
} |
634 |
|
push(@result, '<li>' . $pf . &inline ($l) . '</li>'); |
635 |
} elsif (/^:([^:]+):(.*)/) { |
} elsif (/^:([^:]+):(.*)/) { |
636 |
&back_push('dl', 1, \@saved, \@result); |
&back_push('dl', 1, \@saved, \@result); |
637 |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
638 |
} elsif (/^(>{1,5})(.*)/) { |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
639 |
&back_push('blockquote', length($1), \@saved, \@result); |
&back_push('blockquote', length($1), \@saved, \@result); |
640 |
|
push @result, "<p>"; |
641 |
push(@result, &inline($2)); |
push(@result, &inline($2)); |
642 |
|
unshift @saved, "</p>"; |
643 |
} elsif (/^\s*$/) { |
} elsif (/^\s*$/) { |
644 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
|
unshift(@saved, "</p>"); |
|
645 |
push(@result, "<p>"); |
push(@result, "<p>"); |
646 |
|
unshift(@saved, "</p>"); |
647 |
} elsif (/^(\s+.*)$/) { |
} elsif (/^(\s+.*)$/) { |
648 |
&back_push('pre', 1, \@saved, \@result); |
&back_push('pre', 1, \@saved, \@result); |
649 |
#push(@result, &escape($1)); # Not &inline, but &escape |
#push(@result, &escape($1)); # Not &inline, but &escape |
650 |
push(@result, &inline($1)); # Not &inline, but &escape |
push(@result, &inline($1)); |
651 |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
652 |
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
653 |
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
672 |
push(@result, join('', '<tr>', @value, '</tr>')); |
push(@result, join('', '<tr>', @value, '</tr>')); |
673 |
# XXXXX |
# XXXXX |
674 |
####### |
####### |
675 |
|
} elsif (/^\[(INS|DEL|PRE)\[\s*$/) { |
676 |
|
push @result, splice (@saved), '<'.lc($1).'>'; |
677 |
|
unshift @saved, "</p>"; |
678 |
|
push @result, "<p>"; |
679 |
|
} elsif (/^\](INS|DEL|PRE)\]\s*$/) { |
680 |
|
push @result, splice (@saved), '</'.lc($1).'>'; |
681 |
|
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
682 |
|
my $num = 0+$1; |
683 |
|
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
684 |
|
push @result, &inline ($2); |
685 |
} else { |
} else { |
686 |
push(@result, &inline($_)); |
push(@result, &inline($_)); |
687 |
} |
} |
688 |
} |
} |
689 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
690 |
|
|
691 |
|
my $toc = ''; |
692 |
if ($option{toc}) { |
if ($option{toc}) { |
693 |
# Convert @toc (table of contents) to HTML. |
# Convert @toc (table of contents) to HTML. |
694 |
# This part is taken from Makio Tsukamoto's WalWiki. |
# This part is taken from Makio Tsukamoto's WalWiki. |
695 |
my (@tocsaved, @tocresult); |
my (@tocsaved, @tocresult); |
696 |
foreach (@toc) { |
foreach (@toc,@toc2) { |
697 |
if (/^(-{1,3})(.*)/) { |
if (/^(-{1,6})(.*)$/) { |
698 |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
699 |
push(@tocresult, '<li>' . $2 . '</li>'); |
push(@tocresult, '<li>' . $2 . '</li>'); |
700 |
} |
} |
701 |
} |
} |
702 |
push(@tocresult, splice(@tocsaved)); |
push(@tocresult, splice(@tocsaved)); |
703 |
return join("\n", @tocresult, @result); |
$toc = join("\n", @tocresult); |
704 |
} else { |
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
|
return join("\n", @result); |
|
705 |
} |
} |
706 |
|
$toc .= join("\n", @result); |
707 |
|
$toc =~ s#<p>\n</p>##g; |
708 |
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
709 |
|
$toc =~ s#<pre>\n#<pre>#g; |
710 |
|
$toc; |
711 |
} |
} |
712 |
|
|
713 |
sub back_push { |
sub back_push { |
727 |
sub inline { |
sub inline { |
728 |
my ($line) = @_; |
my ($line) = @_; |
729 |
$line = &escape($line); |
$line = &escape($line); |
730 |
$line =~ s|'''([^']+?)'''|<strong>$1</strong>|g; |
$line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g; |
731 |
$line =~ s|''([^']+?)''|<em>$1</em>|g; |
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
732 |
$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:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
733 |
$line =~ s! |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g; |
734 |
( |
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
735 |
(?:<(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)> |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g; |
736 |
| |
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g; |
737 |
($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
738 |
| |
$line =~ s|''([^']+)''|<em>$1</em>|g; |
739 |
($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]] |
$line =~ s{ |
740 |
#| |
((?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
741 |
# ($wiki_name) |
|\[\[([^[]+?)]>>([0-9]+)] # [[WikiName]>>1] |
742 |
) |
|>>([0-9]+) |
743 |
! |
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
744 |
&make_link($1) |
}{ |
745 |
!gex; |
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
746 |
|
if ($l) { |
747 |
|
&make_link($l) |
748 |
|
} elsif (defined $page) { |
749 |
|
&make_wikilink ($page, anchor => 0+$anchor); |
750 |
|
} elsif ($anum) { |
751 |
|
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
752 |
|
} elsif ($uri) { |
753 |
|
&make_urilink ($uri); |
754 |
|
} |
755 |
|
}gex; |
756 |
return $line; |
return $line; |
757 |
} |
} |
758 |
|
|
759 |
|
sub make_wikilink ($%) { |
760 |
|
my ($ename, %option) = @_; |
761 |
|
my $name = &unescape ($ename); |
762 |
|
if ($database{$name}) { |
763 |
|
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
764 |
|
if ($option{anchor}) { |
765 |
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
766 |
|
} else { |
767 |
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
768 |
|
} |
769 |
|
} else { |
770 |
|
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>); |
771 |
|
} |
772 |
|
} |
773 |
|
|
774 |
|
sub make_urilink ($;%) { |
775 |
|
require URI; |
776 |
|
my $uri = shift; |
777 |
|
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
778 |
|
$uri = &unescape ($uri); |
779 |
|
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
780 |
|
my ($site, $name) = ($1, $2); |
781 |
|
for ($site, $name) { |
782 |
|
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
783 |
|
} |
784 |
|
if ($interwiki{$site}) { |
785 |
|
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
786 |
|
$site = &escape ($site); $name = &escape ($name); |
787 |
|
qq(<<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: <$uri>">$name</a>>); |
788 |
|
} else { |
789 |
|
qq(<未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>); |
790 |
|
} |
791 |
|
} else { |
792 |
|
qq(<不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>); |
793 |
|
} |
794 |
|
} elsif ($uri =~ /^urn:/) { ## URN |
795 |
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
796 |
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
797 |
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
798 |
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
799 |
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
800 |
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
801 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
802 |
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
803 |
|
} else { ## misc. URI |
804 |
|
CGI::Carp::warningsToBrowser (0); |
805 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
806 |
|
CGI::Carp::warningsToBrowser (1); |
807 |
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
808 |
|
} |
809 |
|
} |
810 |
|
|
811 |
|
## to be obsoleted |
812 |
sub make_link { |
sub make_link { |
813 |
my $chunk = shift; |
my $chunk = shift; |
814 |
# Walrus add (3) start |
# Walrus add (3) start |
815 |
$chunk =~ s/^<(.*)>$/$1/; |
$chunk =~ s/^<(.*)>$/$1/; |
816 |
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">) ; |
|
|
} |
|
817 |
$name = &unarmor_name($name); |
$name = &unarmor_name($name); |
818 |
# Walrus add (3) end |
# Walrus add (3) end |
819 |
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$/) { |
|
820 |
return &embedded_to_html($chunk); |
return &embedded_to_html($chunk); |
821 |
} else { |
} else { |
822 |
$chunk = &unarmor_name($chunk); |
$chunk = &unarmor_name($chunk); |
823 |
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
824 |
my $cookedchunk = &encode($chunk); |
my $cookedchunk = &encode($chunk); |
825 |
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">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} else { |
|
|
# return $chunk; # Walrus del (3) |
|
|
return &escape($name); # Walrus add (3) |
|
|
} |
|
|
} elsif ($database{$chunk}) { |
|
826 |
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
827 |
# 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) |
828 |
return qq(<a title="$subject" href="$url_cgi?$cookedchunk">@{[&escape($name)]}</a>); # Walrus add (3) |
return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
829 |
} elsif ($page_command{$chunk}) { |
} elsif ($page_command{$chunk}) { |
830 |
# 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) |
831 |
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
849 |
if (param()) { |
if (param()) { |
850 |
foreach my $var (param()) { |
foreach my $var (param()) { |
851 |
$form{$var} = param($var); |
$form{$var} = param($var); |
852 |
} |
} |
|
} else { |
|
|
$ENV{QUERY_STRING} = $FrontPage; |
|
853 |
} |
} |
854 |
|
if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) { |
855 |
my $query = &decode($ENV{QUERY_STRING}); |
my $query = &decode($main::ENV{QUERY_STRING}); |
856 |
if ($page_command{$query}) { |
if ($page_command{$query}) { |
857 |
$form{mycmd} = $page_command{$query}; |
$form{mycmd} = $page_command{$query}; |
858 |
$form{mypage} = $query; |
$form{mypage} = $query; |
859 |
} elsif ($query =~ /^($wiki_name)$/) { |
} else { |
|
$form{mycmd} = 'read'; |
|
|
$form{mypage} = $1; |
|
|
} elsif ($database{$query}) { |
|
|
$form{mycmd} = 'read'; |
|
860 |
$form{mypage} = $query; |
$form{mypage} = $query; |
861 |
|
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
862 |
|
} |
863 |
} |
} |
864 |
|
$form{mypage} ||= 'HomePage'; |
865 |
|
|
866 |
# mypreview_edit -> do_edit, with preview. |
# mypreview_edit -> do_edit, with preview. |
867 |
# mypreview_adminedit -> do_adminedit, with preview. |
# mypreview_adminedit -> do_adminedit, with preview. |
873 |
} |
} |
874 |
} |
} |
875 |
|
|
876 |
# |
# |
877 |
# $form{mycmd} is frozen here. |
# $form{mycmd} is frozen here. |
878 |
# |
# |
879 |
|
|
880 |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
881 |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
882 |
} |
} |
883 |
|
|
884 |
sub update_recent_changes { |
sub update_recent_changes { |
885 |
my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}"; |
my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; |
886 |
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
887 |
my @updates; |
my @updates; |
888 |
foreach (@oldupdates) { |
foreach (@oldupdates) { |
889 |
/^\- \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+?)\]\]/; |
890 |
my $name = &unarmor_name($1); |
my $name = $1; |
891 |
if (&is_exist_page($name) and ($name ne $form{mypage})) { |
if ($name ne $form{mypage}) { |
892 |
push(@updates, $_); |
push @updates, $_; |
893 |
} |
} |
894 |
} |
} |
895 |
if (&is_exist_page($form{mypage})) { |
if (&is_exist_page($form{mypage})) { |
896 |
unshift(@updates, $update); |
unshift @updates, $update; |
897 |
} |
} |
898 |
splice(@updates, $maxrecent + 1); |
splice(@updates, $maxrecent + 1); |
899 |
$database{$RecentChanges} = join("\n", @updates); |
$database{$RecentChanges} = join("\n", @updates); |
917 |
|
|
918 |
# Get the subject of the page. |
# Get the subject of the page. |
919 |
my $subject = $database{$page}; |
my $subject = $database{$page}; |
920 |
|
$subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; |
921 |
$subject =~ s/\r?\n.*//s; |
$subject =~ s/\r?\n.*//s; |
922 |
return "$delim$subject"; |
return "$delim$subject".$option{tail}; |
923 |
} |
} |
924 |
} |
} |
925 |
|
|
1000 |
my ($word) = @_; |
my ($word) = @_; |
1001 |
print <<"EOD"; |
print <<"EOD"; |
1002 |
<form action="$url_cgi" method="get"> |
<form action="$url_cgi" method="get"> |
1003 |
<input type="hidden" name="mycmd" value="search"> |
<input type="hidden" name="mycmd" value="read"> |
1004 |
<input type="text" name="mymsg" value="$word" size="20"> |
<input type="text" name="mypage" value="$word" size="20"> |
1005 |
<input type="submit" value="$resource{searchbutton}"> |
<input type="submit" value="$resource{searchbutton}"> |
1006 |
</form> |
</form> |
1007 |
EOD |
EOD |
1025 |
} |
} |
1026 |
$mymsg = &escape($form{mymsg}); |
$mymsg = &escape($form{mymsg}); |
1027 |
} else { |
} else { |
1028 |
$mymsg = &escape($mymsg); |
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
1029 |
} |
} |
1030 |
|
|
1031 |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
1034 |
|
|
1035 |
print <<"EOD"; |
print <<"EOD"; |
1036 |
<form action="$url_cgi" method="post"> |
<form action="$url_cgi" method="post"> |
1037 |
|
<h2>$escapedmypageの編集</h2> |
1038 |
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]} |
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]} |
1039 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1040 |
<input type="hidden" name="mypage" value="$escapedmypage"> |
<input type="hidden" name="mypage" value="$escapedmypage"> |
1041 |
<textarea cols="$cols" rows="$rows" name="mymsg" wrap="off" tabindex="1">$mymsg</textarea><br> |
<textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br> |
1042 |
@{[ |
@{[ |
1043 |
$mode{admin} ? |
$mode{admin} ? |
1044 |
qq( |
qq( |
1051 |
qq( |
qq( |
1052 |
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
1053 |
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
1054 |
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br> |
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd> |
1055 |
|
[@{[do {my $n = 0; |
1056 |
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
1057 |
|
++$n}]}]<br> |
1058 |
) |
) |
1059 |
]} |
]} |
1060 |
</form> |
</form> |
1061 |
EOD |
EOD |
1062 |
unless ($mode{conflict}) { |
unless ($mode{conflict}) { |
1063 |
# Show the format rule. |
# Show the format rule. |
1064 |
open(FILE, $file_format) or &print_error("($file_format)"); |
my $help = $database{'WikiEditHelp'}; |
1065 |
my $content = join('', <FILE>); |
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1066 |
&code_convert(\$content, $kanjicode); |
print &text_to_html ($help, toc => 0); |
1067 |
close(FILE); |
# open(FILE, $file_format) or &print_error("($file_format)"); |
1068 |
print &text_to_html($content, toc=>0); |
# my $content = join('', <FILE>); |
1069 |
|
# &code_convert(\$content, $kanjicode); |
1070 |
|
# close(FILE); |
1071 |
|
# print &text_to_html($content, toc=>0); |
1072 |
} |
} |
1073 |
} |
} |
1074 |
|
|
1086 |
|
|
1087 |
sub is_editable { |
sub is_editable { |
1088 |
my ($page) = @_; |
my ($page) = @_; |
1089 |
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$/) { |
|
1090 |
return 0; |
return 0; |
1091 |
} else { |
} else { |
1092 |
return 1; |
return 1; |
1096 |
# armor_name: |
# armor_name: |
1097 |
# WikiName -> WikiName |
# WikiName -> WikiName |
1098 |
# not_wiki_name -> [[not_wiki_name]] |
# not_wiki_name -> [[not_wiki_name]] |
1099 |
sub armor_name { |
sub armor_name { qq([[$_[0]]]) } |
|
my ($name) = @_; |
|
|
if ($name =~ /^$wiki_name$/) { |
|
|
return $name; |
|
|
} else { |
|
|
return "[[$name]]"; |
|
|
} |
|
|
} |
|
1100 |
|
|
1101 |
# unarmor_name: |
# unarmor_name: |
1102 |
# [[bracket_name]] -> bracket_name |
# [[bracket_name]] -> bracket_name |
1110 |
} |
} |
1111 |
} |
} |
1112 |
|
|
|
sub is_bracket_name { |
|
|
my ($name) = @_; |
|
|
if ($name =~ /^$bracket_name$/) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
1113 |
sub decode { |
sub decode { |
1114 |
my ($s) = @_; |
my ($s) = @_; |
1115 |
$s =~ tr/+/ /; |
$s =~ tr/+/ /; |
1150 |
my $content = join('', <FILE>); |
my $content = join('', <FILE>); |
1151 |
&code_convert(\$content, $kanjicode); |
&code_convert(\$content, $kanjicode); |
1152 |
close(FILE); |
close(FILE); |
1153 |
&print_header($page); |
&print_header($page, -noindex => 1); |
1154 |
&print_content($content); |
&print_content($content); |
1155 |
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
1156 |
&print_footer($page); |
&print_footer($page); |
1159 |
|
|
1160 |
sub get_now { |
sub get_now { |
1161 |
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
1162 |
|
my (@week) = qw(日 月 火 水 木 金 土); |
1163 |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
1164 |
$year += 1900; |
$year += 1900; |
1165 |
$mon++; |
$mon++; |
1167 |
$day = "0$day" if $day < 10; |
$day = "0$day" if $day < 10; |
1168 |
$hour = "0$hour" if $hour < 10; |
$hour = "0$hour" if $hour < 10; |
1169 |
$min = "0$min" if $min < 10; |
$min = "0$min" if $min < 10; |
1170 |
$sec = "0$sec" if $sec < 10; |
#$sec = "0$sec" if $sec < 10; |
1171 |
$weekday = $week[$weekday]; |
$weekday = $week[$weekday]; |
1172 |
return "$year-$mon-$day ($weekday) $hour:$min:$sec"; |
return "$year-$mon-$day ($weekday) $hour:$min"; |
1173 |
} |
} |
1174 |
|
|
|
# [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]] |
|
1175 |
sub init_InterWikiName { |
sub init_InterWikiName { |
1176 |
my $content = $database{$InterWikiName}; |
my @content = split /\n/, $database{$InterWikiName}; |
1177 |
while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) { |
for (@content) { |
1178 |
my ($name, $url) = ($1, $2); |
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
1179 |
$interwiki{$name} = $url; |
$interwiki{$1} = $2; |
1180 |
} |
} |
1181 |
|
} |
1182 |
|
require Message::Util::Formatter; |
1183 |
|
$fmt{interwiki} = Message::Util::Formatter->new; |
1184 |
|
$fmt{interwiki}->{encoded} = sub { |
1185 |
|
my ($o, $p) = @_; |
1186 |
|
if ($o->{except}) { |
1187 |
|
$o->{except} =~ tr/\x00-\x20<>\x23%\x22{|}\x5C^[]`\x7F-\xFF//d; |
1188 |
|
} |
1189 |
|
my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit'); |
1190 |
|
$s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%02X', unpack 'C', $1/ge; |
1191 |
|
$s; |
1192 |
|
}; |
1193 |
|
$fmt{interwiki}->{ykwk} = sub { ## YukiWiki1 |
1194 |
|
my ($o, $p) = @_; |
1195 |
|
my $s = $p->{name}; |
1196 |
|
$s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/; |
1197 |
|
&encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis')); |
1198 |
|
}; |
1199 |
} |
} |
1200 |
|
|
|
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; |
|
|
} |
|
|
} |
|
1201 |
|
|
1202 |
sub get_info { |
sub get_info { |
1203 |
my ($page, $key) = @_; |
my ($page, $key) = @_; |
1252 |
|
|
1253 |
sub do_comment { |
sub do_comment { |
1254 |
my ($content) = $database{$form{mypage}}; |
my ($content) = $database{$form{mypage}}; |
1255 |
my $datestr = &get_now; |
my $default_name; ## this code does not strict. |
1256 |
my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " "; |
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
1257 |
if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) { |
my $datestr = '[WEAK['.&get_now.']]'; |
1258 |
; |
my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; |
1259 |
} else { |
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
1260 |
$content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/; |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
1261 |
|
$namestr = qq( ''$namestr'': ); |
1262 |
|
} elsif (length $namestr) { |
1263 |
|
$namestr = qq( ''[[$namestr]]'': ); |
1264 |
|
} |
1265 |
|
my $anchor = 0; |
1266 |
|
$content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
1267 |
|
$anchor++; |
1268 |
|
my $i = 1; my $o = 0; |
1269 |
|
$content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ |
1270 |
|
my $embed = $1; |
1271 |
|
if ($i == $form{comment_index}) { |
1272 |
|
if ($embed eq $embed_comment) { |
1273 |
|
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
1274 |
|
} else { |
1275 |
|
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
1276 |
|
} |
1277 |
|
} |
1278 |
|
$i++; $embed; |
1279 |
|
}ge; |
1280 |
|
unless ($o) { |
1281 |
|
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1282 |
|
$content .= "\n" unless $content =~ /\n$/s; |
1283 |
|
$content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; |
1284 |
} |
} |
1285 |
if ($form{mymsg}) { |
$form{__comment_anchor_index} = $anchor; |
1286 |
|
if ($form{mymsg} || $form{myname}) { |
1287 |
$form{mymsg} = $content; |
$form{mymsg} = $content; |
1288 |
$form{mytouch} = 'on'; |
$form{mytouch} = 'on'; |
1289 |
&do_write; |
&do_write; |
1293 |
} |
} |
1294 |
} |
} |
1295 |
|
|
1296 |
|
my $CommentIndex = 0; |
1297 |
sub embedded_to_html { |
sub embedded_to_html { |
1298 |
my ($embedded) = @_; |
my ($embedded) = @_; |
1299 |
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
1300 |
|
unless ($main::_EMBEDED) { |
1301 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
1302 |
return <<"EOD"; |
return <<"EOD"; |
1303 |
<form action="$url_cgi" method="post"> |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
1304 |
<input type="hidden" name="mycmd" value="comment"> |
<input type="hidden" name="mycmd" value="comment"> |
1305 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
<input type="hidden" name="mypage" value="$form{mypage}"> |
1306 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1307 |
<input type="hidden" name="mytouch" value="on"> |
<input type="hidden" name="mytouch" value="on"> |
1308 |
$resource{yourname} |
<input type="hidden" name="comment_index" value="$CommentIndex"> |
1309 |
<input type="text" name="myname" value="" size="10"> |
$embed_comment_Name_Prompt |
1310 |
<input type="text" name="mymsg" value="" size="40"> |
<input type="text" name="myname" value="" size="10" class="comment-name"> |
1311 |
<input type="submit" value="$resource{commentbutton}"> |
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
1312 |
</form> |
<input type="submit" value="$resource{commentbutton}" class="comment-submit"> |
1313 |
|
</p></form> |
1314 |
|
EOD |
1315 |
|
} else { |
1316 |
|
return <<"EOD"; |
1317 |
|
<del><form action="$url_cgi" method="get"> |
1318 |
|
<input type="hidden" name="mycmd" value="read"> |
1319 |
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1320 |
|
$embed_comment_Name_Prompt |
1321 |
|
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
1322 |
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
1323 |
|
<input type="submit" value="$resource{commentbutton}" disabled="disabled"> |
1324 |
|
</form></del> |
1325 |
EOD |
EOD |
1326 |
|
} |
1327 |
} elsif ($embedded =~ /$embed_command{searched}/) { |
} elsif ($embedded =~ /$embed_command{searched}/) { |
1328 |
return get_search_result ($1); |
return get_search_result ($1, -match_myself => 1); |
1329 |
# Walrus add (5) start |
# Walrus add (5) start |
1330 |
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
1331 |
$_ = &make_interwiki_box($1, $2); |
$_ = &make_interwiki_box($1, $2); |
1332 |
return ($_) ? $_ : $embedded; |
return ($_) ? $_ : $embedded; |
1333 |
# Walrus add (5) end |
# Walrus add (5) end |
1334 |
} else { |
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
1335 |
return $embedded; |
my ($name, $r) = ($1, ''); |
1336 |
} |
if ($main::_EMBEDED != 1) { |
1337 |
|
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
1338 |
|
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1339 |
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
1340 |
|
$main::_EMBEDED = 1; |
1341 |
|
$r = &text_to_html ($content, content_format => $cf); |
1342 |
|
$main::_EMBEDED = 0; |
1343 |
|
} elsif (length $content) { |
1344 |
|
$r = "<pre>@{[&escape ($content)]}</pre>"; |
1345 |
|
} else { |
1346 |
|
$r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1347 |
|
} |
1348 |
|
} else { ## nested #EMBED |
1349 |
|
$r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1350 |
|
} |
1351 |
|
return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>); |
1352 |
|
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
1353 |
|
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
1354 |
|
} else { |
1355 |
|
return $embedded; |
1356 |
|
} |
1357 |
} |
} |
1358 |
|
|
1359 |
# Walrus add (5) start |
# Walrus add (5) start |
1392 |
# Walrus add (5) end |
# Walrus add (5) end |
1393 |
|
|
1394 |
sub code_convert { |
sub code_convert { |
1395 |
my ($contentref, $kanjicode) = @_; |
my ($contentref, $code) = (shift, shift || $kanjicode); |
1396 |
# &Jcode::convert($contentref, $kanjicode); # for Jcode.pm |
$code = 'jis' if $code =~ /iso/; |
1397 |
&jcode::convert($contentref, $kanjicode); # for jcode.pl |
$code = 'euc' if $code =~ /euc/; |
1398 |
|
$code = 'sjis' if $code =~ /shift/; |
1399 |
|
$code = 'utf8' if $code =~ /utf/; |
1400 |
|
# &Jcode::convert($contentref, $code); # for Jcode.pm |
1401 |
|
&jcode::convert($contentref, $code); # for jcode.pl |
1402 |
return $$contentref; |
return $$contentref; |
1403 |
} |
} |
1404 |
|
|
1472 |
} |
} |
1473 |
&open_diff; |
&open_diff; |
1474 |
my $title = $form{mypage}; |
my $title = $form{mypage}; |
1475 |
&print_header($title); |
&print_header($title, -noindex => 1); |
1476 |
$_ = &escape($diffbase{$form{mypage}}); |
$_ = &escape($diffbase{$form{mypage}}); |
1477 |
&close_diff; |
&close_diff; |
1478 |
print qq(<h3>$resource{difftitle}</h3>); |
print qq(<h3>$resource{difftitle}</h3>); |
1508 |
my $count = 0; |
my $count = 0; |
1509 |
foreach (split(/\n/, $recentchanges)) { |
foreach (split(/\n/, $recentchanges)) { |
1510 |
last if ($count >= 15); |
last if ($count >= 15); |
1511 |
/^\- \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. |
1512 |
my $title = &unarmor_name($1); |
my $title = &unarmor_name($1); |
1513 |
my $escaped_title = &escape($title); |
my $escaped_title = &escape($title); |
1514 |
my $link = $modifier_rss_link . '?' . &encode($title); |
my $link = $modifier_rss_link . '?' . &encode($title); |
1537 |
} |
} |
1538 |
} |
} |
1539 |
|
|
1540 |
|
sub __get_database ($) { $database{ $_[0] } } |
1541 |
|
|
1542 |
|
package wiki::referer; |
1543 |
|
sub add ($$) { |
1544 |
|
my $page = shift; |
1545 |
|
my $uri = shift; |
1546 |
|
unless (ref $uri) { |
1547 |
|
require URI; |
1548 |
|
$uri = URI->new ($uri); |
1549 |
|
## Some schemes do not have query part. |
1550 |
|
eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ }; |
1551 |
|
$uri->fragment (undef); |
1552 |
|
} |
1553 |
|
$uri = $uri->canonical; |
1554 |
|
return unless $uri; |
1555 |
|
for my $regex (&get_dont_record) { |
1556 |
|
return if $uri =~ /$regex/; |
1557 |
|
} |
1558 |
|
my %list = get ($page); |
1559 |
|
$list{ $uri }++; |
1560 |
|
set ($page, \%list); |
1561 |
|
} |
1562 |
|
sub get ($) { |
1563 |
|
my $page = shift; |
1564 |
|
split /"/, main::get_info ($page, 'Referer'); |
1565 |
|
} |
1566 |
|
sub set ($%) { |
1567 |
|
my $page = shift; |
1568 |
|
my $list = shift; |
1569 |
|
main::set_info ($page, Referer => join '"', %$list); |
1570 |
|
} |
1571 |
|
|
1572 |
|
sub get_dont_record () { |
1573 |
|
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
1574 |
|
grep !/^#/, |
1575 |
|
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
1576 |
|
} |
1577 |
|
sub get_site_name () { |
1578 |
|
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
1579 |
|
my @item; |
1580 |
|
for (@lines) { |
1581 |
|
next if /^#/; |
1582 |
|
my ($uri, $name) = split /\s+/, $_, 2; |
1583 |
|
$uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; |
1584 |
|
$name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; |
1585 |
|
push @item, [$uri, qq(q($name))]; |
1586 |
|
} |
1587 |
|
@item; |
1588 |
|
} |
1589 |
|
|
1590 |
|
sub list_html ($) { |
1591 |
|
my $page = shift; |
1592 |
|
my %list = get ($page); |
1593 |
|
my $r = ''; |
1594 |
|
my @name = get_site_name; |
1595 |
|
for my $uri (sort keys %list) { |
1596 |
|
my $title; |
1597 |
|
for my $item (@name) { |
1598 |
|
if ($uri =~ /$item->[0]/) { |
1599 |
|
$title = $uri; |
1600 |
|
eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} |
1601 |
|
or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; |
1602 |
|
last; |
1603 |
|
} |
1604 |
|
} |
1605 |
|
my $euri = main::escape ($uri); |
1606 |
|
if ($title) { |
1607 |
|
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
1608 |
|
} else { |
1609 |
|
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
1610 |
|
} |
1611 |
|
} |
1612 |
|
$r ? qq(<ul>$r</ul>\n) : ''; |
1613 |
|
} |
1614 |
|
|
1615 |
|
sub __decode ($) { |
1616 |
|
my $s = shift; |
1617 |
|
$s =~ tr/+/ /; |
1618 |
|
$s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge; |
1619 |
|
main::code_convert (\$s); |
1620 |
|
} |
1621 |
|
|
1622 |
1; |
1; |
1623 |
__END__ |
__END__ |
1624 |
=head1 NAME |
=head1 NAME |