#!/usr/bin/perl # # wiki.cgi - This is YukiWiki, yet another Wiki clone. # # Copyright (C) 2000-2004 by Hiroshi Yuki. # # http://www.hyuki.com/yukiwiki/ # # 徒委記用wiki.cgi # 最終更新: 2007-06-14T09:45:00+09:00 # 無保証です。 # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # ############################## # Libraries. BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File); } use strict; use lib qw(../wiki); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Yuki::RSS; use Yuki::DiffText qw(difftext); #use Yuki::YukiWikiDB; use Yuki::PluginManager; #require 'jcode.pl'; use Jcode; use Fcntl; # Check if the server can use 'AnyDBM_File' or not. eval 'use AnyDBM_File'; my $error_AnyDBM_File = $@; my $version = '2.1.2'; ############################## # # You MUST modify following '$modifier_...' variables. # my $modifier_mail = 'kits@akatsukinishisu.net'; my $modifier_url = 'http://www.akatsukinishisu.net/'; my $modifier_name = '北村曉'; my $modifier_sitename = '徒委記'; my $modifier_dir_data = '../wiki'; # Your data directory (not URL, but DIRECTORY). my $modifier_url_data = 'http://www.akatsukinishisu.net'; # Your data URL (not DIRECTORY, but URL). my $modifier_rss_title = "徒委記"; my $modifier_rss_link = 'http://www.akatsukinishisu.net/wiki.cgi'; my $modifier_rss_description = '徒に記すことを委ねているところです。いわゆるWikiです。'; my $modifier_rss_timezone = '+09:00'; ############################## # # You MAY modify following variables. # my $modifier_dbtype = 'AnyDBM_File'; #my $modifier_sendmail = ''; my $modifier_sendmail = '/usr/sbin/sendmail -t'; my $modifier_dir_plugin = "$modifier_dir_data/plugin"; ############################## # # 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 = 'wiki.cgi'; my $url_stylesheet = "$modifier_url_data/style/sb-wiki.css"; my $url_stylesheet2 = "$modifier_url_data/style/yukiwiki.css"; my $url_csschangejs = "$modifier_url_data/style/csskks.js"; my $icontag = qq(*); my $maxrecent = 50; my $cols = 64; my $rows = 20; ############################## # # You MAY 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 $use_FixedFrontPage = 1; ############################## my $InterWikiName = 'InterWikiName'; my $RecentChanges = 'RecentChanges'; my $AdminChangePassword = 'AdminChangePassword'; my $CompletedSuccessfully = 'CompletedSuccessfully'; my $FrontPage = 'FrontPage'; my $IndexPage = 'IndexPage'; my $SearchPage = 'SearchPage'; my $CreatePage = 'CreatePage'; my $ErrorPage = 'ErrorPage'; my $RssFeed = 'RssFeed'; my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. ############################## my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b'; my $bracket_name = '\[\[(\S+?)\]\]'; my $embedded_name = '\[\[(#\S+?)\]\]'; my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]'; my $interwiki_name = '([^:]+):([^:].*)'; # Sorry for wierd regex. my $inline_plugin = '\&(\w+)\((([^()]*(\([^()]*\))?)*)\)'; ############################## my $embed_comment = '[[#comment]]'; my $embed_rcomment = '[[#rcomment]]'; ############################## my $info_ConflictChecker = 'ConflictChecker'; 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, $RssFeed => 1, $RecentChanges => 1, $SearchPage => 1, $AdminChangePassword => 1, $CompletedSuccessfully => 1, $FrontPage => $use_FixedFrontPage, ); my %form; my %database; my %infobase; my %diffbase; my %resource; my %interwiki; my $plugin_manager; my $plugin_context = { debug => 0, database => \%database, infobase => \%infobase, resource => \%resource, form => \%form, interwiki => \%interwiki, url_cgi => $url_cgi, }; ############################## my %page_command = ( $IndexPage => 'index', $SearchPage => 'searchform', $CreatePage => 'create', $RssFeed => 'rss', $AdminChangePassword => 'adminchangepasswordform', $FrontPage => 'FrontPage', ); my %command_do = ( read => \&do_read, edit => \&do_edit, adminedit => \&do_adminedit, adminchangepasswordform => \&do_adminchangepasswordform, adminchangepassword => \&do_adminchangepassword, write => \&do_write, index => \&do_index, searchform => \&do_searchform, search => \&do_search, create => \&do_create, createresult => \&do_createresult, FrontPage => \&do_FrontPage, comment => \&do_comment, rss => \&do_rss, diff => \&do_diff, ); ############################## # &test_convert; &main; exit(0); ############################## sub main { &init_resource; # &check_modifiers; &open_db; &init_form; &init_InterWikiName; &init_plugin; if ($command_do{$form{mycmd}}) { &{$command_do{$form{mycmd}}}; } else { &do_FrontPage; } &close_db; } sub do_read { &print_header($form{mypage}); &print_content($database{$form{mypage}}); &print_footer($form{mypage}); } sub do_edit { my ($page) = &unarmor_name(&armor_name($form{mypage})); &print_header($page); 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_ConflictChecker), admin=>0); } &print_footer($page); } sub do_adminedit { my ($page) = &unarmor_name(&armor_name($form{mypage})); &print_header($page); if (not &is_editable($page)) { &print_message($resource{cantchange}); } else { &print_message($resource{passwordneeded}); &print_editform($database{$page}, &get_info($page, $info_ConflictChecker), admin=>1); } &print_footer($page); } sub do_adminchangepasswordform { &print_header($AdminChangePassword); &print_passwordform; &print_footer($AdminChangePassword); } sub do_adminchangepassword { if ($form{mynewpassword} ne $form{mynewpassword2}) { &print_error($resource{passwordmismatcherror}); } my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); if ($validpassword_crypt) { if (not &valid_password($form{myoldpassword})) { &send_mail_to_admin(<<"EOD", "AdminChangePassword"); myoldpassword=$form{myoldpassword} mynewpassword=$form{mynewpassword} mynewpassword2=$form{mynewpassword2} EOD &print_error($resource{passworderror}); } } my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z'); my $salt1 = $token[(time | $$) % scalar(@token)]; my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); &set_info($AdminSpecialPage, $info_AdminPassword, $crypted); &print_header($CompletedSuccessfully); &print_message($resource{passwordchanged}); &print_footer($CompletedSuccessfully); } sub do_index { &print_header($IndexPage); print qq(); &print_footer($IndexPage); } sub do_write { if (&frozen_reject()) { return; } if (not &is_editable($form{mypage})) { &print_header($form{mypage}); &print_message($resource{cantchange}); &print_footer($form{mypage}); return; } if (&conflict($form{mypage}, $form{mymsg})) { return; } # Making diff if (1) { &open_diff; my @msg1 = split(/\r?\n/, $database{$form{mypage}}); my @msg2 = split(/\r?\n/, $form{mymsg}); $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); &close_diff; } if ($form{mymsg}) { $database{$form{mypage}} = $form{mymsg}; &send_mail_to_admin($form{mypage}, "Modify"); &set_info($form{mypage}, $info_ConflictChecker, '' . localtime); if ($form{mytouch}) { &set_info($form{mypage}, $info_LastModified, '' . localtime); &update_recent_changes; } &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); &print_header($CompletedSuccessfully); &print_message($resource{saved}); &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); &print_footer($CompletedSuccessfully); } else { &send_mail_to_admin($form{mypage}, "Delete"); delete $database{$form{mypage}}; delete $infobase{$form{mypage}}; if ($form{mytouch}) { &update_recent_changes; } &print_header($form{mypage}); &print_message($resource{deleted}); &print_footer($form{mypage}); } } sub do_searchform { &print_header($SearchPage); &print_searchform(""); &print_footer($SearchPage); } sub do_search { my $word = &escape($form{mymsg}); &print_header($SearchPage); &print_searchform($word); my $counter = 0; foreach my $page (sort keys %database) { next if $page =~ /^$RecentChanges$/; if ($database{$page} =~ /\Q$form{mymsg}\E/ or $page =~ /\Q$form{mymsg}\E/) { if ($counter == 0) { print qq||; } &print_footer($SearchPage); } sub do_create { &print_header($CreatePage); print <<"EOD";

$resource{newpagename}

EOD &print_footer($CreatePage); } sub do_FrontPage { if ($fixedpage{$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); } else { $form{mycmd} = 'read'; $form{mypage} = $FrontPage; &do_read; } } sub print_error { my ($msg) = @_; &print_header($ErrorPage); print qq(

$msg

); &print_plugin_log; &print_footer($ErrorPage); exit(0); } sub print_header { my ($page) = @_; my $bodyclass = "normal"; my $editable = 0; my $admineditable = 0; if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { $editable = 0; $admineditable = 1; $bodyclass = "frozen"; } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { $admineditable = 1; $editable = 1; } else { $editable = 0; } my $cookedpage = &encode($page); my $escapedpage = &escape($page); print <<"EOD"; Content-type: text/html; charset=$charset @{[ ($page eq 'FrontPage') ? $modifier_sitename : "$escapedpage - $modifier_sitename" ]}

@{[ ($page eq 'FrontPage') ? "$modifier_sitename (FrontPage)" : qq{$escapedpage} ]}

EOD } sub print_footer { my ($page) = @_; print <<"EOD";
EOD } sub escape { my $s = shift; $s =~ s|\x0d\x0a|\n|g; $s =~ s|&|&|g; $s =~ s|<|<|g; $s =~ s|>|>|g; $s =~ s|"|"|g; return $s; } # 数値文字参照となる文字列以外をエスケープ sub escape_without_charref { my $arg = shift; $arg =~ s/&(?!\# # 部分マッチの後方参照は必要ないため、 # (a|b)ではなく(?:a|b)を使用 (?: # 十進 0*(?: 9|1[03]|3[2-9]|[4-9][0-9] |1(?:[016-9]\d|2[0-6])|[2-9]\d\d |\d\d\d\d(?:\d\d)? |[1-47-9]\d\d\d\d |5(?:[0-489]\d\d\d |5(?:[01]\d\d |2(?:[0-8]\d |9[0-5])) |7(?:3(?:4[4-9] |[5-9]\d) |[4-9]\d\d)) |6(?:[0-46-9]\d\d\d |5(?:[0-46-9]\d\d |5(?:[0-24-9]\d |3[0-36-9]))) |1(?:0\d\d\d\d\d |1(?:0\d\d\d\d |1(?:[0-3]\d\d\d |4(?:0\d\d |1(?:0\d |1[01]))))) ) | # 十六進 x0*(?: [9ADad]|[2-6A-Fa-f][\dA-Fa-f]|7[\dA-Ea-e] |[\dA-Fa-f]{3}(?:[\dA-Fa-f]{2})? |(?:[\dA-Ca-c][\dA-Fa-f] |[Dd][0-7] |[Ee][\dA-Fa-f] |[Ff][\dA-Ea-e])[\dA-Fa-f][\dA-Fa-f] |[Ff]{2}(?:[\dA-Ea-e][\dA-Fa-f] |[Ff][\dA-Da-d]) |10[\dA-Fa-f]{4} ) ) ;)/&/gx; $arg =~ s//>/g; $arg =~ s/"/"/g; return $arg; } sub unescape { my $s = shift; $s =~ s|&|&|g; $s =~ s|<|<|g; $s =~ s|>|>|g; $s =~ s|"|"|g; return $s; } sub print_content { my ($rawcontent) = @_; print &text_to_html($rawcontent, toc=>1); } ################################ ここからHTML変換部分 sub text_to_html { my ($arg, %option) = @_; my $text = ''; my $in_verbatim_hard = 0; $arg =~ s/\x0D\x0A/\n/g; $arg =~ tr/\x0D\x0A/\n\n/; foreach my $line (split(/\n/, $arg)) { $in_verbatim_hard = 1 if ($line =~ /^---\($/); $in_verbatim_hard = 0 if ($line =~ /^---\)$/); if ($in_verbatim_hard) { $text .= &escape($line); } elsif ($line =~ /^(>{1,3})(.*)/) { $text .= $1 . &inline($2); } else { $text .= &inline($line); } $text .= "\n"; } undef $arg; # 以後使わないので消去 # ブロック要素変換 &verbatim(\$text); # 最初に処理 &horizontal_rule(\$text); # リストの前に処理 &headding(\$text); "ation(\$text); # 他のブロック要素の前に処理 &unordered_list(\$text); &difinition(\$text); &make_table(\$text); &preformat(\$text); &block_plugin(\$text); ¶graph(\$text); # 最後から2番目に処理 &line_break(\$text); # 最後に処理 # 目次追加 &insert_toc(\$text) if ($option{toc}); return $text; } # verbatim機能 sub verbatim { my $ref = shift; ${$ref} =~ s{^(---?)\(\n(.+?)\n\1\)$}{ q{
}
        . join('', split(/\n/, $2))
        . '
' }emsg; } # 水平線 sub horizontal_rule { my $ref = shift; ${$ref} =~ s{^----}{
\n}mg; } # 見出し sub headding { my $ref = shift; ${$ref} =~ s{^\*\*\*(.+)}{

$1

}mg; ${$ref} =~ s{^\*\*(.+)}{

$1

}mg; ${$ref} =~ s{^\*(.+)}{

$1

}mg; } # 引用 sub quotation { my $ref = shift; ## 3段 ${$ref} =~ s{^>>>(.*)}{
$1
}mg; ${$ref} =~ s{\n
}{}g; ${$ref} =~ s{^(>.*)\n
}{$1
}mg; ## 2段 ${$ref} =~ s{^>>(.*)}{
$1
}mg; ${$ref} =~ s{
\n
}{}g; ${$ref} =~ s{^(>.*)\n
}{$1
}mg; ## 1段 ${$ref} =~ s{^>(.*)}{
$1
}mg; ${$ref} =~ s{
\n
}{}g; # 引用文中に他のブロック要素を含めるための処理 ${$ref} =~ s{()(.)}{$1\n$2}g; ${$ref} =~ s{(.)()}{$1\n$2}g; ${$ref} =~ s{}{\n}g; } # 順不同リスト sub unordered_list { my $ref = shift; ## 3段 ${$ref} =~ s{^---(.*)}{
  • $1
}mg; ${$ref} =~ s{\n
    }{}g; ${$ref} =~ s{^-(.*)\n
      }{-$1
        }mg; ## 2段 ${$ref} =~ s{^--(.*)}{
        • $1
        }mg; ${$ref} =~ s{
      \n
        }{}g; ${$ref} =~ s{^-(.*)\n
          }{-$1
            }mg; ## 1段 ${$ref} =~ s{^-(.*)}{
              \n
            • $1
            • \n
            }mg; ${$ref} =~ s{
          \n
            \n}{}g; } # 定義 sub difinition { my $ref = shift; ${$ref} =~ s{^:([^:]+):(.+)}{
            $1
            $2
            }mg; ${$ref} =~ s{\n
            }{\n}g; } # 表 sub make_table { my $ref = shift; ${$ref} =~ s{^,(.+)}{ "\n\n
            " . join('', split(/,/, $1)) . "
            " }emg; ${$ref} =~ s{\n\n}{}g; ${$ref} =~ s{}{}g; } # 整形済みテキスト sub preformat { my $ref = shift; ${$ref} =~ s{^ (.+)}{
             $1
            }mg; ${$ref} =~ s{\n
            }{}g;
            }
            
            # ブロック型プラグイン
            sub block_plugin {
                my $ref = shift;
                ${$ref} =~ s{^#(\w+)(\((.*)\))?}{
                    my $original = "#$1$2";
                    my $plugin_name = $1;
                    my $argument = &escape($3);
                    my $result = $plugin_manager->call($plugin_name, 'block', $argument);
                    (defined($result)) ? $result : $original;
                }emg;
            }
            
            # 段落
            sub paragraph {
                my $ref = shift;
                # 行頭がインライン要素タグ
                ${$ref} =~ s{^(<(?:[ib]|em|strong)>.*)}{

            $1

            }mg; ${$ref} =~ s{^(<(?:a |span).*)}{

            $1

            }mg; # 行頭が"<"と改行以外 ${$ref} =~ s{^([^<\n].*)}{

            $1

            }mg; ${$ref} =~ s{

            \n

            }{}g; } # 改行の後処理 sub line_break { my $ref = shift; ${$ref} =~ s{}{\n}g; } # 目次追加 sub insert_toc { my $ref = shift; my $toc = ''; my $count = 0; while (${$ref} =~ s{^(?! )(.+?)$}{ $2}m) { $toc .= '-' x ($1 - 1); $toc .= qq{} . remove_tag($2) . qq{\n}; $count++; } &unordered_list(\$toc); $toc =~ s/

              /
                /; ${$ref} = $toc . ${$ref}; } ################################ HTML変換部分ここまで sub remove_tag { my ($line) = @_; $line =~ s{]*>}{}g; return $line; } sub inline { my ($line) = @_; $line = &escape_without_charref($line); $line =~ s|'''([^']+?)'''|$1|g; # Italic $line =~ s|''([^']+?)''|$1|g; # Bold $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|$1|g; # Date $line =~ s! ( ((mailto|http|https|ftp):([^\x00-\x20()<>\x7F-\xFF])*) # Direct http://... | ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]] | ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]] | ($wiki_name) # LocalLinkLikeThis | ($inline_plugin) # &user_defined_plugin(123,hello) ) ! &make_link($1) !gex; return $line; } sub make_link { my $chunk = shift; if ($chunk =~ /^(http|https|ftp):/) { if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) { return qq(*); } else { if (length($chunk) > 80) { my $shorten = substr($chunk, 0, 76) . " ..."; return qq($shorten); } else { return qq($chunk); } } } elsif ($chunk =~ /^(mailto):(.*)/) { return qq($2); } elsif ($chunk =~ /^$interwiki_definition$/) { return qq($chunk); } elsif ($chunk =~ /^$embedded_name$/) { return &embedded_to_html($chunk); } elsif ($chunk =~ /^$inline_plugin$/) { # InlinePlugin. my $plugin_name = $1; my $argument = $2; my $result = $plugin_manager->call($plugin_name, 'inline', $argument); if (defined($result)) { return $result; } else { return $chunk; } } else { $chunk = &unarmor_name($chunk); $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. my $cookedchunk = &encode($chunk); my $escapedchunk = &escape($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; return qq($escapedchunk); } else { return $escapedchunk; } } elsif ($database{$chunk}) { my $subject = &escape(&get_subjectline($chunk, delimiter => '')); return qq($escapedchunk); } elsif ($chunk eq $FrontPage) { return qq($escapedchunk); } elsif ($page_command{$chunk}) { return qq($escapedchunk); } else { #return qq($escapedchunk$editchar); return $escapedchunk; } } } sub print_message { my ($msg) = @_; print qq(

                $msg

                ); } sub init_form { if (param()) { foreach my $var (param()) { $form{$var} = param($var); } } else { $ENV{QUERY_STRING} = $FrontPage; } my $query = &decode($ENV{QUERY_STRING}); if ($page_command{$query}) { $form{mycmd} = $page_command{$query}; $form{mypage} = $query; } elsif ($query =~ /^($wiki_name)$/) { $form{mycmd} = 'read'; $form{mypage} = $1; } elsif ($database{$query}) { $form{mycmd} = 'read'; $form{mypage} = $query; } # 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. # $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); $form{myname} = &code_convert(\$form{myname}, $kanjicode); } sub update_recent_changes { my $update = "- @{[&get_now]} @{[&armor_name($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:\d\d (\S+)/; # date format. my $name = &unarmor_name($1); if (&is_exist_page($name) and ($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 ""; } 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/\r?\n.*//s; return "$delim$subject"; } } sub send_mail_to_admin { my ($page, $mode) = @_; my $subject = jcode($page)->mime_encode; return unless $modifier_sendmail; my $message = <<"EOD"; To: $modifier_mail From: $modifier_mail Subject: [Wiki] $subject 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 $modifier_rss_link?@{[&encode($page)]} -------- $database{$page} -------- EOD &code_convert(\$message, 'jis'); open(MAIL, "| $modifier_sendmail"); print MAIL $message; close(MAIL); } sub open_db { if ($modifier_dbtype eq 'dbmopen') { dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname"); dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname"); } elsif ($modifier_dbtype eq 'AnyDBM_File') { tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname"); tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname"); } else { tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname"); tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname"); } } sub close_db { if ($modifier_dbtype eq 'dbmopen') { dbmclose(%database); dbmclose(%infobase); } elsif ($modifier_dbtype eq 'AnyDBM_File') { untie(%database); untie(%infobase); } else { untie(%database); untie(%infobase); } } sub open_diff { if ($modifier_dbtype eq 'dbmopen') { dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname"); } elsif ($modifier_dbtype eq 'AnyDBM_File') { tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname"); } else { tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname"); } } sub close_diff { if ($modifier_dbtype eq 'dbmopen') { dbmclose(%diffbase); } elsif ($modifier_dbtype eq 'AnyDBM_File') { untie(%diffbase); } else { untie(%diffbase); } } sub print_searchform { my ($word) = @_; print <<"EOD";

                EOD } sub print_editform { my ($mymsg, $conflictchecker, %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); } my $edit = $mode{admin} ? 'adminedit' : 'edit'; my $escapedmypage = &escape($form{mypage}); my $escapedmypassword = &escape($form{mypassword}); print <<"EOD";

                @{[ $mode{admin} ? qq($resource{frozenpassword}
                ) : "" ]}
                @{[ $mode{admin} ? qq( $resource{frozenbutton} $resource{notfrozenbutton}
                ) : "" ]} @{[ $mode{conflict} ? "" : qq( $resource{touch}
                ) ]}

                EOD unless ($mode{conflict}) { # Show the format rule. 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); } unless ($mode{conflict}) { # Show plugin information. my $plugin_usage = <<"EOD"; *$resource{available_plugins} EOD foreach my $usage (@{$plugin_manager->usage}) { $plugin_usage .= <<"EOD"; ** $usage->{name} ---( $resource{plugin_usage_name}: $usage->{name} $resource{plugin_usage_version}: $usage->{version} $resource{plugin_usage_author}: $usage->{author} $resource{plugin_usage_syntax}: $usage->{syntax} $resource{plugin_usage_description}: $usage->{description} $resource{plugin_usage_example}: $usage->{example} ---) EOD } &code_convert(\$plugin_usage, $kanjicode); print &text_to_html($plugin_usage, toc=>0); } } sub print_passwordform { print <<"EOD";

                $resource{oldpassword}
                $resource{newpassword}
                $resource{newpassword2}

                EOD } 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; } elsif (not $page) { 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; } } sub decode { my ($s) = @_; $s =~ tr/+/ /; $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; return $s; } # Thanks to WalWiki for [better encode]. sub encode { my ($encoded) = @_; $encoded =~ s/(\W)/'%' . uc(unpack('H2', $1))/eg; 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{myConflictChecker} eq &get_info($page, $info_ConflictChecker)) { return 0; } open(FILE, $file_conflict) or &print_error("(conflict)"); my $content = join('', ); &code_convert(\$content, $kanjicode); close(FILE); &print_header($page); &print_content($content); &print_editform($rawmsg, $form{myConflictChecker}, frozen=>0, conflict=>1); &print_footer($page); return 1; } sub get_now { my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); $year += 1900; $mon++; $mon = "0$mon" if $mon < 10; $day = "0$day" if $day < 10; $hour = "0$hour" if $hour < 10; $min = "0$min" if $min < 10; $sec = "0$sec" if $sec < 10; $weekday = $week[$weekday]; return "$year-$mon-$day ($weekday) $hour:$min:$sec"; } # [[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; } 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"; } $infobase{$page} = $s; } sub frozen_reject { my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); my ($willbefrozen) = $form{myfrozen}; if (not $isfrozen and not $willbefrozen) { # You need no check. return 0; } elsif (valid_password($form{mypassword})) { # You are admin. return 0; } else { &print_error($resource{passworderror}); return 1; } } sub valid_password { my ($givenpassword) = @_; my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) { return 1; } else { return 0; } } sub is_frozen { my ($page) = @_; if (&get_info($page, $info_IsFrozen)) { return 1; } else { return 0; } } sub do_comment { my ($content) = $database{$form{mypage}}; my $datestr = &get_now; my $namestr = $form{myname} ? " ''$form{myname}'' : " : " "; if ($content =~ s/(^|\n)(\Q$embed_comment\E)/$1- $datestr$namestr$form{mymsg}\n$2/) { ; } else { $content =~ s/(^|\n)(\Q$embed_rcomment\E)/$1$2\n- $datestr$namestr$form{mymsg}/; } if ($form{mymsg}) { $form{mymsg} = $content; $form{mytouch} = 'on'; &do_write; } else { $form{mycmd} = 'read'; &do_read; } } sub embedded_to_html { my ($embedded) = @_; my $escapedmypage = &escape($form{mypage}); if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { my $conflictchecker = &get_info($form{mypage}, $info_ConflictChecker); return <<"EOD"; \n

                EOD # 先頭に改行を入れているのは、 # 段落整形に巻き込まれないようにするため。 } else { return $embedded; } } sub code_convert { my ($contentref, $kanjicode) = @_; &Jcode::convert($contentref, $kanjicode); # for Jcode.pm # &jcode::convert($contentref, $kanjicode); # for jcode.pl return $$contentref; } sub test_convert { my $txt = &text_to_html(<<"EOD", toc=>1); *HEADER1 **HEADER1-1 -ITEM1 -ITEM2 -ITEM3 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 **HEADER1-2 :TERM1:DESCRIPTION1 AND ''BOLD'' PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 :TERM2:DESCRIPTION2 :TERM3:DESCRIPTION3 ---- *HEADER2 **HEADER2-1 http://www.hyuki.com/ **HEADER2-2 [[YukiWiki2]] PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0 >LEVEL1 >LEVEL1 >LEVEL1 >>LEVEL2 >>LEVEL2 >>LEVEL2 >>>LEVEL3 -HELLO-1 --HELLO-2 (HELLO-2, HELLO-2, HELLO-2) ---HELLO-3 (HELLO-3, HELLO-3, HELLO-3) --HELLO-2 ---HELLO-3 --HELLO-2 ---HELLO-3 >>>LEVEL3 >>>LEVEL3 >>>LEVEL3 >>>LEVEL3 EOD print $txt; exit; } sub do_diff { if (not &is_editable($form{mypage})) { &do_read; return; } &open_diff; my $title = $form{mypage}; &print_header($title); $_ = &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); } # Thanks to Makio Tsukamoto for dc_date. sub do_rss { my $rss = new Yuki::RSS( version => '1.0', encoding => 'UTF-8', ); $rss->channel( title => $modifier_rss_title, link => $modifier_rss_link, about => "$modifier_rss_link?RssFeed", 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 $dc_date = "$1T$2$modifier_rss_timezone"; my $title = &unarmor_name($3); my $escaped_title = &escape($title); my $link = $modifier_rss_link . '?' . &encode($title); # my $description = &escape(&get_subjectline($title)); # descriptionに差分情報を加える &open_diff; my $description .= $diffbase{$title}; &close_diff; $description =~ s/^[=-].*\n//mg; $description =~ s/^\+//mg; $description = &text_to_html($description, toc=>0); $description =~ s{<[^>]+>}{}g; $description =~ s/^\n//mg; $description = &escape(&round_euc($description)); $description ||= &escape(&get_subjectline($title)); $description =~ s/^$subject_delimiter//; $rss->add_item( title => $escaped_title, link => $link, description => $description, dc_date => $dc_date, ); $count++; } # print RSS information (as XML). print "Content-type: application/xml; charset=UTF-8\n\n"; print code_convert(\($rss->as_string), 'utf8'); } sub is_exist_page { my ($name) = @_; if ($use_exists) { return exists($database{$name}); } else { return $database{$name}; } } # sub check_modifiers { # if ($error_AnyDBM_File and $modifier_dbtype eq 'AnyDBM_File') { # &print_error($resource{anydbmfileerror}); # } # } # Initialize plugins. sub init_plugin { $plugin_manager = new Yuki::PluginManager($plugin_context, $modifier_dir_plugin); } sub print_plugin_log { if ($plugin_context->{debug}) { print "
                (print_plugin_log)\n", join("\n", @{$plugin_manager->{log}}), "
                "; } } sub round_euc { my $str = shift; return $str if (length($str) <= 512); $str = substr($str, 0, 509); $str =~ s/((?:^|[\x20-\x7E]|\x8E[\xA1-\xDF]|\x8F)(?:[\xA1-\xFE]{2})*)[\xA1-\xFE]$/$1/ or $str =~ s/[\x8E\x8F]$// or $str =~ s/\x8F[\xA1-\xFE]$//; "$str..."; } 1;
            \s+(.+?)\s*$1