/[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.29 by wakaba, Mon Oct 21 06:28:02 2002 UTC revision 1.31 by wakaba, Thu Nov 14 10:22:19 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
 #!perl  
2  #  #
3  # wiki.cgi - This is YukiWiki, yet another Wiki clone.  # wiki.cgi - This is YukiWiki, yet another Wiki clone.
4  #  #
# Line 10  Line 9 
9  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
10  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
11  #  #
 ##############################  
 #  
12  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.  # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
 #  
 # WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。  
 #  
 # * 更新内容  
 #  
 # 2.0.beta1.wal.1 on 2002/05/19,22:32:19  
 # (1) Footerの変更  
 # (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない  
 # (3) 別名リンク([別名 URL])に対応。  
 # (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。  
 # (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成  
 # (6) HTMLモード対応。  
 #  
 # 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。  
 # ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。  
 #   - インラインの画像変換  
 #   - YukiWikiDB対応  
 #   - テーブル  
 #   - DB関連モジュールuseのeval化  
 #   - BracketNameによるキーからブラケットを排除  
 # ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。  
 #   [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。  
 #  
 #=======================================  
13    
14  # Walrus add (debug) start  # Walrus add (debug) start
15  my $walrus_log;  my $walrus_log;
# Line 113  my $RssPage = 'RssPage'; Line 86  my $RssPage = 'RssPage';
86  my $NAME_OF_WikiPageLicense = 'WikiPageLicense';  my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
87  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.  my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
88  ##############################  ##############################
 # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b';        # Walrus del (2)  
 my $wiki_name   = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b';        # Walrus add (2)  
89  my $bracket_name = '\[\[(\S+?)\]\]';  my $bracket_name = '\[\[(\S+?)\]\]';
90  my $embedded_name = '\[\[(#\S+?)\]\]';  my $embedded_name = '\[\[(#\S+?)\]\]';
91  my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';  my %fmt;        ## formatter objects
 my $interwiki_name = 'i:([^:]+):([^:].*)';  
92  ##############################  ##############################
93  my $embed_comment = '[[#comment]]';  my $embed_comment = '[[#comment]]';
94  my $embed_rcomment = '[[#rcomment]]';  my $embed_rcomment = '[[#rcomment]]';
# Line 225  sub do_read { Line 195  sub do_read {
195          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
196        &print_content ($content, content_format => $cf, last_modified => $lm,        &print_content ($content, content_format => $cf, last_modified => $lm,
197          -toc => \@toc);          -toc => \@toc);
198        print &text_to_html (q([[#comment]]));        print &text_to_html (q([[#comment]])) unless $cf =~ /obsoleted="yes"/;
199      } else {      } else {
200        &print_header($form{mypage}, -last_modified => $lm);        &print_header($form{mypage}, -last_modified => $lm);
201        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
# Line 266  sub do_edit { Line 236  sub do_edit {
236      } else {      } else {
237          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
238      }      }
239        wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
240        my ($r, $c) = get_search_result ($form{mypage});
241        my $rl = wiki::referer::list_html ($form{mypage});
242        if ($c) {
243          print q{<h2 id="wikipage-see-also">See also</h2>};
244          print $r;
245        }
246        if ($rl) {
247          print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);
248        }
249      &print_footer($page);      &print_footer($page);
250  }  }
251    
# Line 388  sub do_search { Line 368  sub do_search {
368      my $word = $form{mymsg};      my $word = $form{mymsg};
369      &print_header($SearchPage);      &print_header($SearchPage);
370      &print_searchform(&escape($word));      &print_searchform(&escape($word));
371      print scalar get_search_result ($word, -output_not_found => 1);      print scalar get_search_result ($word, -output_not_found => 1, -match_myself => 1);
372      &print_footer($SearchPage);      &print_footer($SearchPage);
373  }  }
374    
375  sub get_search_result ($;%) {  sub get_search_result ($;%) {
376    my $word = shift;    my $word = shift;
377    my %option = @_;    my %option = @_;
378    my $counter = 0;    my @r;
379    my $r = '';    foreach my $page (keys %database) {
380    foreach my $page (sort keys %database) {      next if $page eq $RecentChanges || ($page eq $word && !$option{-match_myself});
     next if $page eq $RecentChanges;  
381      my $content = $database{$page};      my $content = $database{$page};
382      $content =~ s/^\#\?[^\x0A\x0D]+//s;      my $cf = 'SuikaWiki/0.9';
383      if (   index ($content, $word) > 0      $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
384          || index ($page, $word) > 0      next if $cf =~ /obsoleted="yes"/;
385          || index ($word, $page) > 0      if (index ($page, $word) > -1) {
386         ) {        my $c = $content =~ s/\Q$word\E/$word/g;
387        $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a> <span class="wikipage-summary">@{[&escape(&get_subjectline($page))]}</span></li>);        push @r, [$page, $c+20];
388        $counter++;      } elsif (index ($word, $page) > -1) {
389          my $c = $content =~ s/\Q$word\E/$word/g;
390          push @r, [$page, $c+10];
391        } elsif (my $c = $content =~ s/\Q$word\E/$word/g) {
392          push @r, [$page, $c];
393      }      }
394    }    }
395    $r = qq|<ul>$r</ul>| if $r;    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#g; $s };
396    get_message ($resource{notfound})    my $r = join "\n", map {qq(<li>[$_->[1]] <a href ="$url_cgi?@{[&encode($_->[0])]}" class="wiki">@{[&$em(&escape($_->[0]))]}</a> <span class="wikipage-summary">@{[&$em(&escape(&get_subjectline($_->[0])))]}</span></li>)} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
397      if $counter == 0 && $option{-output_not_found};    $r = qq|<ul class="search-result">$r</ul>| if $r;
398    wantarray? ($r, $counter): $r;    get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
399      wantarray? ($r, scalar @r): $r;
400  }  }
401    
402  sub do_create {  sub do_create {
# Line 479  Content-Style-Type: text/css Line 463  Content-Style-Type: text/css
463  <head>  <head>
464      <title>$escapedpage</title>      <title>$escapedpage</title>
465      <link rel="index" href="$url_cgi?$IndexPage">      <link rel="index" href="$url_cgi?$IndexPage">
466        <link rel="help" href="$url_cgi?WikiHelp">
467      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">      <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
     <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">  
468      <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">      <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
469      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
470  </head>  </head>
# Line 651  sub text_to_html { Line 635  sub text_to_html {
635          } elsif (/^:([^:]+):(.*)/) {          } elsif (/^:([^:]+):(.*)/) {
636              &back_push('dl', 1, \@saved, \@result);              &back_push('dl', 1, \@saved, \@result);
637              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');              push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
638          } elsif (/^(>{1,5})(.*)/) {          } elsif (/^(?!>>\d)(>{1,5})(.*)/) {
639              &back_push('blockquote', length($1), \@saved, \@result);              &back_push('blockquote', length($1), \@saved, \@result);
640                push @result, "<p>";
641              push(@result, &inline($2));              push(@result, &inline($2));
642                unshift @saved, "</p>";
643          } elsif (/^\s*$/) {          } elsif (/^\s*$/) {
644              push(@result, splice(@saved));              push(@result, splice(@saved));
             unshift(@saved, "</p>");  
645              push(@result, "<p>");              push(@result, "<p>");
646                unshift(@saved, "</p>");
647          } elsif (/^(\s+.*)$/) {          } elsif (/^(\s+.*)$/) {
648              &back_push('pre', 1, \@saved, \@result);              &back_push('pre', 1, \@saved, \@result);
649              #push(@result, &escape($1)); # Not &inline, but &escape              #push(@result, &escape($1)); # Not &inline, but &escape
# Line 717  sub text_to_html { Line 703  sub text_to_html {
703          $toc = join("\n", @tocresult);          $toc = join("\n", @tocresult);
704          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';          $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';
705      }      }
706      return $toc . join("\n", @result);      $toc .= join("\n", @result);
707        $toc =~ s#<p>\n</p>##g;
708        $toc =~ s#[\x0D\x0A]+</#</#g;
709        $toc =~ s#<pre>\n#<pre>#g;
710        $toc;
711  }  }
712    
713  sub back_push {  sub back_push {
# Line 737  sub back_push { Line 727  sub back_push {
727  sub inline {  sub inline {
728      my ($line) = @_;      my ($line) = @_;
729      $line = &escape($line);      $line = &escape($line);
730      $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2</@{[lc $1]}>:g;      $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g;
731      $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:<acronym title="$2">$1</acronym>:g;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
732      $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
733      $line =~ s%\[Q\[(.+?)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;      $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><ruby class="rb"><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby><span class="rp"> (</span><span class="rt-below">$3</span><span class="rp">) </span></span>:g;
734      $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;      $line =~ s:\[RUBY\[([^]]+)\] \[([^]]+)\]\]:<ruby><rb>$1</rb><rp>(</rp><rt>$2</rt><rp>)</rp></ruby>:g;
735      $line =~ s|''([^']+?)''|<em>$1</em>|g;      $line =~ s:\[RUBYB\[([^]]+)\] \[([^]]+)\]\]:<span class="ruby"><span class="rb">$1</span><span class="rp"> (</span><span class="rt-below">$2</span><span class="rp">) </span></span>:g;
736      $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%\[Q\[([^]]+)\](?: \[&lt;([\x21-\x5A\x5E-\x7E]+)&gt;\])?\]%「<q@{[$2?qq( cite="$2"):'']}>$1</q>」%g;
737      $line =~ s!      $line =~ s|'''([^']+)'''|<strong>$1</strong>|g;
738        (      $line =~ s|''([^']+)''|<em>$1</em>|g;
739          (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;      $line =~ s{
740        |        ((?:$bracket_name))       # [[likethis]], [[#comment]], [[Friend:remotelink]]
741          (?:$bracket_name))      # [[likethis]], [[#comment]], [[Friend:remotelink]]        |\[\[([^[]+?)]&gt;&gt;([0-9]+)]   # [[WikiName]>>1]
       |\[\[([^[]+?)]&gt;&gt;([0-9]+)]  
742        |&gt;&gt;([0-9]+)        |&gt;&gt;([0-9]+)
743      !        |&lt;([A-Za-z0-9%]+:(?:(?!&gt;).)+)&gt;
744        my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5);      }{
745          my ($l, $page,$anchor, $anum, $uri) = ($1, $3,$4, 0+$5, $6);
746        if ($l) {        if ($l) {
747          &make_link($l)          &make_link($l)
748        } elsif (defined $page) {        } elsif (defined $page) {
749          &make_wikilink ($page, anchor => 0+$anchor);          &make_wikilink ($page, anchor => 0+$anchor);
750        } elsif ($anum) {        } elsif ($anum) {
751          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);          qq(<a href="#anchor-$anum" class="wiki-anchor">&gt;&gt;$anum</a>);
752          } elsif ($uri) {
753            &make_urilink ($uri);
754        }        }
755      !gex;      }gex;
756      return $line;      return $line;
757  }  }
758    
# Line 779  sub make_wikilink ($%) { Line 771  sub make_wikilink ($%) {
771    }    }
772  }  }
773    
774    sub make_urilink ($;%) {
775      require URI;
776      my $uri = shift;
777      if ($uri =~ s/^IW://) {       ## InterWiki (not URI)
778        $uri = &unescape ($uri);
779        if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
780          my ($site, $name) = ($1, $2);
781          for ($site, $name) {
782            if (s/^"//) { s/"$//; s/\\(.)/$1/g }
783          }
784          if ($interwiki{$site}) {
785            my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
786            $site = &escape ($site); $name = &escape ($name);
787            qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;">$name</a>&gt;);
788          } else {
789            qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
790          }
791        } else {
792          qq(&lt;不正な <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape($uri)]}>);
793        }
794      } elsif ($uri =~ /^urn:/) {   ## URN
795        my $uri2 = &escape (URI->new ('/uri-res/N2L?'.&unescape ($uri), 'http')->canonical);
796        qq(&lt;<a href="$uri2" title="URI: &lt;$uri&gt; (via &lt;$uri2&gt;)" class="out-of-wiki urn">$uri</a>&gt;);
797      } elsif ($uri =~ s/^MAIL://) {        ## mail address (not URI)
798        my $uri2 = &escape (URI->new ('mailto:'.&unescape ($uri))->canonical);
799        qq(&lt;<a href="$uri2" class="out-of-wiki mail">$uri</a>&gt;);
800      } elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) {   ## image (not URI itself)
801        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
802        qq(<img src="$uri2" alt="" title="URI: &lt;$uri2&gt;" class="out-of-wiki">);
803      } else {      ## misc. URI
804        CGI::Carp::warningsToBrowser (0);
805        my $uri2 = &escape (URI->new (&unescape ($uri))->canonical);
806        CGI::Carp::warningsToBrowser (1);
807        qq(&lt;<a href="$uri2" title="URI: &lt;$uri2&gt;" class="out-of-wiki">$uri</a>&gt;);
808      }
809    }
810    
811    ## to be obsoleted
812  sub make_link {  sub make_link {
813      my $chunk = shift;      my $chunk = shift;
814      # Walrus add (3) start      # Walrus add (3) start
815      $chunk =~ s/^&lt;(.*)&gt;$/$1/;      $chunk =~ s/^&lt;(.*)&gt;$/$1/;
816      my $name  = $chunk;      my $name  = $chunk;
     if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {  
         ($name, $chunk) = ($1, $2);  
     } elsif ($chunk =~ /^mailto:(.*)$/) {  
         $name = $1;  
     }  
     if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {  
         $name = qq(<img src="$name">) ;  
     }  
817      $name = &unarmor_name($name);      $name = &unarmor_name($name);
818      # Walrus add (3) end      # Walrus add (3) end
819      if ($chunk =~ /^(http|https|ftp|news):/) {      if ($chunk =~ /^$embedded_name$/) {
         # Walrus mod (3) start  
 #       if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {  
 #           return qq(<a href="$chunk"><img src="$chunk"></a>);  
 #       } else {  
 #           return qq(<a href="$chunk">$chunk</a>);  
 #       }  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);  
         # Walrus mod (3) end  
     } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {  
         return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;  
     } elsif ($chunk =~ /^mailto:(.*)/) {  
 #       return qq(<a href="$chunk">$2</a>);                 # Walrus del (3)  
         return qq(&lt;<a href="$chunk">$name</a>&gt;);              # Walrus add (3)  
     } elsif ($chunk =~ /^$interwiki_definition$/) {  
 #       return qq(<span class="InterWiki">$chunk</span>);   # Walrus del (3)  
         return qq(<span class="InterWiki">$name</span>);    # Walrus add (3)  
     } elsif ($chunk =~ /^$embedded_name$/) {  
820          return &embedded_to_html($chunk);          return &embedded_to_html($chunk);
821      } else {      } else {
822          $chunk = &unarmor_name($chunk);          $chunk = &unarmor_name($chunk);
823          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.          $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
824          my $cookedchunk = &encode($chunk);          my $cookedchunk = &encode($chunk);
825          if ($chunk =~ /^$interwiki_name$/) {          if ($database{$chunk}) {
             my ($intername, $localname) = ($1, $2);  
             my $remoteurl = $interwiki{$intername};  
             if ($remoteurl) {  
 #               $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e;      # Walrus del (4)  
                 $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)  
 #               return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)  
                 return qq(<a href="$remoteurl">@{[&escape($name)]}</a>);  # Walrus add (3)  
             } else {  
 #               return $chunk;                              # Walrus del (3)  
                 return &escape($name);                               # Walrus add (3)  
             }  
         } elsif ($database{$chunk}) {  
826              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));              my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
827  #           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)
828              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)              return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>);   # Walrus add (3)
# Line 856  sub init_form { Line 849  sub init_form {
849      if (param()) {      if (param()) {
850          foreach my $var (param()) {          foreach my $var (param()) {
851              $form{$var} = param($var);              $form{$var} = param($var);
852          }        }
     } else {  
         $ENV{QUERY_STRING} = $FrontPage;  
853      }      }
854        if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) {
855      my $query = &decode($ENV{QUERY_STRING});        my $query = &decode($main::ENV{QUERY_STRING});
856      if ($page_command{$query}) {        if ($page_command{$query}) {
857          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
858          $form{mypage} = $query;          $form{mypage} = $query;
859      } elsif ($query =~ /^($wiki_name)$/) {        } else {
         $form{mycmd} = 'read';  
         $form{mypage} = $1;  
     } elsif ($database{$query}) {  
         $form{mycmd} = 'read';  
860          $form{mypage} = $query;          $form{mypage} = $query;
861            $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
862          }
863      }      }
864        $form{mypage} ||= 'HomePage';
865    
866      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
867      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 883  sub init_form { Line 873  sub init_form {
873          }          }
874      }      }
875    
876      #      #
877      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
878      #      #
879    
880      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
881      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
# Line 1010  sub print_searchform { Line 1000  sub print_searchform {
1000      my ($word) = @_;      my ($word) = @_;
1001      print <<"EOD";      print <<"EOD";
1002  <form action="$url_cgi" method="get">  <form action="$url_cgi" method="get">
1003      <input type="hidden" name="mycmd" value="search">      <input type="hidden" name="mycmd" value="read">
1004      <input type="text" name="mymsg" value="$word" size="20">      <input type="text" name="mypage" value="$word" size="20">
1005      <input type="submit" value="$resource{searchbutton}">      <input type="submit" value="$resource{searchbutton}">
1006  </form>  </form>
1007  EOD  EOD
# Line 1044  sub print_editform { Line 1034  sub print_editform {
1034    
1035      print <<"EOD";      print <<"EOD";
1036  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1037    <h2>$escapedmypageの編集</h2>
1038      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}
1039      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1040      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="$escapedmypage">
# Line 1060  sub print_editform { Line 1051  sub print_editform {
1051      qq(      qq(
1052          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1053          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1054          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1055            [@{[do {my $n = 0;
1056                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1057                   ++$n}]}]<br>
1058      )      )
1059  ]}  ]}
1060  </form>  </form>
1061  EOD  EOD
1062      unless ($mode{conflict}) {      unless ($mode{conflict}) {
1063          # Show the format rule.          # Show the format rule.
1064          open(FILE, $file_format) or &print_error("($file_format)");          my $help = $database{'WikiEditHelp'};
1065          my $content = join('', <FILE>);          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
1066          &code_convert(\$content, $kanjicode);          print &text_to_html ($help, toc => 0);
1067          close(FILE);      #    open(FILE, $file_format) or &print_error("($file_format)");
1068          print &text_to_html($content, toc=>0);      #    my $content = join('', <FILE>);
1069        #    &code_convert(\$content, $kanjicode);
1070        #    close(FILE);
1071        #    print &text_to_html($content, toc=>0);
1072      }      }
1073  }  }
1074    
# Line 1089  EOD Line 1086  EOD
1086    
1087  sub is_editable {  sub is_editable {
1088      my ($page) = @_;      my ($page) = @_;
1089      if (&is_bracket_name($page)) {      if ($fixedpage{$page} || $page =~ /\s/ || $page =~ /^\#/) {
         return 0;  
     } elsif ($fixedpage{$page}) {  
         return 0;  
     } elsif ($page =~ /\s/) {  
         return 0;  
     } elsif ($page =~ /^\#/) {  
         return 0;  
     } elsif ($page =~ /^$interwiki_name$/) {  
1090          return 0;          return 0;
1091      } else {      } else {
1092          return 1;          return 1;
# Line 1107  sub is_editable { Line 1096  sub is_editable {
1096  # armor_name:  # armor_name:
1097  #   WikiName -> WikiName  #   WikiName -> WikiName
1098  #   not_wiki_name -> [[not_wiki_name]]  #   not_wiki_name -> [[not_wiki_name]]
1099  sub armor_name {  sub armor_name { qq([[$_[0]]]) }
     my ($name) = @_;  
     #if ($name =~ /^$wiki_name$/) {  
     #    return $name;  
     #} else {  
         return "[[$name]]";  
     #}  
 }  
1100    
1101  # unarmor_name:  # unarmor_name:
1102  #   [[bracket_name]] -> bracket_name  #   [[bracket_name]] -> bracket_name
# Line 1128  sub unarmor_name { Line 1110  sub unarmor_name {
1110      }      }
1111  }  }
1112    
 sub is_bracket_name {  
     my ($name) = @_;  
     if ($name =~ /^$bracket_name$/) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
1113  sub decode {  sub decode {
1114      my ($s) = @_;      my ($s) = @_;
1115      $s =~ tr/+/ /;      $s =~ tr/+/ /;
# Line 1199  sub get_now { Line 1172  sub get_now {
1172      return "$year-$mon-$day ($weekday) $hour:$min";      return "$year-$mon-$day ($weekday) $hour:$min";
1173  }  }
1174    
 # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]  
1175  sub init_InterWikiName {  sub init_InterWikiName {
1176      my $content = $database{$InterWikiName};    my @content = split /\n/, $database{$InterWikiName};
1177      while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {    for (@content) {
1178          my ($name, $url) = ($1, $2);      if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
1179          $interwiki{$name} = $url;        $interwiki{$1} = $2;
1180      }      }
1181      }
1182      require Message::Util::Formatter;
1183      $fmt{interwiki} = Message::Util::Formatter->new;
1184      $fmt{interwiki}->{encoded} = sub {
1185        my ($o, $p) = @_;
1186        if ($o->{except}) {
1187          $o->{except} =~ tr/\x00-\x20<>\x23%\x22{|}\x5C^[]`\x7F-\xFF//d;
1188        }
1189        my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1190        $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%02X', unpack 'C', $1/ge;
1191        $s;
1192      };
1193      $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
1194        my ($o, $p) = @_;
1195        my $s = $p->{name};
1196        $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/;
1197        &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis'));
1198      };
1199  }  }
1200    
 sub interwiki_convert {  
     my ($type, $localname) = @_;  
     if ($type eq 'sjis' or $type eq 'euc') {  
         &code_convert(\$localname, $type);  
         return &encode($localname);  
     } elsif ($type eq 'ykwk') {  
         # for YukiWiki1  
         if ($localname =~ /^$wiki_name$/) {  
             return $localname;  
         } else {  
             &code_convert(\$localname, 'sjis');  
             return &encode("[[" . $localname . "]]");  
         }  
     } elsif ($type eq 'asis') {  
         return $localname;  
     # Walrus add (4) start  
     } elsif ($type eq 'isbn') {  
         $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/);  
         return $localname;  
     # Walrus add (4) end  
     } else {  
         return $localname;  
     }  
 }  
1201    
1202  sub get_info {  sub get_info {
1203      my ($page, $key) = @_;      my ($page, $key) = @_;
# Line 1286  sub is_frozen { Line 1252  sub is_frozen {
1252    
1253  sub do_comment {  sub do_comment {
1254      my ($content) = $database{$form{mypage}};      my ($content) = $database{$form{mypage}};
1255      my $datestr = &get_now;      my $default_name;   ## this code does not strict.
1256      my $namestr = $form{myname} || $DEFAULT_embed_comment_name;      $default_name = $1 if $content =~ /default-name="([^"]+)"/;
1257        my $datestr = '[WEAK['.&get_now.']]';
1258        my $namestr = $form{myname} || $default_name || $DEFAULT_embed_comment_name;
1259        ($namestr = '', $datestr = '') if $form{myname} eq 'nodate';
1260      if ($namestr =~ /^(?:>>)?[0-9]/) {      if ($namestr =~ /^(?:>>)?[0-9]/) {
1261        $namestr = qq( ''$namestr'': );        $namestr = qq( ''$namestr'': );
1262      } else {      } elsif (length $namestr) {
1263        $namestr = qq( ''[[$namestr]]'': );        $namestr = qq( ''[[$namestr]]'': );
1264      }      }
1265      my $anchor = 0;      my $anchor = 0;
# Line 1309  sub do_comment { Line 1278  sub do_comment {
1278        $i++; $embed;        $i++; $embed;
1279      }ge;      }ge;
1280      unless ($o) {      unless ($o) {
1281          $content = "#?SuikaWiki/0.9\n\n" unless $content;
1282          $content .= "\n" unless $content =~ /\n$/s;
1283        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";        $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n";
1284      }      }
1285      $form{__comment_anchor_index} = $anchor;      $form{__comment_anchor_index} = $anchor;
1286      if ($form{mymsg}) {      if ($form{mymsg} || $form{myname}) {
1287          $form{mymsg} = $content;          $form{mymsg} = $content;
1288          $form{mytouch} = 'on';          $form{mytouch} = 'on';
1289          &do_write;          &do_write;
# Line 1329  sub embedded_to_html { Line 1300  sub embedded_to_html {
1300        unless ($main::_EMBEDED) {        unless ($main::_EMBEDED) {
1301          my $lastmodified = &get_info($form{mypage}, $info_LastModified);          my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1302          return <<"EOD";          return <<"EOD";
1303  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}">  <form action="$url_cgi" method="post" id="x-comment-@{[++$CommentIndex]}" class="comment"><p>
1304      <input type="hidden" name="mycmd" value="comment">      <input type="hidden" name="mycmd" value="comment">
1305      <input type="hidden" name="mypage" value="$form{mypage}">      <input type="hidden" name="mypage" value="$form{mypage}">
1306      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1307      <input type="hidden" name="mytouch" value="on">      <input type="hidden" name="mytouch" value="on">
1308      <input type="hidden" name="comment_index" value="$CommentIndex">      <input type="hidden" name="comment_index" value="$CommentIndex">
1309      $embed_comment_Name_Prompt      $embed_comment_Name_Prompt
1310      <input type="text" name="myname" value="" size="10">      <input type="text" name="myname" value="" size="10" class="comment-name">
1311      <input type="text" name="mymsg" value="" size="60">      <input type="text" name="mymsg" value="" size="60" class="comment-msg">
1312      <input type="submit" value="$resource{commentbutton}">      <input type="submit" value="$resource{commentbutton}" class="comment-submit">
1313  </form>  </p></form>
1314  EOD  EOD
1315       } else {       } else {
1316          return <<"EOD";          return <<"EOD";
# Line 1354  EOD Line 1325  EOD
1325  EOD  EOD
1326      }      }
1327    } elsif ($embedded =~ /$embed_command{searched}/) {    } elsif ($embedded =~ /$embed_command{searched}/) {
1328      return get_search_result ($1);      return get_search_result ($1, -match_myself => 1);
1329      # Walrus add (5) start      # Walrus add (5) start
1330      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {      } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1331          $_ = &make_interwiki_box($1, $2);          $_ = &make_interwiki_box($1, $2);
# Line 1372  EOD Line 1343  EOD
1343        } elsif (length $content) {        } elsif (length $content) {
1344          $r = "<pre>@{[&escape ($content)]}</pre>";          $r = "<pre>@{[&escape ($content)]}</pre>";
1345        } else {        } else {
1346          $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9');          $r = &text_to_html ("[INS[\n埋め込まれている [[$name]] はまだ書かれていません。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1347        }        }
1348      } else {    ## nested #EMBED      } else {    ## nested #EMBED
1349        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');        $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9');
1350      }      }
1351      return qq(<blockquote title="@{[&escape($name)]}">$r</blockquote>);      return qq(<blockquote title="@{[&escape($name)]}" class="wiki-embed">$r<div class="cite-note">『<cite><a href="$url_cgi?@{[&encode($name)]}" class="wiki">@{[&escape($name)]}</a></cite>』</div></blockquote>);
1352    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {    } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) {
1353      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);      return qq(<a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">$1</a>);
1354    } else {    } else {
# Line 1422  EOD Line 1393  EOD
1393    
1394  sub code_convert {  sub code_convert {
1395      my ($contentref, $code) = (shift, shift || $kanjicode);      my ($contentref, $code) = (shift, shift || $kanjicode);
1396        $code = 'jis' if $code =~ /iso/;
1397        $code = 'euc' if $code =~ /euc/;
1398        $code = 'sjis' if $code =~ /shift/;
1399        $code = 'utf8' if $code =~ /utf/;
1400  #   &Jcode::convert($contentref, $code);       # for Jcode.pm  #   &Jcode::convert($contentref, $code);       # for Jcode.pm
1401      &jcode::convert($contentref, $code);       # for jcode.pl      &jcode::convert($contentref, $code);       # for jcode.pl
1402      return $$contentref;      return $$contentref;

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24