1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
# |
## wiki.cgi --- This is SuikaWiki, yet another WikiEngine |
|
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
|
|
# |
|
|
# Copyright (C) 2000-2002 by Hiroshi Yuki. |
|
|
# <hyuki@hyuki.com> |
|
|
# http://www.hyuki.com/yukiwiki/ |
|
|
# |
|
|
# This program is free software; you can redistribute it and/or |
|
|
# modify it under the same terms as Perl itself. |
|
|
# |
|
|
# walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
|
3 |
|
|
|
# Walrus add (debug) start |
|
|
my $walrus_log; |
|
|
my $walrus_debugging = 0; |
|
|
# Walrus add (debug) end |
|
|
|
|
|
# Libraries. |
|
4 |
use strict; |
use strict; |
|
use lib qw(./WalWiki/lib); |
|
|
use CGI qw(:standard); |
|
5 |
use CGI::Carp qw(fatalsToBrowser); |
use CGI::Carp qw(fatalsToBrowser); |
6 |
use Yuki::RSS; |
our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
7 |
use Yuki::DiffText qw(difftext); |
require 'wikidata/suikawiki-config.ph'; ## the site configuration script |
8 |
use Yuki::YukiWikiDB; |
require 'suikawiki.pl'; ## the main script |
|
use AnyDBM_File; |
|
|
require 'jcode.pl'; |
|
|
require Jcode; |
|
|
use Fcntl; |
|
|
my $version = '2.0.beta1.2002-05-29'; |
|
|
my $walversion; |
|
|
############################## |
|
|
# |
|
|
# You MUST modify following '$modifier_...' variables. |
|
|
# |
|
|
my $modifier_mail = 'w@suika.fam.cx'; # Your mail address, like 'walrus@digit.que.ne.jp'. |
|
|
my $modifier_url = 'http://suika.fam.cx/~wakaba/'; # Your web page, like 'http://digit.que.ne.jp/work/'. |
|
|
my $modifier_name = '和'; # Your name, like 'Makio Tsukamoto'. |
|
|
# my $modifier_dbtype = 'AnyDBM_File'; # Fast, not available on some server, page size limited. |
|
|
# my $modifier_dbtype = 'dbmopen'; # Fast, not available on some server, page size limited. |
|
|
my $modifier_dbtype = 'YukiWikiDB'; # Slow, available on all environment. |
|
|
# my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail. |
|
|
my $modifier_sendmail = ''; # If you don't need mail notification. |
|
|
my $modifier_dir_data = './wikidata'; # Your data directory. |
|
|
my $modifier_rss_title = "SuikaWiki $walversion"; |
|
|
my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed. |
|
|
my $modifier_rss_description = 'This is SuikaWiki'; |
|
|
############################## |
|
|
# |
|
|
# You MAY modify following variables. |
|
|
# |
|
|
$SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/); |
|
|
my $file_touch = "$modifier_dir_data/touched.txt"; |
|
|
my $file_resource = "$modifier_dir_data/resource.txt"; |
|
|
my $file_FrontPage = "$modifier_dir_data/frontpage.txt"; |
|
|
my $file_conflict = "$modifier_dir_data/conflict.txt"; |
|
|
my $file_format = "$modifier_dir_data/format.txt"; |
|
|
my $url_cgi = '/~wakaba/-temp/wiki/wiki'; ## MUST be started from '/' |
|
|
my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle'; |
|
|
my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />'; |
|
|
my $maxrecent = 50; |
|
|
my $cols = 80; |
|
|
my $rows = 20; |
|
|
############################## |
|
|
# |
|
|
# You MAY, but do NOT NEED modify following variables. |
|
|
# |
|
|
my $dataname = "$modifier_dir_data/wiki"; |
|
|
my $infoname = "$modifier_dir_data/info"; |
|
|
my $diffname = "$modifier_dir_data/diff"; |
|
|
my $editchar = '?'; |
|
|
my $subject_delimiter = ' - '; |
|
|
my $use_autoimg = 1; # automatically convert image URL into <img> tag. |
|
|
my $use_exists = 0; # If you can use 'exists' method for your DB. |
|
|
############################## |
|
|
my $InterWikiName = 'InterWikiName'; |
|
|
my $RecentChanges = 'RecentChanges'; |
|
|
my $AdminChangePassword = 'AdminChangePassword'; |
|
|
my $CompletedSuccessfully = 'CompletedSuccessfully'; |
|
|
my $FrontPage = 'HomePage'; |
|
|
my $IndexPage = 'IndexPage'; |
|
|
my $SearchPage = 'SearchPage'; |
|
|
my $CreatePage = 'CreatePage'; |
|
|
my $ErrorPage = 'ErrorPage'; |
|
|
my $RssPage = 'RssPage'; |
|
|
my $NAME_OF_WikiPageLicense = 'WikiPageLicense'; |
|
|
my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. |
|
|
############################## |
|
|
my $bracket_name = '\[\[(\S+?)\]\]'; |
|
|
my $embedded_name = '\[\[(#\S+?)\]\]'; |
|
|
my %fmt; ## formatter objects |
|
|
############################## |
|
|
my $embed_comment = '[[#comment]]'; |
|
|
my $embed_rcomment = '[[#rcomment]]'; |
|
|
my $embed_comment_Name_Prompt = '名前:'; |
|
|
my $DEFAULT_embed_comment_name = '名無しさん'; |
|
|
my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5) |
|
|
my %embed_command = ( |
|
|
searched => '^\[\[#searched:([^\]]+)\]\]$', |
|
|
form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
|
|
); |
|
|
############################## |
|
|
my $info_LastModified = 'LastModified'; |
|
|
my $info_IsFrozen = 'IsFrozen'; |
|
|
my $info_AdminPassword = 'AdminPassword'; |
|
|
############################## |
|
|
my $kanjicode = 'euc'; |
|
|
my $charset = 'EUC-JP'; |
|
|
my $lang = 'ja'; |
|
|
my %fixedpage = ( |
|
|
$IndexPage => 1, |
|
|
$CreatePage => 1, |
|
|
$ErrorPage => 1, |
|
|
$RssPage => 1, |
|
|
$RecentChanges => 1, |
|
|
$SearchPage => 1, |
|
|
$AdminChangePassword => 1, |
|
|
$CompletedSuccessfully => 1, |
|
|
#$FrontPage => 1, |
|
|
WikiUserAgentList => 1, |
|
|
WikiPluginInfo => 1, |
|
|
); |
|
|
my %form; |
|
|
my %database; |
|
|
my %infobase; |
|
|
my %diffbase; |
|
|
my %resource; |
|
|
my %interwiki; |
|
|
############################## |
|
|
my %page_command = ( |
|
|
$IndexPage => 'index', |
|
|
$SearchPage => 'searchform', |
|
|
$CreatePage => 'create', |
|
|
$RssPage => 'rss', |
|
|
$AdminChangePassword => 'adminchangepasswordform', |
|
|
#$FrontPage => 'FrontPage', |
|
|
WikiPluginInfo => 'x_WikiPluginInfo', |
|
|
); |
|
|
my %command_do = ( |
|
|
read => \&do_read, |
|
|
TEXT_CSS => \&do_output_css, |
|
|
edit => \&do_edit, |
|
|
adminedit => \&do_adminedit, |
|
|
adminchangepasswordform => \&do_adminchangepasswordform, |
|
|
adminchangepassword => \&do_adminchangepassword, |
|
|
write => \&do_write, |
|
|
index => \&do_index, |
|
|
searchform => \&do_searchform, |
|
|
search => \&do_search, |
|
|
create => \&do_create, |
|
|
createresult => \&do_createresult, |
|
|
FrontPage => \&do_FrontPage, |
|
|
comment => \&do_comment, |
|
|
RandomJump => \&do_random_jump, |
|
|
rss => \&do_rss, |
|
|
diff => \&do_diff, |
|
|
interwikibox => \&do_interwiki_box, # Walrus add (5) |
|
|
wikiform => \&do_wikiform, |
|
|
x_WikiPluginInfo => \&do_wikiplugininfo, |
|
|
); |
|
|
############################## |
|
|
my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) |
|
|
############################## |
|
|
# &test_convert; |
|
|
my $UA = ''; ## User agent name |
|
|
############################## |
|
|
|
|
|
sub main { |
|
|
$UA = $main::ENV{HTTP_USER_AGENT}; |
|
|
&init_resource; |
|
|
&open_db; |
|
|
&init_form; |
|
|
&init_InterWikiName; |
|
|
if ($command_do{$form{mycmd}}) { |
|
|
&{$command_do{$form{mycmd}}}; |
|
|
} else { |
|
|
&do_FrontPage; |
|
|
} |
|
|
&close_db; |
|
|
} |
|
|
|
|
|
sub do_read { |
|
|
my $content = $database{$form{mypage}}; |
|
|
my $lm = &get_info($form{mypage}, $info_LastModified); |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
|
|
my @toc; |
|
|
push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c; |
|
|
push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl; |
|
|
my $cf = 'SuikaWiki/0.9'; |
|
|
## Should be support at least: |
|
|
## - 'SuikaWiki/0.9' CRLF |
|
|
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
|
|
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
|
|
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
|
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
|
|
&print_header ($form{mypage}, -last_modified => $lm, |
|
|
-content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/); |
|
|
&print_content ($content, content_format => $cf, last_modified => $lm, |
|
|
-toc => \@toc); |
|
|
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}}; |
|
|
} else { |
|
|
&print_header($form{mypage}, -last_modified => $lm); |
|
|
print "<pre>@{[&escape($content)]}</pre>"; |
|
|
} |
|
|
if ($c) { |
|
|
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>}; |
|
|
print $r; |
|
|
} |
|
|
if ($rl) { |
|
|
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer($form{mypage}, $lm); |
|
|
} |
|
|
|
|
|
sub do_output_css { |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
my $content = $database{$form{mypage}}; |
|
|
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
|
|
my $lm = &get_info($form{mypage}, $info_LastModified); |
|
|
print scalar make_navigate_links ($form{mypage}); |
|
|
print "Content-Type: text/css; charset=$charset\n"; |
|
|
print "Last-Modified: $lm\n"; |
|
|
print "\n"; |
|
|
print $content; |
|
|
} else { |
|
|
print "Status: 406 Unsupported Media Type\n"; |
|
|
&print_header('WikiPageIsNotCSS', -noindex => 1); |
|
|
&print_content($database{WikiPageIsNotCSS}); |
|
|
&print_footer('WikiPageIsNotCSS'); |
|
|
} |
|
|
} |
|
|
|
|
|
sub id_and_name ($) { |
|
|
my $name = shift; |
|
|
if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) { |
|
|
qq{id="$name"><a name="$name"></a}; |
|
|
} else { |
|
|
qq{id="$name"}; |
|
|
} |
|
|
} |
|
|
|
|
|
sub do_edit { |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
|
|
&print_header($page, -noindex => 1); |
|
|
if (not &is_editable($page)) { |
|
|
&print_message($resource{cantchange}); |
|
|
} elsif (&is_frozen($page)) { |
|
|
&print_message($resource{cantchange}); |
|
|
} else { |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
|
|
} |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
|
|
if ($c) { |
|
|
print q{<h2 id="wikipage-see-also">See also</h2>}; |
|
|
print $r; |
|
|
} |
|
|
if ($rl) { |
|
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer($page); |
|
|
} |
|
|
|
|
|
sub do_adminedit { |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
|
|
&print_header($page, -noindex => 1); |
|
|
if (not &is_editable($page)) { |
|
|
&print_message($resource{cantchange}); |
|
|
} else { |
|
|
&print_message($resource{passwordneeded}); |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1); |
|
|
} |
|
|
&print_footer($page); |
|
|
} |
|
|
|
|
|
sub do_adminchangepasswordform { |
|
|
&print_header($AdminChangePassword, -noindex => 1); |
|
|
&print_passwordform; |
|
|
&print_footer($AdminChangePassword); |
|
|
} |
|
|
|
|
|
sub do_adminchangepassword { |
|
|
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
|
|
&print_error($resource{passwordmismatcherror}); |
|
|
} |
|
|
my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); |
|
|
if ($validpassword_crypt) { |
|
|
if (not &valid_password($form{myoldpassword})) { |
|
|
&send_mail_to_admin(<<"EOD", "AdminChangePassword"); |
|
|
myoldpassword=$form{myoldpassword} |
|
|
mynewpassword=$form{mynewpassword} |
|
|
mynewpassword2=$form{mynewpassword2} |
|
|
EOD |
|
|
&print_error($resource{passworderror}); |
|
|
} |
|
|
} |
|
|
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
|
|
my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z'); |
|
|
my $salt1 = $token[(time | $$) % scalar(@token)]; |
|
|
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
|
|
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
|
|
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
|
|
|
|
|
&print_header($CompletedSuccessfully, -noindex => 1); |
|
|
&print_message($resource{passwordchanged}); |
|
|
&print_footer($CompletedSuccessfully); |
|
|
} |
|
|
|
|
|
sub do_index { |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
&print_header($IndexPage); |
|
|
print qq(<ul>); |
|
|
foreach my $page (sort keys %database) { |
|
|
if (&is_editable($page)) { |
|
|
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
|
|
# print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>); |
|
|
# print qq(<li>@{[0 + &is_frozen($page)]}</li>); |
|
|
} |
|
|
} |
|
|
print qq(</ul>); |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
|
|
if ($c) { |
|
|
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>}; |
|
|
print $r; |
|
|
} |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
|
|
if ($rl) { |
|
|
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>??????</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer($IndexPage); |
|
|
} |
|
|
|
|
|
sub do_write { |
|
|
if (&frozen_reject()) { |
|
|
return; |
|
|
} |
|
|
|
|
|
if (not &is_editable($form{mypage})) { |
|
|
&print_header($form{mypage}, -noindex => 1); |
|
|
&print_message($resource{cantchange}); |
|
|
&print_footer($form{mypage}); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (&conflict($form{mypage}, $form{mymsg})) { |
|
|
return; |
|
|
} |
|
|
|
|
|
# Making diff |
|
|
{ |
|
|
&open_diff; |
|
|
my @msg1 = split(/\n/, $database{$form{mypage}}); |
|
|
my @msg2 = split(/\n/, $form{mymsg}); |
|
|
$diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); |
|
|
&close_diff; |
|
|
} |
|
|
|
|
|
if ($form{mymsg}) { |
|
|
$database{$form{mypage}} = $form{mymsg}; |
|
|
&send_mail_to_admin($form{mypage}, "Modify"); |
|
|
if ($form{mytouch}) { |
|
|
&set_info($form{mypage}, $info_LastModified, '' . localtime); |
|
|
&update_recent_changes; |
|
|
} |
|
|
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
|
|
my $fragment = ''; |
|
|
$fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd}; |
|
|
if ($form{__comment_anchor_index}) { |
|
|
$fragment .= qq(#anchor-$form{__comment_anchor_index}); |
|
|
} elsif ($form{__wikiform_anchor_index}) { |
|
|
$fragment .= qq(#wikiform-$form{__wikiform_anchor_index}); |
|
|
} |
|
|
&print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment)); |
|
|
&print_message($resource{saved}); |
|
|
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
|
|
&print_footer($CompletedSuccessfully); |
|
|
} else { |
|
|
&send_mail_to_admin($form{mypage}, "Delete"); |
|
|
delete $database{$form{mypage}}; |
|
|
delete $infobase{$form{mypage}}; |
|
|
if ($form{mytouch}) { |
|
|
&update_recent_changes; |
|
|
} |
|
|
&print_header($form{mypage}, -noindex => 1); |
|
|
&print_message($resource{deleted}); |
|
|
&print_footer($form{mypage}); |
|
|
} |
|
|
} |
|
|
|
|
|
sub do_searchform { |
|
|
&print_header($SearchPage); |
|
|
&print_searchform(""); |
|
|
&print_footer($SearchPage); |
|
|
} |
|
|
|
|
|
sub do_search { |
|
|
my $word = $form{mymsg}; |
|
|
&print_header($SearchPage); |
|
|
&print_searchform(&escape($word)); |
|
|
print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1); |
|
|
&print_footer($SearchPage); |
|
|
} |
|
|
|
|
|
sub get_search_result ($;%) { |
|
|
my $word = lc shift; |
|
|
my %option = @_; |
|
|
my @r; |
|
|
foreach my $page (keys %database) { |
|
|
next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself}); |
|
|
my $content = $database{$page}; |
|
|
my $cf = 'SuikaWiki/0.9'; |
|
|
$cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s; |
|
|
next if $cf =~ /obsoleted="yes"/; |
|
|
if (index (lc $page, $word) > -1) { |
|
|
my $c = $content =~ s/\Q$word\E//gi; |
|
|
push @r, [$page, $c+20]; |
|
|
} elsif (index ($word, lc $page) > -1) { |
|
|
my $c = $content =~ s/\Q$word\E//gi; |
|
|
push @r, [$page, $c+10]; |
|
|
} elsif (my $c = $content =~ s/\Q$word\E//gi) { |
|
|
push @r, [$page, $c]; |
|
|
} |
|
|
} |
|
|
my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s }; |
|
|
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; |
|
|
$r = qq|<ul class="search-result">$r</ul>| if $r; |
|
|
get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found}; |
|
|
wantarray? ($r, scalar @r): $r; |
|
|
} |
|
|
|
|
|
sub do_create { |
|
|
&print_header($CreatePage); |
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<input type="hidden" name="mycmd" value="edit"> |
|
|
<strong>$resource{newpagename}</strong><br> |
|
|
<input type="text" name="mypage" value="" size="20"> |
|
|
<input type="submit" value="$resource{createbutton}"><br> |
|
|
</form> |
|
|
EOD |
|
|
&print_footer($CreatePage); |
|
|
} |
|
|
|
|
|
sub do_random_jump { |
|
|
my @list = keys %database; |
|
|
my $name = &encode ($list[rand @list]); |
|
|
my ($scheme) = 'http'; |
|
|
$scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
|
|
print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n"; |
|
|
print "\n"; |
|
|
} |
|
|
|
|
|
sub do_FrontPage { |
|
|
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
|
|
my $content = join('', <FILE>); |
|
|
&code_convert(\$content, $kanjicode); |
|
|
close(FILE); |
|
|
&print_header($FrontPage); |
|
|
&print_content($content); |
|
|
&print_footer($FrontPage); |
|
|
} |
|
|
|
|
|
sub print_error { |
|
|
my ($msg) = @_; |
|
|
&print_header($ErrorPage, -noindex => 1); |
|
|
print qq(<p><strong class="error">$msg</strong></p>); |
|
|
&print_footer($ErrorPage); |
|
|
exit(0); |
|
|
} |
|
|
|
|
|
sub print_header ($;%) { |
|
|
my ($page, %option) = @_; |
|
|
my $bodyclass = "normal"; |
|
|
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
|
|
$bodyclass = "frozen"; |
|
|
} |
|
|
$bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
|
|
if ($option{-goto}) { |
|
|
if ($UA =~ m#Opera|MSIE 2\.#) { |
|
|
$option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#; |
|
|
print qq{Refresh: 0; url=$option{-goto}\n}; |
|
|
$option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">); |
|
|
} else { |
|
|
$option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#; |
|
|
print qq{Refresh: 0; url="$option{-goto}"\n}; |
|
|
$option{-goto} = qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"">); |
|
|
} |
|
|
} |
|
|
print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; |
|
|
my $meta_ct = ''; |
|
|
if ($UA =~ m#Mozilla/2#) { |
|
|
$meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}}; |
|
|
print qq{Content-Type: $meta_ct\n}; |
|
|
$meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">}; |
|
|
} elsif ($UA =~ m#Infomosaic#) { |
|
|
print qq{Content-Type: text/html\n}; |
|
|
} else { |
|
|
print qq{Content-Type: text/html; charset=$charset\n}; |
|
|
} |
|
|
my $cookedpage = &encode($page); |
|
|
my $escapedpage = &escape($page); |
|
|
my ($Links, $links) = &make_navigate_links ($page); |
|
|
print $Links; |
|
|
print <<"EOD"; |
|
|
Content-Language: $lang |
|
|
Content-Style-Type: text/css |
|
|
|
|
|
<!-- |
|
|
<!DOCTYPE html |
|
|
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
|
|
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
|
|
<html lang="$lang"> |
|
|
<head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile"> |
|
|
$meta_ct$option{-goto} |
|
|
<title>$escapedpage</title> |
|
|
@{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']} |
|
|
@{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']} |
|
|
$links |
|
|
</head> |
|
|
<body class="$bodyclass"> |
|
|
EOD |
|
|
&print_navigate_links ($page); |
|
|
print <<EOD; |
|
|
<h1 class="header">@{[&escape($page)]}</h1> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub x_charset ($) { |
|
|
my $charset = lc shift; |
|
|
if ($charset eq 'euc-jp') { |
|
|
$charset = 'x-euc-jp'; |
|
|
} elsif ($charset eq 'shift_jis') { |
|
|
$charset = 'x-sjis'; |
|
|
} |
|
|
$charset; |
|
|
} |
|
|
|
|
|
sub print_navigate_links (@) { |
|
|
my ($page) = @_; |
|
|
my $editable = 0; |
|
|
my $admineditable = 0; |
|
|
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
|
|
$editable = 0; |
|
|
#$admineditable = 1; |
|
|
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
|
|
#$admineditable = 1; |
|
|
$editable = 1; |
|
|
} else { |
|
|
$editable = 0; |
|
|
} |
|
|
my $cookedpage = &encode($page); |
|
|
print <<EOH; |
|
|
<div class="tools"> |
|
|
@{[ $admineditable |
|
|
? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage" class="wiki-cmd">$resource{admineditbutton}</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
@{[ $editable |
|
|
? #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" class="wiki-cmd">編集</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
<a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd">表示</a> | |
|
|
@{[ $admineditable |
|
|
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage" class="wiki-cmd">$resource{diffbutton}</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
<a href="$url_cgi?$CreatePage" class="wiki">新規</a> | |
|
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
|
|
<a href="$url_cgi?$FrontPage" class="wiki">首頁</a> | |
|
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
|
|
<a href="$url_cgi?$RecentChanges" class="wiki">最新</a> |
|
|
</div> |
|
|
EOH |
|
|
} |
|
|
|
|
|
sub make_navigate_links ($) { |
|
|
my $page = shift; |
|
|
my @link; |
|
|
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{editbutton}} if &is_editable ($page) && !&is_frozen ($page); |
|
|
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{admineditbutton}} if &is_editable ($page) || &is_frozen ($page); |
|
|
push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>'View latest version of this page'}; |
|
|
push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'}; |
|
|
push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}}; |
|
|
push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'}; |
|
|
push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}}; |
|
|
push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'}; |
|
|
push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'}; |
|
|
push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to...'}; |
|
|
push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to (edit)...'}; |
|
|
push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>'Somewhere'}; |
|
|
my ($Links, $links) = ('', ''); |
|
|
for my $e (@link) { |
|
|
$links .= qq(<link); |
|
|
$Links .= qq(Link: <$e->{href}>); |
|
|
for my $attr (qw/rel rev href title class type hreflang charset/) { |
|
|
$links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr}; |
|
|
} |
|
|
for my $attr (qw/rel rev title/) { |
|
|
$Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr}; |
|
|
} |
|
|
$links .= qq(>\n); |
|
|
$Links .= qq(\n); |
|
|
} |
|
|
wantarray ? ($Links, $links) : $Links; |
|
|
} |
|
|
|
|
|
sub print_footer { |
|
|
my ($page, $lm) = @_; |
|
|
my $epage = &encode ($page); |
|
|
$walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) |
|
|
# Walrus mod (1) start |
|
|
my $cvslog1 = q$Revision$; |
|
|
my $cvslog2 = q$Date$; |
|
|
print_navigate_links ($page); |
|
|
print <<"EOD"; |
|
|
@{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]} |
|
|
<div class="footer"> |
|
|
<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> |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a> |
|
|
<div class="navigation"> |
|
|
[<a href="/" title="このサーバーの首頁">/</a> |
|
|
<a href="/map" title="このサーバーの案内">地図</a> |
|
|
<a href="/search/" title="このサーバーの検索">検索</a>] |
|
|
</div> |
|
|
<div class="myuri"> |
|
|
<<a href="$url_cgi?$epage">$url_cgi?$epage</a>> |
|
|
</div> |
|
|
</div> |
|
|
$walrus_log |
|
|
</body> |
|
|
</html> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub escape { |
|
|
my $s = shift; |
|
|
$s =~ s|\r\n|\n|g; |
|
|
$s =~ s|&|&|g; |
|
|
$s =~ s|<|<|g; |
|
|
$s =~ s|>|>|g; |
|
|
$s =~ s|"|"|g; |
|
|
return $s; |
|
|
} |
|
|
|
|
|
sub unescape { |
|
|
my $s = shift; |
|
|
# $s =~ s|\n|\r\n|g; |
|
|
$s =~ s|<|<|g; |
|
|
$s =~ s|>|>|g; |
|
|
$s =~ s|"|"|g; |
|
|
$s =~ s|&|&|g; |
|
|
return $s; |
|
|
} |
|
|
|
|
|
sub print_content ($;$) { |
|
|
my ($rawcontent, %option) = @_; |
|
|
print &text_to_html($rawcontent, toc=>1, %option); |
|
|
} |
|
|
|
|
|
sub text_to_html { |
|
|
my ($txt, %option) = @_; |
|
|
my (@txt) = split(/\n/, $txt); |
|
|
my @toc; |
|
|
my @toc2 = @{$option{-toc}||[]}; |
|
|
my $tocnum = 0; |
|
|
my (@saved, @result); |
|
|
unshift(@saved, "</p>"); |
|
|
push(@result, "<p>"); |
|
|
foreach (@txt) { |
|
|
chomp; |
|
|
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
|
|
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
|
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
|
|
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
|
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
|
|
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
|
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
|
|
# if (/^\*\*(.*)/) { |
|
|
# Walrus mod (6) end |
|
|
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
|
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*([^\x0D\x0A]*)/) { |
|
|
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
|
|
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>'); |
|
|
$tocnum++; |
|
|
} elsif (/^(={1,6})(.*)/) { |
|
|
&back_push('ol', length($1), \@saved, \@result); |
|
|
push(@result, '<li>' . &inline($2) . '</li>'); |
|
|
} elsif (/^(-{1,6})(.*)/) { |
|
|
&back_push('ul', length($1), \@saved, \@result); |
|
|
my ($pf, $l) = ('', $2); |
|
|
if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { |
|
|
my $num = 0+$1; |
|
|
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
|
|
} |
|
|
push(@result, '<li>' . $pf . &inline ($l) . '</li>'); |
|
|
} elsif (/^:([^:]+):(.*)/) { |
|
|
&back_push('dl', 1, \@saved, \@result); |
|
|
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
|
|
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
|
|
&back_push('blockquote', length($1), \@saved, \@result); |
|
|
push @result, "<p>"; |
|
|
push(@result, &inline($2)); |
|
|
unshift @saved, "</p>"; |
|
|
} elsif (/^\s*$/) { |
|
|
push(@result, splice(@saved)); |
|
|
push(@result, "<p>"); |
|
|
unshift(@saved, "</p>"); |
|
|
} elsif (/^(\s+.*)$/) { |
|
|
&back_push('pre', 1, \@saved, \@result); |
|
|
#push(@result, &escape($1)); # Not &inline, but &escape |
|
|
push(@result, &inline($1)); |
|
|
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
|
|
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
|
|
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
|
|
####### |
|
|
# This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki. |
|
|
# XXXXX |
|
|
my $tmp = "$1,"; |
|
|
my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g); |
|
|
my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value; |
|
|
my @colspan = map {($_ eq '==') ? 0 : 1} @value; |
|
|
for (my $i = 0; $i < @value; $i++) { |
|
|
if ($colspan[$i]) { |
|
|
while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') { |
|
|
$colspan[$i]++; |
|
|
} |
|
|
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; |
|
|
$value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i])); |
|
|
} else { |
|
|
$value[$i] = ''; |
|
|
} |
|
|
} |
|
|
push(@result, join('', '<tr>', @value, '</tr>')); |
|
|
# XXXXX |
|
|
####### |
|
|
} elsif (/^\[(INS|DEL|PRE)\[\s*$/) { |
|
|
push @result, splice (@saved), '<'.lc($1).'>'; |
|
|
unshift @saved, "</p>"; |
|
|
push @result, "<p>"; |
|
|
} elsif (/^\](INS|DEL|PRE)\]\s*$/) { |
|
|
push @result, splice (@saved), '</'.lc($1).'>'; |
|
|
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
|
|
my $num = 0+$1; |
|
|
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
|
|
push @result, &inline ($2); |
|
|
} else { |
|
|
push(@result, &inline($_)); |
|
|
} |
|
|
} |
|
|
push(@result, splice(@saved)); |
|
|
|
|
|
my $toc = ''; |
|
|
if ($option{toc}) { |
|
|
# Convert @toc (table of contents) to HTML. |
|
|
# This part is taken from Makio Tsukamoto's WalWiki. |
|
|
my (@tocsaved, @tocresult); |
|
|
foreach (@toc,@toc2) { |
|
|
if (/^(-{1,6})(.*)$/) { |
|
|
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
|
|
push(@tocresult, '<li>' . $2 . '</li>'); |
|
|
} |
|
|
} |
|
|
push(@tocresult, splice(@tocsaved)); |
|
|
$toc = join("\n", @tocresult); |
|
|
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
|
|
} |
|
|
$toc .= join("\n", @result); |
|
|
$toc =~ s#<p>\n</p>##g; |
|
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
|
|
$toc =~ s#<pre>\n#<pre>#g; |
|
|
$toc; |
|
|
} |
|
|
|
|
|
sub back_push { |
|
|
my ($tag, $level, $savedref, $resultref, $attr) = @_; |
|
|
while (@$savedref > $level) { |
|
|
push(@$resultref, shift(@$savedref)); |
|
|
} |
|
|
if ($savedref->[0] ne "</$tag>") { |
|
|
push(@$resultref, splice(@$savedref)); |
|
|
} |
|
|
while (@$savedref < $level) { |
|
|
unshift(@$savedref, "</$tag>"); |
|
|
push(@$resultref, "<$tag$attr>"); |
|
|
} |
|
|
} |
|
|
|
|
|
sub inline { |
|
|
my ($line) = @_; |
|
|
$line = &escape($line); |
|
|
$line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge; |
|
|
$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; |
|
|
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
|
|
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
|
|
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g; |
|
|
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
|
|
$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; |
|
|
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g; |
|
|
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
|
|
$line =~ s|''([^']+)''|<em>$1</em>|g; |
|
|
$line =~ s{ |
|
|
((?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
|
|
|\[\[([^[]+?)]>>([0-9]+)] # [[WikiName]>>1] |
|
|
|>>([0-9]+) |
|
|
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
|
|
}{ |
|
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
|
|
if ($l) { |
|
|
&make_link($l) |
|
|
} elsif (defined $page) { |
|
|
&make_wikilink ($page, anchor => 0+$anchor); |
|
|
} elsif ($anum) { |
|
|
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
|
|
} elsif ($uri) { |
|
|
&make_urilink ($uri); |
|
|
} |
|
|
}gex; |
|
|
return $line; |
|
|
} |
|
|
|
|
|
sub make_wikilink ($%) { |
|
|
my ($ename, %option) = @_; |
|
|
my $name = &unescape ($ename); |
|
|
if ($database{$name}) { |
|
|
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
|
|
if ($option{anchor}) { |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
|
|
} else { |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
|
|
} |
|
|
} else { |
|
|
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>); |
|
|
} |
|
|
} |
|
|
|
|
|
sub make_urilink ($;%) { |
|
|
require URI; |
|
|
my $uri = shift; |
|
|
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
|
|
$uri = &unescape ($uri); |
|
|
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
|
|
my ($site, $name) = ($1, $2); |
|
|
for ($site, $name) { |
|
|
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
|
|
} |
|
|
if ($interwiki{$site}) { |
|
|
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
|
|
$site = &escape ($site); $name = &escape ($name); |
|
|
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>>); |
|
|
} else { |
|
|
qq(<未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>); |
|
|
} |
|
|
} else { |
|
|
qq(<不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>); |
|
|
} |
|
|
} elsif ($uri =~ /^urn:/) { ## URN |
|
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
|
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
|
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
|
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
|
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
|
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
|
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
|
|
} else { ## misc. URI |
|
|
CGI::Carp::warningsToBrowser (0); |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
|
|
CGI::Carp::warningsToBrowser (1); |
|
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
|
|
} |
|
|
} |
|
|
|
|
|
my $FormIndex = 0; |
|
|
sub make_custom_form ($$$$) { |
|
|
my ($wfname, $definition, $template, $option) = @_; |
|
|
## $template and $option is currently not used in this procedure. |
|
|
unless ($main::_EMBEDED) { |
|
|
$FormIndex++; |
|
|
if (length $definition) { |
|
|
my $param = bless {}, 'SuikaWiki::Plugin'; |
|
|
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
|
|
&load_formatter (qw/form_input form_option/); |
|
|
$definition = &unescape ($definition); |
|
|
$definition =~ s/\\(.)/$1/g; |
|
|
$definition .= ' %submit;' if $definition !~ /%submit/; |
|
|
$option = &unescape ($option); |
|
|
$option =~ s/\\(.)/$1/g; |
|
|
$fmt{form_option}->replace ($option, $param); |
|
|
my $target_page = $param->{output}->{page} || $form{mypage}; |
|
|
$param->{form_disabled} = 1 if $fixedpage{$target_page}; |
|
|
my $target_form = $param->{output}->{id}; |
|
|
my $r = <<EOH; |
|
|
<form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform"> |
|
|
<input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}"> |
|
|
<input type="hidden" name="mypage" value="@{[&escape($target_page)]}"> |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
|
|
<input type="hidden" name="mytouch" value="on"> |
|
|
<input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}"> |
|
|
EOH |
|
|
$r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#; |
|
|
$r .= $fmt{form_input}->replace ($definition, $param); |
|
|
$r .= <<EOH; |
|
|
</form> |
|
|
EOH |
|
|
$r; |
|
|
} else { ## No input-interface WikiForm |
|
|
qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>); |
|
|
} |
|
|
} else { |
|
|
q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>); |
|
|
} |
|
|
} |
|
|
|
|
|
## to be obsoleted |
|
|
sub make_link { |
|
|
my $chunk = shift; |
|
|
# Walrus add (3) start |
|
|
$chunk =~ s/^<(.*)>$/$1/; |
|
|
my $name = $chunk; |
|
|
$name = &unarmor_name($name); |
|
|
# Walrus add (3) end |
|
|
if ($chunk =~ /^$embedded_name$/) { |
|
|
return &embedded_to_html($chunk); |
|
|
} else { |
|
|
$chunk = &unarmor_name($chunk); |
|
|
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
|
|
my $cookedchunk = &encode($chunk); |
|
|
if ($database{$chunk}) { |
|
|
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
|
|
# return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} elsif ($page_command{$chunk}) { |
|
|
# return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} else { |
|
|
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
sub print_message { |
|
|
my ($msg) = @_; |
|
|
print qq(<p><strong>$msg</strong></p>); |
|
|
} |
|
|
|
|
|
sub get_message { |
|
|
my ($msg) = @_; |
|
|
qq(<p><strong>$msg</strong></p>); |
|
|
} |
|
|
|
|
|
sub init_form { |
|
|
if (param()) { |
|
|
foreach my $var (param()) { |
|
|
$form{$var} = param($var); |
|
|
} |
|
|
} |
|
|
$form{mypage} = &code_convert(\$form{mypage}, $kanjicode); |
|
|
if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) { |
|
|
my $query = &decode($main::ENV{QUERY_STRING}); |
|
|
$query = &code_convert(\$query, $kanjicode); |
|
|
if ($page_command{$query}) { |
|
|
$form{mycmd} = $page_command{$query}; |
|
|
$form{mypage} = $query; |
|
|
} else { |
|
|
$form{mypage} = $query; |
|
|
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
|
|
} |
|
|
} |
|
|
$form{mypage} ||= 'HomePage'; |
|
|
$form{mycmd} ||= 'read'; |
|
|
|
|
|
# mypreview_edit -> do_edit, with preview. |
|
|
# mypreview_adminedit -> do_adminedit, with preview. |
|
|
# mypreview_write -> do_write, without preview. |
|
|
foreach (keys %form) { |
|
|
if (/^mypreview_(.*)$/) { |
|
|
$form{mycmd} = $1; |
|
|
$form{mypreview} = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
# |
|
|
# $form{mycmd} is frozen here. |
|
|
# |
|
|
|
|
|
for (grep /^wikiform__/, keys %form) { |
|
|
$form{$_} = &code_convert (\$form{$_}, $kanjicode); |
|
|
} |
|
|
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
|
|
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
|
|
} |
|
|
|
|
|
sub update_recent_changes { |
|
|
my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; |
|
|
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
|
|
shift (@oldupdates); ## '#?' magic line |
|
|
my @updates; |
|
|
foreach (@oldupdates) { |
|
|
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/; |
|
|
my $name = $1; |
|
|
if ($name ne $form{mypage}) { |
|
|
push @updates, $_; |
|
|
} |
|
|
} |
|
|
if (&is_exist_page($form{mypage})) { |
|
|
unshift @updates, $update; |
|
|
} |
|
|
splice(@updates, $maxrecent + 1); |
|
|
$database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates); |
|
|
if ($file_touch) { |
|
|
open(FILE, "> $file_touch"); |
|
|
print FILE localtime() . "\n"; |
|
|
close(FILE); |
|
|
} |
|
|
} |
|
|
|
|
|
sub get_subjectline { |
|
|
my ($page, %option) = @_; |
|
|
if (not &is_editable($page)) { |
|
|
return ""; |
|
|
} else { |
|
|
# Delimiter check. |
|
|
my $delim = $subject_delimiter; |
|
|
if (defined($option{delimiter})) { |
|
|
$delim = $option{delimiter}; |
|
|
} |
|
|
|
|
|
# Get the subject of the page. |
|
|
my $subject = $database{$page}; |
|
|
$subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; |
|
|
$subject =~ s/\r?\n.*//s; |
|
|
return "$delim$subject".$option{tail}; |
|
|
} |
|
|
} |
|
|
|
|
|
sub send_mail_to_admin { |
|
|
my ($page, $mode) = @_; |
|
|
return unless $modifier_sendmail; |
|
|
my $message = <<"EOD"; |
|
|
To: $modifier_mail |
|
|
From: $modifier_mail |
|
|
Subject: [Wiki] |
|
|
MIME-Version: 1.0 |
|
|
Content-Type: text/plain; charset=ISO-2022-JP |
|
|
Content-Transfer-Encoding: 7bit |
|
|
|
|
|
-------- |
|
|
MODE = $mode |
|
|
REMOTE_ADDR = $ENV{REMOTE_ADDR} |
|
|
REMOTE_HOST = $ENV{REMOTE_HOST} |
|
|
-------- |
|
|
$page |
|
|
-------- |
|
|
$database{$page} |
|
|
-------- |
|
|
EOD |
|
|
&code_convert(\$message, 'jis'); |
|
|
open(MAIL, "| $modifier_sendmail"); |
|
|
print MAIL $message; |
|
|
close(MAIL); |
|
|
} |
|
|
|
|
|
sub open_db { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname"); |
|
|
dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname"); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname"); |
|
|
tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname"); |
|
|
} else { |
|
|
tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname"); |
|
|
tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname"); |
|
|
} |
|
|
} |
|
|
|
|
|
sub close_db { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmclose(%database); |
|
|
dbmclose(%infobase); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
untie(%database); |
|
|
untie(%infobase); |
|
|
} else { |
|
|
untie(%database); |
|
|
untie(%infobase); |
|
|
} |
|
|
} |
|
|
|
|
|
sub open_diff { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname"); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname"); |
|
|
} else { |
|
|
tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname"); |
|
|
} |
|
|
} |
|
|
|
|
|
sub close_diff { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmclose(%diffbase); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
untie(%diffbase); |
|
|
} else { |
|
|
untie(%diffbase); |
|
|
} |
|
|
} |
|
|
|
|
|
sub print_searchform { |
|
|
my ($word) = @_; |
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="get"> |
|
|
<input type="hidden" name="mycmd" value="read"> |
|
|
<input type="text" name="mypage" value="$word" size="20"> |
|
|
<input type="submit" value="$resource{searchbutton}"> |
|
|
</form> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub print_editform { |
|
|
my ($mymsg, $lastmodified, %mode) = @_; |
|
|
my $frozen = &is_frozen($form{mypage}); |
|
|
|
|
|
if ($form{mypreview}) { |
|
|
if ($form{mymsg}) { |
|
|
unless ($mode{conflict}) { |
|
|
print qq(<h3>$resource{previewtitle}</h3>\n); |
|
|
print qq($resource{previewnotice}\n); |
|
|
print qq(<div class="preview">\n); |
|
|
&print_content($form{mymsg}); |
|
|
print qq(</div>\n); |
|
|
} |
|
|
} else { |
|
|
print qq($resource{previewempty}); |
|
|
} |
|
|
$mymsg = &escape($form{mymsg}); |
|
|
} else { |
|
|
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
|
|
} |
|
|
my $magic = ''; |
|
|
$magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s; |
|
|
|
|
|
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
|
|
my $escapedmypage = &escape($form{mypage}); |
|
|
my $escapedmypassword = &escape($form{mypassword}); |
|
|
my $selected = 'read'; |
|
|
if ($form{after_edit_cmd}) { |
|
|
$selected = $form{after_edit_cmd}; |
|
|
} elsif ($magic =~ /Config/ || $magic =~ /CSS/) { |
|
|
$selected = 'edit'; |
|
|
} |
|
|
my $afteredit = <<EOH; |
|
|
<select name="after_edit_cmd"> |
|
|
<option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option> |
|
|
<option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option> |
|
|
</select> |
|
|
EOH |
|
|
|
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<h2>$escapedmypageの編集</h2> |
|
|
@{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]} |
|
|
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0; |
|
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
|
|
++$n}]}]<br> |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
|
|
<input type="hidden" name="mypage" value="$escapedmypage"> |
|
|
<textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br> |
|
|
@{[ |
|
|
$mode{admin} ? |
|
|
qq( |
|
|
<input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton} |
|
|
<input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>) |
|
|
: "" |
|
|
]} |
|
|
@{[ |
|
|
$mode{conflict} ? "" : |
|
|
qq( |
|
|
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
|
|
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
|
|
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd> |
|
|
$afteredit |
|
|
<br> |
|
|
) |
|
|
]} |
|
|
</form> |
|
|
EOD |
|
|
unless ($mode{conflict}) { |
|
|
# Show the format rule. |
|
|
my $help = $database{'WikiEditHelp'}; |
|
|
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
|
|
print &text_to_html ($help, toc => 0); |
|
|
# open(FILE, $file_format) or &print_error("($file_format)"); |
|
|
# my $content = join('', <FILE>); |
|
|
# &code_convert(\$content, $kanjicode); |
|
|
# close(FILE); |
|
|
# print &text_to_html($content, toc=>0); |
|
|
} |
|
|
} |
|
9 |
|
|
|
sub print_passwordform { |
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<input type="hidden" name="mycmd" value="adminchangepassword"> |
|
|
$resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br> |
|
|
$resource{newpassword} <input type="password" name="mynewpassword" size="10"><br> |
|
|
$resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br> |
|
|
<input type="submit" value="$resource{changepasswordbutton}"><br> |
|
|
</form> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub is_editable { |
|
|
my ($page) = @_; |
|
|
if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) { |
|
|
return 0; |
|
|
} else { |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
# armor_name: |
|
|
# WikiName -> WikiName |
|
|
# not_wiki_name -> [[not_wiki_name]] |
|
|
sub armor_name { qq([[$_[0]]]) } |
|
|
|
|
|
# unarmor_name: |
|
|
# [[bracket_name]] -> bracket_name |
|
|
# WikiName -> WikiName |
|
|
sub unarmor_name { |
|
|
my ($name) = @_; |
|
|
if ($name =~ /^$bracket_name$/) { |
|
|
return $1; |
|
|
} else { |
|
|
return $name; |
|
|
} |
|
|
} |
|
|
|
|
|
sub decode { |
|
|
my ($s) = @_; |
|
|
$s =~ tr/+/ /; |
|
|
$s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; |
|
|
return $s; |
|
|
} |
|
|
|
|
|
sub encode { |
|
|
my ($s) = @_; |
|
|
my $encoded = ''; |
|
|
foreach my $ch (split(//, $s)) { |
|
|
if ($ch =~ /[A-Za-z0-9_]/) { |
|
|
$encoded .= $ch; |
|
|
} else { |
|
|
$encoded .= '%' . sprintf("%02X", ord($ch)); |
|
|
} |
|
|
} |
|
|
return $encoded; |
|
|
} |
|
|
|
|
|
sub init_resource { |
|
|
open(FILE, $file_resource) or &print_error("(resource)"); |
|
|
while (<FILE>) { |
|
|
s/[\x0A\x0D]+$//g; |
|
|
next if /^#/; |
|
|
my ($key, $value) = split(/=/, $_, 2); |
|
|
$resource{$key} = &code_convert(\$value, $kanjicode); |
|
|
} |
|
|
close(FILE); |
|
|
} |
|
|
|
|
|
sub conflict { |
|
|
my ($page, $rawmsg) = @_; |
|
|
if ($form{myLastModified} eq &get_info($page, $info_LastModified)) { |
|
|
return 0; |
|
|
} |
|
|
open(FILE, $file_conflict) or &print_error("(conflict)"); |
|
|
my $content = join('', <FILE>); |
|
|
&code_convert(\$content, $kanjicode); |
|
|
close(FILE); |
|
|
&print_header($page, -noindex => 1); |
|
|
&print_content($content); |
|
|
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
|
|
&print_footer($page); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
sub get_now { |
|
|
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
|
|
my (@week) = qw(日 月 火 水 木 金 土); |
|
|
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
|
|
$year += 1900; |
|
|
$mon++; |
|
|
$mon = "0$mon" if $mon < 10; |
|
|
$day = "0$day" if $day < 10; |
|
|
$hour = "0$hour" if $hour < 10; |
|
|
$min = "0$min" if $min < 10; |
|
|
#$sec = "0$sec" if $sec < 10; |
|
|
$weekday = $week[$weekday]; |
|
|
return "$year-$mon-$day ($weekday) $hour:$min"; |
|
|
} |
|
|
|
|
|
sub init_InterWikiName { |
|
|
my @content = split /\n/, $database{$InterWikiName}; |
|
|
for (@content) { |
|
|
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
|
|
$interwiki{$1} = $2; |
|
|
} |
|
|
} |
|
|
require Message::Util::Formatter; |
|
|
$fmt{interwiki} = Message::Util::Formatter->new; |
|
|
$fmt{interwiki}->{encoded} = sub { |
|
|
my ($o, $p) = @_; |
|
|
if ($o->{except}) { |
|
|
$o->{except} =~ tr/\x00-\x20\x22%\x2D<>^[\x5C]`{|}\x7F-\xFF//d; |
|
|
} |
|
|
my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit'); |
|
|
$s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge; |
|
|
$s; |
|
|
}; |
|
|
$fmt{interwiki}->{ykwk} = sub { ## YukiWiki1 |
|
|
my ($o, $p) = @_; |
|
|
my $s = $p->{name}; |
|
|
$s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/; |
|
|
&encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis')); |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
sub get_info { |
|
|
my ($page, $key) = @_; |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
|
|
return $info{$key}; |
|
|
} |
|
|
|
|
|
sub set_info { |
|
|
my ($page, $key, $value) = @_; |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
|
|
$info{$key} = $value; |
|
|
my $s = ''; |
|
|
for (keys %info) { |
|
|
$s .= "$_=$info{$_}\n"; |
|
|
} |
|
|
$infobase{$page} = $s; |
|
|
} |
|
|
|
|
|
sub frozen_reject { |
|
|
my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); |
|
|
my ($willbefrozen) = $form{myfrozen}; |
|
|
if (not $isfrozen and not $willbefrozen) { |
|
|
# You need no check. |
|
|
return 0; |
|
|
} elsif (valid_password($form{mypassword})) { |
|
|
# You are admin. |
|
|
return 0; |
|
|
} else { |
|
|
&print_error($resource{passworderror}); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
sub valid_password { |
|
|
my ($givenpassword) = @_; |
|
|
my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); |
|
|
if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
sub is_frozen { |
|
|
my ($page) = @_; |
|
|
if (&get_info($page, $info_IsFrozen)) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
sub do_comment { |
|
|
my ($content) = $database{$form{mypage}}; |
|
|
my $default_name; ## this code does not strict. |
|
|
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
|
|
my $datestr = '[WEAK['.&get_now.']]'; |
|
|
my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; |
|
|
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
|
|
if ($namestr =~ /^(?:>>)?[0-9]/) { |
|
|
$namestr = qq( ''$namestr'': ); |
|
|
} elsif (length $namestr) { |
|
|
$namestr = qq( ''[[$namestr]]'': ); |
|
|
} |
|
|
my $anchor = &get_new_anchor_index ($content); |
|
|
my $i = 1; my $o = 0; |
|
|
$content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ |
|
|
my $embed = $1; |
|
|
if ($i == $form{comment_index}) { |
|
|
if ($embed eq $embed_comment) { |
|
|
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
|
|
} else { |
|
|
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
|
|
} |
|
|
} |
|
|
$i++; $embed; |
|
|
}ge; |
|
|
unless ($o) { |
|
|
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
|
|
$content .= "\n" unless $content =~ /\n$/s; |
|
|
$content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; |
|
|
} |
|
|
$form{__comment_anchor_index} = $anchor; |
|
|
if ($form{mymsg} || $form{myname}) { |
|
|
$form{mymsg} = $content; |
|
|
$form{mytouch} = 'on'; |
|
|
&do_write; |
|
|
} else { |
|
|
$form{mycmd} = 'read'; |
|
|
&do_read; |
|
|
} |
|
|
} |
|
|
|
|
|
sub get_new_anchor_index ($) { |
|
|
my $content = shift; |
|
|
my $anchor = 0; |
|
|
$content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
|
|
$anchor + 1; |
|
|
} |
|
|
|
|
|
my $CommentIndex = 0; |
|
|
sub embedded_to_html { |
|
|
my ($embedded) = @_; |
|
|
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
|
|
unless ($main::_EMBEDED) { |
|
|
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
|
|
return <<"EOD"; |
|
|
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
|
|
<input type="hidden" name="mycmd" value="comment"> |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
|
|
<input type="hidden" name="mytouch" value="on"> |
|
|
<input type="hidden" name="comment_index" value="$CommentIndex"> |
|
|
$embed_comment_Name_Prompt |
|
|
<input type="text" name="myname" value="" size="10" class="comment-name"> |
|
|
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
|
|
<input type="submit" value="$resource{commentbutton}" class="comment-submit"> |
|
|
</p></form> |
|
|
EOD |
|
|
} else { |
|
|
return <<"EOD"; |
|
|
<del><form action="$url_cgi" method="get"> |
|
|
<input type="hidden" name="mycmd" value="read"> |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
|
|
$embed_comment_Name_Prompt |
|
|
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
|
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
|
|
<input type="submit" value="$resource{commentbutton}" disabled="disabled"> |
|
|
</form></del> |
|
|
EOD |
|
|
} |
|
|
} elsif ($embedded =~ /$embed_command{searched}/) { |
|
|
return get_search_result ($1, -match_myself => 1); |
|
|
# Walrus add (5) start |
|
|
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
|
|
$_ = &make_interwiki_box($1, $2); |
|
|
return ($_) ? $_ : $embedded; |
|
|
# Walrus add (5) end |
|
|
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
|
|
my ($name, $r) = ($1, ''); |
|
|
if ($main::_EMBEDED != 1) { |
|
|
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
|
|
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
|
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
|
|
$main::_EMBEDED = 1; |
|
|
$r = &text_to_html ($content, content_format => $cf); |
|
|
$main::_EMBEDED = 0; |
|
|
} elsif (length $content) { |
|
|
$r = "<pre>@{[&escape ($content)]}</pre>"; |
|
|
} else { |
|
|
$r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
|
|
} |
|
|
} else { ## nested #EMBED |
|
|
$r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
|
|
} |
|
|
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>); |
|
|
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
|
|
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
|
|
} else { |
|
|
return $embedded; |
|
|
} |
|
|
} |
|
|
|
|
|
sub load_formatter (@) { |
|
|
for my $t (@_) { |
|
|
unless ($fmt{$t}) { |
|
|
$fmt{$t} = Message::Util::Formatter->new; |
|
|
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
|
|
$_->load_formatter ($fmt{$t}, type => 'wiki'.$t); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
sub do_wikiform { |
|
|
my $content = $database{$form{mypage}}; |
|
|
my $anchor = &get_new_anchor_index ($content); |
|
|
&load_formatter (qw/form_template form_option/); |
|
|
my $write = 0; |
|
|
my $i = 1; |
|
|
$content =~ s{$embed_command{form}}{ |
|
|
my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4); |
|
|
if (($wfname && $wfname eq $form{wikiform_targetform}) |
|
|
|| $i == $form{wikiform_index}) { |
|
|
$template =~ s/\\(.)/$1/g; |
|
|
$option =~ s/\\(.)/$1/g; |
|
|
my $param = bless {}, 'SuikaWiki::Plugin'; |
|
|
$param->{page} = $form{mypage}; |
|
|
$param->{form_index} = $i; |
|
|
$param->{form_name} = $wfname; |
|
|
$param->{anchor_index} = $anchor; |
|
|
$param->{argv} = \%form; |
|
|
$param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; |
|
|
$param->{default_name} ||= $DEFAULT_embed_comment_name; |
|
|
$fmt{form_option}->replace ($option, $param); |
|
|
my $t = 1; |
|
|
for (@{$param->{require}||[]}) { |
|
|
(undef $t, last) unless length $param->{argv}->{'wikiform__'.$_}; |
|
|
} |
|
|
$t = $fmt{form_template}->replace ($template, $param) if $t; |
|
|
if (length $t) { |
|
|
if ($param->{output}->{reverse}) { |
|
|
$embed .= "\n" . $t; |
|
|
} else { |
|
|
$embed = $t . "\n" . $embed; |
|
|
} |
|
|
$write = 1; |
|
|
$form{__comment_anchor_index} = $anchor |
|
|
if $param->{anchor_index_}; ## $anchor is used! |
|
|
} |
|
|
$form{__wikiform_anchor_index} = $i; |
|
|
undef $form{wikiform_targetform}; ## make sure never to match |
|
|
undef $form{wikiform_index}; ## with WikiForm in rest of page |
|
|
} |
|
|
$i++; $embed; |
|
|
}ge; |
|
|
unless ($write) { |
|
|
#$content = "#?SuikaWiki/0.9\n\n" unless $content; |
|
|
#$content .= "\n" unless $content =~ /\n$/s; |
|
|
# |
|
|
} |
|
|
if ($write) { |
|
|
$form{mymsg} = $content; |
|
|
$form{mytouch} = 'on'; |
|
|
&do_write; |
|
|
} else { |
|
|
$form{mycmd} = 'read'; |
|
|
&do_read; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# Walrus add (5) start |
|
|
sub do_interwiki_box { |
|
|
my $remoteurl = $interwiki{$form{'myintername'}}; |
|
|
if ($remoteurl) { |
|
|
$remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e; |
|
|
print "Location: $remoteurl\n\n"; |
|
|
exit(1); |
|
|
} else { |
|
|
&do_read; |
|
|
} |
|
|
} |
|
|
# Walrus add (5) end |
|
|
|
|
|
# Walrus add (5) start |
|
|
sub make_interwiki_box { |
|
|
my ($localname, $intername) = @_; |
|
|
my %ignoretype = ( |
|
|
'box' => 'text', |
|
|
'text' => 'text', |
|
|
'pass' => 'password', |
|
|
'password' => 'password' |
|
|
); |
|
|
my $converted = ($ignoretype{$localname}) ? <<EOD : undef; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<input type="hidden" name="mycmd" value="interwikibox"> |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
|
|
<input type="hidden" name="myintername" value="$intername"> |
|
|
$intername: |
|
|
<input type="$ignoretype{$localname}" name="mylocalname" value="" size="10"> |
|
|
<input type="submit" value="Submit"> |
|
|
</form> |
|
|
EOD |
|
|
} |
|
|
# Walrus add (5) end |
|
|
|
|
|
sub code_convert { |
|
|
my ($contentref, $code) = (shift, shift || $kanjicode); |
|
|
$code = 'jis' if $code =~ /iso/; |
|
|
$code = 'euc' if $code =~ /euc/; |
|
|
$code = 'sjis' if $code =~ /shift/; |
|
|
$code = 'utf8' if $code =~ /utf/; |
|
|
&Jcode::convert($contentref, $code); # for Jcode.pm |
|
|
# &jcode::convert($contentref, $code); # for jcode.pl |
|
|
&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'; |
|
|
return $$contentref; |
|
|
} |
|
|
|
|
|
sub test_convert { |
|
|
my $txt = &text_to_html(<<"EOD", toc=>1); |
|
|
*HEADER1 |
|
|
**HEADER1-1 |
|
|
-ITEM1 |
|
|
-ITEM2 |
|
|
-ITEM3 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
|
|
|
PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
**HEADER1-2 |
|
|
:TERM1:DESCRIPTION1 AND ''BOLD'' |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
:TERM2:DESCRIPTION2 |
|
|
:TERM3:DESCRIPTION3 |
|
|
---- |
|
|
*HEADER2 |
|
|
**HEADER2-1 |
|
|
http://www.hyuki.com/ |
|
|
**HEADER2-2 |
|
|
|
|
|
[[YukiWiki2]] |
|
|
|
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
|
|
|
|
|
LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0 |
|
|
|
|
|
>LEVEL1 |
|
|
>LEVEL1 |
|
|
>LEVEL1 |
|
|
>>LEVEL2 |
|
|
>>LEVEL2 |
|
|
>>LEVEL2 |
|
|
>>>LEVEL3 |
|
|
-HELLO-1 |
|
|
--HELLO-2 |
|
|
(HELLO-2, HELLO-2, HELLO-2) |
|
|
---HELLO-3 |
|
|
(HELLO-3, HELLO-3, HELLO-3) |
|
|
--HELLO-2 |
|
|
---HELLO-3 |
|
|
--HELLO-2 |
|
|
---HELLO-3 |
|
|
>>>LEVEL3 |
|
|
>>>LEVEL3 |
|
|
>>>LEVEL3 |
|
|
>>>LEVEL3 |
|
|
EOD |
|
|
print $txt; |
|
|
exit; |
|
|
} |
|
|
|
|
|
sub do_diff { |
|
|
if (not &is_editable($form{mypage})) { |
|
|
&do_read; |
|
|
return; |
|
|
} |
|
|
&open_diff; |
|
|
my $title = $form{mypage}; |
|
|
&print_header($title, -noindex => 1); |
|
|
$_ = &escape($diffbase{$form{mypage}}); |
|
|
&close_diff; |
|
|
print qq(<h3>$resource{difftitle}</h3>); |
|
|
print qq($resource{diffnotice}); |
|
|
print qq(<pre class="diff">); |
|
|
foreach (split(/\n/, $_)) { |
|
|
if (/^\+(.*)/) { |
|
|
print qq(<b class="added">$1</b>\n); |
|
|
} elsif (/^\-(.*)/) { |
|
|
print qq(<s class="deleted">$1</s>\n); |
|
|
} elsif (/^\=(.*)/) { |
|
|
print qq(<span class="same">$1</span>\n); |
|
|
} else { |
|
|
print qq|??? $_\n|; |
|
|
} |
|
|
} |
|
|
print qq(</pre>); |
|
|
print qq(<hr>); |
|
|
&print_footer($title); |
|
|
} |
|
|
|
|
|
sub do_rss { |
|
|
my $rss = new Yuki::RSS( |
|
|
version => '1.0', |
|
|
encoding => $charset, |
|
|
); |
|
|
$rss->channel( |
|
|
title => $modifier_rss_title, |
|
|
link => $modifier_rss_link, |
|
|
description => $modifier_rss_description, |
|
|
); |
|
|
my $recentchanges = $database{$RecentChanges}; |
|
|
my $count = 0; |
|
|
foreach (split(/\n/, $recentchanges)) { |
|
|
last if ($count >= 15); |
|
|
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format. |
|
|
my $title = &unarmor_name($1); |
|
|
my $escaped_title = &escape($title); |
|
|
my $link = $modifier_rss_link . '?' . &encode($title); |
|
|
my $description = $escaped_title . &escape(&get_subjectline($title)); |
|
|
$rss->add_item( |
|
|
title => $escaped_title, |
|
|
link => $link, |
|
|
description => $description, |
|
|
); |
|
|
$count++; |
|
|
} |
|
|
# print RSS information (as XML). |
|
|
print scalar &make_navigate_links ('RssPage'); |
|
|
print <<"EOD" |
|
|
Content-type: application/xml |
|
|
|
|
|
@{[$rss->as_string]} |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub is_exist_page { |
|
|
my ($name) = @_; |
|
|
if ($use_exists) { |
|
|
return exists($database{$name}); |
|
|
} else { |
|
|
return $database{$name}; |
|
|
} |
|
|
} |
|
|
|
|
|
sub __get_database ($) { $database{ $_[0] } } |
|
|
sub __set_database ($$) { $database{ $_[0] } = $_[1] } |
|
|
|
|
|
sub do_wikiplugininfo { |
|
|
&print_header (q(WikiPluginInfo)); |
|
|
print text_to_html (&SuikaWiki::Plugin::make_info_page); |
|
|
&print_footer (q(WikiPluginInfo)); |
|
|
} |
|
|
|
|
|
package wiki::referer; |
|
|
sub add ($$) { |
|
|
my $page = shift; |
|
|
my $uri = shift; |
|
|
unless (ref $uri) { |
|
|
require URI; |
|
|
$uri = URI->new ($uri); |
|
|
## Some schemes do not have query part. |
|
|
eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ }; |
|
|
$uri->fragment (undef); |
|
|
} |
|
|
$uri = $uri->canonical; |
|
|
return unless $uri; |
|
|
for my $regex (&get_dont_record) { |
|
|
return if $uri =~ /$regex/; |
|
|
} |
|
|
my %list = get ($page); |
|
|
$list{ $uri }++; |
|
|
set ($page, \%list); |
|
|
} |
|
|
sub get ($) { |
|
|
my $page = shift; |
|
|
split /"/, main::get_info ($page, 'Referer'); |
|
|
} |
|
|
sub set ($%) { |
|
|
my $page = shift; |
|
|
my $list = shift; |
|
|
main::set_info ($page, Referer => join '"', %$list); |
|
|
} |
|
|
|
|
|
sub get_dont_record () { |
|
|
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
|
|
grep !/^#/, |
|
|
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
|
|
} |
|
|
sub get_site_name () { |
|
|
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
|
|
my @item; |
|
|
for (@lines) { |
|
|
next if /^#/; |
|
|
my ($uri, $name) = split /\s+/, $_, 2; |
|
|
$uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; |
|
|
$name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; |
|
|
push @item, [$uri, qq(q($name))]; |
|
|
} |
|
|
@item; |
|
|
} |
|
|
|
|
|
sub list_html ($) { |
|
|
my $page = shift; |
|
|
my %list = get ($page); |
|
|
my $r = ''; |
|
|
my @name = get_site_name; |
|
|
for my $uri (sort keys %list) { |
|
|
my $title; |
|
|
for my $item (@name) { |
|
|
if ($uri =~ /$item->[0]/) { |
|
|
$title = $uri; |
|
|
eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} |
|
|
or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; |
|
|
last; |
|
|
} |
|
|
} |
|
|
my $euri = main::escape ($uri); |
|
|
if ($title) { |
|
|
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
|
|
} else { |
|
|
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
|
|
} |
|
|
} |
|
|
$r ? qq(<ul>$r</ul>\n) : ''; |
|
|
} |
|
|
|
|
|
sub __decode ($) { |
|
|
my $s = shift; |
|
|
$s =~ tr/+/ /; |
|
|
$s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge; |
|
|
main::code_convert (\$s); |
|
|
} |
|
|
|
|
|
package wiki::useragent; |
|
|
|
|
|
sub add ($) { |
|
|
my $s = shift; |
|
|
return unless length $s; |
|
|
$s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g; |
|
|
my %ua; |
|
|
for (split /\n/, &main::__get_database('WikiUserAgentList')) { |
|
|
if (/^-\[(\d+)\] (.+)$/) { |
|
|
my ($t, $n) = ($1, $2); |
|
|
$n =~ tr/\x0A\x0D//d; |
|
|
$ua{$n} = $t; |
|
|
} |
|
|
} |
|
|
$ua{$s}++; |
|
|
my $s = qq(#?SuikaWiki/0.9\n); |
|
|
for (sort {$ua{$a} <=> $ua{$b}} keys %ua) { |
|
|
$s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_; |
|
|
} |
|
|
&main::__set_database ('WikiUserAgentList' => $s); |
|
|
} |
|
|
|
|
|
package SuikaWiki::Plugin; |
|
|
our $plugin_directory; # defined in top of this file. |
|
|
our %List; |
|
|
|
|
|
sub escape ($$) { main::escape ($_[1]) } |
|
|
sub unescape ($$) { main::unescape ($_[1]) } |
|
|
sub encode ($$) { main::encode ($_[1]) } |
|
|
sub decode ($$) { main::decode ($_[1]) } |
|
|
sub __get_datetime ($) { main::get_now () } |
|
|
|
|
|
sub regist ($@) { |
|
|
my $pack = shift; |
|
|
for (@_) { |
|
|
push @{$List{$_}}, $pack; |
|
|
} |
|
|
} |
|
|
|
|
|
sub import_plugins () { |
|
|
opendir PDIR, $plugin_directory; |
|
|
my @plugin = grep {s/\.pm$//} readdir (PDIR); |
|
|
closedir PDIR; |
|
|
for (@plugin) { |
|
|
eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/; |
|
|
push @{$List{_all}}, qq(SuikaWiki::Plugin::$_); |
|
|
} |
|
|
} |
|
|
|
|
|
sub make_info_page () { |
|
|
my $r = <<EOH; |
|
|
EOH |
|
|
unless ($List{_all}) { |
|
|
$r .= qq('''No plugin is installed!'''\n); |
|
|
} else { |
|
|
my $index = 0; |
|
|
for my $package (sort @{$List{_all}}) { |
|
|
$index++; |
|
|
my $prop = $package->property (); |
|
|
$r .= <<EOH; |
|
|
*$package |
|
|
|
|
|
[$index] '''$prop->{name}''' (Version $prop->{version}) |
|
|
<$prop->{uri}> |
|
|
|
|
|
Provide: |
|
|
@{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) { |
|
|
$t .= qq(-''$f''\n); |
|
|
for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) { |
|
|
$t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n); |
|
|
} |
|
|
}$t}]} |
|
|
|
|
|
EOH |
|
|
} |
|
|
} |
|
|
$r; |
|
|
} |
|
|
|
|
|
&import_plugins (); |
|
|
|
|
|
package main; |
|
|
&main; |
|
|
exit 0; |
|
|
|
|
|
1; |
|
|
__END__ |
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
12 |
wiki.cgi - This is YukiWiki, yet another Wiki clone. |
wiki.cgi --- SuikaWiki: Yet yet another WikiEngine |
|
|
|
|
=head1 DESCRIPTION |
|
|
|
|
|
YukiWiki is yet another Wiki clone. |
|
13 |
|
|
14 |
YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]). |
=head1 SEE ALSO |
|
YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS), |
|
|
and some embedded commands (such as [[#comment]] to add comments). |
|
15 |
|
|
16 |
Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail. |
<IW:SuikaWiki:SuikaWiki> |
|
|
|
|
=head1 AUTHOR |
|
|
|
|
|
Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/ |
|
17 |
|
|
18 |
=head1 LICENSE |
=head1 LICENSE |
19 |
|
|
20 |
Copyright (C) 2000-2002 by Hiroshi Yuki. |
Copyright 2002-2003 Wakaba <w@suika.fam.cx> |
21 |
|
|
22 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
23 |
modify it under the same terms as Perl itself. |
modify it under the same terms as Perl itself. |
24 |
|
|
25 |
=cut |
=cut |
26 |
|
|
27 |
|
1; # $Date$ |