/[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.29 by wakaba, Mon Oct 21 06:28:02 2002 UTC
# Line 70  my $modifier_dbtype = 'YukiWikiDB'; Line 70  my $modifier_dbtype = 'YukiWikiDB';
70  # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.  # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.
71  my $modifier_sendmail = ''; # If you don't need mail notification.  my $modifier_sendmail = ''; # If you don't need mail notification.
72  my $modifier_dir_data = './wikidata'; # Your data directory.  my $modifier_dir_data = './wikidata'; # Your data directory.
73  my $modifier_rss_title = "WalWiki $walversion";  my $modifier_rss_title = "SuikaWiki $walversion";
74  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.
75  my $modifier_rss_description = 'This is WalWiki, yet another Wiki clone based on YukiWiki';  my $modifier_rss_description = 'This is SuikaWiki';
76  ##############################  ##############################
77  #  #
78  # You MAY modify following variables.  # You MAY modify following variables.
# Line 82  my $file_resource = "$modifier_dir_data/ Line 82  my $file_resource = "$modifier_dir_data/
82  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
83  my $file_conflict = "$modifier_dir_data/conflict.txt";  my $file_conflict = "$modifier_dir_data/conflict.txt";
84  my $file_format = "$modifier_dir_data/format.txt";  my $file_format = "$modifier_dir_data/format.txt";
85  my $url_cgi = 'wiki';  my $url_cgi = '/~wakaba/-temp/wiki/wiki';       ## MUST be started from '/'
86  my $url_stylesheet = 'wiki-style.css';  my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
87  my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';  my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';
88  my $maxrecent = 50;  my $maxrecent = 50;
89  my $cols = 80;  my $cols = 80;
# Line 110  my $SearchPage = 'SearchPage'; Line 110  my $SearchPage = 'SearchPage';
110  my $CreatePage = 'CreatePage';  my $CreatePage = 'CreatePage';
111  my $ErrorPage = 'ErrorPage';  my $ErrorPage = 'ErrorPage';
112  my $RssPage = 'RssPage';  my $RssPage = 'RssPage';
113    my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
114  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
115  ##############################  ##############################
116  # 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 del (2)
# Line 117  my $wiki_name   = '\b([A-Z][a-z]+([A-Z][ Line 118  my $wiki_name   = '\b([A-Z][a-z]+([A-Z][
118  my $bracket_name = '\[\[(\S+?)\]\]';  my $bracket_name = '\[\[(\S+?)\]\]';
119  my $embedded_name = '\[\[(#\S+?)\]\]';  my $embedded_name = '\[\[(#\S+?)\]\]';
120  my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';
121  my $interwiki_name = '([^:]+):([^:].*)';  my $interwiki_name = 'i:([^:]+):([^:].*)';
122  ##############################  ##############################
123  my $embed_comment = '[[#comment]]';  my $embed_comment = '[[#comment]]';
124  my $embed_rcomment = '[[#rcomment]]';  my $embed_rcomment = '[[#rcomment]]';
125    my $embed_comment_Name_Prompt = '名前:';
126    my $DEFAULT_embed_comment_name = '名無しさん';
127  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)
128    my %embed_command = (
129            searched        => '^\[\[#searched:([^\]]+)\]\]$',
130    );
131  ##############################  ##############################
132  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
133  my $info_IsFrozen = 'IsFrozen';  my $info_IsFrozen = 'IsFrozen';
# Line 158  my %page_command = ( Line 164  my %page_command = (
164  );  );
165  my %command_do = (  my %command_do = (
166      read => \&do_read,      read => \&do_read,
167        TEXT_CSS => \&do_output_css,
168      edit => \&do_edit,      edit => \&do_edit,
169      adminedit => \&do_adminedit,      adminedit => \&do_adminedit,
170      adminchangepasswordform => \&do_adminchangepasswordform,      adminchangepasswordform => \&do_adminchangepasswordform,
# Line 170  my %command_do = ( Line 177  my %command_do = (
177      createresult => \&do_createresult,      createresult => \&do_createresult,
178      FrontPage => \&do_FrontPage,      FrontPage => \&do_FrontPage,
179      comment => \&do_comment,      comment => \&do_comment,
180        RandomJump  => \&do_random_jump,
181      rss => \&do_rss,      rss => \&do_rss,
182      diff => \&do_diff,      diff => \&do_diff,
183      interwikibox => \&do_interwiki_box, # Walrus add (5)      interwikibox => \&do_interwiki_box, # Walrus add (5)
# Line 198  sub main { Line 206  sub main {
206  }  }
207    
208  sub do_read {  sub do_read {
209      &print_header($form{mypage});    my $content = $database{$form{mypage}};
210      &print_content($database{$form{mypage}});    my $lm = &get_info($form{mypage}, $info_LastModified);
211      &print_footer($form{mypage});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
212      my ($r, $c) = get_search_result ($form{mypage});
213      my $rl = wiki::referer::list_html ($form{mypage});
214      my @toc;
215      push @toc, qq(-<a href="#wikipage-see-also">See Also</a>) if $c;
216      push @toc, qq(-<a href="#wikipage-referer">参照元</a>) if $rl;
217        my $cf = 'SuikaWiki/0.9';
218        ## Should be support at least:
219        ## - 'SuikaWiki/0.9' CRLF
220        ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
221        ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
222        $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
223        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
224          &print_header ($form{mypage}, -last_modified => $lm,
225            -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
226          &print_content ($content, content_format => $cf, last_modified => $lm,
227            -toc => \@toc);
228          print &text_to_html (q([[#comment]]));
229        } else {
230          &print_header($form{mypage}, -last_modified => $lm);
231          print "<pre>@{[&escape($content)]}</pre>";
232        }
233        if ($c) {
234          print q{<h2 id="wikipage-see-also">See also</h2>};
235          print $r;
236        }
237        if ($rl) {
238          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
239        }
240      &print_footer($form{mypage}, $lm);
241    }
242    
243    sub do_output_css {
244      my $content = $database{$form{mypage}};
245      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
246        my $lm = &get_info($form{mypage}, $info_LastModified);
247        print "Content-Type: text/css; charset=$charset\n";
248        print "Last-Modified: $lm\n";
249        print "\n";
250        print $content;
251      } else {
252        print "Status: 406 Unsupported Media Type\n";
253        &print_header('WikiPageIsNotCSS', -noindex => 1);
254        &print_content($database{WikiPageIsNotCSS});
255        &print_footer('WikiPageIsNotCSS');
256      }
257  }  }
258    
259  sub do_edit {  sub do_edit {
260      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
261      &print_header($page);      &print_header($page, -noindex => 1);
262      if (not &is_editable($page)) {      if (not &is_editable($page)) {
263          &print_message($resource{cantchange});          &print_message($resource{cantchange});
264      } elsif (&is_frozen($page)) {      } elsif (&is_frozen($page)) {
# Line 218  sub do_edit { Line 271  sub do_edit {
271    
272  sub do_adminedit {  sub do_adminedit {
273      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
274      &print_header($page);      &print_header($page, -noindex => 1);
275      if (not &is_editable($page)) {      if (not &is_editable($page)) {
276          &print_message($resource{cantchange});          &print_message($resource{cantchange});
277      } else {      } else {
# Line 229  sub do_adminedit { Line 282  sub do_adminedit {
282  }  }
283    
284  sub do_adminchangepasswordform {  sub do_adminchangepasswordform {
285      &print_header($AdminChangePassword);      &print_header($AdminChangePassword, -noindex => 1);
286      &print_passwordform;      &print_passwordform;
287      &print_footer($AdminChangePassword);      &print_footer($AdminChangePassword);
288  }  }
# Line 256  EOD Line 309  EOD
309      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");      my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
310      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);      &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
311    
312      &print_header($CompletedSuccessfully);      &print_header($CompletedSuccessfully, -noindex => 1);
313      &print_message($resource{passwordchanged});      &print_message($resource{passwordchanged});
314      &print_footer($CompletedSuccessfully);      &print_footer($CompletedSuccessfully);
315  }  }
# Line 266  sub do_index { Line 319  sub do_index {
319      print qq(<ul>);      print qq(<ul>);
320      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
321          if (&is_editable($page)) {          if (&is_editable($page)) {
322              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>);
323              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
324              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
325          }          }
# Line 281  sub do_write { Line 334  sub do_write {
334      }      }
335    
336      if (not &is_editable($form{mypage})) {      if (not &is_editable($form{mypage})) {
337          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
338          &print_message($resource{cantchange});          &print_message($resource{cantchange});
339          &print_footer($form{mypage});          &print_footer($form{mypage});
340          return;          return;
# Line 308  sub do_write { Line 361  sub do_write {
361              &update_recent_changes;              &update_recent_changes;
362          }          }
363          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
364          &print_header($CompletedSuccessfully);          &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":''));
365          &print_message($resource{saved});          &print_message($resource{saved});
366          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
367          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 319  sub do_write { Line 372  sub do_write {
372          if ($form{mytouch}) {          if ($form{mytouch}) {
373              &update_recent_changes;              &update_recent_changes;
374          }          }
375          &print_header($form{mypage});          &print_header($form{mypage}, -noindex => 1);
376          &print_message($resource{deleted});          &print_message($resource{deleted});
377          &print_footer($form{mypage});          &print_footer($form{mypage});
378      }      }
# Line 332  sub do_searchform { Line 385  sub do_searchform {
385  }  }
386    
387  sub do_search {  sub do_search {
388      my $word = &escape($form{mymsg});      my $word = $form{mymsg};
389      &print_header($SearchPage);      &print_header($SearchPage);
390      &print_searchform($word);      &print_searchform(&escape($word));
391      my $counter = 0;      print scalar get_search_result ($word, -output_not_found => 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>|;  
     }  
392      &print_footer($SearchPage);      &print_footer($SearchPage);
393  }  }
394    
395    sub get_search_result ($;%) {
396      my $word = shift;
397      my %option = @_;
398      my $counter = 0;
399      my $r = '';
400      foreach my $page (sort keys %database) {
401        next if $page eq $RecentChanges;
402        my $content = $database{$page};
403        $content =~ s/^\#\?[^\x0A\x0D]+//s;
404        if (   index ($content, $word) > 0
405            || index ($page, $word) > 0
406            || index ($word, $page) > 0
407           ) {
408          $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);
409          $counter++;
410        }
411      }
412      $r = qq|<ul>$r</ul>| if $r;
413      get_message ($resource{notfound})
414        if $counter == 0 && $option{-output_not_found};
415      wantarray? ($r, $counter): $r;
416    }
417    
418  sub do_create {  sub do_create {
419      &print_header($CreatePage);      &print_header($CreatePage);
420      print <<"EOD";      print <<"EOD";
# Line 367  EOD Line 428  EOD
428      &print_footer($CreatePage);      &print_footer($CreatePage);
429  }  }
430    
431    sub do_random_jump {
432      my @list = keys %database;
433      my $name = &encode ($list[rand @list]);
434      my ($scheme) = 'http';
435      $scheme = $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;
436      print "Location: $scheme://$main::ENV{SERVER_NAME}:$main::ENV{SERVER_PORT}$url_cgi?$name\n";
437      print "\n";
438    }
439    
440  sub do_FrontPage {  sub do_FrontPage {
441      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
442      my $content = join('', <FILE>);      my $content = join('', <FILE>);
# Line 379  sub do_FrontPage { Line 449  sub do_FrontPage {
449    
450  sub print_error {  sub print_error {
451      my ($msg) = @_;      my ($msg) = @_;
452      &print_header($ErrorPage);      &print_header($ErrorPage, -noindex => 1);
453      print qq(<p><strong class="error">$msg</strong></p>);      print qq(<p><strong class="error">$msg</strong></p>);
454      &print_footer($ErrorPage);      &print_footer($ErrorPage);
455      exit(0);      exit(0);
456  }  }
457    
458  sub print_header {  sub print_header ($;%) {
459      my ($page) = @_;      my ($page, %option) = @_;
460      my $bodyclass = "normal";      my $bodyclass = "normal";
     my $editable = 0;  
     my $admineditable = 0;  
461      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
         $editable = 0;  
         $admineditable = 1;  
462          $bodyclass = "frozen";          $bodyclass = "frozen";
     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $admineditable = 1;  
         $editable = 1;  
     } else {  
         $editable = 0;  
463      }      }
464        $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
465        print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};
466        print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
467      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
468        my $escapedpage = &escape($page);
469      print <<"EOD";      print <<"EOD";
470  Content-type: text/html; charset=$charset  Content-type: text/html; charset=$charset
471  Content-Language: $lang  Content-Language: $lang
472  Content-Style-Type: text/css  Content-Style-Type: text/css
473    
474    <!--
475  <!DOCTYPE html  <!DOCTYPE html
476      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
477      "http://www.w3.org/TR/html4/loose.dtd">      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
478  <html lang="$lang">  <html lang="$lang">
479  <head>  <head>
480      <title>$page @{[&escape(&get_subjectline($page))]}</title>      <title>$escapedpage</title>
481      <link rel="index" href="$url_cgi?$IndexPage">      <link rel="index" href="$url_cgi?$IndexPage">
482      <link rev="made" href="mailto:$modifier_mail">      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
483      <link rel="stylesheet" type="text/css" href="$url_stylesheet">      <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">
484        <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
485        @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
486  </head>  </head>
487  <body class="$bodyclass">  <body class="$bodyclass">
488    EOD
489      &print_navigate_links ($page);
490      print <<EOD;
491    <h1 class="header">@{[&escape($page)]}</h1>
492    EOD
493    }
494    
495    sub print_navigate_links (@) {
496      my ($page) = @_;
497        my $editable = 0;
498        my $admineditable = 0;
499        if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
500            $editable = 0;
501            #$admineditable = 1;
502        } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
503            #$admineditable = 1;
504            $editable = 1;
505        } else {
506            $editable = 0;
507        }
508        my $cookedpage = &encode($page);
509      print <<EOH;
510  <div class="tools">  <div class="tools">
511      @{[ $admineditable      @{[ $admineditable
512          ? 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> | )
513          : qq()          : qq()
514      ]}      ]}
515      @{[ $editable      @{[ $editable
516          ? 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> | )
517            qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )
518          : qq()          : qq()
519      ]}      ]}
520      @{[ $admineditable      @{[ $admineditable
521          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
522          : qq()          : qq()
523      ]}      ]}
524      <a href="$url_cgi?$CreatePage">$resource{createbutton}</a> |      <a href="$url_cgi?$CreatePage" class="wiki">新規</a> |
525      <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
526      <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |      <a href="$url_cgi?$FrontPage" class="wiki">首頁</a> |
527      <a href="$url_cgi?$FrontPage">$FrontPage</a> |      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
528      <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> |
529      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
530  </div>  </div>
531  <h1 class="header"><a  EOH
532      title="$resource{searchthispage}"  <<EOH;  ## temp
533      href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1>      <a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> |
534  EOD      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |
535    <!--    <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | -->
536        <a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> |
537        <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |
538        <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |
539        <a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a>
540    </div>
541    EOH
542  }  }
543    
544  sub print_footer {  sub print_footer {
545      my ($page) = @_;      my ($page, $lm) = @_;
546      $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)
547      # Walrus mod (1) start      # Walrus mod (1) start
548  my $cvslog = '$Revision$ $Date$';    my $cvslog1 = q$Revision$;
549      print <<"EOD";    my $cvslog2 = q$Date$;
550      print_navigate_links ($page);
551      print <<"EOD";
552    @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
553  <div class="footer">  <div class="footer">
554  <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>
555  <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>  
556  <div class="navigation">  <div class="navigation">
557  [<a href="/" title="このサーバーの首頁">/</a>  [<a href="/" title="このサーバーの首頁">/</a>
558  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
# Line 486  EOD Line 582  EOD
582  sub escape {  sub escape {
583      my $s = shift;      my $s = shift;
584      $s =~ s|\r\n|\n|g;      $s =~ s|\r\n|\n|g;
585      $s =~ s|\&|&amp;|g;      $s =~ s|&|&amp;|g;
586      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
587      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
588      $s =~ s|"|&quot;|g;      $s =~ s|"|&quot;|g;
# Line 496  sub escape { Line 592  sub escape {
592  sub unescape {  sub unescape {
593      my $s = shift;      my $s = shift;
594      # $s =~ s|\n|\r\n|g;      # $s =~ s|\n|\r\n|g;
595      $s =~ s|\&amp;|\&|g;      $s =~ s|&lt;|<|g;
596      $s =~ s|\&lt;|\<|g;      $s =~ s|&gt;|>|g;
597      $s =~ s|\&gt;|\>|g;      $s =~ s|&quot;|"|g;
598      $s =~ s|\&quot;|\"|g;      $s =~ s|&amp;|&|g;
599      return $s;      return $s;
600  }  }
601    
602  sub print_content {  sub print_content ($;$) {
603      my ($rawcontent) = @_;      my ($rawcontent, %option) = @_;
604      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1, %option);
605  }  }
606    
607  sub text_to_html {  sub text_to_html {
608      my ($txt, %option) = @_;      my ($txt, %option) = @_;
609      my (@txt) = split(/\n/, $txt);      my (@txt) = split(/\n/, $txt);
610      my (@toc);      my @toc;
611        my @toc2 = @{$option{-toc}||[]};
612      my $tocnum = 0;      my $tocnum = 0;
613      my (@saved, @result);      my (@saved, @result);
614      unshift(@saved, "</p>");      unshift(@saved, "</p>");
615      push(@result, "<p>");      push(@result, "<p>");
616      foreach (@txt) {      foreach (@txt) {
617          chomp;          chomp;
618          # Walrus mod (6) start          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
619          #if ($saved[0] eq '</html>') {              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
         #    if (/<\/html>/i) { splice(@saved); }  
         #    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));  
620              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
621              $tocnum++;              $tocnum++;
622          } elsif (/^\*\*\*\*(.*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
623              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
624              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
625              $tocnum++;              $tocnum++;
626          } elsif (/^\*\*\*(.*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
627              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
628              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
629              $tocnum++;              $tocnum++;
630          } elsif (/^\*\*(.*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
631          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
632          # Walrus mod (6) end          # Walrus mod (6) end
633              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
634              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');
635              $tocnum++;              $tocnum++;
636          } elsif (/^\*(.*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
637              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
638              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');
639              $tocnum++;              $tocnum++;
640          #} elsif (/^----/) {          } elsif (/^(={1,6})(.*)/) {
         #    push(@result, splice(@saved), '<hr>');  
         } elsif (/^(={1,5})(.*)/) {  
641              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
642              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
643          } elsif (/^(-{1,5})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
644              &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
645              push(@result, '<li>' . &inline($2) . '</li>');            my ($pf, $l) = ('', $2);
646              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
647                my $num = 0+$1;
648                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
649              }
650              push(@result, '<li>' . $pf . &inline ($l) . '</li>');
651          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
652              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
653              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
# Line 569  sub text_to_html { Line 661  sub text_to_html {
661          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
662              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
663              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
664              push(@result, &inline($1)); # Not &inline, but &escape              push(@result, &inline($1));
665  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
666          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
667              &back_push('table', 1, \@saved, \@result, ' border="1"');              &back_push('table', 1, \@saved, \@result, ' border="1"');
# Line 594  sub text_to_html { Line 686  sub text_to_html {
686              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
687              # XXXXX              # XXXXX
688              #######              #######
689            } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {
690                push @result, splice (@saved), '<'.lc($1).'>';
691                unshift @saved, "</p>";
692                push @result, "<p>";
693            } elsif (/^\](INS|DEL|PRE)\]\s*$/) {
694                push @result, splice (@saved), '</'.lc($1).'>';
695            } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
696              my $num = 0+$1;
697              push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
698              push @result, &inline ($2);
699          } else {          } else {
700              push(@result, &inline($_));              push(@result, &inline($_));
701          }          }
702      }      }
703      push(@result, splice(@saved));      push(@result, splice(@saved));
704        
705        my $toc = '';
706      if ($option{toc}) {      if ($option{toc}) {
707          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
708          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
709          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
710          foreach (@toc) {          foreach (@toc,@toc2) {
711              if (/^(-{1,3})(.*)/) {              if (/^(-{1,6})(.*)$/) {
712                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
713                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
714              }              }
715          }          }
716          push(@tocresult, splice(@tocsaved));          push(@tocresult, splice(@tocsaved));
717          return join("\n", @tocresult, @result);          $toc = join("\n", @tocresult);
718      } else {          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
         return join("\n", @result);  
719      }      }
720        return $toc . join("\n", @result);
721  }  }
722    
723  sub back_push {  sub back_push {
# Line 634  sub back_push { Line 737  sub back_push {
737  sub inline {  sub inline {
738      my ($line) = @_;      my ($line) = @_;
739      $line = &escape($line);      $line = &escape($line);
740        $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2</@{[lc $1]}>:g;
741        $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:<acronym title="$2">$1</acronym>:g;
742        $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
743        $line =~ s%\[Q\[(.+?)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
744      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;
745      $line =~ s|''([^']+?)''|<em>$1</em>|g;      $line =~ s|''([^']+?)''|<em>$1</em>|g;
746      $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|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g;   # Date
747      $line =~ s!      $line =~ s!
748        (        (
749          (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;
750        |        |
751          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]          (?:$bracket_name))      # [[likethis]], [[#comment]], [[Friend:remotelink]]
752        |        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]
753          ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]        |&gt;&gt;([0-9]+)
754        #|      !
755        #  ($wiki_name)        my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);
756        )        if ($l) {
757              !          &make_link($l)
758                  &make_link($1)        } elsif (defined $page) {
759              !gex;          &make_wikilink ($page, anchor => 0+$anchor);
760          } elsif ($anum) {
761            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
762          }
763        !gex;
764      return $line;      return $line;
765  }  }
766    
767    sub make_wikilink ($%) {
768      my ($ename, %option) = @_;
769      my $name = &unescape ($ename);
770      if ($database{$name}) {
771        my $subject = &escape (&get_subjectline ($name, delimiter => ''));
772        if ($option{anchor}) {
773          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
774        } else {
775          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
776        }
777      } else {
778        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>);
779      }
780    }
781    
782  sub make_link {  sub make_link {
783      my $chunk = shift;      my $chunk = shift;
784      # Walrus add (3) start      # Walrus add (3) start
785        $chunk =~ s/^&lt;(.*)&gt;$/$1/;
786      my $name  = $chunk;      my $name  = $chunk;
     $name =~ s/^&lt;(.*)&gt;$/$1/;  
787      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {
788          ($name, $chunk) = ($1, $2);          ($name, $chunk) = ($1, $2);
789      } elsif ($chunk =~ /^mailto:(.*)$/) {      } elsif ($chunk =~ /^mailto:(.*)$/) {
790          $name = $1;          $name = $1;
791      }      }
792      if ($use_autoimg and $name =~ /^(http|https|ftp|):.+\.(png|gif|jpe?g)/) {      if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {
793          $name = qq(<img src="$name">) ;          $name = qq(<img src="$name">) ;
794      }      }
795      $name = &unarmor_name($name);      $name = &unarmor_name($name);
796      # Walrus add (3) end      # Walrus add (3) end
797      if ($chunk =~ /^(http|https|ftp):/) {      if ($chunk =~ /^(http|https|ftp|news):/) {
798          # Walrus mod (3) start          # Walrus mod (3) start
799  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {
800  #           return qq(<a href="$chunk"><img src="$chunk"></a>);  #           return qq(<a href="$chunk"><img src="$chunk"></a>);
801  #       } else {  #       } else {
802  #           return qq(<a href="$chunk">$chunk</a>);  #           return qq(<a href="$chunk">$chunk</a>);
803  #       }  #       }
804          return qq(<a href="$chunk">$name</a>);          return qq(&lt;<a href="$chunk">$name</a>&gt;);
805          # Walrus mod (3) end          # Walrus mod (3) end
806      } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {      } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {
807          return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;          return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;
# Line 698  sub make_link { Line 824  sub make_link {
824  #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)  #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)
825                  $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)                  $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)
826  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)
827                  return qq(<a href="$remoteurl">$name</a>);  # Walrus add (3)                  return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)
828              } else {              } else {
829  #               return $chunk;                              # Walrus del (3)  #               return $chunk;                              # Walrus del (3)
830                  return $name;                               # Walrus add (3)                  return &escape($name);                               # Walrus add (3)
831              }              }
832          } elsif ($database{$chunk}) {          } elsif ($database{$chunk}) {
833              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
834  #           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)
835              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)
836          } elsif ($page_command{$chunk}) {          } elsif ($page_command{$chunk}) {
837  #           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)
838              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)
839          } else {          } else {
840              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>);
841          }          }
842      }      }
843  }  }
844    
 # 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  
   
845  sub print_message {  sub print_message {
846      my ($msg) = @_;      my ($msg) = @_;
847      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>$msg</strong></p>);
848  }  }
849    
850    sub get_message {
851        my ($msg) = @_;
852        qq(<p><strong>$msg</strong></p>);
853    }
854    
855  sub init_form {  sub init_form {
856      if (param()) {      if (param()) {
857          foreach my $var (param()) {          foreach my $var (param()) {
# Line 794  sub init_form { Line 892  sub init_form {
892  }  }
893    
894  sub update_recent_changes {  sub update_recent_changes {
895      my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
896      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
897      my @updates;      my @updates;
898      foreach (@oldupdates) {      foreach (@oldupdates) {
899          /^\- \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+?)\]\]/;
900          my $name = &unarmor_name($1);          my $name = $1;
901          if (&is_exist_page($name) and ($name ne $form{mypage})) {          if ($name ne $form{mypage}) {
902              push(@updates, $_);              push @updates, $_;
903          }          }
904      }      }
905      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
906          unshift(@updates, $update);        unshift @updates, $update;
907      }      }
908      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
909      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = join("\n", @updates);
# Line 829  sub get_subjectline { Line 927  sub get_subjectline {
927    
928          # Get the subject of the page.          # Get the subject of the page.
929          my $subject = $database{$page};          my $subject = $database{$page};
930            $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
931          $subject =~ s/\r?\n.*//s;          $subject =~ s/\r?\n.*//s;
932          return "$delim$subject";          return "$delim$subject".$option{tail};
933      }      }
934  }  }
935    
# Line 936  sub print_editform { Line 1035  sub print_editform {
1035          }          }
1036          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
1037      } else {      } else {
1038          $mymsg = &escape($mymsg);          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1039      }      }
1040    
1041      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1042        my $escapedmypage = &escape($form{mypage});
1043        my $escapedmypassword = &escape($form{mypassword});
1044    
1045      print <<"EOD";      print <<"EOD";
1046  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1047      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$form{mypassword}" size="10"><br>) : "" ]}      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}
1048      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1049      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$escapedmypage">
1050      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="off">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1051  @{[  @{[
1052      $mode{admin} ?      $mode{admin} ?
1053      qq(      qq(
# Line 959  sub print_editform { Line 1060  sub print_editform {
1060      qq(      qq(
1061          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1062          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1063          <input type="submit" name="mypreview_write" value="$resource{savebutton}"><br>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>
1064      )      )
1065  ]}  ]}
1066  </form>  </form>
# Line 1008  sub is_editable { Line 1109  sub is_editable {
1109  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1110  sub armor_name {  sub armor_name {
1111      my ($name) = @_;      my ($name) = @_;
1112      if ($name =~ /^$wiki_name$/) {      #if ($name =~ /^$wiki_name$/) {
1113          return $name;      #    return $name;
1114      } else {      #} else {
1115          return "[[$name]]";          return "[[$name]]";
1116      }      #}
1117  }  }
1118    
1119  # unarmor_name:  # unarmor_name:
# Line 1076  sub conflict { Line 1177  sub conflict {
1177      my $content = join('', <FILE>);      my $content = join('', <FILE>);
1178      &code_convert(\$content, $kanjicode);      &code_convert(\$content, $kanjicode);
1179      close(FILE);      close(FILE);
1180      &print_header($page);      &print_header($page, -noindex => 1);
1181      &print_content($content);      &print_content($content);
1182      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);      &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1183      &print_footer($page);      &print_footer($page);
# Line 1085  sub conflict { Line 1186  sub conflict {
1186    
1187  sub get_now {  sub get_now {
1188      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1189        my (@week) = qw(日 月 火 水 木 金 土);
1190      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1191      $year += 1900;      $year += 1900;
1192      $mon++;      $mon++;
# Line 1092  sub get_now { Line 1194  sub get_now {
1194      $day = "0$day" if $day < 10;      $day = "0$day" if $day < 10;
1195      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1196      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1197      $sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1198      $weekday = $week[$weekday];      $weekday = $week[$weekday];
1199      return "$year-$mon-$day ($weekday) $hour:$min:$sec";      return "$year-$mon-$day ($weekday) $hour:$min";
1200  }  }
1201    
1202  # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]
# Line 1185  sub is_frozen { Line 1287  sub is_frozen {
1287  sub do_comment {  sub do_comment {
1288      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1289      my $datestr = &get_now;      my $datestr = &get_now;
1290      my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " ";      my $namestr = $form{myname} || $DEFAULT_embed_comment_name;
1291      if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      if ($namestr =~ /^(?:>>)?[0-9]/) {
1292          ;        $namestr = qq( ''$namestr'': );
1293      } else {      } else {
1294          $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;        $namestr = qq( ''[[$namestr]]'': );
1295        }
1296        my $anchor = 0;
1297        $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1298        $anchor++;
1299        my $i = 1;  my $o = 0;
1300        $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1301          my $embed = $1;
1302          if ($i == $form{comment_index}) {
1303            if ($embed eq $embed_comment) {
1304              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1305            } else {
1306              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1307            }
1308          }
1309          $i++; $embed;
1310        }ge;
1311        unless ($o) {
1312          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1313      }      }
1314        $form{__comment_anchor_index} = $anchor;
1315      if ($form{mymsg}) {      if ($form{mymsg}) {
1316          $form{mymsg} = $content;          $form{mymsg} = $content;
1317          $form{mytouch} = 'on';          $form{mytouch} = 'on';
# Line 1201  sub do_comment { Line 1322  sub do_comment {
1322      }      }
1323  }  }
1324    
1325    my $CommentIndex = 0;
1326  sub embedded_to_html {  sub embedded_to_html {
1327      my ($embedded) = @_;      my ($embedded) = @_;
1328      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1329          unless ($main::_EMBEDED) {
1330          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1331          return <<"EOD";          return <<"EOD";
1332  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">
1333      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1334      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1335      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1336      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1337      $resource{yourname}      <input type="hidden" name="comment_index" value="$CommentIndex">
1338        $embed_comment_Name_Prompt
1339      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10">
1340      <input type="text" name="mymsg" value="" size="40">      <input type="text" name="mymsg" value="" size="60">
1341      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="$resource{commentbutton}">
1342  </form>  </form>
1343  EOD  EOD
1344         } else {
1345            return <<"EOD";
1346    <del><form action="$url_cgi" method="get">
1347        <input type="hidden" name="mycmd" value="read">
1348        <input type="hidden" name="mypage" value="$form{mypage}">
1349        $embed_comment_Name_Prompt
1350        <input type="text" name="myname" value="" size="10" disabled="disabled">
1351        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1352        <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1353    </form></del>
1354    EOD
1355        }
1356      } elsif ($embedded =~ /$embed_command{searched}/) {
1357        return get_search_result ($1);
1358      # Walrus add (5) start      # Walrus add (5) start
1359      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1360          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
1361          return ($_) ? $_ : $embedded;          return ($_) ? $_ : $embedded;
1362      # Walrus add (5) end      # Walrus add (5) end
1363      } else {    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1364          return $embedded;      my ($name, $r) = ($1, '');
1365        if ($main::_EMBEDED != 1) {
1366          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1367          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1368          if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1369            $main::_EMBEDED = 1;
1370            $r = &text_to_html ($content, content_format => $cf);
1371            $main::_EMBEDED = 0;
1372          } elsif (length $content) {
1373            $r = "<pre>@{[&escape ($content)]}</pre>";
1374          } else {
1375            $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9');
1376          }
1377        } else {    ## nested #EMBED
1378          $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1379      }      }
1380        return qq(<blockquote title="@{[&escape($name)]}">$r</blockquote>);
1381      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1382        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1383      } else {
1384        return $embedded;
1385      }
1386  }  }
1387    
1388  # Walrus add (5) start  # Walrus add (5) start
# Line 1263  EOD Line 1421  EOD
1421  # Walrus add (5) end  # Walrus add (5) end
1422    
1423  sub code_convert {  sub code_convert {
1424      my ($contentref, $kanjicode) = @_;      my ($contentref, $code) = (shift, shift || $kanjicode);
1425  #   &Jcode::convert($contentref, $kanjicode);       # for Jcode.pm  #   &Jcode::convert($contentref, $code);       # for Jcode.pm
1426      &jcode::convert($contentref, $kanjicode);       # for jcode.pl      &jcode::convert($contentref, $code);       # for jcode.pl
1427      return $$contentref;      return $$contentref;
1428  }  }
1429    
# Line 1339  sub do_diff { Line 1497  sub do_diff {
1497      }      }
1498      &open_diff;      &open_diff;
1499      my $title = $form{mypage};      my $title = $form{mypage};
1500      &print_header($title);      &print_header($title, -noindex => 1);
1501      $_ = &escape($diffbase{$form{mypage}});      $_ = &escape($diffbase{$form{mypage}});
1502      &close_diff;      &close_diff;
1503      print qq(<h3>$resource{difftitle}</h3>);      print qq(<h3>$resource{difftitle}</h3>);
# Line 1375  sub do_rss { Line 1533  sub do_rss {
1533      my $count = 0;      my $count = 0;
1534      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1535          last if ($count >= 15);          last if ($count >= 15);
1536          /^\- \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.
1537          my $title = &unarmor_name($1);          my $title = &unarmor_name($1);
1538          my $escaped_title = &escape($title);          my $escaped_title = &escape($title);
1539          my $link = $modifier_rss_link . '?' . &encode($title);          my $link = $modifier_rss_link . '?' . &encode($title);
# Line 1404  sub is_exist_page { Line 1562  sub is_exist_page {
1562      }      }
1563  }  }
1564    
1565    sub __get_database ($) { $database{ $_[0] } }
1566    
1567    package wiki::referer;
1568    sub add ($$) {
1569      my $page = shift;
1570      my $uri = shift;
1571      unless (ref $uri) {
1572        require URI;
1573        $uri = URI->new ($uri);
1574        ## Some schemes do not have query part.
1575        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1576        $uri->fragment (undef);
1577      }
1578      $uri = $uri->canonical;
1579      return unless $uri;
1580      for my $regex (&get_dont_record) {
1581        return if $uri =~ /$regex/;
1582      }
1583      my %list = get ($page);
1584      $list{ $uri }++;
1585      set ($page, \%list);
1586    }
1587    sub get ($) {
1588      my $page = shift;
1589      split /"/, main::get_info ($page, 'Referer');
1590    }
1591    sub set ($%) {
1592      my $page = shift;
1593      my $list = shift;
1594      main::set_info ($page, Referer => join '"', %$list);
1595    }
1596    
1597    sub get_dont_record () {
1598      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1599      grep !/^#/,
1600      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1601    }
1602    sub get_site_name () {
1603      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1604      my @item;
1605      for (@lines) {
1606        next if /^#/;
1607        my ($uri, $name) = split /\s+/, $_, 2;
1608        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1609        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1610        push @item, [$uri, qq(q($name))];
1611      }
1612      @item;
1613    }
1614    
1615    sub list_html ($) {
1616      my $page = shift;
1617      my %list = get ($page);
1618      my $r = '';
1619      my @name = get_site_name;
1620      for my $uri (sort keys %list) {
1621        my $title;
1622        for my $item (@name) {
1623          if ($uri =~ /$item->[0]/) {
1624            $title = $uri;
1625            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1626              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1627            last;
1628          }
1629        }
1630        my $euri = main::escape ($uri);
1631        if ($title) {
1632          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);
1633        } else {
1634          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1635        }
1636      }
1637      $r ? qq(<ul>$r</ul>\n) : '';
1638    }
1639    
1640    sub __decode ($) {
1641      my $s = shift;
1642      $s =~ tr/+/ /;
1643      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1644      main::code_convert (\$s);
1645    }
1646    
1647  1;  1;
1648  __END__  __END__
1649  =head1 NAME  =head1 NAME

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24