/[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.31 by wakaba, Thu Nov 14 10:22:19 2002 UTC revision 1.35 by wakaba, Thu Dec 5 04:32:27 2002 UTC
# Line 26  use Yuki::DiffText qw(difftext); Line 26  use Yuki::DiffText qw(difftext);
26  use Yuki::YukiWikiDB;  use Yuki::YukiWikiDB;
27  use AnyDBM_File;  use AnyDBM_File;
28  require 'jcode.pl';  require 'jcode.pl';
29  # use Jcode;  require Jcode;
30  use Fcntl;  use Fcntl;
31  my $version = '2.0.beta1.2002-05-29';  my $version = '2.0.beta1.2002-05-29';
32  my $walversion;  my $walversion;
# Line 50  my $modifier_rss_description = 'This is Line 50  my $modifier_rss_description = 'This is
50  #  #
51  # You MAY modify following variables.  # You MAY modify following variables.
52  #  #
53    $SuikaWiki::Plugin::plugin_directory = q(./SuikaWiki/Plugin/);
54  my $file_touch = "$modifier_dir_data/touched.txt";  my $file_touch = "$modifier_dir_data/touched.txt";
55  my $file_resource = "$modifier_dir_data/resource.txt";  my $file_resource = "$modifier_dir_data/resource.txt";
56  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";  my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
# Line 97  my $DEFAULT_embed_comment_name = '名無し Line 98  my $DEFAULT_embed_comment_name = '名無し
98  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)  my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$';    # Walrus add (5)
99  my %embed_command = (  my %embed_command = (
100          searched        => '^\[\[#searched:([^\]]+)\]\]$',          searched        => '^\[\[#searched:([^\]]+)\]\]$',
101        form => qw/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
102  );  );
103  ##############################  ##############################
104  my $info_LastModified = 'LastModified';  my $info_LastModified = 'LastModified';
# Line 116  my %fixedpage = ( Line 118  my %fixedpage = (
118      $AdminChangePassword => 1,      $AdminChangePassword => 1,
119      $CompletedSuccessfully => 1,      $CompletedSuccessfully => 1,
120      #$FrontPage => 1,      #$FrontPage => 1,
121        WikiUserAgentList => 1,
122        WikiPluginInfo    => 1,
123  );  );
124  my %form;  my %form;
125  my %database;  my %database;
# Line 131  my %page_command = ( Line 135  my %page_command = (
135      $RssPage => 'rss',      $RssPage => 'rss',
136      $AdminChangePassword => 'adminchangepasswordform',      $AdminChangePassword => 'adminchangepasswordform',
137      #$FrontPage => 'FrontPage',      #$FrontPage => 'FrontPage',
138        WikiPluginInfo       => 'x_WikiPluginInfo',
139  );  );
140  my %command_do = (  my %command_do = (
141      read => \&do_read,      read => \&do_read,
# Line 151  my %command_do = ( Line 156  my %command_do = (
156      rss => \&do_rss,      rss => \&do_rss,
157      diff => \&do_diff,      diff => \&do_diff,
158      interwikibox => \&do_interwiki_box, # Walrus add (5)      interwikibox => \&do_interwiki_box, # Walrus add (5)
159        wikiform => \&do_wikiform,
160        x_WikiPluginInfo  => \&do_wikiplugininfo,
161  );  );
162  ##############################  ##############################
 my @ignore_html_page = ('FrontPage');        # Walrus add (6)  
 my @ignore_html_tags = ('a', 'br', 'img');   # Walrus add (6)  
163  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)  my $walversion = '2.0.beta1.wal.1';          # Walrus add (1)
164  ##############################  ##############################
165  # &test_convert;  # &test_convert;
166  &main;  my $UA = '';  ## User agent name
 exit(0);  
167  ##############################  ##############################
168    
169  sub main {  sub main {
170        $UA = $main::ENV{HTTP_USER_AGENT};
171      &init_resource;      &init_resource;
172      &open_db;      &open_db;
173      &init_form;      &init_form;
# Line 179  sub do_read { Line 184  sub do_read {
184    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
185    my $lm = &get_info($form{mypage}, $info_LastModified);    my $lm = &get_info($form{mypage}, $info_LastModified);
186    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
187      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
188    my ($r, $c) = get_search_result ($form{mypage});    my ($r, $c) = get_search_result ($form{mypage});
189    my $rl = wiki::referer::list_html ($form{mypage});    my $rl = wiki::referer::list_html ($form{mypage});
190    my @toc;    my @toc;
# Line 189  sub do_read { Line 195  sub do_read {
195      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
196      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF      ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF
197      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF      ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF
198      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s;      $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+##s;
199      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {      if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) {
200        &print_header ($form{mypage}, -last_modified => $lm,        &print_header ($form{mypage}, -last_modified => $lm,
201          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);          -content_format => $cf, -noindex => $cf =~ /obsoleted="yes"/);
202        &print_content ($content, content_format => $cf, last_modified => $lm,        &print_content ($content, content_format => $cf, last_modified => $lm,
203          -toc => \@toc);          -toc => \@toc);
204        print &text_to_html (q([[#comment]])) unless $cf =~ /obsoleted="yes"/;        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$fixedpage{$form{mypage}};
205      } else {      } else {
206        &print_header($form{mypage}, -last_modified => $lm);        &print_header($form{mypage}, -last_modified => $lm);
207        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
208      }      }
209      if ($c) {      if ($c) {
210        print q{<h2 id="wikipage-see-also">See also</h2>};        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>See also</h2>};
211        print $r;        print $r;
212      }      }
213      if ($rl) {      if ($rl) {
214        print qq(<div id="wikipage-referer"><h2>参照元</h2>\n$rl</div>\n);        print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>参照元</h2>\n$rl</div>\n);
215      }      }
216    &print_footer($form{mypage}, $lm);    &print_footer($form{mypage}, $lm);
217  }  }
# Line 226  sub do_output_css { Line 232  sub do_output_css {
232    }    }
233  }  }
234    
235    sub id_and_name ($) {
236        my $name = shift;
237        if ($UA =~ m#Mozilla/[12]\.#) {
238          qq{id="$name"><a name="$name"></a};
239        } else {
240            qq{id="$name"};
241        }
242    }
243    
244  sub do_edit {  sub do_edit {
245      my ($page) = &unarmor_name(&armor_name($form{mypage}));      my ($page) = &unarmor_name(&armor_name($form{mypage}));
246      &print_header($page, -noindex => 1);      &print_header($page, -noindex => 1);
# Line 237  sub do_edit { Line 252  sub do_edit {
252          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);          &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
253      }      }
254      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
255        wiki::useragent::add ($ENV{HTTP_USER_AGENT});
256      my ($r, $c) = get_search_result ($form{mypage});      my ($r, $c) = get_search_result ($form{mypage});
257      my $rl = wiki::referer::list_html ($form{mypage});      my $rl = wiki::referer::list_html ($form{mypage});
258      if ($c) {      if ($c) {
# Line 341  sub do_write { Line 357  sub do_write {
357              &update_recent_changes;              &update_recent_changes;
358          }          }
359          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
360          &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?'.&encode($form{mypage}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":''));          my $fragment;
361            if ($form{__comment_anchor_index}) {
362                $fragment = qq(anchor-$form{__comment_anchor_index});
363            } elsif ($form{__wikiform_anchor_index}) {
364                $fragment = qq(wikiform-$form{__wikiform_anchor_index});
365            }
366            &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($fragment?'#'.$fragment:''));
367          &print_message($resource{saved});          &print_message($resource{saved});
368          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
369          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 373  sub do_search { Line 395  sub do_search {
395  }  }
396    
397  sub get_search_result ($;%) {  sub get_search_result ($;%) {
398    my $word = shift;    my $word = lc shift;
399    my %option = @_;    my %option = @_;
400    my @r;    my @r;
401    foreach my $page (keys %database) {    foreach my $page (keys %database) {
# Line 382  sub get_search_result ($;%) { Line 404  sub get_search_result ($;%) {
404      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
405      $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;      $cf = $1 if $content =~ s/^\#\?([^\x0A\x0D]+)//s;
406      next if $cf =~ /obsoleted="yes"/;      next if $cf =~ /obsoleted="yes"/;
407      if (index ($page, $word) > -1) {      if (index (lc $page, $word) > -1) {
408        my $c = $content =~ s/\Q$word\E/$word/g;        my $c = $content =~ s/\Q$word\E//gi;
409        push @r, [$page, $c+20];        push @r, [$page, $c+20];
410      } elsif (index ($word, $page) > -1) {      } elsif (index ($word, lc $page) > -1) {
411        my $c = $content =~ s/\Q$word\E/$word/g;        my $c = $content =~ s/\Q$word\E//gi;
412        push @r, [$page, $c+10];        push @r, [$page, $c+10];
413      } elsif (my $c = $content =~ s/\Q$word\E/$word/g) {      } elsif (my $c = $content =~ s/\Q$word\E//gi) {
414        push @r, [$page, $c];        push @r, [$page, $c];
415      }      }
416    }    }
417    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#g; $s };    my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s };
418    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;    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;
419    $r = qq|<ul class="search-result">$r</ul>| if $r;    $r = qq|<ul class="search-result">$r</ul>| if $r;
420    get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};    get_message ($resource{notfound}) if @r == 0 && $option{-output_not_found};
# Line 446  sub print_header ($;%) { Line 468  sub print_header ($;%) {
468          $bodyclass = "frozen";          $bodyclass = "frozen";
469      }      }
470      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
471      print qq{Refresh: 0; url="$option{-goto}"\n} if $option{-goto};      if ($option{-goto}) {
472          if ($UA =~ m#Mozilla/[12]\.|Opera#) {
473              $option{-goto} =~ tr/;/&/;
474              print qq{Refresh: 0; url=$option{-goto}\n};
475              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
476          } else {
477              print qq{Refresh: 0; url="$option{-goto}"\n};
478              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
479          }
480        }
481      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
482        my $meta_ct = '';
483        if ($UA =~ m#Mozilla/2#) {
484            $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
485            print qq{Content-Type: $meta_ct\n};
486            $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
487        } else {
488            print qq{Content-Type: text/html; charset=$charset\n};
489        }
490      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
491      my $escapedpage = &escape($page);      my $escapedpage = &escape($page);
492      print <<"EOD";      print <<"EOD";
 Content-type: text/html; charset=$charset  
493  Content-Language: $lang  Content-Language: $lang
494  Content-Style-Type: text/css  Content-Style-Type: text/css
495    
# Line 461  Content-Style-Type: text/css Line 499  Content-Style-Type: text/css
499      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
500  <html lang="$lang">  <html lang="$lang">
501  <head>  <head>
502        $meta_ct$option{-goto}
503      <title>$escapedpage</title>      <title>$escapedpage</title>
504      <link rel="index" href="$url_cgi?$IndexPage">      <link rel="index" href="$url_cgi?$IndexPage">
505      <link rel="help" href="$url_cgi?WikiHelp">      <link rel="help" href="$url_cgi?WikiHelp">
# Line 476  EOD Line 515  EOD
515  EOD  EOD
516  }  }
517    
518    sub x_charset ($) {
519        my $charset = lc shift;
520        if ($charset eq 'euc-jp') {
521            $charset = 'x-euc-jp';
522        } elsif ($charset eq 'shift_jis') {
523            $charset = 'x-sjis';
524        }
525        $charset;
526    }
527    
528  sub print_navigate_links (@) {  sub print_navigate_links (@) {
529    my ($page) = @_;    my ($page) = @_;
530      my $editable = 0;      my $editable = 0;
# Line 501  sub print_navigate_links (@) { Line 550  sub print_navigate_links (@) {
550          qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )          qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">編集</a> | )
551          : qq()          : qq()
552      ]}      ]}
553        <a href="$url_cgi?mycmd=read;mypage=$cookedpage;x-param=@{[time.[0..9]->[rand 10]]}">表示</a> |
554      @{[ $admineditable      @{[ $admineditable
555          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )          ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
556          : qq()          : qq()
# Line 527  EOH Line 577  EOH
577    
578  sub print_footer {  sub print_footer {
579      my ($page, $lm) = @_;      my ($page, $lm) = @_;
580        my $epage = &encode ($page);
581      $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)
582      # Walrus mod (1) start      # Walrus mod (1) start
583    my $cvslog1 = q$Revision$;    my $cvslog1 = q$Revision$;
# Line 542  sub print_footer { Line 593  sub print_footer {
593  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
594  <a href="/search/" title="このサーバーの検索">検索</a>]  <a href="/search/" title="このサーバーの検索">検索</a>]
595  </div>  </div>
596    <div class="myuri">
597        &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
598    </div>
599  </div>  </div>
600  $walrus_log  $walrus_log
601  </body>  </body>
602  </html>  </html>
603  EOD  EOD
 #       print <<"EOD";  
 #   <hr>  
 #   <address class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version  
 #       &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />  
 #       Modified by <a href="$modifier_url">$modifier_name</a>.  
 #   </address>  
 #   <p class="footer">  
 #       <a href="http://www.hyuki.com/yukiwiki/">$icontag</a>  
 #   </p>  
 #   </body>  
 #   </html>  
 #   EOD  
     # Walrus mod (1) end  
604  }  }
605    
606  sub escape {  sub escape {
# Line 727  sub back_push { Line 767  sub back_push {
767  sub inline {  sub inline {
768      my ($line) = @_;      my ($line) = @_;
769      $line = &escape($line);      $line = &escape($line);
770      $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g;      $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
771        $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3</@{[lc $1]}>}g;
772      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
773      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
774      $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;      $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;
# Line 784  sub make_urilink ($;%) { Line 825  sub make_urilink ($;%) {
825        if ($interwiki{$site}) {        if ($interwiki{$site}) {
826          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));          my $uri = &escape ($fmt{interwiki}->replace ($interwiki{$site} => {site => $site, name => $name}));
827          $site = &escape ($site); $name = &escape ($name);          $site = &escape ($site); $name = &escape ($name);
828          qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;">$name</a>&gt;);          qq(&lt;<a href="$uri" class="out-of-wiki interwiki" title="$name ($site); URI: &lt;$uri&gt;"><span class="interwiki-site">$site:</span><span class="interwiki-name">$name</span></a>&gt;);
829        } else {        } else {
830          qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);          qq(&lt;未登録の <a href="$url_cgi?InterWikiName" class="wiki">InterWikiName</a>: @{[&escape ($site)]}>);
831        }        }
# Line 808  sub make_urilink ($;%) { Line 849  sub make_urilink ($;%) {
849    }    }
850  }  }
851    
852    my $FormIndex = 0;
853    sub make_custom_form ($$$$) {
854        my ($wfname, $definition, $template, $option) = @_;
855        ## $template and $option is currently not used in this procedure.
856        unless ($main::_EMBEDED) {
857            $FormIndex++;
858            if (length $definition) {
859                my $param = bless {}, 'SuikaWiki::Plugin';
860                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
861                &load_formatter (qw/form_input form_option/);
862                $definition = &unescape ($definition);
863                $definition =~ s/\\(.)/$1/g;
864                $definition .= ' %submit;' if $definition !~ /%submit/;
865                $option = &unescape ($option);
866                $option =~ s/\\(.)/$1/g;
867                $fmt{form_option}->replace ($option, $param);
868                my $target_page = $param->{output}->{page} || $form{mypage};
869                $param->{form_disabled} = 1 if $fixedpage{$target_page};
870                my $target_form = $param->{output}->{id};
871                my $r = <<EOH;
872    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
873      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
874      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
875      <input type="hidden" name="myLastModified" value="$lastmodified">
876      <input type="hidden" name="mytouch" value="on">
877      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
878    EOH
879                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
880                $r .= $fmt{form_input}->replace ($definition, $param);
881                $r .= <<EOH;
882    </form>
883    EOH
884                $r;
885           } else {  ## No input-interface WikiForm
886               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
887           }
888        } else {
889            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
890        }
891    }
892    
893  ## to be obsoleted  ## to be obsoleted
894  sub make_link {  sub make_link {
895      my $chunk = shift;      my $chunk = shift;
# Line 851  sub init_form { Line 933  sub init_form {
933              $form{$var} = param($var);              $form{$var} = param($var);
934        }        }
935      }      }
936      if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;]/) {      $form{mypage} = &code_convert(\$form{mypage}, $kanjicode);
937        if ($main::ENV{QUERY_STRING} && $main::ENV{QUERY_STRING} !~ /[&;=]/) {
938        my $query = &decode($main::ENV{QUERY_STRING});        my $query = &decode($main::ENV{QUERY_STRING});
939          $query = &code_convert(\$query, $kanjicode);
940        if ($page_command{$query}) {        if ($page_command{$query}) {
941          $form{mycmd} = $page_command{$query};          $form{mycmd} = $page_command{$query};
942          $form{mypage} = $query;          $form{mypage} = $query;
# Line 862  sub init_form { Line 946  sub init_form {
946        }        }
947      }      }
948      $form{mypage} ||= 'HomePage';      $form{mypage} ||= 'HomePage';
949        $form{mycmd} ||= 'read';
950    
951      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
952      # mypreview_adminedit   -> do_adminedit, with preview.      # mypreview_adminedit   -> do_adminedit, with preview.
# Line 877  sub init_form { Line 962  sub init_form {
962      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
963      #      #
964    
965        for (grep /^wikiform__/, keys %form) {
966            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
967        }
968      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
969      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
970  }  }
# Line 884  sub init_form { Line 972  sub init_form {
972  sub update_recent_changes {  sub update_recent_changes {
973      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
974      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
975        shift (@oldupdates); ## '#?' magic line
976      my @updates;      my @updates;
977      foreach (@oldupdates) {      foreach (@oldupdates) {
978          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;          /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/;
# Line 896  sub update_recent_changes { Line 985  sub update_recent_changes {
985        unshift @updates, $update;        unshift @updates, $update;
986      }      }
987      splice(@updates, $maxrecent + 1);      splice(@updates, $maxrecent + 1);
988      $database{$RecentChanges} = join("\n", @updates);      $database{$RecentChanges} = "#?SuikaWiki/0.9\n" . join("\n", @updates);
989      if ($file_touch) {      if ($file_touch) {
990          open(FILE, "> $file_touch");          open(FILE, "> $file_touch");
991          print FILE localtime() . "\n";          print FILE localtime() . "\n";
# Line 1184  sub init_InterWikiName { Line 1273  sub init_InterWikiName {
1273    $fmt{interwiki}->{encoded} = sub {    $fmt{interwiki}->{encoded} = sub {
1274      my ($o, $p) = @_;      my ($o, $p) = @_;
1275      if ($o->{except}) {      if ($o->{except}) {
1276        $o->{except} =~ tr/\x00-\x20<>\x23%\x22{|}\x5C^[]`\x7F-\xFF//d;        $o->{except} =~ tr/\x00-\x20\x22\x23%\x2D<>^[\x5C]`{|}\x7F-\xFF//d;
1277      }      }
1278      my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');      my $s = &code_convert (\$p->{name}, $o->{charset} || 'iso-2022-7bit');
1279      $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%02X', unpack 'C', $1/ge;      $s =~ s/([^$o->{except}A-Za-z0-9_-])/sprintf '%%%02X', unpack 'C', $1/ge;
1280      $s;      $s;
1281    };    };
1282    $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1    $fmt{interwiki}->{ykwk} = sub {       ## YukiWiki1
# Line 1262  sub do_comment { Line 1351  sub do_comment {
1351      } elsif (length $namestr) {      } elsif (length $namestr) {
1352        $namestr = qq( ''[[$namestr]]'': );        $namestr = qq( ''[[$namestr]]'': );
1353      }      }
1354      my $anchor = 0;      my $anchor = &get_new_anchor_index ($content);
     $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;  
     $anchor++;  
1355      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1356      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1357        my $embed = $1;        my $embed = $1;
# Line 1293  sub do_comment { Line 1380  sub do_comment {
1380      }      }
1381  }  }
1382    
1383    sub get_new_anchor_index ($) {
1384        my $content = shift;
1385        my $anchor = 0;
1386        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1387        $anchor + 1;
1388    }
1389    
1390  my $CommentIndex = 0;  my $CommentIndex = 0;
1391  sub embedded_to_html {  sub embedded_to_html {
1392      my ($embedded) = @_;      my ($embedded) = @_;
# Line 1356  EOD Line 1450  EOD
1450    }    }
1451  }  }
1452    
1453    sub load_formatter (@) {
1454        for my $t (@_) {
1455            unless ($fmt{$t}) {
1456                $fmt{$t} = Message::Util::Formatter->new;
1457                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1458                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1459                }
1460            }
1461        }
1462    }
1463    
1464    sub do_wikiform {
1465        my $content = $database{$form{mypage}};
1466        my $anchor = &get_new_anchor_index ($content);
1467        &load_formatter (qw/form_template form_option/);
1468        my $write = 0;
1469        my $i = 1;
1470        $content =~ s{$embed_command{form}}{
1471            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1472            if (($wfname && $wfname eq $form{wikiform_targetform})
1473                || $i == $form{wikiform_index}) {
1474                $template =~ s/\\(.)/$1/g;
1475                $option =~ s/\\(.)/$1/g;
1476                my $param = bless {}, 'SuikaWiki::Plugin';
1477                $param->{page} = $form{mypage};
1478                $param->{form_index} = $i;
1479                $param->{form_name} = $wfname;
1480                $param->{anchor_index} = $anchor;
1481                $param->{argv} = \%form;
1482                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1483                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1484                $fmt{form_option}->replace ($option, $param);
1485                my $t = 1;
1486                for (@{$param->{require}||[]}) {
1487                  (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1488                }
1489                $t = $fmt{form_template}->replace ($template, $param) if $t;
1490                if (length $t) {
1491                    if ($param->{output}->{reverse}) {
1492                        $embed .= "\n" . $t;
1493                    } else {
1494                        $embed = $t . "\n" . $embed;
1495                    }
1496                    $write = 1;
1497                    $form{__comment_anchor_index} = $anchor
1498                      if $param->{anchor_index_};  ## $anchor is used!
1499                }
1500                $form{__wikiform_anchor_index} = $i;
1501                undef $form{wikiform_targetform};  ## make sure never to match
1502                undef $form{wikiform_index};       ## with WikiForm in rest of page
1503            }
1504            $i++; $embed;
1505        }ge;
1506        unless ($write) {
1507          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1508          #$content .= "\n" unless $content =~ /\n$/s;
1509          #
1510        }
1511        if ($write) {
1512            $form{mymsg} = $content;
1513            $form{mytouch} = 'on';
1514            &do_write;
1515        } else {
1516            $form{mycmd} = 'read';
1517            &do_read;
1518        }
1519    }
1520    
1521    
1522  # Walrus add (5) start  # Walrus add (5) start
1523  sub do_interwiki_box {  sub do_interwiki_box {
1524      my $remoteurl = $interwiki{$form{'myintername'}};      my $remoteurl = $interwiki{$form{'myintername'}};
# Line 1397  sub code_convert { Line 1560  sub code_convert {
1560      $code = 'euc' if $code =~ /euc/;      $code = 'euc' if $code =~ /euc/;
1561      $code = 'sjis' if $code =~ /shift/;      $code = 'sjis' if $code =~ /shift/;
1562      $code = 'utf8' if $code =~ /utf/;      $code = 'utf8' if $code =~ /utf/;
1563  #   &Jcode::convert($contentref, $code);       # for Jcode.pm      &Jcode::convert($contentref, $code);       # for Jcode.pm
1564      &jcode::convert($contentref, $code);       # for jcode.pl  #    &jcode::convert($contentref, $code);       # for jcode.pl
1565        &jcode::tr ($contentref, "\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xE4\xA1\xE3\xA1\xC0\xA1\xA1" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@='"~-><\ )) if $code eq 'euc';
1566      return $$contentref;      return $$contentref;
1567  }  }
1568    
# Line 1538  sub is_exist_page { Line 1702  sub is_exist_page {
1702  }  }
1703    
1704  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1705    sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1706    
1707    sub do_wikiplugininfo {
1708        &print_header (q(WikiPluginInfo));
1709        print text_to_html (&SuikaWiki::Plugin::make_info_page);
1710        &print_footer (q(WikiPluginInfo));
1711    }
1712    
1713  package wiki::referer;  package wiki::referer;
1714  sub add ($$) {  sub add ($$) {
# Line 1619  sub __decode ($) { Line 1790  sub __decode ($) {
1790    main::code_convert (\$s);    main::code_convert (\$s);
1791  }  }
1792    
1793    package wiki::useragent;
1794    
1795    sub add ($) {
1796      my $s = shift;
1797      return unless length $s;
1798      $s =~ s/([\x00-\x08\x0A-\x1F\x25\x7F-\xFF])/sprintf '%%%02X', unpack 'C', $1/g;
1799      my %ua;
1800      for (split /\n/, &main::__get_database('WikiUserAgentList')) {
1801        if (/^-\[(\d+)\] (.+)$/) {
1802          my ($t, $n) = ($1, $2);
1803          $n =~ tr/\x0A\x0D//d;
1804          $ua{$n} = $t;
1805        }
1806      }
1807      $ua{$s}++;
1808      my $s = qq(#?SuikaWiki/0.9\n);
1809      for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
1810        $s .= sprintf qq(-[%d] %s\n), $ua{$_}, $_;
1811      }
1812      &main::__set_database ('WikiUserAgentList' => $s);
1813    }
1814    
1815    package SuikaWiki::Plugin;
1816      our $plugin_directory;  # defined in top of this file.
1817      our %List;
1818    
1819    sub escape ($$) { main::escape ($_[1]) }
1820    sub unescape ($$) { main::unescape ($_[1]) }
1821    sub encode ($$) { main::encode ($_[1]) }
1822    sub decode ($$) { main::decode ($_[1]) }
1823    sub __get_datetime ($) { main::get_now () }
1824    
1825    sub regist ($@) {
1826        my $pack = shift;
1827        for (@_) {
1828            push @{$List{$_}}, $pack;
1829        }
1830    }
1831    
1832    sub import_plugins () {
1833        opendir PDIR, $plugin_directory;
1834        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1835        closedir PDIR;
1836        for (@plugin) {
1837            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1838            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1839        }
1840    }
1841    
1842    sub make_info_page () {
1843        my $r = <<EOH;
1844    EOH
1845        unless ($List{_all}) {
1846            $r .= qq('''No plugin is installed!'''\n);
1847        } else {
1848            my $index = 0;
1849            for my $package (sort @{$List{_all}}) {
1850                $index++;
1851                my $prop = $package->property ();
1852                $r .= <<EOH;
1853    *$package
1854    
1855    [$index] '''$prop->{name}''' (Version $prop->{version})
1856    <$prop->{uri}>
1857    
1858    Provide:
1859    @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1860        $t .= qq(-''$f''\n);
1861        for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1862             $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1863        }
1864    }$t}]}
1865    
1866    EOH
1867            }
1868        }
1869        $r;
1870    }
1871    
1872    &import_plugins ();
1873    
1874    package main;
1875    &main;
1876    exit 0;
1877    
1878  1;  1;
1879  __END__  __END__
1880  =head1 NAME  =head1 NAME

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24