1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
#!perl |
## wiki.cgi - This is SuikaWiki, yet another WikiEngine |
|
# |
|
|
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
|
|
# |
|
|
# Copyright (C) 2000-2002 by Hiroshi Yuki. |
|
|
# <hyuki@hyuki.com> |
|
|
# http://www.hyuki.com/yukiwiki/ |
|
|
# |
|
|
# This program is free software; you can redistribute it and/or |
|
|
# modify it under the same terms as Perl itself. |
|
|
# |
|
|
############################## |
|
|
# |
|
|
# walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
|
|
# |
|
|
# 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 |
|
3 |
|
|
|
# Libraries. |
|
4 |
use strict; |
use strict; |
5 |
use lib qw(./WalWiki/lib); |
use lib qw(./lib); |
|
use CGI qw(:standard); |
|
6 |
use CGI::Carp qw(fatalsToBrowser); |
use CGI::Carp qw(fatalsToBrowser); |
7 |
use Yuki::RSS; |
binmode STDOUT; binmode STDIN; |
8 |
use Yuki::DiffText qw(difftext); |
our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
9 |
use Yuki::YukiWikiDB; |
require 'wikidata/suikawiki-config.ph'; ## site configuration script |
10 |
use AnyDBM_File; |
require Yuki::YukiWikiCache; |
|
require 'jcode.pl'; |
|
|
# use Jcode; |
|
11 |
use Fcntl; |
use Fcntl; |
12 |
my $version = '2.0.beta1.2002-05-29'; |
our %fmt; ## formatter objects |
13 |
my $walversion; |
our %embed_command = ( |
|
############################## |
|
|
# |
|
|
# 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 = '<img src="/icons/folder" alt="*" width="40" height="40" />'; |
|
|
my $maxrecent = 50; |
|
|
my $cols = 80; |
|
|
my $rows = 20; |
|
|
############################## |
|
|
# |
|
|
# You MAY, but do NOT NEED modify following variables. |
|
|
# |
|
|
my $dataname = "$modifier_dir_data/wiki"; |
|
|
my $infoname = "$modifier_dir_data/info"; |
|
|
my $diffname = "$modifier_dir_data/diff"; |
|
|
my $editchar = '?'; |
|
|
my $subject_delimiter = ' - '; |
|
|
my $use_autoimg = 1; # automatically convert image URL into <img> tag. |
|
|
my $use_exists = 0; # If you can use 'exists' method for your DB. |
|
|
############################## |
|
|
my $InterWikiName = 'InterWikiName'; |
|
|
my $RecentChanges = 'RecentChanges'; |
|
|
my $AdminChangePassword = 'AdminChangePassword'; |
|
|
my $CompletedSuccessfully = 'CompletedSuccessfully'; |
|
|
my $FrontPage = 'HomePage'; |
|
|
my $IndexPage = 'IndexPage'; |
|
|
my $SearchPage = 'SearchPage'; |
|
|
my $CreatePage = 'CreatePage'; |
|
|
my $ErrorPage = 'ErrorPage'; |
|
|
my $RssPage = 'RssPage'; |
|
|
my $NAME_OF_WikiPageLicense = 'WikiPageLicense'; |
|
|
my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. |
|
|
############################## |
|
|
# my $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 = ( |
|
14 |
searched => '^\[\[#searched:([^\]]+)\]\]$', |
searched => '^\[\[#searched:([^\]]+)\]\]$', |
15 |
|
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
16 |
); |
); |
17 |
############################## |
our ($modifier_dbtype,$url_cgi,%uri,%PathTo); |
18 |
my $info_LastModified = 'LastModified'; |
our (%PageName,$kanjicode,$lang,%ViewDefinition); |
19 |
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, |
|
|
); |
|
20 |
my %form; |
my %form; |
21 |
my %database; |
our %database; |
22 |
my %infobase; |
our $database = bless {}, 'wiki::dummy'; |
|
my %diffbase; |
|
|
my %resource; |
|
23 |
my %interwiki; |
my %interwiki; |
|
############################## |
|
|
my %page_command = ( |
|
|
$IndexPage => 'index', |
|
|
$SearchPage => 'searchform', |
|
|
$CreatePage => 'create', |
|
|
$RssPage => 'rss', |
|
|
$AdminChangePassword => 'adminchangepasswordform', |
|
|
#$FrontPage => 'FrontPage', |
|
|
); |
|
24 |
my %command_do = ( |
my %command_do = ( |
25 |
read => \&do_read, |
default => \&do_view, |
|
TEXT_CSS => \&do_output_css, |
|
|
edit => \&do_edit, |
|
|
adminedit => \&do_adminedit, |
|
|
adminchangepasswordform => \&do_adminchangepasswordform, |
|
26 |
adminchangepassword => \&do_adminchangepassword, |
adminchangepassword => \&do_adminchangepassword, |
27 |
write => \&do_write, |
write => \&do_write, |
|
index => \&do_index, |
|
28 |
searchform => \&do_searchform, |
searchform => \&do_searchform, |
|
search => \&do_search, |
|
|
create => \&do_create, |
|
|
createresult => \&do_createresult, |
|
|
FrontPage => \&do_FrontPage, |
|
29 |
comment => \&do_comment, |
comment => \&do_comment, |
30 |
RandomJump => \&do_random_jump, |
RandomJump => \&do_random_jump, |
31 |
rss => \&do_rss, |
wikiform => \&do_wikiform, |
|
diff => \&do_diff, |
|
|
interwikibox => \&do_interwiki_box, # Walrus add (5) |
|
32 |
); |
); |
33 |
############################## |
our $UA = ''; ## User agent name |
34 |
my @ignore_html_page = ('FrontPage'); # Walrus add (6) |
$| = 1; |
|
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); |
|
|
############################## |
|
35 |
|
|
36 |
sub main { |
sub main { |
37 |
&init_resource; |
$UA = $main::ENV{HTTP_USER_AGENT}; |
38 |
&open_db; |
&open_db; |
39 |
&init_form; |
&init_form; |
|
&init_InterWikiName; |
|
40 |
if ($command_do{$form{mycmd}}) { |
if ($command_do{$form{mycmd}}) { |
41 |
&{$command_do{$form{mycmd}}}; |
&{$command_do{$form{mycmd}}}; |
42 |
} else { |
} else { |
43 |
&do_FrontPage; |
&{$command_do{default}}; |
44 |
} |
} |
45 |
&close_db; |
&close_db; |
46 |
} |
} |
47 |
|
|
48 |
sub do_read { |
sub do_view { |
49 |
my $content = $database{$form{mypage}}; |
my $content = $database{$form{mypage}}; |
50 |
my $lm = &get_info($form{mypage}, $info_LastModified); |
my $lm = $database->mtime ($form{mypage}); |
51 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
52 |
my ($r, $c) = get_search_result ($form{mypage}); |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
53 |
my $rl = wiki::referer::list_html ($form{mypage}); |
&load_formatter ('view'); |
54 |
my @toc; |
my $view = $form{mycmd}; |
55 |
push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c; |
if ($view eq 'edit') { |
56 |
push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl; |
$view = 'adminedit' if $form{admin}; |
57 |
my $cf = 'SuikaWiki/0.9'; |
} elsif ($view =~ /[^0-9A-Za-z]/) { |
58 |
## Should be support at least: |
$view = 'default' |
59 |
## - 'SuikaWiki/0.9' CRLF |
} |
60 |
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
if ($view eq 'default' || !$view) { |
61 |
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
## BUG: this code is not strict |
62 |
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
if ($main::ENV{HTTP_COOKIE} =~ /SelectedMode=([0-9A-Za-z]+)/) { |
63 |
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
$view = $1; |
64 |
&print_header ($form{mypage}, -last_modified => $lm, |
} else { |
65 |
-content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/); |
$view = 'read'; |
66 |
&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 "<pre>@{[&escape($content)]}</pre>"; |
|
|
} |
|
|
if ($c) { |
|
|
print q{<h2 id="wikipage-see-also">See also</h2>}; |
|
|
print $r; |
|
|
} |
|
|
if ($rl) { |
|
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
|
67 |
} |
} |
68 |
&print_footer($form{mypage}, $lm); |
my ($magic, $content) = &SuikaWiki::Plugin::magic_and_content (undef, $content); |
69 |
|
$magic ||= '#?SuikaWiki/0.9'; |
70 |
|
my $o = bless {param => \%form, page => $form{mypage}, toc => [], |
71 |
|
magic => $magic, content => $content, |
72 |
|
formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'; |
73 |
|
if (!ref $ViewDefinition{$view} || !&{$ViewDefinition{$view}->{check}} ($o)) { |
74 |
|
print "Status: 406 Unsupported Media Type\n"; |
75 |
|
$view = '-UnsupportedMediaType'; |
76 |
|
} |
77 |
|
my $media = $ViewDefinition{$view}->{media}; |
78 |
|
if ($ViewDefinition{$view}->{xmedia} && $UA =~ /Gecko/) { |
79 |
|
$media = $ViewDefinition{$view}->{xmedia}; |
80 |
|
$o->{media} = $media; |
81 |
|
} elsif ($UA =~ m#Mozilla/0\..+Windows#) { |
82 |
|
$kanjicode = 'shift_jis'; |
83 |
|
} |
84 |
|
if ($magic =~ m!^\#\?SuikaWiki/0.9!) { |
85 |
|
&print_header ($form{mypage}, -last_modified => ($magic =~ /interactive="yes"/ ? time : $lm), |
86 |
|
-expires => ($magic =~ /interactive="yes"/ ? 1 : undef), o => $o, |
87 |
|
-media => $media, -magic => $magic, content => $content); |
88 |
|
} else { |
89 |
|
&print_header($form{mypage}, -media => $media, |
90 |
|
-magic => $magic, -last_modified => $lm, o => $o); |
91 |
|
} |
92 |
|
if ($kanjicode ne 'euc') { |
93 |
|
my $s = $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o); |
94 |
|
print &code_convert (\$s => $kanjicode); |
95 |
|
} else { |
96 |
|
print $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o); |
97 |
|
} |
98 |
} |
} |
99 |
|
|
100 |
sub do_output_css { |
sub _do_view_msg (%) { |
101 |
my $content = $database{$form{mypage}}; |
my %option = @_; |
102 |
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
&load_formatter ('view'); |
103 |
my $lm = &get_info($form{mypage}, $info_LastModified); |
my $o = bless {param => \%form, page => $option{-page}, toc => [], condition => \%option, |
104 |
print "Content-Type: text/css; charset=$charset\n"; |
formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'; |
105 |
print "Last-Modified: $lm\n"; |
unless (&{$ViewDefinition{$option{-view}}->{check}} ($o)) { |
|
print "\n"; |
|
|
print $content; |
|
|
} else { |
|
106 |
print "Status: 406 Unsupported Media Type\n"; |
print "Status: 406 Unsupported Media Type\n"; |
107 |
&print_header('WikiPageIsNotCSS', -noindex => 1); |
$option{-view} = '-UnsupportedMediaType'; |
|
&print_content($database{WikiPageIsNotCSS}); |
|
|
&print_footer('WikiPageIsNotCSS'); |
|
108 |
} |
} |
109 |
|
my $media = $ViewDefinition{$option{-view}}->{media}; |
110 |
|
if ($ViewDefinition{$option{-view}}->{xmedia} && $UA =~ /Gecko/) { |
111 |
|
$media = $ViewDefinition{$option{-view}}->{xmedia}; |
112 |
|
$o->{media} = $media; |
113 |
|
} |
114 |
|
&print_header($option{-page}, -media => $media, o => $o, -goto => $option{-goto}); |
115 |
|
print $fmt{view}->replace ($ViewDefinition{$option{-view}}->{template} => $o); |
116 |
} |
} |
117 |
|
|
118 |
sub do_edit { |
sub id_and_name ($) { |
119 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
my $name = shift; |
120 |
&print_header($page, -noindex => 1); |
if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) { |
121 |
if (not &is_editable($page)) { |
qq{id="$name"><a name="$name"></a}; |
|
&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{<h2 id="wikipage-see-also">See also</h2>}; |
|
|
print $r; |
|
|
} |
|
|
if ($rl) { |
|
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer($page); |
|
|
} |
|
|
|
|
|
sub do_adminedit { |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
|
|
&print_header($page, -noindex => 1); |
|
|
if (not &is_editable($page)) { |
|
|
&print_message($resource{cantchange}); |
|
122 |
} else { |
} else { |
123 |
&print_message($resource{passwordneeded}); |
qq{id="$name"}; |
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1); |
|
124 |
} |
} |
|
&print_footer($page); |
|
|
} |
|
|
|
|
|
sub do_adminchangepasswordform { |
|
|
&print_header($AdminChangePassword, -noindex => 1); |
|
|
&print_passwordform; |
|
|
&print_footer($AdminChangePassword); |
|
125 |
} |
} |
126 |
|
|
127 |
sub do_adminchangepassword { |
sub do_adminchangepassword { |
128 |
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
129 |
&print_error($resource{passwordmismatcherror}); |
&_do_view_msg (-view => '-error', -page => $form{mypage}, |
130 |
|
error_message => &Resource ('Error:PasswordMismatch')); |
131 |
|
return; |
132 |
} |
} |
133 |
my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); |
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
134 |
if ($validpassword_crypt) { |
if ($validpassword_crypt) { |
135 |
if (not &valid_password($form{myoldpassword})) { |
if (not &valid_password($form{myoldpassword})) { |
136 |
&send_mail_to_admin(<<"EOD", "AdminChangePassword"); |
&_do_view_msg (-view => '-error', -page => $form{mypage}, |
137 |
myoldpassword=$form{myoldpassword} |
error_message => &Resource ('Error:PasswordIsIncorrect')); |
138 |
mynewpassword=$form{mynewpassword} |
return; |
|
mynewpassword2=$form{mynewpassword2} |
|
|
EOD |
|
|
&print_error($resource{passworderror}); |
|
139 |
} |
} |
140 |
} |
} |
141 |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
143 |
my $salt1 = $token[(time | $$) % scalar(@token)]; |
my $salt1 = $token[(time | $$) % scalar(@token)]; |
144 |
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
145 |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
146 |
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
$database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted); |
147 |
|
|
148 |
&print_header($CompletedSuccessfully, -noindex => 1); |
&_do_view_msg (-view => '-wrote', -page => $form{mypage}); |
|
&print_message($resource{passwordchanged}); |
|
|
&print_footer($CompletedSuccessfully); |
|
149 |
} |
} |
150 |
|
|
151 |
sub do_index { |
sub valid_password ($) { |
152 |
&print_header($IndexPage); |
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
153 |
print qq(<ul>); |
return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; |
|
foreach my $page (sort keys %database) { |
|
|
if (&is_editable($page)) { |
|
|
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
|
|
# print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>); |
|
|
# print qq(<li>@{[0 + &is_frozen($page)]}</li>); |
|
|
} |
|
|
} |
|
|
print qq(</ul>); |
|
|
&print_footer($IndexPage); |
|
154 |
} |
} |
155 |
|
|
156 |
sub do_write { |
sub do_write { |
159 |
} |
} |
160 |
|
|
161 |
if (not &is_editable($form{mypage})) { |
if (not &is_editable($form{mypage})) { |
162 |
&print_header($form{mypage}, -noindex => 1); |
&_do_view_msg (-view => '-error', -page => $form{mypage}, |
163 |
&print_message($resource{cantchange}); |
error_message => &Resource ('Error:ThisPageIsUneditable')); |
|
&print_footer($form{mypage}); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (&conflict($form{mypage}, $form{mymsg})) { |
|
164 |
return; |
return; |
165 |
} |
} |
166 |
|
|
167 |
# Making diff |
## Check confliction |
168 |
{ |
if ($form{myLastModified} ne $database->mtime ($form{mypage})) { |
169 |
&open_diff; |
&_do_view_msg (-view => '-conflict', -page => $form{mypage}); |
170 |
my @msg1 = split(/\n/, $database{$form{mypage}}); |
return; |
|
my @msg2 = split(/\n/, $form{mymsg}); |
|
|
$diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); |
|
|
&close_diff; |
|
171 |
} |
} |
172 |
|
|
173 |
if ($form{mymsg}) { |
if ($form{mymsg}) { |
174 |
$database{$form{mypage}} = $form{mymsg}; |
if ($form{mytouch} || !ref $database) { |
175 |
&send_mail_to_admin($form{mypage}, "Modify"); |
$database{$form{mypage}} = $form{mymsg}; |
176 |
if ($form{mytouch}) { |
} else { |
177 |
&set_info($form{mypage}, $info_LastModified, '' . localtime); |
$database->STORE ($form{mypage} => $form{mymsg}, -touch => 0); |
|
&update_recent_changes; |
|
178 |
} |
} |
179 |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
$database->meta (IsFrozen => $form{mypage} => 0 + $form{myfrozen}); |
180 |
&print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":'')); |
my $fragment = ''; |
181 |
&print_message($resource{saved}); |
$fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd}; |
182 |
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
if ($form{__comment_anchor_index}) { |
183 |
&print_footer($CompletedSuccessfully); |
$fragment .= qq(#anchor-$form{__comment_anchor_index}); |
184 |
|
} elsif ($form{__wikiform_anchor_index}) { |
185 |
|
$fragment .= qq(#wikiform-$form{__wikiform_anchor_index}); |
186 |
|
} |
187 |
|
&_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)); |
188 |
} else { |
} else { |
|
&send_mail_to_admin($form{mypage}, "Delete"); |
|
189 |
delete $database{$form{mypage}}; |
delete $database{$form{mypage}}; |
190 |
delete $infobase{$form{mypage}}; |
&_do_view_msg (-view => '-deleted', -page => $form{mypage}); |
|
if ($form{mytouch}) { |
|
|
&update_recent_changes; |
|
|
} |
|
|
&print_header($form{mypage}, -noindex => 1); |
|
|
&print_message($resource{deleted}); |
|
|
&print_footer($form{mypage}); |
|
191 |
} |
} |
192 |
} |
} |
193 |
|
|
194 |
sub do_searchform { |
sub _compatible_options () { |
195 |
&print_header($SearchPage); |
(use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0)); |
|
&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); |
|
196 |
} |
} |
197 |
|
|
198 |
sub get_search_result ($;%) { |
sub get_search_result ($;%) { |
199 |
my $word = shift; |
my $word = lc shift; |
200 |
|
my $SearchResult = SuikaWiki::Plugin->cache ('search'); |
201 |
my %option = @_; |
my %option = @_; |
202 |
my @r; |
my @r; |
203 |
foreach my $page (keys %database) { |
unless (defined $SearchResult->{$word}) { |
204 |
next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself}); |
for my $page (keys %database) { |
205 |
my $content = $database{$page}; |
next if !$option{-match_myself} && ($page eq $word); |
206 |
my $cf = 'SuikaWiki/0.9'; |
my $content = lc $database{$page}; |
207 |
$cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s; |
$content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s; |
208 |
next if $cf =~ /obsoleted="yes"/; |
if (index (lc $page, $word) > -1) { |
209 |
if (index ($page, $word) > -1) { |
my $c = $content =~ s/\Q$word\E//g; |
210 |
my $c = $content =~ s/\Q$word\E/$word/g; |
push @r, [$page, $c+20]; |
211 |
push @r, [$page, $c+20]; |
} elsif (index ($word, lc $page) > -1) { |
212 |
} elsif (index ($word, $page) > -1) { |
my $c = $content =~ s/\Q$word\E//g; |
213 |
my $c = $content =~ s/\Q$word\E/$word/g; |
push @r, [$page, $c+10]; |
214 |
push @r, [$page, $c+10]; |
} elsif (my $c = $content =~ s/\Q$word\E//g) { |
215 |
} elsif (my $c = $content =~ s/\Q$word\E/$word/g) { |
push @r, [$page, $c]; |
216 |
push @r, [$page, $c]; |
} |
217 |
} |
} |
218 |
|
@r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
219 |
|
$SearchResult->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r; |
220 |
|
} else { |
221 |
|
@r = map {[split /\x1F/, $_, 2]} split /\x1E/, $SearchResult->{$word}; |
222 |
} |
} |
223 |
my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#g; $s }; |
#my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s }; |
224 |
my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} @r; |
225 |
$r = qq|<ul class="search-result">$r</ul>| if $r; |
$r = qq|<ul class="search-result">$r</ul>| if $r; |
|
get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found}; |
|
226 |
wantarray? ($r, scalar @r): $r; |
wantarray? ($r, scalar @r): $r; |
227 |
} |
} |
228 |
|
|
|
sub do_create { |
|
|
&print_header($CreatePage); |
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<input type="hidden" name="mycmd" value="edit"> |
|
|
<strong>$resource{newpagename}</strong><br> |
|
|
<input type="text" name="mypage" value="" size="20"> |
|
|
<input type="submit" value="$resource{createbutton}"><br> |
|
|
</form> |
|
|
EOD |
|
|
&print_footer($CreatePage); |
|
|
} |
|
|
|
|
229 |
sub do_random_jump { |
sub do_random_jump { |
230 |
my @list = keys %database; |
my @list = keys %database; |
231 |
my $name = &encode ($list[rand @list]); |
my $name = &encode ($list[rand @list]); |
232 |
my ($scheme) = 'http'; |
print "Location: $uri{wiki}?$name\n"; |
|
$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"; |
|
233 |
print "\n"; |
print "\n"; |
234 |
} |
} |
235 |
|
|
|
sub do_FrontPage { |
|
|
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
|
|
my $content = join('', <FILE>); |
|
|
&code_convert(\$content, $kanjicode); |
|
|
close(FILE); |
|
|
&print_header($FrontPage); |
|
|
&print_content($content); |
|
|
&print_footer($FrontPage); |
|
|
} |
|
|
|
|
|
sub print_error { |
|
|
my ($msg) = @_; |
|
|
&print_header($ErrorPage, -noindex => 1); |
|
|
print qq(<p><strong class="error">$msg</strong></p>); |
|
|
&print_footer($ErrorPage); |
|
|
exit(0); |
|
|
} |
|
|
|
|
236 |
sub print_header ($;%) { |
sub print_header ($;%) { |
237 |
my ($page, %option) = @_; |
my ($page, %option) = @_; |
238 |
my $bodyclass = "normal"; |
my @head; |
239 |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
$option{o}->{-header}->{class} = &is_frozen($page) ? 'frozen' : ''; |
240 |
$bodyclass = "frozen"; |
$option{o}->{-header}->{class} .= " wiki-page-obsoleted" if $option{-magic} =~ /obsoleted="yes"/; |
241 |
} |
if ($option{-goto}) { |
242 |
$bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
if ($UA =~ m#Opera|MSIE 2\.#) { |
243 |
print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto}; |
## WARNING: This code may output unsafe HTML document if |
244 |
print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; |
## $option{-goto} is not clean. |
245 |
my $cookedpage = &encode($page); |
$option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#; |
246 |
my $escapedpage = &escape($page); |
print qq{Refresh: 0; url=$option{-goto}\n}; |
247 |
print <<"EOD"; |
push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">); |
248 |
Content-type: text/html; charset=$charset |
} elsif ($UA =~ /Gecko/) { |
249 |
|
print qq{Refresh: 0; url="$option{-goto}"\n}; |
250 |
|
push @head, qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"" />); |
251 |
|
} else { |
252 |
|
$option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#; |
253 |
|
print qq{Refresh: 0; url="$option{-goto}"\n}; |
254 |
|
push @head, qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"">); |
255 |
|
} |
256 |
|
} |
257 |
|
print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified}; |
258 |
|
if ($option{-expires} != -1) { |
259 |
|
if (defined $option{-expires}) { ## TODO: Don't use asctime |
260 |
|
print qq{Expires: @{[scalar gmtime (time + $option{-expires})]}\n}; |
261 |
|
} elsif ($option{-media}->{expires} != -1) { |
262 |
|
print qq{Expires: @{[scalar gmtime (time + $option{-media}->{expires})]}\n}; |
263 |
|
} |
264 |
|
} |
265 |
|
if ($option{-media}->{charset} && $UA =~ m#Mozilla/[12]\.#) { |
266 |
|
my $ct = qq{$option{-media}->{type}; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}}; |
267 |
|
print qq{Content-Type: $ct\n}; |
268 |
|
$option{o}->{-header}->{meta_ct} = qq{<meta http-equiv="content-type" content="$ct">\n}; |
269 |
|
} elsif (!$option{-media}->{charset} || $UA =~ m#Infomosaic|Mozilla/0\.#) { |
270 |
|
print qq{Content-Type: $option{-media}->{type}\n}; |
271 |
|
$option{o}->{-header}->{meta_ct} = qq{<meta http-equiv="content-type" content="$option{-media}->{type}; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}">\n}; |
272 |
|
} else { |
273 |
|
my $type = $option{-media}->{type}; |
274 |
|
$type = 'application/xml' if $type eq 'application/rss+xml'; |
275 |
|
print qq{Content-Type: $type; charset=@{[&get_charset_name($kanjicode)]}\n}; |
276 |
|
} |
277 |
|
print <<"EOD"; ## TODO: |
278 |
Content-Language: $lang |
Content-Language: $lang |
279 |
Content-Style-Type: text/css |
Content-Style-Type: text/css |
280 |
|
|
|
<!-- |
|
|
<!DOCTYPE html |
|
|
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
|
|
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
|
|
<html lang="$lang"> |
|
|
<head> |
|
|
<title>$escapedpage</title> |
|
|
<link rel="index" href="$url_cgi?$IndexPage"> |
|
|
<link rel="help" href="$url_cgi?WikiHelp"> |
|
|
<link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense"> |
|
|
<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}"> |
|
|
@{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']} |
|
|
</head> |
|
|
<body class="$bodyclass"> |
|
|
EOD |
|
|
&print_navigate_links ($page); |
|
|
print <<EOD; |
|
|
<h1 class="header">@{[&escape($page)]}</h1> |
|
281 |
EOD |
EOD |
282 |
|
$option{o}->{-header}->{links} = join "\n", (@head); |
283 |
} |
} |
284 |
|
|
285 |
sub print_navigate_links (@) { |
sub get_charset_name ($;%) { |
286 |
my ($page) = @_; |
my ($charset, %option) = (lc shift, @_); |
287 |
my $editable = 0; |
if ($charset =~ 'euc') { |
288 |
my $admineditable = 0; |
$charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp'; |
289 |
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
} elsif ($charset =~ 'sjis' || $charset =~ 'shift') { |
290 |
$editable = 0; |
$charset = $option{compatible} ? 'x-sjis' : 'shift_jis'; |
291 |
#$admineditable = 1; |
} elsif ($charset =~ 'jis') { |
292 |
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
$charset = 'iso-2022-jp'; |
|
#$admineditable = 1; |
|
|
$editable = 1; |
|
|
} else { |
|
|
$editable = 0; |
|
293 |
} |
} |
294 |
my $cookedpage = &encode($page); |
$charset; |
|
print <<EOH; |
|
|
<div class="tools"> |
|
|
@{[ $admineditable |
|
|
? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
@{[ $editable |
|
|
? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | ) |
|
|
qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
@{[ $admineditable |
|
|
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
|
|
: qq() |
|
|
]} |
|
|
<a href="$url_cgi?$CreatePage" class="wiki">新規</a> | |
|
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
|
|
<a href="$url_cgi?$FrontPage" class="wiki">首頁</a> | |
|
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
|
|
<a href="$url_cgi?$RecentChanges" class="wiki">最新</a> |
|
|
</div> |
|
|
EOH |
|
|
<<EOH; ## temp |
|
|
<a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> | |
|
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
|
|
<!-- <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | --> |
|
|
<a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> | |
|
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
|
|
<a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a> |
|
|
</div> |
|
|
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$; |
|
|
my $cvslog2 = q$Date$; |
|
|
print_navigate_links ($page); |
|
|
print <<"EOD"; |
|
|
@{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]} |
|
|
<div class="footer"> |
|
|
<a href="http://www.hyuki.com/yukiwiki/" title="$version © 2000-2002 by Hiroshi Yuki">YukiWiki</a> <a href="http://digit.que.ne.jp/work/" title="$walversion © 2000-2002 by Makio Tsukamoto">WalWiki</a> |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a> |
|
|
<div class="navigation"> |
|
|
[<a href="/" title="このサーバーの首頁">/</a> |
|
|
<a href="/map" title="このサーバーの案内">地図</a> |
|
|
<a href="/search/" title="このサーバーの検索">検索</a>] |
|
|
</div> |
|
|
</div> |
|
|
$walrus_log |
|
|
</body> |
|
|
</html> |
|
|
EOD |
|
|
# print <<"EOD"; |
|
|
# <hr> |
|
|
# <address class="footer"> |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version |
|
|
# © 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br /> |
|
|
# Modified by <a href="$modifier_url">$modifier_name</a>. |
|
|
# </address> |
|
|
# <p class="footer"> |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">$icontag</a> |
|
|
# </p> |
|
|
# </body> |
|
|
# </html> |
|
|
# EOD |
|
|
# Walrus mod (1) end |
|
295 |
} |
} |
296 |
|
|
297 |
sub escape { |
sub escape { |
298 |
my $s = shift; |
my $s = shift; |
299 |
$s =~ s|\r\n|\n|g; |
$s =~ s|\x0D\x0A|\x0A|g; |
300 |
$s =~ s|&|&|g; |
$s =~ s|&|&|g; |
301 |
$s =~ s|<|<|g; |
$s =~ s|<|<|g; |
302 |
$s =~ s|>|>|g; |
$s =~ s|>|>|g; |
314 |
return $s; |
return $s; |
315 |
} |
} |
316 |
|
|
317 |
sub print_content ($;$) { |
sub convert_format ($$$;%) { |
318 |
my ($rawcontent, %option) = @_; |
my ($content, $d => $t, %option) = @_; |
319 |
print &text_to_html($rawcontent, toc=>1, %option); |
&load_formatter ('format'); |
320 |
|
my $f = SuikaWiki::Plugin->format_converter ($d => $t); |
321 |
|
if (ref $f) { |
322 |
|
$option{content} = $content; |
323 |
|
$option{from} = $d; |
324 |
|
$option{to} = $t; |
325 |
|
&$f ({}, bless (\%option, 'SuikaWiki::Plugin')); |
326 |
|
} elsif ($t =~ /HTML|xml/) { |
327 |
|
length $content ? '<pre>'.&escape($content).'</pre>' : ''; |
328 |
|
} else { |
329 |
|
$content; |
330 |
|
} |
331 |
} |
} |
332 |
|
|
333 |
sub text_to_html { |
sub text_to_html { |
334 |
my ($txt, %option) = @_; |
my ($txt, %option) = @_; |
335 |
my (@txt) = split(/\n/, $txt); |
my $toc = $option{-toc} || (ref $option{toc} ? $option{toc} : []); |
|
my @toc; |
|
|
my @toc2 = @{$option{-toc}||[]}; |
|
336 |
my $tocnum = 0; |
my $tocnum = 0; |
337 |
|
|
338 |
|
## Load constants |
339 |
|
my %const; |
340 |
|
if ($option{magic} =~ /import="([^"]+)"/) { |
341 |
|
for (split /\s*,\s*/, $1) { |
342 |
|
my $wp = $database{$_}; |
343 |
|
if ($wp =~ m!^\#\?SuikaWikiConst/(?:0.9|1.0)!) { |
344 |
|
wiki::suikawikiconst::to_hash ($wp => \%const); |
345 |
|
} |
346 |
|
} |
347 |
|
} |
348 |
|
|
349 |
|
$txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge; |
350 |
|
my (@txt) = split(/\n/, $txt); |
351 |
my (@saved, @result); |
my (@saved, @result); |
352 |
unshift(@saved, "</p>"); |
unshift(@saved, "</p>"); |
353 |
push(@result, "<p>"); |
push(@result, "<p>"); |
354 |
foreach (@txt) { |
foreach (@txt) { |
355 |
chomp; |
chomp; |
356 |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
357 |
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [5, "i$tocnum" => ($1 || $tocnum)]; |
358 |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, %option, const => \%const) . '</h6>'); |
359 |
$tocnum++; |
$tocnum++; |
360 |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
361 |
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [4, "i$tocnum" => ($1 || $tocnum)]; |
362 |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, %option, const => \%const) . '</h5>'); |
363 |
$tocnum++; |
$tocnum++; |
364 |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
365 |
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [3, "i$tocnum" => ($1 || $tocnum)]; |
366 |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, %option, const => \%const) . '</h4>'); |
367 |
$tocnum++; |
$tocnum++; |
368 |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
369 |
# if (/^\*\*(.*)/) { |
# if (/^\*\*(.*)/) { |
370 |
# Walrus mod (6) end |
# Walrus mod (6) end |
371 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [2, "i$tocnum" => ($1 || $tocnum)]; |
372 |
push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>'); |
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, %option, const => \%const) . '</h3>'); |
373 |
$tocnum++; |
$tocnum++; |
374 |
} elsif (/^\*([^\x0D\x0A]*)/) { |
} elsif (/^\*([^\x0D\x0A]*)/) { |
375 |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [1, "i$tocnum" => ($1 || $tocnum)]; |
376 |
push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>'); |
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, %option, const => \%const) . '</h2>'); |
377 |
$tocnum++; |
$tocnum++; |
378 |
} elsif (/^(={1,6})(.*)/) { |
} elsif (/^(={1,6})(.*)/) { |
379 |
&back_push('ol', length($1), \@saved, \@result); |
&back_push('ol', length($1), \@saved, \@result); |
380 |
push(@result, '<li>' . &inline($2) . '</li>'); |
push(@result, '<li>' . &inline($2, %option, const => \%const) . '</li>'); |
381 |
} elsif (/^(-{1,6})(.*)/) { |
} elsif (/^(-{1,6})(.*)/) { |
382 |
&back_push('ul', length($1), \@saved, \@result); |
&back_push('ul', length($1), \@saved, \@result); |
383 |
my ($pf, $l) = ('', $2); |
my ($pf, $l) = ('', $2); |
385 |
my $num = 0+$1; |
my $num = 0+$1; |
386 |
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
387 |
} |
} |
388 |
push(@result, '<li>' . $pf . &inline ($l) . '</li>'); |
push(@result, '<li>' . $pf . &inline ($l, %option, const => \%const) . '</li>'); |
389 |
} elsif (/^:([^:]+):(.*)/) { |
} elsif (/^:([^:]+):(.*)/) { |
390 |
&back_push('dl', 1, \@saved, \@result); |
&back_push('dl', 1, \@saved, \@result); |
391 |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
push(@result, '<dt>' . &inline($1, %option, const => \%const) . '</dt>', '<dd>' . &inline($2, %option, const => \%const) . '</dd>'); |
392 |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
393 |
&back_push('blockquote', length($1), \@saved, \@result); |
&back_push('blockquote', length($1), \@saved, \@result); |
394 |
push @result, "<p>"; |
push @result, "<p>"; |
395 |
push(@result, &inline($2)); |
push(@result, &inline($2, %option, const => \%const)); |
396 |
unshift @saved, "</p>"; |
unshift @saved, "</p>"; |
397 |
} elsif (/^\s*$/) { |
} elsif (/^\s*$/) { |
398 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
400 |
unshift(@saved, "</p>"); |
unshift(@saved, "</p>"); |
401 |
} elsif (/^(\s+.*)$/) { |
} elsif (/^(\s+.*)$/) { |
402 |
&back_push('pre', 1, \@saved, \@result); |
&back_push('pre', 1, \@saved, \@result); |
403 |
#push(@result, &escape($1)); # Not &inline, but &escape |
push(@result, &inline($1, %option, const => \%const)); |
404 |
push(@result, &inline($1)); |
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { |
405 |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
&back_push('table', 1, \@saved, \@result); |
|
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
|
|
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
|
406 |
####### |
####### |
407 |
# This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki. |
# This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki. |
408 |
# XXXXX |
# XXXXX |
416 |
$colspan[$i]++; |
$colspan[$i]++; |
417 |
} |
} |
418 |
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; |
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; |
419 |
$value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i])); |
$value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], %option, const => \%const)); |
420 |
} else { |
} else { |
421 |
$value[$i] = ''; |
$value[$i] = ''; |
422 |
} |
} |
433 |
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
434 |
my $num = 0+$1; |
my $num = 0+$1; |
435 |
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
436 |
push @result, &inline ($2); |
push @result, &inline ($2, %option, const => \%const); |
437 |
} else { |
} else { |
438 |
push(@result, &inline($_)); |
push(@result, &inline($_, %option, const => \%const)); |
439 |
} |
} |
440 |
} |
} |
441 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
442 |
|
|
443 |
my $toc = ''; |
my $r = join("\n", @result); |
444 |
if ($option{toc}) { |
$r =~ s#<p>\x0D?\x0A</p>##g; |
445 |
# Convert @toc (table of contents) to HTML. |
$r =~ s#[\x0D\x0A]+</#</#g; |
446 |
# This part is taken from Makio Tsukamoto's WalWiki. |
$r =~ s#<pre>\x0D?\x0A#<pre>#g; |
447 |
my (@tocsaved, @tocresult); |
$r; |
|
foreach (@toc,@toc2) { |
|
|
if (/^(-{1,6})(.*)$/) { |
|
|
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
|
|
push(@tocresult, '<li>' . $2 . '</li>'); |
|
|
} |
|
|
} |
|
|
push(@tocresult, splice(@tocsaved)); |
|
|
$toc = join("\n", @tocresult); |
|
|
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
|
|
} |
|
|
$toc .= join("\n", @result); |
|
|
$toc =~ s#<p>\n</p>##g; |
|
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
|
|
$toc =~ s#<pre>\n#<pre>#g; |
|
|
$toc; |
|
448 |
} |
} |
449 |
|
|
450 |
sub back_push { |
sub back_push { |
461 |
} |
} |
462 |
} |
} |
463 |
|
|
464 |
sub inline { |
sub inline ($;%) { |
465 |
my ($line) = @_; |
my ($line, %option) = @_; |
466 |
$line = &escape($line); |
$line = &escape($line); |
467 |
$line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g; |
$line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4, \%option)}ge; |
468 |
|
$line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g; |
469 |
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
470 |
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
471 |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g; |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g; |
472 |
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
473 |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g; |
$line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g; |
|
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g; |
|
474 |
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
475 |
$line =~ s|''([^']+)''|<em>$1</em>|g; |
$line =~ s|''([^']+)''|<em>$1</em>|g; |
476 |
$line =~ s! |
$line =~ s{ |
477 |
( |
(\[\[(\#\S+?)\]\]) |
478 |
(?:<(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)> |
|\[\[([^[]+?)](?:>>([0-9]+))?] |
|
| |
|
|
(?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
|
|
|\[\[([^[]+?)]>>([0-9]+)] # [[WikiName]>>1] |
|
479 |
|>>([0-9]+) |
|>>([0-9]+) |
480 |
! |
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
481 |
my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5); |
}{ |
482 |
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
483 |
if ($l) { |
if ($l) { |
484 |
&make_link($l) |
&embedded_to_html($1); |
485 |
} elsif (defined $page) { |
} elsif (defined $page) { |
486 |
&make_wikilink ($page, anchor => 0+$anchor); |
&make_wikilink ($page, anchor => 0+$anchor); |
487 |
} elsif ($anum) { |
} elsif ($anum) { |
488 |
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
489 |
|
} elsif ($uri) { |
490 |
|
&make_urilink ($uri); |
491 |
} |
} |
492 |
!gex; |
}gex; |
493 |
return $line; |
return $line; |
494 |
} |
} |
495 |
|
|
496 |
sub make_wikilink ($%) { |
sub make_wikilink ($%) { |
497 |
my ($ename, %option) = @_; |
my ($ename, %option) = @_; |
498 |
my $name = &unescape ($ename); |
my $name = &unescape ($ename); |
499 |
|
$option{latest} = $option{latest} ? qq(mycmd=default;x-param=@{[time.[0..9]->[rand 10]]};mypage=) : ''; |
500 |
if ($database{$name}) { |
if ($database{$name}) { |
501 |
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
502 |
if ($option{anchor}) { |
if ($option{anchor}) { |
503 |
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
return qq(<a title="$subject" href="$uri{wiki}?$option{latest}@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
504 |
} else { |
} else { |
505 |
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
return qq(<a title="$subject" href="$uri{wiki}?$option{latest}@{[&encode($name)]}" class="wiki">$ename</a>); |
506 |
} |
} |
507 |
} else { |
} else { |
508 |
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>); |
return qq(<a title="@{[&Resource('JumpAndEditWikiPage',escape=>1)]}" href="$uri{wiki}?$option{latest}@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</span></a>); |
509 |
} |
} |
510 |
} |
} |
511 |
|
|
512 |
sub make_link { |
sub make_urilink ($;%) { |
513 |
my $chunk = shift; |
require URI; |
514 |
# Walrus add (3) start |
my $uri = shift; |
515 |
$chunk =~ s/^<(.*)>$/$1/; |
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
516 |
my $name = $chunk; |
$uri = &unescape ($uri); |
517 |
if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) { |
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
518 |
($name, $chunk) = ($1, $2); |
my ($site, $name) = ($1, $2); |
519 |
} elsif ($chunk =~ /^mailto:(.*)$/) { |
for ($site, $name) { |
520 |
$name = $1; |
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
521 |
} |
} |
522 |
if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) { |
&init_InterWikiName () unless $interwiki{'[[]]'}; |
523 |
$name = qq(<img src="$name">) ; |
if ($interwiki{$site}) { |
524 |
} |
&load_formatter ('interwiki'); |
525 |
$name = &unarmor_name($name); |
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
526 |
# Walrus add (3) end |
$site = &escape ($site); $name = &escape ($name); |
527 |
if ($chunk =~ /^(http|https|ftp|news):/) { |
qq(<<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: <$uri>"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>>); |
528 |
# Walrus mod (3) start |
} else { |
529 |
# if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) { |
qq(<@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}>); |
530 |
# return qq(<a href="$chunk"><img src="$chunk"></a>); |
} |
|
# } else { |
|
|
# return qq(<a href="$chunk">$chunk</a>); |
|
|
# } |
|
|
return qq(<<a href="$chunk">$name</a>>); |
|
|
# Walrus mod (3) end |
|
|
} elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) { |
|
|
return qq|<<a href="/uri-res/N2L?${name}">$name</a>>|; |
|
|
} elsif ($chunk =~ /^mailto:(.*)/) { |
|
|
# return qq(<a href="$chunk">$2</a>); # Walrus del (3) |
|
|
return qq(<<a href="$chunk">$name</a>>); # Walrus add (3) |
|
|
} elsif ($chunk =~ /^$interwiki_definition$/) { |
|
|
# return qq(<span class="InterWiki">$chunk</span>); # Walrus del (3) |
|
|
return qq(<span class="InterWiki">$name</span>); # Walrus add (3) |
|
|
} elsif ($chunk =~ /^$embedded_name$/) { |
|
|
return &embedded_to_html($chunk); |
|
531 |
} else { |
} else { |
532 |
$chunk = &unarmor_name($chunk); |
qq(<@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}>); |
|
$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(<a href="$remoteurl">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a href="$remoteurl">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} else { |
|
|
# return $chunk; # Walrus del (3) |
|
|
return &escape($name); # Walrus add (3) |
|
|
} |
|
|
} elsif ($database{$chunk}) { |
|
|
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
|
|
# return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} elsif ($page_command{$chunk}) { |
|
|
# return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
|
|
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
|
|
} else { |
|
|
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>); |
|
|
} |
|
533 |
} |
} |
534 |
|
} elsif ($uri =~ /^urn:/) { ## URN |
535 |
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
536 |
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
537 |
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
538 |
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
539 |
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
540 |
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
541 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
542 |
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
543 |
|
} else { ## misc. URI |
544 |
|
CGI::Carp::warningsToBrowser (0); |
545 |
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
546 |
|
CGI::Carp::warningsToBrowser (1); |
547 |
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
548 |
|
} |
549 |
} |
} |
550 |
|
|
551 |
sub print_message { |
{my %FormIndex; |
552 |
my ($msg) = @_; |
sub make_custom_form ($$$$%) { |
553 |
print qq(<p><strong>$msg</strong></p>); |
my ($wfname, $definition, $template, $foption, $option) = @_; |
554 |
} |
## $template is currently not used in this procedure. |
555 |
|
#unless ($main::_EMBEDED) { |
556 |
sub get_message { |
$FormIndex{$option->{page}}++; |
557 |
my ($msg) = @_; |
if (length $definition) { |
558 |
qq(<p><strong>$msg</strong></p>); |
my $param = bless {depth=>10}, 'SuikaWiki::Plugin'; |
559 |
} |
my $lastmodified = $database->mtime ($option->{page}); |
560 |
|
&load_formatter (qw/form_input form_option/); |
561 |
|
$definition = &unescape ($definition); |
562 |
|
$definition =~ s/\\(.)/$1/g; |
563 |
|
$foption = &unescape ($foption); |
564 |
|
$foption =~ s/\\(.)/$1/g; |
565 |
|
$fmt{form_option}->replace ($foption, $param); |
566 |
|
$param->{output}->{form} = 1 unless defined $param->{output}->{form}; |
567 |
|
$param->{output}->{form} = 0 if $main::_EMBEDED; |
568 |
|
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; |
569 |
|
$param->{output}->{page} ||= $option->{page}; |
570 |
|
$param->{form_disabled} = 1 if $database->meta (IsFrozen => $option->{page}); |
571 |
|
my $target_form = $param->{output}->{id}; |
572 |
|
my $r = ''; |
573 |
|
$r = <<EOH if $param->{output}->{form}; |
574 |
|
<form method="post" action="$url_cgi" id="wikiform-$FormIndex{$option->{page}}" class="wikiform"> |
575 |
|
<input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'default':'wikiform']}" /> |
576 |
|
<input type="hidden" name="mypage" value="@{[&escape($param->{output}->{page})]}" /> |
577 |
|
<input type="hidden" name="myLastModified" value="$lastmodified" /> |
578 |
|
<input type="hidden" name="mytouch" value="on" /> |
579 |
|
<input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex{$option->{page}})]}" /> |
580 |
|
EOH |
581 |
|
$r .= qq(<a name="wikiform-$FormIndex{$option->{page}}"></a>) if $UA =~ m#Mozilla/[12]\.#; |
582 |
|
$r .= $fmt{form_input}->replace ($definition, $param); |
583 |
|
$r .= "</form>\n" if $param->{output}->{form}; |
584 |
|
$r; |
585 |
|
} else { ## No input-interface WikiForm |
586 |
|
qq(<a id="wikiform-$FormIndex{$option->{page}}" name="wikiform-$FormIndex{$option->{page}}"><!-- #form --></a>); |
587 |
|
} |
588 |
|
#} else { |
589 |
|
# qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>); |
590 |
|
#} |
591 |
|
}} |
592 |
|
|
593 |
sub init_form { |
sub init_form { |
594 |
if (param()) { |
## TODO: Support multipart/form-data |
595 |
foreach my $var (param()) { |
my $query = ''; |
596 |
$form{$var} = param($var); |
if (uc $main::ENV{REQUEST_METHOD} eq 'POST') { |
597 |
} |
read STDIN, $query, $main::ENV{CONTENT_LENGTH}; |
598 |
} |
} |
599 |
if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) { |
$query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING}; |
600 |
|
if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) { |
601 |
my $query = &decode($main::ENV{QUERY_STRING}); |
my $query = &decode($main::ENV{QUERY_STRING}); |
602 |
if ($page_command{$query}) { |
$query = &code_convert(\$query, $kanjicode); |
|
$form{mycmd} = $page_command{$query}; |
|
603 |
$form{mypage} = $query; |
$form{mypage} = $query; |
604 |
} else { |
$form{mycmd} = 'default'; |
605 |
$form{mypage} = $query; |
} else { |
606 |
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
for (split /[;&]/, $query) { |
607 |
|
if (my ($n, $v) = split /=/, $_, 2) { |
608 |
|
for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge}; |
609 |
|
$form{$n} = $v; |
610 |
|
} |
611 |
|
} |
612 |
|
unless (defined $form{mypage}) { |
613 |
|
$form{mypage} = $form{epage}; |
614 |
|
$form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g; |
615 |
} |
} |
616 |
} |
} |
617 |
$form{mypage} ||= 'HomePage'; |
$form{mypage} ||= $PageName{FrontPage}; |
618 |
|
$form{mypage} =~ tr/\x00-\x1F\x7F//d; |
619 |
|
$form{mycmd} ||= 'default'; |
620 |
|
|
621 |
# mypreview_edit -> do_edit, with preview. |
# mypreview_edit -> do_edit, with preview. |
622 |
# mypreview_adminedit -> do_adminedit, with preview. |
# mypreview_adminedit -> do_adminedit, with preview. |
632 |
# $form{mycmd} is frozen here. |
# $form{mycmd} is frozen here. |
633 |
# |
# |
634 |
|
|
635 |
|
for (grep /^wikiform__/, keys %form) { |
636 |
|
$form{$_} = &code_convert (\$form{$_}, $kanjicode); |
637 |
|
} |
638 |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
639 |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
640 |
} |
} |
641 |
|
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
642 |
sub get_subjectline { |
sub get_subjectline { |
643 |
my ($page, %option) = @_; |
my ($page, %option) = @_; |
644 |
if (not &is_editable($page)) { |
my $SubjectLine = SuikaWiki::Plugin->cache ('headline'); |
645 |
return ""; |
unless (defined $SubjectLine->{$page}) { |
646 |
|
if (not &is_editable($page)) { |
647 |
|
$SubjectLine->{$page} = ""; |
648 |
|
} else { |
649 |
|
$SubjectLine->{$page} = do { |
650 |
|
my $s=$database{$page}; |
651 |
|
$s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s; |
652 |
|
$s =~ s/\x0D?\x0A.*//s; |
653 |
|
$s}; |
654 |
|
} |
655 |
|
} |
656 |
|
if (length $SubjectLine->{$page}) { |
657 |
|
$option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter'); |
658 |
|
$option{delimiter}.$SubjectLine->{$page}.$option{tail}; |
659 |
} else { |
} else { |
660 |
# 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}; |
|
661 |
} |
} |
662 |
} |
} |
663 |
|
|
|
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); |
|
|
} |
|
|
|
|
664 |
sub open_db { |
sub open_db { |
665 |
if ($modifier_dbtype eq 'dbmopen') { |
if ($modifier_dbtype eq 'dbmopen') { |
666 |
dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname"); |
dbmopen(%database, $PathTo{WikiDataBase}, 0666) or die "(dbmopen) $PathTo{WikiDataBase}"; |
|
dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname"); |
|
667 |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
668 |
tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname"); |
eval q{use AnyDBM_File}; |
669 |
tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname"); |
tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or die ("(tie AnyDBM_File) $PathTo{WikiDataBase}"); |
670 |
} else { |
} elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') { |
671 |
tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname"); |
eval q{use Yuki::YukiWikiDB}; |
672 |
tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname"); |
tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or die ("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}"); |
673 |
|
} else { ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta |
674 |
|
eval qq{use $modifier_dbtype}; |
675 |
|
$database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or die ("(tie $modifier_dbtype) $PathTo{WikiDataBase}"); |
676 |
} |
} |
677 |
} |
} |
678 |
|
|
679 |
sub close_db { |
sub close_db { |
680 |
if ($modifier_dbtype eq 'dbmopen') { |
if ($modifier_dbtype eq 'dbmopen') { |
681 |
dbmclose(%database); |
dbmclose(%database); |
|
dbmclose(%infobase); |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
|
|
untie(%database); |
|
|
untie(%infobase); |
|
682 |
} else { |
} else { |
683 |
untie(%database); |
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); |
|
684 |
} |
} |
685 |
} |
} |
686 |
|
|
687 |
sub print_searchform { |
sub editform (@) { |
688 |
my ($word) = @_; |
my %option = @_; |
689 |
print <<"EOD"; |
my $frozen = &is_frozen ($option{page}); |
690 |
<form action="$url_cgi" method="get"> |
$option{content} = $database{$option{page}} unless defined $option{content}; |
691 |
<input type="hidden" name="mycmd" value="search"> |
$option{content} = $database{NewPageTemplate} unless length $option{content}; |
692 |
<input type="text" name="mymsg" value="$word" size="20"> |
$option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified}; |
693 |
<input type="submit" value="$resource{searchbutton}"> |
my $f = ''; |
694 |
</form> |
my $magic = ''; |
695 |
EOD |
$magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s; |
696 |
} |
|
697 |
|
my $selected = 'default'; |
698 |
sub print_editform { |
if ($form{after_edit_cmd}) { |
699 |
my ($mymsg, $lastmodified, %mode) = @_; |
$selected = $form{after_edit_cmd}; |
700 |
my $frozen = &is_frozen($form{mypage}); |
} elsif ($magic =~ /Const|Config|CSS/) { |
701 |
|
$selected = 'edit'; |
702 |
if ($form{mypreview}) { |
} |
703 |
if ($form{mymsg}) { |
my $afteredit = <<EOH; |
704 |
unless ($mode{conflict}) { |
<select name="after_edit_cmd"> |
705 |
print qq(<h3>$resource{previewtitle}</h3>\n); |
<option value="default" label="@{[&Resource('Edit:SaveAndDefault',escape=>1)]}"@{[$selected eq 'default' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndDefault',escape=>1)]}</option> |
706 |
print qq($resource{previewnotice}\n); |
<option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option> |
707 |
print qq(<div class="preview">\n); |
<option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option> |
708 |
&print_content($form{mymsg}); |
</select> |
709 |
print qq(</div>\n); |
EOH |
710 |
} |
$f .= <<"EOD"; |
711 |
} else { |
<form action="$uri{wiki}" method="post"> |
712 |
print qq($resource{previewempty}); |
@{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" /><kbd>S</kbd></label>) ]} |
713 |
} |
@{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10" /></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br /> |
714 |
$mymsg = &escape($form{mymsg}); |
<input type="hidden" name="myLastModified" value="$option{last_modified}" /> |
715 |
} else { |
<input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}" /> |
716 |
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
<textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br /> |
|
} |
|
|
|
|
|
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
|
|
my $escapedmypage = &escape($form{mypage}); |
|
|
my $escapedmypassword = &escape($form{mypassword}); |
|
|
|
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<h2>$escapedmypageの編集</h2> |
|
|
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]} |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
|
|
<input type="hidden" name="mypage" value="$escapedmypage"> |
|
|
<textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br> |
|
717 |
@{[ |
@{[ |
718 |
$mode{admin} ? |
$option{admin} ? |
719 |
qq( |
qq( |
720 |
<input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton} |
<label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]} />@{[&Resource('Edit:Freeze',escape=>1)]}</label> |
721 |
<input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>) |
<label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]} />@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br />) |
722 |
: "" |
: "" |
723 |
]} |
]} |
724 |
@{[ |
@{[ |
725 |
$mode{conflict} ? "" : |
$option{conflict} ? "" : |
726 |
qq( |
qq( |
727 |
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
<label><input type="checkbox" name="mytouch" value="on" checked="checked" />@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br /> |
728 |
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S" /><kbd>S</kbd></label> |
729 |
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd> |
$afteredit |
|
[@{[do {my $n = 0; |
|
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
|
|
++$n}]}]<br> |
|
730 |
) |
) |
731 |
]} |
]} |
732 |
</form> |
</form> |
733 |
EOD |
EOD |
734 |
unless ($mode{conflict}) { |
$f; |
|
# Show the format rule. |
|
|
my $help = $database{'WikiEditHelp'}; |
|
|
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
|
|
print &text_to_html ($help, toc => 0); |
|
|
# open(FILE, $file_format) or &print_error("($file_format)"); |
|
|
# my $content = join('', <FILE>); |
|
|
# &code_convert(\$content, $kanjicode); |
|
|
# close(FILE); |
|
|
# print &text_to_html($content, toc=>0); |
|
|
} |
|
|
} |
|
|
|
|
|
sub print_passwordform { |
|
|
print <<"EOD"; |
|
|
<form action="$url_cgi" method="post"> |
|
|
<input type="hidden" name="mycmd" value="adminchangepassword"> |
|
|
$resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br> |
|
|
$resource{newpassword} <input type="password" name="mynewpassword" size="10"><br> |
|
|
$resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br> |
|
|
<input type="submit" value="$resource{changepasswordbutton}"><br> |
|
|
</form> |
|
|
EOD |
|
735 |
} |
} |
736 |
|
|
737 |
sub is_editable { |
sub is_editable { |
738 |
my ($page) = @_; |
my ($page) = @_; |
739 |
if (&is_bracket_name($page)) { |
$page =~ /[\x00-\x20\x7F]/ ? 0 : 1; |
|
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; |
|
|
} |
|
740 |
} |
} |
741 |
|
|
742 |
sub decode { |
sub decode { |
747 |
} |
} |
748 |
|
|
749 |
sub encode { |
sub encode { |
750 |
my ($s) = @_; |
my $s = shift; |
751 |
my $encoded = ''; |
$s =~ s/([^0-9A-Za-z_-])/sprintf '%%%02X', ord $1/ge; |
752 |
foreach my $ch (split(//, $s)) { |
$s; |
|
if ($ch =~ /[A-Za-z0-9_]/) { |
|
|
$encoded .= $ch; |
|
|
} else { |
|
|
$encoded .= '%' . sprintf("%02X", ord($ch)); |
|
|
} |
|
|
} |
|
|
return $encoded; |
|
|
} |
|
|
|
|
|
sub init_resource { |
|
|
open(FILE, $file_resource) or &print_error("(resource)"); |
|
|
while (<FILE>) { |
|
|
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('', <FILE>); |
|
|
&code_convert(\$content, $kanjicode); |
|
|
close(FILE); |
|
|
&print_header($page, -noindex => 1); |
|
|
&print_content($content); |
|
|
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
|
|
&print_footer($page); |
|
|
return 1; |
|
753 |
} |
} |
754 |
|
|
755 |
sub get_now { |
sub get_now { |
756 |
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
my ($sec, $min, $hour, $day, $mon, $year) = localtime(time); |
|
my (@week) = qw(日 月 火 水 木 金 土); |
|
|
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
|
757 |
$year += 1900; |
$year += 1900; |
758 |
$mon++; |
$mon++; |
759 |
$mon = "0$mon" if $mon < 10; |
$mon = "0$mon" if $mon < 10; |
761 |
$hour = "0$hour" if $hour < 10; |
$hour = "0$hour" if $hour < 10; |
762 |
$min = "0$min" if $min < 10; |
$min = "0$min" if $min < 10; |
763 |
#$sec = "0$sec" if $sec < 10; |
#$sec = "0$sec" if $sec < 10; |
764 |
$weekday = $week[$weekday]; |
return "$year-$mon-$day $hour:$min"; |
|
return "$year-$mon-$day ($weekday) $hour:$min"; |
|
765 |
} |
} |
766 |
|
|
|
# [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]] |
|
767 |
sub init_InterWikiName { |
sub init_InterWikiName { |
768 |
my $content = $database{$InterWikiName}; |
my @content = split /\n/, $database{InterWikiName}; |
769 |
while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) { |
for (@content) { |
770 |
my ($name, $url) = ($1, $2); |
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
771 |
$interwiki{$name} = $url; |
$interwiki{$1} = $2; |
|
} |
|
|
} |
|
|
|
|
|
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"; |
|
772 |
} |
} |
773 |
$infobase{$page} = $s; |
} |
774 |
|
$interwiki{'[[]]'} = 1; ## dummy |
775 |
} |
} |
776 |
|
|
777 |
sub frozen_reject { |
sub frozen_reject { |
778 |
my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); |
my ($isfrozen) = $database->meta (IsFrozen => $form{mypage}); |
779 |
my ($willbefrozen) = $form{myfrozen}; |
my ($willbefrozen) = $form{myfrozen}; |
780 |
if (not $isfrozen and not $willbefrozen) { |
if (not $isfrozen and not $willbefrozen) { |
781 |
# You need no check. |
# You need no check. |
784 |
# You are admin. |
# You are admin. |
785 |
return 0; |
return 0; |
786 |
} else { |
} else { |
787 |
&print_error($resource{passworderror}); |
&_do_view_msg (-view => '-error', -page => $form{mypage}, |
788 |
return 1; |
error_message => &Resource ('Error:PasswordIsIncorrect')); |
789 |
} |
exit; |
|
} |
|
|
|
|
|
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; |
|
790 |
} |
} |
791 |
} |
} |
792 |
|
|
793 |
sub is_frozen { |
sub is_frozen ($) { $database->meta (IsFrozen => $_[0]) ? 1 : 0 } |
|
my ($page) = @_; |
|
|
if (&get_info($page, $info_IsFrozen)) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
794 |
|
|
795 |
sub do_comment { |
sub do_comment { |
796 |
my ($content) = $database{$form{mypage}}; |
my ($content) = $database{$form{mypage}}; |
797 |
my $default_name; ## this code does not strict. |
my $default_name; ## this code is not strict. |
798 |
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
799 |
my $datestr = '[WEAK['.&get_now.']]'; |
my $datestr = '[WEAK['.&get_now.']]'; |
800 |
my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; |
my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName'); |
801 |
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
802 |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
803 |
$namestr = qq( ''$namestr'': ); |
$namestr = qq( ''$namestr'': ); |
804 |
} elsif (length $namestr) { |
} elsif (length $namestr) { |
805 |
$namestr = qq( ''[[$namestr]]'': ); |
$namestr = qq( ''[[$namestr]]'': ); |
806 |
} |
} |
807 |
my $anchor = 0; |
my $anchor = &get_new_anchor_index ($content); |
|
$content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
|
|
$anchor++; |
|
808 |
my $i = 1; my $o = 0; |
my $i = 1; my $o = 0; |
809 |
$content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ |
$content =~ s{(\[\[\#r?comment\]\])}{ |
810 |
my $embed = $1; |
my $embed = $1; |
811 |
if ($i == $form{comment_index}) { |
if ($i == $form{comment_index}) { |
812 |
if ($embed eq $embed_comment) { |
if ($embed ne '[[#rcomment]]') { |
813 |
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
814 |
} else { |
} else { |
815 |
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
827 |
$form{mymsg} = $content; |
$form{mymsg} = $content; |
828 |
$form{mytouch} = 'on'; |
$form{mytouch} = 'on'; |
829 |
&do_write; |
&do_write; |
830 |
} else { |
} else { ## Don't write |
831 |
$form{mycmd} = 'read'; |
$form{mycmd} = 'default'; |
832 |
&do_read; |
&do_view; |
833 |
} |
} |
834 |
} |
} |
835 |
|
|
836 |
|
sub get_new_anchor_index ($) { |
837 |
|
my $content = shift; |
838 |
|
my $anchor = 0; |
839 |
|
$content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
840 |
|
$anchor + 1; |
841 |
|
} |
842 |
|
|
843 |
my $CommentIndex = 0; |
my $CommentIndex = 0; |
844 |
sub embedded_to_html { |
sub embedded_to_html { |
845 |
my ($embedded) = @_; |
my ($embedded) = @_; |
846 |
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') { |
847 |
unless ($main::_EMBEDED) { |
unless ($main::_EMBEDED) { |
848 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
my $lastmodified = $database->mtime ($form{mypage}); |
849 |
return <<"EOD"; |
return <<"EOD"; |
850 |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
851 |
<input type="hidden" name="mycmd" value="comment"> |
<input type="hidden" name="mycmd" value="comment" /> |
852 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
<input type="hidden" name="mypage" value="$form{mypage}" /> |
853 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
<input type="hidden" name="myLastModified" value="$lastmodified" /> |
854 |
<input type="hidden" name="mytouch" value="on"> |
<input type="hidden" name="mytouch" value="on" /> |
855 |
<input type="hidden" name="comment_index" value="$CommentIndex"> |
<input type="hidden" name="comment_index" value="$CommentIndex" /> |
856 |
$embed_comment_Name_Prompt |
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
857 |
<input type="text" name="myname" value="" size="10" class="comment-name"> |
<input type="text" name="myname" value="" size="10" class="comment-name" /> |
858 |
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
<input type="text" name="mymsg" value="" size="60" class="comment-msg" /> |
859 |
<input type="submit" value="$resource{commentbutton}" class="comment-submit"> |
<input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit" /> |
860 |
</p></form> |
</p></form> |
861 |
EOD |
EOD |
862 |
} else { |
} else { |
863 |
return <<"EOD"; |
return <<"EOD"; |
864 |
<del><form action="$url_cgi" method="get"> |
<del><form action="$url_cgi" method="get"> |
865 |
<input type="hidden" name="mycmd" value="read"> |
<input type="hidden" name="mycmd" value="default" /> |
866 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
<input type="hidden" name="mypage" value="$form{mypage}" /> |
867 |
$embed_comment_Name_Prompt |
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
868 |
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
<input type="text" name="myname" value="" size="10" disabled="disabled" /> |
869 |
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
<input type="text" name="mymsg" value="" size="60" disabled="disabled" /> |
|
<input type="submit" value="$resource{commentbutton}" disabled="disabled"> |
|
870 |
</form></del> |
</form></del> |
871 |
EOD |
EOD |
872 |
} |
} |
873 |
} elsif ($embedded =~ /$embed_command{searched}/) { |
} elsif ($embedded =~ /$embed_command{searched}/) { |
874 |
return get_search_result ($1, -match_myself => 1); |
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 |
|
875 |
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
876 |
my ($name, $r) = ($1, ''); |
my ($name, $r) = ($1, ''); |
877 |
if ($main::_EMBEDED != 1) { |
if ($main::_EMBEDED != 1) { |
878 |
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
my ($cf, $content) = SuikaWiki::Plugin->magic_and_conten ($database{$name}); |
879 |
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
$cf ||= '#?SuikaWiki/0.9'; |
880 |
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
if ($cf =~ m!^#\?SuikaWiki/0.9(?:$|\s)!) { |
881 |
$main::_EMBEDED = 1; |
$main::_EMBEDED = 1; |
882 |
$r = &text_to_html ($content, content_format => $cf); |
$r = &text_to_html ($content, magic => $cf, page => $name); |
883 |
$main::_EMBEDED = 0; |
$main::_EMBEDED = 0; |
884 |
} elsif (length $content) { |
} elsif (length $content) { |
885 |
$r = "<pre>@{[&escape ($content)]}</pre>"; |
$r = "<pre>@{[&escape ($content)]}</pre>"; |
886 |
} else { |
} else { |
887 |
$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'); |
888 |
} |
} |
889 |
} else { ## nested #EMBED |
} else { ## nested #EMBED |
890 |
$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'); |
891 |
} |
} |
892 |
return qq(<blockquote title="@{[&escape($name)]}">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>); |
return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>); |
893 |
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
894 |
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
895 |
} else { |
} else { |
897 |
} |
} |
898 |
} |
} |
899 |
|
|
900 |
# Walrus add (5) start |
sub load_formatter (@) { |
901 |
sub do_interwiki_box { |
for my $t (@_) { |
902 |
my $remoteurl = $interwiki{$form{'myintername'}}; |
unless ($fmt{$t}) { |
903 |
if ($remoteurl) { |
require Message::Util::Formatter; |
904 |
$remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e; |
$fmt{$t} = Message::Util::Formatter->new; |
905 |
print "Location: $remoteurl\n\n"; |
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
906 |
exit(1); |
$_->load_formatter ($fmt{$t}, type => 'wiki'.$t); |
907 |
} else { |
} |
908 |
&do_read; |
} |
909 |
} |
} |
910 |
} |
} |
|
# Walrus add (5) end |
|
911 |
|
|
912 |
# Walrus add (5) start |
sub do_wikiform { |
913 |
sub make_interwiki_box { |
my $content = $database{$form{mypage}}; |
914 |
my ($localname, $intername) = @_; |
my $anchor = &get_new_anchor_index ($content); |
915 |
my %ignoretype = ( |
&load_formatter (qw/form_template form_option/); |
916 |
'box' => 'text', |
my $write = 0; |
917 |
'text' => 'text', |
my $i = 1; |
918 |
'pass' => 'password', |
$content =~ s{$embed_command{form}}{ |
919 |
'password' => 'password' |
my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4); |
920 |
); |
if (($wfname && $wfname eq $form{wikiform_targetform}) |
921 |
my $converted = ($ignoretype{$localname}) ? <<EOD : undef; |
|| $i == $form{wikiform_index}) { |
922 |
<form action="$url_cgi" method="post"> |
$template =~ s/\\(.)/$1/g; |
923 |
<input type="hidden" name="mycmd" value="interwikibox"> |
$option =~ s/\\(.)/$1/g; |
924 |
<input type="hidden" name="mypage" value="$form{mypage}"> |
my $param = bless {depth=>10}, 'SuikaWiki::Plugin'; |
925 |
<input type="hidden" name="myintername" value="$intername"> |
$param->{page} = $form{mypage}; |
926 |
$intername: |
$param->{form_index} = $i; |
927 |
<input type="$ignoretype{$localname}" name="mylocalname" value="" size="10"> |
$param->{form_name} = $wfname; |
928 |
<input type="submit" value="Submit"> |
$param->{anchor_index} = $anchor; |
929 |
</form> |
$param->{argv} = \%form; |
930 |
EOD |
$param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; |
931 |
|
$param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName'); |
932 |
|
$fmt{form_option}->replace ($option, $param); |
933 |
|
my $t = 1; |
934 |
|
for (keys %{$param->{require}||{}}) { |
935 |
|
(undef $t, last) unless length $param->{argv}->{'wikiform__'.$_}; |
936 |
|
} |
937 |
|
$t = $fmt{form_template}->replace ($template, $param) if $t; |
938 |
|
if (length $t) { |
939 |
|
if ($param->{output}->{reverse}) { |
940 |
|
$embed .= "\n" . $t; |
941 |
|
} else { |
942 |
|
$embed = $t . "\n" . $embed; |
943 |
|
} |
944 |
|
$write = 1; |
945 |
|
$form{__comment_anchor_index} = $anchor |
946 |
|
if $param->{anchor_index_}; ## $anchor is used! |
947 |
|
} |
948 |
|
$form{__wikiform_anchor_index} = $i; |
949 |
|
undef $form{wikiform_targetform}; ## Make sure never to match |
950 |
|
undef $form{wikiform_index}; ## with WikiForm in rest of page! |
951 |
|
} |
952 |
|
$i++; $embed; |
953 |
|
}ge; |
954 |
|
unless ($write) { |
955 |
|
#$content = "#?SuikaWiki/0.9\n\n" unless $content; |
956 |
|
#$content .= "\n" unless $content =~ /\n$/s; |
957 |
|
# |
958 |
|
} |
959 |
|
if ($write) { |
960 |
|
$form{mymsg} = $content; |
961 |
|
$form{mytouch} = 'on'; |
962 |
|
&do_write; |
963 |
|
} else { ## Don't write! |
964 |
|
$form{mycmd} = 'default'; |
965 |
|
&do_view; |
966 |
|
} |
967 |
} |
} |
|
# Walrus add (5) end |
|
968 |
|
|
969 |
sub code_convert { |
sub code_convert { |
970 |
|
require Jcode; |
971 |
my ($contentref, $code) = (shift, shift || $kanjicode); |
my ($contentref, $code) = (shift, shift || $kanjicode); |
972 |
# &Jcode::convert($contentref, $code); # for Jcode.pm |
if ($code =~ /euc/) { $code = 'euc' } |
973 |
&jcode::convert($contentref, $code); # for jcode.pl |
elsif ($code =~ /iso/) { $code = 'jis' } |
974 |
|
elsif ($code =~ /shi/) { $code = 'sjis' } |
975 |
|
elsif ($code =~ /utf/) { $code = 'utf8' } |
976 |
|
$$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; |
977 |
return $$contentref; |
return $$contentref; |
978 |
} |
} |
979 |
|
|
980 |
sub test_convert { |
sub _rfc3339_date ($) { |
981 |
my $txt = &text_to_html(<<"EOD", toc=>1); |
my @time = gmtime (shift); |
982 |
*HEADER1 |
sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0]; |
|
**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; |
|
983 |
} |
} |
984 |
|
|
985 |
sub do_diff { |
my %_Resource; |
986 |
if (not &is_editable($form{mypage})) { |
sub Resource ($;%) { |
987 |
&do_read; |
my ($s, %o) = @_; |
988 |
return; |
unless (defined $_Resource{$s}) { |
989 |
} |
$_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option}); |
990 |
&open_diff; |
} |
991 |
my $title = $form{mypage}; |
$o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s}; |
|
&print_header($title, -noindex => 1); |
|
|
$_ = &escape($diffbase{$form{mypage}}); |
|
|
&close_diff; |
|
|
print qq(<h3>$resource{difftitle}</h3>); |
|
|
print qq($resource{diffnotice}); |
|
|
print qq(<pre class="diff">); |
|
|
foreach (split(/\n/, $_)) { |
|
|
if (/^\+(.*)/) { |
|
|
print qq(<b class="added">$1</b>\n); |
|
|
} elsif (/^\-(.*)/) { |
|
|
print qq(<s class="deleted">$1</s>\n); |
|
|
} elsif (/^\=(.*)/) { |
|
|
print qq(<span class="same">$1</span>\n); |
|
|
} else { |
|
|
print qq|??? $_\n|; |
|
|
} |
|
|
} |
|
|
print qq(</pre>); |
|
|
print qq(<hr>); |
|
|
&print_footer($title); |
|
|
} |
|
|
|
|
|
sub do_rss { |
|
|
my $rss = new Yuki::RSS( |
|
|
version => '1.0', |
|
|
encoding => $charset, |
|
|
); |
|
|
$rss->channel( |
|
|
title => $modifier_rss_title, |
|
|
link => $modifier_rss_link, |
|
|
description => $modifier_rss_description, |
|
|
); |
|
|
my $recentchanges = $database{$RecentChanges}; |
|
|
my $count = 0; |
|
|
foreach (split(/\n/, $recentchanges)) { |
|
|
last if ($count >= 15); |
|
|
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format. |
|
|
my $title = &unarmor_name($1); |
|
|
my $escaped_title = &escape($title); |
|
|
my $link = $modifier_rss_link . '?' . &encode($title); |
|
|
my $description = $escaped_title . &escape(&get_subjectline($title)); |
|
|
$rss->add_item( |
|
|
title => $escaped_title, |
|
|
link => $link, |
|
|
description => $description, |
|
|
); |
|
|
$count++; |
|
|
} |
|
|
# print RSS information (as XML). |
|
|
print <<"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}; |
|
|
} |
|
992 |
} |
} |
993 |
|
|
|
sub __get_database ($) { $database{ $_[0] } } |
|
|
|
|
994 |
package wiki::referer; |
package wiki::referer; |
995 |
sub add ($$) { |
sub add ($$) { |
996 |
my $page = shift; |
my $page = shift; |
1011 |
$list{ $uri }++; |
$list{ $uri }++; |
1012 |
set ($page, \%list); |
set ($page, \%list); |
1013 |
} |
} |
1014 |
sub get ($) { |
sub get ($) { split /"/, $main::database->meta (Referer => $_[0]) } |
|
my $page = shift; |
|
|
split /"/, main::get_info ($page, 'Referer'); |
|
|
} |
|
1015 |
sub set ($%) { |
sub set ($%) { |
1016 |
my $page = shift; |
my $page = shift; |
1017 |
my $list = shift; |
my $list = shift; |
1018 |
main::set_info ($page, Referer => join '"', %$list); |
$main::database->meta (Referer => $page => join '"', %$list); |
1019 |
} |
} |
1020 |
|
|
1021 |
sub get_dont_record () { |
sub get_dont_record () { |
1022 |
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
1023 |
grep !/^#/, |
grep !/^#/, |
1024 |
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
split /[\x0D\x0A]+/, $main::database{RefererDontRecord}; |
1025 |
} |
} |
1026 |
sub get_site_name () { |
sub get_site_name () { |
1027 |
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, $main::database{RefererSiteName}; |
1028 |
my @item; |
my @item; |
1029 |
for (@lines) { |
for (@lines) { |
1030 |
next if /^#/; |
next if /^#/; |
1053 |
} |
} |
1054 |
my $euri = main::escape ($uri); |
my $euri = main::escape ($uri); |
1055 |
if ($title) { |
if ($title) { |
1056 |
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
1057 |
} else { |
} else { |
1058 |
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
1059 |
} |
} |
1068 |
main::code_convert (\$s); |
main::code_convert (\$s); |
1069 |
} |
} |
1070 |
|
|
1071 |
|
package wiki::useragent; |
1072 |
|
our $UseLog; |
1073 |
|
|
1074 |
|
sub add ($) { |
1075 |
|
my $s = shift; |
1076 |
|
return unless length $s; |
1077 |
|
return unless $UseLog; |
1078 |
|
$s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge; |
1079 |
|
my %ua; |
1080 |
|
for (split /\n/, $main::database{$main::PageName{UserAgentList}}) { |
1081 |
|
if (/^-\[(\d+)\] (.+)$/) { |
1082 |
|
my ($t, $n) = ($1, $2); |
1083 |
|
$n =~ tr/\x0A\x0D//d; |
1084 |
|
$ua{$n} = $t; |
1085 |
|
} |
1086 |
|
} |
1087 |
|
$ua{$s}++; |
1088 |
|
my $s = qq(#?SuikaWiki/0.9\n); |
1089 |
|
for (sort {$ua{$a} <=> $ua{$b}} keys %ua) { |
1090 |
|
$s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_; |
1091 |
|
} |
1092 |
|
$main::database->STORE ($main::PageName{UserAgentList} => $s, -touch => 0); |
1093 |
|
} |
1094 |
|
|
1095 |
|
package wiki::suikawikiconst; |
1096 |
|
|
1097 |
|
sub to_hash ($;$) { |
1098 |
|
my $page = shift; |
1099 |
|
my $h = shift || {}; |
1100 |
|
my $val; |
1101 |
|
for my $line (split /\n/, $page) { |
1102 |
|
next if $line =~ /^#/; |
1103 |
|
$line =~ tr/\x0A\x0D//d; |
1104 |
|
if ($val && $line =~ s/^\s+//) { |
1105 |
|
$h->{$val} .= length $h->{$val} ? "\n" . $line : $line; |
1106 |
|
} elsif ($line =~ /^(.+):/) { |
1107 |
|
$val = $1; $h->{$val} = ''; |
1108 |
|
} |
1109 |
|
} |
1110 |
|
$h; |
1111 |
|
} |
1112 |
|
|
1113 |
|
package wiki::dummy; |
1114 |
|
sub mtime (@) {undef} |
1115 |
|
sub meta (@) {undef} |
1116 |
|
sub Yuki::YukiWikiDB2::meta (@) {undef} |
1117 |
|
|
1118 |
|
package SuikaWiki::Plugin; |
1119 |
|
our ($plugin_directory, %List, %Index, %Cache); |
1120 |
|
push @main::INC, $plugin_directory.'/../..'; |
1121 |
|
|
1122 |
|
sub escape ($$) { main::escape ($_[1]) } |
1123 |
|
sub unescape ($$) { main::unescape ($_[1]) } |
1124 |
|
sub encode ($$) { main::encode ($_[1]) } |
1125 |
|
sub decode ($$) { main::decode ($_[1]) } |
1126 |
|
sub __get_datetime ($) { main::get_now () } |
1127 |
|
sub resource ($$;%) { shift; &main::Resource (@_) } |
1128 |
|
sub uri ($$) { $main::uri{$_[1]} } |
1129 |
|
sub new_index ($$) { ++$Index{$_[1]} } |
1130 |
|
sub user_agent_names ($) { $main::UA } |
1131 |
|
sub magic_and_content ($$) { |
1132 |
|
my ($magic, $page) = ('', $_[1]); |
1133 |
|
$magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; |
1134 |
|
($magic, $page); |
1135 |
|
} |
1136 |
|
sub formatter ($$) { |
1137 |
|
&main::load_formatter ($_[1]); |
1138 |
|
$main::fmt{$_[1]}; |
1139 |
|
} |
1140 |
|
sub format_converter ($$$) { |
1141 |
|
&main::load_formatter ('format'); |
1142 |
|
$main::fmt{format}->{($_[1]=~/([A-Za-z0-9]\S+)/?$1:'SuikaWiki/0.9').'_to_'.$_[2]} |
1143 |
|
|| $main::fmt{format}->{($_[1]=~/([A-Za-z0-9](?:(?!\/)\S)+)/?$1:'SuikaWiki').'_to_'.$_[2]}; |
1144 |
|
} |
1145 |
|
sub cache ($$) { |
1146 |
|
my $name = $_[1]; |
1147 |
|
unless (ref $Cache{$name}) { |
1148 |
|
my %cache; |
1149 |
|
tie (%cache, 'Yuki::YukiWikiCache', -file => $main::PathTo{CachePrefix}.$name); |
1150 |
|
$Cache{$name} = \%cache; |
1151 |
|
} |
1152 |
|
$Cache{$name}; |
1153 |
|
} |
1154 |
|
|
1155 |
|
sub regist ($@) { |
1156 |
|
my $pack = shift; |
1157 |
|
for (@_) { |
1158 |
|
push @{$List{$_}}, $pack; |
1159 |
|
} |
1160 |
|
} |
1161 |
|
|
1162 |
|
sub import_plugins () { |
1163 |
|
opendir PDIR, $plugin_directory; |
1164 |
|
my @plugin = grep {s/\.pm$//} readdir (PDIR); |
1165 |
|
closedir PDIR; |
1166 |
|
for (@plugin) { |
1167 |
|
eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/; |
1168 |
|
push @{$List{_all}}, qq(SuikaWiki::Plugin::$_); |
1169 |
|
} |
1170 |
|
} |
1171 |
|
|
1172 |
|
&import_plugins (); |
1173 |
|
|
1174 |
|
package wiki::conneg; |
1175 |
|
|
1176 |
|
## BUG: this parser isn't strict. |
1177 |
|
sub get_accept_lang (;$) { |
1178 |
|
my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE}; |
1179 |
|
my %alang = (ja => 0.0002, en => 0.0001); |
1180 |
|
if ($UA =~ m#Mozilla/0\.#) { |
1181 |
|
$alang{ja} = 0.00001; |
1182 |
|
} |
1183 |
|
my $i = 0.1; |
1184 |
|
for (split /\s*,\s*/, $alang) { |
1185 |
|
tr/\x09\x0A\x0D\x20//d; |
1186 |
|
if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) { |
1187 |
|
my $l = lc $1; $l =~ tr/\x22\x5C//d; |
1188 |
|
$alang{$l} = (defined $2 ? $2 : 1.000)*1000; |
1189 |
|
$alang{$l} += $i unless $alang{$l} == 0; |
1190 |
|
$i -= 0.001; |
1191 |
|
} |
1192 |
|
} |
1193 |
|
\%alang; |
1194 |
|
} |
1195 |
|
|
1196 |
|
package wiki::resource; |
1197 |
|
|
1198 |
|
sub get ($;\%) { |
1199 |
|
my ($resname, $option) = @_; |
1200 |
|
$option->{accept_language} ||= &wiki::conneg::get_accept_lang (); |
1201 |
|
$option->{resource} ||= {}; |
1202 |
|
my $v; |
1203 |
|
for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) { |
1204 |
|
while (length $lang) { |
1205 |
|
unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) { |
1206 |
|
$option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash ($main::database{'WikiResource:'.$lang}); |
1207 |
|
$v = $option->{resource}->{$lang}->{$resname}; |
1208 |
|
last if defined $v; |
1209 |
|
} |
1210 |
|
$lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//; |
1211 |
|
} |
1212 |
|
last if defined $v; |
1213 |
|
} |
1214 |
|
defined $v ? $v : $resname; |
1215 |
|
} |
1216 |
|
|
1217 |
|
package main; |
1218 |
|
&main; |
1219 |
|
exit 0; |
1220 |
|
|
1221 |
1; |
1; |
1222 |
__END__ |
__END__ |
1223 |
=head1 NAME |
=head1 NAME |
1224 |
|
|
1225 |
wiki.cgi - This is YukiWiki, yet another Wiki clone. |
wiki.cgi --- SuikaWiki: Yet yet another WikiEngine |
1226 |
|
|
1227 |
=head1 DESCRIPTION |
=head1 SEE ALSO |
1228 |
|
|
1229 |
YukiWiki is yet another Wiki clone. |
<IW:SuikaWiki:SuikaWiki> |
1230 |
|
|
1231 |
YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]). |
=head1 AUTHORS |
|
YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS), |
|
|
and some embedded commands (such as [[#comment]] to add comments). |
|
1232 |
|
|
1233 |
Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail. |
Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/> |
1234 |
|
|
1235 |
=head1 AUTHOR |
Makio Tsukamoto <http://digit.que.ne.jp/> |
1236 |
|
|
1237 |
Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/ |
Wakaba <w@suika.fam.cx> |
1238 |
|
|
1239 |
=head1 LICENSE |
=head1 LICENSE |
1240 |
|
|
1241 |
Copyright (C) 2000-2002 by Hiroshi Yuki. |
Copyright (C) 2000-2003 AUTHORS |
1242 |
|
|
1243 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
1244 |
modify it under the same terms as Perl itself. |
modify it under the same terms as Perl itself. |