--- suikawiki/script/wiki.cgi 2002/12/01 04:32:50 1.32 +++ suikawiki/script/wiki.cgi 2002/12/03 09:34:43 1.33 @@ -97,6 +97,7 @@ my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5) my %embed_command = ( searched => '^\[\[#searched:([^\]]+)\]\]$', + form => qw/\[\[\#form:'((?:[^'\\]|\\.)+)':'((?:[^'\\]|\\.)+)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, ); ############################## my $info_LastModified = 'LastModified'; @@ -152,14 +153,13 @@ rss => \&do_rss, diff => \&do_diff, interwikibox => \&do_interwiki_box, # Walrus add (5) + wikiform => \&do_wikiform, ); ############################## -my @ignore_html_page = ('FrontPage'); # Walrus add (6) -my @ignore_html_tags = ('a', 'br', 'img'); # Walrus add (6) my $walversion = '2.0.beta1.wal.1'; # Walrus add (1) ############################## # &test_convert; -my $UA = ''; +my $UA = ''; ## User agent name &main; exit(0); ############################## @@ -232,7 +232,7 @@ sub id_and_name ($) { my $name = shift; - if ($UA =~ m#Mozilla/2#) { + if ($UA =~ m#Mozilla/[12]\.#) { qq{id="$name"> 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; + if ($form{__comment_anchor_index}) { + $fragment = qq(anchor-$form{__comment_anchor_index}); + } elsif ($form{__wikiform_anchor_index}) { + $fragment = qq(wikiform-$form{__wikiform_anchor_index}); + } + &print_header($CompletedSuccessfully, -noindex => 1, -goto => $url_cgi.'?mycmd=read;mypage='.&encode($form{mypage}).qq(;x-param=@{[time.[0..9]->[rand 10]]}).($fragment?'#'.$fragment:'')); &print_message($resource{saved}); &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}"); &print_footer($CompletedSuccessfully); @@ -461,11 +467,13 @@ } $bodyclass .= " wiki-page-obsoleted" if $option{-content_format} =~ /obsoleted="yes"/; if ($option{-goto}) { - if ($UA =~ m#Mozilla/2|Opera#) { + if ($UA =~ m#Mozilla/[12]\.|Opera#) { $option{-goto} =~ tr/;/&/; - print qq{Refresh: 0; url=$option{-goto}\n}; + print qq{Refresh: 0; url=$option{-goto}\n}; + $option{-goto} = qq(); } else { - print qq{Refresh: 0; url="$option{-goto}"\n}; + print qq{Refresh: 0; url="$option{-goto}"\n}; + $option{-goto} = qq(); } } print qq{Last-Modified: $option{-last_modified}\n} if $option{-last_modified}; @@ -489,7 +497,7 @@ "http://www.w3.org/TR/html4/loose.dtd"> + RUBY --> - $meta_ct + $meta_ct$option{-goto} $escapedpage @@ -567,10 +575,11 @@ sub print_footer { my ($page, $lm) = @_; + my $epage = &encode ($page); $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) # Walrus mod (1) start - my $cvslog1 = q$Revision: 1.32 $; - my $cvslog2 = q$Date: 2002/12/01 04:32:50 $; + my $cvslog1 = q$Revision: 1.33 $; + my $cvslog2 = q$Date: 2002/12/03 09:34:43 $; print_navigate_links ($page); print <<"EOD"; @{[ $lm ? qq(
Last modified: $lm
) : '' ]} @@ -582,25 +591,14 @@
地図 検索] +
+ <$url_cgi?$epage> +
$walrus_log EOD -# print <<"EOD"; -#
-# -# -# -# -# EOD - # Walrus mod (1) end } sub escape { @@ -767,6 +765,7 @@ sub inline { my ($line) = @_; $line = &escape($line); + $line =~ s{$embed_command{form}}{&make_custom_form ($1, $2, $3)}ge; $line =~ s{\[(INS|DEL|SUP|SUB|VAR|CODE|KBD|SAMP|DFN)(?:\(([A-Za-z0-9\x20-]+)\))?\[(.+?)\]\]}{<@{[lc $1]}@{[$2 ? qq( class="$2") : '']}>$3}g; $line =~ s:\[(WEAK)\[(.+?)\]\]:$2:g; $line =~ s:\[ABBR\[([^]]+)\] \[([^]]+)\]\]:$1:g; @@ -848,6 +847,33 @@ } } +my $FormIndex = 0; +sub make_custom_form ($$$) { + my ($definition, $template, $option) = @_; + $definition =~ s/\\(.)/$1/g; + ## $template and $option is currently not used in this procedure. + unless ($main::_EMBEDED) { + $FormIndex++; + my $param = bless {}, 'SuikaWiki::Plugin'; + my $lastmodified = &get_info($form{mypage}, $info_LastModified); + my $r = < + + + + + +EOH + $r .= qq() if $UA =~ m#Mozilla/[12]\.#; + $r .= $fmt{form_input}->replace (&unescape ($definition), $param); + $r .= < +EOH + } else { + q(Warning: form in embeded page is currently not supported.); + } +} + ## to be obsoleted sub make_link { my $chunk = shift; @@ -920,6 +946,9 @@ # $form{mycmd} is frozen here. # + for (grep /^wikiform__/, keys %form) { + $form{$_} = &code_convert (\$form{$_}, $kanjicode); + } $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode); $form{myname} = &code_convert(\$form{myname}, $kanjicode); } @@ -927,6 +956,7 @@ sub update_recent_changes { my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); + shift (@oldupdates); ## '#?' magic line my @updates; foreach (@oldupdates) { /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/; @@ -1239,6 +1269,11 @@ $s = qq([[$s]]) if $s !~ /^[A-Z][a-z]+(?:[A-Z][a-z]+)+$/; &encode (&code_convert (\$p->{name}, $o->{charset} || 'shift_jis')); }; + + $fmt{form_input} = Message::Util::Formatter->new; + for (@{$SuikaWiki::Plugin::List{wikiform_input}||[]}) { + $_->load_formatter ($fmt{form_input}, type => 'wikiform_input'); + } } @@ -1305,9 +1340,10 @@ } elsif (length $namestr) { $namestr = qq( ''[[$namestr]]'': ); } - my $anchor = 0; - $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; - $anchor++; + my $anchor = &get_new_anchor_index ($content); + +# $content =~ s/(?:-+\s)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; + # $anchor++; my $i = 1; my $o = 0; $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{ my $embed = $1; @@ -1336,6 +1372,13 @@ } } +sub get_new_anchor_index ($) { + my $content = shift; + my $anchor = 0; + $content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; + $anchor + 1; +} + my $CommentIndex = 0; sub embedded_to_html { my ($embedded) = @_; @@ -1399,6 +1442,62 @@ } } +sub do_wikiform { + my $content = $database{$form{mypage}}; + my $anchor = &get_new_anchor_index ($content); + for my $t (qw/form_template form_option/) { + unless ($fmt{$t}) { + $fmt{$t} = Message::Util::Formatter->new; + for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { + $_->load_formatter ($fmt{$t}, type => 'wiki'.$t); + } + } + } + my $write = 0; + my $i = 1; + $content =~ s{$embed_command{form}}{ + my ($embed, $template, $option) = ($&, $2, $3); + $template =~ s/\\(.)/$1/g; + $option =~ s/\\(.)/$1/g; + if ($i == $form{wikiform_index}) { + my $param = bless {}, 'SuikaWiki::Plugin'; + $param->{page} = $form{mypage}; + $param->{form_index} = $i; + $param->{anchor_index} = $anchor; + $param->{argv} = \%form; + $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; + $fmt{form_option}->replace ($option, $param); + my $t = $fmt{form_template}->replace ($template, $param); + if (length $t) { + if ($param->{output}->{reverse}) { + $embed = $t . "\n" . $embed; + } else { + $embed .= "\n" . $t; + } + $write = 1; + $form{__comment_anchor_index} = $anchor + unless $param->{anchor_index}; ## $anchor is used! + } + } + $i++; $embed; + }ge; + unless ($write) { + #$content = "#?SuikaWiki/0.9\n\n" unless $content; + #$content .= "\n" unless $content =~ /\n$/s; + # + } + $form{__wikiform_anchor_index} = $form{wikiform_index}; + if ($write) { + $form{mymsg} = $content; + $form{mytouch} = 'on'; + &do_write; + } else { + $form{mycmd} = 'read'; + &do_read; + } +} + + # Walrus add (5) start sub do_interwiki_box { my $remoteurl = $interwiki{$form{'myintername'}}; @@ -1686,6 +1785,24 @@ &main::__set_database ('WikiUserAgentList' => $s); } +package SuikaWiki::Plugin; + our %List; + +sub escape ($$) { main::escape ($_[1]) } +sub unescape ($$) { main::unescape ($_[1]) } +sub encode ($$) { main::encode ($_[1]) } +sub decode ($$) { main::decode ($_[1]) } +sub __get_datetime ($) { main::get_now () } + +sub regist ($@) { + my $pack = shift; + for (@_) { + push @{$List{$_}}, $pack; + } +} + +use SuikaWiki::Plugin::WikiFormBasic; + 1; __END__ =head1 NAME