/[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.20 by wakaba, Sun Jun 2 06:37:36 2002 UTC revision 1.38 by wakaba, Sun Dec 15 06:08:33 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #!perl  
2  #  #
3  # wiki.cgi - This is YukiWiki, yet another Wiki clone.  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
4  #  #
# Line 10  Line 9 
9  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
10  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
11  #  #
 ##############################  
 #  
12  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
 #  
 # WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。  
 #  
 # * 更新内容  
 #  
 # 2.0.beta1.wal.1 on 2002/05/19,22:32:19  
 # (1) Footerの変更  
 # (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない  
 # (3) 別名リンク([別名 URL])に対応。  
 # (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。  
 # (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成  
 # (6) HTMLモード対応。  
 #  
 # 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。  
 # ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。  
 #   - インラインの画像変換  
 #   - YukiWikiDB対応  
 #   - テーブル  
 #   - DB関連モジュールuseのeval化  
 #   - BracketNameによるキーからブラケットを排除  
 # ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。  
 #   [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。  
 #  
 #=======================================  
13    
14  # Walrus add (debug) start  # Walrus add (debug) start
15  my $walrus_log;  my $walrus_log;
# Line 53  use Yuki::DiffText qw(difftext); Line 26  use Yuki::DiffText qw(difftext);
26  use Yuki::YukiWikiDB;  use Yuki::YukiWikiDB;
27  use AnyDBM_File;  use AnyDBM_File;
28  require 'jcode.pl';  require 'jcode.pl';
29  # use Jcode;  require Jcode;
30  use Fcntl;  use Fcntl;
31  my $version = '2.0.beta1.2002-05-29';  my $version = '2.0.beta1.2002-05-29';
32  my $walversion;  my $walversion;
# Line 70  my $modifier_dbtype = 'YukiWikiDB'; Line 43  my $modifier_dbtype = 'YukiWikiDB';
43  # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.  # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.
44  my $modifier_sendmail = ''; # If you don't need mail notification.  my $modifier_sendmail = ''; # If you don't need mail notification.
45  my $modifier_dir_data = './wikidata'; # Your data directory.  my $modifier_dir_data = './wikidata'; # Your data directory.
46  my $modifier_rss_title = "WalWiki $walversion";  my $modifier_rss_title = "SuikaWiki $walversion";
47  my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.  my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.
48  my $modifier_rss_description = 'This is WalWiki, yet another Wiki clone based on YukiWiki';  my $modifier_rss_description = 'This is SuikaWiki';
49  ##############################  ##############################
50  #  #
51  # You MAY modify following variables.  # You MAY modify following variables.
52  #  #
53    $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
54  my $file_touch = "$modifier_dir_data/touched.txt";  my $file_touch = "$modifier_dir_data/touched.txt";
55  my $file_resource = "$modifier_dir_data/resource.txt";  my $file_resource = "$modifier_dir_data/resource.txt";
56  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
57  my $file_conflict = "$modifier_dir_data/conflict.txt";  my $file_conflict = "$modifier_dir_data/conflict.txt";
58  my $file_format = "$modifier_dir_data/format.txt";  my $file_format = "$modifier_dir_data/format.txt";
59  my $url_cgi = 'wiki';  my $url_cgi = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'
60  my $url_stylesheet = 'wiki-style.css';  my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
61  my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';  my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';
62  my $maxrecent = 50;  my $maxrecent = 50;
63  my $cols = 80;  my $cols = 80;
# Line 110  my $SearchPage = 'SearchPage'; Line 84  my $SearchPage = 'SearchPage';
84  my $CreatePage = 'CreatePage';  my $CreatePage = 'CreatePage';
85  my $ErrorPage = 'ErrorPage';  my $ErrorPage = 'ErrorPage';
86  my $RssPage = 'RssPage';  my $RssPage = 'RssPage';
87    my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
88  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
89  ##############################  ##############################
 # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b';        # Walrus del (2)  
 my $wiki_name   = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b';        # Walrus add (2)  
90  my $bracket_name = '\[\[(\S+?)\]\]';  my $bracket_name = '\[\[(\S+?)\]\]';
91  my $embedded_name = '\[\[(#\S+?)\]\]';  my $embedded_name = '\[\[(#\S+?)\]\]';
92  my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  my %fmt;        ## formatter objects
 my $interwiki_name = '([^:]+):([^:].*)';  
93  ##############################  ##############################
94  my $embed_comment = '[[#comment]]';  my $embed_comment = '[[#comment]]';
95  my $embed_rcomment = '[[#rcomment]]';  my $embed_rcomment = '[[#rcomment]]';
96    my $embed_comment_Name_Prompt = '名前:';
97    my $DEFAULT_embed_comment_name = '名無しさん';
98  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)
99    my %embed_command = (
100            searched        => '^\[\[#searched:([^\]]+)\]\]$',
101        form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
102    );
103  ##############################  ##############################
104  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
105  my $info_IsFrozen = 'IsFrozen';  my $info_IsFrozen = 'IsFrozen';
# Line 140  my %fixedpage = ( Line 118  my %fixedpage = (
118      $AdminChangePassword => 1,      $AdminChangePassword => 1,
119      $CompletedSuccessfully => 1,      $CompletedSuccessfully => 1,
120      #$FrontPage => 1,      #$FrontPage => 1,
121        WikiUserAgentList => 1,
122        WikiPluginInfo    => 1,
123  );  );
124  my %form;  my %form;
125  my %database;  my %database;
# Line 155  my %page_command = ( Line 135  my %page_command = (
135      $RssPage => 'rss',      $RssPage => 'rss',
136      $AdminChangePassword => 'adminchangepasswordform',      $AdminChangePassword => 'adminchangepasswordform',
137      #$FrontPage => 'FrontPage',      #$FrontPage => 'FrontPage',
138        WikiPluginInfo       => 'x_WikiPluginInfo',
139  );  );
140  my %command_do = (  my %command_do = (
141      read => \&do_read,      read => \&do_read,
142        TEXT_CSS => \&do_output_css,
143      edit => \&do_edit,      edit => \&do_edit,
144      adminedit => \&do_adminedit,      adminedit => \&do_adminedit,
145      adminchangepasswordform => \&do_adminchangepasswordform,      adminchangepasswordform => \&do_adminchangepasswordform,
# Line 170  my %command_do = ( Line 152  my %command_do = (
152      createresult => \&do_createresult,      createresult => \&do_createresult,
153      FrontPage => \&do_FrontPage,      FrontPage => \&do_FrontPage,
154      comment => \&do_comment,      comment => \&do_comment,
155        RandomJump  => \&do_random_jump,
156      rss => \&do_rss,      rss => \&do_rss,
157      diff => \&do_diff,      diff => \&do_diff,
158      interwikibox => \&do_interwiki_box, # Walrus add (5)      interwikibox => \&do_interwiki_box, # Walrus add (5)
159        wikiform => \&do_wikiform,
160        x_WikiPluginInfo  => \&do_wikiplugininfo,
161  );  );
162  ##############################  ##############################
 my @ignore_html_page = ('FrontPage');        # Walrus add (6)  
 my @ignore_html_tags = ('a', 'br', 'img');   # Walrus add (6)  
163  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)
164  ##############################  ##############################
165  # &test_convert;  # &test_convert;
166  &main;  my $UA = '';  ## User agent name
 exit(0);  
167  ##############################  ##############################
168    
169  sub main {  sub main {
170        $UA = $main::ENV{HTTP_USER_AGENT};
171      &init_resource;      &init_resource;
172      &open_db;      &open_db;
173      &init_form;      &init_form;
# Line 198  sub main { Line 181  sub main {
181  }  }
182    
183  sub do_read {  sub do_read {
184      &print_header($form{mypage});    my $content = $database{$form{mypage}};
185      &print_content($database{$form{mypage}});    my $lm = &get_info($form{mypage}, $info_LastModified);
186      &print_footer($form{mypage});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
187      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
188      my ($r, $c) = get_search_result ($form{mypage});
189      my $rl = wiki::referer::list_html ($form{mypage});
190      my @toc;
191      push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;
192      push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl;
193        my $cf = 'SuikaWiki/0.9';
194        ## Should be support at least:
195        ## - 'SuikaWiki/0.9' CRLF
196        ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
197        ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
198        $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
199        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
200          &print_header ($form{mypage}, -last_modified => $lm,
201            -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
202          &print_content ($content, content_format => $cf, last_modified => $lm,
203            -toc => \@toc);
204          print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
205        } else {
206          &print_header($form{mypage}, -last_modified => $lm);
207          print "<pre>@{[&escape($content)]}</pre>";
208        }
209        if ($c) {
210          print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
211          print $r;
212        }
213        if ($rl) {
214          print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);
215        }
216      &print_footer($form{mypage}, $lm);
217    }
218    
219    sub do_output_css {
220      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
221      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
222      my $content = $database{$form{mypage}};
223      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
224        my $lm = &get_info($form{mypage}, $info_LastModified);
225          print scalar make_navigate_links ($form{mypage});
226        print "Content-Type: text/css; charset=$charset\n";
227        print "Last-Modified: $lm\n";
228        print "\n";
229        print $content;
230      } else {
231        print "Status: 406 Unsupported Media Type\n";
232        &print_header('WikiPageIsNotCSS', -noindex => 1);
233        &print_content($database{WikiPageIsNotCSS});
234        &print_footer('WikiPageIsNotCSS');
235      }
236    }
237    
238    sub id_and_name ($) {
239        my $name = shift;
240        if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
241          qq{id="$name"><a name="$name"></a};
242        } else {
243            qq{id="$name"};
244        }
245  }  }
246    
247  sub do_edit {  sub do_edit {
248      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
249      &print_header($page);      &print_header($page, -noindex => 1);
250      if (not &is_editable($page)) {      if (not &is_editable($page)) {
251          &print_message($resource{cantchange});          &print_message($resource{cantchange});
252      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
# Line 213  sub do_edit { Line 254  sub do_edit {
254      } else {      } else {
255          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
256      }      }
257        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
258        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
259        my ($r, $c) = get_search_result ($form{mypage});
260        my $rl = wiki::referer::list_html ($form{mypage});
261        if ($c) {
262          print q{<h2 id="wikipage-see-also">See also</h2>};
263          print $r;
264        }
265        if ($rl) {
266          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
267        }
268      &print_footer($page);      &print_footer($page);
269  }  }
270    
271  sub do_adminedit {  sub do_adminedit {
272      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
273      &print_header($page);      &print_header($page, -noindex => 1);
274      if (not &is_editable($page)) {      if (not &is_editable($page)) {
275          &print_message($resource{cantchange});          &print_message($resource{cantchange});
276      } else {      } else {
# Line 229  sub do_adminedit { Line 281  sub do_adminedit {
281  }  }
282    
283  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
284      &print_header($AdminChangePassword);      &print_header($AdminChangePassword, -noindex => 1);
285      &print_passwordform;      &print_passwordform;
286      &print_footer($AdminChangePassword);      &print_footer($AdminChangePassword);
287  }  }
# Line 256  EOD Line 308  EOD
308      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
309      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
310    
311      &print_header($CompletedSuccessfully);      &print_header($CompletedSuccessfully, -noindex => 1);
312      &print_message($resource{passwordchanged});      &print_message($resource{passwordchanged});
313      &print_footer($CompletedSuccessfully);      &print_footer($CompletedSuccessfully);
314  }  }
315    
316  sub do_index {  sub do_index {
317      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
318      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
319      &print_header($IndexPage);      &print_header($IndexPage);
320      print qq(<ul>);      print qq(<ul>);
321      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
322          if (&is_editable($page)) {          if (&is_editable($page)) {
323              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">$page</a>@{[&escape(&get_subjectline($page))]}</li>);              print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
324              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
325              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
326          }          }
327      }      }
328      print qq(</ul>);      print qq(</ul>);
329        my ($r, $c) = get_search_result ($form{mypage});
330        if ($c) {
331          print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
332          print $r;
333        }
334        my $rl = wiki::referer::list_html ($form{mypage});
335        if ($rl) {
336            print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>??????</h2>\n$rl</div>\n);
337        }
338      &print_footer($IndexPage);      &print_footer($IndexPage);
339  }  }
340    
# Line 281  sub do_write { Line 344  sub do_write {
344      }      }
345    
346      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
347          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
348          &print_message($resource{cantchange});          &print_message($resource{cantchange});
349          &print_footer($form{mypage});          &print_footer($form{mypage});
350          return;          return;
# Line 308  sub do_write { Line 371  sub do_write {
371              &update_recent_changes;              &update_recent_changes;
372          }          }
373          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
374          &print_header($CompletedSuccessfully);          my $fragment = '';
375            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
376            if ($form{__comment_anchor_index}) {
377                $fragment .= qq(#anchor-$form{__comment_anchor_index});
378            } elsif ($form{__wikiform_anchor_index}) {
379                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
380            }
381            &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));
382          &print_message($resource{saved});          &print_message($resource{saved});
383          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
384          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 319  sub do_write { Line 389  sub do_write {
389          if ($form{mytouch}) {          if ($form{mytouch}) {
390              &update_recent_changes;              &update_recent_changes;
391          }          }
392          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
393          &print_message($resource{deleted});          &print_message($resource{deleted});
394          &print_footer($form{mypage});          &print_footer($form{mypage});
395      }      }
# Line 332  sub do_searchform { Line 402  sub do_searchform {
402  }  }
403    
404  sub do_search {  sub do_search {
405      my $word = &escape($form{mymsg});      my $word = $form{mymsg};
406      &print_header($SearchPage);      &print_header($SearchPage);
407      &print_searchform($word);      &print_searchform(&escape($word));
408      my $counter = 0;      print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);
     foreach my $page (sort keys %database) {  
         next if $page =~ /^$RecentChanges$/;  
         if ($database{$page} =~ /\Q$form{mymsg}\E/ or $page =~ /\Q$form{mymsg}\E/) {  
             if ($counter == 0) {  
                 print qq|<ul>|;  
             }  
             print qq(<li><a href ="$url_cgi?@{[&encode($page)]}">$page</a>@{[&escape(&get_subjectline($page))]}</li>);  
             $counter++;  
         }  
     }  
     if ($counter == 0) {  
         &print_message($resource{notfound});  
     } else {  
         print qq|</ul>|;  
     }  
409      &print_footer($SearchPage);      &print_footer($SearchPage);
410  }  }
411    
412    sub get_search_result ($;%) {
413      my $word = lc shift;
414      my %option = @_;
415      my @r;
416      foreach my $page (keys %database) {
417        next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
418        my $content = $database{$page};
419        my $cf = 'SuikaWiki/0.9';
420        $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
421        next if $cf =~ /obsoleted="yes"/;
422        if (index (lc $page, $word) > -1) {
423          my $c = $content =~ s/\Q$word\E//gi;
424          push @r, [$page, $c+20];
425        } elsif (index ($word, lc $page) > -1) {
426          my $c = $content =~ s/\Q$word\E//gi;
427          push @r, [$page, $c+10];
428        } elsif (my $c = $content =~ s/\Q$word\E//gi) {
429          push @r, [$page, $c];
430        }
431      }
432      my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
433      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;
434      $r = qq|<ul class="search-result">$r</ul>| if $r;
435      get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
436      wantarray? ($r, scalar @r): $r;
437    }
438    
439  sub do_create {  sub do_create {
440      &print_header($CreatePage);      &print_header($CreatePage);
441      print <<"EOD";      print <<"EOD";
# Line 367  EOD Line 449  EOD
449      &print_footer($CreatePage);      &print_footer($CreatePage);
450  }  }
451    
452    sub do_random_jump {
453      my @list = keys %database;
454      my $name = &encode ($list[rand @list]);
455      my ($scheme) = 'http';
456      $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
457      print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
458      print "\n";
459    }
460    
461  sub do_FrontPage {  sub do_FrontPage {
462      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
463      my $content = join('', <FILE>);      my $content = join('', <FILE>);
# Line 379  sub do_FrontPage { Line 470  sub do_FrontPage {
470    
471  sub print_error {  sub print_error {
472      my ($msg) = @_;      my ($msg) = @_;
473      &print_header($ErrorPage);      &print_header($ErrorPage, -noindex => 1);
474      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
475      &print_footer($ErrorPage);      &print_footer($ErrorPage);
476      exit(0);      exit(0);
477  }  }
478    
479  sub print_header {  sub print_header ($;%) {
480      my ($page) = @_;      my ($page, %option) = @_;
481      my $bodyclass = "normal";      my $bodyclass = "normal";
     my $editable = 0;  
     my $admineditable = 0;  
482      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
         $editable = 0;  
         $admineditable = 1;  
483          $bodyclass = "frozen";          $bodyclass = "frozen";
484      } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {      }
485          $admineditable = 1;      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
486          $editable = 1;      if ($option{-goto}) {
487          if ($UA =~ m#Opera|MSIE 2\.#) {
488              $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
489              print qq{Refresh: 0; url=$option{-goto}\n};
490              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
491          } else {
492              $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
493              print qq{Refresh: 0; url="$option{-goto}"\n};
494              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
495          }
496        }
497        print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
498        my $meta_ct = '';
499        if ($UA =~ m#Mozilla/2#) {
500            $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
501            print qq{Content-Type: $meta_ct\n};
502            $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
503        } elsif ($UA =~ m#Infomosaic#) {
504            print qq{Content-Type: text/html\n};
505      } else {      } else {
506          $editable = 0;          print qq{Content-Type: text/html; charset=$charset\n};
507      }      }
508      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
509        my $escapedpage = &escape($page);
510        my ($Links, $links) = &make_navigate_links ($page);
511        print $Links;
512      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
513  Content-Language: $lang  Content-Language: $lang
514  Content-Style-Type: text/css  Content-Style-Type: text/css
515    
516    <!--
517  <!DOCTYPE html  <!DOCTYPE html
518      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
519      "http://www.w3.org/TR/html4/loose.dtd">      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
520  <html lang="$lang">  <html lang="$lang">
521  <head>  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
522      <title>$page @{[&escape(&get_subjectline($page))]}</title>      $meta_ct$option{-goto}
523      <link rel="index" href="$url_cgi?$IndexPage">      <title>$escapedpage</title>
524      <link rev="made" href="mailto:$modifier_mail">      @{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']}
525      <link rel="stylesheet" type="text/css" href="$url_stylesheet">      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
526    $links
527  </head>  </head>
528  <body class="$bodyclass">  <body class="$bodyclass">
529    EOD
530      &print_navigate_links ($page);
531      print <<EOD;
532    <h1 class="header">@{[&escape($page)]}</h1>
533    EOD
534    }
535    
536    sub x_charset ($) {
537        my $charset = lc shift;
538        if ($charset eq 'euc-jp') {
539            $charset = 'x-euc-jp';
540        } elsif ($charset eq 'shift_jis') {
541            $charset = 'x-sjis';
542        }
543        $charset;
544    }
545    
546    sub print_navigate_links (@) {
547      my ($page) = @_;
548        my $editable = 0;
549        my $admineditable = 0;
550        if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
551            $editable = 0;
552            #$admineditable = 1;
553        } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
554            #$admineditable = 1;
555            $editable = 1;
556        } else {
557            $editable = 0;
558        }
559        my $cookedpage = &encode($page);
560      print <<EOH;
561  <div class="tools">  <div class="tools">
562      @{[ $admineditable      @{[ $admineditable
563          ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )          ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage" class="wiki-cmd">$resource{admineditbutton}</a> | )
564          : qq()          : qq()
565      ]}      ]}
566      @{[ $editable      @{[ $editable
567          ? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage">$resource{editbutton}</a> | )          ? #qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )
568            qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E" class="wiki-cmd">編集</a> | )
569          : qq()          : qq()
570      ]}      ]}
571        <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki-cmd">表示</a> |
572      @{[ $admineditable      @{[ $admineditable
573          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage" class="wiki-cmd">$resource{diffbutton}</a> | )
574          : qq()          : qq()
575      ]}      ]}
576      <a href="$url_cgi?$CreatePage">$resource{createbutton}</a> |      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |
577      <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
578      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |
579      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
580      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |
581      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
582  </div>  </div>
583  <h1 class="header"><a  EOH
584      title="$resource{searchthispage}"  }
585      href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1>  
586  EOD  sub make_navigate_links ($) {
587        my $page = shift;
588        my @link;
589        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);
590        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);
591        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'};
592        push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};
593        push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};
594        push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};
595        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};
596        push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};
597        push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};
598        push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};
599        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};
600        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};
601        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...'};
602        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)...'};
603        push @link, {rel=>'lucky', href=>"$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}", class=>'wiki randomlink', title=>'Somewhere'};
604        my ($Links, $links) = ('', '');
605        for my $e (@link) {
606            $links .= qq(<link);
607            $Links .= qq(Link: <$e->{href}>);
608            for my $attr (qw/rel rev href title class type hreflang charset/) {
609                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
610            }
611            for my $attr (qw/rel rev title/) {
612                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
613            }
614            $links .= qq(>\n);
615            $Links .= qq(\n);
616        }
617        wantarray ? ($Links, $links) : $Links;
618  }  }
619    
620  sub print_footer {  sub print_footer {
621      my ($page) = @_;      my ($page, $lm) = @_;
622        my $epage = &encode ($page);
623      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)      $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : '';    # Walrus add (debug)
624      # Walrus mod (1) start      # Walrus mod (1) start
625  my $cvslog = '$Revision$ $Date$';    my $cvslog1 = q$Revision$;
626      print <<"EOD";    my $cvslog2 = q$Date$;
627      print_navigate_links ($page);
628      print <<"EOD";
629    @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
630  <div class="footer">  <div class="footer">
631  <p>  <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>
632  <a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />  <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository of this script ($cvslog2)">SuikaWiki $cvslog1</a>
 based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository">  
 $cvslog  
 </a>  
 </p>  
633  <div class="navigation">  <div class="navigation">
634  [<a href="/" title="このサーバーの首頁">/</a>  [<a href="/" title="このサーバーの首頁">/</a>
635  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
636  <a href="/search/" title="このサーバーの検索">検索</a>]  <a href="/search/" title="このサーバーの検索">検索</a>]
637  </div>  </div>
638    <div class="myuri">
639        &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
640    </div>
641  </div>  </div>
642  $walrus_log  $walrus_log
643  </body>  </body>
644  </html>  </html>
645  EOD  EOD
 #       print <<"EOD";  
 #   <hr>  
 #   <address class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version  
 #       &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 #       Modified by <a href="$modifier_url">$modifier_name</a>.  
 #   </address>  
 #   <p class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">$icontag</a>  
 #   </p>  
 #   </body>  
 #   </html>  
 #   EOD  
     # Walrus mod (1) end  
646  }  }
647    
648  sub escape {  sub escape {
649      my $s = shift;      my $s = shift;
650      $s =~ s|\r\n|\n|g;      $s =~ s|\r\n|\n|g;
651      $s =~ s|\&|&amp;|g;      $s =~ s|&|&amp;|g;
652      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
653      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
654      $s =~ s|"|&quot;|g;      $s =~ s|"|&quot;|g;
# Line 496  sub escape { Line 658  sub escape {
658  sub unescape {  sub unescape {
659      my $s = shift;      my $s = shift;
660      # $s =~ s|\n|\r\n|g;      # $s =~ s|\n|\r\n|g;
661      $s =~ s|\&amp;|\&|g;      $s =~ s|&lt;|<|g;
662      $s =~ s|\&lt;|\<|g;      $s =~ s|&gt;|>|g;
663      $s =~ s|\&gt;|\>|g;      $s =~ s|&quot;|"|g;
664      $s =~ s|\&quot;|\"|g;      $s =~ s|&amp;|&|g;
665      return $s;      return $s;
666  }  }
667    
668  sub print_content {  sub print_content ($;$) {
669      my ($rawcontent) = @_;      my ($rawcontent, %option) = @_;
670      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
671  }  }
672    
673  sub text_to_html {  sub text_to_html {
674      my ($txt, %option) = @_;      my ($txt, %option) = @_;
675      my (@txt) = split(/\n/, $txt);      my (@txt) = split(/\n/, $txt);
676      my (@toc);      my @toc;
677        my @toc2 = @{$option{-toc}||[]};
678      my $tocnum = 0;      my $tocnum = 0;
679      my (@saved, @result);      my (@saved, @result);
680      unshift(@saved, "</p>");      unshift(@saved, "</p>");
681      push(@result, "<p>");      push(@result, "<p>");
682      foreach (@txt) {      foreach (@txt) {
683          chomp;          chomp;
684          # Walrus mod (6) start          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
685          #if ($saved[0] eq '</html>') {              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
686          #    if (/<\/html>/i) { splice(@saved); }              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>');
         #    else { push (@result, &html_to_ignored_html($_)); }  
         #} elsif (/^<html>/i and &is_ignore_html($form{mypage})) {  
         #    push(@result, splice(@saved));  
         #    push(@saved, '</html>');  
         #} els  
         if (/^\*\*\*\*\*(.*)/) {  
             push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));  
             push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');  
687              $tocnum++;              $tocnum++;
688          } elsif (/^\*\*\*\*(.*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
689              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
690              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>');
691              $tocnum++;              $tocnum++;
692          } elsif (/^\*\*\*(.*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
693              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
694              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>');
695              $tocnum++;              $tocnum++;
696          } elsif (/^\*\*(.*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
697          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
698          # Walrus mod (6) end          # Walrus mod (6) end
699              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
700              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>');
701              $tocnum++;              $tocnum++;
702          } elsif (/^\*(.*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
703              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
704              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>');
705              $tocnum++;              $tocnum++;
706          #} elsif (/^----/) {          } elsif (/^(={1,6})(.*)/) {
         #    push(@result, splice(@saved), '<hr>');  
         } elsif (/^(={1,5})(.*)/) {  
707              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
708              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
709          } elsif (/^(-{1,5})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
710              &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
711              push(@result, '<li>' . &inline($2) . '</li>');            my ($pf, $l) = ('', $2);
712              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
713                my $num = 0+$1;
714                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
715              }
716              push(@result, '<li>' . $pf . &inline ($l) . '</li>');
717          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
718              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
719              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
720          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
721              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
722                push @result, "<p>";
723              push(@result, &inline($2));              push(@result, &inline($2));
724                unshift @saved, "</p>";
725          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
726              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
727              push(@result, "<p>");              push(@result, "<p>");
728                unshift(@saved, "</p>");
729          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
730              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
731              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
732              push(@result, &inline($1)); # Not &inline, but &escape              push(@result, &inline($1));
733  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
734          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
735              &back_push('table', 1, \@saved, \@result, ' border="1"');              &back_push('table', 1, \@saved, \@result, ' border="1"');
# Line 594  sub text_to_html { Line 754  sub text_to_html {
754              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
755              # XXXXX              # XXXXX
756              #######              #######
757            } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
758                push @result, splice (@saved), '<'.lc($1).'>';
759                unshift @saved, "</p>";
760                push @result, "<p>";
761            } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
762                push @result, splice (@saved), '</'.lc($1).'>';
763            } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
764              my $num = 0+$1;
765              push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
766              push @result, &inline ($2);
767          } else {          } else {
768              push(@result, &inline($_));              push(@result, &inline($_));
769          }          }
770      }      }
771      push(@result, splice(@saved));      push(@result, splice(@saved));
772        
773        my $toc = '';
774      if ($option{toc}) {      if ($option{toc}) {
775          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
776          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
777          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
778          foreach (@toc) {          foreach (@toc,@toc2) {
779              if (/^(-{1,3})(.*)/) {              if (/^(-{1,6})(.*)$/) {
780                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
781                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
782              }              }
783          }          }
784          push(@tocresult, splice(@tocsaved));          push(@tocresult, splice(@tocsaved));
785          return join("\n", @tocresult, @result);          $toc = join("\n", @tocresult);
786      } else {          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
         return join("\n", @result);  
787      }      }
788        $toc .= join("\n", @result);
789        $toc =~ s#<p>\n</p>##g;
790        $toc =~ s#[\x0D\x0A]+</#</#g;
791        $toc =~ s#<pre>\n#<pre>#g;
792        $toc;
793  }  }
794    
795  sub back_push {  sub back_push {
# Line 634  sub back_push { Line 809  sub back_push {
809  sub inline {  sub inline {
810      my ($line) = @_;      my ($line) = @_;
811      $line = &escape($line);      $line = &escape($line);
812      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
813      $line =~ s|''([^']+?)''|<em>$1</em>|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;
814      $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g;   # Date      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
815      $line =~ s!      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
816        (      $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g;
817          (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
818        |      $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g;
819          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
820        |      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
821          ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]      $line =~ s|''([^']+)''|<em>$1</em>|g;
822        #|      $line =~ s{
823        #  ($wiki_name)        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]
824        )        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]
825              !        |&gt;&gt;([0-9]+)
826                  &make_link($1)        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
827              !gex;      }{
828          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
829          if ($l) {
830            &make_link($l)
831          } elsif (defined $page) {
832            &make_wikilink ($page, anchor => 0+$anchor);
833          } elsif ($anum) {
834            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
835          } elsif ($uri) {
836            &make_urilink ($uri);
837          }
838        }gex;
839      return $line;      return $line;
840  }  }
841    
842    sub make_wikilink ($%) {
843      my ($ename, %option) = @_;
844      my $name = &unescape ($ename);
845      if ($database{$name}) {
846        my $subject = &escape (&get_subjectline ($name, delimiter => ''));
847        if ($option{anchor}) {
848          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
849        } else {
850          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
851        }
852      } else {
853        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>);
854      }
855    }
856    
857    sub make_urilink ($;%) {
858      require URI;
859      my $uri = shift;
860      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
861        $uri = &unescape ($uri);
862        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
863          my ($site, $name) = ($1, $2);
864          for ($site, $name) {
865            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
866          }
867          if ($interwiki{$site}) {
868            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
869            $site = &escape ($site); $name = &escape ($name);
870            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;);
871          } else {
872            qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
873          }
874        } else {
875          qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
876        }
877      } elsif ($uri =~ /^urn:/) {   ## URN
878        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
879        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
880      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
881        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
882        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
883      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
884        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
885        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
886      } else {      ## misc. URI
887        CGI::Carp::warningsToBrowser (0);
888        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
889        CGI::Carp::warningsToBrowser (1);
890        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
891      }
892    }
893    
894    my $FormIndex = 0;
895    sub make_custom_form ($$$$) {
896        my ($wfname, $definition, $template, $option) = @_;
897        ## $template and $option is currently not used in this procedure.
898        unless ($main::_EMBEDED) {
899            $FormIndex++;
900            if (length $definition) {
901                my $param = bless {}, 'SuikaWiki::Plugin';
902                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
903                &load_formatter (qw/form_input form_option/);
904                $definition = &unescape ($definition);
905                $definition =~ s/\\(.)/$1/g;
906                $definition .= ' %submit;' if $definition !~ /%submit/;
907                $option = &unescape ($option);
908                $option =~ s/\\(.)/$1/g;
909                $fmt{form_option}->replace ($option, $param);
910                my $target_page = $param->{output}->{page} || $form{mypage};
911                $param->{form_disabled} = 1 if $fixedpage{$target_page};
912                my $target_form = $param->{output}->{id};
913                my $r = <<EOH;
914    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
915      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
916      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
917      <input type="hidden" name="myLastModified" value="$lastmodified">
918      <input type="hidden" name="mytouch" value="on">
919      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
920    EOH
921                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
922                $r .= $fmt{form_input}->replace ($definition, $param);
923                $r .= <<EOH;
924    </form>
925    EOH
926                $r;
927           } else {  ## No input-interface WikiForm
928               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
929           }
930        } else {
931            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
932        }
933    }
934    
935    ## to be obsoleted
936  sub make_link {  sub make_link {
937      my $chunk = shift;      my $chunk = shift;
938      # Walrus add (3) start      # Walrus add (3) start
939        $chunk =~ s/^&lt;(.*)&gt;$/$1/;
940      my $name  = $chunk;      my $name  = $chunk;
     $name =~ s/^&lt;(.*)&gt;$/$1/;  
     if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {  
         ($name, $chunk) = ($1, $2);  
     } elsif ($chunk =~ /^mailto:(.*)$/) {  
         $name = $1;  
     }  
     if ($use_autoimg and $name =~ /^(http|https|ftp|):.+\.(png|gif|jpe?g)/) {  
         $name = qq(<img src="$name">) ;  
     }  
941      $name = &unarmor_name($name);      $name = &unarmor_name($name);
942      # Walrus add (3) end      # Walrus add (3) end
943      if ($chunk =~ /^(http|https|ftp):/) {      if ($chunk =~ /^$embedded_name$/) {
         # Walrus mod (3) start  
 #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  
 #           return qq(<a href="$chunk"><img src="$chunk"></a>);  
 #       } else {  
 #           return qq(<a href="$chunk">$chunk</a>);  
 #       }  
         return qq(<a href="$chunk">$name</a>);  
         # Walrus mod (3) end  
     } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {  
         return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;  
     } elsif ($chunk =~ /^mailto:(.*)/) {  
 #       return qq(<a href="$chunk">$2</a>);                 # Walrus del (3)  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);              # Walrus add (3)  
     } elsif ($chunk =~ /^$interwiki_definition$/) {  
 #       return qq(<span class="InterWiki">$chunk</span>);   # Walrus del (3)  
         return qq(<span class="InterWiki">$name</span>);    # Walrus add (3)  
     } elsif ($chunk =~ /^$embedded_name$/) {  
944          return &embedded_to_html($chunk);          return &embedded_to_html($chunk);
945      } else {      } else {
946          $chunk = &unarmor_name($chunk);          $chunk = &unarmor_name($chunk);
947          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
948          my $cookedchunk = &encode($chunk);          my $cookedchunk = &encode($chunk);
949          if ($chunk =~ /^$interwiki_name$/) {          if ($database{$chunk}) {
             my ($intername, $localname) = ($1, $2);  
             my $remoteurl = $interwiki{$intername};  
             if ($remoteurl) {  
 #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)  
                 $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)  
 #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  
                 return qq(<a href="$remoteurl">$name</a>);  # Walrus add (3)  
             } else {  
 #               return $chunk;                              # Walrus del (3)  
                 return $name;                               # Walrus add (3)  
             }  
         } elsif ($database{$chunk}) {  
950              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
951  #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)  #           return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>);  # Walrus del (3)
952              return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$name</a>);   # Walrus add (3)              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)
953          } elsif ($page_command{$chunk}) {          } elsif ($page_command{$chunk}) {
954  #           return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>);    # Walrus del (3)  #           return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>);    # Walrus del (3)
955              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">$name</a>);     # Walrus add (3)              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)
956          } else {          } else {
957              return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">$name<span class="mark">$editchar</span></a>);              return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
958          }          }
959      }      }
960  }  }
961    
 # Walrus add (6) start  
 sub is_ignore_html {  
     my ($pagename) = @_;  
     foreach (@ignore_html_page) {  
         return 1 if ($pagename eq $_);  
     }  
     return 0;  
 }  
 # Walrus add (6) end  
   
 # Walrus add (6) start  
 sub html_to_ignored_html {  
     my $str = shift(@_);  
     my $text_regex        = q{[^<]*};  
     my $tag_regex_        = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}}  
     my $comment_tag_regex = '<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)';  
     my $tag_regex         = qq{$comment_tag_regex|<$tag_regex_};  
     my $ignored           = join('|', @ignore_html_tags);  
     my $result = '';  
     while ($str =~ /($text_regex)($tag_regex)?/gso) {  
       last if $1 eq '' and $2 eq '';  
       $result .= $1;  
       my $tag_tmp = $2;  
       $result .= ($tag_tmp =~ /^<\/?($ignored)(?![0-9A-Za-z])/i) ? $tag_tmp : &escape($tag_tmp);  
       if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) {  
         $str =~ /(.*?)(?:<\/$1(?![0-9A-Za-z])$tag_regex_|$)/gsi;  
         $result .= &escape($1);  
       }  
     }  
     return $result;  
 }  
 # Walrus add (6) end  
   
962  sub print_message {  sub print_message {
963      my ($msg) = @_;      my ($msg) = @_;
964      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>$msg</strong></p>);
965  }  }
966    
967    sub get_message {
968        my ($msg) = @_;
969        qq(<p><strong>$msg</strong></p>);
970    }
971    
972  sub init_form {  sub init_form {
973      if (param()) {      if (param()) {
974          foreach my $var (param()) {          foreach my $var (param()) {
975              $form{$var} = param($var);              $form{$var} = param($var);
976          }        }
     } else {  
         $ENV{QUERY_STRING} = $FrontPage;  
977      }      }
978        $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
979      my $query = &decode($ENV{QUERY_STRING});      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
980      if ($page_command{$query}) {        my $query = &decode($main::ENV{QUERY_STRING});
981          $query = &code_convert(\$query, $kanjicode);
982          if ($page_command{$query}) {
983          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
984          $form{mypage} = $query;          $form{mypage} = $query;
985      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
986          $form{mypage} = $query;          $form{mypage} = $query;
987            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
988          }
989      }      }
990        $form{mypage} ||= 'HomePage';
991        $form{mycmd} ||= 'read';
992    
993      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
994      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 785  sub init_form { Line 1000  sub init_form {
1000          }          }
1001      }      }
1002    
1003      #      #
1004      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
1005      #      #
1006    
1007        for (grep /^wikiform__/, keys %form) {
1008            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
1009        }
1010      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
1011      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
1012  }  }
1013    
1014  sub update_recent_changes {  sub update_recent_changes {
1015      my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
1016      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
1017        shift (@oldupdates); ## '#?' magic line
1018      my @updates;      my @updates;
1019      foreach (@oldupdates) {      foreach (@oldupdates) {
1020          /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/;    # date format.          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;
1021          my $name = &unarmor_name($1);          my $name = $1;
1022          if (&is_exist_page($name) and ($name ne $form{mypage})) {          if ($name ne $form{mypage}) {
1023              push(@updates, $_);              push @updates, $_;
1024          }          }
1025      }      }
1026      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
1027          unshift(@updates, $update);        unshift @updates, $update;
1028      }      }
1029      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
1030      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
1031      if ($file_touch) {      if ($file_touch) {
1032          open(FILE, "> $file_touch");          open(FILE, "> $file_touch");
1033          print FILE localtime() . "\n";          print FILE localtime() . "\n";
# Line 829  sub get_subjectline { Line 1048  sub get_subjectline {
1048    
1049          # Get the subject of the page.          # Get the subject of the page.
1050          my $subject = $database{$page};          my $subject = $database{$page};
1051            $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
1052          $subject =~ s/\r?\n.*//s;          $subject =~ s/\r?\n.*//s;
1053          return "$delim$subject";          return "$delim$subject".$option{tail};
1054      }      }
1055  }  }
1056    
# Line 911  sub print_searchform { Line 1131  sub print_searchform {
1131      my ($word) = @_;      my ($word) = @_;
1132      print <<"EOD";      print <<"EOD";
1133  <form action="$url_cgi" method="get">  <form action="$url_cgi" method="get">
1134      <input type="hidden" name="mycmd" value="search">      <input type="hidden" name="mycmd" value="read">
1135      <input type="text" name="mymsg" value="$word" size="20">      <input type="text" name="mypage" value="$word" size="20">
1136      <input type="submit" value="$resource{searchbutton}">      <input type="submit" value="$resource{searchbutton}">
1137  </form>  </form>
1138  EOD  EOD
# Line 936  sub print_editform { Line 1156  sub print_editform {
1156          }          }
1157          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
1158      } else {      } else {
1159          $mymsg = &escape($mymsg);          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1160      }      }
1161        my $magic = '';
1162        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
1163    
1164      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1165        my $escapedmypage = &escape($form{mypage});
1166        my $escapedmypassword = &escape($form{mypassword});
1167        my $selected = 'read';
1168        if ($form{after_edit_cmd}) {
1169            $selected = $form{after_edit_cmd};
1170        } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {
1171            $selected = 'edit';
1172        }
1173        my $afteredit = <<EOH;
1174    <select name="after_edit_cmd">
1175    <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>
1176    <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>
1177    </select>
1178    EOH
1179    
1180      print <<"EOD";      print <<"EOD";
1181  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1182      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$form{mypassword}" size="10"><br>) : "" ]}  <h2>$escapedmypageの編集</h2>
1183        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}
1184        @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;
1185                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1186                   ++$n}]}]<br>
1187      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1188      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$escapedmypage">
1189      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="off">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1190  @{[  @{[
1191      $mode{admin} ?      $mode{admin} ?
1192      qq(      qq(
# Line 959  sub print_editform { Line 1199  sub print_editform {
1199      qq(      qq(
1200          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1201          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1202          <input type="submit" name="mypreview_write" value="$resource{savebutton}"><br>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1203           $afteredit
1204           <br>
1205      )      )
1206  ]}  ]}
1207  </form>  </form>
1208  EOD  EOD
1209      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1210          # Show the format rule.          # Show the format rule.
1211          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{'WikiEditHelp'};
1212          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1213          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
1214          close(FILE);      #    open(FILE, $file_format) or &print_error("($file_format)");
1215          print &text_to_html($content, toc=>0);      #    my $content = join('', <FILE>);
1216        #    &code_convert(\$content, $kanjicode);
1217        #    close(FILE);
1218        #    print &text_to_html($content, toc=>0);
1219      }      }
1220  }  }
1221    
# Line 988  EOD Line 1233  EOD
1233    
1234  sub is_editable {  sub is_editable {
1235      my ($page) = @_;      my ($page) = @_;
1236      if (&is_bracket_name($page)) {      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
         return 0;  
     } elsif ($fixedpage{$page}) {  
         return 0;  
     } elsif ($page =~ /\s/) {  
         return 0;  
     } elsif ($page =~ /^\#/) {  
         return 0;  
     } elsif ($page =~ /^$interwiki_name$/) {  
1237          return 0;          return 0;
1238      } else {      } else {
1239          return 1;          return 1;
# Line 1006  sub is_editable { Line 1243  sub is_editable {
1243  # armor_name:  # armor_name:
1244  #   WikiName -> WikiName  #   WikiName -> WikiName
1245  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1246  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     if ($name =~ /^$wiki_name$/) {  
         return $name;  
     } else {  
         return "[[$name]]";  
     }  
 }  
1247    
1248  # unarmor_name:  # unarmor_name:
1249  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
# Line 1027  sub unarmor_name { Line 1257  sub unarmor_name {
1257      }      }
1258  }  }
1259    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1260  sub decode {  sub decode {
1261      my ($s) = @_;      my ($s) = @_;
1262      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1059  sub encode { Line 1280  sub encode {
1280  sub init_resource {  sub init_resource {
1281      open(FILE, $file_resource) or &print_error("(resource)");      open(FILE, $file_resource) or &print_error("(resource)");
1282      while (<FILE>) {      while (<FILE>) {
1283          chomp;          s/[\x0A\x0D]+$//g;
1284          next if /^#/;          next if /^#/;
1285          my ($key, $value) = split(/=/, $_, 2);          my ($key, $value) = split(/=/, $_, 2);
1286          $resource{$key} = &code_convert(\$value, $kanjicode);          $resource{$key} = &code_convert(\$value, $kanjicode);
# Line 1076  sub conflict { Line 1297  sub conflict {
1297      my $content = join('', <FILE>);      my $content = join('', <FILE>);
1298      &code_convert(\$content, $kanjicode);      &code_convert(\$content, $kanjicode);
1299      close(FILE);      close(FILE);
1300      &print_header($page);      &print_header($page, -noindex => 1);
1301      &print_content($content);      &print_content($content);
1302      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1303      &print_footer($page);      &print_footer($page);
# Line 1085  sub conflict { Line 1306  sub conflict {
1306    
1307  sub get_now {  sub get_now {
1308      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1309        my (@week) = qw(日 月 火 水 木 金 土);
1310      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1311      $year += 1900;      $year += 1900;
1312      $mon++;      $mon++;
# Line 1092  sub get_now { Line 1314  sub get_now {
1314      $day = "0$day" if $day < 10;      $day = "0$day" if $day < 10;
1315      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1316      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1317      $sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1318      $weekday = $week[$weekday];      $weekday = $week[$weekday];
1319      return "$year-$mon-$day ($weekday) $hour:$min:$sec";      return "$year-$mon-$day ($weekday) $hour:$min";
1320  }  }
1321    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1322  sub init_InterWikiName {  sub init_InterWikiName {
1323      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{$InterWikiName};
1324      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1325          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1326          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1327      }      }
1328      }
1329      require Message::Util::Formatter;
1330      $fmt{interwiki} = Message::Util::Formatter->new;
1331      $fmt{interwiki}->{encoded} = sub {
1332        my ($o, $p) = @_;
1333        if ($o->{except}) {
1334          $o->{except} =~ tr/\x00-\x20\x22%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1335        }
1336        my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1337        $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1338        $s;
1339      };
1340      $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
1341        my ($o, $p) = @_;
1342        my $s = $p->{name};
1343        $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1344        &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1345      };
1346  }  }
1347    
 sub interwiki_convert {  
     my ($type, $localname) = @_;  
     if ($type eq 'sjis' or $type eq 'euc') {  
         &code_convert(\$localname, $type);  
         return &encode($localname);  
     } elsif ($type eq 'ykwk') {  
         # for YukiWiki1  
         if ($localname =~ /^$wiki_name$/) {  
             return $localname;  
         } else {  
             &code_convert(\$localname, 'sjis');  
             return &encode("[[" . $localname . "]]");  
         }  
     } elsif ($type eq 'asis') {  
         return $localname;  
     # Walrus add (4) start  
     } elsif ($type eq 'isbn') {  
         $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/);  
         return $localname;  
     # Walrus add (4) end  
     } else {  
         return $localname;  
     }  
 }  
1348    
1349  sub get_info {  sub get_info {
1350      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1184  sub is_frozen { Line 1399  sub is_frozen {
1399    
1400  sub do_comment {  sub do_comment {
1401      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1402      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1403      my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " ";      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1404      if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      my $datestr = '[WEAK['.&get_now.']]';
1405          ;      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1406      } else {      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1407          $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;      if ($namestr =~ /^(?:>>)?[0-9]/) {
1408          $namestr = qq( ''$namestr'': );
1409        } elsif (length $namestr) {
1410          $namestr = qq( ''[[$namestr]]'': );
1411        }
1412        my $anchor = &get_new_anchor_index ($content);
1413        my $i = 1;  my $o = 0;
1414        $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1415          my $embed = $1;
1416          if ($i == $form{comment_index}) {
1417            if ($embed eq $embed_comment) {
1418              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1419            } else {
1420              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1421            }
1422          }
1423          $i++; $embed;
1424        }ge;
1425        unless ($o) {
1426          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1427          $content .= "\n" unless $content =~ /\n$/s;
1428          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1429      }      }
1430      if ($form{mymsg}) {      $form{__comment_anchor_index} = $anchor;
1431        if ($form{mymsg} || $form{myname}) {
1432          $form{mymsg} = $content;          $form{mymsg} = $content;
1433          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1434          &do_write;          &do_write;
# Line 1201  sub do_comment { Line 1438  sub do_comment {
1438      }      }
1439  }  }
1440    
1441    sub get_new_anchor_index ($) {
1442        my $content = shift;
1443        my $anchor = 0;
1444        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1445        $anchor + 1;
1446    }
1447    
1448    my $CommentIndex = 0;
1449  sub embedded_to_html {  sub embedded_to_html {
1450      my ($embedded) = @_;      my ($embedded) = @_;
1451      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1452          unless ($main::_EMBEDED) {
1453          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1454          return <<"EOD";          return <<"EOD";
1455  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1456      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1457      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1458      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1459      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1460      $resource{yourname}      <input type="hidden" name="comment_index" value="$CommentIndex">
1461      <input type="text" name="myname" value="" size="10">      $embed_comment_Name_Prompt
1462      <input type="text" name="mymsg" value="" size="40">      <input type="text" name="myname" value="" size="10" class="comment-name">
1463      <input type="submit" value="$resource{commentbutton}">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1464  </form>      <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1465    </p></form>
1466  EOD  EOD
1467         } else {
1468            return <<"EOD";
1469    <del><form action="$url_cgi" method="get">
1470        <input type="hidden" name="mycmd" value="read">
1471        <input type="hidden" name="mypage" value="$form{mypage}">
1472        $embed_comment_Name_Prompt
1473        <input type="text" name="myname" value="" size="10" disabled="disabled">
1474        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1475        <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1476    </form></del>
1477    EOD
1478        }
1479      } elsif ($embedded =~ /$embed_command{searched}/) {
1480        return get_search_result ($1, -match_myself => 1);
1481      # Walrus add (5) start      # Walrus add (5) start
1482      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1483          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
1484          return ($_) ? $_ : $embedded;          return ($_) ? $_ : $embedded;
1485      # Walrus add (5) end      # Walrus add (5) end
1486      } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1487        my ($name, $r) = ($1, '');
1488        if ($main::_EMBEDED != 1) {
1489          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1490          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1491          if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1492            $main::_EMBEDED = 1;
1493            $r = &text_to_html ($content, content_format => $cf);
1494            $main::_EMBEDED = 0;
1495          } elsif (length $content) {
1496            $r = "<pre>@{[&escape ($content)]}</pre>";
1497          } else {
1498            $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1499          }
1500        } else {    ## nested #EMBED
1501          $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1502        }
1503        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>);
1504      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1505        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1506      } else {
1507        return $embedded;
1508      }
1509    }
1510    
1511    sub load_formatter (@) {
1512        for my $t (@_) {
1513            unless ($fmt{$t}) {
1514                $fmt{$t} = Message::Util::Formatter->new;
1515                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1516                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1517                }
1518            }
1519        }
1520    }
1521    
1522    sub do_wikiform {
1523        my $content = $database{$form{mypage}};
1524        my $anchor = &get_new_anchor_index ($content);
1525        &load_formatter (qw/form_template form_option/);
1526        my $write = 0;
1527        my $i = 1;
1528        $content =~ s{$embed_command{form}}{
1529            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1530            if (($wfname && $wfname eq $form{wikiform_targetform})
1531                || $i == $form{wikiform_index}) {
1532                $template =~ s/\\(.)/$1/g;
1533                $option =~ s/\\(.)/$1/g;
1534                my $param = bless {}, 'SuikaWiki::Plugin';
1535                $param->{page} = $form{mypage};
1536                $param->{form_index} = $i;
1537                $param->{form_name} = $wfname;
1538                $param->{anchor_index} = $anchor;
1539                $param->{argv} = \%form;
1540                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1541                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1542                $fmt{form_option}->replace ($option, $param);
1543                my $t = 1;
1544                for (@{$param->{require}||[]}) {
1545                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1546                }
1547                $t = $fmt{form_template}->replace ($template, $param) if $t;
1548                if (length $t) {
1549                    if ($param->{output}->{reverse}) {
1550                        $embed .= "\n" . $t;
1551                    } else {
1552                        $embed = $t . "\n" . $embed;
1553                    }
1554                    $write = 1;
1555                    $form{__comment_anchor_index} = $anchor
1556                      if $param->{anchor_index_};  ## $anchor is used!
1557                }
1558                $form{__wikiform_anchor_index} = $i;
1559                undef $form{wikiform_targetform};  ## make sure never to match
1560                undef $form{wikiform_index};       ## with WikiForm in rest of page
1561            }
1562            $i++; $embed;
1563        }ge;
1564        unless ($write) {
1565          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1566          #$content .= "\n" unless $content =~ /\n$/s;
1567          #
1568        }
1569        if ($write) {
1570            $form{mymsg} = $content;
1571            $form{mytouch} = 'on';
1572            &do_write;
1573      } else {      } else {
1574          return $embedded;          $form{mycmd} = 'read';
1575            &do_read;
1576      }      }
1577  }  }
1578    
1579    
1580  # Walrus add (5) start  # Walrus add (5) start
1581  sub do_interwiki_box {  sub do_interwiki_box {
1582      my $remoteurl = $interwiki{$form{'myintername'}};      my $remoteurl = $interwiki{$form{'myintername'}};
# Line 1263  EOD Line 1613  EOD
1613  # Walrus add (5) end  # Walrus add (5) end
1614    
1615  sub code_convert {  sub code_convert {
1616      my ($contentref, $kanjicode) = @_;      my ($contentref, $code) = (shift, shift || $kanjicode);
1617  #   &Jcode::convert($contentref, $kanjicode);       # for Jcode.pm      $code = 'jis' if $code =~ /iso/;
1618      &jcode::convert($contentref, $kanjicode);       # for jcode.pl      $code = 'euc' if $code =~ /euc/;
1619        $code = 'sjis' if $code =~ /shift/;
1620        $code = 'utf8' if $code =~ /utf/;
1621        &Jcode::convert($contentref, $code);       # for Jcode.pm
1622    #    &jcode::convert($contentref, $code);       # for jcode.pl
1623        &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';
1624      return $$contentref;      return $$contentref;
1625  }  }
1626    
# Line 1339  sub do_diff { Line 1694  sub do_diff {
1694      }      }
1695      &open_diff;      &open_diff;
1696      my $title = $form{mypage};      my $title = $form{mypage};
1697      &print_header($title);      &print_header($title, -noindex => 1);
1698      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1699      &close_diff;      &close_diff;
1700      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>$resource{difftitle}</h3>);
# Line 1375  sub do_rss { Line 1730  sub do_rss {
1730      my $count = 0;      my $count = 0;
1731      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1732          last if ($count >= 15);          last if ($count >= 15);
1733          /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/;    # date format.          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/;    # date format.
1734          my $title = &unarmor_name($1);          my $title = &unarmor_name($1);
1735          my $escaped_title = &escape($title);          my $escaped_title = &escape($title);
1736          my $link = $modifier_rss_link . '?' . &encode($title);          my $link = $modifier_rss_link . '?' . &encode($title);
# Line 1388  sub do_rss { Line 1743  sub do_rss {
1743          $count++;          $count++;
1744      }      }
1745      # print RSS information (as XML).      # print RSS information (as XML).
1746    print scalar &make_navigate_links ('RssPage');
1747      print <<"EOD"      print <<"EOD"
1748  Content-type: text/xml  Content-type: application/xml
1749    
1750  @{[$rss->as_string]}  @{[$rss->as_string]}
1751  EOD  EOD
# Line 1404  sub is_exist_page { Line 1760  sub is_exist_page {
1760      }      }
1761  }  }
1762    
1763    sub __get_database ($) { $database{ $_[0] } }
1764    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1765    
1766    sub do_wikiplugininfo {
1767        &print_header (q(WikiPluginInfo));
1768        print text_to_html (&SuikaWiki::Plugin::make_info_page);
1769        &print_footer (q(WikiPluginInfo));
1770    }
1771    
1772    package wiki::referer;
1773    sub add ($$) {
1774      my $page = shift;
1775      my $uri = shift;
1776      unless (ref $uri) {
1777        require URI;
1778        $uri = URI->new ($uri);
1779        ## Some schemes do not have query part.
1780        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1781        $uri->fragment (undef);
1782      }
1783      $uri = $uri->canonical;
1784      return unless $uri;
1785      for my $regex (&get_dont_record) {
1786        return if $uri =~ /$regex/;
1787      }
1788      my %list = get ($page);
1789      $list{ $uri }++;
1790      set ($page, \%list);
1791    }
1792    sub get ($) {
1793      my $page = shift;
1794      split /"/, main::get_info ($page, 'Referer');
1795    }
1796    sub set ($%) {
1797      my $page = shift;
1798      my $list = shift;
1799      main::set_info ($page, Referer => join '"', %$list);
1800    }
1801    
1802    sub get_dont_record () {
1803      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1804      grep !/^#/,
1805      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1806    }
1807    sub get_site_name () {
1808      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1809      my @item;
1810      for (@lines) {
1811        next if /^#/;
1812        my ($uri, $name) = split /\s+/, $_, 2;
1813        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1814        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1815        push @item, [$uri, qq(q($name))];
1816      }
1817      @item;
1818    }
1819    
1820    sub list_html ($) {
1821      my $page = shift;
1822      my %list = get ($page);
1823      my $r = '';
1824      my @name = get_site_name;
1825      for my $uri (sort keys %list) {
1826        my $title;
1827        for my $item (@name) {
1828          if ($uri =~ /$item->[0]/) {
1829            $title = $uri;
1830            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1831              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1832            last;
1833          }
1834        }
1835        my $euri = main::escape ($uri);
1836        if ($title) {
1837          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1838        } else {
1839          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1840        }
1841      }
1842      $r ? qq(<ul>$r</ul>\n) : '';
1843    }
1844    
1845    sub __decode ($) {
1846      my $s = shift;
1847      $s =~ tr/+/ /;
1848      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1849      main::code_convert (\$s);
1850    }
1851    
1852    package wiki::useragent;
1853    
1854    sub add ($) {
1855      my $s = shift;
1856      return unless length $s;
1857      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1858      my %ua;
1859      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1860        if (/^-\[(\d+)\] (.+)$/) {
1861          my ($t, $n) = ($1, $2);
1862          $n =~ tr/\x0A\x0D//d;
1863          $ua{$n} = $t;
1864        }
1865      }
1866      $ua{$s}++;
1867      my $s = qq(#?SuikaWiki/0.9\n);
1868      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1869        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1870      }
1871      &main::__set_database ('WikiUserAgentList' => $s);
1872    }
1873    
1874    package SuikaWiki::Plugin;
1875      our $plugin_directory;  # defined in top of this file.
1876      our %List;
1877    
1878    sub escape ($$) { main::escape ($_[1]) }
1879    sub unescape ($$) { main::unescape ($_[1]) }
1880    sub encode ($$) { main::encode ($_[1]) }
1881    sub decode ($$) { main::decode ($_[1]) }
1882    sub __get_datetime ($) { main::get_now () }
1883    
1884    sub regist ($@) {
1885        my $pack = shift;
1886        for (@_) {
1887            push @{$List{$_}}, $pack;
1888        }
1889    }
1890    
1891    sub import_plugins () {
1892        opendir PDIR, $plugin_directory;
1893        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1894        closedir PDIR;
1895        for (@plugin) {
1896            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1897            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1898        }
1899    }
1900    
1901    sub make_info_page () {
1902        my $r = <<EOH;
1903    EOH
1904        unless ($List{_all}) {
1905            $r .= qq('''No plugin is installed!'''\n);
1906        } else {
1907            my $index = 0;
1908            for my $package (sort @{$List{_all}}) {
1909                $index++;
1910                my $prop = $package->property ();
1911                $r .= <<EOH;
1912    *$package
1913    
1914    [$index] '''$prop->{name}''' (Version $prop->{version})
1915    <$prop->{uri}>
1916    
1917    Provide:
1918    @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1919        $t .= qq(-''$f''\n);
1920        for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1921             $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1922        }
1923    }$t}]}
1924    
1925    EOH
1926            }
1927        }
1928        $r;
1929    }
1930    
1931    &import_plugins ();
1932    
1933    package main;
1934    &main;
1935    exit 0;
1936    
1937  1;  1;
1938  __END__  __END__
1939  =head1 NAME  =head1 NAME

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.38

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24