/[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.22 by wakaba, Sun Jun 30 07:52:46 2002 UTC revision 1.28 by wakaba, Thu Oct 17 07:56:58 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 = '([^:]+):i:([^:].*)';  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 = (  my %embed_command = (
129          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
# Line 161  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 173  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 201  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      my ($r, $c) = get_search_result ($form{mypage});    &print_header($form{mypage}, -last_modified => $lm);
212      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
213        my $cf = 'SuikaWiki/0.9';
214        ## Should be support at least:
215        ## - 'SuikaWiki/0.9' CRLF
216        ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
217        ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
218        $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
219        if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
220          &print_content($content, content_format => $cf, last_modified => $lm);
221          print &text_to_html (q([[#comment]]));
222        } else {
223          print "<pre>@{[&escape($content)]}</pre>";
224        }
225      my ($r, $c) = get_search_result ($form{mypage});
226      if ($c) {      if ($c) {
227        print q{<h2>See also</h2>};        print q{<h2 id="SEE-ALSO">See also</h2>};
228        print $r;        print $r;
229      }      }
230      &print_footer($form{mypage});    my $r = wiki::referer::list_html ($form{mypage});
231        if ($r) {
232          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$r</div>\n);
233        }
234      &print_footer($form{mypage}, $lm);
235    }
236    
237    sub do_output_css {
238      my $content = $database{$form{mypage}};
239      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
240        print "Content-Type: text/css; charset=$charset\n";
241        print "\n";
242        print $content;
243      } else {
244        print "Status: 406 Unsupported Media Type\n";
245        &print_header('WikiPageIsNotCSS');
246        &print_content($database{WikiPageIsNotCSS});
247        &print_footer('WikiPageIsNotCSS');
248      }
249  }  }
250    
251  sub do_edit {  sub do_edit {
# Line 274  sub do_index { Line 311  sub do_index {
311      print qq(<ul>);      print qq(<ul>);
312      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
313          if (&is_editable($page)) {          if (&is_editable($page)) {
314              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>);
315              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
316              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
317          }          }
# Line 316  sub do_write { Line 353  sub do_write {
353              &update_recent_changes;              &update_recent_changes;
354          }          }
355          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
356          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}));          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{comment_index}?"#x-comment-$form{comment_index}":''));
357          &print_message($resource{saved});          &print_message($resource{saved});
358          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
359          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 343  sub do_search { Line 380  sub do_search {
380      my $word = $form{mymsg};      my $word = $form{mymsg};
381      &print_header($SearchPage);      &print_header($SearchPage);
382      &print_searchform(&escape($word));      &print_searchform(&escape($word));
383      print get_search_result ($word, -output_not_found => 1);      print scalar get_search_result ($word, -output_not_found => 1);
384      &print_footer($SearchPage);      &print_footer($SearchPage);
385  }  }
386    
# Line 354  sub get_search_result ($;%) { Line 391  sub get_search_result ($;%) {
391    my $r = '';    my $r = '';
392    foreach my $page (sort keys %database) {    foreach my $page (sort keys %database) {
393      next if $page eq $RecentChanges;      next if $page eq $RecentChanges;
394      if (   index ($database{$page}, $word) > 0      my $content = $database{$page};
395        $content =~ s/^\#\?[^\x0A\x0D]+//s;
396        if (   index ($content, $word) > 0
397          || index ($page, $word) > 0          || index ($page, $word) > 0
398          || index ($word, $page) > 0          || index ($word, $page) > 0
399         ) {         ) {
400        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}">$page</a>@{[&escape(&get_subjectline($page))]}</li>);        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);
401        $counter++;        $counter++;
402      }      }
403    }    }
# Line 381  EOD Line 420  EOD
420      &print_footer($CreatePage);      &print_footer($CreatePage);
421  }  }
422    
423    sub do_random_jump {
424      my @list = keys %database;
425      my $name = &encode ($list[rand @list]);
426      print "Location: $url_cgi?$name\n";
427      print "\n";
428    }
429    
430  sub do_FrontPage {  sub do_FrontPage {
431      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");      open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
432      my $content = join('', <FILE>);      my $content = join('', <FILE>);
# Line 399  sub print_error { Line 445  sub print_error {
445      exit(0);      exit(0);
446  }  }
447    
448  sub print_header {  sub print_header ($;%) {
449      my ($page,%option) = @_;      my ($page, %option) = @_;
450      my $bodyclass = "normal";      my $bodyclass = "normal";
451      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
452          $bodyclass = "frozen";          $bodyclass = "frozen";
453      }      }
454      if ($option{-goto}) {      print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};
455        print qq{Refresh: 0; url="$option{-goto}"\n};      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
     }  
456      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
457        my $escapedpage = &escape($page);
458      print <<"EOD";      print <<"EOD";
459  Content-type: text/html; charset=$charset  Content-type: text/html; charset=$charset
460  Content-Language: $lang  Content-Language: $lang
461  Content-Style-Type: text/css  Content-Style-Type: text/css
462    
463    <!--
464  <!DOCTYPE html  <!DOCTYPE html
465      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
466      "http://www.w3.org/TR/html4/loose.dtd">      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
467  <html lang="$lang">  <html lang="$lang">
468  <head>  <head>
469      <title>$page @{[&escape(&get_subjectline($page))]}</title>      <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>
470      <link rel="index" href="$url_cgi?$IndexPage">      <link rel="index" href="$url_cgi?$IndexPage">
471      <link rev="made" href="mailto:$modifier_mail">      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
472      <link rel="stylesheet" type="text/css" href="$url_stylesheet">      <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">
473        <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
474  </head>  </head>
475  <body class="$bodyclass">  <body class="$bodyclass">
476  EOD  EOD
477    &print_navigate_links ($page);    &print_navigate_links ($page);
478    print <<EOD;    print <<EOD;
479  <h1 class="header"><a  <h1 class="header">@{[&escape($page)]}
480      title="$resource{searchthispage}"    <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></h1>
     href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1>  
481  EOD  EOD
482  }  }
483    
# Line 473  EOH Line 520  EOH
520  }  }
521    
522  sub print_footer {  sub print_footer {
523      my ($page) = @_;      my ($page, $lm) = @_;
524      $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)
525      # Walrus mod (1) start      # Walrus mod (1) start
526    my $cvslog = '$Revision$ $Date$';    my $cvslog = '$Revision$ $Date$';
527    print_navigate_links ($page);    print_navigate_links ($page);
528    print <<"EOD";    print <<"EOD";
529    @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
530  <div class="footer">  <div class="footer">
531  <p>  <p>
532  <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="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />
# Line 516  EOD Line 564  EOD
564  sub escape {  sub escape {
565      my $s = shift;      my $s = shift;
566      $s =~ s|\r\n|\n|g;      $s =~ s|\r\n|\n|g;
567      $s =~ s|\&|&amp;|g;      $s =~ s|&|&amp;|g;
568      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
569      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
570      $s =~ s|"|&quot;|g;      $s =~ s|"|&quot;|g;
# Line 526  sub escape { Line 574  sub escape {
574  sub unescape {  sub unescape {
575      my $s = shift;      my $s = shift;
576      # $s =~ s|\n|\r\n|g;      # $s =~ s|\n|\r\n|g;
577      $s =~ s|\&amp;|\&|g;      $s =~ s|&lt;|<|g;
578      $s =~ s|\&lt;|\<|g;      $s =~ s|&gt;|>|g;
579      $s =~ s|\&gt;|\>|g;      $s =~ s|&quot;|"|g;
580      $s =~ s|\&quot;|\"|g;      $s =~ s|&amp;|&|g;
581      return $s;      return $s;
582  }  }
583    
584  sub print_content {  sub print_content ($;$) {
585      my ($rawcontent) = @_;      my ($rawcontent, %option) = @_;
586      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1);
587  }  }
588    
# Line 548  sub text_to_html { Line 596  sub text_to_html {
596      push(@result, "<p>");      push(@result, "<p>");
597      foreach (@txt) {      foreach (@txt) {
598          chomp;          chomp;
599          # Walrus mod (6) start          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
600          #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));  
601              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
602              $tocnum++;              $tocnum++;
603          } elsif (/^\*\*\*\*(.*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
604              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
605              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
606              $tocnum++;              $tocnum++;
607          } elsif (/^\*\*\*(.*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
608              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
609              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
610              $tocnum++;              $tocnum++;
611          } elsif (/^\*\*(.*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
612          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
613          # Walrus mod (6) end          # Walrus mod (6) end
614              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
615              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>');
616              $tocnum++;              $tocnum++;
617          } elsif (/^\*(.*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
618              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
619              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>');
620              $tocnum++;              $tocnum++;
621          #} elsif (/^----/) {          } elsif (/^(={1,6})(.*)/) {
         #    push(@result, splice(@saved), '<hr>');  
         } elsif (/^(={1,5})(.*)/) {  
622              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
623              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
624          } elsif (/^(-{1,5})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
625              &back_push('ul', length($1), \@saved, \@result);            &back_push('ul', length($1), \@saved, \@result);
626              push(@result, '<li>' . &inline($2) . '</li>');            my ($pf, $l) = ('', $2);
627              if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) {
628                my $num = 0+$1;
629                $pf = qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
630              }
631              push(@result, '<li>' . $pf . &inline ($l) . '</li>');
632          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
633              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
634              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
# Line 599  sub text_to_html { Line 642  sub text_to_html {
642          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
643              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
644              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
645              push(@result, &inline($1)); # Not &inline, but &escape              push(@result, &inline($1));
646  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
647          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
648              &back_push('table', 1, \@saved, \@result, ' border="1"');              &back_push('table', 1, \@saved, \@result, ' border="1"');
# Line 624  sub text_to_html { Line 667  sub text_to_html {
667              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
668              # XXXXX              # XXXXX
669              #######              #######
670            } elsif (/^\[(INS|DEL|PRE)\[/) {
671                push @result, splice (@saved), '<'.lc($1).'>';
672                unshift @saved, "</p>";
673                push @result, "<p>";
674            } elsif (/^\](INS|DEL|PRE)\]/) {
675                push @result, splice (@saved), '</'.lc($1).'>';
676            } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
677              my $num = 0+$1;
678              push @result, qq(<a name="anchor-$num" id="anchor-$num" class="anchor">[$num]</a>);
679              push @result, &inline ($2);
680          } else {          } else {
681              push(@result, &inline($_));              push(@result, &inline($_));
682          }          }
683      }      }
684      push(@result, splice(@saved));      push(@result, splice(@saved));
685        
686        my $toc = '';
687      if ($option{toc}) {      if ($option{toc}) {
688          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
689          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
690          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
691          foreach (@toc) {          foreach (@toc) {
692              if (/^(-{1,3})(.*)/) {              if (/^(-{1,6})(.*)$/) {
693                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
694                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
695              }              }
696          }          }
697          push(@tocresult, splice(@tocsaved));          push(@tocresult, splice(@tocsaved));
698          return join("\n", @tocresult, @result);          $toc = join("\n", @tocresult);
699      } else {          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
         return join("\n", @result);  
700      }      }
701        return $toc . join("\n", @result);
702  }  }
703    
704  sub back_push {  sub back_push {
# Line 664  sub back_push { Line 718  sub back_push {
718  sub inline {  sub inline {
719      my ($line) = @_;      my ($line) = @_;
720      $line = &escape($line);      $line = &escape($line);
721        $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2</@{[lc $1]}>:g;
722        $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:<acronym title="$2">$1</acronym>:g;
723        $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
724        $line =~ s%\[Q\[(.+?)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
725      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;
726      $line =~ s|''([^']+?)''|<em>$1</em>|g;      $line =~ s|''([^']+?)''|<em>$1</em>|g;
727      $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
728      $line =~ s!      $line =~ s!
729        (        (
730          (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;
731        |        |
732          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]          (?:$bracket_name))      # [[likethis]], [[#comment]], [[Friend:remotelink]]
733        |        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]
734          ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]        |&gt;&gt;([0-9]+)
735        #|      !
736        #  ($wiki_name)        my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);
737        )        if ($l) {
738              !          &make_link($l)
739                  &make_link($1)        } elsif (defined $page) {
740              !gex;          &make_wikilink ($page, anchor => 0+$anchor);
741          } elsif ($anum) {
742            qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
743          }
744        !gex;
745      return $line;      return $line;
746  }  }
747    
748    sub make_wikilink ($%) {
749      my ($ename, %option) = @_;
750      my $name = &unescape ($ename);
751      if ($database{$name}) {
752        my $subject = &escape (&get_subjectline ($name, delimiter => ''));
753        if ($option{anchor}) {
754          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}#anchor-$option{anchor}" class="wiki">$ename&gt;&gt;$option{anchor}</a>);
755        } else {
756          return qq(<a title="$subject" href="$url_cgi?@{[&encode($name)]}" class="wiki">$ename</a>);
757        }
758      } else {
759        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>);
760      }
761    }
762    
763  sub make_link {  sub make_link {
764      my $chunk = shift;      my $chunk = shift;
765      # Walrus add (3) start      # Walrus add (3) start
# Line 693  sub make_link { Line 770  sub make_link {
770      } elsif ($chunk =~ /^mailto:(.*)$/) {      } elsif ($chunk =~ /^mailto:(.*)$/) {
771          $name = $1;          $name = $1;
772      }      }
773      if ($use_autoimg and $name =~ /^(http|https|ftp|):.+\.(png|gif|jpe?g)/) {      if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {
774          $name = qq(<img src="$name">) ;          $name = qq(<img src="$name">) ;
775      }      }
776      $name = &unarmor_name($name);      $name = &unarmor_name($name);
777      # Walrus add (3) end      # Walrus add (3) end
778      if ($chunk =~ /^(http|https|ftp):/) {      if ($chunk =~ /^(http|https|ftp|news):/) {
779          # Walrus mod (3) start          # Walrus mod (3) start
780  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {
781  #           return qq(<a href="$chunk"><img src="$chunk"></a>);  #           return qq(<a href="$chunk"><img src="$chunk"></a>);
# Line 728  sub make_link { Line 805  sub make_link {
805  #               $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)
806                  $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)
807  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)
808                  return qq(<a href="$remoteurl">$name</a>);  # Walrus add (3)                  return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)
809              } else {              } else {
810  #               return $chunk;                              # Walrus del (3)  #               return $chunk;                              # Walrus del (3)
811                  return $name;                               # Walrus add (3)                  return &escape($name);                               # Walrus add (3)
812              }              }
813          } elsif ($database{$chunk}) {          } elsif ($database{$chunk}) {
814              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
815  #           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)
816              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)
817          } elsif ($page_command{$chunk}) {          } elsif ($page_command{$chunk}) {
818  #           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)
819              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)
820          } else {          } else {
821              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>);
822          }          }
823      }      }
824  }  }
825    
 # 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  
   
826  sub print_message {  sub print_message {
827      my ($msg) = @_;      my ($msg) = @_;
828      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>$msg</strong></p>);
# Line 829  sub init_form { Line 873  sub init_form {
873  }  }
874    
875  sub update_recent_changes {  sub update_recent_changes {
876      my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
877      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
878      my @updates;      my @updates;
879      foreach (@oldupdates) {      foreach (@oldupdates) {
880          /^\- \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+?)\]\]/;
881          my $name = &unarmor_name($1);          my $name = $1;
882          if (&is_exist_page($name) and ($name ne $form{mypage})) {          if ($name ne $form{mypage}) {
883              push(@updates, $_);              push @updates, $_;
884          }          }
885      }      }
886      if (&is_exist_page($form{mypage})) {      if (&is_exist_page($form{mypage})) {
887          unshift(@updates, $update);        unshift @updates, $update;
888      }      }
889      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
890      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = join("\n", @updates);
# Line 864  sub get_subjectline { Line 908  sub get_subjectline {
908    
909          # Get the subject of the page.          # Get the subject of the page.
910          my $subject = $database{$page};          my $subject = $database{$page};
911            $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
912          $subject =~ s/\r?\n.*//s;          $subject =~ s/\r?\n.*//s;
913          return "$delim$subject";          return "$delim$subject".$option{tail};
914      }      }
915  }  }
916    
# Line 971  sub print_editform { Line 1016  sub print_editform {
1016          }          }
1017          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
1018      } else {      } else {
1019          $mymsg = &escape($mymsg);          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1020      }      }
1021    
1022      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1023        my $escapedmypage = &escape($form{mypage});
1024        my $escapedmypassword = &escape($form{mypassword});
1025    
1026      print <<"EOD";      print <<"EOD";
1027  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1028      @{[ $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>) : "" ]}
1029      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1030      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$escapedmypage">
1031      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="off" tabindex="1">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
1032  @{[  @{[
1033      $mode{admin} ?      $mode{admin} ?
1034      qq(      qq(
# Line 1043  sub is_editable { Line 1090  sub is_editable {
1090  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1091  sub armor_name {  sub armor_name {
1092      my ($name) = @_;      my ($name) = @_;
1093      if ($name =~ /^$wiki_name$/) {      #if ($name =~ /^$wiki_name$/) {
1094          return $name;      #    return $name;
1095      } else {      #} else {
1096          return "[[$name]]";          return "[[$name]]";
1097      }      #}
1098  }  }
1099    
1100  # unarmor_name:  # unarmor_name:
# Line 1120  sub conflict { Line 1167  sub conflict {
1167    
1168  sub get_now {  sub get_now {
1169      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);      my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1170        my (@week) = qw(日 月 火 水 木 金 土);
1171      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1172      $year += 1900;      $year += 1900;
1173      $mon++;      $mon++;
# Line 1127  sub get_now { Line 1175  sub get_now {
1175      $day = "0$day" if $day < 10;      $day = "0$day" if $day < 10;
1176      $hour = "0$hour" if $hour < 10;      $hour = "0$hour" if $hour < 10;
1177      $min = "0$min" if $min < 10;      $min = "0$min" if $min < 10;
1178      $sec = "0$sec" if $sec < 10;      #$sec = "0$sec" if $sec < 10;
1179      $weekday = $week[$weekday];      $weekday = $week[$weekday];
1180      return "$year-$mon-$day ($weekday) $hour:$min:$sec";      return "$year-$mon-$day ($weekday) $hour:$min";
1181  }  }
1182    
1183  # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]
# Line 1220  sub is_frozen { Line 1268  sub is_frozen {
1268  sub do_comment {  sub do_comment {
1269      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1270      my $datestr = &get_now;      my $datestr = &get_now;
1271      my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " ";      my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'': ";
1272      if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      my $anchor = 0;
1273          ;      $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1274      } else {      $anchor++;
1275          $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;      my $i = 1;  my $o = 0;
1276        $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1277          my $embed = $1;
1278          if ($i == $form{comment_index}) {
1279            if ($embed eq $embed_comment) {
1280              $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1281            } else {
1282              $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}";  $o = 1;
1283            }
1284          }
1285          $i++; $embed;
1286        }ge;
1287        unless ($o) {
1288          $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1289      }      }
1290      if ($form{mymsg}) {      if ($form{mymsg}) {
1291          $form{mymsg} = $content;          $form{mymsg} = $content;
# Line 1236  sub do_comment { Line 1297  sub do_comment {
1297      }      }
1298  }  }
1299    
1300    my $CommentIndex = 0;
1301  sub embedded_to_html {  sub embedded_to_html {
1302      my ($embedded) = @_;      my ($embedded) = @_;
1303      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1304          unless ($main::_EMBEDED) {
1305          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1306          return <<"EOD";          return <<"EOD";
1307  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">
1308      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1309      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1310      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1311      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1312      $resource{yourname}      <input type="hidden" name="comment_index" value="$CommentIndex">
1313        $embed_comment_Name_Prompt
1314      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10">
1315      <input type="text" name="mymsg" value="" size="40">      <input type="text" name="mymsg" value="" size="60">
1316      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="$resource{commentbutton}">
1317  </form>  </form>
1318  EOD  EOD
1319         } else {
1320            return <<"EOD";
1321    <del><form action="$url_cgi" method="get">
1322        <input type="hidden" name="mycmd" value="read">
1323        <input type="hidden" name="mypage" value="$form{mypage}">
1324        $embed_comment_Name_Prompt
1325        <input type="text" name="myname" value="" size="10" disabled="disabled">
1326        <input type="text" name="mymsg" value="" size="60" disabled="disabled">
1327        <input type="submit" value="$resource{commentbutton}" disabled="disabled">
1328    </form></del>
1329    EOD
1330        }
1331    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1332      return get_search_result ($1);      return get_search_result ($1);
1333      # Walrus add (5) start      # Walrus add (5) start
# Line 1259  EOD Line 1335  EOD
1335          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
1336          return ($_) ? $_ : $embedded;          return ($_) ? $_ : $embedded;
1337      # Walrus add (5) end      # Walrus add (5) end
1338      } else {    } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {
1339          return $embedded;      my ($name, $r) = ($1, '');
1340        if ($main::_EMBEDED != 1) {
1341          my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9');
1342          $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1343          if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
1344            $main::_EMBEDED = 1;
1345            $r = &text_to_html ($content, content_format => $cf);
1346            $main::_EMBEDED = 0;
1347          } elsif (length $content) {
1348            $r = "<pre>@{[&escape ($content)]}</pre>";
1349          } else {
1350            $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9');
1351          }
1352        } else {    ## nested #EMBED
1353          $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1354      }      }
1355        return qq(<blockquote title="@{[&escape($name)]}">$r</blockquote>);
1356      } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1357        return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1358      } else {
1359        return $embedded;
1360      }
1361  }  }
1362    
1363  # Walrus add (5) start  # Walrus add (5) start
# Line 1300  EOD Line 1396  EOD
1396  # Walrus add (5) end  # Walrus add (5) end
1397    
1398  sub code_convert {  sub code_convert {
1399      my ($contentref, $kanjicode) = @_;      my ($contentref, $code) = (shift, shift || $kanjicode);
1400  #   &Jcode::convert($contentref, $kanjicode);       # for Jcode.pm  #   &Jcode::convert($contentref, $code);       # for Jcode.pm
1401      &jcode::convert($contentref, $kanjicode);       # for jcode.pl      &jcode::convert($contentref, $code);       # for jcode.pl
1402      return $$contentref;      return $$contentref;
1403  }  }
1404    
# Line 1412  sub do_rss { Line 1508  sub do_rss {
1508      my $count = 0;      my $count = 0;
1509      foreach (split(/\n/, $recentchanges)) {      foreach (split(/\n/, $recentchanges)) {
1510          last if ($count >= 15);          last if ($count >= 15);
1511          /^\- \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.
1512          my $title = &unarmor_name($1);          my $title = &unarmor_name($1);
1513          my $escaped_title = &escape($title);          my $escaped_title = &escape($title);
1514          my $link = $modifier_rss_link . '?' . &encode($title);          my $link = $modifier_rss_link . '?' . &encode($title);
# Line 1441  sub is_exist_page { Line 1537  sub is_exist_page {
1537      }      }
1538  }  }
1539    
1540    sub __get_database ($) { $database{ $_[0] } }
1541    
1542    package wiki::referer;
1543    sub add ($$) {
1544      my $page = shift;
1545      my $uri = shift;
1546      unless (ref $uri) {
1547        require URI;
1548        $uri = URI->new ($uri);
1549        ## Some schemes do not have query part.
1550        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1551        $uri->fragment (undef);
1552      }
1553      $uri = $uri->canonical;
1554      return unless $uri;
1555      for my $regex (&get_dont_record) {
1556        return if $uri =~ /$regex/;
1557      }
1558      my %list = get ($page);
1559      $list{ $uri }++;
1560      set ($page, \%list);
1561    }
1562    sub get ($) {
1563      my $page = shift;
1564      split /"/, main::get_info ($page, 'Referer');
1565    }
1566    sub set ($%) {
1567      my $page = shift;
1568      my $list = shift;
1569      main::set_info ($page, Referer => join '"', %$list);
1570    }
1571    
1572    sub get_dont_record () {
1573      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1574      grep !/^#/,
1575      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1576    }
1577    sub get_site_name () {
1578      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1579      my @item;
1580      for (@lines) {
1581        next if /^#/;
1582        my ($uri, $name) = split /\s+/, $_, 2;
1583        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1584        $name =~ s!([()/\\])!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1585        push @item, [$uri, qq(q($name))];
1586      }
1587      @item;
1588    }
1589    
1590    sub list_html ($) {
1591      my $page = shift;
1592      my %list = get ($page);
1593      my $r = '';
1594      my @name = get_site_name;
1595      for my $uri (sort keys %list) {
1596        my $title;
1597        for my $item (@name) {
1598          if ($uri =~ /$item->[0]/) {
1599            $title = $uri;
1600            eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}
1601              or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e};
1602            last;
1603          }
1604        }
1605        my $euri = main::escape ($uri);
1606        if ($title) {
1607          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);
1608        } else {
1609          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1610        }
1611      }
1612      $r ? qq(<ul>$r</ul>\n) : '';
1613    }
1614    
1615    sub __decode ($) {
1616      my $s = shift;
1617      $s =~ tr/+/ /;
1618      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1619      main::code_convert (\$s);
1620    }
1621    
1622  1;  1;
1623  __END__  __END__
1624  =head1 NAME  =head1 NAME

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.28

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24