/[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.47 by w, Fri Jan 3 03:27:30 2003 UTC revision 1.48 by w, Fri Jan 3 08:25:31 2003 UTC
# Line 18  my %embed_command = ( Line 18  my %embed_command = (
18          form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,          form    => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
19  );  );
20  our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);  our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
21  our (%PageName,$kanjicode,$lang,%FixedPage);  our (%PageName,$kanjicode,$lang,%ViewDefinition);
22    
23  ##############################  ##############################
24  my %form;  my %form;
# Line 32  my %page_command = ( Line 32  my %page_command = (
32  my %command_do = (  my %command_do = (
33      read => \&do_read,      read => \&do_read,
34      TEXT_CSS => \&do_output_css,      TEXT_CSS => \&do_output_css,
35      edit => \&do_edit,      edit => \&do_view,
     adminedit => \&do_adminedit,  
36      adminchangepassword => \&do_adminchangepassword,      adminchangepassword => \&do_adminchangepassword,
37      write => \&do_write,      write => \&do_write,
38      searchform => \&do_searchform,      searchform => \&do_searchform,
# Line 42  my %command_do = ( Line 41  my %command_do = (
41      rss => \&do_rss,      rss => \&do_rss,
42      diff => \&do_diff,      diff => \&do_diff,
43      wikiform    => \&do_wikiform,      wikiform    => \&do_wikiform,
44      map => \&do_map,      map => \&do_view,
45  );  );
46  my $UA = '';  ## User agent name  my $UA = '';  ## User agent name
47  $| = 1;  $| = 1;
# Line 65  sub do_read { Line 64  sub do_read {
64    my $lm = $database->mtime ($form{mypage});    my $lm = $database->mtime ($form{mypage});
65    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});    wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
66    wiki::useragent::add ($ENV{HTTP_USER_AGENT});    wiki::useragent::add ($ENV{HTTP_USER_AGENT});
   my ($r, $c) = get_search_result ($form{mypage});  
   my $rl = wiki::referer::list_html ($form{mypage});  
67    my @toc;    my @toc;
   push @toc, qq(-<a href="#wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</a>) if $c;  
   push @toc, qq(-<a href="#wikipage-referer">@{[&Resource('Referers',escape=>1)]}</a>) if $rl;  
68      my $cf = 'SuikaWiki/0.9';      my $cf = 'SuikaWiki/0.9';
69      ## Should be support at least:      ## Should be support at least:
70      ## - 'SuikaWiki/0.9' CRLF      ## - 'SuikaWiki/0.9' CRLF
# Line 87  sub do_read { Line 82  sub do_read {
82          -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));          -content_format => $cf, -noindex => ($cf =~ /obsoleted="yes"/ ? 1 : 0));
83        &print_content ($content, content_format => $cf, last_modified => $lm,        &print_content ($content, content_format => $cf, last_modified => $lm,
84          -toc => \@toc);          -toc => \@toc);
85        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$FixedPage{$form{mypage}};        print &text_to_html (q([[#comment]])) if $cf !~ /obsoleted="yes"/ && !$database->meta (IsFrozen => $form{mypage});
86      } else {      } else {
87        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);        &print_header($form{mypage}, -expires => time + 120, -last_modified => $lm);
88        print "<pre>@{[&escape($content)]}</pre>";        print "<pre>@{[&escape($content)]}</pre>";
89      }      }
90      if ($c) {      &load_formatter ('view');
91        print qq{<h2 @{[&id_and_name('wikipage-see-also')]}>@{[&Resource('SeeAlso',escape=>1)]}</h2>};      print $fmt{view}->replace ($ViewDefinition{read} => bless {param => \%form, page => $form{mypage}, toc => \@toc, formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
92        print $r;      &print_footer ($form{mypage}, $lm);
     }  
     if ($rl) {  
       print qq(<div @{[&id_and_name('wikipage-referer')]}><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);  
     }  
         #print "\n". gmtime."Footer...\n";  
   &print_footer($form{mypage}, $lm);  
         #print "\n". gmtime."Fin...\n";  
93  }  }
94    
95  sub do_output_css {  sub do_output_css {
# Line 132  sub id_and_name ($) { Line 120  sub id_and_name ($) {
120      }      }
121  }  }
122    
123  sub do_edit {  sub do_view {
     my ($page) = &unarmor_name(&armor_name($form{mypage}));  
     if (not &is_editable($page)) {  
         &print_header($page, -noindex => 1, -expires => time+60);  
         &print_message(&Resource('Error:ThisPageIsUneditable'));  
     } elsif (&is_frozen($page)) {  
         &print_header($page, -noindex => 1, -expires => time+60);  
         &print_message(&Resource('Error:ThisPageIsUneditable'));  
     } else {  
         &print_header($page, -noindex => 1, -expires => time+60);  
         &print_editform($database{$page}, $database->mtime ($page), admin=>0);  
     }  
124      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});      wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});
125      wiki::useragent::add ($ENV{HTTP_USER_AGENT});      wiki::useragent::add ($ENV{HTTP_USER_AGENT});
126      my ($r, $c) = get_search_result ($form{mypage});      &print_header($form{mypage}, -noindex => 1, -expires => time+60);
127      my $rl = wiki::referer::list_html ($form{mypage});      &load_formatter ('view');
128      if ($c) {      my $view = $form{mycmd};
129        print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};      if ($view eq 'edit') {
130        print $r;        $view = 'adminedit' if $form{admin};
131      }      } elsif ($view =~ /[^0-9A-Za-z]/) {
132      if ($rl) {        $view = 'view'
       print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);  
     }  
     &print_footer($page);  
 }  
   
 sub do_adminedit {  
     my ($page) = &unarmor_name(&armor_name($form{mypage}));  
     &print_header($page, -noindex => 1, -expires => time+60);  
     if (not &is_editable($page)) {  
         &print_message(&Resource('Error:ThisPageIsUneditable'));  
     } else {  
         &print_message(&Resource('Error:PasswordIsNotSpecified'));  
         &print_editform($database{$page}, $database->mtime ($page), admin=>1);  
133      }      }
134      &print_footer($page);      print $fmt{view}->replace ($ViewDefinition{$view} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
135        &print_footer($form{mypage});
136  }  }
137    
138  sub do_adminchangepassword {  sub do_adminchangepassword {
# Line 209  sub do_write { Line 174  sub do_write {
174          return;          return;
175      }      }
176    
177      if (&conflict($form{mypage}, $form{mymsg})) {      ## Check confliction
178          return;      if ($form{myLastModified} ne $database->mtime ($page)) {
179          &print_header($page, -noindex => 1);
180          &load_formatter ('view');
181          print $fmt{view}->replace ($ViewDefinition{-conflict} => bless {param => \%form, page => $form{mypage}, toc => [], formatter => $fmt{view}, &_compatible_options ()}, 'SuikaWiki::Plugin');
182          &print_footer($page);
183          return;
184      }      }
185    
186      if ($form{mymsg}) {      if ($form{mymsg}) {
# Line 239  sub do_write { Line 209  sub do_write {
209      }      }
210  }  }
211    
212    sub _compatible_options () {
213      (use_anchor_name => ($UA =~ m#Mozilla/[12]\.|Microsoft Internet Explorer# ? 1 : 0));
214    }
215    
216  sub get_search_result ($;%) {  sub get_search_result ($;%) {
217    my $word = lc shift;    my $word = lc shift;
218    my %option = @_;    my %option = @_;
# Line 375  sub make_navigate_links ($) { Line 349  sub make_navigate_links ($) {
349      my $page = shift;      my $page = shift;
350      my @link;      my @link;
351      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page);      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('EditThisPageLink')} if &is_editable ($page) && !&is_frozen ($page);
352      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=adminedit;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);      push @link, {rel=>'edit', href=>"$url_cgi?mycmd=edit;admin=1;mypage=@{[&encode($page)]}", class=>"wiki-command", title=>&Resource('AdminEditThisPageLink')} if &is_editable ($page) || &is_frozen ($page);
353      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')};      push @link, {rel=>'view', href=>"$url_cgi?mycmd=read;mypage=@{[&encode($page)]};x-p=@{[time.[0..9]->[rand 10]]}", class=>'wiki-command', title=>&Resource('ViewThisPageLink')};
354      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};      push @link, {rel=>'myself', href=>"$url_cgi?@{[&encode($page)]}", class=>'wiki', title=>&Resource('GoToMyselfLink')};
355      push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};      push @link, {rel=>'index', href=>"$url_cgi?$PageName{IndexPage}", class=>'wiki', title=>&Resource('GoToIndexPageLink')};
# Line 427  EOD Line 401  EOD
401    
402  sub escape {  sub escape {
403      my $s = shift;      my $s = shift;
404      $s =~ s|\r\n|\n|g;      $s =~ s|\x0D\x0A|\x0A|g;
405      $s =~ s|&|&amp;|g;      $s =~ s|&|&amp;|g;
406      $s =~ s|<|&lt;|g;      $s =~ s|<|&lt;|g;
407      $s =~ s|>|&gt;|g;      $s =~ s|>|&gt;|g;
# Line 452  sub print_content ($;$) { Line 426  sub print_content ($;$) {
426    
427  sub text_to_html {  sub text_to_html {
428      my ($txt, %option) = @_;      my ($txt, %option) = @_;
429      my @toc;      my $toc = $option{-toc} || [];
     my @toc2 = @{$option{-toc}||[]};  
430      my $tocnum = 0;      my $tocnum = 0;
431            
432      ## Load constants      ## Load constants
# Line 475  sub text_to_html { Line 448  sub text_to_html {
448      foreach (@txt) {      foreach (@txt) {
449          chomp;          chomp;
450          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {          if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
451              push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [5, "i$tocnum" => ($1 || $tocnum)];
452              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');              push(@result, splice(@saved), qq(<h6 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h6>');
453              $tocnum++;              $tocnum++;
454          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
455              push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [4, "i$tocnum" => ($1 || $tocnum)];
456              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');              push(@result, splice(@saved), qq(<h5 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h5>');
457              $tocnum++;              $tocnum++;
458          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
459              push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [3, "i$tocnum" => ($1 || $tocnum)];
460              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');              push(@result, splice(@saved), qq(<h4 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h4>');
461              $tocnum++;              $tocnum++;
462          } elsif (/^\*\*([^\x0D\x0A]*)/) {          } elsif (/^\*\*([^\x0D\x0A]*)/) {
463          # if (/^\*\*(.*)/) {          # if (/^\*\*(.*)/) {
464          # Walrus mod (6) end          # Walrus mod (6) end
465              push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [2, "i$tocnum" => ($1 || $tocnum)];
466              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');              push(@result, splice(@saved), qq(<h3 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h3>');
467              $tocnum++;              $tocnum++;
468          } elsif (/^\*([^\x0D\x0A]*)/) {          } elsif (/^\*([^\x0D\x0A]*)/) {
469              push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));              push @$toc, [1, "i$tocnum" => ($1 || $tocnum)];
470              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');              push(@result, splice(@saved), qq(<h2 @{[&id_and_name("i$tocnum")]}>) . &inline($1, const => \%const) . '</h2>');
471              $tocnum++;              $tocnum++;
472          } elsif (/^(={1,6})(.*)/) {          } elsif (/^(={1,6})(.*)/) {
# Line 561  sub text_to_html { Line 534  sub text_to_html {
534      }      }
535      push(@result, splice(@saved));      push(@result, splice(@saved));
536            
537      my $toc = '';      my $r = join("\n", @result);
538      if ($option{toc}) {      $r =~ s#<p>\x0D?\x0A</p>##g;
539          # Convert @toc (table of contents) to HTML.      $r =~ s#[\x0D\x0A]+</#</#g;
540          # This part is taken from Makio Tsukamoto's WalWiki.      $r =~ s#<pre>\x0D?\x0A#<pre>#g;
541          my (@tocsaved, @tocresult);      $r;
         foreach (@toc,@toc2) {  
             if (/^(-{1,6})(.*)$/) {  
                 &back_push('ul', length($1), \@tocsaved, \@tocresult);  
                 push(@tocresult, '<li>' . $2 . '</li>');  
             }  
         }  
         push(@tocresult, splice(@tocsaved));  
         $toc = join("\n", @tocresult);  
         $toc = $toc ? qq(<div id="wikipage-toc">$toc</div>) : '';  
     }  
     $toc .= join("\n", @result);  
     $toc =~ s#<p>\n</p>##g;  
     $toc =~ s#[\x0D\x0A]+</#</#g;  
     $toc =~ s#<pre>\n#<pre>#g;  
     $toc;  
542  }  }
543    
544  sub back_push {  sub back_push {
# Line 701  sub make_custom_form ($$$$) { Line 659  sub make_custom_form ($$$$) {
659              $param->{output}->{form} = 1 unless defined $param->{output}->{form};              $param->{output}->{form} = 1 unless defined $param->{output}->{form};
660              $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};              $definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
661              my $target_page = $param->{output}->{page} || $form{mypage};              my $target_page = $param->{output}->{page} || $form{mypage};
662              $param->{form_disabled} = 1 if $FixedPage{$target_page};              $param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage});
663              my $target_form = $param->{output}->{id};              my $target_form = $param->{output}->{id};
664              my $r = '';              my $r = '';
665              $r = <<EOH if $param->{output}->{form};              $r = <<EOH if $param->{output}->{form};
# Line 763  sub init_form { Line 721  sub init_form {
721        }        }
722      }      }
723      $form{mypage} ||= 'HomePage';      $form{mypage} ||= 'HomePage';
724        $form{mypage} =~ tr/\x00-\x1F\x7F//d;
725      $form{mycmd} ||= 'read';      $form{mycmd} ||= 'read';
726    
727      # mypreview_edit        -> do_edit, with preview.      # mypreview_edit        -> do_edit, with preview.
# Line 829  sub close_db { Line 788  sub close_db {
788      }      }
789  }  }
790    
791  sub print_editform {  sub editform (@) {
792      my ($mymsg, $lastmodified, %mode) = @_;    my %option = @_;
793      my $frozen = &is_frozen($form{mypage});    my $frozen = &is_frozen ($option{page});
794      $option{content} = $database{$option{page}} unless defined $option{content};
795      if ($form{mypreview}) {    $option{content} = $database{NewPageTemplate} unless length $option{content};
796          if ($form{mymsg}) {    $option{last_modified} = $database->mtime ($option{page}) unless defined $option{last_modified};
797              unless ($mode{conflict}) {    my $f = '';
798                  print qq(<h3>@{[&Resource('Preview:Title',escape=>1)]}</h3>\n);    my $magic = '';
799                  print qq(<p>@{[&Resource('Preview:Notice',escape=>1)]}</p>\n);    $magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s;
800                  print qq(<div class="preview">\n);    
801                  &print_content($form{mymsg});    my $selected = 'read';
802                  print qq(</div>\n);    if ($form{after_edit_cmd}) {
803              }      $selected = $form{after_edit_cmd};
804          } else {    } elsif ($magic =~ /Const|Config|CSS/) {
805              print @{[&Resource('Preview:Empty',escape=>1)]};      $selected = 'edit';
806          }    }
807          $mymsg = &escape($form{mymsg});    my $afteredit = <<EOH;
     } else {  
         $mymsg = &escape($mymsg || $database{NewPageTemplate});  
     }  
     my $magic = '';  
     $magic = $1 if $mymsg =~ m/^([^\x0A\x0D]+)/s;  
   
     my $edit = $mode{admin} ? 'adminedit' : 'edit';  
     my $selected = 'read';  
     if ($form{after_edit_cmd}) {  
         $selected = $form{after_edit_cmd};  
     } elsif ($magic =~ /Const|Config|CSS/) {  
         $selected = 'edit';  
     }  
     my $afteredit = <<EOH;  
808  <select name="after_edit_cmd">  <select name="after_edit_cmd">
809  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>  <option value="read" label="@{[&Resource('Edit:SaveAndView',escape=>1)]}"@{[$selected eq 'read' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndView',escape=>1)]}</option>
810  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>  <option value="edit" label="@{[&Resource('Edit:SaveAndEdit',escape=>1)]}"@{[$selected eq 'edit' ? ' selected="selected"':'']}>@{[&Resource('Edit:SaveAndEdit',escape=>1)]}</option>
811  </select>  </select>
812  EOH  EOH
813      $f .= <<"EOD";
814      print <<"EOD";  <form action="$uri{wiki}" method="post">
815  <form action="$url_cgi" method="post">      @{[ $option{conflict} ? '' : qq(<label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd></label>) ]}
816  <h2>@{[&Resource('Edit:Title',escape=>1)]}</h2>      @{[ $option{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[&get_new_anchor_index($option{content})]}]<br>
817      @{[ $mode{conflict} ? '' : qq(<input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}"><kbd>S</kbd>) ]}      <input type="hidden" name="myLastModified" value="$option{last_modified}">
     @{[ $mode{admin} ? qq(<label>@{[&Resource('Edit:Password=',escape=>1)]}<input type="password" name="mypassword" value="" size="10"></label>) : "" ]} [@{[do {my $n = 0;  
                $mymsg =~ s/(?:-+\s)?\[([0-9]+)\]/$n = $1 if $1 > $n; $&/mge;  
                ++$n}]}]<br>  
     <input type="hidden" name="myLastModified" value="$lastmodified">  
818      <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">      <input type="hidden" name="mypage" value="@{[&escape($form{mypage})]}">
819      <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">$mymsg</textarea><br>      <textarea cols="@{[&Resource('Edit:Form:Cols')+0||80]}" rows="@{[&Resource('Edit:Form:Rows')+0||20]}" name="mymsg" tabindex="1">@{[&escape($option{content})]}</textarea><br>
820  @{[  @{[
821      $mode{admin} ?      $option{admin} ?
822      qq(      qq(
823      <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>      <label><input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>@{[&Resource('Edit:Freeze',escape=>1)]}</label>
824      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)      <label><input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>@{[&Resource('Edit:DontFreeze',escape=>1)]}</label><br>)
825      : ""      : ""
826  ]}  ]}
827  @{[  @{[
828      $mode{conflict} ? "" :      $option{conflict} ? "" :
829      qq(      qq(
830          <label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br>          <label><input type="checkbox" name="mytouch" value="on" checked="checked">@{[&Resource('Edit:UpdateTimeStamp',escape=>1)]}</label><br>
         <input type="submit" name="mypreview_$edit" value="@{[&Resource('Edit:Preview',escape=>1)]}">  
831          <label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label>          <label><input type="submit" name="mypreview_write" value="@{[&Resource('Edit:Save',escape=>1)]}" accesskey="S"><kbd>S</kbd></label>
832         $afteredit         $afteredit
833      )      )
834  ]}  ]}
835  </form>  </form>
836  EOD  EOD
837      unless ($mode{conflict}) {      unless ($option{conflict}) {
838          ## Show help text          ## Show help text
839          my $help = $database{WikiEditHelp};          my $help = $database{WikiEditHelp};
840          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;          $help =~ s!^\#\?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.\x0D\x0A][^\x0D\x0A]*)?)[\x0D\x0A]+!!s;
841          print &text_to_html ($help, toc => 0);          $f .= &text_to_html ($help, toc => 0);
842      }      }
843        $f;
844  }  }
845    
846  sub is_editable {  sub is_editable {
847      my ($page) = @_;      my ($page) = @_;
848      if ($FixedPage{$page} || $page =~ /\s/ || $page =~ /^\#/) {      $page =~ /[\x00-\x1F\x7F]/ ? 0 : 1;
         return 0;  
     } else {  
         return 1;  
     }  
849  }  }
850    
851  # armor_name:  # armor_name:
# Line 948  sub encode { Line 885  sub encode {
885      return $encoded;      return $encoded;
886  }  }
887    
 sub conflict {  
     my ($page, $rawmsg) = @_;  
     if ($form{myLastModified} eq $database->mtime ($page)) {  
         return 0;  
     }  
     &print_header($page, -noindex => 1);  
     &print_content(&Resource('Error:Conflict'));  
     &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);  
     &print_footer($page);  
     return 1;  
 }  
   
888  sub get_now {  sub get_now {
889      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);      my ($sec, $min, $hour, $day, $mon, $year) = localtime(time);
890      $year += 1900;      $year += 1900;
# Line 1263  sub is_exist_page { Line 1188  sub is_exist_page {
1188    
1189  sub __get_database ($) { $database{ $_[0] } }  sub __get_database ($) { $database{ $_[0] } }
1190    
 sub do_map {  
     my $page = $form{mypage};  
     &print_header ($page);  
     wiki::referer::add ($form{mypage}, $ENV{HTTP_REFERER});  
     wiki::useragent::add ($ENV{HTTP_USER_AGENT});  
     my ($r, $c) = get_search_result ($form{mypage});  
     my $rl = wiki::referer::list_html ($form{mypage});  
     print "<h2>@{[&Resource('Map:Title',escape=>1)]}</h2>\n<p>@{[&Resource('Map:Description',escape=>1)]}</p>\n";  
     my %option = (level => 0+&Resource('Map:Depth'), weight_list => {}, not_exist => {},  
       map_from_here => &Resource('Map:FromHere'),  
       map_from_here_description => &Resource('Map:FromHereLong'));  
     &wiki::map::make_list ($page, %option);  
     print &wiki::map::list_to_html ($page, $option{weight_list}, %option);  
     if ($c) {  
       print qq{<h2 id="wikipage-see-also">@{[&Resource('SeeAlso',escape=>1)]}</h2>};  
       print $r;  
     }  
     if ($rl) {  
       print qq(<div id="wikipage-referer"><h2>@{[&Resource('Referers',escape=>1)]}</h2>\n$rl</div>\n);  
     }  
     &print_footer ($page);  
 }  
   
1191  my %_Resource;  my %_Resource;
1192  sub Resource ($;%) {  sub Resource ($;%) {
1193    my ($s, %o) = @_;    my ($s, %o) = @_;
# Line 1421  sub Yuki::YukiWikiDB2::meta (@) {undef} Line 1323  sub Yuki::YukiWikiDB2::meta (@) {undef}
1323  package SuikaWiki::Plugin;  package SuikaWiki::Plugin;
1324    our $plugin_directory;  # defined in top of this file.    our $plugin_directory;  # defined in top of this file.
1325    our %List;    our %List;
1326      our %Index;
1327    
1328  sub escape ($$) { main::escape ($_[1]) }  sub escape ($$) { main::escape ($_[1]) }
1329  sub unescape ($$) { main::unescape ($_[1]) }  sub unescape ($$) { main::unescape ($_[1]) }
# Line 1429  sub decode ($$) { main::decode ($_[1]) } Line 1332  sub decode ($$) { main::decode ($_[1]) }
1332  sub __get_datetime ($) { main::get_now () }  sub __get_datetime ($) { main::get_now () }
1333  sub resource ($$;%) { shift; &main::Resource (@_) }  sub resource ($$;%) { shift; &main::Resource (@_) }
1334  sub uri ($$) { $main::uri{$_[1]} }  sub uri ($$) { $main::uri{$_[1]} }
1335    sub new_index ($$) { ++$Index{$_[1]} }
1336    
1337  sub regist ($@) {  sub regist ($@) {
1338      my $pack = shift;      my $pack = shift;
# Line 1489  sub get ($;\%) { Line 1393  sub get ($;\%) {
1393    defined $v ? $v : $resname;    defined $v ? $v : $resname;
1394  }  }
1395    
 package wiki::map;  
   
 sub make_list ($;%) {  
   my ($page, %option) = @_;  
   $option{level} ||= 3;  
   my %weight;  
   my $content = &main::__get_database ($page);  
   $content =~ s{^\#\?([^\x0A\x0D]+)}{  
     if ($1 =~ /import="([^"]+)"/) {  
       for (split /\s*,\s*/, $1) {  
         $weight{$_} += 2;  
       }  
     }  
     $&;  
   }ges;  
   ## Bug: this code does not support content type.  
   $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{  
     $weight{$1}++; $&;  
   }ge;  
   delete $weight{$page};        ## Delete myself  
   for my $page (keys %weight) {  
     my $w = ($content =~ s/\Q$page\E/$&/g);  
     $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.  
     ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless &main::is_exist_page ($page);  
   }  
   $option{weight_list}->{$page} = \%weight;  
   if (--$option{level}) {  
     for my $page (keys %weight) {  
       &make_list ($page, %option) unless $option{weight_list}->{$page};  
     }  
   }  
   $option{weight_list};  
 }  
   
 sub list_to_html ($$;%) {  
   my ($Page, $wlist, %option) = @_;  
   my $r = '';  
   $option{outputed}->{$Page} = 1;  
   for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {  
     $r .= qq(<li><span class="weight">[@{[0+$wlist->{$Page}->{$page}]}]</span> <a href="$main::url_cgi?@{[&main::encode($page)]}" class="wiki@{[$option{not_exist}->{$page}?' not-exist':'']}">@{[&main::escape ($page).($option{not_exist}->{$page}?qq(<span class="mark">@{[&main::Resource('JumpAndEditWikiPageMark',escape=>1)]}</span>):'')]}</a> <a href="$main::url_cgi?mycmd=map;mypage=@{[&main::encode($page)]}" class="wiki-cmd map-from-here" title="@{[&main::escape($option{map_from_here_description})]}">@{[&main::escape($option{map_from_here})]}</a> <span class="summary">@{[&main::escape(&main::get_subjectline($page))]}</span>);  
     unless ($option{outputed}->{$page}) {  
       $r .= &list_to_html ($page, $wlist, %option);  
     }  
     $r .= "</li>\n";  
   }  
   $r ? qq(<ul class="map">$r</ul>) : '';  
 }  
   
1396  package main;  package main;
1397  &main;  &main;
1398  exit 0;  exit 0;

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24