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

Diff of /suikawiki/script/wiki.cgi

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

revision 1.19 by wakaba, Sun Jun 2 06:28:30 2002 UTC revision 1.27 by wakaba, Mon Oct 7 12:50:51 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 83  my $file_FrontPage = "$modifier_dir_data Line 83  my $file_FrontPage = "$modifier_dir_data
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 = 'wiki';
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 198  sub main { Line 205  sub main {
205  }  }
206    
207  sub do_read {  sub do_read {
208      &print_header($form{mypage});    my $content = $database{$form{mypage}};
209      &print_content($database{$form{mypage}});    my $lm = &get_info($form{mypage}, $info_LastModified);
210      &print_footer($form{mypage});    &print_header($form{mypage}, -last_modified => $lm);
211      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
212        my $cf = 'SuikaWiki/0.9';
213        ## Should be support at least:
214        ## - 'SuikaWiki/0.9' CRLF
215        ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
216        ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
217        $cf = $1 if $content =~ s#^(?:/\*\s*|\#\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
218        if ($cf =~ m#^SuikaWiki/0.9(?:$|\s)#) {
219          &print_content($content, content_format => $cf, last_modified => $lm);
220          print &text_to_html (q([[#comment]]));
221        } else {
222          print "<pre>@{[&escape($content)]}</pre>";
223        }
224      my ($r, $c) = get_search_result ($form{mypage});
225        if ($c) {
226          print q{<h2 id="SEE-ALSO">See also</h2>};
227          print $r;
228        }
229      my $r = wiki::referer::list_html ($form{mypage});
230        if ($r) {
231          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$r</div>\n);
232        }
233      &print_footer($form{mypage}, $lm);
234    }
235    
236    sub do_output_css {
237      my $content = $database{$form{mypage}};
238      if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
239        print "Content-Type: text/css; charset=$charset\n";
240        print "\n";
241        print $content;
242      } else {
243        print "Status: 406 Unsupported Media Type\n";
244        &print_header('WikiPageIsNotCSS');
245        &print_content($database{WikiPageIsNotCSS});
246        &print_footer('WikiPageIsNotCSS');
247      }
248  }  }
249    
250  sub do_edit {  sub do_edit {
# Line 266  sub do_index { Line 310  sub do_index {
310      print qq(<ul>);      print qq(<ul>);
311      foreach my $page (sort keys %database) {      foreach my $page (sort keys %database) {
312          if (&is_editable($page)) {          if (&is_editable($page)) {
313              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>);
314              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);              # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
315              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);              # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
316          }          }
# Line 308  sub do_write { Line 352  sub do_write {
352              &update_recent_changes;              &update_recent_changes;
353          }          }
354          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
355          &print_header($CompletedSuccessfully);          &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{comment_index}?"#x-comment-$form{comment_index}":''));
356          &print_message($resource{saved});          &print_message($resource{saved});
357          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
358          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 332  sub do_searchform { Line 376  sub do_searchform {
376  }  }
377    
378  sub do_search {  sub do_search {
379      my $word = &escape($form{mymsg});      my $word = $form{mymsg};
380      &print_header($SearchPage);      &print_header($SearchPage);
381      &print_searchform($word);      &print_searchform(&escape($word));
382      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>|;  
     }  
383      &print_footer($SearchPage);      &print_footer($SearchPage);
384  }  }
385    
386    sub get_search_result ($;%) {
387      my $word = shift;
388      my %option = @_;
389      my $counter = 0;
390      my $r = '';
391      foreach my $page (sort keys %database) {
392        next if $page eq $RecentChanges;
393        if (   index ($database{$page}, $word) > 0
394            || index ($page, $word) > 0
395            || index ($word, $page) > 0
396           ) {
397          $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);
398          $counter++;
399        }
400      }
401      $r = qq|<ul>$r</ul>| if $r;
402      get_message ($resource{notfound})
403        if $counter == 0 && $option{-output_not_found};
404      wantarray? ($r, $counter): $r;
405    }
406    
407  sub do_create {  sub do_create {
408      &print_header($CreatePage);      &print_header($CreatePage);
409      print <<"EOD";      print <<"EOD";
# Line 385  sub print_error { Line 435  sub print_error {
435      exit(0);      exit(0);
436  }  }
437    
438  sub print_header {  sub print_header ($;%) {
439      my ($page) = @_;      my ($page, %option) = @_;
440      my $bodyclass = "normal";      my $bodyclass = "normal";
     my $editable = 0;  
     my $admineditable = 0;  
441      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {      if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
         $editable = 0;  
         $admineditable = 1;  
442          $bodyclass = "frozen";          $bodyclass = "frozen";
     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {  
         $admineditable = 1;  
         $editable = 1;  
     } else {  
         $editable = 0;  
443      }      }
444        print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};
445        print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
446      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
447        my $escapedpage = &escape($page);
448      print <<"EOD";      print <<"EOD";
449  Content-type: text/html; charset=$charset  Content-type: text/html; charset=$charset
450  Content-Language: $lang  Content-Language: $lang
# Line 411  Content-Style-Type: text/css Line 455  Content-Style-Type: text/css
455      "http://www.w3.org/TR/html4/loose.dtd">      "http://www.w3.org/TR/html4/loose.dtd">
456  <html lang="$lang">  <html lang="$lang">
457  <head>  <head>
458      <title>$page @{[&escape(&get_subjectline($page))]}</title>      <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>
459      <link rel="index" href="$url_cgi?$IndexPage">      <link rel="index" href="$url_cgi?$IndexPage">
460      <link rev="made" href="mailto:$modifier_mail">      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
461      <link rel="stylesheet" type="text/css" href="$url_stylesheet">      <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">
462        <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
463  </head>  </head>
464  <body class="$bodyclass">  <body class="$bodyclass">
465    EOD
466      &print_navigate_links ($page);
467      print <<EOD;
468    <h1 class="header">@{[&escape($page)]}
469      <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></h1>
470    EOD
471    }
472    
473    sub print_navigate_links (@) {
474      my ($page) = @_;
475        my $editable = 0;
476        my $admineditable = 0;
477        if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
478            $editable = 0;
479            $admineditable = 1;
480        } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
481            $admineditable = 1;
482            $editable = 1;
483        } else {
484            $editable = 0;
485        }
486        my $cookedpage = &encode($page);
487      print <<EOH;
488  <div class="tools">  <div class="tools">
489      @{[ $admineditable      @{[ $admineditable
490          ? 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> | )
491          : qq()          : qq()
492      ]}      ]}
493      @{[ $editable      @{[ $editable
494          ? 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> | )
495          : qq()          : qq()
496      ]}      ]}
497      @{[ $admineditable      @{[ $admineditable
# Line 437  Content-Style-Type: text/css Line 505  Content-Style-Type: text/css
505      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |      <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |
506      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>      <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>
507  </div>  </div>
508  <h1 class="header"><a  EOH
     title="$resource{searchthispage}"  
     href="$url_cgi?mycmd=search;mymsg=$cookedpage">$page</a>@{[&escape(&get_subjectline($page))]}</h1>  
 EOD  
509  }  }
510    
511  sub print_footer {  sub print_footer {
512      my ($page) = @_;      my ($page, $lm) = @_;
513      $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)
514      # Walrus mod (1) start      # Walrus mod (1) start
515  my $cvslog = '$Revision$ $Date$';    my $cvslog = '$Revision$ $Date$';
516      print <<"EOD";    print_navigate_links ($page);
517      print <<"EOD";
518    @{[ $lm ? qq(<div id="wikipage-last-modified">Last modified: $lm</div>) : '' ]}
519  <div class="footer">  <div class="footer">
520  <p>  <p>
521  <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 486  EOD Line 553  EOD
553  sub escape {  sub escape {
554      my $s = shift;      my $s = shift;
555      $s =~ s|\r\n|\n|g;      $s =~ s|\r\n|\n|g;
556      $s =~ s|\&|&amp;|g;      $s =~ s|&|&amp;|g;
557      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
558      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
559      $s =~ s|"|&quot;|g;      $s =~ s|"|&quot;|g;
# Line 496  sub escape { Line 563  sub escape {
563  sub unescape {  sub unescape {
564      my $s = shift;      my $s = shift;
565      # $s =~ s|\n|\r\n|g;      # $s =~ s|\n|\r\n|g;
566      $s =~ s|\&amp;|\&|g;      $s =~ s|&lt;|<|g;
567      $s =~ s|\&lt;|\<|g;      $s =~ s|&gt;|>|g;
568      $s =~ s|\&gt;|\>|g;      $s =~ s|&quot;|"|g;
569      $s =~ s|\&quot;|\"|g;      $s =~ s|&amp;|&|g;
570      return $s;      return $s;
571  }  }
572    
573  sub print_content {  sub print_content ($;$) {
574      my ($rawcontent) = @_;      my ($rawcontent, %option) = @_;
575      print &text_to_html($rawcontent, toc=>1);      print &text_to_html($rawcontent, toc=>1);
576  }  }
577    
# Line 518  sub text_to_html { Line 585  sub text_to_html {
585      push(@result, "<p>");      push(@result, "<p>");
586      foreach (@txt) {      foreach (@txt) {
587          chomp;          chomp;
588          # Walrus mod (6) start          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
589          #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));  
590              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
591              $tocnum++;              $tocnum++;
592          } elsif (/^\*\*\*\*(.*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
593              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
594              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
595              $tocnum++;              $tocnum++;
596          } elsif (/^\*\*\*(.*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
597              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
598              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
599              $tocnum++;              $tocnum++;
600          } elsif (/^\*\*(.*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
601          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
602          # Walrus mod (6) end          # Walrus mod (6) end
603              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
604              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>');
605              $tocnum++;              $tocnum++;
606          } elsif (/^\*(.*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
607              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
608              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>');
609              $tocnum++;              $tocnum++;
610          #} elsif (/^----/) {          } elsif (/^(={1,6})(.*)/) {
         #    push(@result, splice(@saved), '<hr>');  
         } elsif (/^(={1,5})(.*)/) {  
611              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
612              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
613          } elsif (/^(-{1,5})(.*)/) {          } elsif (/^(-{1,6})(.*)/) {
614              &back_push('ul', length($1), \@saved, \@result);              &back_push('ul', length($1), \@saved, \@result);
615              push(@result, '<li>' . &inline($2) . '</li>');              push(@result, '<li>' . &inline($2) . '</li>');
616          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
# Line 569  sub text_to_html { Line 626  sub text_to_html {
626          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
627              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
628              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
629              push(@result, &inline($1)); # Not &inline, but &escape              push(@result, &inline($1));
630  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)  #       } elsif (/^\,(.*)$/) {             # Walrus del (BF)
631          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)          } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
632              &back_push('table', 1, \@saved, \@result, ' border="1"');              &back_push('table', 1, \@saved, \@result, ' border="1"');
# Line 594  sub text_to_html { Line 651  sub text_to_html {
651              push(@result, join('', '<tr>', @value, '</tr>'));              push(@result, join('', '<tr>', @value, '</tr>'));
652              # XXXXX              # XXXXX
653              #######              #######
654            } elsif (/^\[INS\[/) {
655                push(@result, "<ins>");
656            } elsif (/^\]INS\]/) {
657                push(@result, "</ins>");
658            } elsif (/^\[DEL\[/) {
659                push(@result, "<del>");
660            } elsif (/^\]DEL\]/) {
661                push(@result, "</del>");
662            } elsif (/^\[PRE\[/) {
663                push(@result, "<pre>");
664            } elsif (/^\]PRE\]/) {
665                push(@result, "</pre>");
666          } else {          } else {
667              push(@result, &inline($_));              push(@result, &inline($_));
668          }          }
669      }      }
670      push(@result, splice(@saved));      push(@result, splice(@saved));
671        
672        my $toc = '';
673      if ($option{toc}) {      if ($option{toc}) {
674          # Convert @toc (table of contents) to HTML.          # Convert @toc (table of contents) to HTML.
675          # This part is taken from Makio Tsukamoto's WalWiki.          # This part is taken from Makio Tsukamoto's WalWiki.
676          my (@tocsaved, @tocresult);          my (@tocsaved, @tocresult);
677          foreach (@toc) {          foreach (@toc) {
678              if (/^(-{1,3})(.*)/) {              if (/^(-{1,6})(.*)$/) {
679                  &back_push('ul', length($1), \@tocsaved, \@tocresult);                  &back_push('ul', length($1), \@tocsaved, \@tocresult);
680                  push(@tocresult, '<li>' . $2 . '</li>');                  push(@tocresult, '<li>' . $2 . '</li>');
681              }              }
682          }          }
683          push(@tocresult, splice(@tocsaved));          push(@tocresult, splice(@tocsaved));
684          return join("\n", @tocresult, @result);          $toc = join("\n", @tocresult);
685      } else {          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
         return join("\n", @result);  
686      }      }
687        return $toc . join("\n", @result);
688  }  }
689    
690  sub back_push {  sub back_push {
# Line 639  sub inline { Line 709  sub inline {
709      $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
710      $line =~ s!      $line =~ s!
711        (        (
712          (?:&lt;(?:mailto|http|https|ftp|urn):[\x21-\x7E]*)&gt;          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;
713        |        |
714          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]          ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]
715        |        |
# Line 656  sub inline { Line 726  sub inline {
726  sub make_link {  sub make_link {
727      my $chunk = shift;      my $chunk = shift;
728      # Walrus add (3) start      # Walrus add (3) start
729        $chunk =~ s/^&lt;(.*)&gt;$/$1/;
730      my $name  = $chunk;      my $name  = $chunk;
     $name =~ s/^&lt;(.*)&gt;$/$1/;  
731      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {      if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {
732          ($name, $chunk) = ($1, $2);          ($name, $chunk) = ($1, $2);
733      } elsif ($chunk =~ /^mailto:(.*)$/) {      } elsif ($chunk =~ /^mailto:(.*)$/) {
734          $name = $1;          $name = $1;
735      }      }
736      if ($use_autoimg and $name =~ /^(http|https|ftp|):.+\.(png|gif|jpe?g)/) {      if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {
737          $name = qq(<img src="$name">) ;          $name = qq(<img src="$name">) ;
738      }      }
739      $name = &unarmor_name($name);      $name = &unarmor_name($name);
740      # Walrus add (3) end      # Walrus add (3) end
741      if ($chunk =~ /^(http|https|ftp):/) {      if ($chunk =~ /^(http|https|ftp|news):/) {
742          # Walrus mod (3) start          # Walrus mod (3) start
743  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {
744  #           return qq(<a href="$chunk"><img src="$chunk"></a>);  #           return qq(<a href="$chunk"><img src="$chunk"></a>);
745  #       } else {  #       } else {
746  #           return qq(<a href="$chunk">$chunk</a>);  #           return qq(<a href="$chunk">$chunk</a>);
747  #       }  #       }
748          return qq(<a href="$chunk">$name</a>);          return qq(&lt;<a href="$chunk">$name</a>&gt;);
749          # Walrus mod (3) end          # Walrus mod (3) end
750      } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {      } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {
751          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 768  sub make_link {
768  #               $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)
769                  $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)
770  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)
771                  return qq(<a href="$remoteurl">$name</a>);  # Walrus add (3)                  return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)
772              } else {              } else {
773  #               return $chunk;                              # Walrus del (3)  #               return $chunk;                              # Walrus del (3)
774                  return $name;                               # Walrus add (3)                  return &escape($name);                               # Walrus add (3)
775              }              }
776          } elsif ($database{$chunk}) {          } elsif ($database{$chunk}) {
777              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
778  #           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)
779              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)
780          } elsif ($page_command{$chunk}) {          } elsif ($page_command{$chunk}) {
781  #           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)
782              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$name</a>);     # Walrus add (3)              return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);     # Walrus add (3)
783          } else {          } else {
784  #           return qq($chunk<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit&amp;mypage=$cookedchunk">$editchar</a>); # Walrus del (3)              return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
             return qq($name<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit&amp;mypage=$cookedchunk">$editchar</a>);  # Walrus add (3)  
785          }          }
786      }      }
787  }  }
788    
 # 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  
   
789  sub print_message {  sub print_message {
790      my ($msg) = @_;      my ($msg) = @_;
791      print qq(<p><strong>$msg</strong></p>);      print qq(<p><strong>$msg</strong></p>);
792  }  }
793    
794    sub get_message {
795        my ($msg) = @_;
796        qq(<p><strong>$msg</strong></p>);
797    }
798    
799  sub init_form {  sub init_form {
800      if (param()) {      if (param()) {
801          foreach my $var (param()) {          foreach my $var (param()) {
# Line 830  sub get_subjectline { Line 871  sub get_subjectline {
871    
872          # Get the subject of the page.          # Get the subject of the page.
873          my $subject = $database{$page};          my $subject = $database{$page};
874            $subject =~ s#^SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
875          $subject =~ s/\r?\n.*//s;          $subject =~ s/\r?\n.*//s;
876          return "$delim$subject";          return "$delim$subject".$option{tail};
877      }      }
878  }  }
879    
# Line 937  sub print_editform { Line 979  sub print_editform {
979          }          }
980          $mymsg = &escape($form{mymsg});          $mymsg = &escape($form{mymsg});
981      } else {      } else {
982          $mymsg = &escape($mymsg);          $mymsg = &escape($mymsg || $database{NewPageTemplate});
983      }      }
984    
985      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
986        my $escapedmypage = &escape($form{mypage});
987        my $escapedmypassword = &escape($form{mypassword});
988    
989      print <<"EOD";      print <<"EOD";
990  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
991      @{[ $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>) : "" ]}
992      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
993      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$escapedmypage">
994      <textarea cols="$cols" rows="$rows" name="mymsg" wrap="off">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
995  @{[  @{[
996      $mode{admin} ?      $mode{admin} ?
997      qq(      qq(
# Line 960  sub print_editform { Line 1004  sub print_editform {
1004      qq(      qq(
1005          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1006          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1007          <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>
1008      )      )
1009  ]}  ]}
1010  </form>  </form>
# Line 1009  sub is_editable { Line 1053  sub is_editable {
1053  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1054  sub armor_name {  sub armor_name {
1055      my ($name) = @_;      my ($name) = @_;
1056      if ($name =~ /^$wiki_name$/) {      #if ($name =~ /^$wiki_name$/) {
1057          return $name;      #    return $name;
1058      } else {      #} else {
1059          return "[[$name]]";          return "[[$name]]";
1060      }      #}
1061  }  }
1062    
1063  # unarmor_name:  # unarmor_name:
# Line 1186  sub is_frozen { Line 1230  sub is_frozen {
1230  sub do_comment {  sub do_comment {
1231      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1232      my $datestr = &get_now;      my $datestr = &get_now;
1233      my $namestr = $form{myname} ? " ''[[$form{myname}]]'' : " : " ";      my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'' : ";
1234      if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {      #if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {
1235          ;      #  ;
1236      } else {      #} else {
1237          $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;      #  $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;
1238        #}
1239        my $i = 1;  my $o = 0;
1240        $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1241          my $embed = $1;
1242          if ($i == $form{comment_index}) {
1243            if ($embed eq $embed_comment) {
1244              $embed = "- $datestr$namestr$form{mymsg}\n$embed";  $o = 1;
1245            } else {
1246              $embed .= "\n- $datestr$namestr$form{mymsg}";  $o = 1;
1247            }
1248          }
1249          $i++; $embed;
1250        }ge;
1251        unless ($o) {
1252          $content .= "- $datestr$namestr$form{mymsg}\n";
1253      }      }
1254      if ($form{mymsg}) {      if ($form{mymsg}) {
1255          $form{mymsg} = $content;          $form{mymsg} = $content;
# Line 1202  sub do_comment { Line 1261  sub do_comment {
1261      }      }
1262  }  }
1263    
1264    my $CommentIndex = 0;
1265  sub embedded_to_html {  sub embedded_to_html {
1266      my ($embedded) = @_;      my ($embedded) = @_;
1267      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {      if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1268          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1269          return <<"EOD";          return <<"EOD";
1270  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">
1271      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1272      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1273      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1274      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1275      $resource{yourname}      <input type="hidden" name="comment_index" value="$CommentIndex">
1276        $embed_comment_Name_Prompt
1277      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10">
1278      <input type="text" name="mymsg" value="" size="40">      <input type="text" name="mymsg" value="" size="60">
1279      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="$resource{commentbutton}">
1280  </form>  </form>
1281  EOD  EOD
1282      } elsif ($embedded =~ /$embed_command{searched}/) {
1283        return get_search_result ($1);
1284      # Walrus add (5) start      # Walrus add (5) start
1285      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1286          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
# Line 1264  EOD Line 1327  EOD
1327  # Walrus add (5) end  # Walrus add (5) end
1328    
1329  sub code_convert {  sub code_convert {
1330      my ($contentref, $kanjicode) = @_;      my ($contentref, $code) = (shift, shift || $kanjicode);
1331  #   &Jcode::convert($contentref, $kanjicode);       # for Jcode.pm  #   &Jcode::convert($contentref, $code);       # for Jcode.pm
1332      &jcode::convert($contentref, $kanjicode);       # for jcode.pl      &jcode::convert($contentref, $code);       # for jcode.pl
1333      return $$contentref;      return $$contentref;
1334  }  }
1335    
# Line 1405  sub is_exist_page { Line 1468  sub is_exist_page {
1468      }      }
1469  }  }
1470    
1471    sub __get_database ($) { $database{ $_[0] } }
1472    
1473    package wiki::referer;
1474    sub add ($$) {
1475      my $page = shift;
1476      my $uri = shift;
1477      unless (ref $uri) {
1478        require URI;
1479        $uri = URI->new ($uri);
1480        ## Some schemes do not have query part.
1481        eval q{ $uri->query (undef) if $uri->query =~ /^[0-9]{6,8}$/ };
1482        $uri->fragment (undef);
1483      }
1484      $uri = $uri->canonical;
1485      return unless $uri;
1486      for my $regex (&get_dont_record) {
1487        return if $uri =~ /$regex/;
1488      }
1489      my %list = get ($page);
1490      $list{ $uri }++;
1491      set ($page, \%list);
1492    }
1493    sub get ($) {
1494      my $page = shift;
1495      split /"/, main::get_info ($page, 'Referer');
1496    }
1497    sub set ($%) {
1498      my $page = shift;
1499      my $list = shift;
1500      main::set_info ($page, Referer => join '"', %$list);
1501    }
1502    
1503    sub get_dont_record () {
1504      map {s/\$/\\\$/g; s/\@/\\\@/g; $_}
1505      grep !/^#/,
1506      split /[\x0D\x0A]+/, &main::__get_database ('RefererDontRecord');
1507    }
1508    sub get_site_name () {
1509      my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName');
1510      my %item;
1511      for (@lines) {
1512        next if /^#/;
1513        my ($uri, $name) = split /\s+/, $_, 2;
1514        $uri =~ s/\$/\\\$/g;  $uri =~ s/\@/\\\@/g;  $uri =~ s/\//\\\//g;
1515        $name =~ s![()/\\]!\\$1!g;  $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g;
1516        $item{$uri} = qq(q($name));
1517      }
1518      %item;
1519    }
1520    
1521    sub list_html ($) {
1522      my $page = shift;
1523      my %list = get ($page);
1524      my $r = '';
1525      my %name = get_site_name;
1526      for my $uri (sort keys %list) {
1527        my $title;
1528        for my $regex (keys %name) {
1529          if ($uri =~ /$regex/) {
1530            $title = $uri;
1531            eval qq{\$title =~ s/^.*$regex.*\$/$name{$regex}/e} or die $@;
1532            last;
1533          }
1534        }
1535        my $euri = main::escape ($uri);
1536        if ($title) {
1537          $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);
1538        } else {
1539          $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1540        }
1541      }
1542      $r ? qq(<ul>$r</ul>\n) : '';
1543    }
1544    
1545    sub __decode ($) {
1546      my $s = shift;
1547      $s =~ tr/+/ /;
1548      $s =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
1549      main::code_convert (\$s);
1550    }
1551    
1552  1;  1;
1553  __END__  __END__
1554  =head1 NAME  =head1 NAME

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24