18 |
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
19 |
); |
); |
20 |
our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists); |
our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists); |
21 |
our (%PageName,$kanjicode,$lang,%FixedPage); |
our (%PageName,$kanjicode,$lang,%ViewDefinition); |
22 |
|
|
23 |
############################## |
############################## |
|
my $info_LastModified = 'LastModified'; |
|
|
my $info_IsFrozen = 'IsFrozen'; |
|
|
############################## |
|
24 |
my %form; |
my %form; |
25 |
our %database; |
our %database; |
26 |
our $database; |
our $database = bless {}, 'wiki::dummy'; |
|
my %infobase; |
|
27 |
my %interwiki; |
my %interwiki; |
28 |
############################## |
############################## |
29 |
my %page_command = ( |
my %page_command = ( |
32 |
my %command_do = ( |
my %command_do = ( |
33 |
read => \&do_read, |
read => \&do_read, |
34 |
TEXT_CSS => \&do_output_css, |
TEXT_CSS => \&do_output_css, |
35 |
edit => \&do_edit, |
edit => \&do_view, |
|
adminedit => \&do_adminedit, |
|
36 |
adminchangepassword => \&do_adminchangepassword, |
adminchangepassword => \&do_adminchangepassword, |
37 |
write => \&do_write, |
write => \&do_write, |
38 |
searchform => \&do_searchform, |
searchform => \&do_searchform, |
41 |
rss => \&do_rss, |
rss => \&do_rss, |
42 |
diff => \&do_diff, |
diff => \&do_diff, |
43 |
wikiform => \&do_wikiform, |
wikiform => \&do_wikiform, |
44 |
map => \&do_map, |
map => \&do_view, |
45 |
); |
); |
46 |
my $UA = ''; ## User agent name |
my $UA = ''; ## User agent name |
47 |
$| = 1; |
$| = 1; |
61 |
|
|
62 |
sub do_read { |
sub do_read { |
63 |
my $content = $database{$form{mypage}}; |
my $content = $database{$form{mypage}}; |
64 |
#print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n"; |
my $lm = $database->mtime ($form{mypage}); |
|
my $lm = &get_info($form{mypage}, $info_LastModified); |
|
65 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
66 |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
#print gmtime."Search...\n"; |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
|
67 |
my @toc; |
my @toc; |
|
push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c; |
|
|
push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl; |
|
68 |
my $cf = 'SuikaWiki/0.9'; |
my $cf = 'SuikaWiki/0.9'; |
69 |
## Should be support at least: |
## Should be support at least: |
70 |
## - 'SuikaWiki/0.9' CRLF |
## - 'SuikaWiki/0.9' CRLF |
72 |
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF |
73 |
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
$cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s; |
74 |
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { |
75 |
#print gmtime."Header...\n"; |
my $expires = time; |
76 |
&print_header ($form{mypage}, -last_modified => $lm, -expires => time + 120, |
if ($cf =~ /interactive="yes"/) { |
77 |
|
$lm = $expires; |
78 |
|
} else { |
79 |
|
$expires += 120; |
80 |
|
} |
81 |
|
&print_header ($form{mypage}, -last_modified => $lm, -expires => $expires, |
82 |
-content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0)); |
-content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0)); |
|
#print "\n". gmtime."Body...\n"; |
|
83 |
&print_content ($content, content_format => $cf, last_modified => $lm, |
&print_content ($content, content_format => $cf, last_modified => $lm, |
84 |
-toc => \@toc); |
-toc => \@toc); |
85 |
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$FixedPage{$form{mypage}}; |
print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$database->meta (IsFrozen => $form{mypage}); |
86 |
} else { |
} else { |
87 |
&print_header($form{mypage}, -expires => time + 120, -last_modified => $lm); |
&print_header($form{mypage}, -expires => time + 120, -last_modified => $lm); |
88 |
print "<pre>@{[&escape($content)]}</pre>"; |
print "<pre>@{[&escape($content)]}</pre>"; |
89 |
} |
} |
90 |
if ($c) { |
&load_formatter ('view'); |
91 |
print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
print $fmt{view}->replace ($ViewDefinition{read} => bless {param => \%form, page => $form{mypage}, toc => \@toc, formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
92 |
print $r; |
&print_footer ($form{mypage}, $lm); |
|
} |
|
|
if ($rl) { |
|
|
print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
|
|
} |
|
|
#print "\n". gmtime."Footer...\n"; |
|
|
&print_footer($form{mypage}, $lm); |
|
|
#print "\n". gmtime."Fin...\n"; |
|
93 |
} |
} |
94 |
|
|
95 |
sub do_output_css { |
sub do_output_css { |
97 |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
98 |
my $content = $database{$form{mypage}}; |
my $content = $database{$form{mypage}}; |
99 |
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
if ($content =~ m#^\s*/\*\s*W3C-CSS#) { |
100 |
my $lm = gmtime &get_info($form{mypage}, $info_LastModified); |
my $lm = gmtime $database->mtime ($form{mypage}); |
101 |
print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n"; |
print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n"; |
102 |
print "Last-Modified: $lm\n"; |
print "Last-Modified: $lm\n"; |
103 |
print "Expires: @{[scalar gmtime time+3600]}\n"; ## TODO: don't use asctime |
print "Expires: @{[scalar gmtime time+3600]}\n"; ## TODO: don't use asctime |
120 |
} |
} |
121 |
} |
} |
122 |
|
|
123 |
sub do_edit { |
sub do_view { |
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
|
|
if (not &is_editable($page)) { |
|
|
&print_header($page, -noindex => 1, -expires => time+60); |
|
|
&print_message(&Resource('Error:ThisPageIsUneditable')); |
|
|
} elsif (&is_frozen($page)) { |
|
|
&print_header($page, -noindex => 1, -expires => time+60); |
|
|
&print_message(&Resource('Error:ThisPageIsUneditable')); |
|
|
} else { |
|
|
&print_header($page, -noindex => 1, -expires => time+60); |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0); |
|
|
} |
|
124 |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
125 |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
126 |
my ($r, $c) = get_search_result ($form{mypage}); |
&print_header($form{mypage}, -noindex => 1, -expires => time+60); |
127 |
my $rl = wiki::referer::list_html ($form{mypage}); |
&load_formatter ('view'); |
128 |
if ($c) { |
my $view = $form{mycmd}; |
129 |
print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
if ($view eq 'edit') { |
130 |
print $r; |
$view = 'adminedit' if $form{admin}; |
131 |
} |
} elsif ($view =~ /[^0-9A-Za-z]/) { |
132 |
if ($rl) { |
$view = 'view' |
|
print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer($page); |
|
|
} |
|
|
|
|
|
sub do_adminedit { |
|
|
my ($page) = &unarmor_name(&armor_name($form{mypage})); |
|
|
&print_header($page, -noindex => 1, -expires => time+60); |
|
|
if (not &is_editable($page)) { |
|
|
&print_message(&Resource('Error:ThisPageIsUneditable')); |
|
|
} else { |
|
|
&print_message(&Resource('Error:PasswordIsNotSpecified')); |
|
|
&print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1); |
|
133 |
} |
} |
134 |
&print_footer($page); |
print $fmt{view}->replace ($ViewDefinition{$view} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
135 |
|
&print_footer($form{mypage}); |
136 |
} |
} |
137 |
|
|
138 |
sub do_adminchangepassword { |
sub do_adminchangepassword { |
139 |
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
if ($form{mynewpassword} ne $form{mynewpassword2}) { |
140 |
&print_error(&Resource('Error:PasswordMismatch')); |
&print_error(&Resource('Error:PasswordMismatch')); |
141 |
} |
} |
142 |
my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword'); |
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
143 |
if ($validpassword_crypt) { |
if ($validpassword_crypt) { |
144 |
if (not &valid_password($form{myoldpassword})) { |
if (not &valid_password($form{myoldpassword})) { |
145 |
&print_error(&Resource('Error:PasswordIsIncorrect')); |
&print_error(&Resource('Error:PasswordIsIncorrect')); |
150 |
my $salt1 = $token[(time | $$) % scalar(@token)]; |
my $salt1 = $token[(time | $$) % scalar(@token)]; |
151 |
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
152 |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
my $crypted = crypt($form{mynewpassword}, "$salt1$salt2"); |
153 |
&set_info($PageName{AdminSpecialPage}, 'AdminPassword', $crypted); |
$database->meta (AdminPassword => $PageName{AdminSpecialPage} => $crypted); |
154 |
|
|
155 |
&print_header('CompletedSuccessfully', -noindex => 1); |
&print_header('CompletedSuccessfully', -noindex => 1); |
156 |
&print_message(&Resource('Error:PasswordIsChanged')); |
&print_message(&Resource('Error:PasswordIsChanged')); |
158 |
} |
} |
159 |
|
|
160 |
sub valid_password ($) { |
sub valid_password ($) { |
161 |
my ($validpassword_crypt) = &get_info($PageName{AdminSpecialPage}, 'AdminPassword'); |
my ($validpassword_crypt) = $database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
162 |
return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; |
return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; |
163 |
} |
} |
164 |
|
|
174 |
return; |
return; |
175 |
} |
} |
176 |
|
|
177 |
if (&conflict($form{mypage}, $form{mymsg})) { |
## Check confliction |
178 |
return; |
if ($form{myLastModified} ne $database->mtime ($page)) { |
179 |
|
&print_header($page, -noindex => 1); |
180 |
|
&load_formatter ('view'); |
181 |
|
print $fmt{view}->replace ($ViewDefinition{-conflict} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin'); |
182 |
|
&print_footer($page); |
183 |
|
return; |
184 |
} |
} |
185 |
|
|
186 |
if ($form{mymsg}) { |
if ($form{mymsg}) { |
189 |
} else { |
} else { |
190 |
$database->STORE ($form{mypage} => $form{mymsg}, -touch => 0); |
$database->STORE ($form{mypage} => $form{mymsg}, -touch => 0); |
191 |
} |
} |
192 |
&set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen}); |
$database->meta (IsFrozen => $form{mypage} => 0 + $form{myfrozen}); |
193 |
my $fragment = ''; |
my $fragment = ''; |
194 |
$fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd}; |
$fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd}; |
195 |
if ($form{__comment_anchor_index}) { |
if ($form{__comment_anchor_index}) { |
203 |
&print_footer('CompletedSuccessfully'); |
&print_footer('CompletedSuccessfully'); |
204 |
} else { |
} else { |
205 |
delete $database{$form{mypage}}; |
delete $database{$form{mypage}}; |
|
delete $infobase{$form{mypage}}; |
|
206 |
&print_header($form{mypage}, -noindex => 1); |
&print_header($form{mypage}, -noindex => 1); |
207 |
&print_message(&Resource('Error:PageIsDeletedSuccessfully')); |
&print_message(&Resource('Error:PageIsDeletedSuccessfully')); |
208 |
&print_footer($form{mypage}); |
&print_footer($form{mypage}); |
209 |
} |
} |
210 |
} |
} |
211 |
|
|
212 |
|
sub _compatible_options () { |
213 |
|
(use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0)); |
214 |
|
} |
215 |
|
|
216 |
sub get_search_result ($;%) { |
sub get_search_result ($;%) { |
217 |
my $word = lc shift; |
my $word = lc shift; |
218 |
my %option = @_; |
my %option = @_; |
286 |
} |
} |
287 |
push @head, qq(<title>@{[&escape($page)]}</title>); |
push @head, qq(<title>@{[&escape($page)]}</title>); |
288 |
if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) { |
if ($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) { |
289 |
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))]}"); |
push @head, qq(<link rel="stylesheet" type="text/css"). |
290 |
|
qq( href="@{[&escape($uri{wiki}.'?mycmd=TEXT_CSS;mypage='.&encode($PageName{DefaultStyleForHTML}).';x-lm='.$database->mtime ($PageName{DefaultStyleForHTML}))]}"); |
291 |
} |
} |
292 |
push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex}; |
push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex}; |
293 |
my ($Links, $links) = &make_navigate_links ($page); |
my ($Links, $links) = &make_navigate_links ($page); |
349 |
my $page = shift; |
my $page = shift; |
350 |
my @link; |
my @link; |
351 |
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); |
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); |
352 |
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); |
push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;admin=1;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page); |
353 |
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')}; |
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')}; |
354 |
push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')}; |
push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')}; |
355 |
push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')}; |
push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')}; |
401 |
|
|
402 |
sub escape { |
sub escape { |
403 |
my $s = shift; |
my $s = shift; |
404 |
$s =~ s|\r\n|\n|g; |
$s =~ s|\x0D\x0A|\x0A|g; |
405 |
$s =~ s|&|&|g; |
$s =~ s|&|&|g; |
406 |
$s =~ s|<|<|g; |
$s =~ s|<|<|g; |
407 |
$s =~ s|>|>|g; |
$s =~ s|>|>|g; |
426 |
|
|
427 |
sub text_to_html { |
sub text_to_html { |
428 |
my ($txt, %option) = @_; |
my ($txt, %option) = @_; |
429 |
my @toc; |
my $toc = $option{-toc} || []; |
|
my @toc2 = @{$option{-toc}||[]}; |
|
430 |
my $tocnum = 0; |
my $tocnum = 0; |
431 |
|
|
432 |
## Load constants |
## Load constants |
448 |
foreach (@txt) { |
foreach (@txt) { |
449 |
chomp; |
chomp; |
450 |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) { |
451 |
push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [5, "i$tocnum" => ($1 || $tocnum)]; |
452 |
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>'); |
push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>'); |
453 |
$tocnum++; |
$tocnum++; |
454 |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) { |
455 |
push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [4, "i$tocnum" => ($1 || $tocnum)]; |
456 |
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>'); |
push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>'); |
457 |
$tocnum++; |
$tocnum++; |
458 |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*\*([^\x0D\x0A]*)/) { |
459 |
push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [3, "i$tocnum" => ($1 || $tocnum)]; |
460 |
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>'); |
push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>'); |
461 |
$tocnum++; |
$tocnum++; |
462 |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
} elsif (/^\*\*([^\x0D\x0A]*)/) { |
463 |
# if (/^\*\*(.*)/) { |
# if (/^\*\*(.*)/) { |
464 |
# Walrus mod (6) end |
# Walrus mod (6) end |
465 |
push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [2, "i$tocnum" => ($1 || $tocnum)]; |
466 |
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>'); |
push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>'); |
467 |
$tocnum++; |
$tocnum++; |
468 |
} elsif (/^\*([^\x0D\x0A]*)/) { |
} elsif (/^\*([^\x0D\x0A]*)/) { |
469 |
push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n)); |
push @$toc, [1, "i$tocnum" => ($1 || $tocnum)]; |
470 |
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>'); |
push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>'); |
471 |
$tocnum++; |
$tocnum++; |
472 |
} elsif (/^(={1,6})(.*)/) { |
} elsif (/^(={1,6})(.*)/) { |
534 |
} |
} |
535 |
push(@result, splice(@saved)); |
push(@result, splice(@saved)); |
536 |
|
|
537 |
my $toc = ''; |
my $r = join("\n", @result); |
538 |
if ($option{toc}) { |
$r =~ s#<p>\x0D?\x0A</p>##g; |
539 |
# Convert @toc (table of contents) to HTML. |
$r =~ s#[\x0D\x0A]+</#</#g; |
540 |
# This part is taken from Makio Tsukamoto's WalWiki. |
$r =~ s#<pre>\x0D?\x0A#<pre>#g; |
541 |
my (@tocsaved, @tocresult); |
$r; |
|
foreach (@toc,@toc2) { |
|
|
if (/^(-{1,6})(.*)$/) { |
|
|
&back_push('ul', length($1), \@tocsaved, \@tocresult); |
|
|
push(@tocresult, '<li>' . $2 . '</li>'); |
|
|
} |
|
|
} |
|
|
push(@tocresult, splice(@tocsaved)); |
|
|
$toc = join("\n", @tocresult); |
|
|
$toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : ''; |
|
|
} |
|
|
$toc .= join("\n", @result); |
|
|
$toc =~ s#<p>\n</p>##g; |
|
|
$toc =~ s#[\x0D\x0A]+</#</#g; |
|
|
$toc =~ s#<pre>\n#<pre>#g; |
|
|
$toc; |
|
542 |
} |
} |
543 |
|
|
544 |
sub back_push { |
sub back_push { |
649 |
$FormIndex++; |
$FormIndex++; |
650 |
if (length $definition) { |
if (length $definition) { |
651 |
my $param = bless {}, 'SuikaWiki::Plugin'; |
my $param = bless {}, 'SuikaWiki::Plugin'; |
652 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
my $lastmodified = $database->mtime ($form{mypage}); |
653 |
&load_formatter (qw/form_input form_option/); |
&load_formatter (qw/form_input form_option/); |
654 |
$definition = &unescape ($definition); |
$definition = &unescape ($definition); |
655 |
$definition =~ s/\\(.)/$1/g; |
$definition =~ s/\\(.)/$1/g; |
659 |
$param->{output}->{form} = 1 unless defined $param->{output}->{form}; |
$param->{output}->{form} = 1 unless defined $param->{output}->{form}; |
660 |
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; |
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form}; |
661 |
my $target_page = $param->{output}->{page} || $form{mypage}; |
my $target_page = $param->{output}->{page} || $form{mypage}; |
662 |
$param->{form_disabled} = 1 if $FixedPage{$target_page}; |
$param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage}); |
663 |
my $target_form = $param->{output}->{id}; |
my $target_form = $param->{output}->{id}; |
664 |
my $r = ''; |
my $r = ''; |
665 |
$r = <<EOH if $param->{output}->{form}; |
$r = <<EOH if $param->{output}->{form}; |
721 |
} |
} |
722 |
} |
} |
723 |
$form{mypage} ||= 'HomePage'; |
$form{mypage} ||= 'HomePage'; |
724 |
|
$form{mypage} =~ tr/\x00-\x1F\x7F//d; |
725 |
$form{mycmd} ||= 'read'; |
$form{mycmd} ||= 'read'; |
726 |
|
|
727 |
# mypreview_edit -> do_edit, with preview. |
# mypreview_edit -> do_edit, with preview. |
768 |
sub open_db { |
sub open_db { |
769 |
if ($modifier_dbtype eq 'dbmopen') { |
if ($modifier_dbtype eq 'dbmopen') { |
770 |
dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}"); |
dbmopen(%database, $PathTo{WikiDataBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiDataBase}"); |
|
dbmopen(%infobase, $PathTo{WikiInfoBase}, 0666) or &print_error("(dbmopen) $PathTo{WikiInfoBase}"); |
|
771 |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
} elsif ($modifier_dbtype eq 'AnyDBM_File') { |
772 |
eval q{use AnyDBM_File}; |
eval q{use AnyDBM_File}; |
773 |
tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}"); |
tie(%database, "AnyDBM_File", $PathTo{WikiDataBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiDataBase}"); |
774 |
tie(%infobase, "AnyDBM_File", $PathTo{WikiInfoBase}, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $PathTo{WikiInfoBase}"); |
} elsif ($modifier_dbtype eq 'Yuki::YukiWikiDB') { |
|
} elsif ($modifier_dbtype eq 'YukiWikiDB') { |
|
775 |
eval q{use Yuki::YukiWikiDB}; |
eval q{use Yuki::YukiWikiDB}; |
776 |
tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}"); |
tie(%database, "Yuki::YukiWikiDB", $PathTo{WikiDataBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiDataBase}"); |
777 |
tie(%infobase, "Yuki::YukiWikiDB", $PathTo{WikiInfoBase}) or &print_error("(tie Yuki::YukiWikiDB) $PathTo{WikiInfoBase}"); |
} else { ## Yuki::YukiWikiDB || Yuki::YukiWikiDBMeta |
|
} else { |
|
778 |
eval qq{use $modifier_dbtype}; |
eval qq{use $modifier_dbtype}; |
779 |
$database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or &print_error("(tie $modifier_dbtype) $PathTo{WikiDataBase}"); |
$database = tie(%database, $modifier_dbtype => $PathTo{WikiDataBase}, -lock => 2, -backup => $wiki::diff::UseDiff) or &print_error("(tie $modifier_dbtype) $PathTo{WikiDataBase}"); |
|
tie(%infobase, $modifier_dbtype => $PathTo{WikiInfoBase}, -lock => 2) or &print_error("(tie $modifier_dbtype) $PathTo{WikiInfoBase}"); |
|
780 |
} |
} |
781 |
} |
} |
782 |
|
|
783 |
sub close_db { |
sub close_db { |
784 |
if ($modifier_dbtype eq 'dbmopen') { |
if ($modifier_dbtype eq 'dbmopen') { |
785 |
dbmclose(%database); |
dbmclose(%database); |
|
dbmclose(%infobase); |
|
786 |
} else { |
} else { |
787 |
untie(%database); |
untie(%database); |
|
untie(%infobase); |
|
788 |
} |
} |
789 |
} |
} |
790 |
|
|
791 |
sub print_editform { |
sub editform (@) { |
792 |
my ($mymsg, $lastmodified, %mode) = @_; |
my %option = @_; |
793 |
my $frozen = &is_frozen($form{mypage}); |
my $frozen = &is_frozen ($option{page}); |
794 |
|
$option{content} = $database{$option{page}} unless defined $option{content}; |
795 |
if ($form{mypreview}) { |
$option{content} = $database{NewPageTemplate} unless length $option{content}; |
796 |
if ($form{mymsg}) { |
$option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified}; |
797 |
unless ($mode{conflict}) { |
my $f = ''; |
798 |
print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n); |
my $magic = ''; |
799 |
print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n); |
$magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s; |
800 |
print qq(<div class="preview">\n); |
|
801 |
&print_content($form{mymsg}); |
my $selected = 'read'; |
802 |
print qq(</div>\n); |
if ($form{after_edit_cmd}) { |
803 |
} |
$selected = $form{after_edit_cmd}; |
804 |
} else { |
} elsif ($magic =~ /Const|Config|CSS/) { |
805 |
print @{[&Resource('Preview:Empty',escape=>1)]}; |
$selected = 'edit'; |
806 |
} |
} |
807 |
$mymsg = &escape($form{mymsg}); |
my $afteredit = <<EOH; |
|
} else { |
|
|
$mymsg = &escape($mymsg || $database{NewPageTemplate}); |
|
|
} |
|
|
my $magic = ''; |
|
|
$magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s; |
|
|
|
|
|
my $edit = $mode{admin} ? 'adminedit' : 'edit'; |
|
|
my $selected = 'read'; |
|
|
if ($form{after_edit_cmd}) { |
|
|
$selected = $form{after_edit_cmd}; |
|
|
} elsif ($magic =~ /Const|Config|CSS/) { |
|
|
$selected = 'edit'; |
|
|
} |
|
|
my $afteredit = <<EOH; |
|
808 |
<select name="after_edit_cmd"> |
<select name="after_edit_cmd"> |
809 |
<option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option> |
<option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option> |
810 |
<option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option> |
<option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option> |
811 |
</select> |
</select> |
812 |
EOH |
EOH |
813 |
|
$f .= <<"EOD"; |
814 |
print <<"EOD"; |
<form action="$uri{wiki}" method="post"> |
815 |
<form action="$url_cgi" method="post"> |
@{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd></label>) ]} |
816 |
<h2>@{[&Resource('Edit:Title',escape=>1)]}</h2> |
@{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br> |
817 |
@{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]} |
<input type="hidden" name="myLastModified" value="$option{last_modified}"> |
|
@{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[do {my $n = 0; |
|
|
$mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge; |
|
|
++$n}]}]<br> |
|
|
<input type="hidden" name="myLastModified" value="$lastmodified"> |
|
818 |
<input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}"> |
<input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}"> |
819 |
<textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">$mymsg</textarea><br> |
<textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br> |
820 |
@{[ |
@{[ |
821 |
$mode{admin} ? |
$option{admin} ? |
822 |
qq( |
qq( |
823 |
<label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label> |
<label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label> |
824 |
<label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>) |
<label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>) |
825 |
: "" |
: "" |
826 |
]} |
]} |
827 |
@{[ |
@{[ |
828 |
$mode{conflict} ? "" : |
$option{conflict} ? "" : |
829 |
qq( |
qq( |
830 |
<label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br> |
<label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br> |
|
<input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}"> |
|
831 |
<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label> |
<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label> |
832 |
$afteredit |
$afteredit |
833 |
) |
) |
834 |
]} |
]} |
835 |
</form> |
</form> |
836 |
EOD |
EOD |
837 |
unless ($mode{conflict}) { |
unless ($option{conflict}) { |
838 |
## Show help text |
## Show help text |
839 |
my $help = $database{WikiEditHelp}; |
my $help = $database{WikiEditHelp}; |
840 |
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
$help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; |
841 |
print &text_to_html ($help, toc => 0); |
$f .= &text_to_html ($help, toc => 0); |
842 |
} |
} |
843 |
|
$f; |
844 |
} |
} |
845 |
|
|
846 |
sub is_editable { |
sub is_editable { |
847 |
my ($page) = @_; |
my ($page) = @_; |
848 |
if ($FixedPage{$page} || $page =~ /\s/ || $page =~ /^\#/) { |
$page =~ /[\x00-\x1F\x7F]/ ? 0 : 1; |
|
return 0; |
|
|
} else { |
|
|
return 1; |
|
|
} |
|
849 |
} |
} |
850 |
|
|
851 |
# armor_name: |
# armor_name: |
885 |
return $encoded; |
return $encoded; |
886 |
} |
} |
887 |
|
|
|
sub conflict { |
|
|
my ($page, $rawmsg) = @_; |
|
|
if ($form{myLastModified} eq &get_info($page, $info_LastModified)) { |
|
|
return 0; |
|
|
} |
|
|
&print_header($page, -noindex => 1); |
|
|
&print_content(&Resource('Error:Conflict')); |
|
|
&print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1); |
|
|
&print_footer($page); |
|
|
return 1; |
|
|
} |
|
|
|
|
888 |
sub get_now { |
sub get_now { |
889 |
my ($sec, $min, $hour, $day, $mon, $year) = localtime(time); |
my ($sec, $min, $hour, $day, $mon, $year) = localtime(time); |
890 |
$year += 1900; |
$year += 1900; |
907 |
$interwiki{'[[]]'} = 1; ## dummy |
$interwiki{'[[]]'} = 1; ## dummy |
908 |
} |
} |
909 |
|
|
|
|
|
|
sub get_info { |
|
|
my ($page, $key) = @_; |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
|
|
return $info{$key}; |
|
|
} |
|
|
|
|
|
sub set_info { |
|
|
my ($page, $key, $value) = @_; |
|
|
my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page}); |
|
|
$info{$key} = $value; |
|
|
my $s = ''; |
|
|
for (keys %info) { |
|
|
$s .= "$_=$info{$_}\n"; |
|
|
} |
|
|
$infobase{$page} = $s; |
|
|
} |
|
|
|
|
910 |
sub frozen_reject { |
sub frozen_reject { |
911 |
my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen); |
my ($isfrozen) = $database->meta (IsFrozen => $form{mypage}); |
912 |
my ($willbefrozen) = $form{myfrozen}; |
my ($willbefrozen) = $form{myfrozen}; |
913 |
if (not $isfrozen and not $willbefrozen) { |
if (not $isfrozen and not $willbefrozen) { |
914 |
# You need no check. |
# You need no check. |
922 |
} |
} |
923 |
} |
} |
924 |
|
|
925 |
sub is_frozen { |
sub is_frozen ($) { $database->meta (IsFrozen => $_[0]) ? 1 : 0 } |
|
my ($page) = @_; |
|
|
if (&get_info($page, $info_IsFrozen)) { |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
926 |
|
|
927 |
sub do_comment { |
sub do_comment { |
928 |
my ($content) = $database{$form{mypage}}; |
my ($content) = $database{$form{mypage}}; |
977 |
my ($embedded) = @_; |
my ($embedded) = @_; |
978 |
if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') { |
if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') { |
979 |
unless ($main::_EMBEDED) { |
unless ($main::_EMBEDED) { |
980 |
my $lastmodified = &get_info($form{mypage}, $info_LastModified); |
my $lastmodified = $database->mtime ($form{mypage}); |
981 |
return <<"EOD"; |
return <<"EOD"; |
982 |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
<form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p> |
983 |
<input type="hidden" name="mycmd" value="comment"> |
<input type="hidden" name="mycmd" value="comment"> |
1159 |
title => &escape($title), |
title => &escape($title), |
1160 |
link => $myuri . '?' . &encode($title), |
link => $myuri . '?' . &encode($title), |
1161 |
description => &escape(&get_subjectline($title,delimiter=>'')), |
description => &escape(&get_subjectline($title,delimiter=>'')), |
1162 |
'dc:date' => &get_info ($title, $info_LastModified), |
'dc:date' => $database->mtime ($title), |
1163 |
); |
); |
1164 |
$count++; |
$count++; |
1165 |
} |
} |
1187 |
} |
} |
1188 |
|
|
1189 |
sub __get_database ($) { $database{ $_[0] } } |
sub __get_database ($) { $database{ $_[0] } } |
|
sub __set_database ($$) { $database{ $_[0] } = $_[1] } |
|
|
|
|
|
sub do_map { |
|
|
my $page = $form{mypage}; |
|
|
&print_header ($page); |
|
|
wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER}); |
|
|
wiki::useragent::add ($ENV{HTTP_USER_AGENT}); |
|
|
my ($r, $c) = get_search_result ($form{mypage}); |
|
|
my $rl = wiki::referer::list_html ($form{mypage}); |
|
|
print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n"; |
|
|
my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {}, |
|
|
map_from_here => &Resource('Map:FromHere'), |
|
|
map_from_here_description => &Resource('Map:FromHereLong')); |
|
|
&wiki::map::make_list ($page, %option); |
|
|
print &wiki::map::list_to_html ($page, $option{weight_list}, %option); |
|
|
if ($c) { |
|
|
print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>}; |
|
|
print $r; |
|
|
} |
|
|
if ($rl) { |
|
|
print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n); |
|
|
} |
|
|
&print_footer ($page); |
|
|
} |
|
1190 |
|
|
1191 |
my %_Resource; |
my %_Resource; |
1192 |
sub Resource ($;%) { |
sub Resource ($;%) { |
1217 |
$list{ $uri }++; |
$list{ $uri }++; |
1218 |
set ($page, \%list); |
set ($page, \%list); |
1219 |
} |
} |
1220 |
sub get ($) { |
sub get ($) { split /"/, $main::database->meta (Referer => $_[0]) } |
|
my $page = shift; |
|
|
split /"/, main::get_info ($page, 'Referer'); |
|
|
} |
|
1221 |
sub set ($%) { |
sub set ($%) { |
1222 |
my $page = shift; |
my $page = shift; |
1223 |
my $list = shift; |
my $list = shift; |
1224 |
main::set_info ($page, Referer => join '"', %$list); |
$main::database->meta (Referer => $page => join '"', %$list); |
1225 |
} |
} |
1226 |
|
|
1227 |
sub get_dont_record () { |
sub get_dont_record () { |
1315 |
$h; |
$h; |
1316 |
} |
} |
1317 |
|
|
1318 |
|
package wiki::dummy; |
1319 |
|
sub mtime (@) {undef} |
1320 |
|
sub meta (@) {undef} |
1321 |
|
sub Yuki::YukiWikiDB2::meta (@) {undef} |
1322 |
|
|
1323 |
package SuikaWiki::Plugin; |
package SuikaWiki::Plugin; |
1324 |
our $plugin_directory; # defined in top of this file. |
our $plugin_directory; # defined in top of this file. |
1325 |
our %List; |
our %List; |
1326 |
|
our %Index; |
1327 |
|
|
1328 |
sub escape ($$) { main::escape ($_[1]) } |
sub escape ($$) { main::escape ($_[1]) } |
1329 |
sub unescape ($$) { main::unescape ($_[1]) } |
sub unescape ($$) { main::unescape ($_[1]) } |
1332 |
sub __get_datetime ($) { main::get_now () } |
sub __get_datetime ($) { main::get_now () } |
1333 |
sub resource ($$;%) { shift; &main::Resource (@_) } |
sub resource ($$;%) { shift; &main::Resource (@_) } |
1334 |
sub uri ($$) { $main::uri{$_[1]} } |
sub uri ($$) { $main::uri{$_[1]} } |
1335 |
|
sub new_index ($$) { ++$Index{$_[1]} } |
1336 |
|
|
1337 |
sub regist ($@) { |
sub regist ($@) { |
1338 |
my $pack = shift; |
my $pack = shift; |
1393 |
defined $v ? $v : $resname; |
defined $v ? $v : $resname; |
1394 |
} |
} |
1395 |
|
|
|
package wiki::map; |
|
|
|
|
|
sub make_list ($;%) { |
|
|
my ($page, %option) = @_; |
|
|
$option{level} ||= 3; |
|
|
my %weight; |
|
|
my $content = &main::__get_database ($page); |
|
|
$content =~ s{^\#\?([^\x0A\x0D]+)}{ |
|
|
if ($1 =~ /import="([^"]+)"/) { |
|
|
for (split /\s*,\s*/, $1) { |
|
|
$weight{$_} += 2; |
|
|
} |
|
|
} |
|
|
$&; |
|
|
}ges; |
|
|
## Bug: this code does not support content type. |
|
|
$content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{ |
|
|
$weight{$1}++; $&; |
|
|
}ge; |
|
|
delete $weight{$page}; ## Delete myself |
|
|
for my $page (keys %weight) { |
|
|
my $w = ($content =~ s/\Q$page\E/$&/g); |
|
|
$weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2. |
|
|
($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page); |
|
|
} |
|
|
$option{weight_list}->{$page} = \%weight; |
|
|
if (--$option{level}) { |
|
|
for my $page (keys %weight) { |
|
|
&make_list ($page, %option) unless $option{weight_list}->{$page}; |
|
|
} |
|
|
} |
|
|
$option{weight_list}; |
|
|
} |
|
|
|
|
|
sub list_to_html ($$;%) { |
|
|
my ($Page, $wlist, %option) = @_; |
|
|
my $r = ''; |
|
|
$option{outputed}->{$Page} = 1; |
|
|
for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) { |
|
|
$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>); |
|
|
unless ($option{outputed}->{$page}) { |
|
|
$r .= &list_to_html ($page, $wlist, %option); |
|
|
} |
|
|
$r .= "</li>\n"; |
|
|
} |
|
|
$r ? qq(<ul class="map">$r</ul>) : ''; |
|
|
} |
|
|
|
|
1396 |
package main; |
package main; |
1397 |
&main; |
&main; |
1398 |
exit 0; |
exit 0; |