/[pub]/suikawiki/script/wiki.cgi
Suika

Diff of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.40 by wakaba, Thu Dec 19 09:50:18 2002 UTC revision 1.41 by wakaba, Wed Dec 25 02:04:11 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #  
2  # wiki.cgi - This is YukiWiki, yet another Wiki clone.  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
3  #  #
 # Copyright (C) 2000-2002 by Hiroshi Yuki.  
 # <hyuki@hyuki.com>  
 # http://www.hyuki.com/yukiwiki/  
 #  
4  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
5  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
 #  
 # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.  
   
 # Walrus add (debug) start  
 my $walrus_log;  
 my $walrus_debugging = 0;  
 # Walrus add (debug) end  
6    
 # Libraries.  
7  use strict;  use strict;
8  use lib qw(./WalWiki/lib);  use lib qw(./WalWiki/lib);
 use CGI qw(:standard);  
9  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
 use Yuki::RSS;  
10  use Yuki::DiffText qw(difftext);  use Yuki::DiffText qw(difftext);
 use Yuki::YukiWikiDB;  
 use AnyDBM_File;  
 require 'jcode.pl';  
 require Jcode;  
11  use Fcntl;  use Fcntl;
 my $version = '2.0.beta1.2002-05-29';  
 my $walversion;  
 ##############################  
12  #  #
13  # You MUST modify following '$modifier_...' variables.  # You MUST modify following '$modifier_...' variables.
14  #  #
 my $modifier_mail = 'w@suika.fam.cx';   # Your mail address, like 'walrus@digit.que.ne.jp'.  
 my $modifier_url  = 'http://suika.fam.cx/~wakaba/';     # Your web page, like 'http://digit.que.ne.jp/work/'.  
 my $modifier_name = '和';       # Your name, like 'Makio Tsukamoto'.  
15  # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.  # my $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.
16  # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.  # my $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.
17  my $modifier_dbtype = 'YukiWikiDB';     # Slow, available on all environment.  my $modifier_dbtype = 'YukiWikiDB';     # Slow, available on all environment.
 # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.  
 my $modifier_sendmail = ''; # If you don't need mail notification.  
18  my $modifier_dir_data = './wikidata'; # Your data directory.  my $modifier_dir_data = './wikidata'; # Your data directory.
19  my $modifier_rss_title = "SuikaWiki $walversion";  our $url_cgi = '/~wakaba/-temp/wiki/wiki';      ## MUST be started by '/'
 my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.  
 my $modifier_rss_description = 'This is SuikaWiki';  
20  ##############################  ##############################
21  #  #
22  # You MAY modify following variables.  # You MAY modify following variables.
23  #  #
24  $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);  $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
25  my $file_touch = "$modifier_dir_data/touched.txt";  my $file_touch = "$modifier_dir_data/touched.txt";
26  my $file_resource = "$modifier_dir_data/resource.txt";  our %uri;
27  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  $uri{stylesheet} = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
28  my $file_conflict = "$modifier_dir_data/conflict.txt";  $uri{cvs_wikipage} = '/gate/cvs/wakaba/suikawiki/wiki/';
 my $file_format = "$modifier_dir_data/format.txt";  
 my $url_cgi = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'  
 my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';  
 my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';  
 my $maxrecent = 50;  
 my $cols = 80;  
 my $rows = 20;  
29  ##############################  ##############################
30  #  #
31  # You MAY, but do NOT NEED modify following variables.  # You MAY, but do NOT NEED modify following variables.
# Line 69  my $rows = 20; Line 33  my $rows = 20;
33  my $dataname = "$modifier_dir_data/wiki";  my $dataname = "$modifier_dir_data/wiki";
34  my $infoname = "$modifier_dir_data/info";  my $infoname = "$modifier_dir_data/info";
35  my $diffname = "$modifier_dir_data/diff";  my $diffname = "$modifier_dir_data/diff";
 my $editchar = '?';  
 my $subject_delimiter = ' - ';  
 my $use_autoimg = 1; # automatically convert image URL into <img> tag.  
36  my $use_exists = 0; # If you can use 'exists' method for your DB.  my $use_exists = 0; # If you can use 'exists' method for your DB.
37  ##############################  ##############################
 my $InterWikiName = 'InterWikiName';  
 my $RecentChanges = 'RecentChanges';  
 my $AdminChangePassword = 'AdminChangePassword';  
 my $CompletedSuccessfully = 'CompletedSuccessfully';  
38  my $FrontPage = 'HomePage';  my $FrontPage = 'HomePage';
39  my $IndexPage = 'IndexPage';  my $IndexPage = 'IndexPage';
40  my $SearchPage = 'SearchPage';  my $SearchPage = 'SearchPage';
41  my $CreatePage = 'CreatePage';  my $CreatePage = 'CreatePage';
42  my $ErrorPage = 'ErrorPage';  my $ErrorPage = 'ErrorPage';
43  my $RssPage = 'RssPage';  my $RssPage = 'RssPage';
 my $NAME_OF_WikiPageLicense = 'WikiPageLicense';  
44  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
45  ##############################  ##############################
 my $bracket_name = '\[\[(\S+?)\]\]';  
 my $embedded_name = '\[\[(#\S+?)\]\]';  
46  my %fmt;        ## formatter objects  my %fmt;        ## formatter objects
 ##############################  
 my $embed_comment = '[[#comment]]';  
 my $embed_rcomment = '[[#rcomment]]';  
 my $embed_comment_Name_Prompt = '名前:';  
 my $DEFAULT_embed_comment_name = '名無しさん';  
 my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  
47  my %embed_command = (  my %embed_command = (
48          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
49      form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,          form    => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
50  );  );
51  ##############################  ##############################
52  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
53  my $info_IsFrozen = 'IsFrozen';  my $info_IsFrozen = 'IsFrozen';
 my $info_AdminPassword = 'AdminPassword';  
54  ##############################  ##############################
55  my $kanjicode = 'euc';  my $kanjicode = 'euc';
 my $charset = 'EUC-JP';  
56  my $lang = 'ja';  my $lang = 'ja';
57  my %fixedpage = (  my %fixedpage = (
58      $IndexPage => 1,      $IndexPage => 1,
59      $CreatePage => 1,      $CreatePage => 1,
60      $ErrorPage => 1,      $ErrorPage => 1,
61      $RssPage => 1,      $RssPage => 1,
62      $RecentChanges => 1,      RecentChanges => 1,
63      $SearchPage => 1,      $SearchPage => 1,
64      $AdminChangePassword => 1,      AdminChangePassword => 1,
65      $CompletedSuccessfully => 1,      CompletedSuccessfully => 1,
     #$FrontPage => 1,  
66      WikiUserAgentList => 1,      WikiUserAgentList => 1,
67      WikiPluginInfo    => 1,      WikiPluginInfo    => 1,
68  );  );
# Line 125  my %form; Line 70  my %form;
70  my %database;  my %database;
71  my %infobase;  my %infobase;
72  my %diffbase;  my %diffbase;
 my %resource;  
73  my %interwiki;  my %interwiki;
74  ##############################  ##############################
75  my %page_command = (  my %page_command = (
# Line 133  my %page_command = ( Line 77  my %page_command = (
77      $SearchPage => 'searchform',      $SearchPage => 'searchform',
78      $CreatePage => 'create',      $CreatePage => 'create',
79      $RssPage => 'rss',      $RssPage => 'rss',
80      $AdminChangePassword => 'adminchangepasswordform',      AdminChangePassword => 'adminchangepasswordform',
     #$FrontPage => 'FrontPage',  
81      WikiPluginInfo       => 'x_WikiPluginInfo',      WikiPluginInfo       => 'x_WikiPluginInfo',
82  );  );
83  my %command_do = (  my %command_do = (
# Line 150  my %command_do = ( Line 93  my %command_do = (
93      search => \&do_search,      search => \&do_search,
94      create => \&do_create,      create => \&do_create,
95      createresult => \&do_createresult,      createresult => \&do_createresult,
     FrontPage => \&do_FrontPage,  
96      comment => \&do_comment,      comment => \&do_comment,
97      RandomJump  => \&do_random_jump,      RandomJump  => \&do_random_jump,
98      rss => \&do_rss,      rss => \&do_rss,
99      diff => \&do_diff,      diff => \&do_diff,
100      interwikibox => \&do_interwiki_box, # Walrus add (5)      wikiform    => \&do_wikiform,
101      wikiform => \&do_wikiform,      x_WikiPluginInfo    => \&do_wikiplugininfo,
102      x_WikiPluginInfo  => \&do_wikiplugininfo,      map => \&do_map,
103  );  );
 ##############################  
 my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  
 ##############################  
 # &test_convert;  
104  my $UA = '';  ## User agent name  my $UA = '';  ## User agent name
105    $| = 1;
106  ##############################  ##############################
107    
108  sub main {  sub main {
109      $UA = $main::ENV{HTTP_USER_AGENT};      $UA = $main::ENV{HTTP_USER_AGENT};
     &init_resource;  
110      &open_db;      &open_db;
111      &init_form;      &init_form;
     &init_InterWikiName;  
112      if ($command_do{$form{mycmd}}) {      if ($command_do{$form{mycmd}}) {
113          &{$command_do{$form{mycmd}}};          &{$command_do{$form{mycmd}}};
114      } else {      } else {
115          &do_FrontPage;          &{$command_do{$form{read}}};
116      }      }
117      &close_db;      &close_db;
118  }  }
119    
120  sub do_read {  sub do_read {
121    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
122      #print "content-type:text/plain;charset=euc-jp\n\n".gmtime."Get Lastmodified\n";
123    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = &get_info($form{mypage}, $info_LastModified);
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      #print gmtime."Search...\n";
127    my ($r, $c) = get_search_result ($form{mypage});    my ($r, $c) = get_search_result ($form{mypage});
128    my $rl = wiki::referer::list_html ($form{mypage});    my $rl = wiki::referer::list_html ($form{mypage});
129    my @toc;    my @toc;
130    push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;    push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;
131    push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl;    push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;
132      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
133      ## Should be support at least:      ## Should be support at least:
134      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
# Line 197  sub do_read { Line 136  sub do_read {
136      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
137      $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;
138      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
139        #print gmtime."Header...\n";
140        &print_header ($form{mypage}, -last_modified => $lm,        &print_header ($form{mypage}, -last_modified => $lm,
141          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
142            #print "\n". gmtime."Body...\n";
143        &print_content ($content, content_format => $cf, last_modified => $lm,        &print_content ($content, content_format => $cf, last_modified => $lm,
144          -toc => \@toc);          -toc => \@toc);
145        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
# Line 207  sub do_read { Line 148  sub do_read {
148        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
149      }      }
150      if ($c) {      if ($c) {
151        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
152        print $r;        print $r;
153      }      }
154      if ($rl) {      if ($rl) {
155        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
156      }      }
157            #print "\n". gmtime."Footer...\n";
158    &print_footer($form{mypage}, $lm);    &print_footer($form{mypage}, $lm);
159            #print "\n". gmtime."Fin...\n";
160  }  }
161    
162  sub do_output_css {  sub do_output_css {
# Line 221  sub do_output_css { Line 164  sub do_output_css {
164    wiki::useragent::add ($ENV{HTTP_USER_AGENT});    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
165    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
166    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
167      my $lm = &get_info($form{mypage}, $info_LastModified);      my $lm = gmtime &get_info($form{mypage}, $info_LastModified);
168        print scalar make_navigate_links ($form{mypage});      print "Content-Type: text/css; charset=@{[&get_charset_name($kanjicode)]}\n";
     print "Content-Type: text/css; charset=$charset\n";  
169      print "Last-Modified: $lm\n";      print "Last-Modified: $lm\n";
170      print "\n";      print "\n";
171      print $content;      print $content;
# Line 248  sub do_edit { Line 190  sub do_edit {
190      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
191      &print_header($page, -noindex => 1);      &print_header($page, -noindex => 1);
192      if (not &is_editable($page)) {      if (not &is_editable($page)) {
193          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
194      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
195          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
196      } else {      } else {
197          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
198      }      }
# Line 259  sub do_edit { Line 201  sub do_edit {
201      my ($r, $c) = get_search_result ($form{mypage});      my ($r, $c) = get_search_result ($form{mypage});
202      my $rl = wiki::referer::list_html ($form{mypage});      my $rl = wiki::referer::list_html ($form{mypage});
203      if ($c) {      if ($c) {
204        print q{<h2 id="wikipage-see-also">See also</h2>};        print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
205        print $r;        print $r;
206      }      }
207      if ($rl) {      if ($rl) {
208        print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);        print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
209      }      }
210      &print_footer($page);      &print_footer($page);
211  }  }
# Line 272  sub do_adminedit { Line 214  sub do_adminedit {
214      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
215      &print_header($page, -noindex => 1);      &print_header($page, -noindex => 1);
216      if (not &is_editable($page)) {      if (not &is_editable($page)) {
217          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
218      } else {      } else {
219          &print_message($resource{passwordneeded});          &print_message(&Resource('Error:PasswordIsNotSpecified'));
220          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
221      }      }
222      &print_footer($page);      &print_footer($page);
223  }  }
224    
225  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
226      &print_header($AdminChangePassword, -noindex => 1);      &print_header('AdminChangePassword', -noindex => 1);
227      &print_passwordform;      &print_passwordform;
228      &print_footer($AdminChangePassword);      &print_footer('AdminChangePassword');
229  }  }
230    
231  sub do_adminchangepassword {  sub do_adminchangepassword {
232      if ($form{mynewpassword} ne $form{mynewpassword2}) {      if ($form{mynewpassword} ne $form{mynewpassword2}) {
233          &print_error($resource{passwordmismatcherror});          &print_error(&Resource('Error:PasswordMismatch'));
234      }      }
235      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = &get_info($AdminSpecialPage, 'AdminPassword');
236      if ($validpassword_crypt) {      if ($validpassword_crypt) {
237          if (not &valid_password($form{myoldpassword})) {          if (not &valid_password($form{myoldpassword})) {
238              &send_mail_to_admin(<<"EOD", "AdminChangePassword");  #            &send_mail_to_admin(<<"EOD", "AdminChangePassword");
239  myoldpassword=$form{myoldpassword}  #myoldpassword=$form{myoldpassword}
240  mynewpassword=$form{mynewpassword}  #mynewpassword=$form{mynewpassword}
241  mynewpassword2=$form{mynewpassword2}  #mynewpassword2=$form{mynewpassword2}
242  EOD  #EOD
243              &print_error($resource{passworderror});              &print_error(&Resource('Error:PasswordIsIncorrect'));
244          }          }
245      }      }
246      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
# Line 306  EOD Line 248  EOD
248      my $salt1 = $token[(time | $$) % scalar(@token)];      my $salt1 = $token[(time | $$) % scalar(@token)];
249      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];      my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
250      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
251      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($AdminSpecialPage, 'AdminPassword', $crypted);
252    
253      &print_header($CompletedSuccessfully, -noindex => 1);      &print_header('CompletedSuccessfully', -noindex => 1);
254      &print_message($resource{passwordchanged});      &print_message(&Resource('Error:PasswordIsChanged'));
255      &print_footer($CompletedSuccessfully);      &print_footer('CompletedSuccessfully');
256  }  }
257    
258  sub do_index {  sub do_index {
# Line 321  sub do_index { Line 263  sub do_index {
263      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
264          if (&is_editable($page)) {          if (&is_editable($page)) {
265              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
             # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);  
             # print qq(<li>@{[0 + &is_frozen($page)]}</li>);  
266          }          }
267      }      }
268      print qq(</ul>);      print qq(</ul>);
269      my ($r, $c) = get_search_result ($form{mypage});      my ($r, $c) = get_search_result ($form{mypage});
270      if ($c) {      if ($c) {
271        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};
272        print $r;        print $r;
273      }      }
274      my $rl = wiki::referer::list_html ($form{mypage});      my $rl = wiki::referer::list_html ($form{mypage});
275      if ($rl) {      if ($rl) {
276          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>??????</h2>\n$rl</div>\n);          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
277      }      }
278      &print_footer($IndexPage);      &print_footer($IndexPage);
279  }  }
# Line 345  sub do_write { Line 285  sub do_write {
285    
286      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
287          &print_header($form{mypage}, -noindex => 1);          &print_header($form{mypage}, -noindex => 1);
288          &print_message($resource{cantchange});          &print_message(&Resource('Error:ThisPageIsUneditable'));
289          &print_footer($form{mypage});          &print_footer($form{mypage});
290          return;          return;
291      }      }
# Line 365  sub do_write { Line 305  sub do_write {
305    
306      if ($form{mymsg}) {      if ($form{mymsg}) {
307          $database{$form{mypage}} = $form{mymsg};          $database{$form{mypage}} = $form{mymsg};
308          &send_mail_to_admin($form{mypage}, "Modify");          #&send_mail_to_admin($form{mypage}, "Modify");
309          if ($form{mytouch}) {          if ($form{mytouch}) {
310              &set_info($form{mypage}, $info_LastModified, '' . localtime);              &set_info($form{mypage}, $info_LastModified, time);
311              &update_recent_changes;              &update_recent_changes;
312          }          }
313          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
# Line 378  sub do_write { Line 318  sub do_write {
318          } elsif ($form{__wikiform_anchor_index}) {          } elsif ($form{__wikiform_anchor_index}) {
319              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});              $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
320          }          }
321          &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));          &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));
322          &print_message($resource{saved});          &print_message(&Resource('Error:SavedSuccessfully'));
323          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content(&Resource('Error:ContinueReading')." @{[&armor_name($form{mypage})]}");
324          &print_footer($CompletedSuccessfully);          &print_footer('CompletedSuccessfully');
325      } else {      } else {
326          &send_mail_to_admin($form{mypage}, "Delete");          #&send_mail_to_admin($form{mypage}, "Delete");
327          delete $database{$form{mypage}};          delete $database{$form{mypage}};
328          delete $infobase{$form{mypage}};          delete $infobase{$form{mypage}};
329          if ($form{mytouch}) {          if ($form{mytouch}) {
330              &update_recent_changes;              &update_recent_changes;
331          }          }
332          &print_header($form{mypage}, -noindex => 1);          &print_header($form{mypage}, -noindex => 1);
333          &print_message($resource{deleted});          &print_message(&Resource('Error:PageIsDeletedSuccessfully'));
334          &print_footer($form{mypage});          &print_footer($form{mypage});
335      }      }
336  }  }
# Line 414  sub get_search_result ($;%) { Line 354  sub get_search_result ($;%) {
354    my %option = @_;    my %option = @_;
355    my @r;    my @r;
356    foreach my $page (keys %database) {    foreach my $page (keys %database) {
357      next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});      next if !$option{-match_myself} && ($page eq $word);
358      my $content = $database{$page};      my $content = lc $database{$page};
     my $cf = 'SuikaWiki/0.9';  
     $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;  
     next if $cf =~ /obsoleted="yes"/;  
359      if (index (lc $page, $word) > -1) {      if (index (lc $page, $word) > -1) {
360        my $c = $content =~ s/\Q$word\E//gi;        my $c = $content =~ s/\Q$word\E//g;
361        push @r, [$page, $c+20];        push @r, [$page, $c+20];
362      } elsif (index ($word, lc $page) > -1) {      } elsif (index ($word, lc $page) > -1) {
363        my $c = $content =~ s/\Q$word\E//gi;        my $c = $content =~ s/\Q$word\E//g;
364        push @r, [$page, $c+10];        push @r, [$page, $c+10];
365      } elsif (my $c = $content =~ s/\Q$word\E//gi) {      } elsif (my $c = $content =~ s/\Q$word\E//g) {
366        push @r, [$page, $c];        push @r, [$page, $c];
367      }      }
368    }    }
369    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };    #my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
370    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&escape($_->[0])]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($_->[0]))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
371    $r = qq|<ul class="search-result">$r</ul>| if $r;    $r = qq|<ul class="search-result">$r</ul>| if $r;
   get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};  
372    wantarray? ($r, scalar @r): $r;    wantarray? ($r, scalar @r): $r;
373  }  }
374    
# Line 441  sub do_create { Line 377  sub do_create {
377      print <<"EOD";      print <<"EOD";
378  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
379      <input type="hidden" name="mycmd" value="edit">      <input type="hidden" name="mycmd" value="edit">
380      <strong>$resource{newpagename}</strong><br>      <strong>@{[&Resource('InputPageNameEdited',escape=>1)]}</strong><br>
381      <input type="text" name="mypage" value="" size="20">      <input type="text" name="mypage" value="" size="20">
382      <input type="submit" value="$resource{createbutton}"><br>      <input type="submit" value="@{[&Resource('WikiForm:Create',escape=>1)]}"><br>
383  </form>  </form>
384  EOD  EOD
385      &print_footer($CreatePage);      &print_footer($CreatePage);
# Line 452  EOD Line 388  EOD
388  sub do_random_jump {  sub do_random_jump {
389    my @list = keys %database;    my @list = keys %database;
390    my $name = &encode ($list[rand @list]);    my $name = &encode ($list[rand @list]);
391    my ($scheme) = 'http';    my $scheme = 'http';
392    $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;    $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
393    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";    print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
394    print "\n";    print "\n";
395  }  }
396    
 sub do_FrontPage {  
     open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");  
     my $content = join('', <FILE>);  
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
     &print_header($FrontPage);  
     &print_content($content);  
     &print_footer($FrontPage);  
 }  
   
397  sub print_error {  sub print_error {
398      my ($msg) = @_;      my ($msg) = @_;
399      &print_header($ErrorPage, -noindex => 1);      &print_header($ErrorPage, -noindex => 1);
# Line 478  sub print_error { Line 404  sub print_error {
404    
405  sub print_header ($;%) {  sub print_header ($;%) {
406      my ($page, %option) = @_;      my ($page, %option) = @_;
407      my $bodyclass = "normal";      my @head;
408      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      $option{body_class} = &is_frozen($page) ? 'frozen' : 'normal';
409          $bodyclass = "frozen";      $option{body_class} .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
     }  
     $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;  
410      if ($option{-goto}) {      if ($option{-goto}) {
411        if ($UA =~ m#Opera|MSIE 2\.#) {        if ($UA =~ m#Opera|MSIE 2\.#) {
412              ## WARNING: This code may output unsafe HTML document if
413              ##          $option{-goto} is not clean.
414            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
415            print qq{Refresh: 0; url=$option{-goto}\n};            print qq{Refresh: 0; url=$option{-goto}\n};
416            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);            push @head, qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
417        } else {        } else {
418            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
419            print qq{Refresh: 0; url="$option{-goto}"\n};            print qq{Refresh: 0; url="$option{-goto}"\n};
420            $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);            push @head, qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
421        }        }
422      }      }
423      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};      print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} if $option{-last_modified};
     my $meta_ct = '';  
424      if ($UA =~ m#Mozilla/2#) {      if ($UA =~ m#Mozilla/2#) {
425          $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};          my $ct = qq{text/html; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
426          print qq{Content-Type: $meta_ct\n};          print qq{Content-Type: $ct\n};
427          $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};          push @head, qq{<meta http-equiv="content-type" content="$ct">};
428      } elsif ($UA =~ m#Infomosaic#) {      } elsif ($UA =~ m#Infomosaic#) {
429          print qq{Content-Type: text/html\n};          print qq{Content-Type: text/html\n};
430      } else {      } else {
431          print qq{Content-Type: text/html; charset=$charset\n};          print qq{Content-Type: text/html; charset=@{[&get_charset_name($kanjicode)]}\n};
432      }      }
433      my $cookedpage = &encode($page);      push @head, qq(<title>@{[&escape($page)]}</title>);
434      my $escapedpage = &escape($page);      push @head, qq(<link rel="stylesheet" type="text/css" href="@{[&escape($uri{stylesheet})]}")
435          if $UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#;
436        push @head, q(<meta name="ROBOTS" content="NOINDEX">) if $option{-noindex};
437      my ($Links, $links) = &make_navigate_links ($page);      my ($Links, $links) = &make_navigate_links ($page);
438      print $Links;      #print $Links;      ## Link: fields
439        $links = join "\n", (@head, $links);
440      print <<"EOD";      print <<"EOD";
441  Content-Language: $lang  Content-Language: $lang
442  Content-Style-Type: text/css  Content-Style-Type: text/css
443    
444  <!--  <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
445  <!DOCTYPE html  "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
446      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  <html lang="$lang" class="$option{body_class}">
     "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->  
 <html lang="$lang">  
447  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
     $meta_ct$option{-goto}  
     <title>$escapedpage</title>  
     @{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']}  
     @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}  
448  $links  $links
449  </head>  </head>
450  <body class="$bodyclass">  <body class="$option{body_class}">
451  EOD  EOD
452    &print_navigate_links ($page);      &print_navigate_links ($page);
453    print <<EOD;      print <<EOD;
454  <h1 class="header">@{[&escape($page)]}</h1>  <h1 class="header">@{[&escape($page)]}</h1>
455  EOD  EOD
456  }  }
457    
458  sub x_charset ($) {  sub get_charset_name ($;%) {
459      my $charset = lc shift;      my ($charset, %option) = (lc shift, @_);
460      if ($charset eq 'euc-jp') {      if ($charset =~ 'euc') {
461          $charset = 'x-euc-jp';          $charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp';
462      } elsif ($charset eq 'shift_jis') {      } elsif ($charset =~ 'sjis' || $charset =~ 'shift') {
463          $charset = 'x-sjis';          $charset = $option{compatible} ? 'x-sjis' : 'shift_jis';
464        } elsif ($charset =~ 'jis') {
465            $charset = 'iso-2022-jp';
466      }      }
467      $charset;      $charset;
468  }  }
469    
470  sub print_navigate_links (@) {  sub print_navigate_links (@) {
471    my ($page) = @_;    my ($page) = @_;
472      my $editable = 0;    my $editable = (&is_editable($page) && !&is_frozen($page)) ? 1 : 0;
473      my $admineditable = 0;    my $cookedpage = &encode($page);
     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $editable = 0;  
         #$admineditable = 1;  
     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {  
         #$admineditable = 1;  
         $editable = 1;  
     } else {  
         $editable = 0;  
     }  
     my $cookedpage = &encode($page);  
474    print <<EOH;    print <<EOH;
475  <div class="tools">  <div class="tools">
     @{[ $admineditable  
         ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage" class="wiki-cmd">$resource{admineditbutton}</a> | )  
         : qq()  
     ]}  
476      @{[ $editable      @{[ $editable
477          ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )          ? qq(<a title="@{[&Resource('EditThisPageLong',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">@{[&Resource('EditThisPage',escape=>1)]}</a> | )
         qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">編集</a> | )  
         : qq()  
     ]}  
     <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd">表示</a> |  
     @{[ $admineditable  
         ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage" class="wiki-cmd">$resource{diffbutton}</a> | )  
478          : qq()          : qq()
479      ]}      ]}
480      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |      <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> |
481      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |      <a href="$url_cgi?mycmd=map;mypage=$cookedpage" class="wiki-cmd" title="@{[&Resource('ShowMapOfThisPageLong',escape=>1)]}">@{[&Resource('ShowMapOfThisPage',escape=>1)]}</a> |
482      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |      <a href="$url_cgi?$CreatePage" class="wiki" title="@{[&Resource('GoToCreatePageLong',escape=>1)]}">@{[&Resource('GoToCreatePage',escape=>1)]}</a> |
483      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |      <a href="$url_cgi?$IndexPage" class="wiki" title="@{[&Resource('GoToIndexPageLong',escape=>1)]}">@{[&Resource('GoToIndexPage',escape=>1)]}</a> |
484      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |      <a href="$url_cgi?$FrontPage" class="wiki" title="@{[&Resource('GoToHomePageLong',escape=>1)]}">@{[&Resource('GoToHomePage',escape=>1)]}</a> |
485      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>      <a href="$url_cgi?$SearchPage" class="wiki" title="@{[&Resource('GoToSearchPageLong',escape=>1)]}">@{[&Resource('GoToSearchPage',escape=>1)]}</a> |
486        <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> |
487        <a href="$url_cgi?RecentChanges" class="wiki" title="@{[&Resource('GoToRecentChangesLong',escape=>1)]}">@{[&Resource('GoToRecentChanges',escape=>1)]}</a>
488  </div>  </div>
489  EOH  EOH
490  }  }
# Line 586  EOH Line 492  EOH
492  sub make_navigate_links ($) {  sub make_navigate_links ($) {
493      my $page = shift;      my $page = shift;
494      my @link;      my @link;
495      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{editbutton}} 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);
496      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{admineditbutton}} if &is_editable ($page) || &is_frozen ($page);      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);
497      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>'View latest version of this page'};      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')};
498      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
499      push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};      push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
500      push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};      push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>&Resource('GoToHomePageLink')};
501      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};      push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>&Resource('GoToWikiNewsLink')};
502      push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};      push @link, {rel=>'News', href=>"$url_cgi?RecentChanges", class=>"wiki", title=>&Resource('GoToRecentChangesLink')};
503      push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};      push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>&Resource('GoToRssPageLink'), type=>'application/xml'};
504      push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};      push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>&Resource('GoToSearchPageLink')};
505      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};      push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki', title=>&Resource('GoToWikiHelpLink')};
506      push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};      push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki', title=>&Resource('GoToWikiPageLicenseLink')};
507      push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3F'+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to...'};      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')};
508      push @link, {rel=>'jump', href=>q(javascript:var%20WikiName=prompt('Please%20input%20the%20WikiName:','','Jump%20to%20SuikaWiki');if(WikiName)%7B_content.location.href='http://suika.fam.cx/%7Ewakaba/-temp/wiki/wiki%3Fmycmd=edit;mypage='+encodeURIComponent(WikiName)%7D), class=>'wiki-cmd', title=>'Jump to (edit)...'};      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')};
509      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>'Somewhere'};      push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>&Resource('GoSomewhereLink')};
510        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};
511        push @link, {rel=>'history', href=>"$url_cgi?mycmd=diff;mypage=@{[&encode($page)]}", title=>&Resource('ViewDiffOfThisPageLink'), class=>'wiki-command'};
512        push @link, {rel=>'contents', href=>"$url_cgi?mycmd=map;mypage=@{[&encode($page)]}", title=>&Resource('ShowMapOfThisPageLink'), class=>'wiki-command'};
513      my ($Links, $links) = ('', '');      my ($Links, $links) = ('', '');
514      for my $e (@link) {      for my $e (@link) {
515          $links .= qq(<link);          $links .= qq(<link);
# Line 620  sub make_navigate_links ($) { Line 529  sub make_navigate_links ($) {
529  sub print_footer {  sub print_footer {
530      my ($page, $lm) = @_;      my ($page, $lm) = @_;
531      my $epage = &encode ($page);      my $epage = &encode ($page);
     $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)  
     # Walrus mod (1) start  
532    my $cvslog1 = q$Revision$;    my $cvslog1 = q$Revision$;
533    my $cvslog2 = q$Date$;    my $cvslog2 = q$Date$;
534    print_navigate_links ($page);    print_navigate_links ($page);
535    print <<"EOD";    print <<"EOD";
536  @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}  @{[ $lm ? qq(<div id="wikipage-last-modified">@{[&Resource('LastModified=',escape=>1)]}@{[&_rfc3339_date ($lm)]}</div>) : '' ]}
537  <div class="footer">  <div class="footer">
538  <a href="http://www.hyuki.com/yukiwiki/" title="$version &copy; 2000-2002 by Hiroshi Yuki">YukiWiki</a> <a href="http://digit.que.ne.jp/work/" title="$walversion &copy; 2000-2002 by Makio Tsukamoto">WalWiki</a>  <a href="http://www.hyuki.com/yukiwiki/" title="YukiWiki 2.0.beta1.2002-05-29 &copy; 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 &copy; 2000-2002 by Makio Tsukamoto">@{[&Resource('About:Name:WalWiki',escape=>1)]}</a>
539  <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>  <a href="/gate/cvs/wakaba/wiki/" title="@{[&Resource('About:SuikaWiki:JumpToCVS',escape=>1)]} ($cvslog2)">@{[&Resource('About:Name:SuikaWiki',escape=>1)]} $cvslog1</a>
 <div class="navigation">  
 [<a href="/" title="このサーバーの首頁">/</a>  
 <a href="/map" title="このサーバーの案内">地図</a>  
 <a href="/search/" title="このサーバーの検索">検索</a>]  
540  </div>  </div>
 <div class="myuri">  
     &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;  
 </div>  
 </div>  
 $walrus_log  
541  </body>  </body>
542  </html>  </html>
543  EOD  EOD
# Line 672  sub print_content ($;$) { Line 570  sub print_content ($;$) {
570    
571  sub text_to_html {  sub text_to_html {
572      my ($txt, %option) = @_;      my ($txt, %option) = @_;
     my (@txt) = split(/\n/, $txt);  
573      my @toc;      my @toc;
574      my @toc2 = @{$option{-toc}||[]};      my @toc2 = @{$option{-toc}||[]};
575      my $tocnum = 0;      my $tocnum = 0;
576        
577        ## Load constants
578        my %const;
579        if ($option{content_format} =~ /import="([^"]+)"/) {
580          for (split /\s*,\s*/, $1) {
581            my $wp = $database{$_};
582            if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
583              wiki::suikawikiconst::to_hash ($wp => \%const);
584            }
585          }
586        }
587        
588        $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;
589        my (@txt) = split(/\n/, $txt);
590      my (@saved, @result);      my (@saved, @result);
591      unshift(@saved, "</p>");      unshift(@saved, "</p>");
592      push(@result, "<p>");      push(@result, "<p>");
# Line 683  sub text_to_html { Line 594  sub text_to_html {
594          chomp;          chomp;
595          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
596              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
597              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
598              $tocnum++;              $tocnum++;
599          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
600              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
601              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
602              $tocnum++;              $tocnum++;
603          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
604              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
605              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
606              $tocnum++;              $tocnum++;
607          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
608          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
609          # Walrus mod (6) end          # Walrus mod (6) end
610              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
611              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
612              $tocnum++;              $tocnum++;
613          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
614              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
615              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
616              $tocnum++;              $tocnum++;
617          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
618              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
619              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2, const => \%const) . '</li>');
620          } elsif (/^(-{1,6})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
621            &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
622            my ($pf, $l) = ('', $2);            my ($pf, $l) = ('', $2);
# Line 713  sub text_to_html { Line 624  sub text_to_html {
624              my $num = 0+$1;              my $num = 0+$1;
625              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);              $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
626            }            }
627            push(@result, '<li>' . $pf . &inline ($l) . '</li>');            push(@result, '<li>' . $pf . &inline ($l, const => \%const) . '</li>');
628          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
629              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
630              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1, const => \%const) . '</dt>', '<dd>' . &inline($2, const => \%const) . '</dd>');
631          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
632              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
633              push @result, "<p>";              push @result, "<p>";
634              push(@result, &inline($2));              push(@result, &inline($2, const => \%const));
635              unshift @saved, "</p>";              unshift @saved, "</p>";
636          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
637              push(@result, splice(@saved));              push(@result, splice(@saved));
# Line 728  sub text_to_html { Line 639  sub text_to_html {
639              unshift(@saved, "</p>");              unshift(@saved, "</p>");
640          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
641              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
642              #push(@result, &escape($1)); # Not &inline, but &escape              push(@result, &inline($1, const => \%const));
643              push(@result, &inline($1));          } elsif (/^\,(.*?)[\x0D\x0A]*$/) {
644  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)              &back_push('table', 1, \@saved, \@result);
         } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)  
             &back_push('table', 1, \@saved, \@result, ' border="1"');  
645              #######              #######
646              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.              # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
647              # XXXXX              # XXXXX
# Line 746  sub text_to_html { Line 655  sub text_to_html {
655                          $colspan[$i]++;                          $colspan[$i]++;
656                      }                      }
657                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';                      $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
658                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i]));                      $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i], const => \%const));
659                  } else {                  } else {
660                      $value[$i] = '';                      $value[$i] = '';
661                  }                  }
# Line 763  sub text_to_html { Line 672  sub text_to_html {
672          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {          } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
673            my $num = 0+$1;            my $num = 0+$1;
674            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);            push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
675            push @result, &inline ($2);            push @result, &inline ($2, const => \%const);
676          } else {          } else {
677              push(@result, &inline($_));              push(@result, &inline($_, const => \%const));
678          }          }
679      }      }
680      push(@result, splice(@saved));      push(@result, splice(@saved));
# Line 806  sub back_push { Line 715  sub back_push {
715      }      }
716  }  }
717    
718  sub inline {  sub inline ($;%) {
719      my ($line) = @_;      my ($line, %option) = @_;
720      $line = &escape($line);      $line = &escape($line);
721      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
722      $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;      $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;
# Line 820  sub inline { Line 729  sub inline {
729      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
730      $line =~ s|''([^']+)''|<em>$1</em>|g;      $line =~ s|''([^']+)''|<em>$1</em>|g;
731      $line =~ s{      $line =~ s{
732        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]        (\[\[(\#\S+?)\]\])
733        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]        |\[\[([^[]+?)](?:&gt;&gt;([0-9]+))?]
734        |&gt;&gt;([0-9]+)        |&gt;&gt;([0-9]+)
735        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
736      }{      }{
737        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);        my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
738        if ($l) {        if ($l) {
739          &make_link($l)          return &embedded_to_html($1);
740        } elsif (defined $page) {        } elsif (defined $page) {
741          &make_wikilink ($page, anchor => 0+$anchor);          &make_wikilink ($page, anchor => 0+$anchor);
742        } elsif ($anum) {        } elsif ($anum) {
# Line 850  sub make_wikilink ($%) { Line 759  sub make_wikilink ($%) {
759        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);        return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
760      }      }
761    } else {    } else {
762      return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">$editchar</span></a>);      return qq(<a title="@{[&Resource('JumpAndEditWikiPage',escape=>1)]}" href="$url_cgi?mycmd=edit;mypage=@{[&escape($name)]}" class="wiki not-exist">$ename<span class="mark">@{[&Resource('JumpAndEditWikiPageMark',escape=>1)]}</span></a>);
763    }    }
764  }  }
765    
# Line 864  sub make_urilink ($;%) { Line 773  sub make_urilink ($;%) {
773        for ($site, $name) {        for ($site, $name) {
774          if (s/^"//) { s/"$//; s/\\(.)/$1/g }          if (s/^"//) { s/"$//; s/\\(.)/$1/g }
775        }        }
776          &init_InterWikiName () unless $interwiki{'[[]]'};
777        if ($interwiki{$site}) {        if ($interwiki{$site}) {
778            &load_formatter ('interwiki');
779          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
780          $site = &escape ($site); $name = &escape ($name);          $site = &escape ($site); $name = &escape ($name);
781          qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>&gt;);          qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>&gt;);
782        } else {        } else {
783          qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);          qq(&lt;@{[&Resource('Error:UnknownInterWikiName=',escape=>1)]}@{[&escape ($site)]}&gt;);
784        }        }
785      } else {      } else {
786        qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);        qq(&lt;@{[&Resource('Error:InvalidInterWiki=',escape=>1)]}@{[&escape($uri)]}&gt;);
787      }      }
788    } elsif ($uri =~ /^urn:/) {   ## URN    } elsif ($uri =~ /^urn:/) {   ## URN
789      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);      my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
# Line 891  sub make_urilink ($;%) { Line 802  sub make_urilink ($;%) {
802    }    }
803  }  }
804    
805  my $FormIndex = 0;  {my $FormIndex = 0;
806  sub make_custom_form ($$$$) {  sub make_custom_form ($$$$) {
807      my ($wfname, $definition, $template, $option) = @_;      my ($wfname, $definition, $template, $option) = @_;
808      ## $template and $option is currently not used in this procedure.      ## $template and $option is currently not used in this procedure.
# Line 928  EOH Line 839  EOH
839             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);             qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
840         }         }
841      } else {      } else {
842          q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);          qq(<ins class="wiki-error">@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]}</ins>);
     }  
 }  
   
 ## to be obsoleted  
 sub make_link {  
     my $chunk = shift;  
     # Walrus add (3) start  
     $chunk =~ s/^&lt;(.*)&gt;$/$1/;  
     my $name  = $chunk;  
     $name = &unarmor_name($name);  
     # Walrus add (3) end  
     if ($chunk =~ /^$embedded_name$/) {  
         return &embedded_to_html($chunk);  
     } else {  
         $chunk = &unarmor_name($chunk);  
         $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.  
         my $cookedchunk = &encode($chunk);  
         if ($database{$chunk}) {  
             my $subject = &escape(&get_subjectline($chunk, delimiter => ''));  
 #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)  
             return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)  
         } elsif ($page_command{$chunk}) {  
 #           return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>);    # Walrus del (3)  
             return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)  
         } else {  
             return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);  
         }  
843      }      }
844  }  }}
845    
846  sub print_message {  sub print_message {
847      my ($msg) = @_;      my ($msg) = @_;
848      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>@{[&escape($msg)]}</strong></p>);
 }  
   
 sub get_message {  
     my ($msg) = @_;  
     qq(<p><strong>$msg</strong></p>);  
849  }  }
850    
851  sub init_form {  sub init_form {
852      if (param()) {      ## TODO: Support multipart/form-data
853          foreach my $var (param()) {      my $query = '';
854              $form{$var} = param($var);      if (uc $main::ENV{REQUEST_METHOD} eq 'POST') {
855        }        read STDIN, $query, $main::ENV{CONTENT_LENGTH};
856      }      }
857      $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);      $query .= ($query ? ';' : '') . $main::ENV{QUERY_STRING};
858      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
859        my $query = &decode($main::ENV{QUERY_STRING});        my $query = &decode($main::ENV{QUERY_STRING});
860        $query = &code_convert(\$query, $kanjicode);        $query = &code_convert(\$query, $kanjicode);
# Line 986  sub init_form { Line 865  sub init_form {
865          $form{mypage} = $query;          $form{mypage} = $query;
866          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';          $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
867        }        }
868        } else {
869          for (split /[;&]/, $query) {
870            if (my ($n, $v) = split /=/, $_, 2) {
871              for ($n, $v) {tr/+/ /; s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge};
872              $form{$n} = $v;
873            }
874          }
875          if ($page_command{$form{mypage}} && $form{mycmd} eq 'read') {
876            $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
877            $form{mycmd} = $page_command{$form{mypage}};
878          }
879      }      }
880      $form{mypage} ||= 'HomePage';      $form{mypage} ||= 'HomePage';
881      $form{mycmd} ||= 'read';      $form{mycmd} ||= 'read';
# Line 1012  sub init_form { Line 902  sub init_form {
902  }  }
903    
904  sub update_recent_changes {  sub update_recent_changes {
905      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[$form{mypage}]] @{[&get_subjectline($form{mypage})]}";
906      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\x0D?\x0A/, $database{RecentChanges});
907      shift (@oldupdates); ## '#?' magic line      shift @oldupdates; ## '#?' magic line
908      my @updates;      my @updates;
909      foreach (@oldupdates) {      foreach (@oldupdates) {
910          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;          /^\- \d\d\d\d\-\d\d\-\d\d \d\d:\d\d \[\[([^]]+)\]\]/;
911          my $name = $1;          my $name = $1;
912          if ($name ne $form{mypage}) {          if ($name ne $form{mypage}) {
913              push @updates, $_;              push @updates, $_;
# Line 1026  sub update_recent_changes { Line 916  sub update_recent_changes {
916      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
917        unshift @updates, $update;        unshift @updates, $update;
918      }      }
919      splice(@updates, $maxrecent + 1);      splice @updates, (&Resource ('RecentChanges:Max') || 50) + 1;
920      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);      $database{RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
921      if ($file_touch) {      if ($file_touch) {
922          open(FILE, "> $file_touch");          open(FILE, "> $file_touch");
923          print FILE localtime() . "\n";          print FILE localtime() . "\n";
# Line 1035  sub update_recent_changes { Line 925  sub update_recent_changes {
925      }      }
926  }  }
927    
928    {my %SubjectLine;
929  sub get_subjectline {  sub get_subjectline {
930      my ($page, %option) = @_;      my ($page, %option) = @_;
931      if (not &is_editable($page)) {      unless (defined $SubjectLine{$page}) {
932          return "";        if (not &is_editable($page)) {
933            $SubjectLine{$page} = "";
934          } else {
935            $SubjectLine{$page} = $database{$page};
936            $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
937            $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
938          }
939        }
940        if (length $SubjectLine{$page}) {
941          $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
942          $option{delimiter}.$SubjectLine{$page}.$option{tail};
943      } else {      } else {
944          # Delimiter check.        '';
         my $delim = $subject_delimiter;  
         if (defined($option{delimiter})) {  
             $delim = $option{delimiter};  
         }  
   
         # Get the subject of the page.  
         my $subject = $database{$page};  
         $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;  
         $subject =~ s/\r?\n.*//s;  
         return "$delim$subject".$option{tail};  
945      }      }
946  }  }}
   
 sub send_mail_to_admin {  
     my ($page, $mode) = @_;  
     return unless $modifier_sendmail;  
     my $message = <<"EOD";  
 To: $modifier_mail  
 From: $modifier_mail  
 Subject: [Wiki]  
 MIME-Version: 1.0  
 Content-Type: text/plain; charset=ISO-2022-JP  
 Content-Transfer-Encoding: 7bit  
   
 --------  
 MODE = $mode  
 REMOTE_ADDR = $ENV{REMOTE_ADDR}  
 REMOTE_HOST = $ENV{REMOTE_HOST}  
 --------  
 $page  
 --------  
 $database{$page}  
 --------  
 EOD  
     &code_convert(\$message, 'jis');  
     open(MAIL, "| $modifier_sendmail");  
     print MAIL $message;  
     close(MAIL);  
 }  
947    
948  sub open_db {  sub open_db {
949      if ($modifier_dbtype eq 'dbmopen') {      if ($modifier_dbtype eq 'dbmopen') {
950          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");          dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");
951          dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");          dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");
952      } elsif ($modifier_dbtype eq 'AnyDBM_File') {      } elsif ($modifier_dbtype eq 'AnyDBM_File') {
953            eval q{use AnyDBM_File};
954          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");          tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");
955          tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");          tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");
956      } else {      } else {
957            eval q{use Yuki::YukiWikiDB};
958          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");          tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");
959          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");          tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");
960      }      }
# Line 1133  sub print_searchform { Line 999  sub print_searchform {
999  <form action="$url_cgi" method="get">  <form action="$url_cgi" method="get">
1000      <input type="hidden" name="mycmd" value="read">      <input type="hidden" name="mycmd" value="read">
1001      <input type="text" name="mypage" value="$word" size="20">      <input type="text" name="mypage" value="$word" size="20">
1002      <input type="submit" value="$resource{searchbutton}">      <input type="submit" value="@{[&Resource('WikiForm:Search',escape=>1)]}">
1003  </form>  </form>
1004  EOD  EOD
1005  }  }
# Line 1145  sub print_editform { Line 1011  sub print_editform {
1011      if ($form{mypreview}) {      if ($form{mypreview}) {
1012          if ($form{mymsg}) {          if ($form{mymsg}) {
1013              unless ($mode{conflict}) {              unless ($mode{conflict}) {
1014                  print qq(<h3>$resource{previewtitle}</h3>\n);                  print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);
1015                  print qq($resource{previewnotice}\n);                  print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);
1016                  print qq(<div class="preview">\n);                  print qq(<div class="preview">\n);
1017                  &print_content($form{mymsg});                  &print_content($form{mymsg});
1018                  print qq(</div>\n);                  print qq(</div>\n);
1019              }              }
1020          } else {          } else {
1021              print qq($resource{previewempty});              print @{[&Resource('Preview:Empty',escape=>1)]};
1022          }          }
1023          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
1024      } else {      } else {
# Line 1167  sub print_editform { Line 1033  sub print_editform {
1033      my $selected = 'read';      my $selected = 'read';
1034      if ($form{after_edit_cmd}) {      if ($form{after_edit_cmd}) {
1035          $selected = $form{after_edit_cmd};          $selected = $form{after_edit_cmd};
1036      } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {      } elsif ($magic =~ /Const|Config|CSS/) {
1037          $selected = 'edit';          $selected = 'edit';
1038      }      }
1039      my $afteredit = <<EOH;      my $afteredit = <<EOH;
1040  <select name="after_edit_cmd">  <select name="after_edit_cmd">
1041  <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
1042  <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
1043  </select>  </select>
1044  EOH  EOH
1045    
1046      print <<"EOD";      print <<"EOD";
1047  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1048  <h2>$escapedmypageの編集</h2>  <h2>@{[&Resource('Edit:Title',escape=>1)]}</h2>
1049      @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}      @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]}
1050      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;      @{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="$escapedmypassword" size="10"></label>) : "" ]} [@{[do {my $n = 0;
1051                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1052                 ++$n}]}]<br>                 ++$n}]}]<br>
1053      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1054      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="$escapedmypage">
1055      <textarea cols="$cols" rows="$rows" 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">$mymsg</textarea><br>
1056  @{[  @{[
1057      $mode{admin} ?      $mode{admin} ?
1058      qq(      qq(
1059      <input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton}      <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
1060      <input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>)      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)
1061      : ""      : ""
1062  ]}  ]}
1063  @{[  @{[
1064      $mode{conflict} ? "" :      $mode{conflict} ? "" :
1065      qq(      qq(
1066          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}<br>
1067          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}">
1068          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>          <input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd>
1069         $afteredit         $afteredit
1070         <br>         <br>
1071      )      )
# Line 1207  EOH Line 1073  EOH
1073  </form>  </form>
1074  EOD  EOD
1075      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1076          # Show the format rule.          ## Show help text
1077          my $help = $database{'WikiEditHelp'};          my $help = $database{WikiEditHelp};
1078          $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;
1079          print &text_to_html ($help, toc => 0);          print &text_to_html ($help, toc => 0);
     #    open(FILE, $file_format) or &print_error("($file_format)");  
     #    my $content = join('', <FILE>);  
     #    &code_convert(\$content, $kanjicode);  
     #    close(FILE);  
     #    print &text_to_html($content, toc=>0);  
1080      }      }
1081  }  }
1082    
# Line 1223  sub print_passwordform { Line 1084  sub print_passwordform {
1084          print <<"EOD";          print <<"EOD";
1085  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1086      <input type="hidden" name="mycmd" value="adminchangepassword">      <input type="hidden" name="mycmd" value="adminchangepassword">
1087      $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>      <label>@{[&Resource('Password:Old=',escape=>1)]}<input type="password" name="myoldpassword" size="10"></label><br>
1088      $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>      <label>@{[&Resource('Password:New1=',escape=>1)]}<input type="password" name="mynewpassword" size="10"></label><br>
1089      $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>      <label>@{[&Resource('Password:New2=',escape=>1)]}<input type="password" name="mynewpassword2" size="10"></label><br>
1090      <input type="submit" value="$resource{changepasswordbutton}"><br>      <input type="submit" value="@{[&Resource('WikiForm:Change',escape=>1)]}"><br>
1091  </form>  </form>
1092  EOD  EOD
1093  }  }
# Line 1250  sub armor_name { qq([[$_[0]]]) } Line 1111  sub armor_name { qq([[$_[0]]]) }
1111  #   WikiName -> WikiName  #   WikiName -> WikiName
1112  sub unarmor_name {  sub unarmor_name {
1113      my ($name) = @_;      my ($name) = @_;
1114      if ($name =~ /^$bracket_name$/) {      if ($name =~ /^\[\[(\S+?)\]\]$/) {
1115          return $1;          return $1;
1116      } else {      } else {
1117          return $name;          return $name;
# Line 1277  sub encode { Line 1138  sub encode {
1138      return $encoded;      return $encoded;
1139  }  }
1140    
 sub init_resource {  
     open(FILE, $file_resource) or &print_error("(resource)");  
     while (<FILE>) {  
         s/[\x0A\x0D]+$//g;  
         next if /^#/;  
         my ($key, $value) = split(/=/, $_, 2);  
         $resource{$key} = &code_convert(\$value, $kanjicode);  
     }  
     close(FILE);  
 }  
   
1141  sub conflict {  sub conflict {
1142      my ($page, $rawmsg) = @_;      my ($page, $rawmsg) = @_;
1143      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {      if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1144          return 0;          return 0;
1145      }      }
     open(FILE, $file_conflict) or &print_error("(conflict)");  
     my $content = join('', <FILE>);  
     &code_convert(\$content, $kanjicode);  
     close(FILE);  
1146      &print_header($page, -noindex => 1);      &print_header($page, -noindex => 1);
1147      &print_content($content);      &print_content(&Resource('Error:Conflict'));
1148      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1149      &print_footer($page);      &print_footer($page);
1150      return 1;      return 1;
1151  }  }
1152    
1153  sub get_now {  sub get_now {
1154      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
     my (@week) = qw(日 月 火 水 木 金 土);  
     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);  
1155      $year += 1900;      $year += 1900;
1156      $mon++;      $mon++;
1157      $mon = "0$mon" if $mon < 10;      $mon = "0$mon" if $mon < 10;
# Line 1315  sub get_now { Line 1159  sub get_now {
1159      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1160      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1161      #$sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1162      $weekday = $week[$weekday];      return "$year-$mon-$day $hour:$min";
     return "$year-$mon-$day ($weekday) $hour:$min";  
1163  }  }
1164    
1165  sub init_InterWikiName {  sub init_InterWikiName {
1166    my @content = split /\n/, $database{$InterWikiName};    my @content = split /\n/, $database{InterWikiName};
1167    for (@content) {    for (@content) {
1168      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1169        $interwiki{$1} = $2;        $interwiki{$1} = $2;
1170      }      }
1171    }    }
1172    require Message::Util::Formatter;    $interwiki{'[[]]'} = 1;       ## dummy
   $fmt{interwiki} = Message::Util::Formatter->new;  
   $fmt{interwiki}->{encoded} = sub {  
     my ($o, $p) = @_;  
     if ($o->{except}) {  
       $o->{except} =~ tr/\x00-\x20\x22%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;  
     }  
     my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');  
     $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;  
     $s;  
   };  
   $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1  
     my ($o, $p) = @_;  
     my $s = $p->{name};  
     $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;  
     &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));  
   };  
1173  }  }
1174    
1175    
# Line 1373  sub frozen_reject { Line 1200  sub frozen_reject {
1200          # You are admin.          # You are admin.
1201          return 0;          return 0;
1202      } else {      } else {
1203          &print_error($resource{passworderror});          &print_error(&Resource('Error:PasswordIsIncorrect'));
1204          return 1;          return 1;
1205      }      }
1206  }  }
1207    
1208  sub valid_password {  sub valid_password {
1209      my ($givenpassword) = @_;      my ($givenpassword) = @_;
1210      my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);      my ($validpassword_crypt) = &get_info($AdminSpecialPage, 'AdminPassword');
1211      if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {      if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1212          return 1;          return 1;
1213      } else {      } else {
# Line 1402  sub do_comment { Line 1229  sub do_comment {
1229      my $default_name;   ## this code does not strict.      my $default_name;   ## this code does not strict.
1230      $default_name = $1 if $content =~ /default-name="([^"]+)"/;      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1231      my $datestr = '[WEAK['.&get_now.']]';      my $datestr = '[WEAK['.&get_now.']]';
1232      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;      my $namestr = $form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
1233      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1234      if ($namestr =~ /^(?:>>)?[0-9]/) {      if ($namestr =~ /^(?:>>)?[0-9]/) {
1235        $namestr = qq( ''$namestr'': );        $namestr = qq( ''$namestr'': );
# Line 1411  sub do_comment { Line 1238  sub do_comment {
1238      }      }
1239      my $anchor = &get_new_anchor_index ($content);      my $anchor = &get_new_anchor_index ($content);
1240      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1241      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\[\[\#r?comment\]\])}{
1242        my $embed = $1;        my $embed = $1;
1243        if ($i == $form{comment_index}) {        if ($i == $form{comment_index}) {
1244          if ($embed eq $embed_comment) {          if ($embed ne '[[#rcomment]]') {
1245            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;            $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1246          } else {          } else {
1247            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;            $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
# Line 1448  sub get_new_anchor_index ($) { Line 1275  sub get_new_anchor_index ($) {
1275  my $CommentIndex = 0;  my $CommentIndex = 0;
1276  sub embedded_to_html {  sub embedded_to_html {
1277      my ($embedded) = @_;      my ($embedded) = @_;
1278      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {
1279        unless ($main::_EMBEDED) {        unless ($main::_EMBEDED) {
1280          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1281          return <<"EOD";          return <<"EOD";
# Line 1458  sub embedded_to_html { Line 1285  sub embedded_to_html {
1285      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1286      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1287      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
1288      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1289      <input type="text" name="myname" value="" size="10" class="comment-name">      <input type="text" name="myname" value="" size="10" class="comment-name">
1290      <input type="text" name="mymsg" value="" size="60" class="comment-msg">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1291      <input type="submit" value="$resource{commentbutton}" class="comment-submit">      <input type="submit" value="@{[&Resource('WikiForm:Add',escape=>1)]}" title="@{[&Resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit">
1292  </p></form>  </p></form>
1293  EOD  EOD
1294       } else {       } else {
# Line 1469  EOD Line 1296  EOD
1296  <del><form action="$url_cgi" method="get">  <del><form action="$url_cgi" method="get">
1297      <input type="hidden" name="mycmd" value="read">      <input type="hidden" name="mycmd" value="read">
1298      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1299      $embed_comment_Name_Prompt      @{[&Resource('WikiForm:WikiComment:Name=',escape=>1)]}
1300      <input type="text" name="myname" value="" size="10" disabled="disabled">      <input type="text" name="myname" value="" size="10" disabled="disabled">
1301      <input type="text" name="mymsg" value="" size="60" disabled="disabled">      <input type="text" name="mymsg" value="" size="60" disabled="disabled">
     <input type="submit" value="$resource{commentbutton}" disabled="disabled">  
1302  </form></del>  </form></del>
1303  EOD  EOD
1304      }      }
1305    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1306      return get_search_result ($1, -match_myself => 1);      return get_search_result ($1, -match_myself => 1);
     # Walrus add (5) start  
     } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {  
         $_ = &make_interwiki_box($1, $2);  
         return ($_) ? $_ : $embedded;  
     # Walrus add (5) end  
1307    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1308      my ($name, $r) = ($1, '');      my ($name, $r) = ($1, '');
1309      if ($main::_EMBEDED != 1) {      if ($main::_EMBEDED != 1) {
# Line 1495  EOD Line 1316  EOD
1316        } elsif (length $content) {        } elsif (length $content) {
1317          $r = "<pre>@{[&escape ($content)]}</pre>";          $r = "<pre>@{[&escape ($content)]}</pre>";
1318        } else {        } else {
1319          $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');          $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:PageNotFound')]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1320        }        }
1321      } else {    ## nested #EMBED      } else {    ## nested #EMBED
1322        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');        $r = &text_to_html ("[INS[\n[[$name]]: @{[&Resource('Embed:Nested',escape=>1)]}\n]INS]\n", content_format => 'SuikaWiki/0.9');
1323      }      }
1324      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>);      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>);
1325    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
# Line 1511  EOD Line 1332  EOD
1332  sub load_formatter (@) {  sub load_formatter (@) {
1333      for my $t (@_) {      for my $t (@_) {
1334          unless ($fmt{$t}) {          unless ($fmt{$t}) {
1335                require Message::Util::Formatter;
1336              $fmt{$t} = Message::Util::Formatter->new;              $fmt{$t} = Message::Util::Formatter->new;
1337              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {              for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1338                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);                  $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
# Line 1538  sub do_wikiform { Line 1360  sub do_wikiform {
1360              $param->{anchor_index} = $anchor;              $param->{anchor_index} = $anchor;
1361              $param->{argv} = \%form;              $param->{argv} = \%form;
1362              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;              $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1363              $param->{default_name} ||= $DEFAULT_embed_comment_name;              $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
1364              $fmt{form_option}->replace ($option, $param);              $fmt{form_option}->replace ($option, $param);
1365              my $t = 1;              my $t = 1;
1366              for (@{$param->{require}||[]}) {              for (@{$param->{require}||[]}) {
# Line 1576  sub do_wikiform { Line 1398  sub do_wikiform {
1398      }      }
1399  }  }
1400    
   
 # Walrus add (5) start  
 sub do_interwiki_box {  
     my $remoteurl = $interwiki{$form{'myintername'}};  
     if ($remoteurl) {  
         $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;  
         print "Location: $remoteurl\n\n";  
         exit(1);  
     } else {  
         &do_read;  
     }  
 }  
 # Walrus add (5) end  
   
 # Walrus add (5) start  
 sub make_interwiki_box {  
     my ($localname, $intername) = @_;  
     my %ignoretype = (  
         'box'      => 'text',  
         'text'     => 'text',  
         'pass'     => 'password',  
         'password' => 'password'  
     );  
     my $converted = ($ignoretype{$localname}) ? <<EOD : undef;  
 <form action="$url_cgi" method="post">  
     <input type="hidden" name="mycmd" value="interwikibox">  
     <input type="hidden" name="mypage" value="$form{mypage}">  
     <input type="hidden" name="myintername" value="$intername">  
     $intername:  
     <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">  
     <input type="submit" value="Submit">  
 </form>  
 EOD  
 }  
 # Walrus add (5) end  
   
1401  sub code_convert {  sub code_convert {
1402      require Jcode;
1403      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1404      $code = 'jis' if $code =~ /iso/;      $code = 'jis' if $code =~ /iso/;
1405      $code = 'euc' if $code =~ /euc/;      $code = 'euc' if $code =~ /euc/;
1406      $code = 'sjis' if $code =~ /shift/;      $code = 'sjis' if $code =~ /shift/;
1407      $code = 'utf8' if $code =~ /utf/;      $code = 'utf8' if $code =~ /utf/;
1408      &Jcode::convert($contentref, $code);       # for Jcode.pm      #&Jcode::convert($contentref, $code);       # for Jcode.pm
1409  #    &jcode::convert($contentref, $code);       # for jcode.pl  #    &jcode::convert($contentref, $code);       # for jcode.pl
1410      &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';      #&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';
1411        Jcode->new ($contentref)->h2z->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;
1412      return $$contentref;      return $$contentref;
1413  }  }
1414    
 sub test_convert {  
     my $txt = &text_to_html(<<"EOD", toc=>1);  
 *HEADER1  
 **HEADER1-1  
 -ITEM1  
 -ITEM2  
 -ITEM3  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
   
 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 **HEADER1-2  
 :TERM1:DESCRIPTION1 AND ''BOLD''  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 :TERM2:DESCRIPTION2  
 :TERM3:DESCRIPTION3  
 ----  
 *HEADER2  
 **HEADER2-1  
 http://www.hyuki.com/  
 **HEADER2-2  
   
 [[YukiWiki2]]  
   
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1  
 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1  
 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
 >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2  
   
 LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0  
   
 >LEVEL1  
 >LEVEL1  
 >LEVEL1  
 >>LEVEL2  
 >>LEVEL2  
 >>LEVEL2  
 >>>LEVEL3  
 -HELLO-1  
 --HELLO-2  
 (HELLO-2, HELLO-2, HELLO-2)  
 ---HELLO-3  
 (HELLO-3, HELLO-3, HELLO-3)  
 --HELLO-2  
 ---HELLO-3  
 --HELLO-2  
 ---HELLO-3  
 >>>LEVEL3  
 >>>LEVEL3  
 >>>LEVEL3  
 >>>LEVEL3  
 EOD  
     print $txt;  
     exit;  
 }  
   
1415  sub do_diff {  sub do_diff {
1416      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
1417          &do_read;          &do_read;
# Line 1697  sub do_diff { Line 1422  sub do_diff {
1422      &print_header($title, -noindex => 1);      &print_header($title, -noindex => 1);
1423      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1424      &close_diff;      &close_diff;
1425      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>@{[&Resource('Diff:Title',escape=>1)]}</h3>);
1426      print qq($resource{diffnotice});      print qq(<p>@{[&Resource('Diff:Notice',escape=>1)]}</p>);
1427      print qq(<pre class="diff">);      print qq(<pre class="diff">);
1428      foreach (split(/\n/, $_)) {      foreach (split(/\n/, $_)) {
1429          if (/^\+(.*)/) {          if (/^\+(.*)/) {
1430              print qq(<b class="added">$1</b>\n);              print qq(<ins class="added">$1</ins>\n);
1431          } elsif (/^\-(.*)/) {          } elsif (/^\-(.*)/) {
1432              print qq(<s class="deleted">$1</s>\n);              print qq(<del class="deleted">$1</del>\n);
1433          } elsif (/^\=(.*)/) {          } elsif (/^\=(.*)/) {
1434              print qq(<span class="same">$1</span>\n);              print qq(<span class="same">$1</span>\n);
1435          } else {          } else {
# Line 1712  sub do_diff { Line 1437  sub do_diff {
1437          }          }
1438      }      }
1439      print qq(</pre>);      print qq(</pre>);
     print qq(<hr>);  
1440      &print_footer($title);      &print_footer($title);
1441  }  }
1442    
1443  sub do_rss {  sub do_rss {
1444        eval q{use Yuki::RSS};
1445      my $rss = new Yuki::RSS(      my $rss = new Yuki::RSS(
1446          version => '1.0',          version => '1.0',
1447          encoding => $charset,          encoding => &get_charset_name ($kanjicode),
1448        );
1449        my $scheme = 'http';
1450        $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
1451        my $myuri = "$scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi";
1452        $rss->stylesheet (
1453          href      => $myuri . "?mycmd=TEXT_CSS;mypage=WikiStyle:RSS",
1454          type      => 'text/css',
1455      );      );
1456      $rss->channel(      $rss->channel(
1457          title => $modifier_rss_title,          title   => &Resource ('RSS:WikiTitle'),
1458          link  => $modifier_rss_link,          link    => $myuri,
1459          description => $modifier_rss_description,          description     => &Resource ('RSS:WikiDescription'),
1460            'dc:language'   => $lang,
1461      );      );
1462      my $recentchanges = $database{$RecentChanges};      my $recentchanges = $database{RecentChanges};
1463      my $count = 0;      my $count = 0;
1464      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1465          last if ($count >= 15);          last if ($count >= 15);
1466          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/;    # date format.          if (/\[\[([^]]+)\]\]/) {
1467          my $title = &unarmor_name($1);            my $title = $1;
1468          my $escaped_title = &escape($title);            $rss->add_item (
1469          my $link = $modifier_rss_link . '?' . &encode($title);              title       => &escape($title),
1470          my $description = $escaped_title . &escape(&get_subjectline($title));              link        => $myuri . '?' . &encode($title),
1471          $rss->add_item(              description => &escape(&get_subjectline($title,delimiter=>'')),
1472              title => $escaped_title,              'dc:date'   => &get_info ($title, $info_LastModified),
1473              link  => $link,            );
1474              description => $description,            $count++;
1475          );          }
         $count++;  
1476      }      }
1477      # print RSS information (as XML).      # print RSS information (as XML).
 print scalar &make_navigate_links ('RssPage');  
1478      print <<"EOD"      print <<"EOD"
1479  Content-type: application/xml  Content-type: application/xml; charset=@{[&get_charset_name ($kanjicode)]}
1480    
1481  @{[$rss->as_string]}  @{[$rss->as_string]}
1482  EOD  EOD
1483  }  }
1484    
1485    sub _rfc3339_date ($) {
1486      my @time = gmtime (shift);
1487      sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0];
1488    }
1489    
1490  sub is_exist_page {  sub is_exist_page {
1491      my ($name) = @_;      my ($name) = @_;
1492      if ($use_exists) {      if ($use_exists) {
# Line 1769  sub do_wikiplugininfo { Line 1505  sub do_wikiplugininfo {
1505      &print_footer (q(WikiPluginInfo));      &print_footer (q(WikiPluginInfo));
1506  }  }
1507    
1508    sub do_map {
1509        my $page = $form{mypage};
1510        &print_header ($page);
1511        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
1512        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
1513        my ($r, $c) = get_search_result ($form{mypage});
1514        my $rl = wiki::referer::list_html ($form{mypage});
1515        print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n";
1516        my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {},
1517          map_from_here => &Resource('Map:FromHere'),
1518          map_from_here_description => &Resource('Map:FromHereLong'));
1519        &wiki::map::make_list ($page, %option);
1520        print &wiki::map::list_to_html ($page, $option{weight_list}, %option);
1521        if ($c) {
1522          print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};
1523          print $r;
1524        }
1525        if ($rl) {
1526          print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);
1527        }
1528        &print_footer ($page);
1529    }
1530    
1531    my %_Resource;
1532    sub Resource ($;%) {
1533      my ($s, %o) = @_;
1534      unless (defined $_Resource{$s}) {
1535        $_Resource{$_[0]} = &wiki::resource::get ($s, $_Resource{__option});
1536      }
1537      $o{escape} ? &escape ($_Resource{$s}) : $_Resource{$s};
1538    }
1539    
1540  package wiki::referer;  package wiki::referer;
1541  sub add ($$) {  sub add ($$) {
1542    my $page = shift;    my $page = shift;
# Line 1871  sub add ($) { Line 1639  sub add ($) {
1639    &main::__set_database ('WikiUserAgentList' => $s);    &main::__set_database ('WikiUserAgentList' => $s);
1640  }  }
1641    
1642    package wiki::suikawikiconst;
1643    
1644    sub to_hash ($;$) {
1645      my $page = shift;
1646      my $h = shift || {};
1647      my $val;
1648      for my $line (split /\n/, $page) {
1649        $line =~ tr/\x0A\x0D//d;
1650        if ($val && $line =~ s/^\s+//) {
1651          $h->{$val} .= length $h->{$val} ? "\n" . $line : $line;
1652        } elsif ($line =~ /^(.+):/) {
1653          $val = $1; $h->{$val} = '';
1654        }
1655      }
1656      $h;
1657    }
1658    
1659  package SuikaWiki::Plugin;  package SuikaWiki::Plugin;
1660    our $plugin_directory;  # defined in top of this file.    our $plugin_directory;  # defined in top of this file.
1661    our %List;    our %List;
# Line 1930  EOH Line 1715  EOH
1715    
1716  &import_plugins ();  &import_plugins ();
1717    
1718    package wiki::conneg;
1719    
1720    ## BUG: this parser isn't strict.
1721    sub get_accept_lang (;$) {
1722      my $alang = shift || $main::ENV{HTTP_ACCEPT_LANGUAGE};
1723      my %alang = (ja => 0.0002, en => 0.0001);
1724      my $i = 0.1;
1725      for (split /\s*,\s*/, $alang) {
1726        tr/\x09\x0A\x0D\x20//d;
1727        if (/((?:(?!;q=).)+)(?:;q="?([0-9.]+)"?)?/) {
1728          my $l = lc $1; $l =~ tr/\x22\x5C//d;
1729          $alang{$l} = (defined $2 ? $2 : 1.000)*1000;
1730          $alang{$l} += $i unless $alang{$l} == 0;
1731          $i -= 0.001;
1732        }
1733      }
1734      \%alang;
1735    }
1736    
1737    package wiki::resource;
1738    
1739    sub get ($;\%) {
1740      my ($resname, $option) = @_;
1741      $option->{accept_language} ||= &wiki::conneg::get_accept_lang ();
1742      $option->{resource} ||= {};
1743      my $v;
1744      for my $lang (sort {$option->{accept_language}->{$b} <=> $option->{accept_language}->{$a}} grep {$option->{accept_language}->{$_}!=0} keys %{$option->{accept_language}}) {
1745        while (length $lang) {
1746          unless ($option->{accept_language}->{defined $option->{accept_language}->{$lang} ? $lang : '*'} == 0) {
1747            $option->{resource}->{$lang} ||= &wiki::suikawikiconst::to_hash (&main::__get_database('WikiResource:'.$lang));
1748            $v = $option->{resource}->{$lang}->{$resname};
1749            last if defined $v;
1750          }
1751          $lang =~ s/[^+-]*$//; $lang =~ s/[+-]$//;
1752        }
1753        last if defined $v;
1754      }
1755      defined $v ? $v : $resname;
1756    }
1757    
1758    package wiki::map;
1759    
1760    sub make_list ($;%) {
1761      my ($page, %option) = @_;
1762      $option{level} ||= 3;
1763      my %weight;
1764      my $content = &main::__get_database ($page);
1765      $content =~ s{^\#\?([^\x0A\x0D]+)}{
1766        if ($1 =~ /import="([^"]+)"/) {
1767          for (split /\s*,\s*/, $1) {
1768            $weight{$_} += 2;
1769          }
1770        }
1771        $&;
1772      }ges;
1773      ## Bug: this code does not support content type.
1774      $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{
1775        $weight{$1}++; $&;
1776      }ge;
1777      delete $weight{$page};        ## Delete myself
1778      for my $page (keys %weight) {
1779        my $w = ($content =~ s/\Q$page\E/$&/g);
1780        $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.
1781        ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page);
1782      }
1783      $option{weight_list}->{$page} = \%weight;
1784      if (--$option{level}) {
1785        for my $page (keys %weight) {
1786          &make_list ($page, %option) unless $option{weight_list}->{$page};
1787        }
1788      }
1789      $option{weight_list};
1790    }
1791    
1792    sub list_to_html ($$;%) {
1793      my ($Page, $wlist, %option) = @_;
1794      my $r = '';
1795      $option{outputed}->{$Page} = 1;
1796      for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {
1797        $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>);
1798        unless ($option{outputed}->{$page}) {
1799          $r .= &list_to_html ($page, $wlist, %option);
1800        }
1801        $r .= "</li>\n";
1802      }
1803      $r ? qq(<ul class="map">$r</ul>) : '';
1804    }
1805    
1806  package main;  package main;
1807  &main;  &main;
1808  exit 0;  exit 0;
# Line 1939  __END__ Line 1812  __END__
1812  =head1 NAME  =head1 NAME
1813    
1814  wiki.cgi - This is YukiWiki, yet another Wiki clone.  wiki.cgi - This is YukiWiki, yet another Wiki clone.
1815    walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
1816    
1817  =head1 DESCRIPTION  =head1 DESCRIPTION
1818    

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.41

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24