1 |
wakaba |
1.9 |
#!/usr/bin/perl |
2 |
wakaba |
1.16 |
# wiki.cgi - This is YukiWiki, yet another Wiki clone. |
3 |
wakaba |
1.9 |
# |
4 |
wakaba |
1.16 |
# This program is free software; you can redistribute it and/or |
5 |
|
|
# modify it under the same terms as Perl itself. |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
w |
1.44 |
use lib qw(./lib); |
9 |
wakaba |
1.16 |
use CGI::Carp qw(fatalsToBrowser); |
10 |
w |
1.43 |
|
11 |
|
|
require 'wikidata/suikawiki-config.ph'; |
12 |
wakaba |
1.16 |
use Yuki::DiffText qw(difftext); |
13 |
|
|
use Fcntl; |
14 |
|
|
############################## |
15 |
wakaba |
1.31 |
my %fmt; ## formatter objects |
16 |
wakaba |
1.22 |
my %embed_command = ( |
17 |
|
|
searched => '^\[\[#searched:([^\]]+)\]\]$', |
18 |
w |
1.43 |
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
19 |
wakaba |
1.22 |
); |
20 |
w |
1.43 |
our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists); |
21 |
|
|
our (%PageName,$kanjicode,$lang,%fixedpage); |
22 |
|
|
|
23 |
wakaba |
1.16 |
############################## |
24 |
|
|
my $info_LastModified = 'LastModified'; |
25 |
|
|
my $info_IsFrozen = 'IsFrozen'; |
26 |
|
|
############################## |
27 |
|
|
my %form; |
28 |
|
|
my %database; |
29 |
|
|
my %infobase; |
30 |
|
|
my %diffbase; |
31 |
|
|
my %interwiki; |
32 |
|
|
############################## |
33 |
|
|
my %page_command = ( |
34 |
w |
1.43 |
$PageName{IndexPage} => 'index', |
35 |
|
|
$PageName{RssPage} => 'rss', |
36 |
wakaba |
1.41 |
AdminChangePassword => 'adminchangepasswordform', |
37 |
wakaba |
1.16 |
); |
38 |
|
|
my %command_do = ( |
39 |
|
|
read => \&do_read, |
40 |
wakaba |
1.25 |
TEXT_CSS => \&do_output_css, |
41 |
wakaba |
1.16 |
edit => \&do_edit, |
42 |
|
|
adminedit => \&do_adminedit, |
43 |
|
|
adminchangepasswordform => \&do_adminchangepasswordform, |
44 |
|
|
adminchangepassword => \&do_adminchangepassword, |
45 |
|
|
write => \&do_write, |
46 |
|
|
index => \&do_index, |
47 |
|
|
searchform => \&do_searchform, |
48 |
|
|
comment => \&do_comment, |
49 |
wakaba |
1.28 |
RandomJump => \&do_random_jump, |
50 |
wakaba |
1.16 |
rss => \&do_rss, |
51 |
|
|
diff => \&do_diff, |
52 |
wakaba |
1.41 |
wikiform => \&do_wikiform, |
53 |
|
|
map => \&do_map, |
54 |
wakaba |
1.16 |
); |
55 |
wakaba |
1.33 |
my $UA = ''; ## User agent name |
56 |
wakaba |
1.41 |
$| = 1; |
57 |
wakaba |
1.16 |
############################## |
58 |
wakaba |
1.9 |
|
59 |
|
|
sub main { |
60 |
wakaba |
1.32 |
$UA = $main::ENV{HTTP_USER_AGENT}; |
61 |
wakaba |
1.16 |
&open_db; |
62 |
|
|
&init_form; |
63 |
|
|
if ($command_do{$form{mycmd}}) { |
64 |
|
|
&{$command_do{$form{mycmd}}}; |
65 |
wakaba |
1.9 |
} else { |
66 |
wakaba |
1.42 |
&{$command_do{read}}; |
67 |
wakaba |
1.9 |
} |
68 |
wakaba |
1.16 |
&close_db; |
69 |
wakaba |
1.9 |
} |
70 |
|
|
|
71 |
|
|
sub do_read { |
72 |
wakaba |
1.26 |
my $content = $database{$form{mypage}}; |
73 |
wakaba |
1.41 |
#print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n"; |
74 |
wakaba |
1.27 |
my $lm = &get_info($form{mypage}, $info_LastModified); |
75 |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
76 |
wakaba |
1.32 |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
77 |
wakaba |
1.41 |
#print gmtime."Search...\n"; |
78 |
wakaba |
1.29 |
my ($r, $c) = get_search_result ($form{mypage}); |
79 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
80 |
|
|
my @toc; |
81 |
wakaba |
1.41 |
push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c; |
82 |
|
|
push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl; |
83 |
wakaba |
1.26 |
my $cf = 'SuikaWiki/0.9'; |
84 |
wakaba |
1.27 |
## Should be support at least: |
85 |
|
|
## - 'SuikaWiki/0.9' CRLF |
86 |
|
|
## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF |
87 |
|
|
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
88 |
wakaba |
1.32 |
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
89 |
wakaba |
1.28 |
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
90 |
wakaba |
1.41 |
#print gmtime."Header...\n"; |
91 |
wakaba |
1.42 |
&print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120, |
92 |
|
|
-content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0)); |
93 |
wakaba |
1.41 |
#print "\n". gmtime."Body...\n"; |
94 |
wakaba |
1.29 |
&print_content ($content, content_format => $cf, last_modified => $lm, |
95 |
|
|
-toc => \@toc); |
96 |
wakaba |
1.32 |
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}}; |
97 |
wakaba |
1.26 |
} else { |
98 |
wakaba |
1.42 |
&print_header($form{mypage}, -expires => time + 120, -last_modified => $lm); |
99 |
wakaba |
1.26 |
print "<pre>@{[&escape($content)]}</pre>"; |
100 |
|
|
} |
101 |
wakaba |
1.22 |
if ($c) { |
102 |
wakaba |
1.41 |
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
103 |
wakaba |
1.22 |
print $r; |
104 |
|
|
} |
105 |
wakaba |
1.29 |
if ($rl) { |
106 |
wakaba |
1.41 |
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
107 |
wakaba |
1.27 |
} |
108 |
wakaba |
1.41 |
#print "\n". gmtime."Footer...\n"; |
109 |
wakaba |
1.27 |
&print_footer($form{mypage}, $lm); |
110 |
wakaba |
1.41 |
#print "\n". gmtime."Fin...\n"; |
111 |
wakaba |
1.9 |
} |
112 |
|
|
|
113 |
wakaba |
1.25 |
sub do_output_css { |
114 |
wakaba |
1.37 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
115 |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
116 |
wakaba |
1.25 |
my $content = $database{$form{mypage}}; |
117 |
|
|
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
118 |
wakaba |
1.41 |
my $lm = gmtime &get_info($form{mypage}, $info_LastModified); |
119 |
|
|
print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n"; |
120 |
wakaba |
1.29 |
print "Last-Modified: $lm\n"; |
121 |
wakaba |
1.42 |
print "Expires: @{[scalar gmtime time+3600]}\n"; ## TODO: don't use asctime |
122 |
wakaba |
1.25 |
print "\n"; |
123 |
|
|
print $content; |
124 |
|
|
} else { |
125 |
|
|
print "Status: 406 Unsupported Media Type\n"; |
126 |
wakaba |
1.29 |
&print_header('WikiPageIsNotCSS', -noindex => 1); |
127 |
wakaba |
1.25 |
&print_content($database{WikiPageIsNotCSS}); |
128 |
|
|
&print_footer('WikiPageIsNotCSS'); |
129 |
|
|
} |
130 |
|
|
} |
131 |
|
|
|
132 |
wakaba |
1.32 |
sub id_and_name ($) { |
133 |
|
|
my $name = shift; |
134 |
wakaba |
1.36 |
if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) { |
135 |
wakaba |
1.32 |
qq{id="$name"><a name="$name"></a}; |
136 |
|
|
} else { |
137 |
|
|
qq{id="$name"}; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
|
141 |
wakaba |
1.9 |
sub do_edit { |
142 |
wakaba |
1.16 |
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
143 |
|
|
if (not &is_editable($page)) { |
144 |
wakaba |
1.42 |
&print_header($page, -noindex => 1); |
145 |
wakaba |
1.41 |
&print_message(&Resource('Error:ThisPageIsUneditable')); |
146 |
wakaba |
1.16 |
} elsif (&is_frozen($page)) { |
147 |
wakaba |
1.42 |
&print_header($page, -noindex => 1); |
148 |
wakaba |
1.41 |
&print_message(&Resource('Error:ThisPageIsUneditable')); |
149 |
wakaba |
1.16 |
} else { |
150 |
wakaba |
1.42 |
&print_header($page, -noindex => 1, -expires => time+60); |
151 |
wakaba |
1.16 |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
152 |
wakaba |
1.9 |
} |
153 |
wakaba |
1.30 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
154 |
wakaba |
1.32 |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
155 |
wakaba |
1.30 |
my ($r, $c) = get_search_result ($form{mypage}); |
156 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
157 |
|
|
if ($c) { |
158 |
wakaba |
1.41 |
print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
159 |
wakaba |
1.30 |
print $r; |
160 |
|
|
} |
161 |
|
|
if ($rl) { |
162 |
wakaba |
1.41 |
print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
163 |
wakaba |
1.30 |
} |
164 |
wakaba |
1.16 |
&print_footer($page); |
165 |
wakaba |
1.9 |
} |
166 |
|
|
|
167 |
wakaba |
1.16 |
sub do_adminedit { |
168 |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
169 |
wakaba |
1.29 |
&print_header($page, -noindex => 1); |
170 |
wakaba |
1.16 |
if (not &is_editable($page)) { |
171 |
wakaba |
1.41 |
&print_message(&Resource('Error:ThisPageIsUneditable')); |
172 |
wakaba |
1.9 |
} else { |
173 |
wakaba |
1.41 |
&print_message(&Resource('Error:PasswordIsNotSpecified')); |
174 |
wakaba |
1.16 |
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1); |
175 |
wakaba |
1.9 |
} |
176 |
wakaba |
1.16 |
&print_footer($page); |
177 |
wakaba |
1.9 |
} |
178 |
|
|
|
179 |
wakaba |
1.16 |
sub do_adminchangepasswordform { |
180 |
wakaba |
1.41 |
&print_header('AdminChangePassword', -noindex => 1); |
181 |
wakaba |
1.16 |
&print_passwordform; |
182 |
wakaba |
1.41 |
&print_footer('AdminChangePassword'); |
183 |
wakaba |
1.16 |
} |
184 |
wakaba |
1.9 |
|
185 |
wakaba |
1.16 |
sub do_adminchangepassword { |
186 |
|
|
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
187 |
wakaba |
1.41 |
&print_error(&Resource('Error:PasswordMismatch')); |
188 |
wakaba |
1.16 |
} |
189 |
w |
1.43 |
my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword'); |
190 |
wakaba |
1.16 |
if ($validpassword_crypt) { |
191 |
|
|
if (not &valid_password($form{myoldpassword})) { |
192 |
wakaba |
1.41 |
# &send_mail_to_admin(<<"EOD", "AdminChangePassword"); |
193 |
|
|
#myoldpassword=$form{myoldpassword} |
194 |
|
|
#mynewpassword=$form{mynewpassword} |
195 |
|
|
#mynewpassword2=$form{mynewpassword2} |
196 |
|
|
#EOD |
197 |
|
|
&print_error(&Resource('Error:PasswordIsIncorrect')); |
198 |
wakaba |
1.9 |
} |
199 |
wakaba |
1.16 |
} |
200 |
|
|
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
201 |
|
|
my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z'); |
202 |
|
|
my $salt1 = $token[(time | $$) % scalar(@token)]; |
203 |
|
|
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
204 |
|
|
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
205 |
w |
1.43 |
&set_info($PageName{AdminSpecialPage}, 'AdminPassword', $crypted); |
206 |
wakaba |
1.16 |
|
207 |
wakaba |
1.41 |
&print_header('CompletedSuccessfully', -noindex => 1); |
208 |
|
|
&print_message(&Resource('Error:PasswordIsChanged')); |
209 |
|
|
&print_footer('CompletedSuccessfully'); |
210 |
wakaba |
1.16 |
} |
211 |
|
|
|
212 |
|
|
sub do_index { |
213 |
wakaba |
1.37 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
214 |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
215 |
w |
1.43 |
&print_header($PageName{IndexPage}); |
216 |
wakaba |
1.16 |
print qq(<ul>); |
217 |
|
|
foreach my $page (sort keys %database) { |
218 |
|
|
if (&is_editable($page)) { |
219 |
wakaba |
1.24 |
print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>); |
220 |
wakaba |
1.9 |
} |
221 |
|
|
} |
222 |
wakaba |
1.16 |
print qq(</ul>); |
223 |
wakaba |
1.37 |
my ($r, $c) = get_search_result ($form{mypage}); |
224 |
|
|
if ($c) { |
225 |
wakaba |
1.41 |
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
226 |
wakaba |
1.37 |
print $r; |
227 |
|
|
} |
228 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
229 |
|
|
if ($rl) { |
230 |
wakaba |
1.41 |
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
231 |
wakaba |
1.37 |
} |
232 |
w |
1.43 |
&print_footer($PageName{IndexPage}); |
233 |
wakaba |
1.9 |
} |
234 |
|
|
|
235 |
wakaba |
1.16 |
sub do_write { |
236 |
|
|
if (&frozen_reject()) { |
237 |
|
|
return; |
238 |
wakaba |
1.9 |
} |
239 |
|
|
|
240 |
|
|
if (not &is_editable($form{mypage})) { |
241 |
wakaba |
1.29 |
&print_header($form{mypage}, -noindex => 1); |
242 |
wakaba |
1.41 |
&print_message(&Resource('Error:ThisPageIsUneditable')); |
243 |
wakaba |
1.16 |
&print_footer($form{mypage}); |
244 |
wakaba |
1.9 |
return; |
245 |
|
|
} |
246 |
|
|
|
247 |
wakaba |
1.16 |
if (&conflict($form{mypage}, $form{mymsg})) { |
248 |
wakaba |
1.9 |
return; |
249 |
|
|
} |
250 |
|
|
|
251 |
wakaba |
1.16 |
# Making diff |
252 |
wakaba |
1.9 |
{ |
253 |
wakaba |
1.16 |
&open_diff; |
254 |
|
|
my @msg1 = split(/\n/, $database{$form{mypage}}); |
255 |
wakaba |
1.9 |
my @msg2 = split(/\n/, $form{mymsg}); |
256 |
wakaba |
1.16 |
$diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); |
257 |
|
|
&close_diff; |
258 |
wakaba |
1.9 |
} |
259 |
|
|
|
260 |
|
|
if ($form{mymsg}) { |
261 |
wakaba |
1.16 |
$database{$form{mypage}} = $form{mymsg}; |
262 |
wakaba |
1.41 |
#&send_mail_to_admin($form{mypage}, "Modify"); |
263 |
wakaba |
1.16 |
if ($form{mytouch}) { |
264 |
wakaba |
1.41 |
&set_info($form{mypage}, $info_LastModified, time); |
265 |
wakaba |
1.16 |
&update_recent_changes; |
266 |
|
|
} |
267 |
|
|
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
268 |
wakaba |
1.36 |
my $fragment = ''; |
269 |
|
|
$fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd}; |
270 |
wakaba |
1.33 |
if ($form{__comment_anchor_index}) { |
271 |
wakaba |
1.36 |
$fragment .= qq(#anchor-$form{__comment_anchor_index}); |
272 |
wakaba |
1.33 |
} elsif ($form{__wikiform_anchor_index}) { |
273 |
wakaba |
1.36 |
$fragment .= qq(#wikiform-$form{__wikiform_anchor_index}); |
274 |
wakaba |
1.33 |
} |
275 |
wakaba |
1.41 |
&print_header('CompletedSuccessfully', -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment)); |
276 |
|
|
&print_message(&Resource('Error:SavedSuccessfully')); |
277 |
|
|
&print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}"); |
278 |
|
|
&print_footer('CompletedSuccessfully'); |
279 |
wakaba |
1.16 |
} else { |
280 |
wakaba |
1.41 |
#&send_mail_to_admin($form{mypage}, "Delete"); |
281 |
wakaba |
1.16 |
delete $database{$form{mypage}}; |
282 |
|
|
delete $infobase{$form{mypage}}; |
283 |
|
|
if ($form{mytouch}) { |
284 |
|
|
&update_recent_changes; |
285 |
|
|
} |
286 |
wakaba |
1.29 |
&print_header($form{mypage}, -noindex => 1); |
287 |
wakaba |
1.41 |
&print_message(&Resource('Error:PageIsDeletedSuccessfully')); |
288 |
wakaba |
1.16 |
&print_footer($form{mypage}); |
289 |
wakaba |
1.9 |
} |
290 |
|
|
} |
291 |
|
|
|
292 |
wakaba |
1.22 |
sub get_search_result ($;%) { |
293 |
wakaba |
1.32 |
my $word = lc shift; |
294 |
wakaba |
1.22 |
my %option = @_; |
295 |
wakaba |
1.30 |
my @r; |
296 |
|
|
foreach my $page (keys %database) { |
297 |
wakaba |
1.41 |
next if !$option{-match_myself} && ($page eq $word); |
298 |
|
|
my $content = lc $database{$page}; |
299 |
wakaba |
1.32 |
if (index (lc $page, $word) > -1) { |
300 |
wakaba |
1.41 |
my $c = $content =~ s/\Q$word\E//g; |
301 |
wakaba |
1.30 |
push @r, [$page, $c+20]; |
302 |
wakaba |
1.32 |
} elsif (index ($word, lc $page) > -1) { |
303 |
wakaba |
1.41 |
my $c = $content =~ s/\Q$word\E//g; |
304 |
wakaba |
1.30 |
push @r, [$page, $c+10]; |
305 |
wakaba |
1.41 |
} elsif (my $c = $content =~ s/\Q$word\E//g) { |
306 |
wakaba |
1.30 |
push @r, [$page, $c]; |
307 |
wakaba |
1.22 |
} |
308 |
|
|
} |
309 |
wakaba |
1.41 |
#my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s }; |
310 |
|
|
my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
311 |
wakaba |
1.30 |
$r = qq|<ul class="search-result">$r</ul>| if $r; |
312 |
|
|
wantarray? ($r, scalar @r): $r; |
313 |
wakaba |
1.22 |
} |
314 |
|
|
|
315 |
wakaba |
1.28 |
sub do_random_jump { |
316 |
|
|
my @list = keys %database; |
317 |
|
|
my $name = &encode ($list[rand @list]); |
318 |
wakaba |
1.41 |
my $scheme = 'http'; |
319 |
|
|
$scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
320 |
wakaba |
1.29 |
print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n"; |
321 |
wakaba |
1.28 |
print "\n"; |
322 |
|
|
} |
323 |
|
|
|
324 |
wakaba |
1.9 |
sub print_error { |
325 |
|
|
my ($msg) = @_; |
326 |
w |
1.43 |
&print_header($PageName{ErrorPage}, -noindex => 1); |
327 |
wakaba |
1.16 |
print qq(<p><strong class="error">$msg</strong></p>); |
328 |
w |
1.43 |
&print_footer($PageName{ErrorPage}); |
329 |
wakaba |
1.9 |
exit(0); |
330 |
|
|
} |
331 |
|
|
|
332 |
wakaba |
1.27 |
sub print_header ($;%) { |
333 |
|
|
my ($page, %option) = @_; |
334 |
wakaba |
1.41 |
my @head; |
335 |
|
|
$option{body_class} = &is_frozen($page) ? 'frozen' : 'normal'; |
336 |
|
|
$option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; |
337 |
wakaba |
1.32 |
if ($option{-goto}) { |
338 |
wakaba |
1.36 |
if ($UA =~ m#Opera|MSIE 2\.#) { |
339 |
wakaba |
1.41 |
## WARNING: This code may output unsafe HTML document if |
340 |
|
|
## $option{-goto} is not clean. |
341 |
wakaba |
1.36 |
$option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#; |
342 |
wakaba |
1.33 |
print qq{Refresh: 0; url=$option{-goto}\n}; |
343 |
wakaba |
1.41 |
push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">); |
344 |
wakaba |
1.32 |
} else { |
345 |
wakaba |
1.36 |
$option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#; |
346 |
wakaba |
1.33 |
print qq{Refresh: 0; url="$option{-goto}"\n}; |
347 |
wakaba |
1.41 |
push @head, qq(<meta http-equiv="refresh" content="0; url="@{[&escape($option{-goto})]}"">); |
348 |
wakaba |
1.32 |
} |
349 |
|
|
} |
350 |
wakaba |
1.41 |
print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified}; |
351 |
wakaba |
1.42 |
if ($option{-expires}) { |
352 |
|
|
print qq{Expires: @{[scalar gmtime $option{-expires}]}\n}; |
353 |
|
|
} |
354 |
wakaba |
1.32 |
if ($UA =~ m#Mozilla/2#) { |
355 |
wakaba |
1.41 |
my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}}; |
356 |
|
|
print qq{Content-Type: $ct\n}; |
357 |
|
|
push @head, qq{<meta http-equiv="content-type" content="$ct">}; |
358 |
wakaba |
1.36 |
} elsif ($UA =~ m#Infomosaic#) { |
359 |
|
|
print qq{Content-Type: text/html\n}; |
360 |
wakaba |
1.32 |
} else { |
361 |
wakaba |
1.41 |
print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n}; |
362 |
wakaba |
1.32 |
} |
363 |
wakaba |
1.41 |
push @head, qq(<title>@{[&escape($page)]}</title>); |
364 |
wakaba |
1.42 |
if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) { |
365 |
|
|
push @head, qq(<link rel="stylesheet" type="text/css" href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.&get_info($PageName{DefaultStyleForHTML}, $info_LastModified))]}"); |
366 |
|
|
} |
367 |
wakaba |
1.41 |
push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex}; |
368 |
wakaba |
1.36 |
my ($Links, $links) = &make_navigate_links ($page); |
369 |
wakaba |
1.41 |
#print $Links; ## Link: fields |
370 |
|
|
$links = join "\n", (@head, $links); |
371 |
wakaba |
1.9 |
print <<"EOD"; |
372 |
wakaba |
1.18 |
Content-Language: $lang |
373 |
|
|
Content-Style-Type: text/css |
374 |
wakaba |
1.9 |
|
375 |
wakaba |
1.41 |
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
376 |
|
|
"http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> |
377 |
|
|
<html lang="$lang" class="$option{body_class}"> |
378 |
wakaba |
1.36 |
<head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile"> |
379 |
|
|
$links |
380 |
wakaba |
1.9 |
</head> |
381 |
wakaba |
1.41 |
<body class="$option{body_class}"> |
382 |
wakaba |
1.22 |
EOD |
383 |
wakaba |
1.41 |
&print_navigate_links ($page); |
384 |
|
|
print <<EOD; |
385 |
wakaba |
1.29 |
<h1 class="header">@{[&escape($page)]}</h1> |
386 |
wakaba |
1.22 |
EOD |
387 |
|
|
} |
388 |
|
|
|
389 |
wakaba |
1.41 |
sub get_charset_name ($;%) { |
390 |
|
|
my ($charset, %option) = (lc shift, @_); |
391 |
|
|
if ($charset =~ 'euc') { |
392 |
|
|
$charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp'; |
393 |
|
|
} elsif ($charset =~ 'sjis' || $charset =~ 'shift') { |
394 |
|
|
$charset = $option{compatible} ? 'x-sjis' : 'shift_jis'; |
395 |
|
|
} elsif ($charset =~ 'jis') { |
396 |
|
|
$charset = 'iso-2022-jp'; |
397 |
wakaba |
1.32 |
} |
398 |
|
|
$charset; |
399 |
|
|
} |
400 |
|
|
|
401 |
wakaba |
1.22 |
sub print_navigate_links (@) { |
402 |
|
|
my ($page) = @_; |
403 |
wakaba |
1.41 |
my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0; |
404 |
|
|
my $cookedpage = &encode($page); |
405 |
wakaba |
1.22 |
print <<EOH; |
406 |
wakaba |
1.16 |
<div class="tools"> |
407 |
|
|
@{[ $editable |
408 |
wakaba |
1.41 |
? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | ) |
409 |
wakaba |
1.16 |
: qq() |
410 |
|
|
]} |
411 |
wakaba |
1.41 |
<a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd" title="@{[&Resource('ViewThisPageLong',escape=>1)]}">@{[&Resource('ViewThisPage',escape=>1)]}</a> | |
412 |
|
|
<a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> | |
413 |
w |
1.43 |
<a href="$url_cgi?$PageName{CreatePage}" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> | |
414 |
|
|
<a href="$url_cgi?$PageName{IndexPage}" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> | |
415 |
|
|
<a href="$url_cgi?$PageName{FrontPage}" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> | |
416 |
|
|
<a href="$url_cgi?$PageName{SearchPage}" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> | |
417 |
wakaba |
1.41 |
<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink" title="@{[&Resource('GoSomewhereLong',escape=>1)]}">@{[&Resource('GoSomewhere',escape=>1)]}</a> | |
418 |
|
|
<a href="$url_cgi?RecentChanges" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a> |
419 |
wakaba |
1.29 |
</div> |
420 |
|
|
EOH |
421 |
wakaba |
1.36 |
} |
422 |
|
|
|
423 |
|
|
sub make_navigate_links ($) { |
424 |
|
|
my $page = shift; |
425 |
|
|
my @link; |
426 |
wakaba |
1.41 |
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page); |
427 |
|
|
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page); |
428 |
|
|
push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')}; |
429 |
|
|
push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')}; |
430 |
w |
1.43 |
push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')}; |
431 |
|
|
push @link, {rel=>'home', href=>"$url_cgi?$PageName{FrontPage}", class=>'wiki', title=>&Resource('GoToHomePageLink')}; |
432 |
wakaba |
1.41 |
push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')}; |
433 |
|
|
push @link, {rel=>'News', href=>"$url_cgi?RecentChanges", class=>"wiki", title=>&Resource('GoToRecentChangesLink')}; |
434 |
w |
1.43 |
push @link, {rel=>'News', href=>"$url_cgi?$PageName{RssPage}", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'}; |
435 |
|
|
push @link, {rel=>'search', href=>"$url_cgi?$PageName{SearchPage}", class=>'wiki', title=>&Resource('GoToSearchPageLink')}; |
436 |
wakaba |
1.41 |
push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')}; |
437 |
|
|
push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')}; |
438 |
|
|
push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToLink')}; |
439 |
|
|
push @link, {rel=>'jump', href=>qq(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='$url_cgi%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>&Resource('JumpToEditLink')}; |
440 |
|
|
push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')}; |
441 |
|
|
push @link, {rel=>'history', href=>$uri{cvs_wikipage}.do{my $s=$page;$s=~s/(.)/sprintf '%02X', ord $1/ges;$s}.'.txt', title=>&Resource('ViewHistoryOfThisPageLink'),hreflang=>'en'} if $uri{cvs_wikipage}; |
442 |
|
|
push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'}; |
443 |
|
|
push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'}; |
444 |
wakaba |
1.36 |
my ($Links, $links) = ('', ''); |
445 |
|
|
for my $e (@link) { |
446 |
|
|
$links .= qq(<link); |
447 |
|
|
$Links .= qq(Link: <$e->{href}>); |
448 |
|
|
for my $attr (qw/rel rev href title class type hreflang charset/) { |
449 |
|
|
$links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr}; |
450 |
|
|
} |
451 |
|
|
for my $attr (qw/rel rev title/) { |
452 |
|
|
$Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr}; |
453 |
|
|
} |
454 |
|
|
$links .= qq(>\n); |
455 |
|
|
$Links .= qq(\n); |
456 |
|
|
} |
457 |
|
|
wantarray ? ($Links, $links) : $Links; |
458 |
wakaba |
1.9 |
} |
459 |
|
|
|
460 |
wakaba |
1.16 |
sub print_footer { |
461 |
wakaba |
1.27 |
my ($page, $lm) = @_; |
462 |
wakaba |
1.33 |
my $epage = &encode ($page); |
463 |
w |
1.44 |
my $cvslog1 = q$Revision: 1.43 $; |
464 |
|
|
my $cvslog2 = q$Date: 2003/01/01 01:29:04 $; |
465 |
wakaba |
1.22 |
print_navigate_links ($page); |
466 |
|
|
print <<"EOD"; |
467 |
wakaba |
1.41 |
@{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]} |
468 |
wakaba |
1.16 |
<div class="footer"> |
469 |
wakaba |
1.41 |
<a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 © 2000-2002 by Hiroshi Yuki">@{[&Resource('About:Name:YukiWiki',escape=>1)]}</a> <a href="http://digit.que.ne.jp/work/" title="WalWiki 2.0.beta1.wal.1 © 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a> |
470 |
|
|
<a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a> |
471 |
wakaba |
1.18 |
</div> |
472 |
wakaba |
1.16 |
</body> |
473 |
|
|
</html> |
474 |
wakaba |
1.12 |
EOD |
475 |
wakaba |
1.9 |
} |
476 |
|
|
|
477 |
wakaba |
1.16 |
sub escape { |
478 |
|
|
my $s = shift; |
479 |
|
|
$s =~ s|\r\n|\n|g; |
480 |
wakaba |
1.23 |
$s =~ s|&|&|g; |
481 |
wakaba |
1.16 |
$s =~ s|<|<|g; |
482 |
|
|
$s =~ s|>|>|g; |
483 |
|
|
$s =~ s|"|"|g; |
484 |
|
|
return $s; |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
sub unescape { |
488 |
|
|
my $s = shift; |
489 |
|
|
# $s =~ s|\n|\r\n|g; |
490 |
wakaba |
1.23 |
$s =~ s|<|<|g; |
491 |
|
|
$s =~ s|>|>|g; |
492 |
|
|
$s =~ s|"|"|g; |
493 |
|
|
$s =~ s|&|&|g; |
494 |
wakaba |
1.16 |
return $s; |
495 |
|
|
} |
496 |
|
|
|
497 |
wakaba |
1.26 |
sub print_content ($;$) { |
498 |
wakaba |
1.27 |
my ($rawcontent, %option) = @_; |
499 |
wakaba |
1.29 |
print &text_to_html($rawcontent, toc=>1, %option); |
500 |
wakaba |
1.9 |
} |
501 |
|
|
|
502 |
wakaba |
1.16 |
sub text_to_html { |
503 |
|
|
my ($txt, %option) = @_; |
504 |
wakaba |
1.29 |
my @toc; |
505 |
|
|
my @toc2 = @{$option{-toc}||[]}; |
506 |
wakaba |
1.16 |
my $tocnum = 0; |
507 |
wakaba |
1.41 |
|
508 |
|
|
## Load constants |
509 |
|
|
my %const; |
510 |
|
|
if ($option{content_format} =~ /import="([^"]+)"/) { |
511 |
|
|
for (split /\s*,\s*/, $1) { |
512 |
|
|
my $wp = $database{$_}; |
513 |
|
|
if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) { |
514 |
|
|
wiki::suikawikiconst::to_hash ($wp => \%const); |
515 |
|
|
} |
516 |
|
|
} |
517 |
|
|
} |
518 |
|
|
|
519 |
|
|
$txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge; |
520 |
|
|
my (@txt) = split(/\n/, $txt); |
521 |
wakaba |
1.16 |
my (@saved, @result); |
522 |
|
|
unshift(@saved, "</p>"); |
523 |
|
|
push(@result, "<p>"); |
524 |
wakaba |
1.9 |
foreach (@txt) { |
525 |
|
|
chomp; |
526 |
wakaba |
1.25 |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
527 |
|
|
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
528 |
wakaba |
1.41 |
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>'); |
529 |
wakaba |
1.18 |
$tocnum++; |
530 |
wakaba |
1.25 |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
531 |
|
|
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
532 |
wakaba |
1.41 |
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>'); |
533 |
wakaba |
1.18 |
$tocnum++; |
534 |
wakaba |
1.25 |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
535 |
|
|
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
536 |
wakaba |
1.41 |
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>'); |
537 |
wakaba |
1.18 |
$tocnum++; |
538 |
wakaba |
1.25 |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
539 |
wakaba |
1.16 |
# if (/^\*\*(.*)/) { |
540 |
|
|
# Walrus mod (6) end |
541 |
wakaba |
1.25 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
542 |
wakaba |
1.41 |
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>'); |
543 |
wakaba |
1.16 |
$tocnum++; |
544 |
wakaba |
1.25 |
} elsif (/^\*([^\x0D\x0A]*)/) { |
545 |
|
|
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
546 |
wakaba |
1.41 |
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>'); |
547 |
wakaba |
1.16 |
$tocnum++; |
548 |
wakaba |
1.25 |
} elsif (/^(={1,6})(.*)/) { |
549 |
wakaba |
1.18 |
&back_push('ol', length($1), \@saved, \@result); |
550 |
wakaba |
1.41 |
push(@result, '<li>' . &inline($2, const => \%const) . '</li>'); |
551 |
wakaba |
1.25 |
} elsif (/^(-{1,6})(.*)/) { |
552 |
wakaba |
1.28 |
&back_push('ul', length($1), \@saved, \@result); |
553 |
|
|
my ($pf, $l) = ('', $2); |
554 |
|
|
if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { |
555 |
|
|
my $num = 0+$1; |
556 |
|
|
$pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
557 |
|
|
} |
558 |
wakaba |
1.41 |
push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>'); |
559 |
wakaba |
1.9 |
} elsif (/^:([^:]+):(.*)/) { |
560 |
wakaba |
1.16 |
&back_push('dl', 1, \@saved, \@result); |
561 |
wakaba |
1.41 |
push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>'); |
562 |
wakaba |
1.30 |
} elsif (/^(?!>>\d)(>{1,5})(.*)/) { |
563 |
wakaba |
1.16 |
&back_push('blockquote', length($1), \@saved, \@result); |
564 |
wakaba |
1.30 |
push @result, "<p>"; |
565 |
wakaba |
1.41 |
push(@result, &inline($2, const => \%const)); |
566 |
wakaba |
1.30 |
unshift @saved, "</p>"; |
567 |
wakaba |
1.9 |
} elsif (/^\s*$/) { |
568 |
|
|
push(@result, splice(@saved)); |
569 |
wakaba |
1.30 |
push(@result, "<p>"); |
570 |
wakaba |
1.9 |
unshift(@saved, "</p>"); |
571 |
|
|
} elsif (/^(\s+.*)$/) { |
572 |
wakaba |
1.16 |
&back_push('pre', 1, \@saved, \@result); |
573 |
wakaba |
1.41 |
push(@result, &inline($1, const => \%const)); |
574 |
|
|
} elsif (/^\,(.*?)[\x0D\x0A]*$/) { |
575 |
|
|
&back_push('table', 1, \@saved, \@result); |
576 |
wakaba |
1.16 |
####### |
577 |
|
|
# This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki. |
578 |
|
|
# XXXXX |
579 |
|
|
my $tmp = "$1,"; |
580 |
|
|
my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g); |
581 |
|
|
my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value; |
582 |
|
|
my @colspan = map {($_ eq '==') ? 0 : 1} @value; |
583 |
|
|
for (my $i = 0; $i < @value; $i++) { |
584 |
|
|
if ($colspan[$i]) { |
585 |
|
|
while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') { |
586 |
|
|
$colspan[$i]++; |
587 |
|
|
} |
588 |
|
|
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : ''; |
589 |
wakaba |
1.41 |
$value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], const => \%const)); |
590 |
wakaba |
1.16 |
} else { |
591 |
|
|
$value[$i] = ''; |
592 |
|
|
} |
593 |
|
|
} |
594 |
|
|
push(@result, join('', '<tr>', @value, '</tr>')); |
595 |
|
|
# XXXXX |
596 |
|
|
####### |
597 |
wakaba |
1.29 |
} elsif (/^\[(INS|DEL|PRE)\[\s*$/) { |
598 |
wakaba |
1.28 |
push @result, splice (@saved), '<'.lc($1).'>'; |
599 |
|
|
unshift @saved, "</p>"; |
600 |
|
|
push @result, "<p>"; |
601 |
wakaba |
1.29 |
} elsif (/^\](INS|DEL|PRE)\]\s*$/) { |
602 |
wakaba |
1.28 |
push @result, splice (@saved), '</'.lc($1).'>'; |
603 |
|
|
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { |
604 |
|
|
my $num = 0+$1; |
605 |
|
|
push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>); |
606 |
wakaba |
1.41 |
push @result, &inline ($2, const => \%const); |
607 |
wakaba |
1.9 |
} else { |
608 |
wakaba |
1.41 |
push(@result, &inline($_, const => \%const)); |
609 |
wakaba |
1.9 |
} |
610 |
|
|
} |
611 |
|
|
push(@result, splice(@saved)); |
612 |
wakaba |
1.27 |
|
613 |
|
|
my $toc = ''; |
614 |
wakaba |
1.16 |
if ($option{toc}) { |
615 |
|
|
# Convert @toc (table of contents) to HTML. |
616 |
|
|
# This part is taken from Makio Tsukamoto's WalWiki. |
617 |
|
|
my (@tocsaved, @tocresult); |
618 |
wakaba |
1.29 |
foreach (@toc,@toc2) { |
619 |
wakaba |
1.25 |
if (/^(-{1,6})(.*)$/) { |
620 |
wakaba |
1.16 |
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
621 |
|
|
push(@tocresult, '<li>' . $2 . '</li>'); |
622 |
|
|
} |
623 |
|
|
} |
624 |
|
|
push(@tocresult, splice(@tocsaved)); |
625 |
wakaba |
1.27 |
$toc = join("\n", @tocresult); |
626 |
|
|
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
627 |
wakaba |
1.16 |
} |
628 |
wakaba |
1.30 |
$toc .= join("\n", @result); |
629 |
|
|
$toc =~ s#<p>\n</p>##g; |
630 |
|
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
631 |
|
|
$toc =~ s#<pre>\n#<pre>#g; |
632 |
|
|
$toc; |
633 |
wakaba |
1.9 |
} |
634 |
|
|
|
635 |
|
|
sub back_push { |
636 |
wakaba |
1.16 |
my ($tag, $level, $savedref, $resultref, $attr) = @_; |
637 |
|
|
while (@$savedref > $level) { |
638 |
|
|
push(@$resultref, shift(@$savedref)); |
639 |
|
|
} |
640 |
|
|
if ($savedref->[0] ne "</$tag>") { |
641 |
|
|
push(@$resultref, splice(@$savedref)); |
642 |
|
|
} |
643 |
|
|
while (@$savedref < $level) { |
644 |
|
|
unshift(@$savedref, "</$tag>"); |
645 |
|
|
push(@$resultref, "<$tag$attr>"); |
646 |
wakaba |
1.9 |
} |
647 |
|
|
} |
648 |
|
|
|
649 |
wakaba |
1.41 |
sub inline ($;%) { |
650 |
|
|
my ($line, %option) = @_; |
651 |
wakaba |
1.16 |
$line = &escape($line); |
652 |
wakaba |
1.34 |
$line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge; |
653 |
wakaba |
1.32 |
$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; |
654 |
wakaba |
1.30 |
$line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g; |
655 |
|
|
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g; |
656 |
|
|
$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; |
657 |
|
|
$line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g; |
658 |
|
|
$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; |
659 |
|
|
$line =~ s%\[Q\[([^]]+)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%¡Ö<q@{[$2?qq( cite="$2"):'']}>$1</q>¡×%g; |
660 |
|
|
$line =~ s|'''([^']+)'''|<strong>$1</strong>|g; |
661 |
|
|
$line =~ s|''([^']+)''|<em>$1</em>|g; |
662 |
wakaba |
1.31 |
$line =~ s{ |
663 |
wakaba |
1.41 |
(\[\[(\#\S+?)\]\]) |
664 |
|
|
|\[\[([^[]+?)](?:>>([0-9]+))?] |
665 |
wakaba |
1.28 |
|>>([0-9]+) |
666 |
wakaba |
1.31 |
|<([A-Za-z0-9%]+:(?:(?!>).)+)> |
667 |
|
|
}{ |
668 |
|
|
my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6); |
669 |
wakaba |
1.28 |
if ($l) { |
670 |
wakaba |
1.41 |
return &embedded_to_html($1); |
671 |
wakaba |
1.28 |
} elsif (defined $page) { |
672 |
|
|
&make_wikilink ($page, anchor => 0+$anchor); |
673 |
|
|
} elsif ($anum) { |
674 |
|
|
qq(<a href="#anchor-$anum" class="wiki-anchor">>>$anum</a>); |
675 |
wakaba |
1.31 |
} elsif ($uri) { |
676 |
|
|
&make_urilink ($uri); |
677 |
wakaba |
1.28 |
} |
678 |
wakaba |
1.31 |
}gex; |
679 |
wakaba |
1.16 |
return $line; |
680 |
|
|
} |
681 |
|
|
|
682 |
wakaba |
1.28 |
sub make_wikilink ($%) { |
683 |
|
|
my ($ename, %option) = @_; |
684 |
|
|
my $name = &unescape ($ename); |
685 |
|
|
if ($database{$name}) { |
686 |
|
|
my $subject = &escape (&get_subjectline ($name, delimiter => '')); |
687 |
|
|
if ($option{anchor}) { |
688 |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename>>$option{anchor}</a>); |
689 |
|
|
} else { |
690 |
|
|
return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>); |
691 |
|
|
} |
692 |
|
|
} else { |
693 |
wakaba |
1.42 |
return qq(<a title="@{[&Resource('JumpAndEditWikiPage',escape=>1)]}" href="$url_cgi?@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</span></a>); |
694 |
wakaba |
1.28 |
} |
695 |
|
|
} |
696 |
|
|
|
697 |
wakaba |
1.31 |
sub make_urilink ($;%) { |
698 |
|
|
require URI; |
699 |
|
|
my $uri = shift; |
700 |
|
|
if ($uri =~ s/^IW://) { ## InterWiki (not URI) |
701 |
|
|
$uri = &unescape ($uri); |
702 |
|
|
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) { |
703 |
|
|
my ($site, $name) = ($1, $2); |
704 |
|
|
for ($site, $name) { |
705 |
|
|
if (s/^"//) { s/"$//; s/\\(.)/$1/g } |
706 |
|
|
} |
707 |
wakaba |
1.41 |
&init_InterWikiName () unless $interwiki{'[[]]'}; |
708 |
wakaba |
1.31 |
if ($interwiki{$site}) { |
709 |
wakaba |
1.41 |
&load_formatter ('interwiki'); |
710 |
wakaba |
1.31 |
my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name})); |
711 |
|
|
$site = &escape ($site); $name = &escape ($name); |
712 |
wakaba |
1.32 |
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>>); |
713 |
wakaba |
1.31 |
} else { |
714 |
wakaba |
1.41 |
qq(<@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}>); |
715 |
wakaba |
1.31 |
} |
716 |
|
|
} else { |
717 |
wakaba |
1.41 |
qq(<@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}>); |
718 |
wakaba |
1.31 |
} |
719 |
|
|
} elsif ($uri =~ /^urn:/) { ## URN |
720 |
|
|
my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical); |
721 |
|
|
qq(<<a href="$uri2" title="URI: <$uri> (via <$uri2>)" class="out-of-wiki urn">$uri</a>>); |
722 |
|
|
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI) |
723 |
|
|
my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical); |
724 |
|
|
qq(<<a href="$uri2" class="out-of-wiki mail">$uri</a>>); |
725 |
|
|
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself) |
726 |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
727 |
|
|
qq(<img src="$uri2" alt="" title="URI: <$uri2>" class="out-of-wiki">); |
728 |
|
|
} else { ## misc. URI |
729 |
|
|
CGI::Carp::warningsToBrowser (0); |
730 |
|
|
my $uri2 = &escape (URI->new (&unescape ($uri))->canonical); |
731 |
|
|
CGI::Carp::warningsToBrowser (1); |
732 |
|
|
qq(<<a href="$uri2" title="URI: <$uri2>" class="out-of-wiki">$uri</a>>); |
733 |
|
|
} |
734 |
|
|
} |
735 |
|
|
|
736 |
wakaba |
1.41 |
{my $FormIndex = 0; |
737 |
wakaba |
1.35 |
sub make_custom_form ($$$$) { |
738 |
wakaba |
1.34 |
my ($wfname, $definition, $template, $option) = @_; |
739 |
wakaba |
1.33 |
## $template and $option is currently not used in this procedure. |
740 |
|
|
unless ($main::_EMBEDED) { |
741 |
|
|
$FormIndex++; |
742 |
wakaba |
1.34 |
if (length $definition) { |
743 |
|
|
my $param = bless {}, 'SuikaWiki::Plugin'; |
744 |
|
|
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
745 |
wakaba |
1.35 |
&load_formatter (qw/form_input form_option/); |
746 |
|
|
$definition = &unescape ($definition); |
747 |
wakaba |
1.34 |
$definition =~ s/\\(.)/$1/g; |
748 |
|
|
$option = &unescape ($option); |
749 |
|
|
$option =~ s/\\(.)/$1/g; |
750 |
|
|
$fmt{form_option}->replace ($option, $param); |
751 |
wakaba |
1.42 |
$param->{output}->{form} = 1 unless defined $param->{output}->{form}; |
752 |
|
|
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; |
753 |
wakaba |
1.35 |
my $target_page = $param->{output}->{page} || $form{mypage}; |
754 |
|
|
$param->{form_disabled} = 1 if $fixedpage{$target_page}; |
755 |
wakaba |
1.34 |
my $target_form = $param->{output}->{id}; |
756 |
wakaba |
1.42 |
my $r = ''; |
757 |
|
|
$r = <<EOH if $param->{output}->{form}; |
758 |
wakaba |
1.33 |
<form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform"> |
759 |
wakaba |
1.35 |
<input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}"> |
760 |
|
|
<input type="hidden" name="mypage" value="@{[&escape($target_page)]}"> |
761 |
wakaba |
1.33 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
762 |
|
|
<input type="hidden" name="mytouch" value="on"> |
763 |
wakaba |
1.34 |
<input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}"> |
764 |
wakaba |
1.33 |
EOH |
765 |
wakaba |
1.34 |
$r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#; |
766 |
wakaba |
1.35 |
$r .= $fmt{form_input}->replace ($definition, $param); |
767 |
wakaba |
1.42 |
$r .= "</form>\n" if $param->{output}->{form}; |
768 |
wakaba |
1.34 |
$r; |
769 |
|
|
} else { ## No input-interface WikiForm |
770 |
|
|
qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>); |
771 |
|
|
} |
772 |
wakaba |
1.33 |
} else { |
773 |
wakaba |
1.41 |
qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>); |
774 |
wakaba |
1.9 |
} |
775 |
wakaba |
1.41 |
}} |
776 |
wakaba |
1.9 |
|
777 |
wakaba |
1.16 |
sub print_message { |
778 |
|
|
my ($msg) = @_; |
779 |
wakaba |
1.41 |
print qq(<p><strong>@{[&escape($msg)]}</strong></p>); |
780 |
wakaba |
1.22 |
} |
781 |
|
|
|
782 |
wakaba |
1.16 |
sub init_form { |
783 |
wakaba |
1.41 |
## TODO: Support multipart/form-data |
784 |
|
|
my $query = ''; |
785 |
|
|
if (uc $main::ENV{REQUEST_METHOD} eq 'POST') { |
786 |
|
|
read STDIN, $query, $main::ENV{CONTENT_LENGTH}; |
787 |
wakaba |
1.16 |
} |
788 |
wakaba |
1.41 |
$query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING}; |
789 |
wakaba |
1.42 |
if ($main::ENV{REQUEST_METHOD} ne 'POST' && $main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) { |
790 |
wakaba |
1.30 |
my $query = &decode($main::ENV{QUERY_STRING}); |
791 |
wakaba |
1.32 |
$query = &code_convert(\$query, $kanjicode); |
792 |
wakaba |
1.30 |
if ($page_command{$query}) { |
793 |
wakaba |
1.16 |
$form{mycmd} = $page_command{$query}; |
794 |
|
|
$form{mypage} = $query; |
795 |
wakaba |
1.30 |
} else { |
796 |
wakaba |
1.16 |
$form{mypage} = $query; |
797 |
wakaba |
1.30 |
$form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit'; |
798 |
|
|
} |
799 |
wakaba |
1.41 |
} else { |
800 |
|
|
for (split /[;&]/, $query) { |
801 |
|
|
if (my ($n, $v) = split /=/, $_, 2) { |
802 |
|
|
for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge}; |
803 |
|
|
$form{$n} = $v; |
804 |
|
|
} |
805 |
|
|
} |
806 |
w |
1.43 |
unless (defined $form{mypage}) { |
807 |
|
|
$form{mypage} = $form{epage}; |
808 |
|
|
$form{mypage} =~ s/([0-9A-F]{2})/ord hex $1/g; |
809 |
|
|
} |
810 |
wakaba |
1.41 |
if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') { |
811 |
|
|
$form{mypage} = &code_convert(\$form{mypage}, $kanjicode); |
812 |
|
|
$form{mycmd} = $page_command{$form{mypage}}; |
813 |
|
|
} |
814 |
wakaba |
1.16 |
} |
815 |
wakaba |
1.30 |
$form{mypage} ||= 'HomePage'; |
816 |
wakaba |
1.32 |
$form{mycmd} ||= 'read'; |
817 |
wakaba |
1.16 |
|
818 |
|
|
# mypreview_edit -> do_edit, with preview. |
819 |
|
|
# mypreview_adminedit -> do_adminedit, with preview. |
820 |
|
|
# mypreview_write -> do_write, without preview. |
821 |
|
|
foreach (keys %form) { |
822 |
|
|
if (/^mypreview_(.*)$/) { |
823 |
|
|
$form{mycmd} = $1; |
824 |
|
|
$form{mypreview} = 1; |
825 |
|
|
} |
826 |
|
|
} |
827 |
wakaba |
1.9 |
|
828 |
wakaba |
1.30 |
# |
829 |
wakaba |
1.16 |
# $form{mycmd} is frozen here. |
830 |
wakaba |
1.30 |
# |
831 |
wakaba |
1.16 |
|
832 |
wakaba |
1.33 |
for (grep /^wikiform__/, keys %form) { |
833 |
|
|
$form{$_} = &code_convert (\$form{$_}, $kanjicode); |
834 |
|
|
} |
835 |
wakaba |
1.16 |
$form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); |
836 |
|
|
$form{myname} = &code_convert(\$form{myname}, $kanjicode); |
837 |
|
|
} |
838 |
|
|
|
839 |
|
|
sub update_recent_changes { |
840 |
wakaba |
1.41 |
my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}"; |
841 |
|
|
my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges}); |
842 |
|
|
shift @oldupdates; ## '#?' magic line |
843 |
wakaba |
1.16 |
my @updates; |
844 |
|
|
foreach (@oldupdates) { |
845 |
wakaba |
1.41 |
/^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/; |
846 |
wakaba |
1.28 |
my $name = $1; |
847 |
|
|
if ($name ne $form{mypage}) { |
848 |
|
|
push @updates, $_; |
849 |
wakaba |
1.16 |
} |
850 |
|
|
} |
851 |
|
|
if (&is_exist_page($form{mypage})) { |
852 |
wakaba |
1.28 |
unshift @updates, $update; |
853 |
wakaba |
1.16 |
} |
854 |
wakaba |
1.41 |
splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1; |
855 |
|
|
$database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates); |
856 |
w |
1.43 |
if ($PathTo{TouchFile}) { |
857 |
|
|
open(FILE, "> ".$PathTo{TouchFile}); |
858 |
wakaba |
1.16 |
print FILE localtime() . "\n"; |
859 |
|
|
close(FILE); |
860 |
|
|
} |
861 |
wakaba |
1.9 |
} |
862 |
|
|
|
863 |
wakaba |
1.41 |
{my %SubjectLine; |
864 |
wakaba |
1.16 |
sub get_subjectline { |
865 |
|
|
my ($page, %option) = @_; |
866 |
wakaba |
1.41 |
unless (defined $SubjectLine{$page}) { |
867 |
|
|
if (not &is_editable($page)) { |
868 |
|
|
$SubjectLine{$page} = ""; |
869 |
|
|
} else { |
870 |
|
|
$SubjectLine{$page} = $database{$page}; |
871 |
|
|
$SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s; |
872 |
|
|
$SubjectLine{$page} =~ s/\x0D?\x0A.*//s; |
873 |
|
|
} |
874 |
|
|
} |
875 |
|
|
if (length $SubjectLine{$page}) { |
876 |
|
|
$option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter'); |
877 |
|
|
$option{delimiter}.$SubjectLine{$page}.$option{tail}; |
878 |
wakaba |
1.16 |
} else { |
879 |
wakaba |
1.41 |
''; |
880 |
wakaba |
1.16 |
} |
881 |
wakaba |
1.41 |
}} |
882 |
wakaba |
1.9 |
|
883 |
wakaba |
1.16 |
sub open_db { |
884 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
885 |
w |
1.43 |
dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}"); |
886 |
|
|
dbmopen(%infobase, $PathTo{WikiInfoBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiInfoBase}"); |
887 |
wakaba |
1.16 |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
888 |
wakaba |
1.41 |
eval q{use AnyDBM_File}; |
889 |
w |
1.43 |
tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}"); |
890 |
|
|
tie(%infobase, "AnyDBM_File", $PathTo{WikiInfoBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiInfoBase}"); |
891 |
wakaba |
1.16 |
} else { |
892 |
wakaba |
1.41 |
eval q{use Yuki::YukiWikiDB}; |
893 |
w |
1.43 |
tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}"); |
894 |
|
|
tie(%infobase, "Yuki::YukiWikiDB", $PathTo{WikiInfoBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiInfoBase}"); |
895 |
wakaba |
1.9 |
} |
896 |
|
|
} |
897 |
|
|
|
898 |
wakaba |
1.16 |
sub close_db { |
899 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
900 |
|
|
dbmclose(%database); |
901 |
|
|
dbmclose(%infobase); |
902 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
903 |
|
|
untie(%database); |
904 |
|
|
untie(%infobase); |
905 |
|
|
} else { |
906 |
|
|
untie(%database); |
907 |
|
|
untie(%infobase); |
908 |
|
|
} |
909 |
|
|
} |
910 |
wakaba |
1.9 |
|
911 |
wakaba |
1.16 |
sub open_diff { |
912 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
913 |
w |
1.43 |
dbmopen(%diffbase, $PathTo{WikiDiffBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDiffBase}"); |
914 |
wakaba |
1.16 |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
915 |
w |
1.43 |
tie(%diffbase, "AnyDBM_File", $PathTo{WikiDiffBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDiffBase}"); |
916 |
wakaba |
1.16 |
} else { |
917 |
w |
1.43 |
tie(%diffbase, "Yuki::YukiWikiDB", $PathTo{WikiDiffBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDiffBase}"); |
918 |
wakaba |
1.16 |
} |
919 |
|
|
} |
920 |
wakaba |
1.9 |
|
921 |
wakaba |
1.16 |
sub close_diff { |
922 |
|
|
if ($modifier_dbtype eq 'dbmopen') { |
923 |
|
|
dbmclose(%diffbase); |
924 |
|
|
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
925 |
|
|
untie(%diffbase); |
926 |
|
|
} else { |
927 |
|
|
untie(%diffbase); |
928 |
|
|
} |
929 |
wakaba |
1.9 |
} |
930 |
|
|
|
931 |
wakaba |
1.16 |
sub print_editform { |
932 |
|
|
my ($mymsg, $lastmodified, %mode) = @_; |
933 |
|
|
my $frozen = &is_frozen($form{mypage}); |
934 |
|
|
|
935 |
|
|
if ($form{mypreview}) { |
936 |
|
|
if ($form{mymsg}) { |
937 |
|
|
unless ($mode{conflict}) { |
938 |
wakaba |
1.41 |
print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n); |
939 |
|
|
print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n); |
940 |
wakaba |
1.16 |
print qq(<div class="preview">\n); |
941 |
|
|
&print_content($form{mymsg}); |
942 |
|
|
print qq(</div>\n); |
943 |
|
|
} |
944 |
|
|
} else { |
945 |
wakaba |
1.41 |
print @{[&Resource('Preview:Empty',escape=>1)]}; |
946 |
wakaba |
1.16 |
} |
947 |
|
|
$mymsg = &escape($form{mymsg}); |
948 |
wakaba |
1.9 |
} else { |
949 |
wakaba |
1.25 |
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
950 |
wakaba |
1.9 |
} |
951 |
wakaba |
1.36 |
my $magic = ''; |
952 |
|
|
$magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s; |
953 |
wakaba |
1.9 |
|
954 |
wakaba |
1.16 |
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
955 |
wakaba |
1.24 |
my $escapedmypage = &escape($form{mypage}); |
956 |
|
|
my $escapedmypassword = &escape($form{mypassword}); |
957 |
wakaba |
1.36 |
my $selected = 'read'; |
958 |
|
|
if ($form{after_edit_cmd}) { |
959 |
|
|
$selected = $form{after_edit_cmd}; |
960 |
wakaba |
1.41 |
} elsif ($magic =~ /Const|Config|CSS/) { |
961 |
wakaba |
1.36 |
$selected = 'edit'; |
962 |
|
|
} |
963 |
|
|
my $afteredit = <<EOH; |
964 |
|
|
<select name="after_edit_cmd"> |
965 |
wakaba |
1.41 |
<option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option> |
966 |
|
|
<option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option> |
967 |
wakaba |
1.36 |
</select> |
968 |
|
|
EOH |
969 |
wakaba |
1.16 |
|
970 |
|
|
print <<"EOD"; |
971 |
|
|
<form action="$url_cgi" method="post"> |
972 |
wakaba |
1.41 |
<h2>@{[&Resource('Edit:Title',escape=>1)]}</h2> |
973 |
|
|
@{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]} |
974 |
|
|
@{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="$escapedmypassword" size="10"></label>) : "" ]} [@{[do {my $n = 0; |
975 |
wakaba |
1.36 |
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
976 |
|
|
++$n}]}]<br> |
977 |
wakaba |
1.16 |
<input type="hidden" name="myLastModified" value="$lastmodified"> |
978 |
wakaba |
1.24 |
<input type="hidden" name="mypage" value="$escapedmypage"> |
979 |
wakaba |
1.41 |
<textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">$mymsg</textarea><br> |
980 |
wakaba |
1.16 |
@{[ |
981 |
|
|
$mode{admin} ? |
982 |
|
|
qq( |
983 |
wakaba |
1.41 |
<label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label> |
984 |
|
|
<label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>) |
985 |
wakaba |
1.16 |
: "" |
986 |
|
|
]} |
987 |
|
|
@{[ |
988 |
|
|
$mode{conflict} ? "" : |
989 |
|
|
qq( |
990 |
wakaba |
1.41 |
<input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}<br> |
991 |
|
|
<input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}"> |
992 |
|
|
<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd> |
993 |
wakaba |
1.36 |
$afteredit |
994 |
|
|
<br> |
995 |
wakaba |
1.16 |
) |
996 |
|
|
]} |
997 |
|
|
</form> |
998 |
|
|
EOD |
999 |
|
|
unless ($mode{conflict}) { |
1000 |
wakaba |
1.41 |
## Show help text |
1001 |
|
|
my $help = $database{WikiEditHelp}; |
1002 |
wakaba |
1.30 |
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1003 |
|
|
print &text_to_html ($help, toc => 0); |
1004 |
wakaba |
1.9 |
} |
1005 |
|
|
} |
1006 |
|
|
|
1007 |
wakaba |
1.16 |
sub print_passwordform { |
1008 |
|
|
print <<"EOD"; |
1009 |
|
|
<form action="$url_cgi" method="post"> |
1010 |
|
|
<input type="hidden" name="mycmd" value="adminchangepassword"> |
1011 |
wakaba |
1.41 |
<label>@{[&Resource('Password:Old=',escape=>1)]}<input type="password" name="myoldpassword" size="10"></label><br> |
1012 |
|
|
<label>@{[&Resource('Password:New1=',escape=>1)]}<input type="password" name="mynewpassword" size="10"></label><br> |
1013 |
|
|
<label>@{[&Resource('Password:New2=',escape=>1)]}<input type="password" name="mynewpassword2" size="10"></label><br> |
1014 |
|
|
<input type="submit" value="@{[&Resource('WikiForm:Change',escape=>1)]}"><br> |
1015 |
wakaba |
1.16 |
</form> |
1016 |
|
|
EOD |
1017 |
wakaba |
1.9 |
} |
1018 |
|
|
|
1019 |
wakaba |
1.16 |
sub is_editable { |
1020 |
|
|
my ($page) = @_; |
1021 |
wakaba |
1.31 |
if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) { |
1022 |
wakaba |
1.16 |
return 0; |
1023 |
|
|
} else { |
1024 |
|
|
return 1; |
1025 |
|
|
} |
1026 |
wakaba |
1.9 |
} |
1027 |
|
|
|
1028 |
wakaba |
1.16 |
# armor_name: |
1029 |
|
|
# WikiName -> WikiName |
1030 |
|
|
# not_wiki_name -> [[not_wiki_name]] |
1031 |
wakaba |
1.31 |
sub armor_name { qq([[$_[0]]]) } |
1032 |
wakaba |
1.9 |
|
1033 |
wakaba |
1.16 |
# unarmor_name: |
1034 |
|
|
# [[bracket_name]] -> bracket_name |
1035 |
|
|
# WikiName -> WikiName |
1036 |
|
|
sub unarmor_name { |
1037 |
|
|
my ($name) = @_; |
1038 |
wakaba |
1.41 |
if ($name =~ /^\[\[(\S+?)\]\]$/) { |
1039 |
wakaba |
1.16 |
return $1; |
1040 |
|
|
} else { |
1041 |
|
|
return $name; |
1042 |
|
|
} |
1043 |
wakaba |
1.9 |
} |
1044 |
|
|
|
1045 |
wakaba |
1.16 |
sub decode { |
1046 |
|
|
my ($s) = @_; |
1047 |
|
|
$s =~ tr/+/ /; |
1048 |
|
|
$s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; |
1049 |
|
|
return $s; |
1050 |
|
|
} |
1051 |
wakaba |
1.9 |
|
1052 |
wakaba |
1.16 |
sub encode { |
1053 |
|
|
my ($s) = @_; |
1054 |
|
|
my $encoded = ''; |
1055 |
|
|
foreach my $ch (split(//, $s)) { |
1056 |
|
|
if ($ch =~ /[A-Za-z0-9_]/) { |
1057 |
|
|
$encoded .= $ch; |
1058 |
|
|
} else { |
1059 |
|
|
$encoded .= '%' . sprintf("%02X", ord($ch)); |
1060 |
|
|
} |
1061 |
|
|
} |
1062 |
|
|
return $encoded; |
1063 |
|
|
} |
1064 |
wakaba |
1.9 |
|
1065 |
wakaba |
1.16 |
sub conflict { |
1066 |
|
|
my ($page, $rawmsg) = @_; |
1067 |
|
|
if ($form{myLastModified} eq &get_info($page, $info_LastModified)) { |
1068 |
|
|
return 0; |
1069 |
|
|
} |
1070 |
wakaba |
1.29 |
&print_header($page, -noindex => 1); |
1071 |
wakaba |
1.41 |
&print_content(&Resource('Error:Conflict')); |
1072 |
wakaba |
1.16 |
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
1073 |
|
|
&print_footer($page); |
1074 |
|
|
return 1; |
1075 |
|
|
} |
1076 |
|
|
|
1077 |
|
|
sub get_now { |
1078 |
wakaba |
1.41 |
my ($sec, $min, $hour, $day, $mon, $year) = localtime(time); |
1079 |
wakaba |
1.16 |
$year += 1900; |
1080 |
|
|
$mon++; |
1081 |
|
|
$mon = "0$mon" if $mon < 10; |
1082 |
|
|
$day = "0$day" if $day < 10; |
1083 |
|
|
$hour = "0$hour" if $hour < 10; |
1084 |
|
|
$min = "0$min" if $min < 10; |
1085 |
wakaba |
1.28 |
#$sec = "0$sec" if $sec < 10; |
1086 |
wakaba |
1.41 |
return "$year-$mon-$day $hour:$min"; |
1087 |
wakaba |
1.16 |
} |
1088 |
|
|
|
1089 |
|
|
sub init_InterWikiName { |
1090 |
wakaba |
1.41 |
my @content = split /\n/, $database{InterWikiName}; |
1091 |
wakaba |
1.31 |
for (@content) { |
1092 |
|
|
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) { |
1093 |
|
|
$interwiki{$1} = $2; |
1094 |
wakaba |
1.16 |
} |
1095 |
wakaba |
1.31 |
} |
1096 |
wakaba |
1.41 |
$interwiki{'[[]]'} = 1; ## dummy |
1097 |
wakaba |
1.16 |
} |
1098 |
wakaba |
1.9 |
|
1099 |
|
|
|
1100 |
wakaba |
1.16 |
sub get_info { |
1101 |
|
|
my ($page, $key) = @_; |
1102 |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
1103 |
|
|
return $info{$key}; |
1104 |
|
|
} |
1105 |
wakaba |
1.9 |
|
1106 |
wakaba |
1.16 |
sub set_info { |
1107 |
|
|
my ($page, $key, $value) = @_; |
1108 |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
1109 |
|
|
$info{$key} = $value; |
1110 |
|
|
my $s = ''; |
1111 |
|
|
for (keys %info) { |
1112 |
|
|
$s .= "$_=$info{$_}\n"; |
1113 |
|
|
} |
1114 |
|
|
$infobase{$page} = $s; |
1115 |
|
|
} |
1116 |
wakaba |
1.9 |
|
1117 |
wakaba |
1.16 |
sub frozen_reject { |
1118 |
|
|
my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); |
1119 |
|
|
my ($willbefrozen) = $form{myfrozen}; |
1120 |
|
|
if (not $isfrozen and not $willbefrozen) { |
1121 |
|
|
# You need no check. |
1122 |
|
|
return 0; |
1123 |
|
|
} elsif (valid_password($form{mypassword})) { |
1124 |
|
|
# You are admin. |
1125 |
|
|
return 0; |
1126 |
|
|
} else { |
1127 |
wakaba |
1.41 |
&print_error(&Resource('Error:PasswordIsIncorrect')); |
1128 |
wakaba |
1.16 |
return 1; |
1129 |
|
|
} |
1130 |
|
|
} |
1131 |
wakaba |
1.9 |
|
1132 |
wakaba |
1.16 |
sub valid_password { |
1133 |
|
|
my ($givenpassword) = @_; |
1134 |
w |
1.43 |
my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword'); |
1135 |
wakaba |
1.16 |
if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) { |
1136 |
|
|
return 1; |
1137 |
|
|
} else { |
1138 |
|
|
return 0; |
1139 |
|
|
} |
1140 |
|
|
} |
1141 |
wakaba |
1.9 |
|
1142 |
wakaba |
1.16 |
sub is_frozen { |
1143 |
|
|
my ($page) = @_; |
1144 |
|
|
if (&get_info($page, $info_IsFrozen)) { |
1145 |
|
|
return 1; |
1146 |
|
|
} else { |
1147 |
|
|
return 0; |
1148 |
|
|
} |
1149 |
|
|
} |
1150 |
wakaba |
1.9 |
|
1151 |
wakaba |
1.16 |
sub do_comment { |
1152 |
|
|
my ($content) = $database{$form{mypage}}; |
1153 |
wakaba |
1.30 |
my $default_name; ## this code does not strict. |
1154 |
|
|
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
1155 |
|
|
my $datestr = '[WEAK['.&get_now.']]'; |
1156 |
wakaba |
1.41 |
my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName'); |
1157 |
wakaba |
1.30 |
($namestr = '', $datestr = '') if $form{myname} eq 'nodate'; |
1158 |
wakaba |
1.29 |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
1159 |
|
|
$namestr = qq( ''$namestr'': ); |
1160 |
wakaba |
1.30 |
} elsif (length $namestr) { |
1161 |
wakaba |
1.29 |
$namestr = qq( ''[[$namestr]]'': ); |
1162 |
|
|
} |
1163 |
wakaba |
1.33 |
my $anchor = &get_new_anchor_index ($content); |
1164 |
wakaba |
1.27 |
my $i = 1; my $o = 0; |
1165 |
wakaba |
1.41 |
$content =~ s{(\[\[\#r?comment\]\])}{ |
1166 |
wakaba |
1.25 |
my $embed = $1; |
1167 |
|
|
if ($i == $form{comment_index}) { |
1168 |
wakaba |
1.41 |
if ($embed ne '[[#rcomment]]') { |
1169 |
wakaba |
1.28 |
$embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; |
1170 |
wakaba |
1.25 |
} else { |
1171 |
wakaba |
1.28 |
$embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; |
1172 |
wakaba |
1.25 |
} |
1173 |
|
|
} |
1174 |
|
|
$i++; $embed; |
1175 |
|
|
}ge; |
1176 |
|
|
unless ($o) { |
1177 |
wakaba |
1.30 |
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1178 |
|
|
$content .= "\n" unless $content =~ /\n$/s; |
1179 |
wakaba |
1.28 |
$content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; |
1180 |
wakaba |
1.16 |
} |
1181 |
wakaba |
1.29 |
$form{__comment_anchor_index} = $anchor; |
1182 |
wakaba |
1.30 |
if ($form{mymsg} || $form{myname}) { |
1183 |
wakaba |
1.16 |
$form{mymsg} = $content; |
1184 |
|
|
$form{mytouch} = 'on'; |
1185 |
|
|
&do_write; |
1186 |
|
|
} else { |
1187 |
|
|
$form{mycmd} = 'read'; |
1188 |
|
|
&do_read; |
1189 |
|
|
} |
1190 |
|
|
} |
1191 |
wakaba |
1.9 |
|
1192 |
wakaba |
1.33 |
sub get_new_anchor_index ($) { |
1193 |
|
|
my $content = shift; |
1194 |
|
|
my $anchor = 0; |
1195 |
|
|
$content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
1196 |
|
|
$anchor + 1; |
1197 |
|
|
} |
1198 |
|
|
|
1199 |
wakaba |
1.27 |
my $CommentIndex = 0; |
1200 |
wakaba |
1.16 |
sub embedded_to_html { |
1201 |
|
|
my ($embedded) = @_; |
1202 |
wakaba |
1.41 |
if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') { |
1203 |
wakaba |
1.28 |
unless ($main::_EMBEDED) { |
1204 |
wakaba |
1.16 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
1205 |
|
|
return <<"EOD"; |
1206 |
wakaba |
1.30 |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
1207 |
wakaba |
1.16 |
<input type="hidden" name="mycmd" value="comment"> |
1208 |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1209 |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
1210 |
|
|
<input type="hidden" name="mytouch" value="on"> |
1211 |
wakaba |
1.27 |
<input type="hidden" name="comment_index" value="$CommentIndex"> |
1212 |
wakaba |
1.41 |
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
1213 |
wakaba |
1.30 |
<input type="text" name="myname" value="" size="10" class="comment-name"> |
1214 |
|
|
<input type="text" name="mymsg" value="" size="60" class="comment-msg"> |
1215 |
wakaba |
1.41 |
<input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit"> |
1216 |
wakaba |
1.30 |
</p></form> |
1217 |
wakaba |
1.16 |
EOD |
1218 |
wakaba |
1.28 |
} else { |
1219 |
|
|
return <<"EOD"; |
1220 |
|
|
<del><form action="$url_cgi" method="get"> |
1221 |
|
|
<input type="hidden" name="mycmd" value="read"> |
1222 |
|
|
<input type="hidden" name="mypage" value="$form{mypage}"> |
1223 |
wakaba |
1.41 |
@{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]} |
1224 |
wakaba |
1.28 |
<input type="text" name="myname" value="" size="10" disabled="disabled"> |
1225 |
|
|
<input type="text" name="mymsg" value="" size="60" disabled="disabled"> |
1226 |
|
|
</form></del> |
1227 |
|
|
EOD |
1228 |
|
|
} |
1229 |
wakaba |
1.22 |
} elsif ($embedded =~ /$embed_command{searched}/) { |
1230 |
wakaba |
1.30 |
return get_search_result ($1, -match_myself => 1); |
1231 |
wakaba |
1.28 |
} elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { |
1232 |
|
|
my ($name, $r) = ($1, ''); |
1233 |
|
|
if ($main::_EMBEDED != 1) { |
1234 |
|
|
my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); |
1235 |
|
|
$cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
1236 |
|
|
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
1237 |
|
|
$main::_EMBEDED = 1; |
1238 |
|
|
$r = &text_to_html ($content, content_format => $cf); |
1239 |
|
|
$main::_EMBEDED = 0; |
1240 |
|
|
} elsif (length $content) { |
1241 |
|
|
$r = "<pre>@{[&escape ($content)]}</pre>"; |
1242 |
|
|
} else { |
1243 |
wakaba |
1.41 |
$r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1244 |
wakaba |
1.28 |
} |
1245 |
|
|
} else { ## nested #EMBED |
1246 |
wakaba |
1.41 |
$r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9'); |
1247 |
wakaba |
1.16 |
} |
1248 |
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>); |
1249 |
wakaba |
1.28 |
} elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { |
1250 |
|
|
return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>); |
1251 |
|
|
} else { |
1252 |
|
|
return $embedded; |
1253 |
|
|
} |
1254 |
wakaba |
1.16 |
} |
1255 |
wakaba |
1.9 |
|
1256 |
wakaba |
1.35 |
sub load_formatter (@) { |
1257 |
|
|
for my $t (@_) { |
1258 |
wakaba |
1.33 |
unless ($fmt{$t}) { |
1259 |
wakaba |
1.41 |
require Message::Util::Formatter; |
1260 |
wakaba |
1.33 |
$fmt{$t} = Message::Util::Formatter->new; |
1261 |
|
|
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
1262 |
|
|
$_->load_formatter ($fmt{$t}, type => 'wiki'.$t); |
1263 |
|
|
} |
1264 |
|
|
} |
1265 |
|
|
} |
1266 |
wakaba |
1.35 |
} |
1267 |
|
|
|
1268 |
|
|
sub do_wikiform { |
1269 |
|
|
my $content = $database{$form{mypage}}; |
1270 |
|
|
my $anchor = &get_new_anchor_index ($content); |
1271 |
|
|
&load_formatter (qw/form_template form_option/); |
1272 |
wakaba |
1.33 |
my $write = 0; |
1273 |
|
|
my $i = 1; |
1274 |
|
|
$content =~ s{$embed_command{form}}{ |
1275 |
wakaba |
1.34 |
my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4); |
1276 |
|
|
if (($wfname && $wfname eq $form{wikiform_targetform}) |
1277 |
|
|
|| $i == $form{wikiform_index}) { |
1278 |
|
|
$template =~ s/\\(.)/$1/g; |
1279 |
|
|
$option =~ s/\\(.)/$1/g; |
1280 |
wakaba |
1.33 |
my $param = bless {}, 'SuikaWiki::Plugin'; |
1281 |
|
|
$param->{page} = $form{mypage}; |
1282 |
|
|
$param->{form_index} = $i; |
1283 |
wakaba |
1.34 |
$param->{form_name} = $wfname; |
1284 |
wakaba |
1.33 |
$param->{anchor_index} = $anchor; |
1285 |
|
|
$param->{argv} = \%form; |
1286 |
|
|
$param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; |
1287 |
wakaba |
1.41 |
$param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName'); |
1288 |
wakaba |
1.33 |
$fmt{form_option}->replace ($option, $param); |
1289 |
wakaba |
1.34 |
my $t = 1; |
1290 |
|
|
for (@{$param->{require}||[]}) { |
1291 |
wakaba |
1.36 |
(undef $t, last) unless length $param->{argv}->{'wikiform__'.$_}; |
1292 |
wakaba |
1.34 |
} |
1293 |
|
|
$t = $fmt{form_template}->replace ($template, $param) if $t; |
1294 |
wakaba |
1.33 |
if (length $t) { |
1295 |
|
|
if ($param->{output}->{reverse}) { |
1296 |
wakaba |
1.34 |
$embed .= "\n" . $t; |
1297 |
|
|
} else { |
1298 |
wakaba |
1.33 |
$embed = $t . "\n" . $embed; |
1299 |
|
|
} |
1300 |
|
|
$write = 1; |
1301 |
|
|
$form{__comment_anchor_index} = $anchor |
1302 |
wakaba |
1.34 |
if $param->{anchor_index_}; ## $anchor is used! |
1303 |
wakaba |
1.33 |
} |
1304 |
wakaba |
1.34 |
$form{__wikiform_anchor_index} = $i; |
1305 |
|
|
undef $form{wikiform_targetform}; ## make sure never to match |
1306 |
|
|
undef $form{wikiform_index}; ## with WikiForm in rest of page |
1307 |
wakaba |
1.33 |
} |
1308 |
|
|
$i++; $embed; |
1309 |
|
|
}ge; |
1310 |
|
|
unless ($write) { |
1311 |
|
|
#$content = "#?SuikaWiki/0.9\n\n" unless $content; |
1312 |
|
|
#$content .= "\n" unless $content =~ /\n$/s; |
1313 |
|
|
# |
1314 |
|
|
} |
1315 |
|
|
if ($write) { |
1316 |
|
|
$form{mymsg} = $content; |
1317 |
|
|
$form{mytouch} = 'on'; |
1318 |
|
|
&do_write; |
1319 |
|
|
} else { |
1320 |
|
|
$form{mycmd} = 'read'; |
1321 |
|
|
&do_read; |
1322 |
|
|
} |
1323 |
|
|
} |
1324 |
|
|
|
1325 |
wakaba |
1.16 |
sub code_convert { |
1326 |
wakaba |
1.41 |
require Jcode; |
1327 |
wakaba |
1.27 |
my ($contentref, $code) = (shift, shift || $kanjicode); |
1328 |
wakaba |
1.31 |
$code = 'jis' if $code =~ /iso/; |
1329 |
|
|
$code = 'euc' if $code =~ /euc/; |
1330 |
|
|
$code = 'sjis' if $code =~ /shift/; |
1331 |
|
|
$code = 'utf8' if $code =~ /utf/; |
1332 |
wakaba |
1.41 |
#&Jcode::convert($contentref, $code); # for Jcode.pm |
1333 |
wakaba |
1.32 |
# &jcode::convert($contentref, $code); # for jcode.pl |
1334 |
wakaba |
1.41 |
#&Jcode::tr ($contentref, "\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&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ )) if $code eq 'euc'; |
1335 |
w |
1.43 |
$$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; |
1336 |
wakaba |
1.16 |
return $$contentref; |
1337 |
|
|
} |
1338 |
|
|
|
1339 |
|
|
sub do_diff { |
1340 |
|
|
if (not &is_editable($form{mypage})) { |
1341 |
|
|
&do_read; |
1342 |
|
|
return; |
1343 |
|
|
} |
1344 |
|
|
&open_diff; |
1345 |
|
|
my $title = $form{mypage}; |
1346 |
wakaba |
1.29 |
&print_header($title, -noindex => 1); |
1347 |
wakaba |
1.16 |
$_ = &escape($diffbase{$form{mypage}}); |
1348 |
|
|
&close_diff; |
1349 |
wakaba |
1.41 |
print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>); |
1350 |
|
|
print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>); |
1351 |
wakaba |
1.16 |
print qq(<pre class="diff">); |
1352 |
|
|
foreach (split(/\n/, $_)) { |
1353 |
|
|
if (/^\+(.*)/) { |
1354 |
wakaba |
1.41 |
print qq(<ins class="added">$1</ins>\n); |
1355 |
wakaba |
1.16 |
} elsif (/^\-(.*)/) { |
1356 |
wakaba |
1.41 |
print qq(<del class="deleted">$1</del>\n); |
1357 |
wakaba |
1.16 |
} elsif (/^\=(.*)/) { |
1358 |
|
|
print qq(<span class="same">$1</span>\n); |
1359 |
|
|
} else { |
1360 |
|
|
print qq|??? $_\n|; |
1361 |
|
|
} |
1362 |
|
|
} |
1363 |
|
|
print qq(</pre>); |
1364 |
|
|
&print_footer($title); |
1365 |
|
|
} |
1366 |
wakaba |
1.9 |
|
1367 |
wakaba |
1.16 |
sub do_rss { |
1368 |
wakaba |
1.41 |
eval q{use Yuki::RSS}; |
1369 |
wakaba |
1.16 |
my $rss = new Yuki::RSS( |
1370 |
|
|
version => '1.0', |
1371 |
wakaba |
1.41 |
encoding => &get_charset_name ($kanjicode), |
1372 |
|
|
); |
1373 |
|
|
my $scheme = 'http'; |
1374 |
|
|
$scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#; |
1375 |
|
|
my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi"; |
1376 |
|
|
$rss->stylesheet ( |
1377 |
|
|
href => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS", |
1378 |
|
|
type => 'text/css', |
1379 |
wakaba |
1.16 |
); |
1380 |
|
|
$rss->channel( |
1381 |
wakaba |
1.41 |
title => &Resource ('RSS:WikiTitle'), |
1382 |
|
|
link => $myuri, |
1383 |
|
|
description => &Resource ('RSS:WikiDescription'), |
1384 |
|
|
'dc:language' => $lang, |
1385 |
wakaba |
1.16 |
); |
1386 |
wakaba |
1.41 |
my $recentchanges = $database{RecentChanges}; |
1387 |
wakaba |
1.16 |
my $count = 0; |
1388 |
|
|
foreach (split(/\n/, $recentchanges)) { |
1389 |
|
|
last if ($count >= 15); |
1390 |
wakaba |
1.41 |
if (/\[\[([^]]+)\]\]/) { |
1391 |
|
|
my $title = $1; |
1392 |
|
|
$rss->add_item ( |
1393 |
|
|
title => &escape($title), |
1394 |
|
|
link => $myuri . '?' . &encode($title), |
1395 |
|
|
description => &escape(&get_subjectline($title,delimiter=>'')), |
1396 |
|
|
'dc:date' => &get_info ($title, $info_LastModified), |
1397 |
|
|
); |
1398 |
|
|
$count++; |
1399 |
|
|
} |
1400 |
wakaba |
1.16 |
} |
1401 |
|
|
# print RSS information (as XML). |
1402 |
|
|
print <<"EOD" |
1403 |
wakaba |
1.41 |
Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]} |
1404 |
wakaba |
1.9 |
|
1405 |
wakaba |
1.16 |
@{[$rss->as_string]} |
1406 |
|
|
EOD |
1407 |
|
|
} |
1408 |
wakaba |
1.9 |
|
1409 |
wakaba |
1.41 |
sub _rfc3339_date ($) { |
1410 |
|
|
my @time = gmtime (shift); |
1411 |
|
|
sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0]; |
1412 |
|
|
} |
1413 |
|
|
|
1414 |
wakaba |
1.16 |
sub is_exist_page { |
1415 |
|
|
my ($name) = @_; |
1416 |
|
|
if ($use_exists) { |
1417 |
|
|
return exists($database{$name}); |
1418 |
|
|
} else { |
1419 |
|
|
return $database{$name}; |
1420 |
|
|
} |
1421 |
wakaba |
1.27 |
} |
1422 |
|
|
|
1423 |
|
|
sub __get_database ($) { $database{ $_[0] } } |
1424 |
wakaba |
1.32 |
sub __set_database ($$) { $database{ $_[0] } = $_[1] } |
1425 |
wakaba |
1.27 |
|
1426 |
wakaba |
1.41 |
sub do_map { |
1427 |
|
|
my $page = $form{mypage}; |
1428 |
|
|
&print_header ($page); |
1429 |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
1430 |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
1431 |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
1432 |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
1433 |
|
|
print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n"; |
1434 |
|
|
my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {}, |
1435 |
|
|
map_from_here => &Resource('Map:FromHere'), |
1436 |
|
|
map_from_here_description => &Resource('Map:FromHereLong')); |
1437 |
|
|
&wiki::map::make_list ($page, %option); |
1438 |
|
|
print &wiki::map::list_to_html ($page, $option{weight_list}, %option); |
1439 |
|
|
if ($c) { |
1440 |
|
|
print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
1441 |
|
|
print $r; |
1442 |
|
|
} |
1443 |
|
|
if ($rl) { |
1444 |
|
|
print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
1445 |
|
|
} |
1446 |
|
|
&print_footer ($page); |
1447 |
|
|
} |
1448 |
|
|
|
1449 |
|
|
my %_Resource; |
1450 |
|
|
sub Resource ($;%) { |
1451 |
|
|
my ($s, %o) = @_; |
1452 |
|
|
unless (defined $_Resource{$s}) { |
1453 |
|
|
$_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option}); |
1454 |
|
|
} |
1455 |
|
|
$o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s}; |
1456 |
|
|
} |
1457 |
|
|
|
1458 |
wakaba |
1.27 |
package wiki::referer; |
1459 |
|
|
sub add ($$) { |
1460 |
|
|
my $page = shift; |
1461 |
|
|
my $uri = shift; |
1462 |
|
|
unless (ref $uri) { |
1463 |
|
|
require URI; |
1464 |
|
|
$uri = URI->new ($uri); |
1465 |
|
|
## Some schemes do not have query part. |
1466 |
|
|
eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ }; |
1467 |
|
|
$uri->fragment (undef); |
1468 |
|
|
} |
1469 |
|
|
$uri = $uri->canonical; |
1470 |
|
|
return unless $uri; |
1471 |
|
|
for my $regex (&get_dont_record) { |
1472 |
|
|
return if $uri =~ /$regex/; |
1473 |
|
|
} |
1474 |
|
|
my %list = get ($page); |
1475 |
|
|
$list{ $uri }++; |
1476 |
|
|
set ($page, \%list); |
1477 |
|
|
} |
1478 |
|
|
sub get ($) { |
1479 |
|
|
my $page = shift; |
1480 |
|
|
split /"/, main::get_info ($page, 'Referer'); |
1481 |
|
|
} |
1482 |
|
|
sub set ($%) { |
1483 |
|
|
my $page = shift; |
1484 |
|
|
my $list = shift; |
1485 |
|
|
main::set_info ($page, Referer => join '"', %$list); |
1486 |
|
|
} |
1487 |
|
|
|
1488 |
|
|
sub get_dont_record () { |
1489 |
|
|
map {s/\$/\\\$/g; s/\@/\\\@/g; $_} |
1490 |
|
|
grep !/^#/, |
1491 |
|
|
split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord'); |
1492 |
|
|
} |
1493 |
|
|
sub get_site_name () { |
1494 |
|
|
my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); |
1495 |
wakaba |
1.28 |
my @item; |
1496 |
wakaba |
1.27 |
for (@lines) { |
1497 |
|
|
next if /^#/; |
1498 |
|
|
my ($uri, $name) = split /\s+/, $_, 2; |
1499 |
|
|
$uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; |
1500 |
wakaba |
1.28 |
$name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; |
1501 |
|
|
push @item, [$uri, qq(q($name))]; |
1502 |
wakaba |
1.27 |
} |
1503 |
wakaba |
1.28 |
@item; |
1504 |
wakaba |
1.27 |
} |
1505 |
|
|
|
1506 |
|
|
sub list_html ($) { |
1507 |
|
|
my $page = shift; |
1508 |
|
|
my %list = get ($page); |
1509 |
|
|
my $r = ''; |
1510 |
wakaba |
1.28 |
my @name = get_site_name; |
1511 |
wakaba |
1.27 |
for my $uri (sort keys %list) { |
1512 |
|
|
my $title; |
1513 |
wakaba |
1.28 |
for my $item (@name) { |
1514 |
|
|
if ($uri =~ /$item->[0]/) { |
1515 |
wakaba |
1.27 |
$title = $uri; |
1516 |
wakaba |
1.28 |
eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} |
1517 |
|
|
or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; |
1518 |
wakaba |
1.27 |
last; |
1519 |
|
|
} |
1520 |
|
|
} |
1521 |
|
|
my $euri = main::escape ($uri); |
1522 |
|
|
if ($title) { |
1523 |
wakaba |
1.36 |
$r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: <$euri>">@{[main::escape ($title)]}</a></li>\n); |
1524 |
wakaba |
1.27 |
} else { |
1525 |
|
|
$r .= qq(<li>[$list{$uri}] <<a href="$euri">$euri</a>></li>\n); |
1526 |
|
|
} |
1527 |
|
|
} |
1528 |
|
|
$r ? qq(<ul>$r</ul>\n) : ''; |
1529 |
|
|
} |
1530 |
|
|
|
1531 |
|
|
sub __decode ($) { |
1532 |
|
|
my $s = shift; |
1533 |
|
|
$s =~ tr/+/ /; |
1534 |
|
|
$s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge; |
1535 |
|
|
main::code_convert (\$s); |
1536 |
wakaba |
1.32 |
} |
1537 |
|
|
|
1538 |
|
|
package wiki::useragent; |
1539 |
|
|
|
1540 |
|
|
sub add ($) { |
1541 |
|
|
my $s = shift; |
1542 |
|
|
return unless length $s; |
1543 |
wakaba |
1.39 |
$s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/ge; |
1544 |
wakaba |
1.32 |
my %ua; |
1545 |
|
|
for (split /\n/, &main::__get_database('WikiUserAgentList')) { |
1546 |
|
|
if (/^-\[(\d+)\] (.+)$/) { |
1547 |
|
|
my ($t, $n) = ($1, $2); |
1548 |
|
|
$n =~ tr/\x0A\x0D//d; |
1549 |
|
|
$ua{$n} = $t; |
1550 |
|
|
} |
1551 |
|
|
} |
1552 |
|
|
$ua{$s}++; |
1553 |
|
|
my $s = qq(#?SuikaWiki/0.9\n); |
1554 |
|
|
for (sort {$ua{$a} <=> $ua{$b}} keys %ua) { |
1555 |
|
|
$s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_; |
1556 |
|
|
} |
1557 |
|
|
&main::__set_database ('WikiUserAgentList' => $s); |
1558 |
wakaba |
1.16 |
} |
1559 |
wakaba |
1.33 |
|
1560 |
wakaba |
1.41 |
package wiki::suikawikiconst; |
1561 |
|
|
|
1562 |
|
|
sub to_hash ($;$) { |
1563 |
|
|
my $page = shift; |
1564 |
|
|
my $h = shift || {}; |
1565 |
|
|
my $val; |
1566 |
|
|
for my $line (split /\n/, $page) { |
1567 |
|
|
$line =~ tr/\x0A\x0D//d; |
1568 |
|
|
if ($val && $line =~ s/^\s+//) { |
1569 |
|
|
$h->{$val} .= length $h->{$val} ? "\n" . $line : $line; |
1570 |
|
|
} elsif ($line =~ /^(.+):/) { |
1571 |
|
|
$val = $1; $h->{$val} = ''; |
1572 |
|
|
} |
1573 |
|
|
} |
1574 |
|
|
$h; |
1575 |
|
|
} |
1576 |
|
|
|
1577 |
wakaba |
1.33 |
package SuikaWiki::Plugin; |
1578 |
wakaba |
1.35 |
our $plugin_directory; # defined in top of this file. |
1579 |
wakaba |
1.33 |
our %List; |
1580 |
|
|
|
1581 |
|
|
sub escape ($$) { main::escape ($_[1]) } |
1582 |
|
|
sub unescape ($$) { main::unescape ($_[1]) } |
1583 |
|
|
sub encode ($$) { main::encode ($_[1]) } |
1584 |
|
|
sub decode ($$) { main::decode ($_[1]) } |
1585 |
|
|
sub __get_datetime ($) { main::get_now () } |
1586 |
wakaba |
1.42 |
sub resource ($$;%) { shift; &main::Resource (@_) } |
1587 |
|
|
sub uri ($$) { $main::uri{$_[1]} } |
1588 |
wakaba |
1.33 |
|
1589 |
|
|
sub regist ($@) { |
1590 |
|
|
my $pack = shift; |
1591 |
|
|
for (@_) { |
1592 |
|
|
push @{$List{$_}}, $pack; |
1593 |
|
|
} |
1594 |
|
|
} |
1595 |
|
|
|
1596 |
wakaba |
1.35 |
sub import_plugins () { |
1597 |
|
|
opendir PDIR, $plugin_directory; |
1598 |
|
|
my @plugin = grep {s/\.pm$//} readdir (PDIR); |
1599 |
|
|
closedir PDIR; |
1600 |
|
|
for (@plugin) { |
1601 |
|
|
eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/; |
1602 |
|
|
push @{$List{_all}}, qq(SuikaWiki::Plugin::$_); |
1603 |
|
|
} |
1604 |
|
|
} |
1605 |
|
|
|
1606 |
|
|
&import_plugins (); |
1607 |
|
|
|
1608 |
wakaba |
1.41 |
package wiki::conneg; |
1609 |
|
|
|
1610 |
|
|
## BUG: this parser isn't strict. |
1611 |
|
|
sub get_accept_lang (;$) { |
1612 |
|
|
my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE}; |
1613 |
|
|
my %alang = (ja => 0.0002, en => 0.0001); |
1614 |
|
|
my $i = 0.1; |
1615 |
|
|
for (split /\s*,\s*/, $alang) { |
1616 |
|
|
tr/\x09\x0A\x0D\x20//d; |
1617 |
|
|
if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) { |
1618 |
|
|
my $l = lc $1; $l =~ tr/\x22\x5C//d; |
1619 |
|
|
$alang{$l} = (defined $2 ? $2 : 1.000)*1000; |
1620 |
|
|
$alang{$l} += $i unless $alang{$l} == 0; |
1621 |
|
|
$i -= 0.001; |
1622 |
|
|
} |
1623 |
|
|
} |
1624 |
|
|
\%alang; |
1625 |
|
|
} |
1626 |
|
|
|
1627 |
|
|
package wiki::resource; |
1628 |
|
|
|
1629 |
|
|
sub get ($;\%) { |
1630 |
|
|
my ($resname, $option) = @_; |
1631 |
|
|
$option->{accept_language} ||= &wiki::conneg::get_accept_lang (); |
1632 |
|
|
$option->{resource} ||= {}; |
1633 |
|
|
my $v; |
1634 |
|
|
for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) { |
1635 |
|
|
while (length $lang) { |
1636 |
|
|
unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) { |
1637 |
|
|
$option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang)); |
1638 |
|
|
$v = $option->{resource}->{$lang}->{$resname}; |
1639 |
|
|
last if defined $v; |
1640 |
|
|
} |
1641 |
|
|
$lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//; |
1642 |
|
|
} |
1643 |
|
|
last if defined $v; |
1644 |
|
|
} |
1645 |
|
|
defined $v ? $v : $resname; |
1646 |
|
|
} |
1647 |
|
|
|
1648 |
|
|
package wiki::map; |
1649 |
|
|
|
1650 |
|
|
sub make_list ($;%) { |
1651 |
|
|
my ($page, %option) = @_; |
1652 |
|
|
$option{level} ||= 3; |
1653 |
|
|
my %weight; |
1654 |
|
|
my $content = &main::__get_database ($page); |
1655 |
|
|
$content =~ s{^\#\?([^\x0A\x0D]+)}{ |
1656 |
|
|
if ($1 =~ /import="([^"]+)"/) { |
1657 |
|
|
for (split /\s*,\s*/, $1) { |
1658 |
|
|
$weight{$_} += 2; |
1659 |
|
|
} |
1660 |
|
|
} |
1661 |
|
|
$&; |
1662 |
|
|
}ges; |
1663 |
|
|
## Bug: this code does not support content type. |
1664 |
|
|
$content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{ |
1665 |
|
|
$weight{$1}++; $&; |
1666 |
|
|
}ge; |
1667 |
|
|
delete $weight{$page}; ## Delete myself |
1668 |
|
|
for my $page (keys %weight) { |
1669 |
|
|
my $w = ($content =~ s/\Q$page\E/$&/g); |
1670 |
|
|
$weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2. |
1671 |
|
|
($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page); |
1672 |
|
|
} |
1673 |
|
|
$option{weight_list}->{$page} = \%weight; |
1674 |
|
|
if (--$option{level}) { |
1675 |
|
|
for my $page (keys %weight) { |
1676 |
|
|
&make_list ($page, %option) unless $option{weight_list}->{$page}; |
1677 |
|
|
} |
1678 |
|
|
} |
1679 |
|
|
$option{weight_list}; |
1680 |
|
|
} |
1681 |
|
|
|
1682 |
|
|
sub list_to_html ($$;%) { |
1683 |
|
|
my ($Page, $wlist, %option) = @_; |
1684 |
|
|
my $r = ''; |
1685 |
|
|
$option{outputed}->{$Page} = 1; |
1686 |
|
|
for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) { |
1687 |
|
|
$r .= qq(<li><span class="weight">[@{[0+$wlist->{$Page}->{$page}]}]</span> <a href="$main::url_cgi?@{[&main::encode($page)]}" class="wiki@{[$option{not_exist}->{$page}?' not-exist':'']}">@{[&main::escape ($page).($option{not_exist}->{$page}?qq(<span class="mark">@{[&main::Resource('JumpAndEditWikiPageMark',escape=>1)]}</span>):'')]}</a> <a href="$main::url_cgi?mycmd=map;mypage=@{[&main::encode($page)]}" class="wiki-cmd map-from-here" title="@{[&main::escape($option{map_from_here_description})]}">@{[&main::escape($option{map_from_here})]}</a> <span class="summary">@{[&main::escape(&main::get_subjectline($page))]}</span>); |
1688 |
|
|
unless ($option{outputed}->{$page}) { |
1689 |
|
|
$r .= &list_to_html ($page, $wlist, %option); |
1690 |
|
|
} |
1691 |
|
|
$r .= "</li>\n"; |
1692 |
|
|
} |
1693 |
|
|
$r ? qq(<ul class="map">$r</ul>) : ''; |
1694 |
|
|
} |
1695 |
|
|
|
1696 |
wakaba |
1.35 |
package main; |
1697 |
|
|
&main; |
1698 |
|
|
exit 0; |
1699 |
wakaba |
1.9 |
|
1700 |
wakaba |
1.16 |
1; |
1701 |
|
|
__END__ |
1702 |
|
|
=head1 NAME |
1703 |
wakaba |
1.9 |
|
1704 |
wakaba |
1.16 |
wiki.cgi - This is YukiWiki, yet another Wiki clone. |
1705 |
wakaba |
1.41 |
walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone. |
1706 |
wakaba |
1.9 |
|
1707 |
wakaba |
1.16 |
=head1 DESCRIPTION |
1708 |
wakaba |
1.9 |
|
1709 |
wakaba |
1.16 |
YukiWiki is yet another Wiki clone. |
1710 |
wakaba |
1.9 |
|
1711 |
wakaba |
1.16 |
YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]). |
1712 |
|
|
YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS), |
1713 |
|
|
and some embedded commands (such as [[#comment]] to add comments). |
1714 |
wakaba |
1.9 |
|
1715 |
wakaba |
1.16 |
Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail. |
1716 |
wakaba |
1.9 |
|
1717 |
wakaba |
1.16 |
=head1 AUTHOR |
1718 |
wakaba |
1.9 |
|
1719 |
wakaba |
1.16 |
Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/ |
1720 |
wakaba |
1.9 |
|
1721 |
wakaba |
1.16 |
=head1 LICENSE |
1722 |
wakaba |
1.9 |
|
1723 |
wakaba |
1.16 |
Copyright (C) 2000-2002 by Hiroshi Yuki. |
1724 |
wakaba |
1.9 |
|
1725 |
wakaba |
1.16 |
This program is free software; you can redistribute it and/or |
1726 |
|
|
modify it under the same terms as Perl itself. |
1727 |
wakaba |
1.9 |
|
1728 |
|
|
=cut |