--- suikawiki/script/wiki.cgi 2003/01/12 09:15:06 1.50
+++ suikawiki/script/wiki.cgi 2003/01/26 02:30:24 1.51
@@ -1,33 +1,28 @@
#!/usr/bin/perl
-# wiki.cgi - This is YukiWiki, yet another Wiki clone.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the same terms as Perl itself.
+## wiki.cgi - This is SuikaWiki, yet another WikiEngine
use strict;
use lib qw(./lib);
use CGI::Carp qw(fatalsToBrowser);
-our $VERSION = do{my @r=(q$Revision: 1.50 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
binmode STDOUT; binmode STDIN;
-require 'wikidata/suikawiki-config.ph';
+our $VERSION = do{my @r=(q$Revision: 1.51 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
+require 'wikidata/suikawiki-config.ph'; ## site configuration script
+require Yuki::YukiWikiCache;
use Fcntl;
-##############################
our %fmt; ## formatter objects
our %embed_command = (
searched => '^\[\[#searched:([^\]]+)\]\]$',
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/,
);
-our ($modifier_dbtype,$url_cgi,%uri,%PathTo,$use_exists);
+our ($modifier_dbtype,$url_cgi,%uri,%PathTo);
our (%PageName,$kanjicode,$lang,%ViewDefinition);
-##############################
my %form;
our %database;
our $database = bless {}, 'wiki::dummy';
my %interwiki;
-##############################
my %command_do = (
- read => \&do_view,
+ default => \&do_view,
adminchangepassword => \&do_adminchangepassword,
write => \&do_write,
searchform => \&do_searchform,
@@ -35,9 +30,8 @@
RandomJump => \&do_random_jump,
wikiform => \&do_wikiform,
);
-my $UA = ''; ## User agent name
+our $UA = ''; ## User agent name
$| = 1;
-##############################
sub main {
$UA = $main::ENV{HTTP_USER_AGENT};
@@ -46,7 +40,7 @@
if ($command_do{$form{mycmd}}) {
&{$command_do{$form{mycmd}}};
} else {
- &{$command_do{read}};
+ &{$command_do{default}};
}
&close_db;
}
@@ -61,7 +55,15 @@
if ($view eq 'edit') {
$view = 'adminedit' if $form{admin};
} elsif ($view =~ /[^0-9A-Za-z]/) {
- $view = 'view'
+ $view = 'default'
+ }
+ if ($view eq 'default' || !$view) {
+ ## BUG: this code is not strict
+ if ($main::ENV{HTTP_COOKIE} =~ /SelectedMode=([0-9A-Za-z]+)/) {
+ $view = $1;
+ } else {
+ $view = 'read';
+ }
}
my ($magic, $content) = &SuikaWiki::Plugin::magic_and_content (undef, $content);
$magic ||= '#?SuikaWiki/0.9';
@@ -76,16 +78,23 @@
if ($ViewDefinition{$view}->{xmedia} && $UA =~ /Gecko/) {
$media = $ViewDefinition{$view}->{xmedia};
$o->{media} = $media;
+ } elsif ($UA =~ m#Mozilla/0\..+Windows#) {
+ $kanjicode = 'shift_jis';
}
if ($magic =~ m!^\#\?SuikaWiki/0.9!) {
- &print_header ($form{mypage}, -last_modified => ($magic =~ /interactive="yes"/ ? $lm : time),
+ &print_header ($form{mypage}, -last_modified => ($magic =~ /interactive="yes"/ ? time : $lm),
-expires => ($magic =~ /interactive="yes"/ ? 1 : undef), o => $o,
-media => $media, -magic => $magic, content => $content);
} else {
&print_header($form{mypage}, -media => $media,
-magic => $magic, -last_modified => $lm, o => $o);
}
+ if ($kanjicode ne 'euc') {
+ my $s = $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o);
+ print &code_convert (\$s => $kanjicode);
+ } else {
print $fmt{view}->replace ($ViewDefinition{$view}->{template} => $o);
+ }
}
sub _do_view_msg (%) {
@@ -175,7 +184,7 @@
} elsif ($form{__wikiform_anchor_index}) {
$fragment .= qq(#wikiform-$form{__wikiform_anchor_index});
}
- &_do_view_msg (-view => '-wrote', -page => $form{mypage}, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'read').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
+ &_do_view_msg (-view => '-wrote', -page => $form{mypage}, -goto => $url_cgi.'?mycmd='.&encode($form{after_edit_cmd}||'default').';mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}$fragment));
} else {
delete $database{$form{mypage}};
&_do_view_msg (-view => '-deleted', -page => $form{mypage});
@@ -188,23 +197,31 @@
sub get_search_result ($;%) {
my $word = lc shift;
+ my $SearchResult = SuikaWiki::Plugin->cache ('search');
my %option = @_;
my @r;
- foreach my $page (keys %database) {
- next if !$option{-match_myself} && ($page eq $word);
- my $content = lc $database{$page};
- if (index (lc $page, $word) > -1) {
- my $c = $content =~ s/\Q$word\E//g;
- push @r, [$page, $c+20];
- } elsif (index ($word, lc $page) > -1) {
- my $c = $content =~ s/\Q$word\E//g;
- push @r, [$page, $c+10];
- } elsif (my $c = $content =~ s/\Q$word\E//g) {
- push @r, [$page, $c];
+ unless (defined $SearchResult->{$word}) {
+ for my $page (keys %database) {
+ next if !$option{-match_myself} && ($page eq $word);
+ my $content = lc $database{$page};
+ $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
+ if (index (lc $page, $word) > -1) {
+ my $c = $content =~ s/\Q$word\E//g;
+ push @r, [$page, $c+20];
+ } elsif (index ($word, lc $page) > -1) {
+ my $c = $content =~ s/\Q$word\E//g;
+ push @r, [$page, $c+10];
+ } elsif (my $c = $content =~ s/\Q$word\E//g) {
+ push @r, [$page, $c];
+ }
}
+ @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
+ $SearchResult->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r;
+ } else {
+ @r = map {[split /\x1F/, $_, 2]} split /\x1E/, $SearchResult->{$word};
}
#my $em = sub { my $s = shift; $s =~ s#(\Q$word\E)#$1#gi; $s };
- my $r = join "\n", map {qq(
[$_->[1]] @{[&escape($_->[0])]} @{[&escape(&get_subjectline($_->[0]))]})} sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
+ my $r = join "\n", map {qq([$_->[1]] @{[&escape($_->[0])]} @{[&escape(&get_subjectline($_->[0]))]})} @r;
$r = qq|| if $r;
wantarray? ($r, scalar @r): $r;
}
@@ -245,12 +262,13 @@
print qq{Expires: @{[scalar gmtime (time + $option{-media}->{expires})]}\n};
}
}
- if ($option{-media}->{charset} && $UA =~ m#Mozilla/2#) {
+ if ($option{-media}->{charset} && $UA =~ m#Mozilla/[12]\.#) {
my $ct = qq{$option{-media}->{type}; charset=@{[&get_charset_name($kanjicode,compatible=>1)]}};
print qq{Content-Type: $ct\n};
$option{o}->{-header}->{meta_ct} = qq{\n};
- } elsif (!$option{-media}->{charset} || $UA =~ m#Infomosaic#) {
+ } elsif (!$option{-media}->{charset} || $UA =~ m#Infomosaic|Mozilla/0\.#) {
print qq{Content-Type: $option{-media}->{type}\n};
+ $option{o}->{-header}->{meta_ct} = qq{\n};
} else {
my $type = $option{-media}->{type};
$type = 'application/xml' if $type eq 'application/rss+xml';
@@ -319,10 +337,10 @@
## Load constants
my %const;
- if ($option{content_format} =~ /import="([^"]+)"/) {
+ if ($option{magic} =~ /import="([^"]+)"/) {
for (split /\s*,\s*/, $1) {
my $wp = $database{$_};
- if ($wp =~ m!^\#\?SuikaWikiConst/1.0!) {
+ if ($wp =~ m!^\#\?SuikaWikiConst/(?:0.9|1.0)!) {
wiki::suikawikiconst::to_hash ($wp => \%const);
}
}
@@ -337,29 +355,29 @@
chomp;
if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
push @$toc, [5, "i$tocnum" => ($1 || $tocnum)];
- push(@result, splice(@saved), qq() . &inline($1, const => \%const) . '
');
+ push(@result, splice(@saved), qq() . &inline($1, %option, const => \%const) . '
');
$tocnum++;
} elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
push @$toc, [4, "i$tocnum" => ($1 || $tocnum)];
- push(@result, splice(@saved), qq() . &inline($1, const => \%const) . '
');
+ push(@result, splice(@saved), qq() . &inline($1, %option, const => \%const) . '
');
$tocnum++;
} elsif (/^\*\*\*([^\x0D\x0A]*)/) {
push @$toc, [3, "i$tocnum" => ($1 || $tocnum)];
- push(@result, splice(@saved), qq() . &inline($1, const => \%const) . '
');
+ push(@result, splice(@saved), qq() . &inline($1, %option, const => \%const) . '
');
$tocnum++;
} elsif (/^\*\*([^\x0D\x0A]*)/) {
# if (/^\*\*(.*)/) {
# Walrus mod (6) end
push @$toc, [2, "i$tocnum" => ($1 || $tocnum)];
- push(@result, splice(@saved), qq() . &inline($1, const => \%const) . '
');
+ push(@result, splice(@saved), qq() . &inline($1, %option, const => \%const) . '
');
$tocnum++;
} elsif (/^\*([^\x0D\x0A]*)/) {
push @$toc, [1, "i$tocnum" => ($1 || $tocnum)];
- push(@result, splice(@saved), qq() . &inline($1, const => \%const) . '
');
+ push(@result, splice(@saved), qq() . &inline($1, %option, const => \%const) . '
');
$tocnum++;
} elsif (/^(={1,6})(.*)/) {
&back_push('ol', length($1), \@saved, \@result);
- push(@result, '' . &inline($2, const => \%const) . '');
+ push(@result, '' . &inline($2, %option, const => \%const) . '');
} elsif (/^(-{1,6})(.*)/) {
&back_push('ul', length($1), \@saved, \@result);
my ($pf, $l) = ('', $2);
@@ -367,14 +385,14 @@
my $num = 0+$1;
$pf = qq([$num]);
}
- push(@result, '' . $pf . &inline ($l, const => \%const) . '');
+ push(@result, '' . $pf . &inline ($l, %option, const => \%const) . '');
} elsif (/^:([^:]+):(.*)/) {
&back_push('dl', 1, \@saved, \@result);
- push(@result, '' . &inline($1, const => \%const) . '', '' . &inline($2, const => \%const) . '');
+ push(@result, '' . &inline($1, %option, const => \%const) . '', '' . &inline($2, %option, const => \%const) . '');
} elsif (/^(?!>>\d)(>{1,5})(.*)/) {
&back_push('blockquote', length($1), \@saved, \@result);
push @result, "";
- push(@result, &inline($2, const => \%const));
+ push(@result, &inline($2, %option, const => \%const));
unshift @saved, "
";
} elsif (/^\s*$/) {
push(@result, splice(@saved));
@@ -382,7 +400,7 @@
unshift(@saved, "");
} elsif (/^(\s+.*)$/) {
&back_push('pre', 1, \@saved, \@result);
- push(@result, &inline($1, const => \%const));
+ push(@result, &inline($1, %option, const => \%const));
} elsif (/^\,(.*?)[\x0D\x0A]*$/) {
&back_push('table', 1, \@saved, \@result);
#######
@@ -398,7 +416,7 @@
$colspan[$i]++;
}
$colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
- $value[$i] = sprintf('%s | ', $align[$i], $colspan[$i], &inline($value[$i], const => \%const));
+ $value[$i] = sprintf('%s | ', $align[$i], $colspan[$i], &inline($value[$i], %option, const => \%const));
} else {
$value[$i] = '';
}
@@ -415,9 +433,9 @@
} elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) {
my $num = 0+$1;
push @result, qq([$num]);
- push @result, &inline ($2, const => \%const);
+ push @result, &inline ($2, %option, const => \%const);
} else {
- push(@result, &inline($_, const => \%const));
+ push(@result, &inline($_, %option, const => \%const));
}
}
push(@result, splice(@saved));
@@ -446,7 +464,7 @@
sub inline ($;%) {
my ($line, %option) = @_;
$line = &escape($line);
- $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4)}ge;
+ $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3, $4, \%option)}ge;
$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:\[(WEAK)\[(.+?)\]\]:$2:g;
$line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:$1:g;
@@ -478,7 +496,7 @@
sub make_wikilink ($%) {
my ($ename, %option) = @_;
my $name = &unescape ($ename);
- $option{latest} = $option{latest} ? qq(mycmd=read;x-param=@{[time.[0..9]->[rand 10]]};mypage=) : '';
+ $option{latest} = $option{latest} ? qq(mycmd=default;x-param=@{[time.[0..9]->[rand 10]]};mypage=) : '';
if ($database{$name}) {
my $subject = &escape (&get_subjectline ($name, delimiter => ''));
if ($option{anchor}) {
@@ -530,45 +548,46 @@
}
}
-{my $FormIndex = 0;
-sub make_custom_form ($$$$) {
- my ($wfname, $definition, $template, $option) = @_;
- ## $template and $option is currently not used in this procedure.
- unless ($main::_EMBEDED) {
- $FormIndex++;
+{my %FormIndex;
+sub make_custom_form ($$$$%) {
+ my ($wfname, $definition, $template, $foption, $option) = @_;
+ ## $template is currently not used in this procedure.
+ #unless ($main::_EMBEDED) {
+ $FormIndex{$option->{page}}++;
if (length $definition) {
- my $param = bless {}, 'SuikaWiki::Plugin';
- my $lastmodified = $database->mtime ($form{mypage});
+ my $param = bless {depth=>10}, 'SuikaWiki::Plugin';
+ my $lastmodified = $database->mtime ($option->{page});
&load_formatter (qw/form_input form_option/);
$definition = &unescape ($definition);
$definition =~ s/\\(.)/$1/g;
- $option = &unescape ($option);
- $option =~ s/\\(.)/$1/g;
- $fmt{form_option}->replace ($option, $param);
+ $foption = &unescape ($foption);
+ $foption =~ s/\\(.)/$1/g;
+ $fmt{form_option}->replace ($foption, $param);
$param->{output}->{form} = 1 unless defined $param->{output}->{form};
+ $param->{output}->{form} = 0 if $main::_EMBEDED;
$definition .= ' %submit;' if $definition !~ /%submit/ && !$param->{output}->{nosubmit} && $param->{output}->{form};
- $param->{output}->{page} ||= $form{mypage};
- $param->{form_disabled} = 1 if $database->meta (IsFrozen => $form{mypage});
+ $param->{output}->{page} ||= $option->{page};
+ $param->{form_disabled} = 1 if $database->meta (IsFrozen => $option->{page});
my $target_form = $param->{output}->{id};
my $r = '';
$r = <{output}->{form};
-\n" if $param->{output}->{form};
$r;
} else { ## No input-interface WikiForm
- qq();
+ qq();
}
- } else {
- qq(@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]});
- }
+ #} else {
+ # qq(@{[&Resource('Error:WikiForm:EmbedIsNotSupported',escape=>1)]});
+ #}
}}
sub init_form {
@@ -582,7 +601,7 @@
my $query = &decode($main::ENV{QUERY_STRING});
$query = &code_convert(\$query, $kanjicode);
$form{mypage} = $query;
- $form{mycmd} = $database{$form{mypage}} ? 'read' : 'edit';
+ $form{mycmd} = 'default';
} else {
for (split /[;&]/, $query) {
if (my ($n, $v) = split /=/, $_, 2) {
@@ -597,7 +616,7 @@
}
$form{mypage} ||= $PageName{FrontPage};
$form{mypage} =~ tr/\x00-\x1F\x7F//d;
- $form{mycmd} ||= 'read';
+ $form{mycmd} ||= 'default';
# mypreview_edit -> do_edit, with preview.
# mypreview_adminedit -> do_adminedit, with preview.
@@ -620,25 +639,27 @@
$form{myname} = &code_convert(\$form{myname}, $kanjicode);
}
-{my %SubjectLine;
sub get_subjectline {
my ($page, %option) = @_;
- unless (defined $SubjectLine{$page}) {
+ my $SubjectLine = SuikaWiki::Plugin->cache ('headline');
+ unless (defined $SubjectLine->{$page}) {
if (not &is_editable($page)) {
- $SubjectLine{$page} = "";
+ $SubjectLine->{$page} = "";
} else {
- $SubjectLine{$page} = $database{$page};
- $SubjectLine{$page} =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
- $SubjectLine{$page} =~ s/\x0D?\x0A.*//s;
+ $SubjectLine->{$page} = do {
+ my $s=$database{$page};
+ $s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
+ $s =~ s/\x0D?\x0A.*//s;
+ $s};
}
}
- if (length $SubjectLine{$page}) {
+ if (length $SubjectLine->{$page}) {
$option{delimiter} = defined $option{delimiter} ? $option{delimiter} : &Resource('Title-Summary Delimiter');
- $option{delimiter}.$SubjectLine{$page}.$option{tail};
+ $option{delimiter}.$SubjectLine->{$page}.$option{tail};
} else {
'';
}
-}}
+}
sub open_db {
if ($modifier_dbtype eq 'dbmopen') {
@@ -673,7 +694,7 @@
my $magic = '';
$magic = $1 if $option{content} =~ m/^([^\x0A\x0D]+)/s;
- my $selected = 'read';
+ my $selected = 'default';
if ($form{after_edit_cmd}) {
$selected = $form{after_edit_cmd};
} elsif ($magic =~ /Const|Config|CSS/) {
@@ -681,6 +702,7 @@
}
my $afteredit = <
+
@@ -805,9 +827,9 @@
$form{mymsg} = $content;
$form{mytouch} = 'on';
&do_write;
- } else {
- $form{mycmd} = 'read';
- &do_read;
+ } else { ## Don't write
+ $form{mycmd} = 'default';
+ &do_view;
}
}
@@ -840,7 +862,7 @@
} else {
return <<"EOD";