1 |
#!/usr/bin/perl |
#!/usr/bin/perl -d:DProf |
2 |
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
BEGIN { $0 = ''.$0 } |
|
# |
|
|
# This program is free software; you can redistribute it and/or |
|
|
# modify it under the same terms as Perl itself. |
|
|
|
|
3 |
use strict; |
use strict; |
4 |
use lib qw(./lib); |
use lib qw(lib); |
5 |
use CGI::Carp qw(fatalsToBrowser); |
use CGI::Carp qw(fatalsToBrowser); |
6 |
our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
require 'suikawiki.pl'; |
|
|
|
|
require 'wikidata/suikawiki-config.ph'; |
|
|
use Fcntl; |
|
|
############################## |
|
|
my %fmt; ## formatter objects |
|
|
my %embed_command = ( |
|
|
searched => '^\[\[#searched:([^\]]+)\]\]$', |
|
|
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
|
|
); |
|
|
our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists); |
|
|
our (%PageName,$kanjicode,$lang,%ViewDefinition); |
|
|
|
|
|
############################## |
|
|
my %form; |
|
|
our %database; |
|
|
our $database = bless {}, 'wiki::dummy'; |
|
|
my %interwiki; |
|
|
############################## |
|
|
my %page_command = ( |
|
|
$PageName{RssPage} => 'rss', |
|
|
); |
|
|
my %command_do = ( |
|
|
read => \&do_read, |
|
|
TEXT_CSS => \&do_output_css, |
|
|
edit => \&do_view, |
|
|
adminchangepassword => \&do_adminchangepassword, |
|
|
write => \&do_write, |
|
|
searchform => \&do_searchform, |
|
|
comment => \&do_comment, |
|
|
RandomJump => \&do_random_jump, |
|
|
rss => \&do_rss, |
|
|
diff => \&do_diff, |
|
|
wikiform => \&do_wikiform, |
|
|
map => \&do_view, |
|
|
); |
|
|
my $UA = ''; ## User agent name |
|
|
$| = 1; |
|
|
############################## |
|
|
|
|
|
sub main { |
|
|
$UA = $main::ENV{HTTP_USER_AGENT}; |
|
|
&open_db; |
|
|
&init_form; |
|
|
if ($command_do{$form{mycmd}}) { |
|
|
&{$command_do{$form{mycmd}}}; |
|
|
} else { |
|
|
&{$command_do{read}}; |
|
|
} |
|
|
&close_db; |
|
|
} |
|
|
|
|
|
sub do_read { |
|
|
my $content = $database{$form{mypage}}; |
|
|
my $lm = $database->mtime ($form{mypage}); |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
my @toc; |
|
|
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)!) { |
|
|
my $expires = time; |
|
|
if ($cf =~ /interactive="yes"/) { |
|
|
$lm = $expires; |
|
|
} else { |
|
|
$expires += 120; |
|
|
} |
|
|
&print_header ($form{mypage}, -last_modified => $lm, -expires => $expires, |
|
|
-content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0)); |
|
|
&print_content ($content, content_format => $cf, last_modified => $lm, |
|
|
-toc => \@toc); |
|
|
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$database->meta (IsFrozen => $form{mypage}); |
|
|
} else { |
|
|
&print_header($form{mypage}, -expires => time + 120, -last_modified => $lm); |
|
|
print "<pre>@{[&escape($content)]}</pre>"; |
|
|
} |
|
|
&load_formatter ('view'); |
|
|
print $fmt{view}->replace ($ViewDefinition{read} => bless {param => \%form, page => $form{mypage}, toc => \@toc, formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
|
|
&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 = gmtime $database->mtime ($form{mypage}); |
|
|
print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n"; |
|
|
print "Last-Modified: $lm\n"; |
|
|
print "Expires: @{[scalar gmtime time+3600]}\n"; ## TODO: don't use asctime |
|
|
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_view { |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
&print_header($form{mypage}, -noindex => 1, -expires => time+60); |
|
|
&load_formatter ('view'); |
|
|
my $view = $form{mycmd}; |
|
|
if ($view eq 'edit') { |
|
|
$view = 'adminedit' if $form{admin}; |
|
|
} elsif ($view =~ /[^0-9A-Za-z]/) { |
|
|
$view = 'view' |
|
|
} |
|
|
print $fmt{view}->replace ($ViewDefinition{$view} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
|
|
&print_footer($form{mypage}); |
|
|
} |
|
|
|
|
|
sub do_adminchangepassword { |
|
|
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
|
|
&print_error(&Resource('Error:PasswordMismatch')); |
|
|
} |
|
|
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
|
|
if ($validpassword_crypt) { |
|
|
if (not &valid_password($form{myoldpassword})) { |
|
|
&print_error(&Resource('Error:PasswordIsIncorrect')); |
|
|
} |
|
|
} |
|
|
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"); |
|
|
$database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted); |
|
|
|
|
|
&print_header('CompletedSuccessfully', -noindex => 1); |
|
|
&print_message(&Resource('Error:PasswordIsChanged')); |
|
|
&print_footer('CompletedSuccessfully'); |
|
|
} |
|
|
|
|
|
sub valid_password ($) { |
|
|
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
|
|
return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; |
|
|
} |
|
|
|
|
|
sub do_write { |
|
|
if (&frozen_reject()) { |
|
|
return; |
|
|
} |
|
|
|
|
|
if (not &is_editable($form{mypage})) { |
|
|
&print_header($form{mypage}, -noindex => 1); |
|
|
&print_message(&Resource('Error:ThisPageIsUneditable')); |
|
|
&print_footer($form{mypage}); |
|
|
return; |
|
|
} |
|
|
|
|
|
## Check confliction |
|
|
if ($form{myLastModified} ne $database->mtime ($page)) { |
|
|
&print_header($page, -noindex => 1); |
|
|
&load_formatter ('view'); |
|
|
print $fmt{view}->replace ($ViewDefinition{-conflict} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
|
|
&print_footer($page); |
|
|
return; |
|
|
} |
|
|
|
|
|
if ($form{mymsg}) { |
|
|
if ($form{mytouch} || !ref $database) { |
|
|
$database{$form{mypage}} = $form{mymsg}; |
|
|
} else { |
|
|
$database->STORE ($form{mypage} => $form{mymsg}, -touch => 0); |
|
|
} |
|
|
$database->meta (IsFrozen => $form{mypage} => 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('Error:SavedSuccessfully')); |
|
|
&print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}"); |
|
|
&print_footer('CompletedSuccessfully'); |
|
|
} else { |
|
|
delete $database{$form{mypage}}; |
|
|
&print_header($form{mypage}, -noindex => 1); |
|
|
&print_message(&Resource('Error:PageIsDeletedSuccessfully')); |
|
|
&print_footer($form{mypage}); |
|
|
} |
|
|
} |
|
|
|
|
|
sub _compatible_options () { |
|
|
(use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0)); |
|
|
} |
|
|
|
|
|
sub get_search_result ($;%) { |
|
|
my $word = lc shift; |
|
|
my %option = @_; |
|
|
my @r; |
|
|
foreach my $page (keys %database) { |
|
|
next if !$option{-match_myself} && ($page eq $word); |
|
|
my $content = lc $database{$page}; |
|
|
if (index (lc $page, $word) > -1) { |
|
|
my $c = $content =~ s/\Q$word\E//g; |
|
|
push @r, [$page, $c+20]; |
|
|
} elsif (index ($word, lc $page) > -1) { |
|
|
my $c = $content =~ s/\Q$word\E//g; |
|
|
push @r, [$page, $c+10]; |
|
|
} elsif (my $c = $content =~ s/\Q$word\E//g) { |
|
|
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">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&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; |
|
|
wantarray? ($r, scalar @r): $r; |
|
|
} |
|
|
|
|
|
sub do_random_jump { |
|
|
my @list = keys %database; |
|
|
my $name = &encode ($list[rand @list]); |
|
|
my $scheme = 'http'; |
|
|
$scheme = lc $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 print_error { |
|
|
my ($msg) = @_; |
|
|
&print_header($PageName{ErrorPage}, -noindex => 1); |
|
|
print qq(<p><strong class="error">$msg</strong></p>); |
|
|
&print_footer($PageName{ErrorPage}); |
|
|
exit(0); |
|
|
} |
|
|
|
|
|
sub print_header ($;%) { |
|
|
my ($page, %option) = @_; |
|
|
my @head; |
|
|
$option{body_class} = &is_frozen($page) ? 'frozen' : 'normal'; |
|
|
$option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
|
|
if ($option{-goto}) { |
|
|
if ($UA =~ m#Opera|MSIE 2\.#) { |
|
|
## WARNING: This code may output unsafe HTML document if |
|
|
## $option{-goto} is not clean. |
|
|
$option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#; |
|
|
print qq{Refresh: 0; url=$option{-goto}\n}; |
|
|
push @head, 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}; |
|
|
push @head, qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"">); |
|
|
} |
|
|
} |
|
|
print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified}; |
|
|
if ($option{-expires}) { |
|
|
print qq{Expires: @{[scalar gmtime $option{-expires}]}\n}; |
|
|
} |
|
|
if ($UA =~ m#Mozilla/2#) { |
|
|
my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}}; |
|
|
print qq{Content-Type: $ct\n}; |
|
|
push @head, qq{<meta http-equiv="content-type" content="$ct">}; |
|
|
} elsif ($UA =~ m#Infomosaic#) { |
|
|
print qq{Content-Type: text/html\n}; |
|
|
} else { |
|
|
print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n}; |
|
|
} |
|
|
push @head, qq(<title>@{[&escape($page)]}</title>); |
|
|
if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) { |
|
|
push @head, qq(<link rel="stylesheet" type="text/css"). |
|
|
qq( href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.$database->mtime ($PageName{DefaultStyleForHTML}))]}"); |
|
|
} |
|
|
push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex}; |
|
|
my ($Links, $links) = &make_navigate_links ($page); |
|
|
#print $Links; ## Link: fields |
|
|
$links = join "\n", (@head, $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" class="$option{body_class}"> |
|
|
<head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile"> |
|
|
$links |
|
|
</head> |
|
|
<body class="$option{body_class}"> |
|
|
EOD |
|
|
&print_navigate_links ($page); |
|
|
print <<EOD; |
|
|
<h1 class="header">@{[&escape($page)]}</h1> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub get_charset_name ($;%) { |
|
|
my ($charset, %option) = (lc shift, @_); |
|
|
if ($charset =~ 'euc') { |
|
|
$charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp'; |
|
|
} elsif ($charset =~ 'sjis' || $charset =~ 'shift') { |
|
|
$charset = $option{compatible} ? 'x-sjis' : 'shift_jis'; |
|
|
} elsif ($charset =~ 'jis') { |
|
|
$charset = 'iso-2022-jp'; |
|
|
} |
|
|
$charset; |
|
|
} |
|
|
|
|
|
sub print_navigate_links (@) { |
|
|
my ($page) = @_; |
|
|
my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0; |
|
|
my $cookedpage = &encode($page); |
|
|
print <<EOH; |
|
|
<div class="tools"> |
|
|
@{[ $editable |
|
|
? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
<a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd" title="@{[&Resource('ViewThisPageLong',escape=>1)]}">@{[&Resource('ViewThisPage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink" title="@{[&Resource('GoSomewhereLong',escape=>1)]}">@{[&Resource('GoSomewhere',escape=>1)]}</a> | |
|
|
<a href="$url_cgi?$PageName{RecentChanges}" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</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('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page); |
|
|
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;admin=1;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page); |
|
|
push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')}; |
|
|
push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')}; |
|
|
push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')}; |
|
|
push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?$PageName{RecentChanges}", class=>"wiki", title=>&Resource('GoToRecentChangesLink')}; |
|
|
push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'}; |
|
|
push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')}; |
|
|
push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')}; |
|
|
push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')}; |
|
|
push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToLink')}; |
|
|
push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToEditLink')}; |
|
|
push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')}; |
|
|
push @link, {rel=>'history', href=>$uri{cvs_wikipage}.do{my $s=$page;$s=~s/(.)/sprintf '%02X', ord $1/ges;$s}.'.txt', title=>&Resource('ViewHistoryOfThisPageLink'),hreflang=>'en'} if $uri{cvs_wikipage}; |
|
|
push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'} if $wiki::diff::UseDiff; |
|
|
push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'}; |
|
|
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); |
|
|
my $cvslog1 = q$Revision$; |
|
|
my $cvslog2 = q$Date$; |
|
|
print_navigate_links ($page); |
|
|
print <<"EOD"; |
|
|
@{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]} |
|
|
<div class="footer"> |
|
|
<a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 © 2000-2002 by Hiroshi Yuki">@{[&Resource('About:Name:YukiWiki',escape=>1)]}</a> <a href="http://digit.que.ne.jp/work/" title="WalWiki 2.0.beta1.wal.1 © 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a> |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a> |
|
|
</div> |
|
|
</body> |
|
|
</html> |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub escape { |
|
|
my $s = shift; |
|
|
$s =~ s|\x0D\x0A|\x0A|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 $toc = $option{-toc} || []; |
|
|
my $tocnum = 0; |
|
|
|
|
|
## Load constants |
|
|
my %const; |
|
|
if ($option{content_format} =~ /import="([^"]+)"/) { |
|
|
for (split /\s*,\s*/, $1) { |
|
|
my $wp = $database{$_}; |
|
|
if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) { |
|
|
wiki::suikawikiconst::to_hash ($wp => \%const); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
$txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge; |
|
|
my (@txt) = split(/\n/, $txt); |
|
|
my (@saved, @result); |
|
|
unshift(@saved, "</p>"); |
|
|
push(@result, "<p>"); |
|
|
foreach (@txt) { |
|
|
chomp; |
|
|
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
|
|
push @$toc, [5, "i$tocnum" => ($1 || $tocnum)]; |
|
|
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
|
|
push @$toc, [4, "i$tocnum" => ($1 || $tocnum)]; |
|
|
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
|
|
push @$toc, [3, "i$tocnum" => ($1 || $tocnum)]; |
|
|
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
|
|
# if (/^\*\*(.*)/) { |
|
|
# Walrus mod (6) end |
|
|
push @$toc, [2, "i$tocnum" => ($1 || $tocnum)]; |
|
|
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>'); |
|
|
$tocnum++; |
|
|
} elsif (/^\*([^\x0D\x0A]*)/) { |
|
|
push @$toc, [1, "i$tocnum" => ($1 || $tocnum)]; |
|
|
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>'); |
|
|
$tocnum++; |
|
|
} elsif (/^(={1,6})(.*)/) { |
|
|
&back_push('ol', length($1), \@saved, \@result); |
|
|
push(@result, '<li>' . &inline($2, const => \%const) . '</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, const => \%const) . '</li>'); |
|
|
} elsif (/^:([^:]+):(.*)/) { |
|
|
&back_push('dl', 1, \@saved, \@result); |
|
|
push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>'); |
|
|
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
|
|
&back_push('blockquote', length($1), \@saved, \@result); |
|
|
push @result, "<p>"; |
|
|
push(@result, &inline($2, const => \%const)); |
|
|
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, &inline($1, const => \%const)); |
|
|
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { |
|
|
&back_push('table', 1, \@saved, \@result); |
|
|
####### |
|
|
# 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], const => \%const)); |
|
|
} 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, const => \%const); |
|
|
} else { |
|
|
push(@result, &inline($_, const => \%const)); |
|
|
} |
|
|
} |
|
|
push(@result, splice(@saved)); |
|
|
|
|
|
my $r = join("\n", @result); |
|
|
$r =~ s#<p>\x0D?\x0A</p>##g; |
|
|
$r =~ s#[\x0D\x0A]+</#</#g; |
|
|
$r =~ s#<pre>\x0D?\x0A#<pre>#g; |
|
|
$r; |
|
|
} |
|
|
|
|
|
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, %option) = @_; |
|
|
$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|'''([^']+)'''|<strong>$1</strong>|g; |
|
|
$line =~ s|''([^']+)''|<em>$1</em>|g; |
|
|
$line =~ s{ |
|
|
(\[\[(\#\S+?)\]\]) |
|
|
|\[\[([^[]+?)](?:>>([0-9]+))?] |
|
|
|>>([0-9]+) |
|
|
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
|
|
}{ |
|
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
|
|
if ($l) { |
|
|
&embedded_to_html($1); |
|
|
} 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('JumpAndEditWikiPage',escape=>1)]}" href="$url_cgi?@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</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 } |
|
|
} |
|
|
&init_InterWikiName () unless $interwiki{'[[]]'}; |
|
|
if ($interwiki{$site}) { |
|
|
&load_formatter ('interwiki'); |
|
|
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(<@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}>); |
|
|
} |
|
|
} else { |
|
|
qq(<@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&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 = $database->mtime ($form{mypage}); |
|
|
&load_formatter (qw/form_input form_option/); |
|
|
$definition = &unescape ($definition); |
|
|
$definition =~ s/\\(.)/$1/g; |
|
|
$option = &unescape ($option); |
|
|
$option =~ s/\\(.)/$1/g; |
|
|
$fmt{form_option}->replace ($option, $param); |
|
|
$param->{output}->{form} = 1 unless defined $param->{output}->{form}; |
|
|
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; |
|
|
my $target_page = $param->{output}->{page} || $form{mypage}; |
|
|
$param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage}); |
|
|
my $target_form = $param->{output}->{id}; |
|
|
my $r = ''; |
|
|
$r = <<EOH if $param->{output}->{form}; |
|
|
<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 .= "</form>\n" if $param->{output}->{form}; |
|
|
$r; |
|
|
} else { ## No input-interface WikiForm |
|
|
qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>); |
|
|
} |
|
|
} else { |
|
|
qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>); |
|
|
} |
|
|
}} |
|
|
|
|
|
sub print_message { |
|
|
my ($msg) = @_; |
|
|
print qq(<p><strong>@{[&escape($msg)]}</strong></p>); |
|
|
} |
|
|
|
|
|
sub init_form { |
|
|
## TODO: Support multipart/form-data |
|
|
my $query = ''; |
|
|
if (uc $main::ENV{REQUEST_METHOD} eq 'POST') { |
|
|
read STDIN, $query, $main::ENV{CONTENT_LENGTH}; |
|
|
} |
|
|
$query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING}; |
|
|
if ($main::ENV{REQUEST_METHOD} ne 'POST' && $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'; |
|
|
} |
|
|
} else { |
|
|
for (split /[;&]/, $query) { |
|
|
if (my ($n, $v) = split /=/, $_, 2) { |
|
|
for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge}; |
|
|
$form{$n} = $v; |
|
|
} |
|
|
} |
|
|
unless (defined $form{mypage}) { |
|
|
$form{mypage} = $form{epage}; |
|
|
$form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g; |
|
|
} |
|
|
if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') { |
|
|
$form{mypage} = &code_convert(\$form{mypage}, $kanjicode); |
|
|
$form{mycmd} = $page_command{$form{mypage}}; |
|
|
} |
|
|
} |
|
|
$form{mypage} ||= 'HomePage'; |
|
|
$form{mypage} =~ tr/\x00-\x1F\x7F//d; |
|
|
$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); |
|
|
} |
|
|
|
|
|
{my %SubjectLine; |
|
|
sub get_subjectline { |
|
|
my ($page, %option) = @_; |
|
|
unless (defined $SubjectLine{$page}) { |
|
|
if (not &is_editable($page)) { |
|
|
$SubjectLine{$page} = ""; |
|
|
} else { |
|
|
$SubjectLine{$page} = $database{$page}; |
|
|
$SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s; |
|
|
$SubjectLine{$page} =~ s/\x0D?\x0A.*//s; |
|
|
} |
|
|
} |
|
|
if (length $SubjectLine{$page}) { |
|
|
$option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter'); |
|
|
$option{delimiter}.$SubjectLine{$page}.$option{tail}; |
|
|
} else { |
|
|
''; |
|
|
} |
|
|
}} |
|
|
|
|
|
sub open_db { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}"); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
eval q{use AnyDBM_File}; |
|
|
tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}"); |
|
|
} elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') { |
|
|
eval q{use Yuki::YukiWikiDB}; |
|
|
tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}"); |
|
|
} else { ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta |
|
|
eval qq{use $modifier_dbtype}; |
|
|
$database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or &print_error("(tie $modifier_dbtype) $PathTo{WikiDataBase}"); |
|
|
} |
|
|
} |
|
|
|
|
|
sub close_db { |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
|
|
dbmclose(%database); |
|
|
} else { |
|
|
untie(%database); |
|
|
} |
|
|
} |
|
7 |
|
|
8 |
sub editform (@) { |
=head1 NAME |
|
my %option = @_; |
|
|
my $frozen = &is_frozen ($option{page}); |
|
|
$option{content} = $database{$option{page}} unless defined $option{content}; |
|
|
$option{content} = $database{NewPageTemplate} unless length $option{content}; |
|
|
$option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified}; |
|
|
my $f = ''; |
|
|
my $magic = ''; |
|
|
$magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s; |
|
|
|
|
|
my $selected = 'read'; |
|
|
if ($form{after_edit_cmd}) { |
|
|
$selected = $form{after_edit_cmd}; |
|
|
} elsif ($magic =~ /Const|Config|CSS/) { |
|
|
$selected = 'edit'; |
|
|
} |
|
|
my $afteredit = <<EOH; |
|
|
<select name="after_edit_cmd"> |
|
|
<option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option> |
|
|
<option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option> |
|
|
</select> |
|
|
EOH |
|
|
$f .= <<"EOD"; |
|
|
<form action="$uri{wiki}" method="post"> |
|
|
@{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd></label>) ]} |
|
|
@{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br> |
|
|
<input type="hidden" name="myLastModified" value="$option{last_modified}"> |
|
|
<input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}"> |
|
|
<textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br> |
|
|
@{[ |
|
|
$option{admin} ? |
|
|
qq( |
|
|
<label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label> |
|
|
<label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>) |
|
|
: "" |
|
|
]} |
|
|
@{[ |
|
|
$option{conflict} ? "" : |
|
|
qq( |
|
|
<label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br> |
|
|
<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label> |
|
|
$afteredit |
|
|
) |
|
|
]} |
|
|
</form> |
|
|
EOD |
|
|
unless ($option{conflict}) { |
|
|
## Show help text |
|
|
my $help = $database{WikiEditHelp}; |
|
|
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
|
|
$f .= &text_to_html ($help, toc => 0); |
|
|
} |
|
|
$f; |
|
|
} |
|
|
|
|
|
sub is_editable { |
|
|
my ($page) = @_; |
|
|
$page =~ /[\x00-\x1F\x7F]/ ? 0 : 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 =~ /^\[\[(\S+?)\]\]$/) { |
|
|
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 get_now { |
|
|
my ($sec, $min, $hour, $day, $mon, $year) = 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; |
|
|
return "$year-$mon-$day $hour:$min"; |
|
|
} |
|
|
|
|
|
sub init_InterWikiName { |
|
|
my @content = split /\n/, $database{InterWikiName}; |
|
|
for (@content) { |
|
|
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
|
|
$interwiki{$1} = $2; |
|
|
} |
|
|
} |
|
|
$interwiki{'[[]]'} = 1; ## dummy |
|
|
} |
|
|
|
|
|
sub frozen_reject { |
|
|
my ($isfrozen) = $database->meta (IsFrozen => $form{mypage}); |
|
|
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('Error:PasswordIsIncorrect')); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
sub is_frozen ($) { $database->meta (IsFrozen => $_[0]) ? 1 : 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 || &Resource('WikiForm:WikiComment:DefaultName'); |
|
|
($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{(\[\[\#r?comment\]\])}{ |
|
|
my $embed = $1; |
|
|
if ($i == $form{comment_index}) { |
|
|
if ($embed ne '[[#rcomment]]') { |
|
|
$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 '[[#comment]]' or $embedded eq '[[#rcomment]]') { |
|
|
unless ($main::_EMBEDED) { |
|
|
my $lastmodified = $database->mtime ($form{mypage}); |
|
|
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"> |
|
|
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
|
|
<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('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" 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}"> |
|
|
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
|
|
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
|
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
|
|
</form></del> |
|
|
EOD |
|
|
} |
|
|
} elsif ($embedded =~ /$embed_command{searched}/) { |
|
|
return get_search_result ($1, -match_myself => 1); |
|
|
} 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]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
|
|
} |
|
|
} else { ## nested #EMBED |
|
|
$r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\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}) { |
|
|
require Message::Util::Formatter; |
|
|
$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} ||= &Resource('WikiForm:WikiComment:DefaultName'); |
|
|
$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; |
|
|
} |
|
|
} |
|
|
|
|
|
sub code_convert { |
|
|
require Jcode; |
|
|
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/; |
|
|
$$contentref = Jcode->new ($contentref)->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ ))->$code; |
|
|
return $$contentref; |
|
|
} |
|
|
|
|
|
sub do_diff { |
|
|
my $title = $form{mypage}; |
|
|
&print_header($title, -noindex => 1); |
|
|
print qq(<h2>@{[&Resource('Diff:Title',escape=>1)]}</h2>); |
|
|
print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>); |
|
|
print qq(<pre class="diff">); |
|
|
for (split(/\n/, &escape ($database->traverse_diff ($form{mypage})))) { |
|
|
if (/^\+(.*)/) { |
|
|
print qq(<ins class="added">$1</ins>\n); |
|
|
} elsif (/^\-(.*)/) { |
|
|
print qq(<del class="deleted">$1</del>\n); |
|
|
} elsif (/^\=(.*)/) { |
|
|
print qq(<span class="same">$1</span>\n); |
|
|
} else { |
|
|
print qq|??? $_\n|; |
|
|
} |
|
|
} |
|
|
print qq(</pre>); |
|
|
&print_footer($title); |
|
|
} |
|
|
|
|
|
sub do_rss { |
|
|
eval q{use Yuki::RSS}; |
|
|
my $rss = new Yuki::RSS( |
|
|
version => '1.0', |
|
|
encoding => &get_charset_name ($kanjicode), |
|
|
); |
|
|
my $scheme = 'http'; |
|
|
$scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
|
|
my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi"; |
|
|
$rss->stylesheet ( |
|
|
href => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS", |
|
|
type => 'text/css', |
|
|
); |
|
|
$rss->channel( |
|
|
title => &Resource ('RSS:WikiTitle'), |
|
|
link => $myuri, |
|
|
description => &Resource ('RSS:WikiDescription'), |
|
|
'dc:language' => $lang, |
|
|
); |
|
|
my $recentchanges = $database{RecentChanges}; |
|
|
my $count = 0; |
|
|
foreach (split(/\n/, $recentchanges)) { |
|
|
last if ($count >= 15); |
|
|
if (/\[\[([^]]+)\]\]/) { |
|
|
my $title = $1; |
|
|
$rss->add_item ( |
|
|
title => &escape($title), |
|
|
link => $myuri . '?' . &encode($title), |
|
|
description => &escape(&get_subjectline($title,delimiter=>'')), |
|
|
'dc:date' => $database->mtime ($title), |
|
|
); |
|
|
$count++; |
|
|
} |
|
|
} |
|
|
# print RSS information (as XML). |
|
|
print <<"EOD" |
|
|
Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]} |
|
|
|
|
|
@{[$rss->as_string]} |
|
|
EOD |
|
|
} |
|
|
|
|
|
sub _rfc3339_date ($) { |
|
|
my @time = gmtime (shift); |
|
|
sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0]; |
|
|
} |
|
|
|
|
|
sub is_exist_page { |
|
|
my ($name) = @_; |
|
|
if ($use_exists) { |
|
|
return exists($database{$name}); |
|
|
} else { |
|
|
return $database{$name}; |
|
|
} |
|
|
} |
|
|
|
|
|
sub __get_database ($) { $database{ $_[0] } } |
|
|
|
|
|
my %_Resource; |
|
|
sub Resource ($;%) { |
|
|
my ($s, %o) = @_; |
|
|
unless (defined $_Resource{$s}) { |
|
|
$_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option}); |
|
|
} |
|
|
$o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s}; |
|
|
} |
|
|
|
|
|
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 ($) { split /"/, $main::database->meta (Referer => $_[0]) } |
|
|
sub set ($%) { |
|
|
my $page = shift; |
|
|
my $list = shift; |
|
|
$main::database->meta (Referer => $page => 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; |
|
|
our $UseLog; |
|
|
|
|
|
sub add ($) { |
|
|
my $s = shift; |
|
|
return unless length $s; |
|
|
return unless $UseLog; |
|
|
$s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge; |
|
|
my %ua; |
|
|
for (split /\n/, &main::__get_database($main::PageName{UserAgentList})) { |
|
|
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::database->STORE ($main::PageName{UserAgentList} => $s, -touch => 0); |
|
|
} |
|
|
|
|
|
package wiki::suikawikiconst; |
|
|
|
|
|
sub to_hash ($;$) { |
|
|
my $page = shift; |
|
|
my $h = shift || {}; |
|
|
my $val; |
|
|
for my $line (split /\n/, $page) { |
|
|
$line =~ tr/\x0A\x0D//d; |
|
|
if ($val && $line =~ s/^\s+//) { |
|
|
$h->{$val} .= length $h->{$val} ? "\n" . $line : $line; |
|
|
} elsif ($line =~ /^(.+):/) { |
|
|
$val = $1; $h->{$val} = ''; |
|
|
} |
|
|
} |
|
|
$h; |
|
|
} |
|
|
|
|
|
package wiki::dummy; |
|
|
sub mtime (@) {undef} |
|
|
sub meta (@) {undef} |
|
|
sub Yuki::YukiWikiDB2::meta (@) {undef} |
|
|
|
|
|
package SuikaWiki::Plugin; |
|
|
our $plugin_directory; # defined in top of this file. |
|
|
our %List; |
|
|
our %Index; |
|
|
|
|
|
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 resource ($$;%) { shift; &main::Resource (@_) } |
|
|
sub uri ($$) { $main::uri{$_[1]} } |
|
|
sub new_index ($$) { ++$Index{$_[1]} } |
|
|
|
|
|
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::$_); |
|
|
} |
|
|
} |
|
|
|
|
|
&import_plugins (); |
|
|
|
|
|
package wiki::conneg; |
|
9 |
|
|
10 |
## BUG: this parser isn't strict. |
wiki.cgi - SuikaWiki: Yet yet another WikiEngine - HTTP CGI Script Driver |
|
sub get_accept_lang (;$) { |
|
|
my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE}; |
|
|
my %alang = (ja => 0.0002, en => 0.0001); |
|
|
my $i = 0.1; |
|
|
for (split /\s*,\s*/, $alang) { |
|
|
tr/\x09\x0A\x0D\x20//d; |
|
|
if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) { |
|
|
my $l = lc $1; $l =~ tr/\x22\x5C//d; |
|
|
$alang{$l} = (defined $2 ? $2 : 1.000)*1000; |
|
|
$alang{$l} += $i unless $alang{$l} == 0; |
|
|
$i -= 0.001; |
|
|
} |
|
|
} |
|
|
\%alang; |
|
|
} |
|
11 |
|
|
12 |
package wiki::resource; |
=head1 DESCRIPTION |
13 |
|
|
14 |
sub get ($;\%) { |
This is a boot script for SuikaWiki HTTP CGI Script Driver (SWHCS). |
15 |
my ($resname, $option) = @_; |
Actual driving of WikiEngine is coded in C<lib/suikawiki.pl>. |
16 |
$option->{accept_language} ||= &wiki::conneg::get_accept_lang (); |
Options such as WikiDB directories can be specified in C<wikidata/suikawiki.ph>. |
|
$option->{resource} ||= {}; |
|
|
my $v; |
|
|
for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) { |
|
|
while (length $lang) { |
|
|
unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) { |
|
|
$option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang)); |
|
|
$v = $option->{resource}->{$lang}->{$resname}; |
|
|
last if defined $v; |
|
|
} |
|
|
$lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//; |
|
|
} |
|
|
last if defined $v; |
|
|
} |
|
|
defined $v ? $v : $resname; |
|
|
} |
|
17 |
|
|
18 |
package main; |
This file is part of SuikaWiki. |
|
&main; |
|
|
exit 0; |
|
19 |
|
|
20 |
1; |
=head1 SYNOPSIS |
|
__END__ |
|
|
=head1 NAME |
|
21 |
|
|
22 |
wiki.cgi --- SuikaWiki: Yet yet another Wiki engine |
$ telnet www.example.net 80<Enter> |
23 |
|
GET /path/to/wiki/cgi/script?WikiName HTTP/1.1<Enter> |
24 |
|
Host: www.example.net<Enter> |
25 |
|
<Enter> |
26 |
|
|
27 |
=head1 AUTHORS |
Future version of SuikaWiki will accept "Accept: text/plain" HTTP |
28 |
|
request header field. |
29 |
|
|
30 |
Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/> |
=head1 SEE ALSO |
31 |
|
|
32 |
Makio Tsukamoto <http://digit.que.ne.jp/> |
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>, |
33 |
|
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SWHCS>, |
34 |
Wakaba <w@suika.fam.cx> |
C<lib/suikawiki.pl>, |
35 |
|
C<wikidata/suikawiki-config.ph> |
36 |
|
|
37 |
=head1 LICENSE |
=head1 LICENSE |
38 |
|
|
39 |
Copyright (C) 2000-2003 AUTHORS |
Copyright 2002-2004 Wakaba <w@suika.fam.cx>. All rights reserved. |
40 |
|
|
41 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
42 |
modify it under the same terms as Perl itself. |
modify it under the same terms as Perl itself. |
43 |
|
|
44 |
=cut |
=cut |
45 |
|
|
46 |
|
1; # $Date$ |