1 |
wakaba |
1.9 |
#!/usr/bin/perl |
2 |
|
|
# |
3 |
wakaba |
1.16 |
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
4 |
wakaba |
1.9 |
# |
5 |
wakaba |
1.16 |
# Copyright (C) 2000-2002 by Hiroshi Yuki. |
6 |
wakaba |
1.9 |
# <hyuki@hyuki.com> |
7 |
|
|
# http://www.hyuki.com/yukiwiki/ |
8 |
|
|
# |
9 |
wakaba |
1.16 |
# This program is free software; you can redistribute it and/or |
10 |
|
|
# modify it under the same terms as Perl itself. |
11 |
wakaba |
1.9 |
# |
12 |
wakaba |
1.16 |
# walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
13 |
|
|
|
14 |
|
|
# Walrus add (debug) start |
15 |
|
|
my $walrus_log; |
16 |
|
|
my $walrus_debugging = 0; |
17 |
|
|
# Walrus add (debug) end |
18 |
|
|
|
19 |
|
|
# Libraries. |
20 |
|
|
use strict; |
21 |
|
|
use lib qw(./WalWiki/lib); |
22 |
|
|
use CGI qw(:standard); |
23 |
|
|
use CGI::Carp qw(fatalsToBrowser); |
24 |
|
|
use Yuki::RSS; |
25 |
|
|
use Yuki::DiffText qw(difftext); |
26 |
|
|
use Yuki::YukiWikiDB; |
27 |
|
|
use AnyDBM_File; |
28 |
|
|
require 'jcode.pl'; |
29 |
|
|
# use Jcode; |
30 |
|
|
use Fcntl; |
31 |
|
|
my $version = '2.0.beta1.2002-05-29'; |
32 |
wakaba |
1.17 |
my $walversion; |
33 |
wakaba |
1.9 |
############################## |
34 |
wakaba |
1.16 |
# |
35 |
|
|
# You MUST modify following '$modifier_...' variables. |
36 |
|
|
# |
37 |
|
|
my $modifier_mail = 'w@suika.fam.cx'; # Your mail address, like 'walrus@digit.que.ne.jp'. |
38 |
|
|
my $modifier_url = 'http://suika.fam.cx/~wakaba/'; # Your web page, like 'http://digit.que.ne.jp/work/'. |
39 |
|
|
my $modifier_name = '和'; # Your name, like 'Makio Tsukamoto'. |
40 |
|
|
# my $modifier_dbtype = 'AnyDBM_File'; # Fast, not available on some server, page size limited. |
41 |
|
|
# my $modifier_dbtype = 'dbmopen'; # Fast, not available on some server, page size limited. |
42 |
|
|
my $modifier_dbtype = 'YukiWikiDB'; # Slow, available on all environment. |
43 |
|
|
# my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail. |
44 |
|
|
my $modifier_sendmail = ''; # If you don't need mail notification. |
45 |
wakaba |
1.17 |
my $modifier_dir_data = './wikidata'; # Your data directory. |
46 |
wakaba |
1.27 |
my $modifier_rss_title = "SuikaWiki $walversion"; |
47 |
wakaba |
1.16 |
my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed. |
48 |
wakaba |
1.27 |
my $modifier_rss_description = 'This is SuikaWiki'; |
49 |
wakaba |
1.9 |
############################## |
50 |
wakaba |
1.16 |
# |
51 |
|
|
# You MAY modify following variables. |
52 |
|
|
# |
53 |
|
|
my $file_touch = "$modifier_dir_data/touched.txt"; |
54 |
|
|
my $file_resource = "$modifier_dir_data/resource.txt"; |
55 |
|
|
my $file_FrontPage = "$modifier_dir_data/frontpage.txt"; |
56 |
|
|
my $file_conflict = "$modifier_dir_data/conflict.txt"; |
57 |
|
|
my $file_format = "$modifier_dir_data/format.txt"; |
58 |
wakaba |
1.28 |
my $url_cgi = '/~wakaba/-temp/wiki/wiki'; ## MUST be started from '/' |
59 |
wakaba |
1.25 |
my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle'; |
60 |
wakaba |
1.16 |
my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />'; |
61 |
|
|
my $maxrecent = 50; |
62 |
wakaba |
1.9 |
my $cols = 80; |
63 |
|
|
my $rows = 20; |
64 |
|
|
############################## |
65 |
wakaba |
1.16 |
# |
66 |
|
|
# You MAY, but do NOT NEED modify following variables. |
67 |
|
|
# |
68 |
|
|
my $dataname = "$modifier_dir_data/wiki"; |
69 |
|
|
my $infoname = "$modifier_dir_data/info"; |
70 |
|
|
my $diffname = "$modifier_dir_data/diff"; |
71 |
|
|
my $editchar = '?'; |
72 |
|
|
my $subject_delimiter = ' - '; |
73 |
|
|
my $use_autoimg = 1; # automatically convert image URL into <img> tag. |
74 |
|
|
my $use_exists = 0; # If you can use 'exists' method for your DB. |
75 |
|
|
############################## |
76 |
|
|
my $InterWikiName = 'InterWikiName'; |
77 |
|
|
my $RecentChanges = 'RecentChanges'; |
78 |
|
|
my $AdminChangePassword = 'AdminChangePassword'; |
79 |
|
|
my $CompletedSuccessfully = 'CompletedSuccessfully'; |
80 |
wakaba |
1.18 |
my $FrontPage = 'HomePage'; |
81 |
wakaba |
1.16 |
my $IndexPage = 'IndexPage'; |
82 |
|
|
my $SearchPage = 'SearchPage'; |
83 |
|
|
my $CreatePage = 'CreatePage'; |
84 |
|
|
my $ErrorPage = 'ErrorPage'; |
85 |
|
|
my $RssPage = 'RssPage'; |
86 |
wakaba |
1.26 |
my $NAME_OF_WikiPageLicense = 'WikiPageLicense'; |
87 |
wakaba |
1.16 |
my $AdminSpecialPage = 'Admin Special Page'; # must include spaces. |
88 |
|
|
############################## |
89 |
|
|
my $bracket_name = '\[\[(\S+?)\]\]'; |
90 |
|
|
my $embedded_name = '\[\[(#\S+?)\]\]'; |
91 |
wakaba |
1.31 |
my %fmt; ## formatter objects |
92 |
wakaba |
1.16 |
############################## |
93 |
|
|
my $embed_comment = '[[#comment]]'; |
94 |
|
|
my $embed_rcomment = '[[#rcomment]]'; |
95 |
wakaba |
1.25 |
my $embed_comment_Name_Prompt = '名前:'; |
96 |
|
|
my $DEFAULT_embed_comment_name = '名無しさん'; |
97 |
wakaba |
1.16 |
my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5) |
98 |
wakaba |
1.22 |
my %embed_command = ( |
99 |
|
|
searched => '^\[\[#searched:([^\]]+)\]\]$', |
100 |
|
|
); |
101 |
wakaba |
1.16 |
############################## |
102 |
|
|
my $info_LastModified = 'LastModified'; |
103 |
|
|
my $info_IsFrozen = 'IsFrozen'; |
104 |
|
|
my $info_AdminPassword = 'AdminPassword'; |
105 |
|
|
############################## |
106 |
|
|
my $kanjicode = 'euc'; |
107 |
|
|
my $charset = 'EUC-JP'; |
108 |
|
|
my $lang = 'ja'; |
109 |
|
|
my %fixedpage = ( |
110 |
|
|
$IndexPage => 1, |
111 |
|
|
$CreatePage => 1, |
112 |
|
|
$ErrorPage => 1, |
113 |
|
|
$RssPage => 1, |
114 |
|
|
$RecentChanges => 1, |
115 |
|
|
$SearchPage => 1, |
116 |
|
|
$AdminChangePassword => 1, |
117 |
|
|
$CompletedSuccessfully => 1, |
118 |
wakaba |
1.18 |
#$FrontPage => 1, |
119 |
wakaba |
1.16 |
); |
120 |
|
|
my %form; |
121 |
|
|
my %database; |
122 |
|
|
my %infobase; |
123 |
|
|
my %diffbase; |
124 |
|
|
my %resource; |
125 |
|
|
my %interwiki; |
126 |
|
|
############################## |
127 |
|
|
my %page_command = ( |
128 |
|
|
$IndexPage => 'index', |
129 |
|
|
$SearchPage => 'searchform', |
130 |
|
|
$CreatePage => 'create', |
131 |
|
|
$RssPage => 'rss', |
132 |
|
|
$AdminChangePassword => 'adminchangepasswordform', |
133 |
wakaba |
1.18 |
#$FrontPage => 'FrontPage', |
134 |
wakaba |
1.16 |
); |
135 |
|
|
my %command_do = ( |
136 |
|
|
read => \&do_read, |
137 |
wakaba |
1.25 |
TEXT_CSS => \&do_output_css, |
138 |
wakaba |
1.16 |
edit => \&do_edit, |
139 |
|
|
adminedit => \&do_adminedit, |
140 |
|
|
adminchangepasswordform => \&do_adminchangepasswordform, |
141 |
|
|
adminchangepassword => \&do_adminchangepassword, |
142 |
|
|
write => \&do_write, |
143 |
|
|
index => \&do_index, |
144 |
|
|
searchform => \&do_searchform, |
145 |
|
|
search => \&do_search, |
146 |
|
|
create => \&do_create, |
147 |
|
|
createresult => \&do_createresult, |
148 |
|
|
FrontPage => \&do_FrontPage, |
149 |
|
|
comment => \&do_comment, |
150 |
wakaba |
1.28 |
RandomJump => \&do_random_jump, |
151 |
wakaba |
1.16 |
rss => \&do_rss, |
152 |
|
|
diff => \&do_diff, |
153 |
|
|
interwikibox => \&do_interwiki_box, # Walrus add (5) |
154 |
|
|
); |
155 |
|
|
############################## |
156 |
|
|
my @ignore_html_page = ('FrontPage'); # Walrus add (6) |
157 |
|
|
my @ignore_html_tags = ('a', 'br', 'img'); # Walrus add (6) |
158 |
|
|
my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) |
159 |
wakaba |
1.9 |
############################## |
160 |
wakaba |
1.16 |
# &test_convert; |
161 |
wakaba |
1.9 |
&main; |
162 |
|
|
exit(0); |
163 |
wakaba |
1.16 |
############################## |
164 |
wakaba |
1.9 |
|
165 |
|
|
sub main { |
166 |
wakaba |
1.16 |
&init_resource; |
167 |
|
|
&open_db; |
168 |
|
|
&init_form; |
169 |
|
|
&init_InterWikiName; |
170 |
|
|
if ($command_do{$form{mycmd}}) { |
171 |
|
|
&{$command_do{$form{mycmd}}}; |
172 |
wakaba |
1.9 |
} else { |
173 |
wakaba |
1.16 |
&do_FrontPage; |
174 |
wakaba |
1.9 |
} |
175 |
wakaba |
1.16 |
&close_db; |
176 |
wakaba |
1.9 |
} |
177 |
|
|
|
178 |
|
|
sub do_read { |
179 |
wakaba |
1.26 |
my $content = $database{$form{mypage}}; |
180 |
wakaba |
1.27 |
my $lm = &get_info($form{mypage}, $info_LastModified); |
181 |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
182 |
wakaba |
1.29 |
my ($r, $c) = get_search_result ($form{mypage}); |
183 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
184 |
|
|
my @toc; |
185 |
|
|
push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c; |
186 |
|
|
push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl; |
187 |
wakaba |
1.26 |
my $cf = 'SuikaWiki/0.9'; |
188 |
wakaba |
1.27 |
## Should be support at least: |
189 |
|
|
## - 'SuikaWiki/0.9' CRLF |
190 |
|
|
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
191 |
|
|
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
192 |
wakaba |
1.28 |
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
193 |
|
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
194 |
wakaba |
1.29 |
&print_header ($form{mypage}, -last_modified => $lm, |
195 |
|
|
-content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/); |
196 |
|
|
&print_content ($content, content_format => $cf, last_modified => $lm, |
197 |
|
|
-toc => \@toc); |
198 |
wakaba |
1.30 |
print &text_to_html (q([[#comment]])) unless $cf =~ /obsoleted="yes"/; |
199 |
wakaba |
1.26 |
} else { |
200 |
wakaba |
1.29 |
&print_header($form{mypage}, -last_modified => $lm); |
201 |
wakaba |
1.26 |
print "<pre>@{[&escape($content)]}</pre>"; |
202 |
|
|
} |
203 |
wakaba |
1.22 |
if ($c) { |
204 |
wakaba |
1.29 |
print q{<h2 id="wikipage-see-also">See also</h2>}; |
205 |
wakaba |
1.22 |
print $r; |
206 |
|
|
} |
207 |
wakaba |
1.29 |
if ($rl) { |
208 |
|
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
209 |
wakaba |
1.27 |
} |
210 |
|
|
&print_footer($form{mypage}, $lm); |
211 |
wakaba |
1.9 |
} |
212 |
|
|
|
213 |
wakaba |
1.25 |
sub do_output_css { |
214 |
|
|
my $content = $database{$form{mypage}}; |
215 |
|
|
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
216 |
wakaba |
1.29 |
my $lm = &get_info($form{mypage}, $info_LastModified); |
217 |
wakaba |
1.25 |
print "Content-Type: text/css; charset=$charset\n"; |
218 |
wakaba |
1.29 |
print "Last-Modified: $lm\n"; |
219 |
wakaba |
1.25 |
print "\n"; |
220 |
|
|
print $content; |
221 |
|
|
} else { |
222 |
|
|
print "Status: 406 Unsupported Media Type\n"; |
223 |
wakaba |
1.29 |
&print_header('WikiPageIsNotCSS', -noindex => 1); |
224 |
wakaba |
1.25 |
&print_content($database{WikiPageIsNotCSS}); |
225 |
|
|
&print_footer('WikiPageIsNotCSS'); |
226 |
|
|
} |
227 |
|
|
} |
228 |
|
|
|
229 |
wakaba |
1.9 |
sub do_edit { |
230 |
wakaba |
1.16 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
231 |
wakaba |
1.29 |
&print_header($page, -noindex => 1); |
232 |
wakaba |
1.16 |
if (not &is_editable($page)) { |
233 |
|
|
&print_message($resource{cantchange}); |
234 |
|
|
} elsif (&is_frozen($page)) { |
235 |
|
|
&print_message($resource{cantchange}); |
236 |
|
|
} else { |
237 |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
238 |
wakaba |
1.9 |
} |
239 |
wakaba |
1.30 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
240 |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
241 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
242 |
|
|
if ($c) { |
243 |
|
|
print q{<h2 id="wikipage-see-also">See also</h2>}; |
244 |
|
|
print $r; |
245 |
|
|
} |
246 |
|
|
if ($rl) { |
247 |
|
|
print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n); |
248 |
|
|
} |
249 |
wakaba |
1.16 |
&print_footer($page); |
250 |
wakaba |
1.9 |
} |
251 |
|
|
|
252 |
wakaba |
1.16 |
sub do_adminedit { |
253 |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
254 |
wakaba |
1.29 |
&print_header($page, -noindex => 1); |
255 |
wakaba |
1.16 |
if (not &is_editable($page)) { |
256 |
|
|
&print_message($resource{cantchange}); |
257 |
wakaba |
1.9 |
} else { |
258 |
wakaba |
1.16 |
&print_message($resource{passwordneeded}); |
259 |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1); |
260 |
wakaba |
1.9 |
} |
261 |
wakaba |
1.16 |
&print_footer($page); |
262 |
wakaba |
1.9 |
} |
263 |
|
|
|
264 |
wakaba |
1.16 |
sub do_adminchangepasswordform { |
265 |
wakaba |
1.29 |
&print_header($AdminChangePassword, -noindex => 1); |
266 |
wakaba |
1.16 |
&print_passwordform; |
267 |
|
|
&print_footer($AdminChangePassword); |
268 |
|
|
} |
269 |
wakaba |
1.9 |
|
270 |
wakaba |
1.16 |
sub do_adminchangepassword { |
271 |
|
|
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
272 |
|
|
&print_error($resource{passwordmismatcherror}); |
273 |
|
|
} |
274 |
|
|
my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); |
275 |
|
|
if ($validpassword_crypt) { |
276 |
|
|
if (not &valid_password($form{myoldpassword})) { |
277 |
|
|
&send_mail_to_admin(<<"EOD", "AdminChangePassword"); |
278 |
|
|
myoldpassword=$form{myoldpassword} |
279 |
|
|
mynewpassword=$form{mynewpassword} |
280 |
|
|
mynewpassword2=$form{mynewpassword2} |
281 |
wakaba |
1.9 |
EOD |
282 |
wakaba |
1.16 |
&print_error($resource{passworderror}); |
283 |
wakaba |
1.9 |
} |
284 |
wakaba |
1.16 |
} |
285 |
|
|
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
286 |
|
|
my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z'); |
287 |
|
|
my $salt1 = $token[(time | $$) % scalar(@token)]; |
288 |
|
|
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
289 |
|
|
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
290 |
|
|
&set_info($AdminSpecialPage, $info_AdminPassword, $crypted); |
291 |
|
|
|
292 |
wakaba |
1.29 |
&print_header($CompletedSuccessfully, -noindex => 1); |
293 |
wakaba |
1.16 |
&print_message($resource{passwordchanged}); |
294 |
|
|
&print_footer($CompletedSuccessfully); |
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
sub do_index { |
298 |
|
|
&print_header($IndexPage); |
299 |
|
|
print qq(<ul>); |
300 |
|
|
foreach my $page (sort keys %database) { |
301 |
|
|
if (&is_editable($page)) { |
302 |
wakaba |
1.24 |
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
303 |
wakaba |
1.16 |
# print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>); |
304 |
|
|
# print qq(<li>@{[0 + &is_frozen($page)]}</li>); |
305 |
wakaba |
1.9 |
} |
306 |
|
|
} |
307 |
wakaba |
1.16 |
print qq(</ul>); |
308 |
|
|
&print_footer($IndexPage); |
309 |
wakaba |
1.9 |
} |
310 |
|
|
|
311 |
wakaba |
1.16 |
sub do_write { |
312 |
|
|
if (&frozen_reject()) { |
313 |
|
|
return; |
314 |
wakaba |
1.9 |
} |
315 |
|
|
|
316 |
|
|
if (not &is_editable($form{mypage})) { |
317 |
wakaba |
1.29 |
&print_header($form{mypage}, -noindex => 1); |
318 |
wakaba |
1.16 |
&print_message($resource{cantchange}); |
319 |
|
|
&print_footer($form{mypage}); |
320 |
wakaba |
1.9 |
return; |
321 |
|
|
} |
322 |
|
|
|
323 |
wakaba |
1.16 |
if (&conflict($form{mypage}, $form{mymsg})) { |
324 |
wakaba |
1.9 |
return; |
325 |
|
|
} |
326 |
|
|
|
327 |
wakaba |
1.16 |
# Making diff |
328 |
wakaba |
1.9 |
{ |
329 |
wakaba |
1.16 |
&open_diff; |
330 |
|
|
my @msg1 = split(/\n/, $database{$form{mypage}}); |
331 |
wakaba |
1.9 |
my @msg2 = split(/\n/, $form{mymsg}); |
332 |
wakaba |
1.16 |
$diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); |
333 |
|
|
&close_diff; |
334 |
wakaba |
1.9 |
} |
335 |
|
|
|
336 |
|
|
if ($form{mymsg}) { |
337 |
wakaba |
1.16 |
$database{$form{mypage}} = $form{mymsg}; |
338 |
|
|
&send_mail_to_admin($form{mypage}, "Modify"); |
339 |
|
|
if ($form{mytouch}) { |
340 |
|
|
&set_info($form{mypage}, $info_LastModified, '' . localtime); |
341 |
|
|
&update_recent_changes; |
342 |
|
|
} |
343 |
|
|
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
344 |
wakaba |
1.29 |
&print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":'')); |
345 |
wakaba |
1.16 |
&print_message($resource{saved}); |
346 |
|
|
&print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); |
347 |
|
|
&print_footer($CompletedSuccessfully); |
348 |
|
|
} else { |
349 |
|
|
&send_mail_to_admin($form{mypage}, "Delete"); |
350 |
|
|
delete $database{$form{mypage}}; |
351 |
|
|
delete $infobase{$form{mypage}}; |
352 |
|
|
if ($form{mytouch}) { |
353 |
|
|
&update_recent_changes; |
354 |
|
|
} |
355 |
wakaba |
1.29 |
&print_header($form{mypage}, -noindex => 1); |
356 |
wakaba |
1.16 |
&print_message($resource{deleted}); |
357 |
|
|
&print_footer($form{mypage}); |
358 |
wakaba |
1.9 |
} |
359 |
|
|
} |
360 |
|
|
|
361 |
wakaba |
1.16 |
sub do_searchform { |
362 |
|
|
&print_header($SearchPage); |
363 |
|
|
&print_searchform(""); |
364 |
|
|
&print_footer($SearchPage); |
365 |
wakaba |
1.9 |
} |
366 |
|
|
|
367 |
wakaba |
1.16 |
sub do_search { |
368 |
wakaba |
1.22 |
my $word = $form{mymsg}; |
369 |
wakaba |
1.16 |
&print_header($SearchPage); |
370 |
wakaba |
1.22 |
&print_searchform(&escape($word)); |
371 |
wakaba |
1.30 |
print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1); |
372 |
wakaba |
1.16 |
&print_footer($SearchPage); |
373 |
wakaba |
1.9 |
} |
374 |
|
|
|
375 |
wakaba |
1.22 |
sub get_search_result ($;%) { |
376 |
|
|
my $word = shift; |
377 |
|
|
my %option = @_; |
378 |
wakaba |
1.30 |
my @r; |
379 |
|
|
foreach my $page (keys %database) { |
380 |
|
|
next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself}); |
381 |
wakaba |
1.28 |
my $content = $database{$page}; |
382 |
wakaba |
1.30 |
my $cf = 'SuikaWiki/0.9'; |
383 |
|
|
$cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s; |
384 |
|
|
next if $cf =~ /obsoleted="yes"/; |
385 |
|
|
if (index ($page, $word) > -1) { |
386 |
|
|
my $c = $content =~ s/\Q$word\E/$word/g; |
387 |
|
|
push @r, [$page, $c+20]; |
388 |
|
|
} elsif (index ($word, $page) > -1) { |
389 |
|
|
my $c = $content =~ s/\Q$word\E/$word/g; |
390 |
|
|
push @r, [$page, $c+10]; |
391 |
|
|
} elsif (my $c = $content =~ s/\Q$word\E/$word/g) { |
392 |
|
|
push @r, [$page, $c]; |
393 |
wakaba |
1.22 |
} |
394 |
|
|
} |
395 |
wakaba |
1.30 |
my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#g; $s }; |
396 |
|
|
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; |
397 |
|
|
$r = qq|<ul class="search-result">$r</ul>| if $r; |
398 |
|
|
get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found}; |
399 |
|
|
wantarray? ($r, scalar @r): $r; |
400 |
wakaba |
1.22 |
} |
401 |
|
|
|
402 |
wakaba |
1.16 |
sub do_create { |
403 |
|
|
&print_header($CreatePage); |
404 |
|
|
print <<"EOD"; |
405 |
|
|
<form action="$url_cgi" method="post"> |
406 |
|
|
<input type="hidden" name="mycmd" value="edit"> |
407 |
|
|
<strong>$resource{newpagename}</strong><br> |
408 |
|
|
<input type="text" name="mypage" value="" size="20"> |
409 |
|
|
<input type="submit" value="$resource{createbutton}"><br> |
410 |
|
|
</form> |
411 |
|
|
EOD |
412 |
|
|
&print_footer($CreatePage); |
413 |
wakaba |
1.9 |
} |
414 |
|
|
|
415 |
wakaba |
1.28 |
sub do_random_jump { |
416 |
|
|
my @list = keys %database; |
417 |
|
|
my $name = &encode ($list[rand @list]); |
418 |
wakaba |
1.29 |
my ($scheme) = 'http'; |
419 |
|
|
$scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
420 |
|
|
print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n"; |
421 |
wakaba |
1.28 |
print "\n"; |
422 |
|
|
} |
423 |
|
|
|
424 |
wakaba |
1.16 |
sub do_FrontPage { |
425 |
|
|
open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); |
426 |
|
|
my $content = join('', <FILE>); |
427 |
|
|
&code_convert(\$content, $kanjicode); |
428 |
|
|
close(FILE); |
429 |
|
|
&print_header($FrontPage); |
430 |
|
|
&print_content($content); |
431 |
|
|
&print_footer($FrontPage); |
432 |
wakaba |
1.9 |
} |
433 |
|
|
|
434 |
|
|
sub print_error { |
435 |
|
|
my ($msg) = @_; |
436 |
wakaba |
1.29 |
&print_header($ErrorPage, -noindex => 1); |
437 |
wakaba |
1.16 |
print qq(<p><strong class="error">$msg</strong></p>); |
438 |
|
|
&print_footer($ErrorPage); |
439 |
wakaba |
1.9 |
exit(0); |
440 |
|
|
} |
441 |
|
|
|
442 |
wakaba |
1.27 |
sub print_header ($;%) { |
443 |
|
|
my ($page, %option) = @_; |
444 |
wakaba |
1.16 |
my $bodyclass = "normal"; |
445 |
|
|
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
446 |
|
|
$bodyclass = "frozen"; |
447 |
wakaba |
1.22 |
} |
448 |
wakaba |
1.29 |
$bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
449 |
wakaba |
1.27 |
print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto}; |
450 |
|
|
print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; |
451 |
wakaba |
1.16 |
my $cookedpage = &encode($page); |
452 |
wakaba |
1.24 |
my $escapedpage = &escape($page); |
453 |
wakaba |
1.9 |
print <<"EOD"; |
454 |
wakaba |
1.16 |
Content-type: text/html; charset=$charset |
455 |
wakaba |
1.18 |
Content-Language: $lang |
456 |
|
|
Content-Style-Type: text/css |
457 |
wakaba |
1.9 |
|
458 |
wakaba |
1.28 |
<!-- |
459 |
wakaba |
1.16 |
<!DOCTYPE html |
460 |
|
|
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
461 |
wakaba |
1.28 |
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
462 |
wakaba |
1.16 |
<html lang="$lang"> |
463 |
|
|
<head> |
464 |
wakaba |
1.29 |
<title>$escapedpage</title> |
465 |
wakaba |
1.16 |
<link rel="index" href="$url_cgi?$IndexPage"> |
466 |
wakaba |
1.30 |
<link rel="help" href="$url_cgi?WikiHelp"> |
467 |
wakaba |
1.26 |
<link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense"> |
468 |
wakaba |
1.24 |
<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}"> |
469 |
wakaba |
1.29 |
@{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']} |
470 |
wakaba |
1.9 |
</head> |
471 |
wakaba |
1.16 |
<body class="$bodyclass"> |
472 |
wakaba |
1.22 |
EOD |
473 |
|
|
&print_navigate_links ($page); |
474 |
|
|
print <<EOD; |
475 |
wakaba |
1.29 |
<h1 class="header">@{[&escape($page)]}</h1> |
476 |
wakaba |
1.22 |
EOD |
477 |
|
|
} |
478 |
|
|
|
479 |
|
|
sub print_navigate_links (@) { |
480 |
|
|
my ($page) = @_; |
481 |
|
|
my $editable = 0; |
482 |
|
|
my $admineditable = 0; |
483 |
|
|
if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) { |
484 |
|
|
$editable = 0; |
485 |
wakaba |
1.29 |
#$admineditable = 1; |
486 |
wakaba |
1.22 |
} elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) { |
487 |
wakaba |
1.29 |
#$admineditable = 1; |
488 |
wakaba |
1.22 |
$editable = 1; |
489 |
|
|
} else { |
490 |
|
|
$editable = 0; |
491 |
|
|
} |
492 |
|
|
my $cookedpage = &encode($page); |
493 |
|
|
print <<EOH; |
494 |
wakaba |
1.16 |
<div class="tools"> |
495 |
|
|
@{[ $admineditable |
496 |
|
|
? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | ) |
497 |
|
|
: qq() |
498 |
|
|
]} |
499 |
|
|
@{[ $editable |
500 |
wakaba |
1.29 |
? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | ) |
501 |
|
|
qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | ) |
502 |
wakaba |
1.16 |
: qq() |
503 |
|
|
]} |
504 |
|
|
@{[ $admineditable |
505 |
|
|
? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | ) |
506 |
|
|
: qq() |
507 |
|
|
]} |
508 |
wakaba |
1.29 |
<a href="$url_cgi?$CreatePage" class="wiki">新規</a> | |
509 |
|
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
510 |
|
|
<a href="$url_cgi?$FrontPage" class="wiki">首頁</a> | |
511 |
|
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
512 |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
513 |
|
|
<a href="$url_cgi?$RecentChanges" class="wiki">最新</a> |
514 |
|
|
</div> |
515 |
|
|
EOH |
516 |
|
|
<<EOH; ## temp |
517 |
|
|
<a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> | |
518 |
|
|
<a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> | |
519 |
|
|
<!-- <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | --> |
520 |
|
|
<a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> | |
521 |
|
|
<a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> | |
522 |
|
|
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> | |
523 |
|
|
<a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a> |
524 |
wakaba |
1.16 |
</div> |
525 |
wakaba |
1.22 |
EOH |
526 |
wakaba |
1.9 |
} |
527 |
|
|
|
528 |
wakaba |
1.16 |
sub print_footer { |
529 |
wakaba |
1.27 |
my ($page, $lm) = @_; |
530 |
wakaba |
1.16 |
$walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) |
531 |
|
|
# Walrus mod (1) start |
532 |
wakaba |
1.30 |
my $cvslog1 = q$Revision: 1.29 $; |
533 |
|
|
my $cvslog2 = q$Date: 2002/10/21 06:28:02 $; |
534 |
wakaba |
1.22 |
print_navigate_links ($page); |
535 |
|
|
print <<"EOD"; |
536 |
wakaba |
1.27 |
@{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]} |
537 |
wakaba |
1.16 |
<div class="footer"> |
538 |
wakaba |
1.29 |
<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> |
539 |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a> |
540 |
wakaba |
1.18 |
<div class="navigation"> |
541 |
|
|
[<a href="/" title="このサーバーの首頁">/</a> |
542 |
|
|
<a href="/map" title="このサーバーの案内">地図</a> |
543 |
|
|
<a href="/search/" title="このサーバーの検索">検索</a>] |
544 |
|
|
</div> |
545 |
wakaba |
1.10 |
</div> |
546 |
wakaba |
1.19 |
$walrus_log |
547 |
wakaba |
1.16 |
</body> |
548 |
|
|
</html> |
549 |
wakaba |
1.12 |
EOD |
550 |
wakaba |
1.16 |
# print <<"EOD"; |
551 |
|
|
# <hr> |
552 |
|
|
# <address class="footer"> |
553 |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version |
554 |
|
|
# © 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br /> |
555 |
|
|
# Modified by <a href="$modifier_url">$modifier_name</a>. |
556 |
|
|
# </address> |
557 |
|
|
# <p class="footer"> |
558 |
|
|
# <a href="http://www.hyuki.com/yukiwiki/">$icontag</a> |
559 |
|
|
# </p> |
560 |
|
|
# </body> |
561 |
|
|
# </html> |
562 |
|
|
# EOD |
563 |
|
|
# Walrus mod (1) end |
564 |
wakaba |
1.9 |
} |
565 |
|
|
|
566 |
wakaba |
1.16 |
sub escape { |
567 |
|
|
my $s = shift; |
568 |
|
|
$s =~ s|\r\n|\n|g; |
569 |
wakaba |
1.23 |
$s =~ s|&|&|g; |
570 |
wakaba |
1.16 |
$s =~ s|<|<|g; |
571 |
|
|
$s =~ s|>|>|g; |
572 |
|
|
$s =~ s|"|"|g; |
573 |
|
|
return $s; |
574 |
|
|
} |
575 |
|
|
|
576 |
|
|
sub unescape { |
577 |
|
|
my $s = shift; |
578 |
|
|
# $s =~ s|\n|\r\n|g; |
579 |
wakaba |
1.23 |
$s =~ s|<|<|g; |
580 |
|
|
$s =~ s|>|>|g; |
581 |
|
|
$s =~ s|"|"|g; |
582 |
|
|
$s =~ s|&|&|g; |
583 |
wakaba |
1.16 |
return $s; |
584 |
|
|
} |
585 |
|
|
|
586 |
wakaba |
1.26 |
sub print_content ($;$) { |
587 |
wakaba |
1.27 |
my ($rawcontent, %option) = @_; |
588 |
wakaba |
1.29 |
print &text_to_html($rawcontent, toc=>1, %option); |
589 |
wakaba |
1.9 |
} |
590 |
|
|
|
591 |
wakaba |
1.16 |
sub text_to_html { |
592 |
|
|
my ($txt, %option) = @_; |
593 |
wakaba |
1.9 |
my (@txt) = split(/\n/, $txt); |
594 |
wakaba |
1.29 |
my @toc; |
595 |
|
|
my @toc2 = @{$option{-toc}||[]}; |
596 |
wakaba |
1.16 |
my $tocnum = 0; |
597 |
|
|
my (@saved, @result); |
598 |
|
|
unshift(@saved, "</p>"); |
599 |
|
|
push(@result, "<p>"); |
600 |
wakaba |
1.9 |
foreach (@txt) { |
601 |
|
|
chomp; |
602 |
wakaba |
1.25 |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
603 |
|
|
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
604 |
wakaba |
1.18 |
push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>'); |
605 |
|
|
$tocnum++; |
606 |
wakaba |
1.25 |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
607 |
|
|
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
608 |
wakaba |
1.18 |
push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>'); |
609 |
|
|
$tocnum++; |
610 |
wakaba |
1.25 |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
611 |
|
|
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
612 |
wakaba |
1.18 |
push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>'); |
613 |
|
|
$tocnum++; |
614 |
wakaba |
1.25 |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
615 |
wakaba |
1.16 |
# if (/^\*\*(.*)/) { |
616 |
|
|
# Walrus mod (6) end |
617 |
wakaba |
1.25 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
618 |
wakaba |
1.16 |
push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>'); |
619 |
|
|
$tocnum++; |
620 |
wakaba |
1.25 |
} elsif (/^\*([^\x0D\x0A]*)/) { |
621 |
|
|
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
622 |
wakaba |
1.16 |
push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>'); |
623 |
|
|
$tocnum++; |
624 |
wakaba |
1.25 |
} elsif (/^(={1,6})(.*)/) { |
625 |
wakaba |
1.18 |
&back_push('ol', length($1), \@saved, \@result); |
626 |
|
|
push(@result, '<li>' . &inline($2) . '</li>'); |
627 |
wakaba |
1.25 |
} elsif (/^(-{1,6})(.*)/) { |
628 |
wakaba |
1.28 |
&back_push('ul', length($1), \@saved, \@result); |
629 |
|
|
my ($pf, $l) = ('', $2); |
630 |
|
|
if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { |
631 |
|
|
my $num = 0+$1; |
632 |
|
|
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
633 |
|
|
} |
634 |
|
|
push(@result, '<li>' . $pf . &inline ($l) . '</li>'); |
635 |
wakaba |
1.9 |
} elsif (/^:([^:]+):(.*)/) { |
636 |
wakaba |
1.16 |
&back_push('dl', 1, \@saved, \@result); |
637 |
wakaba |
1.9 |
push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>'); |
638 |
wakaba |
1.30 |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
639 |
wakaba |
1.16 |
&back_push('blockquote', length($1), \@saved, \@result); |
640 |
wakaba |
1.30 |
push @result, "<p>"; |
641 |
wakaba |
1.9 |
push(@result, &inline($2)); |
642 |
wakaba |
1.30 |
unshift @saved, "</p>"; |
643 |
wakaba |
1.9 |
} elsif (/^\s*$/) { |
644 |
|
|
push(@result, splice(@saved)); |
645 |
wakaba |
1.30 |
push(@result, "<p>"); |
646 |
wakaba |
1.9 |
unshift(@saved, "</p>"); |
647 |
|
|
} elsif (/^(\s+.*)$/) { |
648 |
wakaba |
1.16 |
&back_push('pre', 1, \@saved, \@result); |
649 |
wakaba |
1.18 |
#push(@result, &escape($1)); # Not &inline, but &escape |
650 |
wakaba |
1.26 |
push(@result, &inline($1)); |
651 |
wakaba |
1.16 |
# } elsif (/^\,(.*)$/) { # Walrus del (BF) |
652 |
|
|
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF) |
653 |
|
|
&back_push('table', 1, \@saved, \@result, ' border="1"'); |
654 |
|
|
####### |
655 |
|
|
# This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki. |
656 |
|
|
# XXXXX |
657 |
|
|
my $tmp = "$1,"; |
658 |
|
|
my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g); |
659 |
|
|
my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value; |
660 |
|
|
my @colspan = map {($_ eq '==') ? 0 : 1} @value; |
661 |
|
|
for (my $i = 0; $i < @value; $i++) { |
662 |
|
|
if ($colspan[$i]) { |
663 |
|
|
while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') { |
664 |
|
|
$colspan[$i]++; |
665 |
|
|
} |
666 |
|
|
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; |
667 |
|
|
$value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i])); |
668 |
|
|
} else { |
669 |
|
|
$value[$i] = ''; |
670 |
|
|
} |
671 |
|
|
} |
672 |
|
|
push(@result, join('', '<tr>', @value, '</tr>')); |
673 |
|
|
# XXXXX |
674 |
|
|
####### |
675 |
wakaba |
1.29 |
} elsif (/^\[(INS|DEL|PRE)\[\s*$/) { |
676 |
wakaba |
1.28 |
push @result, splice (@saved), '<'.lc($1).'>'; |
677 |
|
|
unshift @saved, "</p>"; |
678 |
|
|
push @result, "<p>"; |
679 |
wakaba |
1.29 |
} elsif (/^\](INS|DEL|PRE)\]\s*$/) { |
680 |
wakaba |
1.28 |
push @result, splice (@saved), '</'.lc($1).'>'; |
681 |
|
|
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
682 |
|
|
my $num = 0+$1; |
683 |
|
|
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
684 |
|
|
push @result, &inline ($2); |
685 |
wakaba |
1.9 |
} else { |
686 |
|
|
push(@result, &inline($_)); |
687 |
|
|
} |
688 |
|
|
} |
689 |
|
|
push(@result, splice(@saved)); |
690 |
wakaba |
1.27 |
|
691 |
|
|
my $toc = ''; |
692 |
wakaba |
1.16 |
if ($option{toc}) { |
693 |
|
|
# Convert @toc (table of contents) to HTML. |
694 |
|
|
# This part is taken from Makio Tsukamoto's WalWiki. |
695 |
|
|
my (@tocsaved, @tocresult); |
696 |
wakaba |
1.29 |
foreach (@toc,@toc2) { |
697 |
wakaba |
1.25 |
if (/^(-{1,6})(.*)$/) { |
698 |
wakaba |
1.16 |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
699 |
|
|
push(@tocresult, '<li>' . $2 . '</li>'); |
700 |
|
|
} |
701 |
|
|
} |
702 |
|
|
push(@tocresult, splice(@tocsaved)); |
703 |
wakaba |
1.27 |
$toc = join("\n", @tocresult); |
704 |
|
|
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
705 |
wakaba |
1.16 |
} |
706 |
wakaba |
1.30 |
$toc .= join("\n", @result); |
707 |
|
|
$toc =~ s#<p>\n</p>##g; |
708 |
|
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
709 |
|
|
$toc =~ s#<pre>\n#<pre>#g; |
710 |
|
|
$toc; |
711 |
wakaba |
1.9 |
} |
712 |
|
|
|
713 |
|
|
sub back_push { |
714 |
wakaba |
1.16 |
my ($tag, $level, $savedref, $resultref, $attr) = @_; |
715 |
|
|
while (@$savedref > $level) { |
716 |
|
|
push(@$resultref, shift(@$savedref)); |
717 |
|
|
} |
718 |
|
|
if ($savedref->[0] ne "</$tag>") { |
719 |
|
|
push(@$resultref, splice(@$savedref)); |
720 |
|
|
} |
721 |
|
|
while (@$savedref < $level) { |
722 |
|
|
unshift(@$savedref, "</$tag>"); |
723 |
|
|
push(@$resultref, "<$tag$attr>"); |
724 |
wakaba |
1.9 |
} |
725 |
|
|
} |
726 |
|
|
|
727 |
wakaba |
1.16 |
sub inline { |
728 |
|
|
my ($line) = @_; |
729 |
|
|
$line = &escape($line); |
730 |
wakaba |
1.30 |
$line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g; |
731 |
|
|
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
732 |
|
|
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
733 |
|
|
$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; |
734 |
|
|
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
735 |
|
|
$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; |
736 |
|
|
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g; |
737 |
|
|
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
738 |
|
|
$line =~ s|''([^']+)''|<em>$1</em>|g; |
739 |
wakaba |
1.31 |
$line =~ s{ |
740 |
|
|
((?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] |
741 |
wakaba |
1.30 |
|\[\[([^[]+?)]>>([0-9]+)] # [[WikiName]>>1] |
742 |
wakaba |
1.28 |
|>>([0-9]+) |
743 |
wakaba |
1.31 |
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
744 |
|
|
}{ |
745 |
|
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
746 |
wakaba |
1.28 |
if ($l) { |
747 |
|
|
&make_link($l) |
748 |
|
|
} elsif (defined $page) { |
749 |
|
|
&make_wikilink ($page, anchor => 0+$anchor); |
750 |
|
|
} elsif ($anum) { |
751 |
|
|
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
752 |
wakaba |
1.31 |
} elsif ($uri) { |
753 |
|
|
&make_urilink ($uri); |
754 |
wakaba |
1.28 |
} |
755 |
wakaba |
1.31 |
}gex; |
756 |
wakaba |
1.16 |
return $line; |
757 |
|
|
} |
758 |
|
|
|
759 |
wakaba |
1.28 |
sub make_wikilink ($%) { |
760 |
|
|
my ($ename, %option) = @_; |
761 |
|
|
my $name = &unescape ($ename); |
762 |
|
|
if ($database{$name}) { |
763 |
|
|
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
764 |
|
|
if ($option{anchor}) { |
765 |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
766 |
|
|
} else { |
767 |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
768 |
|
|
} |
769 |
|
|
} else { |
770 |
|
|
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>); |
771 |
|
|
} |
772 |
|
|
} |
773 |
|
|
|
774 |
wakaba |
1.31 |
sub make_urilink ($;%) { |
775 |
|
|
require URI; |
776 |
|
|
my $uri = shift; |
777 |
|
|
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
778 |
|
|
$uri = &unescape ($uri); |
779 |
|
|
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
780 |
|
|
my ($site, $name) = ($1, $2); |
781 |
|
|
for ($site, $name) { |
782 |
|
|
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
783 |
|
|
} |
784 |
|
|
if ($interwiki{$site}) { |
785 |
|
|
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
786 |
|
|
$site = &escape ($site); $name = &escape ($name); |
787 |
|
|
qq(<<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: <$uri>">$name</a>>); |
788 |
|
|
} else { |
789 |
|
|
qq(<未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>); |
790 |
|
|
} |
791 |
|
|
} else { |
792 |
|
|
qq(<不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>); |
793 |
|
|
} |
794 |
|
|
} elsif ($uri =~ /^urn:/) { ## URN |
795 |
|
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
796 |
|
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
797 |
|
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
798 |
|
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
799 |
|
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
800 |
|
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
801 |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
802 |
|
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
803 |
|
|
} else { ## misc. URI |
804 |
|
|
CGI::Carp::warningsToBrowser (0); |
805 |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
806 |
|
|
CGI::Carp::warningsToBrowser (1); |
807 |
|
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
808 |
|
|
} |
809 |
|
|
} |
810 |
|
|
|
811 |
|
|
## to be obsoleted |
812 |
wakaba |
1.16 |
sub make_link { |
813 |
|
|
my $chunk = shift; |
814 |
|
|
# Walrus add (3) start |
815 |
wakaba |
1.21 |
$chunk =~ s/^<(.*)>$/$1/; |
816 |
wakaba |
1.16 |
my $name = $chunk; |
817 |
|
|
$name = &unarmor_name($name); |
818 |
|
|
# Walrus add (3) end |
819 |
wakaba |
1.31 |
if ($chunk =~ /^$embedded_name$/) { |
820 |
wakaba |
1.16 |
return &embedded_to_html($chunk); |
821 |
|
|
} else { |
822 |
|
|
$chunk = &unarmor_name($chunk); |
823 |
|
|
$chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly. |
824 |
|
|
my $cookedchunk = &encode($chunk); |
825 |
wakaba |
1.31 |
if ($database{$chunk}) { |
826 |
wakaba |
1.16 |
my $subject = &escape(&get_subjectline($chunk, delimiter => '')); |
827 |
|
|
# return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
828 |
wakaba |
1.26 |
return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
829 |
wakaba |
1.16 |
} elsif ($page_command{$chunk}) { |
830 |
|
|
# return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3) |
831 |
wakaba |
1.24 |
return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3) |
832 |
wakaba |
1.16 |
} else { |
833 |
wakaba |
1.24 |
return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>); |
834 |
wakaba |
1.9 |
} |
835 |
|
|
} |
836 |
|
|
} |
837 |
|
|
|
838 |
wakaba |
1.16 |
sub print_message { |
839 |
|
|
my ($msg) = @_; |
840 |
|
|
print qq(<p><strong>$msg</strong></p>); |
841 |
wakaba |
1.9 |
} |
842 |
|
|
|
843 |
wakaba |
1.22 |
sub get_message { |
844 |
|
|
my ($msg) = @_; |
845 |
|
|
qq(<p><strong>$msg</strong></p>); |
846 |
|
|
} |
847 |
|
|
|
848 |
wakaba |
1.16 |
sub init_form { |
849 |
|
|
if (param()) { |
850 |
|
|
foreach my $var (param()) { |
851 |
|
|
$form{$var} = param($var); |
852 |
wakaba |
1.30 |
} |
853 |
wakaba |
1.16 |
} |
854 |
wakaba |
1.30 |
if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) { |
855 |
|
|
my $query = &decode($main::ENV{QUERY_STRING}); |
856 |
|
|
if ($page_command{$query}) { |
857 |
wakaba |
1.16 |
$form{mycmd} = $page_command{$query}; |
858 |
|
|
$form{mypage} = $query; |
859 |
wakaba |
1.30 |
} else { |
860 |
wakaba |
1.16 |
$form{mypage} = $query; |
861 |
wakaba |
1.30 |
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
862 |
|
|
} |
863 |
wakaba |
1.16 |
} |
864 |
wakaba |
1.30 |
$form{mypage} ||= 'HomePage'; |
865 |
wakaba |
1.16 |
|
866 |
|
|
# mypreview_edit -> do_edit, with preview. |
867 |
|
|
# mypreview_adminedit -> do_adminedit, with preview. |
868 |
|
|
# mypreview_write -> do_write, without preview. |
869 |
|
|
foreach (keys %form) { |
870 |
|
|
if (/^mypreview_(.*)$/) { |
871 |
|
|
$form{mycmd} = $1; |
872 |
|
|
$form{mypreview} = 1; |
873 |
|
|
} |
874 |
|
|
} |
875 |
wakaba |
1.9 |
|
876 |
wakaba |
1.30 |
# |
877 |
wakaba |
1.16 |
# $form{mycmd} is frozen here. |
878 |
wakaba |
1.30 |
# |
879 |
wakaba |
1.16 |
|
880 |
|
|
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
881 |
|
|
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
882 |
|
|
} |
883 |
|
|
|
884 |
|
|
sub update_recent_changes { |
885 |
wakaba |
1.28 |
my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; |
886 |
wakaba |
1.16 |
my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); |
887 |
|
|
my @updates; |
888 |
|
|
foreach (@oldupdates) { |
889 |
wakaba |
1.28 |
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/; |
890 |
|
|
my $name = $1; |
891 |
|
|
if ($name ne $form{mypage}) { |
892 |
|
|
push @updates, $_; |
893 |
wakaba |
1.16 |
} |
894 |
|
|
} |
895 |
|
|
if (&is_exist_page($form{mypage})) { |
896 |
wakaba |
1.28 |
unshift @updates, $update; |
897 |
wakaba |
1.16 |
} |
898 |
|
|
splice(@updates, $maxrecent + 1); |
899 |
|
|
$database{$RecentChanges} = join("\n", @updates); |
900 |
|
|
if ($file_touch) { |
901 |
|
|
open(FILE, "> $file_touch"); |
902 |
|
|
print FILE localtime() . "\n"; |
903 |
|
|
close(FILE); |
904 |
|
|
} |
905 |
wakaba |
1.9 |
} |
906 |
|
|
|
907 |
wakaba |
1.16 |
sub get_subjectline { |
908 |
|
|
my ($page, %option) = @_; |
909 |
|
|
if (not &is_editable($page)) { |
910 |
|
|
return ""; |
911 |
|
|
} else { |
912 |
|
|
# Delimiter check. |
913 |
|
|
my $delim = $subject_delimiter; |
914 |
|
|
if (defined($option{delimiter})) { |
915 |
|
|
$delim = $option{delimiter}; |
916 |
|
|
} |
917 |
wakaba |
1.9 |
|
918 |
wakaba |
1.16 |
# Get the subject of the page. |
919 |
|
|
my $subject = $database{$page}; |
920 |
wakaba |
1.28 |
$subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; |
921 |
wakaba |
1.16 |
$subject =~ s/\r?\n.*//s; |
922 |
wakaba |
1.27 |
return "$delim$subject".$option{tail}; |
923 |
wakaba |
1.16 |
} |
924 |
wakaba |
1.9 |
} |
925 |
|
|
|
926 |
wakaba |
1.16 |
sub send_mail_to_admin { |
927 |
|
|
my ($page, $mode) = @_; |
928 |
|
|
return unless $modifier_sendmail; |
929 |
|
|
my $message = <<"EOD"; |
930 |
|
|
To: $modifier_mail |
931 |
|
|
From: $modifier_mail |
932 |
|
|
Subject: [Wiki] |
933 |
|
|
MIME-Version: 1.0 |
934 |
|
|
Content-Type: text/plain; charset=ISO-2022-JP |
935 |
|
|
Content-Transfer-Encoding: 7bit |
936 |
|
|
|
937 |
|
|
-------- |
938 |
|
|
MODE = $mode |
939 |
|
|
REMOTE_ADDR = $ENV{REMOTE_ADDR} |
940 |
|
|
REMOTE_HOST = $ENV{REMOTE_HOST} |
941 |
|
|
-------- |
942 |
|
|
$page |
943 |
|
|
-------- |
944 |
|
|
$database{$page} |
945 |
|
|
-------- |
946 |
|
|
EOD |
947 |
|
|
&code_convert(\$message, 'jis'); |
948 |
|
|
open(MAIL, "| $modifier_sendmail"); |
949 |
|
|
print MAIL $message; |
950 |
|
|
close(MAIL); |
951 |
wakaba |
1.9 |
} |
952 |
|
|
|
953 |
wakaba |
1.16 |
sub open_db { |
954 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
955 |
|
|
dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname"); |
956 |
|
|
dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname"); |
957 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
958 |
|
|
tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname"); |
959 |
|
|
tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname"); |
960 |
|
|
} else { |
961 |
|
|
tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname"); |
962 |
|
|
tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname"); |
963 |
wakaba |
1.9 |
} |
964 |
|
|
} |
965 |
|
|
|
966 |
wakaba |
1.16 |
sub close_db { |
967 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
968 |
|
|
dbmclose(%database); |
969 |
|
|
dbmclose(%infobase); |
970 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
971 |
|
|
untie(%database); |
972 |
|
|
untie(%infobase); |
973 |
|
|
} else { |
974 |
|
|
untie(%database); |
975 |
|
|
untie(%infobase); |
976 |
|
|
} |
977 |
|
|
} |
978 |
wakaba |
1.9 |
|
979 |
wakaba |
1.16 |
sub open_diff { |
980 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
981 |
|
|
dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname"); |
982 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
983 |
|
|
tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname"); |
984 |
|
|
} else { |
985 |
|
|
tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname"); |
986 |
|
|
} |
987 |
|
|
} |
988 |
wakaba |
1.9 |
|
989 |
wakaba |
1.16 |
sub close_diff { |
990 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
991 |
|
|
dbmclose(%diffbase); |
992 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
993 |
|
|
untie(%diffbase); |
994 |
|
|
} else { |
995 |
|
|
untie(%diffbase); |
996 |
|
|
} |
997 |
wakaba |
1.9 |
} |
998 |
|
|
|
999 |
wakaba |
1.16 |
sub print_searchform { |
1000 |
|
|
my ($word) = @_; |
1001 |
|
|
print <<"EOD"; |
1002 |
|
|
<form action="$url_cgi" method="get"> |
1003 |
wakaba |
1.31 |
<input type="hidden" name="mycmd" value="read"> |
1004 |
|
|
<input type="text" name="mypage" value="$word" size="20"> |
1005 |
wakaba |
1.16 |
<input type="submit" value="$resource{searchbutton}"> |
1006 |
|
|
</form> |
1007 |
|
|
EOD |
1008 |
wakaba |
1.9 |
} |
1009 |
|
|
|
1010 |
wakaba |
1.16 |
sub print_editform { |
1011 |
|
|
my ($mymsg, $lastmodified, %mode) = @_; |
1012 |
|
|
my $frozen = &is_frozen($form{mypage}); |
1013 |
|
|
|
1014 |
|
|
if ($form{mypreview}) { |
1015 |
|
|
if ($form{mymsg}) { |
1016 |
|
|
unless ($mode{conflict}) { |
1017 |
|
|
print qq(<h3>$resource{previewtitle}</h3>\n); |
1018 |
|
|
print qq($resource{previewnotice}\n); |
1019 |
|
|
print qq(<div class="preview">\n); |
1020 |
|
|
&print_content($form{mymsg}); |
1021 |
|
|
print qq(</div>\n); |
1022 |
|
|
} |
1023 |
|
|
} else { |
1024 |
|
|
print qq($resource{previewempty}); |
1025 |
|
|
} |
1026 |
|
|
$mymsg = &escape($form{mymsg}); |
1027 |
wakaba |
1.9 |
} else { |
1028 |
wakaba |
1.25 |
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
1029 |
wakaba |
1.9 |
} |
1030 |
|
|
|
1031 |
wakaba |
1.16 |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
1032 |
wakaba |
1.24 |
my $escapedmypage = &escape($form{mypage}); |
1033 |
|
|
my $escapedmypassword = &escape($form{mypassword}); |
1034 |
wakaba |
1.16 |
|
1035 |
|
|
print <<"EOD"; |
1036 |
|
|
<form action="$url_cgi" method="post"> |
1037 |
wakaba |
1.30 |
<h2>$escapedmypageの編集</h2> |
1038 |
wakaba |
1.24 |
@{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]} |
1039 |
wakaba |
1.16 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1040 |
wakaba |
1.24 |
<input type="hidden" name="mypage" value="$escapedmypage"> |
1041 |
wakaba |
1.25 |
<textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br> |
1042 |
wakaba |
1.16 |
@{[ |
1043 |
|
|
$mode{admin} ? |
1044 |
|
|
qq( |
1045 |
|
|
<input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton} |
1046 |
|
|
<input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>) |
1047 |
|
|
: "" |
1048 |
|
|
]} |
1049 |
|
|
@{[ |
1050 |
|
|
$mode{conflict} ? "" : |
1051 |
|
|
qq( |
1052 |
|
|
<input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br> |
1053 |
|
|
<input type="submit" name="mypreview_$edit" value="$resource{previewbutton}"> |
1054 |
wakaba |
1.30 |
<input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd> |
1055 |
|
|
[@{[do {my $n = 0; |
1056 |
|
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
1057 |
|
|
++$n}]}]<br> |
1058 |
wakaba |
1.16 |
) |
1059 |
|
|
]} |
1060 |
|
|
</form> |
1061 |
|
|
EOD |
1062 |
|
|
unless ($mode{conflict}) { |
1063 |
|
|
# Show the format rule. |
1064 |
wakaba |
1.30 |
my $help = $database{'WikiEditHelp'}; |
1065 |
|
|
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1066 |
|
|
print &text_to_html ($help, toc => 0); |
1067 |
|
|
# open(FILE, $file_format) or &print_error("($file_format)"); |
1068 |
|
|
# my $content = join('', <FILE>); |
1069 |
|
|
# &code_convert(\$content, $kanjicode); |
1070 |
|
|
# close(FILE); |
1071 |
|
|
# print &text_to_html($content, toc=>0); |
1072 |
wakaba |
1.9 |
} |
1073 |
|
|
} |
1074 |
|
|
|
1075 |
wakaba |
1.16 |
sub print_passwordform { |
1076 |
|
|
print <<"EOD"; |
1077 |
|
|
<form action="$url_cgi" method="post"> |
1078 |
|
|
<input type="hidden" name="mycmd" value="adminchangepassword"> |
1079 |
|
|
$resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br> |
1080 |
|
|
$resource{newpassword} <input type="password" name="mynewpassword" size="10"><br> |
1081 |
|
|
$resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br> |
1082 |
|
|
<input type="submit" value="$resource{changepasswordbutton}"><br> |
1083 |
|
|
</form> |
1084 |
|
|
EOD |
1085 |
wakaba |
1.9 |
} |
1086 |
|
|
|
1087 |
wakaba |
1.16 |
sub is_editable { |
1088 |
|
|
my ($page) = @_; |
1089 |
wakaba |
1.31 |
if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) { |
1090 |
wakaba |
1.16 |
return 0; |
1091 |
|
|
} else { |
1092 |
|
|
return 1; |
1093 |
|
|
} |
1094 |
wakaba |
1.9 |
} |
1095 |
|
|
|
1096 |
wakaba |
1.16 |
# armor_name: |
1097 |
|
|
# WikiName -> WikiName |
1098 |
|
|
# not_wiki_name -> [[not_wiki_name]] |
1099 |
wakaba |
1.31 |
sub armor_name { qq([[$_[0]]]) } |
1100 |
wakaba |
1.9 |
|
1101 |
wakaba |
1.16 |
# unarmor_name: |
1102 |
|
|
# [[bracket_name]] -> bracket_name |
1103 |
|
|
# WikiName -> WikiName |
1104 |
|
|
sub unarmor_name { |
1105 |
|
|
my ($name) = @_; |
1106 |
|
|
if ($name =~ /^$bracket_name$/) { |
1107 |
|
|
return $1; |
1108 |
|
|
} else { |
1109 |
|
|
return $name; |
1110 |
|
|
} |
1111 |
wakaba |
1.9 |
} |
1112 |
|
|
|
1113 |
wakaba |
1.16 |
sub decode { |
1114 |
|
|
my ($s) = @_; |
1115 |
|
|
$s =~ tr/+/ /; |
1116 |
|
|
$s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; |
1117 |
|
|
return $s; |
1118 |
|
|
} |
1119 |
wakaba |
1.9 |
|
1120 |
wakaba |
1.16 |
sub encode { |
1121 |
|
|
my ($s) = @_; |
1122 |
|
|
my $encoded = ''; |
1123 |
|
|
foreach my $ch (split(//, $s)) { |
1124 |
|
|
if ($ch =~ /[A-Za-z0-9_]/) { |
1125 |
|
|
$encoded .= $ch; |
1126 |
|
|
} else { |
1127 |
|
|
$encoded .= '%' . sprintf("%02X", ord($ch)); |
1128 |
|
|
} |
1129 |
|
|
} |
1130 |
|
|
return $encoded; |
1131 |
|
|
} |
1132 |
wakaba |
1.9 |
|
1133 |
wakaba |
1.16 |
sub init_resource { |
1134 |
|
|
open(FILE, $file_resource) or &print_error("(resource)"); |
1135 |
|
|
while (<FILE>) { |
1136 |
|
|
chomp; |
1137 |
|
|
next if /^#/; |
1138 |
|
|
my ($key, $value) = split(/=/, $_, 2); |
1139 |
|
|
$resource{$key} = &code_convert(\$value, $kanjicode); |
1140 |
|
|
} |
1141 |
|
|
close(FILE); |
1142 |
|
|
} |
1143 |
wakaba |
1.9 |
|
1144 |
wakaba |
1.16 |
sub conflict { |
1145 |
|
|
my ($page, $rawmsg) = @_; |
1146 |
|
|
if ($form{myLastModified} eq &get_info($page, $info_LastModified)) { |
1147 |
|
|
return 0; |
1148 |
|
|
} |
1149 |
|
|
open(FILE, $file_conflict) or &print_error("(conflict)"); |
1150 |
|
|
my $content = join('', <FILE>); |
1151 |
|
|
&code_convert(\$content, $kanjicode); |
1152 |
|
|
close(FILE); |
1153 |
wakaba |
1.29 |
&print_header($page, -noindex => 1); |
1154 |
wakaba |
1.16 |
&print_content($content); |
1155 |
|
|
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
1156 |
|
|
&print_footer($page); |
1157 |
|
|
return 1; |
1158 |
|
|
} |
1159 |
|
|
|
1160 |
|
|
sub get_now { |
1161 |
|
|
my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); |
1162 |
wakaba |
1.28 |
my (@week) = qw(日 月 火 水 木 金 土); |
1163 |
wakaba |
1.16 |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
1164 |
|
|
$year += 1900; |
1165 |
|
|
$mon++; |
1166 |
|
|
$mon = "0$mon" if $mon < 10; |
1167 |
|
|
$day = "0$day" if $day < 10; |
1168 |
|
|
$hour = "0$hour" if $hour < 10; |
1169 |
|
|
$min = "0$min" if $min < 10; |
1170 |
wakaba |
1.28 |
#$sec = "0$sec" if $sec < 10; |
1171 |
wakaba |
1.16 |
$weekday = $week[$weekday]; |
1172 |
wakaba |
1.28 |
return "$year-$mon-$day ($weekday) $hour:$min"; |
1173 |
wakaba |
1.16 |
} |
1174 |
|
|
|
1175 |
|
|
sub init_InterWikiName { |
1176 |
wakaba |
1.31 |
my @content = split /\n/, $database{$InterWikiName}; |
1177 |
|
|
for (@content) { |
1178 |
|
|
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
1179 |
|
|
$interwiki{$1} = $2; |
1180 |
wakaba |
1.16 |
} |
1181 |
wakaba |
1.31 |
} |
1182 |
|
|
require Message::Util::Formatter; |
1183 |
|
|
$fmt{interwiki} = Message::Util::Formatter->new; |
1184 |
|
|
$fmt{interwiki}->{encoded} = sub { |
1185 |
|
|
my ($o, $p) = @_; |
1186 |
|
|
if ($o->{except}) { |
1187 |
|
|
$o->{except} =~ tr/\x00-\x20<>\x23%\x22{|}\x5C^[]`\x7F-\xFF//d; |
1188 |
|
|
} |
1189 |
|
|
my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit'); |
1190 |
|
|
$s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%02X', unpack 'C', $1/ge; |
1191 |
|
|
$s; |
1192 |
|
|
}; |
1193 |
|
|
$fmt{interwiki}->{ykwk} = sub { ## YukiWiki1 |
1194 |
|
|
my ($o, $p) = @_; |
1195 |
|
|
my $s = $p->{name}; |
1196 |
|
|
$s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/; |
1197 |
|
|
&encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis')); |
1198 |
|
|
}; |
1199 |
wakaba |
1.16 |
} |
1200 |
wakaba |
1.9 |
|
1201 |
|
|
|
1202 |
wakaba |
1.16 |
sub get_info { |
1203 |
|
|
my ($page, $key) = @_; |
1204 |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
1205 |
|
|
return $info{$key}; |
1206 |
|
|
} |
1207 |
wakaba |
1.9 |
|
1208 |
wakaba |
1.16 |
sub set_info { |
1209 |
|
|
my ($page, $key, $value) = @_; |
1210 |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
1211 |
|
|
$info{$key} = $value; |
1212 |
|
|
my $s = ''; |
1213 |
|
|
for (keys %info) { |
1214 |
|
|
$s .= "$_=$info{$_}\n"; |
1215 |
|
|
} |
1216 |
|
|
$infobase{$page} = $s; |
1217 |
|
|
} |
1218 |
wakaba |
1.9 |
|
1219 |
wakaba |
1.16 |
sub frozen_reject { |
1220 |
|
|
my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); |
1221 |
|
|
my ($willbefrozen) = $form{myfrozen}; |
1222 |
|
|
if (not $isfrozen and not $willbefrozen) { |
1223 |
|
|
# You need no check. |
1224 |
|
|
return 0; |
1225 |
|
|
} elsif (valid_password($form{mypassword})) { |
1226 |
|
|
# You are admin. |
1227 |
|
|
return 0; |
1228 |
|
|
} else { |
1229 |
|
|
&print_error($resource{passworderror}); |
1230 |
|
|
return 1; |
1231 |
|
|
} |
1232 |
|
|
} |
1233 |
wakaba |
1.9 |
|
1234 |
wakaba |
1.16 |
sub valid_password { |
1235 |
|
|
my ($givenpassword) = @_; |
1236 |
|
|
my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword); |
1237 |
|
|
if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) { |
1238 |
|
|
return 1; |
1239 |
|
|
} else { |
1240 |
|
|
return 0; |
1241 |
|
|
} |
1242 |
|
|
} |
1243 |
wakaba |
1.9 |
|
1244 |
wakaba |
1.16 |
sub is_frozen { |
1245 |
|
|
my ($page) = @_; |
1246 |
|
|
if (&get_info($page, $info_IsFrozen)) { |
1247 |
|
|
return 1; |
1248 |
|
|
} else { |
1249 |
|
|
return 0; |
1250 |
|
|
} |
1251 |
|
|
} |
1252 |
wakaba |
1.9 |
|
1253 |
wakaba |
1.16 |
sub do_comment { |
1254 |
|
|
my ($content) = $database{$form{mypage}}; |
1255 |
wakaba |
1.30 |
my $default_name; ## this code does not strict. |
1256 |
|
|
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
1257 |
|
|
my $datestr = '[WEAK['.&get_now.']]'; |
1258 |
|
|
my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name; |
1259 |
|
|
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
1260 |
wakaba |
1.29 |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
1261 |
|
|
$namestr = qq( ''$namestr'': ); |
1262 |
wakaba |
1.30 |
} elsif (length $namestr) { |
1263 |
wakaba |
1.29 |
$namestr = qq( ''[[$namestr]]'': ); |
1264 |
|
|
} |
1265 |
wakaba |
1.28 |
my $anchor = 0; |
1266 |
|
|
$content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
1267 |
|
|
$anchor++; |
1268 |
wakaba |
1.27 |
my $i = 1; my $o = 0; |
1269 |
wakaba |
1.25 |
$content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ |
1270 |
|
|
my $embed = $1; |
1271 |
|
|
if ($i == $form{comment_index}) { |
1272 |
|
|
if ($embed eq $embed_comment) { |
1273 |
wakaba |
1.28 |
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
1274 |
wakaba |
1.25 |
} else { |
1275 |
wakaba |
1.28 |
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
1276 |
wakaba |
1.25 |
} |
1277 |
|
|
} |
1278 |
|
|
$i++; $embed; |
1279 |
|
|
}ge; |
1280 |
|
|
unless ($o) { |
1281 |
wakaba |
1.30 |
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1282 |
|
|
$content .= "\n" unless $content =~ /\n$/s; |
1283 |
wakaba |
1.28 |
$content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; |
1284 |
wakaba |
1.16 |
} |
1285 |
wakaba |
1.29 |
$form{__comment_anchor_index} = $anchor; |
1286 |
wakaba |
1.30 |
if ($form{mymsg} || $form{myname}) { |
1287 |
wakaba |
1.16 |
$form{mymsg} = $content; |
1288 |
|
|
$form{mytouch} = 'on'; |
1289 |
|
|
&do_write; |
1290 |
|
|
} else { |
1291 |
|
|
$form{mycmd} = 'read'; |
1292 |
|
|
&do_read; |
1293 |
|
|
} |
1294 |
|
|
} |
1295 |
wakaba |
1.9 |
|
1296 |
wakaba |
1.27 |
my $CommentIndex = 0; |
1297 |
wakaba |
1.16 |
sub embedded_to_html { |
1298 |
|
|
my ($embedded) = @_; |
1299 |
|
|
if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { |
1300 |
wakaba |
1.28 |
unless ($main::_EMBEDED) { |
1301 |
wakaba |
1.16 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
1302 |
|
|
return <<"EOD"; |
1303 |
wakaba |
1.30 |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
1304 |
wakaba |
1.16 |
<input type="hidden" name="mycmd" value="comment"> |
1305 |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1306 |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1307 |
|
|
<input type="hidden" name="mytouch" value="on"> |
1308 |
wakaba |
1.27 |
<input type="hidden" name="comment_index" value="$CommentIndex"> |
1309 |
wakaba |
1.25 |
$embed_comment_Name_Prompt |
1310 |
wakaba |
1.30 |
<input type="text" name="myname" value="" size="10" class="comment-name"> |
1311 |
|
|
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
1312 |
|
|
<input type="submit" value="$resource{commentbutton}" class="comment-submit"> |
1313 |
|
|
</p></form> |
1314 |
wakaba |
1.16 |
EOD |
1315 |
wakaba |
1.28 |
} else { |
1316 |
|
|
return <<"EOD"; |
1317 |
|
|
<del><form action="$url_cgi" method="get"> |
1318 |
|
|
<input type="hidden" name="mycmd" value="read"> |
1319 |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1320 |
|
|
$embed_comment_Name_Prompt |
1321 |
|
|
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
1322 |
|
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
1323 |
|
|
<input type="submit" value="$resource{commentbutton}" disabled="disabled"> |
1324 |
|
|
</form></del> |
1325 |
|
|
EOD |
1326 |
|
|
} |
1327 |
wakaba |
1.22 |
} elsif ($embedded =~ /$embed_command{searched}/) { |
1328 |
wakaba |
1.30 |
return get_search_result ($1, -match_myself => 1); |
1329 |
wakaba |
1.16 |
# Walrus add (5) start |
1330 |
|
|
} elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) { |
1331 |
|
|
$_ = &make_interwiki_box($1, $2); |
1332 |
|
|
return ($_) ? $_ : $embedded; |
1333 |
|
|
# Walrus add (5) end |
1334 |
wakaba |
1.28 |
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
1335 |
|
|
my ($name, $r) = ($1, ''); |
1336 |
|
|
if ($main::_EMBEDED != 1) { |
1337 |
|
|
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
1338 |
|
|
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1339 |
|
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
1340 |
|
|
$main::_EMBEDED = 1; |
1341 |
|
|
$r = &text_to_html ($content, content_format => $cf); |
1342 |
|
|
$main::_EMBEDED = 0; |
1343 |
|
|
} elsif (length $content) { |
1344 |
|
|
$r = "<pre>@{[&escape ($content)]}</pre>"; |
1345 |
|
|
} else { |
1346 |
wakaba |
1.30 |
$r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1347 |
wakaba |
1.28 |
} |
1348 |
|
|
} else { ## nested #EMBED |
1349 |
|
|
$r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1350 |
wakaba |
1.16 |
} |
1351 |
wakaba |
1.31 |
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>); |
1352 |
wakaba |
1.28 |
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
1353 |
|
|
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
1354 |
|
|
} else { |
1355 |
|
|
return $embedded; |
1356 |
|
|
} |
1357 |
wakaba |
1.16 |
} |
1358 |
wakaba |
1.9 |
|
1359 |
wakaba |
1.16 |
# Walrus add (5) start |
1360 |
|
|
sub do_interwiki_box { |
1361 |
|
|
my $remoteurl = $interwiki{$form{'myintername'}}; |
1362 |
|
|
if ($remoteurl) { |
1363 |
|
|
$remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e; |
1364 |
|
|
print "Location: $remoteurl\n\n"; |
1365 |
|
|
exit(1); |
1366 |
|
|
} else { |
1367 |
|
|
&do_read; |
1368 |
|
|
} |
1369 |
|
|
} |
1370 |
|
|
# Walrus add (5) end |
1371 |
wakaba |
1.9 |
|
1372 |
wakaba |
1.16 |
# Walrus add (5) start |
1373 |
|
|
sub make_interwiki_box { |
1374 |
|
|
my ($localname, $intername) = @_; |
1375 |
|
|
my %ignoretype = ( |
1376 |
|
|
'box' => 'text', |
1377 |
|
|
'text' => 'text', |
1378 |
|
|
'pass' => 'password', |
1379 |
|
|
'password' => 'password' |
1380 |
|
|
); |
1381 |
|
|
my $converted = ($ignoretype{$localname}) ? <<EOD : undef; |
1382 |
|
|
<form action="$url_cgi" method="post"> |
1383 |
|
|
<input type="hidden" name="mycmd" value="interwikibox"> |
1384 |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1385 |
|
|
<input type="hidden" name="myintername" value="$intername"> |
1386 |
|
|
$intername: |
1387 |
|
|
<input type="$ignoretype{$localname}" name="mylocalname" value="" size="10"> |
1388 |
|
|
<input type="submit" value="Submit"> |
1389 |
|
|
</form> |
1390 |
|
|
EOD |
1391 |
|
|
} |
1392 |
|
|
# Walrus add (5) end |
1393 |
wakaba |
1.9 |
|
1394 |
wakaba |
1.16 |
sub code_convert { |
1395 |
wakaba |
1.27 |
my ($contentref, $code) = (shift, shift || $kanjicode); |
1396 |
wakaba |
1.31 |
$code = 'jis' if $code =~ /iso/; |
1397 |
|
|
$code = 'euc' if $code =~ /euc/; |
1398 |
|
|
$code = 'sjis' if $code =~ /shift/; |
1399 |
|
|
$code = 'utf8' if $code =~ /utf/; |
1400 |
wakaba |
1.27 |
# &Jcode::convert($contentref, $code); # for Jcode.pm |
1401 |
|
|
&jcode::convert($contentref, $code); # for jcode.pl |
1402 |
wakaba |
1.16 |
return $$contentref; |
1403 |
|
|
} |
1404 |
|
|
|
1405 |
|
|
sub test_convert { |
1406 |
|
|
my $txt = &text_to_html(<<"EOD", toc=>1); |
1407 |
|
|
*HEADER1 |
1408 |
|
|
**HEADER1-1 |
1409 |
|
|
-ITEM1 |
1410 |
|
|
-ITEM2 |
1411 |
|
|
-ITEM3 |
1412 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1413 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1414 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1415 |
|
|
|
1416 |
|
|
PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1417 |
|
|
PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1418 |
|
|
PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1419 |
|
|
**HEADER1-2 |
1420 |
|
|
:TERM1:DESCRIPTION1 AND ''BOLD'' |
1421 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1422 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1423 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1424 |
|
|
:TERM2:DESCRIPTION2 |
1425 |
|
|
:TERM3:DESCRIPTION3 |
1426 |
|
|
---- |
1427 |
|
|
*HEADER2 |
1428 |
|
|
**HEADER2-1 |
1429 |
|
|
http://www.hyuki.com/ |
1430 |
|
|
**HEADER2-2 |
1431 |
wakaba |
1.9 |
|
1432 |
wakaba |
1.16 |
[[YukiWiki2]] |
1433 |
wakaba |
1.9 |
|
1434 |
wakaba |
1.16 |
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1435 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1 |
1436 |
|
|
PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1 |
1437 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1438 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1439 |
|
|
>PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2 |
1440 |
|
|
|
1441 |
|
|
LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0 |
1442 |
|
|
|
1443 |
|
|
>LEVEL1 |
1444 |
|
|
>LEVEL1 |
1445 |
|
|
>LEVEL1 |
1446 |
|
|
>>LEVEL2 |
1447 |
|
|
>>LEVEL2 |
1448 |
|
|
>>LEVEL2 |
1449 |
|
|
>>>LEVEL3 |
1450 |
|
|
-HELLO-1 |
1451 |
|
|
--HELLO-2 |
1452 |
|
|
(HELLO-2, HELLO-2, HELLO-2) |
1453 |
|
|
---HELLO-3 |
1454 |
|
|
(HELLO-3, HELLO-3, HELLO-3) |
1455 |
|
|
--HELLO-2 |
1456 |
|
|
---HELLO-3 |
1457 |
|
|
--HELLO-2 |
1458 |
|
|
---HELLO-3 |
1459 |
|
|
>>>LEVEL3 |
1460 |
|
|
>>>LEVEL3 |
1461 |
|
|
>>>LEVEL3 |
1462 |
|
|
>>>LEVEL3 |
1463 |
|
|
EOD |
1464 |
|
|
print $txt; |
1465 |
|
|
exit; |
1466 |
|
|
} |
1467 |
wakaba |
1.9 |
|
1468 |
wakaba |
1.16 |
sub do_diff { |
1469 |
|
|
if (not &is_editable($form{mypage})) { |
1470 |
|
|
&do_read; |
1471 |
|
|
return; |
1472 |
|
|
} |
1473 |
|
|
&open_diff; |
1474 |
|
|
my $title = $form{mypage}; |
1475 |
wakaba |
1.29 |
&print_header($title, -noindex => 1); |
1476 |
wakaba |
1.16 |
$_ = &escape($diffbase{$form{mypage}}); |
1477 |
|
|
&close_diff; |
1478 |
|
|
print qq(<h3>$resource{difftitle}</h3>); |
1479 |
|
|
print qq($resource{diffnotice}); |
1480 |
|
|
print qq(<pre class="diff">); |
1481 |
|
|
foreach (split(/\n/, $_)) { |
1482 |
|
|
if (/^\+(.*)/) { |
1483 |
|
|
print qq(<b class="added">$1</b>\n); |
1484 |
|
|
} elsif (/^\-(.*)/) { |
1485 |
|
|
print qq(<s class="deleted">$1</s>\n); |
1486 |
|
|
} elsif (/^\=(.*)/) { |
1487 |
|
|
print qq(<span class="same">$1</span>\n); |
1488 |
|
|
} else { |
1489 |
|
|
print qq|??? $_\n|; |
1490 |
|
|
} |
1491 |
|
|
} |
1492 |
|
|
print qq(</pre>); |
1493 |
|
|
print qq(<hr>); |
1494 |
|
|
&print_footer($title); |
1495 |
|
|
} |
1496 |
wakaba |
1.9 |
|
1497 |
wakaba |
1.16 |
sub do_rss { |
1498 |
|
|
my $rss = new Yuki::RSS( |
1499 |
|
|
version => '1.0', |
1500 |
|
|
encoding => $charset, |
1501 |
|
|
); |
1502 |
|
|
$rss->channel( |
1503 |
|
|
title => $modifier_rss_title, |
1504 |
|
|
link => $modifier_rss_link, |
1505 |
|
|
description => $modifier_rss_description, |
1506 |
|
|
); |
1507 |
|
|
my $recentchanges = $database{$RecentChanges}; |
1508 |
|
|
my $count = 0; |
1509 |
|
|
foreach (split(/\n/, $recentchanges)) { |
1510 |
|
|
last if ($count >= 15); |
1511 |
wakaba |
1.28 |
/^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format. |
1512 |
wakaba |
1.16 |
my $title = &unarmor_name($1); |
1513 |
|
|
my $escaped_title = &escape($title); |
1514 |
|
|
my $link = $modifier_rss_link . '?' . &encode($title); |
1515 |
|
|
my $description = $escaped_title . &escape(&get_subjectline($title)); |
1516 |
|
|
$rss->add_item( |
1517 |
|
|
title => $escaped_title, |
1518 |
|
|
link => $link, |
1519 |
|
|
description => $description, |
1520 |
|
|
); |
1521 |
|
|
$count++; |
1522 |
|
|
} |
1523 |
|
|
# print RSS information (as XML). |
1524 |
|
|
print <<"EOD" |
1525 |
|
|
Content-type: text/xml |
1526 |
wakaba |
1.9 |
|
1527 |
wakaba |
1.16 |
@{[$rss->as_string]} |
1528 |
|
|
EOD |
1529 |
|
|
} |
1530 |
wakaba |
1.9 |
|
1531 |
wakaba |
1.16 |
sub is_exist_page { |
1532 |
|
|
my ($name) = @_; |
1533 |
|
|
if ($use_exists) { |
1534 |
|
|
return exists($database{$name}); |
1535 |
|
|
} else { |
1536 |
|
|
return $database{$name}; |
1537 |
|
|
} |
1538 |
wakaba |
1.27 |
} |
1539 |
|
|
|
1540 |
|
|
sub __get_database ($) { $database{ $_[0] } } |
1541 |
|
|
|
1542 |
|
|
package wiki::referer; |
1543 |
|
|
sub add ($$) { |
1544 |
|
|
my $page = shift; |
1545 |
|
|
my $uri = shift; |
1546 |
|
|
unless (ref $uri) { |
1547 |
|
|
require URI; |
1548 |
|
|
$uri = URI->new ($uri); |
1549 |
|
|
## Some schemes do not have query part. |
1550 |
|
|
eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ }; |
1551 |
|
|
$uri->fragment (undef); |
1552 |
|
|
} |
1553 |
|
|
$uri = $uri->canonical; |
1554 |
|
|
return unless $uri; |
1555 |
|
|
for my $regex (&get_dont_record) { |
1556 |
|
|
return if $uri =~ /$regex/; |
1557 |
|
|
} |
1558 |
|
|
my %list = get ($page); |
1559 |
|
|
$list{ $uri }++; |
1560 |
|
|
set ($page, \%list); |
1561 |
|
|
} |
1562 |
|
|
sub get ($) { |
1563 |
|
|
my $page = shift; |
1564 |
|
|
split /"/, main::get_info ($page, 'Referer'); |
1565 |
|
|
} |
1566 |
|
|
sub set ($%) { |
1567 |
|
|
my $page = shift; |
1568 |
|
|
my $list = shift; |
1569 |
|
|
main::set_info ($page, Referer => join '"', %$list); |
1570 |
|
|
} |
1571 |
|
|
|
1572 |
|
|
sub get_dont_record () { |
1573 |
|
|
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
1574 |
|
|
grep !/^#/, |
1575 |
|
|
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
1576 |
|
|
} |
1577 |
|
|
sub get_site_name () { |
1578 |
|
|
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
1579 |
wakaba |
1.28 |
my @item; |
1580 |
wakaba |
1.27 |
for (@lines) { |
1581 |
|
|
next if /^#/; |
1582 |
|
|
my ($uri, $name) = split /\s+/, $_, 2; |
1583 |
|
|
$uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; |
1584 |
wakaba |
1.28 |
$name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; |
1585 |
|
|
push @item, [$uri, qq(q($name))]; |
1586 |
wakaba |
1.27 |
} |
1587 |
wakaba |
1.28 |
@item; |
1588 |
wakaba |
1.27 |
} |
1589 |
|
|
|
1590 |
|
|
sub list_html ($) { |
1591 |
|
|
my $page = shift; |
1592 |
|
|
my %list = get ($page); |
1593 |
|
|
my $r = ''; |
1594 |
wakaba |
1.28 |
my @name = get_site_name; |
1595 |
wakaba |
1.27 |
for my $uri (sort keys %list) { |
1596 |
|
|
my $title; |
1597 |
wakaba |
1.28 |
for my $item (@name) { |
1598 |
|
|
if ($uri =~ /$item->[0]/) { |
1599 |
wakaba |
1.27 |
$title = $uri; |
1600 |
wakaba |
1.28 |
eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} |
1601 |
|
|
or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; |
1602 |
wakaba |
1.27 |
last; |
1603 |
|
|
} |
1604 |
|
|
} |
1605 |
|
|
my $euri = main::escape ($uri); |
1606 |
|
|
if ($title) { |
1607 |
|
|
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
1608 |
|
|
} else { |
1609 |
|
|
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
1610 |
|
|
} |
1611 |
|
|
} |
1612 |
|
|
$r ? qq(<ul>$r</ul>\n) : ''; |
1613 |
|
|
} |
1614 |
|
|
|
1615 |
|
|
sub __decode ($) { |
1616 |
|
|
my $s = shift; |
1617 |
|
|
$s =~ tr/+/ /; |
1618 |
|
|
$s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge; |
1619 |
|
|
main::code_convert (\$s); |
1620 |
wakaba |
1.16 |
} |
1621 |
wakaba |
1.9 |
|
1622 |
wakaba |
1.16 |
1; |
1623 |
|
|
__END__ |
1624 |
|
|
=head1 NAME |
1625 |
wakaba |
1.9 |
|
1626 |
wakaba |
1.16 |
wiki.cgi - This is YukiWiki, yet another Wiki clone. |
1627 |
wakaba |
1.9 |
|
1628 |
wakaba |
1.16 |
=head1 DESCRIPTION |
1629 |
wakaba |
1.9 |
|
1630 |
wakaba |
1.16 |
YukiWiki is yet another Wiki clone. |
1631 |
wakaba |
1.9 |
|
1632 |
wakaba |
1.16 |
YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]). |
1633 |
|
|
YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS), |
1634 |
|
|
and some embedded commands (such as [[#comment]] to add comments). |
1635 |
wakaba |
1.9 |
|
1636 |
wakaba |
1.16 |
Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail. |
1637 |
wakaba |
1.9 |
|
1638 |
wakaba |
1.16 |
=head1 AUTHOR |
1639 |
wakaba |
1.9 |
|
1640 |
wakaba |
1.16 |
Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/ |
1641 |
wakaba |
1.9 |
|
1642 |
wakaba |
1.16 |
=head1 LICENSE |
1643 |
wakaba |
1.9 |
|
1644 |
wakaba |
1.16 |
Copyright (C) 2000-2002 by Hiroshi Yuki. |
1645 |
wakaba |
1.9 |
|
1646 |
wakaba |
1.16 |
This program is free software; you can redistribute it and/or |
1647 |
|
|
modify it under the same terms as Perl itself. |
1648 |
wakaba |
1.9 |
|
1649 |
|
|
=cut |