/[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.32 by wakaba, Sun Dec 1 04:32:50 2002 UTC revision 1.36 by wakaba, Tue Dec 10 07:27:38 2002 UTC
# 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 117  my %fixedpage = ( Line 119  my %fixedpage = (
119      $CompletedSuccessfully => 1,      $CompletedSuccessfully => 1,
120      #$FrontPage => 1,      #$FrontPage => 1,
121      WikiUserAgentList => 1,      WikiUserAgentList => 1,
122        WikiPluginInfo    => 1,
123  );  );
124  my %form;  my %form;
125  my %database;  my %database;
# Line 132  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 152  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  my $UA = '';  my $UA = '';  ## User agent name
 &main;  
 exit(0);  
167  ##############################  ##############################
168    
169  sub main {  sub main {
# Line 218  sub do_output_css { Line 220  sub do_output_css {
220    my $content = $database{$form{mypage}};    my $content = $database{$form{mypage}};
221    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {    if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
222      my $lm = &get_info($form{mypage}, $info_LastModified);      my $lm = &get_info($form{mypage}, $info_LastModified);
223          print scalar make_navigate_links ($form{mypage});
224      print "Content-Type: text/css; charset=$charset\n";      print "Content-Type: text/css; charset=$charset\n";
225      print "Last-Modified: $lm\n";      print "Last-Modified: $lm\n";
226      print "\n";      print "\n";
# Line 232  sub do_output_css { Line 235  sub do_output_css {
235    
236  sub id_and_name ($) {  sub id_and_name ($) {
237      my $name = shift;      my $name = shift;
238      if ($UA =~ m#Mozilla/2#) {      if ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {
239        qq{id="$name"><a name="$name"></a};        qq{id="$name"><a name="$name"></a};
240      } else {      } else {
241          qq{id="$name"};          qq{id="$name"};
# Line 355  sub do_write { Line 358  sub do_write {
358              &update_recent_changes;              &update_recent_changes;
359          }          }
360          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});          &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
361          &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($form{__comment_anchor_index}?"#anchor-$form{__comment_anchor_index}":''));          my $fragment = '';
362            $fragment .= qq(;after_edit_cmd=@{[&encode($form{after_edit_cmd})]}) if $form{after_edit_cmd};
363            if ($form{__comment_anchor_index}) {
364                $fragment .= qq(#anchor-$form{__comment_anchor_index});
365            } elsif ($form{__wikiform_anchor_index}) {
366                $fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
367            }
368            &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
369          &print_message($resource{saved});          &print_message($resource{saved});
370          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");          &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
371          &print_footer($CompletedSuccessfully);          &print_footer($CompletedSuccessfully);
# Line 461  sub print_header ($;%) { Line 471  sub print_header ($;%) {
471      }      }
472      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;      $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/;
473      if ($option{-goto}) {      if ($option{-goto}) {
474        if ($UA =~ m#Mozilla/2|Opera#) {        if ($UA =~ m#Opera|MSIE 2\.#) {
475            $option{-goto} =~ tr/;/&/;            $option{-goto} =~ tr/;/&/ if $UA =~ m#Opera#;
476          print qq{Refresh: 0; url=$option{-goto}\n};            print qq{Refresh: 0; url=$option{-goto}\n};
477              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=$option{-goto}">);
478        } else {        } else {
479          print qq{Refresh: 0; url="$option{-goto}"\n};            $option{-goto} =~ tr/;/&/ if $UA =~ m#Mozilla/[1-4]\.#;
480              print qq{Refresh: 0; url="$option{-goto}"\n};
481              $option{-goto} = qq(<meta http-equiv="refresh" content="0; url=&quot;@{[&escape($option{-goto})]}&quot;">);
482        }        }
483      }      }
484      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};      print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified};
# Line 474  sub print_header ($;%) { Line 487  sub print_header ($;%) {
487          $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};          $meta_ct = qq{text/html; charset=@{[&x_charset($charset)]}};
488          print qq{Content-Type: $meta_ct\n};          print qq{Content-Type: $meta_ct\n};
489          $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};          $meta_ct = qq{<meta http-equiv="content-type" content="$meta_ct">};
490        } elsif ($UA =~ m#Infomosaic#) {
491            print qq{Content-Type: text/html\n};
492      } else {      } else {
493          print qq{Content-Type: text/html; charset=$charset\n};          print qq{Content-Type: text/html; charset=$charset\n};
494      }      }
495      my $cookedpage = &encode($page);      my $cookedpage = &encode($page);
496      my $escapedpage = &escape($page);      my $escapedpage = &escape($page);
497        my ($Links, $links) = &make_navigate_links ($page);
498        print $Links;
499      print <<"EOD";      print <<"EOD";
500  Content-Language: $lang  Content-Language: $lang
501  Content-Style-Type: text/css  Content-Style-Type: text/css
# Line 488  Content-Style-Type: text/css Line 505  Content-Style-Type: text/css
505      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
506      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->      "http://www.w3.org/TR/html4/loose.dtd"> + RUBY -->
507  <html lang="$lang">  <html lang="$lang">
508  <head>  <head profile="http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiHTMLMetaProfile">
509      $meta_ct      $meta_ct$option{-goto}
510      <title>$escapedpage</title>      <title>$escapedpage</title>
511      <link rel="index" href="$url_cgi?$IndexPage">      @{[($UA !~ m#Mozilla/[1-4]\.# || $UA =~ m#MSIE (?:[4-9]\.|\d\d)#) ? qq(<link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">) : '']}
     <link rel="help" href="$url_cgi?WikiHelp">  
     <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">  
     <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">  
512      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}      @{[$option{-noindex} ? q(<meta name="ROBOTS" content="NOINDEX">) : '']}
513    $links
514  </head>  </head>
515  <body class="$bodyclass">  <body class="$bodyclass">
516  EOD  EOD
# Line 553  sub print_navigate_links (@) { Line 568  sub print_navigate_links (@) {
568      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>      <a href="$url_cgi?$RecentChanges" class="wiki">最新</a>
569  </div>  </div>
570  EOH  EOH
571  <<EOH;  ## temp  }
572      <a href="$url_cgi?$CreatePage" class="wiki">$resource{createbutton}</a> |  
573      <a href="$url_cgi?$IndexPage" class="wiki">$resource{indexbutton}</a> |  sub make_navigate_links ($) {
574  <!--    <a href="$url_cgi?$RssPage" class="wiki">$resource{rssbutton}</a> | -->      my $page = shift;
575      <a href="$url_cgi?$FrontPage" class="wiki">$FrontPage</a> |      my @link;
576      <a href="$url_cgi?$SearchPage" class="wiki">$resource{searchbutton}</a> |      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{editbutton}} if &is_editable ($page) && !&is_frozen ($page);
577      <a href="$url_cgi?mycmd=RandomJump;x-param=@{[time.[0..9]->[rand 10]]}" class="wiki randomlink">どこか</a> |      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>$resource{admineditbutton}} if &is_editable ($page) || &is_frozen ($page);
578      <a href="$url_cgi?$RecentChanges" class="wiki">$resource{recentchangesbutton}</a>      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>'View latest version of this page'};
579  </div>      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki'};
580  EOH      push @link, {rel=>'index', href=>"$url_cgi?$IndexPage", class=>'wiki', title=>$resource{indexbutton}};
581        push @link, {rel=>'home', href=>"$url_cgi?$FrontPage", class=>'wiki', title=>$FrontPage};
582        push @link, {rel=>'News', href=>"$url_cgi?WikiNews", class=>'wiki', title=>'News on this wiki'};
583        push @link, {rel=>'News', href=>"$url_cgi?$RecentChanges", class=>"wiki", title=>$resource{recentchangesbutton}};
584        push @link, {rel=>'News', href=>"$url_cgi?$RssPage", class=>"wiki", title=>$resource{rssbutton}, type=>'application/xml'};
585        push @link, {rel=>'search', href=>"$url_cgi?$SearchPage", class=>'wiki', title=>$resource{searchbutton}};
586        push @link, {rel=>'help', href=>"$url_cgi?WikiHelp", class=>'wiki'};
587        push @link, {rel=>'copyright', href=>"$url_cgi?WikiPageLicense", class=>'wiki'};
588        my ($Links, $links) = ('', '');
589        for my $e (@link) {
590            $links .= qq(<link);
591            $Links .= qq(Link: <$e->{href}>);
592            for my $attr (qw/rel rev href title class type hreflang charset/) {
593                $links .= qq( $attr="@{[&escape($e->{$attr})]}") if $e->{$attr};
594            }
595            for my $attr (qw/rel rev title/) {
596                $Links .= qq(; $attr="@{[do{$e->{$attr} =~ s/([\\\"])/\\$1/g; $e->{$attr}}]}") if $e->{$attr};
597            }
598            $links .= qq(>\n);
599            $Links .= qq(\n);
600        }
601        wantarray ? ($Links, $links) : $Links;
602  }  }
603    
604  sub print_footer {  sub print_footer {
605      my ($page, $lm) = @_;      my ($page, $lm) = @_;
606        my $epage = &encode ($page);
607      $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)
608      # Walrus mod (1) start      # Walrus mod (1) start
609    my $cvslog1 = q$Revision$;    my $cvslog1 = q$Revision$;
# Line 582  sub print_footer { Line 619  sub print_footer {
619  <a href="/map" title="このサーバーの案内">地図</a>  <a href="/map" title="このサーバーの案内">地図</a>
620  <a href="/search/" title="このサーバーの検索">検索</a>]  <a href="/search/" title="このサーバーの検索">検索</a>]
621  </div>  </div>
622    <div class="myuri">
623        &lt;<a href="$url_cgi?$epage">$url_cgi?$epage</a>&gt;
624    </div>
625  </div>  </div>
626  $walrus_log  $walrus_log
627  </body>  </body>
628  </html>  </html>
629  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  
630  }  }
631    
632  sub escape {  sub escape {
# Line 641  sub text_to_html { Line 667  sub text_to_html {
667          chomp;          chomp;
668          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
669              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
670              push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h6>');
671              $tocnum++;              $tocnum++;
672          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
673              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
674              push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h5>');
675              $tocnum++;              $tocnum++;
676          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
677              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
678              push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h4>');
679              $tocnum++;              $tocnum++;
680          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
681          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
682          # Walrus mod (6) end          # Walrus mod (6) end
683              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
684              push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h3>');
685              $tocnum++;              $tocnum++;
686          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
687              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
688              push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1) . '</h2>');
689              $tocnum++;              $tocnum++;
690          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
691              &back_push('ol', length($1), \@saved, \@result);              &back_push('ol', length($1), \@saved, \@result);
# Line 767  sub back_push { Line 793  sub back_push {
793  sub inline {  sub inline {
794      my ($line) = @_;      my ($line) = @_;
795      $line = &escape($line);      $line = &escape($line);
796        $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
797      $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;      $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;
798      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;      $line =~ s:\[(WEAK)\[(.+?)\]\]:<span class="@{[lc $1]}">$2</span>:g;
799      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;      $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:<acronym title="$2">$1</acronym>:g;
# Line 848  sub make_urilink ($;%) { Line 875  sub make_urilink ($;%) {
875    }    }
876  }  }
877    
878    my $FormIndex = 0;
879    sub make_custom_form ($$$$) {
880        my ($wfname, $definition, $template, $option) = @_;
881        ## $template and $option is currently not used in this procedure.
882        unless ($main::_EMBEDED) {
883            $FormIndex++;
884            if (length $definition) {
885                my $param = bless {}, 'SuikaWiki::Plugin';
886                my $lastmodified = &get_info($form{mypage}, $info_LastModified);
887                &load_formatter (qw/form_input form_option/);
888                $definition = &unescape ($definition);
889                $definition =~ s/\\(.)/$1/g;
890                $definition .= ' %submit;' if $definition !~ /%submit/;
891                $option = &unescape ($option);
892                $option =~ s/\\(.)/$1/g;
893                $fmt{form_option}->replace ($option, $param);
894                my $target_page = $param->{output}->{page} || $form{mypage};
895                $param->{form_disabled} = 1 if $fixedpage{$target_page};
896                my $target_form = $param->{output}->{id};
897                my $r = <<EOH;
898    <form method="post" action="$url_cgi" id="wikiform-$FormIndex" class="wikiform">
899      <input type="hidden" name="mycmd" value="@{[$param->{form_disabled}?'read':'wikiform']}">
900      <input type="hidden" name="mypage" value="@{[&escape($target_page)]}">
901      <input type="hidden" name="myLastModified" value="$lastmodified">
902      <input type="hidden" name="mytouch" value="on">
903      <input type="hidden" name="@{[$target_form? qq(wikiform_targetform" value="@{[&escape($target_form)]}) : qq(wikiform_index" value="$FormIndex)]}">
904    EOH
905                $r .= qq(<a name="wikiform-$FormIndex"></a>) if $UA =~ m#Mozilla/[12]\.#;
906                $r .= $fmt{form_input}->replace ($definition, $param);
907                $r .= <<EOH;
908    </form>
909    EOH
910                $r;
911           } else {  ## No input-interface WikiForm
912               qq(<a id="wikiform-$FormIndex" name="wikiform-$FormIndex"><!-- #form --></a>);
913           }
914        } else {
915            q(<ins class="wiki-error"><strong>Warning</strong>: form in embeded page is currently not supported.</ins>);
916        }
917    }
918    
919  ## to be obsoleted  ## to be obsoleted
920  sub make_link {  sub make_link {
921      my $chunk = shift;      my $chunk = shift;
# Line 920  sub init_form { Line 988  sub init_form {
988      # $form{mycmd} is frozen here.      # $form{mycmd} is frozen here.
989      #      #
990    
991        for (grep /^wikiform__/, keys %form) {
992            $form{$_} = &code_convert (\$form{$_}, $kanjicode);
993        }
994      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);      $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
995      $form{myname} = &code_convert(\$form{myname}, $kanjicode);      $form{myname} = &code_convert(\$form{myname}, $kanjicode);
996  }  }
# Line 927  sub init_form { Line 998  sub init_form {
998  sub update_recent_changes {  sub update_recent_changes {
999      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";      my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}";
1000      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});      my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
1001        shift (@oldupdates); ## '#?' magic line
1002      my @updates;      my @updates;
1003      foreach (@oldupdates) {      foreach (@oldupdates) {
1004          /^\- \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 1070  sub print_editform { Line 1142  sub print_editform {
1142      } else {      } else {
1143          $mymsg = &escape($mymsg || $database{NewPageTemplate});          $mymsg = &escape($mymsg || $database{NewPageTemplate});
1144      }      }
1145        my $magic = '';
1146        $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;
1147    
1148      my $edit = $mode{admin} ? 'adminedit' : 'edit';      my $edit = $mode{admin} ? 'adminedit' : 'edit';
1149      my $escapedmypage = &escape($form{mypage});      my $escapedmypage = &escape($form{mypage});
1150      my $escapedmypassword = &escape($form{mypassword});      my $escapedmypassword = &escape($form{mypassword});
1151        my $selected = 'read';
1152        if ($form{after_edit_cmd}) {
1153            $selected = $form{after_edit_cmd};
1154        } elsif ($magic =~ /Config/ || $magic =~ /CSS/) {
1155            $selected = 'edit';
1156        }
1157        my $afteredit = <<EOH;
1158    <select name="after_edit_cmd">
1159    <option value="read" label="View changed page"@{[$selected eq 'read' ? ' selected="selected"':'']}>read</option>
1160    <option value="edit" label="Edit changed page"@{[$selected eq 'edit' ? ' selected="selected"':'']}>edit</option>
1161    </select>
1162    EOH
1163    
1164      print <<"EOD";      print <<"EOD";
1165  <form action="$url_cgi" method="post">  <form action="$url_cgi" method="post">
1166  <h2>$escapedmypageの編集</h2>  <h2>$escapedmypageの編集</h2>
1167      @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}      @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="$resource{savebutton}"><kbd>S</kbd>) ]}
1168        @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10">) : "" ]} [@{[do {my $n = 0;
1169                   $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;
1170                   ++$n}]}]<br>
1171      <input type="hidden" name="myLastModified" value="$lastmodified">      <input type="hidden" name="myLastModified" value="$lastmodified">
1172      <input type="hidden" name="mypage" value="$escapedmypage">      <input type="hidden" name="mypage" value="$escapedmypage">
1173      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>      <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
# Line 1095  sub print_editform { Line 1184  sub print_editform {
1184          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>          <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
1185          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">          <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
1186          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>          <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd>
1187          [@{[do {my $n = 0;         $afteredit
1188                 $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;         <br>
                ++$n}]}]<br>  
1189      )      )
1190  ]}  ]}
1191  </form>  </form>
# Line 1176  sub encode { Line 1264  sub encode {
1264  sub init_resource {  sub init_resource {
1265      open(FILE, $file_resource) or &print_error("(resource)");      open(FILE, $file_resource) or &print_error("(resource)");
1266      while (<FILE>) {      while (<FILE>) {
1267          chomp;          s/[\x0A\x0D]+$//g;
1268          next if /^#/;          next if /^#/;
1269          my ($key, $value) = split(/=/, $_, 2);          my ($key, $value) = split(/=/, $_, 2);
1270          $resource{$key} = &code_convert(\$value, $kanjicode);          $resource{$key} = &code_convert(\$value, $kanjicode);
# Line 1305  sub do_comment { Line 1393  sub do_comment {
1393      } elsif (length $namestr) {      } elsif (length $namestr) {
1394        $namestr = qq( ''[[$namestr]]'': );        $namestr = qq( ''[[$namestr]]'': );
1395      }      }
1396      my $anchor = 0;      my $anchor = &get_new_anchor_index ($content);
     $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;  
     $anchor++;  
1397      my $i = 1;  my $o = 0;      my $i = 1;  my $o = 0;
1398      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{      $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1399        my $embed = $1;        my $embed = $1;
# Line 1336  sub do_comment { Line 1422  sub do_comment {
1422      }      }
1423  }  }
1424    
1425    sub get_new_anchor_index ($) {
1426        my $content = shift;
1427        my $anchor = 0;
1428        $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge;
1429        $anchor + 1;
1430    }
1431    
1432  my $CommentIndex = 0;  my $CommentIndex = 0;
1433  sub embedded_to_html {  sub embedded_to_html {
1434      my ($embedded) = @_;      my ($embedded) = @_;
# Line 1399  EOD Line 1492  EOD
1492    }    }
1493  }  }
1494    
1495    sub load_formatter (@) {
1496        for my $t (@_) {
1497            unless ($fmt{$t}) {
1498                $fmt{$t} = Message::Util::Formatter->new;
1499                for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
1500                    $_->load_formatter ($fmt{$t}, type => 'wiki'.$t);
1501                }
1502            }
1503        }
1504    }
1505    
1506    sub do_wikiform {
1507        my $content = $database{$form{mypage}};
1508        my $anchor = &get_new_anchor_index ($content);
1509        &load_formatter (qw/form_template form_option/);
1510        my $write = 0;
1511        my $i = 1;
1512        $content =~ s{$embed_command{form}}{
1513            my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4);
1514            if (($wfname && $wfname eq $form{wikiform_targetform})
1515                || $i == $form{wikiform_index}) {
1516                $template =~ s/\\(.)/$1/g;
1517                $option =~ s/\\(.)/$1/g;
1518                my $param = bless {}, 'SuikaWiki::Plugin';
1519                $param->{page} = $form{mypage};
1520                $param->{form_index} = $i;
1521                $param->{form_name} = $wfname;
1522                $param->{anchor_index} = $anchor;
1523                $param->{argv} = \%form;
1524                $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
1525                $param->{default_name} ||= $DEFAULT_embed_comment_name;
1526                $fmt{form_option}->replace ($option, $param);
1527                my $t = 1;
1528                for (@{$param->{require}||[]}) {
1529                    (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
1530                }
1531                $t = $fmt{form_template}->replace ($template, $param) if $t;
1532                if (length $t) {
1533                    if ($param->{output}->{reverse}) {
1534                        $embed .= "\n" . $t;
1535                    } else {
1536                        $embed = $t . "\n" . $embed;
1537                    }
1538                    $write = 1;
1539                    $form{__comment_anchor_index} = $anchor
1540                      if $param->{anchor_index_};  ## $anchor is used!
1541                }
1542                $form{__wikiform_anchor_index} = $i;
1543                undef $form{wikiform_targetform};  ## make sure never to match
1544                undef $form{wikiform_index};       ## with WikiForm in rest of page
1545            }
1546            $i++; $embed;
1547        }ge;
1548        unless ($write) {
1549          #$content = "#?SuikaWiki/0.9\n\n" unless $content;
1550          #$content .= "\n" unless $content =~ /\n$/s;
1551          #
1552        }
1553        if ($write) {
1554            $form{mymsg} = $content;
1555            $form{mytouch} = 'on';
1556            &do_write;
1557        } else {
1558            $form{mycmd} = 'read';
1559            &do_read;
1560        }
1561    }
1562    
1563    
1564  # Walrus add (5) start  # Walrus add (5) start
1565  sub do_interwiki_box {  sub do_interwiki_box {
1566      my $remoteurl = $interwiki{$form{'myintername'}};      my $remoteurl = $interwiki{$form{'myintername'}};
# Line 1565  sub do_rss { Line 1727  sub do_rss {
1727          $count++;          $count++;
1728      }      }
1729      # print RSS information (as XML).      # print RSS information (as XML).
1730    print scalar &make_navigate_links ('RssPage');
1731      print <<"EOD"      print <<"EOD"
1732  Content-type: text/xml  Content-type: application/xml
1733    
1734  @{[$rss->as_string]}  @{[$rss->as_string]}
1735  EOD  EOD
# Line 1584  sub is_exist_page { Line 1747  sub is_exist_page {
1747  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1748  sub __set_database ($$) { $database{ $_[0] } = $_[1] }  sub __set_database ($$) { $database{ $_[0] } = $_[1] }
1749    
1750    sub do_wikiplugininfo {
1751        &print_header (q(WikiPluginInfo));
1752        print text_to_html (&SuikaWiki::Plugin::make_info_page);
1753        &print_footer (q(WikiPluginInfo));
1754    }
1755    
1756  package wiki::referer;  package wiki::referer;
1757  sub add ($$) {  sub add ($$) {
1758    my $page = shift;    my $page = shift;
# Line 1649  sub list_html ($) { Line 1818  sub list_html ($) {
1818      }      }
1819      my $euri = main::escape ($uri);      my $euri = main::escape ($uri);
1820      if ($title) {      if ($title) {
1821        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri>">@{[main::escape ($title)]}</a></li>\n);        $r .= qq(<li>[$list{$uri}] <a href="$euri" title="URI: &lt;$euri&gt;">@{[main::escape ($title)]}</a></li>\n);
1822      } else {      } else {
1823        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);        $r .= qq(<li>[$list{$uri}] &lt;<a href="$euri">$euri</a>&gt;</li>\n);
1824      }      }
# Line 1686  sub add ($) { Line 1855  sub add ($) {
1855    &main::__set_database ('WikiUserAgentList' => $s);    &main::__set_database ('WikiUserAgentList' => $s);
1856  }  }
1857    
1858    package SuikaWiki::Plugin;
1859      our $plugin_directory;  # defined in top of this file.
1860      our %List;
1861    
1862    sub escape ($$) { main::escape ($_[1]) }
1863    sub unescape ($$) { main::unescape ($_[1]) }
1864    sub encode ($$) { main::encode ($_[1]) }
1865    sub decode ($$) { main::decode ($_[1]) }
1866    sub __get_datetime ($) { main::get_now () }
1867    
1868    sub regist ($@) {
1869        my $pack = shift;
1870        for (@_) {
1871            push @{$List{$_}}, $pack;
1872        }
1873    }
1874    
1875    sub import_plugins () {
1876        opendir PDIR, $plugin_directory;
1877        my @plugin = grep {s/\.pm$//} readdir (PDIR);
1878        closedir PDIR;
1879        for (@plugin) {
1880            eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
1881            push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
1882        }
1883    }
1884    
1885    sub make_info_page () {
1886        my $r = <<EOH;
1887    EOH
1888        unless ($List{_all}) {
1889            $r .= qq('''No plugin is installed!'''\n);
1890        } else {
1891            my $index = 0;
1892            for my $package (sort @{$List{_all}}) {
1893                $index++;
1894                my $prop = $package->property ();
1895                $r .= <<EOH;
1896    *$package
1897    
1898    [$index] '''$prop->{name}''' (Version $prop->{version})
1899    <$prop->{uri}>
1900    
1901    Provide:
1902    @{[do{my $t = ''; for my $f (@{$prop->{provide}||[]}) {
1903        $t .= qq(-''$f''\n);
1904        for (sort grep m#^\Q$f\E/#, keys %{$prop->{partinfo}}) {
1905             $t .= qq(--''$_'' -- $prop->{partinfo}->{$_}\n);
1906        }
1907    }$t}]}
1908    
1909    EOH
1910            }
1911        }
1912        $r;
1913    }
1914    
1915    &import_plugins ();
1916    
1917    package main;
1918    &main;
1919    exit 0;
1920    
1921  1;  1;
1922  __END__  __END__
1923  =head1 NAME  =head1 NAME

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.36

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24