--- suikawiki/script/wiki.cgi 2002/11/13 08:28:15 1.30 +++ suikawiki/script/wiki.cgi 2003/01/26 02:30:24 1.51 @@ -1,315 +1,141 @@ #!/usr/bin/perl -#!perl -# -# wiki.cgi - This is YukiWiki, yet another Wiki clone. -# -# Copyright (C) 2000-2002 by Hiroshi Yuki. -# -# 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. -# -# WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。 -# -# * 更新内容 -# -# 2.0.beta1.wal.1 on 2002/05/19,22:32:19 -# (1) Footerの変更 -# (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない -# (3) 別名リンク([別名 URL])に対応。 -# (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。 -# (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成 -# (6) HTMLモード対応。 -# -# 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。 -# ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。 -# - インラインの画像変換 -# - YukiWikiDB対応 -# - テーブル -# - DB関連モジュールuseのeval化 -# - BracketNameによるキーからブラケットを排除 -# ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。 -# [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。 -# -#======================================= - -# Walrus add (debug) start -my $walrus_log; -my $walrus_debugging = 0; -# Walrus add (debug) end +## wiki.cgi - This is SuikaWiki, yet another WikiEngine -# Libraries. use strict; -use lib qw(./WalWiki/lib); -use CGI qw(:standard); +use lib qw(./lib); use CGI::Carp qw(fatalsToBrowser); -use Yuki::RSS; -use Yuki::DiffText qw(difftext); -use Yuki::YukiWikiDB; -use AnyDBM_File; -require 'jcode.pl'; -# use Jcode; +binmode STDOUT; binmode STDIN; +our $VERSION = do{my @r=(q$Revision: 1.51 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; +require 'wikidata/suikawiki-config.ph'; ## site configuration script +require Yuki::YukiWikiCache; 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. -# -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 = '*'; -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 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 $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b'; # Walrus del (2) -my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b'; # Walrus add (2) -my $bracket_name = '\[\[(\S+?)\]\]'; -my $embedded_name = '\[\[(#\S+?)\]\]'; -my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]'; -my $interwiki_name = 'i:([^:]+):([^:].*)'; -############################## -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 = ( +our %fmt; ## formatter objects +our %embed_command = ( searched => '^\[\[#searched:([^\]]+)\]\]$', + form => qr/\[\[\#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, -); +our ($modifier_dbtype,$url_cgi,%uri,%PathTo); +our (%PageName,$kanjicode,$lang,%ViewDefinition); + my %form; -my %database; -my %infobase; -my %diffbase; -my %resource; +our %database; +our $database = bless {}, 'wiki::dummy'; my %interwiki; -############################## -my %page_command = ( - $IndexPage => 'index', - $SearchPage => 'searchform', - $CreatePage => 'create', - $RssPage => 'rss', - $AdminChangePassword => 'adminchangepasswordform', - #$FrontPage => 'FrontPage', -); my %command_do = ( - read => \&do_read, - TEXT_CSS => \&do_output_css, - edit => \&do_edit, - adminedit => \&do_adminedit, - adminchangepasswordform => \&do_adminchangepasswordform, + default => \&do_view, 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, ); -############################## -my @ignore_html_page = ('FrontPage'); # Walrus add (6) -my @ignore_html_tags = ('a', 'br', 'img'); # Walrus add (6) -my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) -############################## -# &test_convert; -&main; -exit(0); -############################## +our $UA = ''; ## User agent name +$| = 1; sub main { - &init_resource; + $UA = $main::ENV{HTTP_USER_AGENT}; &open_db; &init_form; - &init_InterWikiName; if ($command_do{$form{mycmd}}) { &{$command_do{$form{mycmd}}}; } else { - &do_FrontPage; + &{$command_do{default}}; } &close_db; } -sub do_read { +sub do_view { my $content = $database{$form{mypage}}; - my $lm = &get_info($form{mypage}, $info_LastModified); + my $lm = $database->mtime ($form{mypage}); wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); - my ($r, $c) = get_search_result ($form{mypage}); - my $rl = wiki::referer::list_html ($form{mypage}); - my @toc; - push @toc, qq(-See Also) if $c; - push @toc, qq(-参照元) 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]+##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]])) unless $cf =~ /obsoleted="yes"/; - } else { - &print_header($form{mypage}, -last_modified => $lm); - print "
@{[&escape($content)]}
"; - } - if ($c) { - print q{

See also

}; - print $r; - } - if ($rl) { - print qq(

参照元

\n$rl
\n); + wiki::useragent::add ($ENV{HTTP_USER_AGENT}); + &load_formatter ('view'); + my $view = $form{mycmd}; + if ($view eq 'edit') { + $view = 'adminedit' if $form{admin}; + } elsif ($view =~ /[^0-9A-Za-z]/) { + $view = 'default' + } + if ($view eq 'default' || !$view) { + ## BUG: this code is not strict + if ($main::ENV{HTTP_COOKIE} =~ /SelectedMode=([0-9A-Za-z]+)/) { + $view = $1; + } else { + $view = 'read'; + } } - &print_footer($form{mypage}, $lm); + my ($magic, $content) = &SuikaWiki::Plugin::magic_and_content (undef, $content); + $magic ||= '#?SuikaWiki/0.9'; + my $o = bless {param => \%form, page => $form{mypage}, toc => [], + magic => $magic, content => $content, + formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'; + if (!ref $ViewDefinition{$view} || !&{$ViewDefinition{$view}->{check}} ($o)) { + print "Status: 406 Unsupported Media Type\n"; + $view = '-UnsupportedMediaType'; + } + my $media = $ViewDefinition{$view}->{media}; + if ($ViewDefinition{$view}->{xmedia} && $UA =~ /Gecko/) { + $media = $ViewDefinition{$view}->{xmedia}; + $o->{media} = $media; + } elsif ($UA =~ m#Mozilla/0\..+Windows#) { + $kanjicode = 'shift_jis'; + } + if ($magic =~ m!^\#\?SuikaWiki/0.9!) { + &print_header ($form{mypage}, -last_modified => ($magic =~ /interactive="yes"/ ? time : $lm), + -expires => ($magic =~ /interactive="yes"/ ? 1 : undef), o => $o, + -media => $media, -magic => $magic, content => $content); + } else { + &print_header($form{mypage}, -media => $media, + -magic => $magic, -last_modified => $lm, o => $o); + } + if ($kanjicode ne 'euc') { + my $s = $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o); + print &code_convert (\$s => $kanjicode); + } else { + print $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o); + } } -sub do_output_css { - my $content = $database{$form{mypage}}; - if ($content =~ m#^\s*/\*\s*W3C-CSS#) { - my $lm = &get_info($form{mypage}, $info_LastModified); - print "Content-Type: text/css; charset=$charset\n"; - print "Last-Modified: $lm\n"; - print "\n"; - print $content; - } else { +sub _do_view_msg (%) { + my %option = @_; + &load_formatter ('view'); + my $o = bless {param => \%form, page => $option{-page}, toc => [], condition => \%option, + formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'; + unless (&{$ViewDefinition{$option{-view}}->{check}} ($o)) { print "Status: 406 Unsupported Media Type\n"; - &print_header('WikiPageIsNotCSS', -noindex => 1); - &print_content($database{WikiPageIsNotCSS}); - &print_footer('WikiPageIsNotCSS'); + $option{-view} = '-UnsupportedMediaType'; } + my $media = $ViewDefinition{$option{-view}}->{media}; + if ($ViewDefinition{$option{-view}}->{xmedia} && $UA =~ /Gecko/) { + $media = $ViewDefinition{$option{-view}}->{xmedia}; + $o->{media} = $media; + } + &print_header($option{-page}, -media => $media, o => $o, -goto => $option{-goto}); + print $fmt{view}->replace ($ViewDefinition{$option{-view}}->{template} => $o); } -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}); - my ($r, $c) = get_search_result ($form{mypage}); - my $rl = wiki::referer::list_html ($form{mypage}); - if ($c) { - print q{

See also

}; - print $r; - } - if ($rl) { - print qq(

参照元

\n$rl
\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}); +sub id_and_name ($) { + my $name = shift; + if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) { + qq{id="$name">1); + qq{id="$name"}; } - &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}); + &_do_view_msg (-view => '-error', -page => $form{mypage}, + error_message => &Resource ('Error:PasswordMismatch')); + return; } - my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); + my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); 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}); + &_do_view_msg (-view => '-error', -page => $form{mypage}, + error_message => &Resource ('Error:PasswordIsIncorrect')); + return; } } my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); @@ -317,25 +143,14 @@ 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); + $database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted); + + &_do_view_msg (-view => '-wrote', -page => $form{mypage}); } -sub do_index { - &print_header($IndexPage); - print qq(); - &print_footer($IndexPage); +sub valid_password ($) { + my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); + return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; } sub do_write { @@ -344,258 +159,144 @@ } 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})) { + &_do_view_msg (-view => '-error', -page => $form{mypage}, + error_message => &Resource ('Error:ThisPageIsUneditable')); 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; + ## Check confliction + if ($form{myLastModified} ne $database->mtime ($form{mypage})) { + &_do_view_msg (-view => '-conflict', -page => $form{mypage}); + return; } 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; + if ($form{mytouch} || !ref $database) { + $database{$form{mypage}} = $form{mymsg}; + } else { + $database->STORE ($form{mypage} => $form{mymsg}, -touch => 0); } - &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); - &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":'')); - &print_message($resource{saved}); - &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); - &print_footer($CompletedSuccessfully); + $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}); + } + &_do_view_msg (-view => '-wrote', -page => $form{mypage}, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'default').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment)); } 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}); + &_do_view_msg (-view => '-deleted', -page => $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 _compatible_options () { + (use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0)); } sub get_search_result ($;%) { - my $word = shift; + my $word = lc shift; + my $SearchResult = SuikaWiki::Plugin->cache ('search'); 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 ($page, $word) > -1) { - my $c = $content =~ s/\Q$word\E/$word/g; - push @r, [$page, $c+20]; - } elsif (index ($word, $page) > -1) { - my $c = $content =~ s/\Q$word\E/$word/g; - push @r, [$page, $c+10]; - } elsif (my $c = $content =~ s/\Q$word\E/$word/g) { - push @r, [$page, $c]; + unless (defined $SearchResult->{$word}) { + for my $page (keys %database) { + next if !$option{-match_myself} && ($page eq $word); + my $content = lc $database{$page}; + $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s; + 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]; + } } + @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; + $SearchResult->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r; + } else { + @r = map {[split /\x1F/, $_, 2]} split /\x1E/, $SearchResult->{$word}; } - my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#$1#g; $s }; - my $r = join "\n", map {qq(
  • [$_->[1]] @{[&$em(&escape($_->[0]))]} @{[&$em(&escape(&get_subjectline($_->[0])))]}
  • )} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; + #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#$1#gi; $s }; + my $r = join "\n", map {qq(
  • [$_->[1]] @{[&escape($_->[0])]} @{[&escape(&get_subjectline($_->[0]))]}
  • )} @r; $r = qq|| 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"; -
    - - $resource{newpagename}
    - -
    -
    -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 "Location: $uri{wiki}?$name\n"; print "\n"; } -sub do_FrontPage { - open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); - my $content = join('', ); - &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(

    $msg

    ); - &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"/; - print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto}; - print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; - my $cookedpage = &encode($page); - my $escapedpage = &escape($page); - print <<"EOD"; -Content-type: text/html; charset=$charset + my @head; + $option{o}->{-header}->{class} = &is_frozen($page) ? 'frozen' : ''; + $option{o}->{-header}->{class} .= " wiki-page-obsoleted" if $option{-magic} =~ /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(); + } elsif ($UA =~ /Gecko/) { + print qq{Refresh: 0; url="$option{-goto}"\n}; + push @head, qq(); + } else { + $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#; + print qq{Refresh: 0; url="$option{-goto}"\n}; + push @head, qq(); + } + } + print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified}; + if ($option{-expires} != -1) { + if (defined $option{-expires}) { ## TODO: Don't use asctime + print qq{Expires: @{[scalar gmtime (time + $option{-expires})]}\n}; + } elsif ($option{-media}->{expires} != -1) { + print qq{Expires: @{[scalar gmtime (time + $option{-media}->{expires})]}\n}; + } + } + if ($option{-media}->{charset} && $UA =~ m#Mozilla/[12]\.#) { + my $ct = qq{$option{-media}->{type}; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}}; + print qq{Content-Type: $ct\n}; + $option{o}->{-header}->{meta_ct} = qq{\n}; + } elsif (!$option{-media}->{charset} || $UA =~ m#Infomosaic|Mozilla/0\.#) { + print qq{Content-Type: $option{-media}->{type}\n}; + $option{o}->{-header}->{meta_ct} = qq{\n}; + } else { + my $type = $option{-media}->{type}; + $type = 'application/xml' if $type eq 'application/rss+xml'; + print qq{Content-Type: $type; charset=@{[&get_charset_name($kanjicode)]}\n}; + } + print <<"EOD"; ## TODO: Content-Language: $lang Content-Style-Type: text/css - - - - $escapedpage - - - - - @{[$option{-noindex} ? q() : '']} - - -EOD - &print_navigate_links ($page); - print <@{[&escape($page)]} EOD + $option{o}->{-header}->{links} = join "\n", (@head); } -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; +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'; } - my $cookedpage = &encode($page); - print < - @{[ $admineditable - ? qq($resource{admineditbutton} | ) - : qq() - ]} - @{[ $editable - ? #qq($resource{editbutton} E | ) - qq(編集 | ) - : qq() - ]} - @{[ $admineditable - ? qq($resource{diffbutton} | ) - : qq() - ]} - 新規 | - $resource{indexbutton} | - 首頁 | - $resource{searchbutton} | - どこか | - 最新 - -EOH -<$resource{createbutton} | - $resource{indexbutton} | - - $FrontPage | - $resource{searchbutton} | - どこか | - $resource{recentchangesbutton} - -EOH -} - -sub print_footer { - my ($page, $lm) = @_; - $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) - # Walrus mod (1) start - my $cvslog1 = q$Revision: 1.30 $; - my $cvslog2 = q$Date: 2002/11/13 08:28:15 $; - print_navigate_links ($page); - print <<"EOD"; -@{[ $lm ? qq(
    Last modified: $lm
    ) : '' ]} - -$walrus_log - - -EOD -# print <<"EOD"; -#
    -# -# -# -# -# EOD - # Walrus mod (1) end + $charset; } sub escape { my $s = shift; - $s =~ s|\r\n|\n|g; + $s =~ s|\x0D\x0A|\x0A|g; $s =~ s|&|&|g; $s =~ s|<|<|g; $s =~ s|>|>|g; @@ -613,47 +314,70 @@ return $s; } -sub print_content ($;$) { - my ($rawcontent, %option) = @_; - print &text_to_html($rawcontent, toc=>1, %option); +sub convert_format ($$$;%) { + my ($content, $d => $t, %option) = @_; + &load_formatter ('format'); + my $f = SuikaWiki::Plugin->format_converter ($d => $t); + if (ref $f) { + $option{content} = $content; + $option{from} = $d; + $option{to} = $t; + &$f ({}, bless (\%option, 'SuikaWiki::Plugin')); + } elsif ($t =~ /HTML|xml/) { + length $content ? '
    '.&escape($content).'
    ' : ''; + } else { + $content; + } } sub text_to_html { my ($txt, %option) = @_; - my (@txt) = split(/\n/, $txt); - my @toc; - my @toc2 = @{$option{-toc}||[]}; + my $toc = $option{-toc} || (ref $option{toc} ? $option{toc} : []); my $tocnum = 0; + + ## Load constants + my %const; + if ($option{magic} =~ /import="([^"]+)"/) { + for (split /\s*,\s*/, $1) { + my $wp = $database{$_}; + if ($wp =~ m!^\#\?SuikaWikiConst/(?:0.9|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, "

    "); push(@result, "

    "); foreach (@txt) { chomp; if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { - push(@toc, qq(----- @{[&escape($1)||$tocnum]}\n)); - push(@result, splice(@saved), qq(

    ) . &inline($1) . '
    '); + push @$toc, [5, "i$tocnum" => ($1 || $tocnum)]; + push(@result, splice(@saved), qq(
    ) . &inline($1, %option, const => \%const) . '
    '); $tocnum++; } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { - push(@toc, qq(---- @{[&escape($1)||$tocnum]}\n)); - push(@result, splice(@saved), qq(
    ) . &inline($1) . '
    '); + push @$toc, [4, "i$tocnum" => ($1 || $tocnum)]; + push(@result, splice(@saved), qq(
    ) . &inline($1, %option, const => \%const) . '
    '); $tocnum++; } elsif (/^\*\*\*([^\x0D\x0A]*)/) { - push(@toc, qq(--- @{[&escape($1)||$tocnum]}\n)); - push(@result, splice(@saved), qq(

    ) . &inline($1) . '

    '); + push @$toc, [3, "i$tocnum" => ($1 || $tocnum)]; + push(@result, splice(@saved), qq(

    ) . &inline($1, %option, const => \%const) . '

    '); $tocnum++; } elsif (/^\*\*([^\x0D\x0A]*)/) { # if (/^\*\*(.*)/) { # Walrus mod (6) end - push(@toc, qq(-- @{[&escape($1)||$tocnum]}\n)); - push(@result, splice(@saved), qq(

    ) . &inline($1) . '

    '); + push @$toc, [2, "i$tocnum" => ($1 || $tocnum)]; + push(@result, splice(@saved), qq(

    ) . &inline($1, %option, const => \%const) . '

    '); $tocnum++; } elsif (/^\*([^\x0D\x0A]*)/) { - push(@toc, qq(- @{[&escape($1)||$tocnum]}\n)); - push(@result, splice(@saved), qq(

    ) . &inline($1) . '

    '); + push @$toc, [1, "i$tocnum" => ($1 || $tocnum)]; + push(@result, splice(@saved), qq(

    ) . &inline($1, %option, const => \%const) . '

    '); $tocnum++; } elsif (/^(={1,6})(.*)/) { &back_push('ol', length($1), \@saved, \@result); - push(@result, '
  • ' . &inline($2) . '
  • '); + push(@result, '
  • ' . &inline($2, %option, const => \%const) . '
  • '); } elsif (/^(-{1,6})(.*)/) { &back_push('ul', length($1), \@saved, \@result); my ($pf, $l) = ('', $2); @@ -661,14 +385,14 @@ my $num = 0+$1; $pf = qq([$num]); } - push(@result, '
  • ' . $pf . &inline ($l) . '
  • '); + push(@result, '
  • ' . $pf . &inline ($l, %option, const => \%const) . '
  • '); } elsif (/^:([^:]+):(.*)/) { &back_push('dl', 1, \@saved, \@result); - push(@result, '
    ' . &inline($1) . '
    ', '
    ' . &inline($2) . '
    '); + push(@result, '
    ' . &inline($1, %option, const => \%const) . '
    ', '
    ' . &inline($2, %option, const => \%const) . '
    '); } elsif (/^(?!>>\d)(>{1,5})(.*)/) { &back_push('blockquote', length($1), \@saved, \@result); push @result, "

    "; - push(@result, &inline($2)); + push(@result, &inline($2, %option, const => \%const)); unshift @saved, "

    "; } elsif (/^\s*$/) { push(@result, splice(@saved)); @@ -676,11 +400,9 @@ unshift(@saved, "

    "); } 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"'); + push(@result, &inline($1, %option, 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 @@ -694,7 +416,7 @@ $colspan[$i]++; } $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; - $value[$i] = sprintf('%s', $align[$i], $colspan[$i], &inline($value[$i])); + $value[$i] = sprintf('%s', $align[$i], $colspan[$i], &inline($value[$i], %option, const => \%const)); } else { $value[$i] = ''; } @@ -711,33 +433,18 @@ } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { my $num = 0+$1; push @result, qq([$num]); - push @result, &inline ($2); + push @result, &inline ($2, %option, const => \%const); } else { - push(@result, &inline($_)); + push(@result, &inline($_, %option, const => \%const)); } } 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, '
  • ' . $2 . '
  • '); - } - } - push(@tocresult, splice(@tocsaved)); - $toc = join("\n", @tocresult); - $toc = $toc ? qq(
    $toc
    ) : ''; - } - $toc .= join("\n", @result); - $toc =~ s#

    \n

    ##g; - $toc =~ s#[\x0D\x0A]+\n#
    #g;
    -    $toc;
    +    my $r = join("\n", @result);
    +    $r =~ s#

    \x0D?\x0A

    ##g; + $r =~ s#[\x0D\x0A]+\x0D?\x0A#
    #g;
    +    $r;
     }
     
     sub back_push {
    @@ -754,143 +461,162 @@
         }
     }
     
    -sub inline {
    -    my ($line) = @_;
    +sub inline ($;%) {
    +    my ($line, %option) = @_;
         $line = &escape($line);
    -    $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3}g;
    +    $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4, \%option)}ge;
    +    $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3}g;
         $line =~ s:\[(WEAK)\[(.+?)\]\]:$2:g;
         $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:$1:g;
         $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:$1($2) ($3) :g;
         $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:$1($2):g;
         $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:$1 ($2) :g;
    -    $line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「$1」%g;
         $line =~ s|'''([^']+)'''|$1|g;
         $line =~ s|''([^']+)''|$1|g;
    -    $line =~ s!
    -      (
    -        (?:<(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)>
    -      |
    -        (?:$bracket_name))	# [[likethis]], [[#comment]], [[Friend:remotelink]]
    -      |\[\[([^[]+?)]>>([0-9]+)]	# [[WikiName]>>1]
    +    $line =~ s{
    +      (\[\[(\#\S+?)\]\])
    +      |\[\[([^[]+?)](?:>>([0-9]+))?]
           |>>([0-9]+)
    -    !
    -      my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);
    +      |<([A-Za-z0-9%]+:(?:(?!>).)+)>
    +    }{
    +      my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
           if ($l) {
    -        &make_link($l)
    +        &embedded_to_html($1);
           } elsif (defined $page) {
             &make_wikilink ($page, anchor => 0+$anchor);
           } elsif ($anum) {
             qq(>>$anum);
    +      } elsif ($uri) {
    +        &make_urilink ($uri);
           }
    -    !gex;
    +    }gex;
         return $line;
     }
     
     sub make_wikilink ($%) {
       my ($ename, %option) = @_;
       my $name = &unescape ($ename);
    +  $option{latest} = $option{latest} ? qq(mycmd=default;x-param=@{[time.[0..9]->[rand 10]]};mypage=) : '';
       if ($database{$name}) {
         my $subject = &escape (&get_subjectline ($name, delimiter => ''));
         if ($option{anchor}) {
    -      return qq($ename>>$option{anchor});
    +      return qq($ename>>$option{anchor});
         } else {
    -      return qq($ename);
    +      return qq($ename);
         }
       } else {
    -    return qq($ename$editchar);
    +    return qq($ename@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]});
       }
     }
     
    -sub make_link {
    -    my $chunk = shift;
    -    # Walrus add (3) start
    -    $chunk =~ s/^<(.*)>$/$1/;
    -    my $name  = $chunk;
    -    if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {
    -        ($name, $chunk) = ($1, $2);
    -    } elsif ($chunk =~ /^mailto:(.*)$/) {
    -        $name = $1;
    -    }
    -    if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {
    -        $name = qq() ;
    -    }
    -    $name = &unarmor_name($name);
    -    # Walrus add (3) end
    -    if ($chunk =~ /^(http|https|ftp|news):/) {
    -        # Walrus mod (3) start
    -#       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {
    -#           return qq();
    -#       } else {
    -#           return qq($chunk);
    -#       }
    -        return qq(<$name>);
    -        # Walrus mod (3) end
    -    } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {
    -        return qq|<$name>|;
    -    } elsif ($chunk =~ /^mailto:(.*)/) {
    -#       return qq($2);                 # Walrus del (3)
    -        return qq(<$name>);              # Walrus add (3)
    -    } elsif ($chunk =~ /^$interwiki_definition$/) {
    -#       return qq($chunk);   # Walrus del (3)
    -        return qq($name);    # Walrus add (3)
    -    } elsif ($chunk =~ /^$embedded_name$/) {
    -        return &embedded_to_html($chunk);
    +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(<$site:$name>);
    +      } else {
    +        qq(<@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}>);
    +      }
         } else {
    -        $chunk = &unarmor_name($chunk);
    -        $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
    -        my $cookedchunk = &encode($chunk);
    -        if ($chunk =~ /^$interwiki_name$/) {
    -            my ($intername, $localname) = ($1, $2);
    -            my $remoteurl = $interwiki{$intername};
    -            if ($remoteurl) {
    -#               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)
    -                $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)
    -#               return qq($chunk); # Walrus del (3)
    -                return qq(@{[&escape($name)]});  # Walrus add (3)
    -            } else {
    -#               return $chunk;                              # Walrus del (3)
    -                return &escape($name);                               # Walrus add (3)
    -            }
    -        } elsif ($database{$chunk}) {
    -            my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
    -#           return qq($chunk);  # Walrus del (3)
    -            return qq(@{[&escape($name)]});   # Walrus add (3)
    -        } elsif ($page_command{$chunk}) {
    -#           return qq($chunk);    # Walrus del (3)
    -            return qq(@{[&escape($name)]});     # Walrus add (3)
    -        } else {
    -            return qq(@{[&escape($name)]}$editchar);
    -        }
    +      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(<$uri>);
    +  } elsif ($uri =~ s/^MAIL://) {	## mail address (not URI)
    +    my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
    +    qq(<$uri>);
    +  } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {	## image (not URI itself)
    +    my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
    +    qq();
    +  } else {	## misc. URI
    +    CGI::Carp::warningsToBrowser (0);
    +    my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
    +    CGI::Carp::warningsToBrowser (1);
    +    qq(<$uri>);
    +  }
     }
     
    -sub print_message {
    -    my ($msg) = @_;
    -    print qq(

    $msg

    ); -} - -sub get_message { - my ($msg) = @_; - qq(

    $msg

    ); -} +{my %FormIndex; +sub make_custom_form ($$$$%) { + my ($wfname, $definition, $template, $foption, $option) = @_; + ## $template is currently not used in this procedure. + #unless ($main::_EMBEDED) { + $FormIndex{$option->{page}}++; + if (length $definition) { + my $param = bless {depth=>10}, 'SuikaWiki::Plugin'; + my $lastmodified = $database->mtime ($option->{page}); + &load_formatter (qw/form_input form_option/); + $definition = &unescape ($definition); + $definition =~ s/\\(.)/$1/g; + $foption = &unescape ($foption); + $foption =~ s/\\(.)/$1/g; + $fmt{form_option}->replace ($foption, $param); + $param->{output}->{form} = 1 unless defined $param->{output}->{form}; + $param->{output}->{form} = 0 if $main::_EMBEDED; + $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; + $param->{output}->{page} ||= $option->{page}; + $param->{form_disabled} = 1 if $database->meta (IsFrozen => $option->{page}); + my $target_form = $param->{output}->{id}; + my $r = ''; + $r = <{output}->{form}; +
    + + + + + +EOH + $r .= qq() if $UA =~ m#Mozilla/[12]\.#; + $r .= $fmt{form_input}->replace ($definition, $param); + $r .= "
    \n" if $param->{output}->{form}; + $r; + } else { ## No input-interface WikiForm + qq(); + } + #} else { + # qq(@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}); + #} +}} sub init_form { - if (param()) { - foreach my $var (param()) { - $form{$var} = param($var); - } + ## TODO: Support multipart/form-data + my $query = ''; + if (uc $main::ENV{REQUEST_METHOD} eq 'POST') { + read STDIN, $query, $main::ENV{CONTENT_LENGTH}; } - if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) { + $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}); - if ($page_command{$query}) { - $form{mycmd} = $page_command{$query}; + $query = &code_convert(\$query, $kanjicode); $form{mypage} = $query; - } else { - $form{mypage} = $query; - $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; + $form{mycmd} = 'default'; + } 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; } } - $form{mypage} ||= 'HomePage'; + $form{mypage} ||= $PageName{FrontPage}; + $form{mypage} =~ tr/\x00-\x1F\x7F//d; + $form{mycmd} ||= 'default'; # mypreview_edit -> do_edit, with preview. # mypreview_adminedit -> do_adminedit, with preview. @@ -906,261 +632,111 @@ # $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}); - 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} = 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 ""; + my $SubjectLine = SuikaWiki::Plugin->cache ('headline'); + unless (defined $SubjectLine->{$page}) { + if (not &is_editable($page)) { + $SubjectLine->{$page} = ""; + } else { + $SubjectLine->{$page} = do { + my $s=$database{$page}; + $s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s; + $s =~ s/\x0D?\x0A.*//s; + $s}; + } + } + if (length $SubjectLine->{$page}) { + $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter'); + $option{delimiter}.$SubjectLine->{$page}.$option{tail}; } 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"); + dbmopen(%database, $PathTo{WikiDataBase}, 0666) or die "(dbmopen) $PathTo{WikiDataBase}"; } 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"); + eval q{use AnyDBM_File}; + tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or die ("(tie AnyDBM_File) $PathTo{WikiDataBase}"); + } elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') { + eval q{use Yuki::YukiWikiDB}; + tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or die ("(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 die ("(tie $modifier_dbtype) $PathTo{WikiDataBase}"); } } 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"; -
    - - - -
    -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(

    $resource{previewtitle}

    \n); - print qq($resource{previewnotice}\n); - print qq(
    \n); - &print_content($form{mymsg}); - print qq(
    \n); - } - } else { - print qq($resource{previewempty}); - } - $mymsg = &escape($form{mymsg}); - } else { - $mymsg = &escape($mymsg || $database{NewPageTemplate}); - } - - my $edit = $mode{admin} ? 'adminedit' : 'edit'; - my $escapedmypage = &escape($form{mypage}); - my $escapedmypassword = &escape($form{mypassword}); - - print <<"EOD"; -
    -

    $escapedmypageの編集

    - @{[ $mode{admin} ? qq($resource{frozenpassword}
    ) : "" ]} - - -
    +sub editform (@) { + 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 = 'default'; + if ($form{after_edit_cmd}) { + $selected = $form{after_edit_cmd}; + } elsif ($magic =~ /Const|Config|CSS/) { + $selected = 'edit'; + } + my $afteredit = < + + + + +EOH + $f .= <<"EOD"; + + @{[ $option{conflict} ? '' : qq() ]} + @{[ $option{admin} ? qq() : "" ]} [@{[&get_new_anchor_index($option{content})]}]
    + + +
    @{[ - $mode{admin} ? + $option{admin} ? qq( - $resource{frozenbutton} - $resource{notfrozenbutton}
    ) + +
    ) : "" ]} @{[ - $mode{conflict} ? "" : + $option{conflict} ? "" : qq( - $resource{touch}
    - - S - [@{[do {my $n = 0; - $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; - ++$n}]}]
    +
    + + $afteredit ) ]} 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('', ); - # &code_convert(\$content, $kanjicode); - # close(FILE); - # print &text_to_html($content, toc=>0); - } -} - -sub print_passwordform { - print <<"EOD"; -
    - - $resource{oldpassword}
    - $resource{newpassword}
    - $resource{newpassword2}
    -
    -
    -EOD + $f; } sub is_editable { my ($page) = @_; - if (&is_bracket_name($page)) { - return 0; - } elsif ($fixedpage{$page}) { - return 0; - } elsif ($page =~ /\s/) { - return 0; - } elsif ($page =~ /^\#/) { - return 0; - } elsif ($page =~ /^$interwiki_name$/) { - return 0; - } else { - return 1; - } -} - -# armor_name: -# WikiName -> WikiName -# not_wiki_name -> [[not_wiki_name]] -sub armor_name { - my ($name) = @_; - #if ($name =~ /^$wiki_name$/) { - # return $name; - #} else { - return "[[$name]]"; - #} -} - -# unarmor_name: -# [[bracket_name]] -> bracket_name -# WikiName -> WikiName -sub unarmor_name { - my ($name) = @_; - if ($name =~ /^$bracket_name$/) { - return $1; - } else { - return $name; - } -} - -sub is_bracket_name { - my ($name) = @_; - if ($name =~ /^$bracket_name$/) { - return 1; - } else { - return 0; - } + $page =~ /[\x00-\x20\x7F]/ ? 0 : 1; } sub decode { @@ -1171,49 +747,13 @@ } 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 () { - chomp; - 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('', ); - &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; + my $s = shift; + $s =~ s/([^0-9A-Za-z_-])/sprintf '%%%02X', ord $1/ge; + $s; } 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); + my ($sec, $min, $hour, $day, $mon, $year) = localtime(time); $year += 1900; $mon++; $mon = "0$mon" if $mon < 10; @@ -1221,63 +761,21 @@ $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"; + return "$year-$mon-$day $hour:$min"; } -# [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]] sub init_InterWikiName { - my $content = $database{$InterWikiName}; - while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) { - my ($name, $url) = ($1, $2); - $interwiki{$name} = $url; - } -} - -sub interwiki_convert { - my ($type, $localname) = @_; - if ($type eq 'sjis' or $type eq 'euc') { - &code_convert(\$localname, $type); - return &encode($localname); - } elsif ($type eq 'ykwk') { - # for YukiWiki1 - if ($localname =~ /^$wiki_name$/) { - return $localname; - } else { - &code_convert(\$localname, 'sjis'); - return &encode("[[" . $localname . "]]"); - } - } elsif ($type eq 'asis') { - return $localname; - # Walrus add (4) start - } elsif ($type eq 'isbn') { - $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/); - return $localname; - # Walrus add (4) end - } else { - return $localname; - } -} - -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"; + my @content = split /\n/, $database{InterWikiName}; + for (@content) { + if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { + $interwiki{$1} = $2; } - $infobase{$page} = $s; + } + $interwiki{'[[]]'} = 1; ## dummy } sub frozen_reject { - my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); + my ($isfrozen) = $database->meta (IsFrozen => $form{mypage}); my ($willbefrozen) = $form{myfrozen}; if (not $isfrozen and not $willbefrozen) { # You need no check. @@ -1286,50 +784,32 @@ # 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; + &_do_view_msg (-view => '-error', -page => $form{mypage}, + error_message => &Resource ('Error:PasswordIsIncorrect')); + exit; } } -sub is_frozen { - my ($page) = @_; - if (&get_info($page, $info_IsFrozen)) { - return 1; - } else { - return 0; - } -} +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. + my $default_name; ## this code is not strict. $default_name = $1 if $content =~ /default-name="([^"]+)"/; my $datestr = '[WEAK['.&get_now.']]'; - my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; + 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 = 0; - $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; - $anchor++; + my $anchor = &get_new_anchor_index ($content); my $i = 1; my $o = 0; - $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ + $content =~ s{(\[\[\#r?comment\]\])}{ my $embed = $1; if ($i == $form{comment_index}) { - if ($embed eq $embed_comment) { + if ($embed ne '[[#rcomment]]') { $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; } else { $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; @@ -1347,68 +827,69 @@ $form{mymsg} = $content; $form{mytouch} = 'on'; &do_write; - } else { - $form{mycmd} = 'read'; - &do_read; + } else { ## Don't write + $form{mycmd} = 'default'; + &do_view; } } +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) { + if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') { unless ($main::_EMBEDED) { - my $lastmodified = &get_info($form{mypage}, $info_LastModified); + my $lastmodified = $database->mtime ($form{mypage}); return <<"EOD";

    - - - - - - $embed_comment_Name_Prompt - - - + + + + + + @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} + + +

    EOD } else { return <<"EOD";
    - - - $embed_comment_Name_Prompt - - - + + + @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} + +
    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)!) { + my ($cf, $content) = SuikaWiki::Plugin->magic_and_conten ($database{$name}); + $cf ||= '#?SuikaWiki/0.9'; + if ($cf =~ m!^#\?SuikaWiki/0.9(?:$|\s)!) { $main::_EMBEDED = 1; - $r = &text_to_html ($content, content_format => $cf); + $r = &text_to_html ($content, magic => $cf, page => $name); $main::_EMBEDED = 0; } elsif (length $content) { $r = "
    @{[&escape ($content)]}
    "; } else { - $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9'); + $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", magic => '#?SuikaWiki/0.9'); } } else { ## nested #EMBED - $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); + $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", magic => '#?SuikaWiki/0.9'); } - return qq(
    $r
    ); + return qq(
    $r
    ); } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { return qq($1); } else { @@ -1416,185 +897,100 @@ } } -# 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; +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); + } + } } } -# 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}) ? < - - - - $intername: - - - -EOD +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 {depth=>10}, '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 (keys %{$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 { ## Don't write! + $form{mycmd} = 'default'; + &do_view; + } } -# Walrus add (5) end sub code_convert { + require Jcode; my ($contentref, $code) = (shift, shift || $kanjicode); -# &Jcode::convert($contentref, $code); # for Jcode.pm - &jcode::convert($contentref, $code); # for jcode.pl + if ($code =~ /euc/) { $code = 'euc' } + elsif ($code =~ /iso/) { $code = 'jis' } + elsif ($code =~ /shi/) { $code = 'sjis' } + elsif ($code =~ /utf/) { $code = 'utf8' } + $$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 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 _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 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(

    $resource{difftitle}

    ); - print qq($resource{diffnotice}); - print qq(
    );
    -    foreach (split(/\n/, $_)) {
    -        if (/^\+(.*)/) {
    -            print qq($1\n);
    -        } elsif (/^\-(.*)/) {
    -            print qq($1\n);
    -        } elsif (/^\=(.*)/) {
    -            print qq($1\n);
    -        } else {
    -            print qq|??? $_\n|;
    -        }
    -    }
    -    print qq(
    ); - print qq(
    ); - &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 <<"EOD" -Content-type: text/xml - -@{[$rss->as_string]} -EOD -} - -sub is_exist_page { - my ($name) = @_; - if ($use_exists) { - return exists($database{$name}); - } else { - return $database{$name}; - } +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}; } -sub __get_database ($) { $database{ $_[0] } } - package wiki::referer; sub add ($$) { my $page = shift; @@ -1615,23 +1011,20 @@ $list{ $uri }++; set ($page, \%list); } -sub get ($) { - my $page = shift; - split /"/, main::get_info ($page, 'Referer'); -} +sub get ($) { split /"/, $main::database->meta (Referer => $_[0]) } sub set ($%) { my $page = shift; my $list = shift; - main::set_info ($page, Referer => join '"', %$list); + $main::database->meta (Referer => $page => join '"', %$list); } sub get_dont_record () { map {s/\$/\\\$/g; s/\@/\\\@/g; $_} grep !/^#/, - split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); + split /[\x0D\x0A]+/, $main::database{RefererDontRecord}; } sub get_site_name () { - my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); + my @lines = grep /[^#]/, split /[\x0D\x0A]+/, $main::database{RefererSiteName}; my @item; for (@lines) { next if /^#/; @@ -1660,7 +1053,7 @@ } my $euri = main::escape ($uri); if ($title) { - $r .= qq(
  • [$list{$uri}] @{[main::escape ($title)]}
  • \n); + $r .= qq(
  • [$list{$uri}] @{[main::escape ($title)]}
  • \n); } else { $r .= qq(
  • [$list{$uri}] <$euri>
  • \n); } @@ -1675,29 +1068,177 @@ 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::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) { + next if $line =~ /^#/; + $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, %List, %Index, %Cache); + push @main::INC, $plugin_directory.'/../..'; + +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 user_agent_names ($) { $main::UA } +sub magic_and_content ($$) { + my ($magic, $page) = ('', $_[1]); + $magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; + ($magic, $page); +} +sub formatter ($$) { + &main::load_formatter ($_[1]); + $main::fmt{$_[1]}; +} +sub format_converter ($$$) { + &main::load_formatter ('format'); + $main::fmt{format}->{($_[1]=~/([A-Za-z0-9]\S+)/?$1:'SuikaWiki/0.9').'_to_'.$_[2]} + || $main::fmt{format}->{($_[1]=~/([A-Za-z0-9](?:(?!\/)\S)+)/?$1:'SuikaWiki').'_to_'.$_[2]}; +} +sub cache ($$) { + my $name = $_[1]; + unless (ref $Cache{$name}) { + my %cache; + tie (%cache, 'Yuki::YukiWikiCache', -file => $main::PathTo{CachePrefix}.$name); + $Cache{$name} = \%cache; + } + $Cache{$name}; +} + +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; + +## BUG: this parser isn't strict. +sub get_accept_lang (;$) { + my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE}; + my %alang = (ja => 0.0002, en => 0.0001); + if ($UA =~ m#Mozilla/0\.#) { + $alang{ja} = 0.00001; + } + 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; +} + +package wiki::resource; + +sub get ($;\%) { + my ($resname, $option) = @_; + $option->{accept_language} ||= &wiki::conneg::get_accept_lang (); + $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::database{'WikiResource:'.$lang}); + $v = $option->{resource}->{$lang}->{$resname}; + last if defined $v; + } + $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//; + } + last if defined $v; + } + defined $v ? $v : $resname; +} + +package main; +&main; +exit 0; + 1; __END__ =head1 NAME -wiki.cgi - This is YukiWiki, yet another Wiki clone. +wiki.cgi --- SuikaWiki: Yet yet another WikiEngine -=head1 DESCRIPTION +=head1 SEE ALSO -YukiWiki is yet another Wiki clone. + -YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]). -YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS), -and some embedded commands (such as [[#comment]] to add comments). +=head1 AUTHORS -Read F (English) or F (Japanese) in more detail. +Hiroshi Yuki -=head1 AUTHOR +Makio Tsukamoto -Hiroshi Yuki http://www.hyuki.com/yukiwiki/ +Wakaba =head1 LICENSE -Copyright (C) 2000-2002 by Hiroshi Yuki. +Copyright (C) 2000-2003 AUTHORS This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.