/[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.19 by wakaba, Sun Jun 2 06:28:30 2002 UTC revision 1.36 by wakaba, Tue Dec 10 07:27:38 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      my $content = $database{$form{mypage}};
221      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
222        my $lm = &get_info($form{mypage}, $info_LastModified);
223          print scalar make_navigate_links ($form{mypage});
224        print "Content-Type: text/css; charset=$charset\n";
225        print "Last-Modified: $lm\n";
226        print "\n";
227        print $content;
228      } else {
229        print "Status: 406 Unsupported Media Type\n";
230        &print_header('WikiPageIsNotCSS', -noindex => 1);
231        &print_content($database{WikiPageIsNotCSS});
232        &print_footer('WikiPageIsNotCSS');
233      }
234    }
235    
236    sub id_and_name ($) {
237        my $name = shift;
238        if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
239          qq{id="$name"><a name="$name"></a};
240        } else {
241            qq{id="$name"};
242        }
243  }  }
244    
245  sub do_edit {  sub do_edit {
246      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
247      &print_header($page);      &print_header($page, -noindex => 1);
248      if (not &is_editable($page)) {      if (not &is_editable($page)) {
249          &print_message($resource{cantchange});          &print_message($resource{cantchange});
250      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
# Line 213  sub do_edit { Line 252  sub do_edit {
252      } else {      } else {
253          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
254      }      }
255        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
256        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
257        my ($r, $c) = get_search_result ($form{mypage});
258        my $rl = wiki::referer::list_html ($form{mypage});
259        if ($c) {
260          print q{<h2 id="wikipage-see-also">See also</h2>};
261          print $r;
262        }
263        if ($rl) {
264          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
265        }
266      &print_footer($page);      &print_footer($page);
267  }  }
268    
269  sub do_adminedit {  sub do_adminedit {
270      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
271      &print_header($page);      &print_header($page, -noindex => 1);
272      if (not &is_editable($page)) {      if (not &is_editable($page)) {
273          &print_message($resource{cantchange});          &print_message($resource{cantchange});
274      } else {      } else {
# Line 229  sub do_adminedit { Line 279  sub do_adminedit {
279  }  }
280    
281  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
282      &print_header($AdminChangePassword);      &print_header($AdminChangePassword, -noindex => 1);
283      &print_passwordform;      &print_passwordform;
284      &print_footer($AdminChangePassword);      &print_footer($AdminChangePassword);
285  }  }
# Line 256  EOD Line 306  EOD
306      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
307      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
308    
309      &print_header($CompletedSuccessfully);      &print_header($CompletedSuccessfully, -noindex => 1);
310      &print_message($resource{passwordchanged});      &print_message($resource{passwordchanged});
311      &print_footer($CompletedSuccessfully);      &print_footer($CompletedSuccessfully);
312  }  }
# Line 266  sub do_index { Line 316  sub do_index {
316      print qq(<ul>);      print qq(<ul>);
317      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
318          if (&is_editable($page)) {          if (&is_editable($page)) {
319              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>);
320              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
321              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
322          }          }
# Line 281  sub do_write { Line 331  sub do_write {
331      }      }
332    
333      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
334          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
335          &print_message($resource{cantchange});          &print_message($resource{cantchange});
336          &print_footer($form{mypage});          &print_footer($form{mypage});
337          return;          return;
# Line 308  sub do_write { Line 358  sub do_write {
358              &update_recent_changes;              &update_recent_changes;
359          }          }
360          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
361          &print_header($CompletedSuccessfully);          my $fragment = '';
362            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
363            if ($form{__comment_anchor_index}) {
364                $fragment .= qq(#anchor-$form{__comment_anchor_index});
365            } elsif ($form{__wikiform_anchor_index}) {
366                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
367            }
368            &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));
369          &print_message($resource{saved});          &print_message($resource{saved});
370          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
371          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 319  sub do_write { Line 376  sub do_write {
376          if ($form{mytouch}) {          if ($form{mytouch}) {
377              &update_recent_changes;              &update_recent_changes;
378          }          }
379          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
380          &print_message($resource{deleted});          &print_message($resource{deleted});
381          &print_footer($form{mypage});          &print_footer($form{mypage});
382      }      }
# Line 332  sub do_searchform { Line 389  sub do_searchform {
389  }  }
390    
391  sub do_search {  sub do_search {
392      my $word = &escape($form{mymsg});      my $word = $form{mymsg};
393      &print_header($SearchPage);      &print_header($SearchPage);
394      &print_searchform($word);      &print_searchform(&escape($word));
395      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>|;  
     }  
396      &print_footer($SearchPage);      &print_footer($SearchPage);
397  }  }
398    
399    sub get_search_result ($;%) {
400      my $word = lc shift;
401      my %option = @_;
402      my @r;
403      foreach my $page (keys %database) {
404        next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
405        my $content = $database{$page};
406        my $cf = 'SuikaWiki/0.9';
407        $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
408        next if $cf =~ /obsoleted="yes"/;
409        if (index (lc $page, $word) > -1) {
410          my $c = $content =~ s/\Q$word\E//gi;
411          push @r, [$page, $c+20];
412        } elsif (index ($word, lc $page) > -1) {
413          my $c = $content =~ s/\Q$word\E//gi;
414          push @r, [$page, $c+10];
415        } elsif (my $c = $content =~ s/\Q$word\E//gi) {
416          push @r, [$page, $c];
417        }
418      }
419      my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
420      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;
421      $r = qq|<ul class="search-result">$r</ul>| if $r;
422      get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
423      wantarray? ($r, scalar @r): $r;
424    }
425    
426  sub do_create {  sub do_create {
427      &print_header($CreatePage);      &print_header($CreatePage);
428      print <<"EOD";      print <<"EOD";
# Line 367  EOD Line 436  EOD
436      &print_footer($CreatePage);      &print_footer($CreatePage);
437  }  }
438    
439    sub do_random_jump {
440      my @list = keys %database;
441      my $name = &encode ($list[rand @list]);
442      my ($scheme) = 'http';
443      $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
444      print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
445      print "\n";
446    }
447    
448  sub do_FrontPage {  sub do_FrontPage {
449      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
450      my $content = join('', <FILE>);      my $content = join('', <FILE>);
# Line 379  sub do_FrontPage { Line 457  sub do_FrontPage {
457    
458  sub print_error {  sub print_error {
459      my ($msg) = @_;      my ($msg) = @_;
460      &print_header($ErrorPage);      &print_header($ErrorPage, -noindex => 1);
461      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
462      &print_footer($ErrorPage);      &print_footer($ErrorPage);
463      exit(0);      exit(0);
464  }  }
465    
466  sub print_header {  sub print_header ($;%) {
467      my ($page) = @_;      my ($page, %option) = @_;
468      my $bodyclass = "normal";      my $bodyclass = "normal";
     my $editable = 0;  
     my $admineditable = 0;  
469      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
         $editable = 0;  
         $admineditable = 1;  
470          $bodyclass = "frozen";          $bodyclass = "frozen";
471      } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {      }
472          $admineditable = 1;      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
473          $editable = 1;      if ($option{-goto}) {
474          if ($UA =~ m#Opera|MSIE 2\.#) {
475              $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
476              print qq{Refresh: 0; url=$option{-goto}\n};
477              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
478          } else {
479              $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
480              print qq{Refresh: 0; url="$option{-goto}"\n};
481              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
482          }
483        }
484        print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
485        my $meta_ct = '';
486        if ($UA =~ m#Mozilla/2#) {
487            $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
488            print qq{Content-Type: $meta_ct\n};
489            $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
490        } elsif ($UA =~ m#Infomosaic#) {
491            print qq{Content-Type: text/html\n};
492      } else {      } else {
493          $editable = 0;          print qq{Content-Type: text/html; charset=$charset\n};
494      }      }
495      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
496        my $escapedpage = &escape($page);
497        my ($Links, $links) = &make_navigate_links ($page);
498        print $Links;
499      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
500  Content-Language: $lang  Content-Language: $lang
501  Content-Style-Type: text/css  Content-Style-Type: text/css
502    
503    <!--
504  <!DOCTYPE html  <!DOCTYPE html
505      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
506      "http://www.w3.org/TR/html4/loose.dtd">      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
507  <html lang="$lang">  <html lang="$lang">
508  <head>  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
509      <title>$page @{[&escape(&get_subjectline($page))]}</title>      $meta_ct$option{-goto}
510      <link rel="index" href="$url_cgi?$IndexPage">      <title>$escapedpage</title>
511      <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)]}">) : '']}
512      <link rel="stylesheet" type="text/css" href="$url_stylesheet">      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
513    $links
514  </head>  </head>
515  <body class="$bodyclass">  <body class="$bodyclass">
516    EOD
517      &print_navigate_links ($page);
518      print <<EOD;
519    <h1 class="header">@{[&escape($page)]}</h1>
520    EOD
521    }
522    
523    sub x_charset ($) {
524        my $charset = lc shift;
525        if ($charset eq 'euc-jp') {
526            $charset = 'x-euc-jp';
527        } elsif ($charset eq 'shift_jis') {
528            $charset = 'x-sjis';
529        }
530        $charset;
531    }
532    
533    sub print_navigate_links (@) {
534      my ($page) = @_;
535        my $editable = 0;
536        my $admineditable = 0;
537        if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
538            $editable = 0;
539            #$admineditable = 1;
540        } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
541            #$admineditable = 1;
542            $editable = 1;
543        } else {
544            $editable = 0;
545        }
546        my $cookedpage = &encode($page);
547      print <<EOH;
548  <div class="tools">  <div class="tools">
549      @{[ $admineditable      @{[ $admineditable
550          ? 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">$resource{admineditbutton}</a> | )
551          : qq()          : qq()
552      ]}      ]}
553      @{[ $editable      @{[ $editable
554          ? 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> | )
555            qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )
556          : qq()          : qq()
557      ]}      ]}
558        <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">表示</a> |
559      @{[ $admineditable      @{[ $admineditable
560          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
561          : qq()          : qq()
562      ]}      ]}
563      <a href="$url_cgi?$CreatePage">$resource{createbutton}</a> |      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |
564      <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
565      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |
566      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
567      <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> |
568      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
569  </div>  </div>
570  <h1 class="header"><a  EOH
571      title="$resource{searchthispage}"  }
572      href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1>  
573  EOD  sub make_navigate_links ($) {
574        my $page = shift;
575        my @link;
576        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);
577        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);
578        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'};
579        push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};
580        push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};
581        push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};
582        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};
583        push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};
584        push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};
585        push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};
586        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};
587        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};
588        my ($Links, $links) = ('', '');
589        for my $e (@link) {
590            $links .= qq(<link);
591            $Links .= qq(Link: <$e->{href}>);
592            for my $attr (qw/rel rev href title class type hreflang charset/) {
593                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
594            }
595            for my $attr (qw/rel rev title/) {
596                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
597            }
598            $links .= qq(>\n);
599            $Links .= qq(\n);
600        }
601        wantarray ? ($Links, $links) : $Links;
602  }  }
603    
604  sub print_footer {  sub print_footer {
605      my ($page) = @_;      my ($page, $lm) = @_;
606        my $epage = &encode ($page);
607      $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)
608      # Walrus mod (1) start      # Walrus mod (1) start
609  my $cvslog = '$Revision$ $Date$';    my $cvslog1 = q$Revision$;
610      print <<"EOD";    my $cvslog2 = q$Date$;
611      print_navigate_links ($page);
612      print <<"EOD";
613    @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
614  <div class="footer">  <div class="footer">
615  <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>
616  <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>  
617  <div class="navigation">  <div class="navigation">
618  [<a href="/" title="このサーバーの首頁">/</a>  [<a href="/" title="このサーバーの首頁">/</a>
619  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
620  <a href="/search/" title="このサーバーの検索">検索</a>]  <a href="/search/" title="このサーバーの検索">検索</a>]
621  </div>  </div>
622    <div class="myuri">
623        &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
624    </div>
625  </div>  </div>
626  $walrus_log  $walrus_log
627  </body>  </body>
628  </html>  </html>
629  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  
630  }  }
631    
632  sub escape {  sub escape {
633      my $s = shift;      my $s = shift;
634      $s =~ s|\r\n|\n|g;      $s =~ s|\r\n|\n|g;
635      $s =~ s|\&|&amp;|g;      $s =~ s|&|&amp;|g;
636      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
637      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
638      $s =~ s|"|&quot;|g;      $s =~ s|"|&quot;|g;
# Line 496  sub escape { Line 642  sub escape {
642  sub unescape {  sub unescape {
643      my $s = shift;      my $s = shift;
644      # $s =~ s|\n|\r\n|g;      # $s =~ s|\n|\r\n|g;
645      $s =~ s|\&amp;|\&|g;      $s =~ s|&lt;|<|g;
646      $s =~ s|\&lt;|\<|g;      $s =~ s|&gt;|>|g;
647      $s =~ s|\&gt;|\>|g;      $s =~ s|&quot;|"|g;
648      $s =~ s|\&quot;|\"|g;      $s =~ s|&amp;|&|g;
649      return $s;      return $s;
650  }  }
651    
652  sub print_content {  sub print_content ($;$) {
653      my ($rawcontent) = @_;      my ($rawcontent, %option) = @_;
654      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
655  }  }
656    
657  sub text_to_html {  sub text_to_html {
658      my ($txt, %option) = @_;      my ($txt, %option) = @_;
659      my (@txt) = split(/\n/, $txt);      my (@txt) = split(/\n/, $txt);
660      my (@toc);      my @toc;
661        my @toc2 = @{$option{-toc}||[]};
662      my $tocnum = 0;      my $tocnum = 0;
663      my (@saved, @result);      my (@saved, @result);
664      unshift(@saved, "</p>");      unshift(@saved, "</p>");
665      push(@result, "<p>");      push(@result, "<p>");
666      foreach (@txt) {      foreach (@txt) {
667          chomp;          chomp;
668          # Walrus mod (6) start          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
669          #if ($saved[0] eq '</html>') {              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
670          #    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>');  
671              $tocnum++;              $tocnum++;
672          } elsif (/^\*\*\*\*(.*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
673              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
674              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>');
675              $tocnum++;              $tocnum++;
676          } elsif (/^\*\*\*(.*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
677              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
678              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>');
679              $tocnum++;              $tocnum++;
680          } elsif (/^\*\*(.*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
681          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
682          # Walrus mod (6) end          # Walrus mod (6) end
683              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
684              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>');
685              $tocnum++;              $tocnum++;
686          } elsif (/^\*(.*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
687              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
688              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>');
689              $tocnum++;              $tocnum++;
690          #} elsif (/^----/) {          } elsif (/^(={1,6})(.*)/) {
         #    push(@result, splice(@saved), '<hr>');  
         } elsif (/^(={1,5})(.*)/) {  
691              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
692              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
693          } elsif (/^(-{1,5})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
694              &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
695              push(@result, '<li>' . &inline($2) . '</li>');            my ($pf, $l) = ('', $2);
696              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
697                my $num = 0+$1;
698                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
699              }
700              push(@result, '<li>' . $pf . &inline ($l) . '</li>');
701          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
702              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
703              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
704          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
705              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
706                push @result, "<p>";
707              push(@result, &inline($2));              push(@result, &inline($2));
708                unshift @saved, "</p>";
709          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
710              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
711              push(@result, "<p>");              push(@result, "<p>");
712                unshift(@saved, "</p>");
713          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
714              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
715              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
716              push(@result, &inline($1)); # Not &inline, but &escape              push(@result, &inline($1));
717  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
718          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
719              &back_push('table', 1, \@saved, \@result, ' border="1"');              &back_push('table', 1, \@saved, \@result, ' border="1"');
# Line 594  sub text_to_html { Line 738  sub text_to_html {
738              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
739              # XXXXX              # XXXXX
740              #######              #######
741            } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
742                push @result, splice (@saved), '<'.lc($1).'>';
743                unshift @saved, "</p>";
744                push @result, "<p>";
745            } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
746                push @result, splice (@saved), '</'.lc($1).'>';
747            } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
748              my $num = 0+$1;
749              push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
750              push @result, &inline ($2);
751          } else {          } else {
752              push(@result, &inline($_));              push(@result, &inline($_));
753          }          }
754      }      }
755      push(@result, splice(@saved));      push(@result, splice(@saved));
756        
757        my $toc = '';
758      if ($option{toc}) {      if ($option{toc}) {
759          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
760          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
761          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
762          foreach (@toc) {          foreach (@toc,@toc2) {
763              if (/^(-{1,3})(.*)/) {              if (/^(-{1,6})(.*)$/) {
764                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
765                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
766              }              }
767          }          }
768          push(@tocresult, splice(@tocsaved));          push(@tocresult, splice(@tocsaved));
769          return join("\n", @tocresult, @result);          $toc = join("\n", @tocresult);
770      } else {          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
         return join("\n", @result);  
771      }      }
772        $toc .= join("\n", @result);
773        $toc =~ s#<p>\n</p>##g;
774        $toc =~ s#[\x0D\x0A]+</#</#g;
775        $toc =~ s#<pre>\n#<pre>#g;
776        $toc;
777  }  }
778    
779  sub back_push {  sub back_push {
# Line 634  sub back_push { Line 793  sub back_push {
793  sub inline {  sub inline {
794      my ($line) = @_;      my ($line) = @_;
795      $line = &escape($line);      $line = &escape($line);
796      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
797      $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;
798      $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;
799      $line =~ s!      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
800        (      $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;
801          (?:&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;
802        |      $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;
803          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]      $line =~ s%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
804        |      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
805          ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]      $line =~ s|''([^']+)''|<em>$1</em>|g;
806        #|      $line =~ s{
807        #  ($wiki_name)        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]
808        )        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]
809              !        |&gt;&gt;([0-9]+)
810                  &make_link($1)        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
811              !gex;      }{
812          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
813          if ($l) {
814            &make_link($l)
815          } elsif (defined $page) {
816            &make_wikilink ($page, anchor => 0+$anchor);
817          } elsif ($anum) {
818            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
819          } elsif ($uri) {
820            &make_urilink ($uri);
821          }
822        }gex;
823      return $line;      return $line;
824  }  }
825    
826    sub make_wikilink ($%) {
827      my ($ename, %option) = @_;
828      my $name = &unescape ($ename);
829      if ($database{$name}) {
830        my $subject = &escape (&get_subjectline ($name, delimiter => ''));
831        if ($option{anchor}) {
832          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
833        } else {
834          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
835        }
836      } else {
837        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>);
838      }
839    }
840    
841    sub make_urilink ($;%) {
842      require URI;
843      my $uri = shift;
844      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
845        $uri = &unescape ($uri);
846        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
847          my ($site, $name) = ($1, $2);
848          for ($site, $name) {
849            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
850          }
851          if ($interwiki{$site}) {
852            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
853            $site = &escape ($site); $name = &escape ($name);
854            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;);
855          } else {
856            qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
857          }
858        } else {
859          qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
860        }
861      } elsif ($uri =~ /^urn:/) {   ## URN
862        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
863        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
864      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
865        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
866        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
867      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
868        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
869        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
870      } else {      ## misc. URI
871        CGI::Carp::warningsToBrowser (0);
872        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
873        CGI::Carp::warningsToBrowser (1);
874        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
875      }
876    }
877    
878    my $FormIndex = 0;
879    sub make_custom_form ($$$$) {
880        my ($wfname, $definition, $template, $option) = @_;
881        ## $template and $option is currently not used in this procedure.
882        unless ($main::_EMBEDED) {
883            $FormIndex++;
884            if (length $definition) {
885                my $param = bless {}, 'SuikaWiki::Plugin';
886                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
887                &load_formatter (qw/form_input form_option/);
888                $definition = &unescape ($definition);
889                $definition =~ s/\\(.)/$1/g;
890                $definition .= ' %submit;' if $definition !~ /%submit/;
891                $option = &unescape ($option);
892                $option =~ s/\\(.)/$1/g;
893                $fmt{form_option}->replace ($option, $param);
894                my $target_page = $param->{output}->{page} || $form{mypage};
895                $param->{form_disabled} = 1 if $fixedpage{$target_page};
896                my $target_form = $param->{output}->{id};
897                my $r = <<EOH;
898    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
899      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
900      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
901      <input type="hidden" name="myLastModified" value="$lastmodified">
902      <input type="hidden" name="mytouch" value="on">
903      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
904    EOH
905                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
906                $r .= $fmt{form_input}->replace ($definition, $param);
907                $r .= <<EOH;
908    </form>
909    EOH
910                $r;
911           } else {  ## No input-interface WikiForm
912               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
913           }
914        } else {
915            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
916        }
917    }
918    
919    ## to be obsoleted
920  sub make_link {  sub make_link {
921      my $chunk = shift;      my $chunk = shift;
922      # Walrus add (3) start      # Walrus add (3) start
923        $chunk =~ s/^&lt;(.*)&gt;$/$1/;
924      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">) ;  
     }  
925      $name = &unarmor_name($name);      $name = &unarmor_name($name);
926      # Walrus add (3) end      # Walrus add (3) end
927      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$/) {  
928          return &embedded_to_html($chunk);          return &embedded_to_html($chunk);
929      } else {      } else {
930          $chunk = &unarmor_name($chunk);          $chunk = &unarmor_name($chunk);
931          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
932          my $cookedchunk = &encode($chunk);          my $cookedchunk = &encode($chunk);
933          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}) {  
934              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
935  #           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)
936              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)
937          } elsif ($page_command{$chunk}) {          } elsif ($page_command{$chunk}) {
938  #           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)
939              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$name</a>);     # Walrus add (3)              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)
940          } else {          } else {
941  #           return qq($chunk<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit&amp;mypage=$cookedchunk">$editchar</a>); # Walrus del (3)              return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
             return qq($name<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit&amp;mypage=$cookedchunk">$editchar</a>);  # Walrus add (3)  
942          }          }
943      }      }
944  }  }
945    
 # 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  
   
946  sub print_message {  sub print_message {
947      my ($msg) = @_;      my ($msg) = @_;
948      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>$msg</strong></p>);
949  }  }
950    
951    sub get_message {
952        my ($msg) = @_;
953        qq(<p><strong>$msg</strong></p>);
954    }
955    
956  sub init_form {  sub init_form {
957      if (param()) {      if (param()) {
958          foreach my $var (param()) {          foreach my $var (param()) {
959              $form{$var} = param($var);              $form{$var} = param($var);
960          }        }
     } else {  
         $ENV{QUERY_STRING} = $FrontPage;  
961      }      }
962        $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
963      my $query = &decode($ENV{QUERY_STRING});      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
964      if ($page_command{$query}) {        my $query = &decode($main::ENV{QUERY_STRING});
965          $query = &code_convert(\$query, $kanjicode);
966          if ($page_command{$query}) {
967          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
968          $form{mypage} = $query;          $form{mypage} = $query;
969      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
970          $form{mypage} = $query;          $form{mypage} = $query;
971            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
972          }
973      }      }
974        $form{mypage} ||= 'HomePage';
975        $form{mycmd} ||= 'read';
976    
977      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
978      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 786  sub init_form { Line 984  sub init_form {
984          }          }
985      }      }
986    
987      #      #
988      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
989      #      #
990    
991        for (grep /^wikiform__/, keys %form) {
992            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
993        }
994      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
995      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
996  }  }
997    
998  sub update_recent_changes {  sub update_recent_changes {
999      my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
1000      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
1001        shift (@oldupdates); ## '#?' magic line
1002      my @updates;      my @updates;
1003      foreach (@oldupdates) {      foreach (@oldupdates) {
1004          /^\- \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+?)\]\]/;
1005          my $name = &unarmor_name($1);          my $name = $1;
1006          if (&is_exist_page($name) and ($name ne $form{mypage})) {          if ($name ne $form{mypage}) {
1007              push(@updates, $_);              push @updates, $_;
1008          }          }
1009      }      }
1010      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
1011          unshift(@updates, $update);        unshift @updates, $update;
1012      }      }
1013      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
1014      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
1015      if ($file_touch) {      if ($file_touch) {
1016          open(FILE, "> $file_touch");          open(FILE, "> $file_touch");
1017          print FILE localtime() . "\n";          print FILE localtime() . "\n";
# Line 830  sub get_subjectline { Line 1032  sub get_subjectline {
1032    
1033          # Get the subject of the page.          # Get the subject of the page.
1034          my $subject = $database{$page};          my $subject = $database{$page};
1035            $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
1036          $subject =~ s/\r?\n.*//s;          $subject =~ s/\r?\n.*//s;
1037          return "$delim$subject";          return "$delim$subject".$option{tail};
1038      }      }
1039  }  }
1040    
# Line 912  sub print_searchform { Line 1115  sub print_searchform {
1115      my ($word) = @_;      my ($word) = @_;
1116      print <<"EOD";      print <<"EOD";
1117  <form action="$url_cgi" method="get">  <form action="$url_cgi" method="get">
1118      <input type="hidden" name="mycmd" value="search">      <input type="hidden" name="mycmd" value="read">
1119      <input type="text" name="mymsg" value="$word" size="20">      <input type="text" name="mypage" value="$word" size="20">
1120      <input type="submit" value="$resource{searchbutton}">      <input type="submit" value="$resource{searchbutton}">
1121  </form>  </form>
1122  EOD  EOD
# Line 937  sub print_editform { Line 1140  sub print_editform {
1140          }          }
1141          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
1142      } else {      } else {
1143          $mymsg = &escape($mymsg);          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1144      }      }
1145        my $magic = '';
1146        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
1147    
1148      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1149        my $escapedmypage = &escape($form{mypage});
1150        my $escapedmypassword = &escape($form{mypassword});
1151        my $selected = 'read';
1152        if ($form{after_edit_cmd}) {
1153            $selected = $form{after_edit_cmd};
1154        } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {
1155            $selected = 'edit';
1156        }
1157        my $afteredit = <<EOH;
1158    <select name="after_edit_cmd">
1159    <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>
1160    <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>
1161    </select>
1162    EOH
1163    
1164      print <<"EOD";      print <<"EOD";
1165  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1166      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$form{mypassword}" size="10"><br>) : "" ]}  <h2>$escapedmypageの編集</h2>
1167        @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}
1168        @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;
1169                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1170                   ++$n}]}]<br>
1171      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1172      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$escapedmypage">
1173      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="off">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1174  @{[  @{[
1175      $mode{admin} ?      $mode{admin} ?
1176      qq(      qq(
# Line 960  sub print_editform { Line 1183  sub print_editform {
1183      qq(      qq(
1184          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1185          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1186          <input type="submit" name="mypreview_write" value="$resource{savebutton}"><br>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1187           $afteredit
1188           <br>
1189      )      )
1190  ]}  ]}
1191  </form>  </form>
1192  EOD  EOD
1193      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1194          # Show the format rule.          # Show the format rule.
1195          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{'WikiEditHelp'};
1196          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1197          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
1198          close(FILE);      #    open(FILE, $file_format) or &print_error("($file_format)");
1199          print &text_to_html($content, toc=>0);      #    my $content = join('', <FILE>);
1200        #    &code_convert(\$content, $kanjicode);
1201        #    close(FILE);
1202        #    print &text_to_html($content, toc=>0);
1203      }      }
1204  }  }
1205    
# Line 989  EOD Line 1217  EOD
1217    
1218  sub is_editable {  sub is_editable {
1219      my ($page) = @_;      my ($page) = @_;
1220      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$/) {  
1221          return 0;          return 0;
1222      } else {      } else {
1223          return 1;          return 1;
# Line 1007  sub is_editable { Line 1227  sub is_editable {
1227  # armor_name:  # armor_name:
1228  #   WikiName -> WikiName  #   WikiName -> WikiName
1229  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1230  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     if ($name =~ /^$wiki_name$/) {  
         return $name;  
     } else {  
         return "[[$name]]";  
     }  
 }  
1231    
1232  # unarmor_name:  # unarmor_name:
1233  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
# Line 1028  sub unarmor_name { Line 1241  sub unarmor_name {
1241      }      }
1242  }  }
1243    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1244  sub decode {  sub decode {
1245      my ($s) = @_;      my ($s) = @_;
1246      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1060  sub encode { Line 1264  sub encode {
1264  sub init_resource {  sub init_resource {
1265      open(FILE, $file_resource) or &print_error("(resource)");      open(FILE, $file_resource) or &print_error("(resource)");
1266      while (<FILE>) {      while (<FILE>) {
1267          chomp;          s/[\x0A\x0D]+$//g;
1268          next if /^#/;          next if /^#/;
1269          my ($key, $value) = split(/=/, $_, 2);          my ($key, $value) = split(/=/, $_, 2);
1270          $resource{$key} = &code_convert(\$value, $kanjicode);          $resource{$key} = &code_convert(\$value, $kanjicode);
# Line 1077  sub conflict { Line 1281  sub conflict {
1281      my $content = join('', <FILE>);      my $content = join('', <FILE>);
1282      &code_convert(\$content, $kanjicode);      &code_convert(\$content, $kanjicode);
1283      close(FILE);      close(FILE);
1284      &print_header($page);      &print_header($page, -noindex => 1);
1285      &print_content($content);      &print_content($content);
1286      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1287      &print_footer($page);      &print_footer($page);
# Line 1086  sub conflict { Line 1290  sub conflict {
1290    
1291  sub get_now {  sub get_now {
1292      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1293        my (@week) = qw(日 月 火 水 木 金 土);
1294      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1295      $year += 1900;      $year += 1900;
1296      $mon++;      $mon++;
# Line 1093  sub get_now { Line 1298  sub get_now {
1298      $day = "0$day" if $day < 10;      $day = "0$day" if $day < 10;
1299      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1300      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1301      $sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1302      $weekday = $week[$weekday];      $weekday = $week[$weekday];
1303      return "$year-$mon-$day ($weekday) $hour:$min:$sec";      return "$year-$mon-$day ($weekday) $hour:$min";
1304  }  }
1305    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1306  sub init_InterWikiName {  sub init_InterWikiName {
1307      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{$InterWikiName};
1308      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1309          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1310          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1311      }      }
1312      }
1313      require Message::Util::Formatter;
1314      $fmt{interwiki} = Message::Util::Formatter->new;
1315      $fmt{interwiki}->{encoded} = sub {
1316        my ($o, $p) = @_;
1317        if ($o->{except}) {
1318          $o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1319        }
1320        my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1321        $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1322        $s;
1323      };
1324      $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
1325        my ($o, $p) = @_;
1326        my $s = $p->{name};
1327        $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1328        &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1329      };
1330  }  }
1331    
 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;  
     }  
 }  
1332    
1333  sub get_info {  sub get_info {
1334      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1185  sub is_frozen { Line 1383  sub is_frozen {
1383    
1384  sub do_comment {  sub do_comment {
1385      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1386      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1387      my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " ";      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1388      if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      my $datestr = '[WEAK['.&get_now.']]';
1389          ;      my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1390      } else {      ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1391          $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;      if ($namestr =~ /^(?:>>)?[0-9]/) {
1392          $namestr = qq( ''$namestr'': );
1393        } elsif (length $namestr) {
1394          $namestr = qq( ''[[$namestr]]'': );
1395        }
1396        my $anchor = &get_new_anchor_index ($content);
1397        my $i = 1;  my $o = 0;
1398        $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1399          my $embed = $1;
1400          if ($i == $form{comment_index}) {
1401            if ($embed eq $embed_comment) {
1402              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1403            } else {
1404              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1405            }
1406          }
1407          $i++; $embed;
1408        }ge;
1409        unless ($o) {
1410          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1411          $content .= "\n" unless $content =~ /\n$/s;
1412          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1413      }      }
1414      if ($form{mymsg}) {      $form{__comment_anchor_index} = $anchor;
1415        if ($form{mymsg} || $form{myname}) {
1416          $form{mymsg} = $content;          $form{mymsg} = $content;
1417          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1418          &do_write;          &do_write;
# Line 1202  sub do_comment { Line 1422  sub do_comment {
1422      }      }
1423  }  }
1424    
1425    sub get_new_anchor_index ($) {
1426        my $content = shift;
1427        my $anchor = 0;
1428        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1429        $anchor + 1;
1430    }
1431    
1432    my $CommentIndex = 0;
1433  sub embedded_to_html {  sub embedded_to_html {
1434      my ($embedded) = @_;      my ($embedded) = @_;
1435      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1436          unless ($main::_EMBEDED) {
1437          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1438          return <<"EOD";          return <<"EOD";
1439  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1440      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1441      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1442      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1443      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1444      $resource{yourname}      <input type="hidden" name="comment_index" value="$CommentIndex">
1445      <input type="text" name="myname" value="" size="10">      $embed_comment_Name_Prompt
1446      <input type="text" name="mymsg" value="" size="40">      <input type="text" name="myname" value="" size="10" class="comment-name">
1447      <input type="submit" value="$resource{commentbutton}">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1448  </form>      <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1449    </p></form>
1450  EOD  EOD
1451         } else {
1452            return <<"EOD";
1453    <del><form action="$url_cgi" method="get">
1454        <input type="hidden" name="mycmd" value="read">
1455        <input type="hidden" name="mypage" value="$form{mypage}">
1456        $embed_comment_Name_Prompt
1457        <input type="text" name="myname" value="" size="10" disabled="disabled">
1458        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1459        <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1460    </form></del>
1461    EOD
1462        }
1463      } elsif ($embedded =~ /$embed_command{searched}/) {
1464        return get_search_result ($1, -match_myself => 1);
1465      # Walrus add (5) start      # Walrus add (5) start
1466      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1467          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
1468          return ($_) ? $_ : $embedded;          return ($_) ? $_ : $embedded;
1469      # Walrus add (5) end      # Walrus add (5) end
1470      } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1471        my ($name, $r) = ($1, '');
1472        if ($main::_EMBEDED != 1) {
1473          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1474          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1475          if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1476            $main::_EMBEDED = 1;
1477            $r = &text_to_html ($content, content_format => $cf);
1478            $main::_EMBEDED = 0;
1479          } elsif (length $content) {
1480            $r = "<pre>@{[&escape ($content)]}</pre>";
1481          } else {
1482            $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1483          }
1484        } else {    ## nested #EMBED
1485          $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1486        }
1487        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>);
1488      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1489        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1490      } else {
1491        return $embedded;
1492      }
1493    }
1494    
1495    sub load_formatter (@) {
1496        for my $t (@_) {
1497            unless ($fmt{$t}) {
1498                $fmt{$t} = Message::Util::Formatter->new;
1499                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1500                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1501                }
1502            }
1503        }
1504    }
1505    
1506    sub do_wikiform {
1507        my $content = $database{$form{mypage}};
1508        my $anchor = &get_new_anchor_index ($content);
1509        &load_formatter (qw/form_template form_option/);
1510        my $write = 0;
1511        my $i = 1;
1512        $content =~ s{$embed_command{form}}{
1513            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1514            if (($wfname && $wfname eq $form{wikiform_targetform})
1515                || $i == $form{wikiform_index}) {
1516                $template =~ s/\\(.)/$1/g;
1517                $option =~ s/\\(.)/$1/g;
1518                my $param = bless {}, 'SuikaWiki::Plugin';
1519                $param->{page} = $form{mypage};
1520                $param->{form_index} = $i;
1521                $param->{form_name} = $wfname;
1522                $param->{anchor_index} = $anchor;
1523                $param->{argv} = \%form;
1524                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1525                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1526                $fmt{form_option}->replace ($option, $param);
1527                my $t = 1;
1528                for (@{$param->{require}||[]}) {
1529                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1530                }
1531                $t = $fmt{form_template}->replace ($template, $param) if $t;
1532                if (length $t) {
1533                    if ($param->{output}->{reverse}) {
1534                        $embed .= "\n" . $t;
1535                    } else {
1536                        $embed = $t . "\n" . $embed;
1537                    }
1538                    $write = 1;
1539                    $form{__comment_anchor_index} = $anchor
1540                      if $param->{anchor_index_};  ## $anchor is used!
1541                }
1542                $form{__wikiform_anchor_index} = $i;
1543                undef $form{wikiform_targetform};  ## make sure never to match
1544                undef $form{wikiform_index};       ## with WikiForm in rest of page
1545            }
1546            $i++; $embed;
1547        }ge;
1548        unless ($write) {
1549          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1550          #$content .= "\n" unless $content =~ /\n$/s;
1551          #
1552        }
1553        if ($write) {
1554            $form{mymsg} = $content;
1555            $form{mytouch} = 'on';
1556            &do_write;
1557      } else {      } else {
1558          return $embedded;          $form{mycmd} = 'read';
1559            &do_read;
1560      }      }
1561  }  }
1562    
1563    
1564  # Walrus add (5) start  # Walrus add (5) start
1565  sub do_interwiki_box {  sub do_interwiki_box {
1566      my $remoteurl = $interwiki{$form{'myintername'}};      my $remoteurl = $interwiki{$form{'myintername'}};
# Line 1264  EOD Line 1597  EOD
1597  # Walrus add (5) end  # Walrus add (5) end
1598    
1599  sub code_convert {  sub code_convert {
1600      my ($contentref, $kanjicode) = @_;      my ($contentref, $code) = (shift, shift || $kanjicode);
1601  #   &Jcode::convert($contentref, $kanjicode);       # for Jcode.pm      $code = 'jis' if $code =~ /iso/;
1602      &jcode::convert($contentref, $kanjicode);       # for jcode.pl      $code = 'euc' if $code =~ /euc/;
1603        $code = 'sjis' if $code =~ /shift/;
1604        $code = 'utf8' if $code =~ /utf/;
1605        &Jcode::convert($contentref, $code);       # for Jcode.pm
1606    #    &jcode::convert($contentref, $code);       # for jcode.pl
1607        &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';
1608      return $$contentref;      return $$contentref;
1609  }  }
1610    
# Line 1340  sub do_diff { Line 1678  sub do_diff {
1678      }      }
1679      &open_diff;      &open_diff;
1680      my $title = $form{mypage};      my $title = $form{mypage};
1681      &print_header($title);      &print_header($title, -noindex => 1);
1682      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1683      &close_diff;      &close_diff;
1684      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>$resource{difftitle}</h3>);
# Line 1376  sub do_rss { Line 1714  sub do_rss {
1714      my $count = 0;      my $count = 0;
1715      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1716          last if ($count >= 15);          last if ($count >= 15);
1717          /^\- \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.
1718          my $title = &unarmor_name($1);          my $title = &unarmor_name($1);
1719          my $escaped_title = &escape($title);          my $escaped_title = &escape($title);
1720          my $link = $modifier_rss_link . '?' . &encode($title);          my $link = $modifier_rss_link . '?' . &encode($title);
# Line 1389  sub do_rss { Line 1727  sub do_rss {
1727          $count++;          $count++;
1728      }      }
1729      # print RSS information (as XML).      # print RSS information (as XML).
1730    print scalar &make_navigate_links ('RssPage');
1731      print <<"EOD"      print <<"EOD"
1732  Content-type: text/xml  Content-type: application/xml
1733    
1734  @{[$rss->as_string]}  @{[$rss->as_string]}
1735  EOD  EOD
# Line 1405  sub is_exist_page { Line 1744  sub is_exist_page {
1744      }      }
1745  }  }
1746    
1747    sub __get_database ($) { $database{ $_[0] } }
1748    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1749    
1750    sub do_wikiplugininfo {
1751        &print_header (q(WikiPluginInfo));
1752        print text_to_html (&SuikaWiki::Plugin::make_info_page);
1753        &print_footer (q(WikiPluginInfo));
1754    }
1755    
1756    package wiki::referer;
1757    sub add ($$) {
1758      my $page = shift;
1759      my $uri = shift;
1760      unless (ref $uri) {
1761        require URI;
1762        $uri = URI->new ($uri);
1763        ## Some schemes do not have query part.
1764        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1765        $uri->fragment (undef);
1766      }
1767      $uri = $uri->canonical;
1768      return unless $uri;
1769      for my $regex (&get_dont_record) {
1770        return if $uri =~ /$regex/;
1771      }
1772      my %list = get ($page);
1773      $list{ $uri }++;
1774      set ($page, \%list);
1775    }
1776    sub get ($) {
1777      my $page = shift;
1778      split /"/, main::get_info ($page, 'Referer');
1779    }
1780    sub set ($%) {
1781      my $page = shift;
1782      my $list = shift;
1783      main::set_info ($page, Referer => join '"', %$list);
1784    }
1785    
1786    sub get_dont_record () {
1787      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1788      grep !/^#/,
1789      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1790    }
1791    sub get_site_name () {
1792      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1793      my @item;
1794      for (@lines) {
1795        next if /^#/;
1796        my ($uri, $name) = split /\s+/, $_, 2;
1797        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1798        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1799        push @item, [$uri, qq(q($name))];
1800      }
1801      @item;
1802    }
1803    
1804    sub list_html ($) {
1805      my $page = shift;
1806      my %list = get ($page);
1807      my $r = '';
1808      my @name = get_site_name;
1809      for my $uri (sort keys %list) {
1810        my $title;
1811        for my $item (@name) {
1812          if ($uri =~ /$item->[0]/) {
1813            $title = $uri;
1814            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1815              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1816            last;
1817          }
1818        }
1819        my $euri = main::escape ($uri);
1820        if ($title) {
1821          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1822        } else {
1823          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1824        }
1825      }
1826      $r ? qq(<ul>$r</ul>\n) : '';
1827    }
1828    
1829    sub __decode ($) {
1830      my $s = shift;
1831      $s =~ tr/+/ /;
1832      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1833      main::code_convert (\$s);
1834    }
1835    
1836    package wiki::useragent;
1837    
1838    sub add ($) {
1839      my $s = shift;
1840      return unless length $s;
1841      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1842      my %ua;
1843      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1844        if (/^-\[(\d+)\] (.+)$/) {
1845          my ($t, $n) = ($1, $2);
1846          $n =~ tr/\x0A\x0D//d;
1847          $ua{$n} = $t;
1848        }
1849      }
1850      $ua{$s}++;
1851      my $s = qq(#?SuikaWiki/0.9\n);
1852      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1853        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1854      }
1855      &main::__set_database ('WikiUserAgentList' => $s);
1856    }
1857    
1858    package SuikaWiki::Plugin;
1859      our $plugin_directory;  # defined in top of this file.
1860      our %List;
1861    
1862    sub escape ($$) { main::escape ($_[1]) }
1863    sub unescape ($$) { main::unescape ($_[1]) }
1864    sub encode ($$) { main::encode ($_[1]) }
1865    sub decode ($$) { main::decode ($_[1]) }
1866    sub __get_datetime ($) { main::get_now () }
1867    
1868    sub regist ($@) {
1869        my $pack = shift;
1870        for (@_) {
1871            push @{$List{$_}}, $pack;
1872        }
1873    }
1874    
1875    sub import_plugins () {
1876        opendir PDIR, $plugin_directory;
1877        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1878        closedir PDIR;
1879        for (@plugin) {
1880            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1881            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1882        }
1883    }
1884    
1885    sub make_info_page () {
1886        my $r = <<EOH;
1887    EOH
1888        unless ($List{_all}) {
1889            $r .= qq('''No plugin is installed!'''\n);
1890        } else {
1891            my $index = 0;
1892            for my $package (sort @{$List{_all}}) {
1893                $index++;
1894                my $prop = $package->property ();
1895                $r .= <<EOH;
1896    *$package
1897    
1898    [$index] '''$prop->{name}''' (Version $prop->{version})
1899    <$prop->{uri}>
1900    
1901    Provide:
1902    @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1903        $t .= qq(-''$f''\n);
1904        for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1905             $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1906        }
1907    }$t}]}
1908    
1909    EOH
1910            }
1911        }
1912        $r;
1913    }
1914    
1915    &import_plugins ();
1916    
1917    package main;
1918    &main;
1919    exit 0;
1920    
1921  1;  1;
1922  __END__  __END__
1923  =head1 NAME  =head1 NAME

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.36

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24