--- suikawiki/script/wiki.cgi 2002/10/07 12:50:51 1.27 +++ suikawiki/script/wiki.cgi 2002/10/17 07:56:58 1.28 @@ -82,7 +82,7 @@ my $file_FrontPage = "$modifier_dir_data/frontpage.txt"; my $file_conflict = "$modifier_dir_data/conflict.txt"; my $file_format = "$modifier_dir_data/format.txt"; -my $url_cgi = 'wiki'; +my $url_cgi = '/~wakaba/-temp/wiki/wiki'; ## MUST be started from '/' my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle'; my $icontag = '*'; my $maxrecent = 50; @@ -177,6 +177,7 @@ createresult => \&do_createresult, FrontPage => \&do_FrontPage, comment => \&do_comment, + RandomJump => \&do_random_jump, rss => \&do_rss, diff => \&do_diff, interwikibox => \&do_interwiki_box, # Walrus add (5) @@ -214,8 +215,8 @@ ## - 'SuikaWiki/0.9' CRLF ## - 'H2H/' ("0.9" / "1.0" / "1.1") CRLF ## - "/*" WSP* 'W3C-CSS/' ("1.0" / "2.0") "*/" CRLF - $cf = $1 if $content =~ s#^(?:/\*\s*|\#\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s; - if ($cf =~ m#^SuikaWiki/0.9(?:$|\s)#) { + $cf = $1 if $content =~ s#^(?:/\*\s*|[\#<]\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+##s; + if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { &print_content($content, content_format => $cf, last_modified => $lm); print &text_to_html (q([[#comment]])); } else { @@ -390,7 +391,9 @@ my $r = ''; foreach my $page (sort keys %database) { next if $page eq $RecentChanges; - if ( index ($database{$page}, $word) > 0 + my $content = $database{$page}; + $content =~ s/^\#\?[^\x0A\x0D]+//s; + if ( index ($content, $word) > 0 || index ($page, $word) > 0 || index ($word, $page) > 0 ) { @@ -417,6 +420,13 @@ &print_footer($CreatePage); } +sub do_random_jump { + my @list = keys %database; + my $name = &encode ($list[rand @list]); + print "Location: $url_cgi?$name\n"; + print "\n"; +} + sub do_FrontPage { open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)"); my $content = join('', ); @@ -450,9 +460,10 @@ Content-Language: $lang Content-Style-Type: text/css + $escapedpage @{[&escape(&get_subjectline($page))]} @@ -512,7 +523,7 @@ my ($page, $lm) = @_; $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug) # Walrus mod (1) start - my $cvslog = '$Revision: 1.27 $ $Date: 2002/10/07 12:50:51 $'; + my $cvslog = '$Revision: 1.28 $ $Date: 2002/10/17 07:56:58 $'; print_navigate_links ($page); print <<"EOD"; @{[ $lm ? qq(
Last modified: $lm
) : '' ]} @@ -611,8 +622,13 @@ &back_push('ol', length($1), \@saved, \@result); push(@result, '
  • ' . &inline($2) . '
  • '); } elsif (/^(-{1,6})(.*)/) { - &back_push('ul', length($1), \@saved, \@result); - push(@result, '
  • ' . &inline($2) . '
  • '); + &back_push('ul', length($1), \@saved, \@result); + my ($pf, $l) = ('', $2); + if (!$main::_EMBEDED && $l =~ s/^\s*\[([0-9]+)\]//) { + my $num = 0+$1; + $pf = qq([$num]); + } + push(@result, '
  • ' . $pf . &inline ($l) . '
  • '); } elsif (/^:([^:]+):(.*)/) { &back_push('dl', 1, \@saved, \@result); push(@result, '
    ' . &inline($1) . '
    ', '
    ' . &inline($2) . '
    '); @@ -651,18 +667,16 @@ push(@result, join('', '', @value, '')); # XXXXX ####### - } elsif (/^\[INS\[/) { - push(@result, ""); - } elsif (/^\]INS\]/) { - push(@result, ""); - } elsif (/^\[DEL\[/) { - push(@result, ""); - } elsif (/^\]DEL\]/) { - push(@result, ""); - } elsif (/^\[PRE\[/) { - push(@result, "
    ");
    -        } elsif (/^\]PRE\]/) {
    -            push(@result, "
    "); + } elsif (/^\[(INS|DEL|PRE)\[/) { + push @result, splice (@saved), '<'.lc($1).'>'; + unshift @saved, "

    "; + push @result, "

    "; + } elsif (/^\](INS|DEL|PRE)\]/) { + push @result, splice (@saved), ''; + } elsif (/^\[([0-9]+)\](.*)$/ && !$main::_EMBEDED) { + my $num = 0+$1; + push @result, qq([$num]); + push @result, &inline ($2); } else { push(@result, &inline($_)); } @@ -704,6 +718,10 @@ sub inline { my ($line) = @_; $line = &escape($line); + $line =~ s:\[(INS|DEL|SUP|SUB)\[(.+?)\]\]:<@{[lc $1]}>$2:g; + $line =~ s:\[ABBR\[(.+?)\] \[(.+?)\]\]:$1:g; + $line =~ s:\[RUBY\[(.+?)\] \[(.+?)\]\]:$1($2):g; + $line =~ s%\[Q\[(.+?)\](?: \[<([\x21-\x5A\x5E-\x7E]+)>\])?\]%「$1」%g; $line =~ s|'''([^']+?)'''|$1|g; $line =~ s|''([^']+?)''|$1|g; $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|$1|g; # Date @@ -711,18 +729,37 @@ ( (?:<(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)> | - ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]] - | - ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]] - #| - # ($wiki_name) - ) - ! - &make_link($1) - !gex; + (?:$bracket_name)) # [[likethis]], [[#comment]], [[Friend:remotelink]] + |\[\[([^[]+?)]>>([0-9]+)] + |>>([0-9]+) + ! + my ($l, $page,$anchor, $anum) = ($1, $3,$4, 0+$5); + if ($l) { + &make_link($l) + } elsif (defined $page) { + &make_wikilink ($page, anchor => 0+$anchor); + } elsif ($anum) { + qq(>>$anum); + } + !gex; return $line; } +sub make_wikilink ($%) { + my ($ename, %option) = @_; + my $name = &unescape ($ename); + if ($database{$name}) { + my $subject = &escape (&get_subjectline ($name, delimiter => '')); + if ($option{anchor}) { + return qq($ename>>$option{anchor}); + } else { + return qq($ename); + } + } else { + return qq($ename$editchar); + } +} + sub make_link { my $chunk = shift; # Walrus add (3) start @@ -836,18 +873,18 @@ } sub update_recent_changes { - my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}"; + my $update = "- @{[&get_now]} [[@{[&escape($form{mypage})]}]] @{[&get_subjectline($form{mypage})]}"; my @oldupdates = split(/\r?\n/, $database{$RecentChanges}); my @updates; foreach (@oldupdates) { - /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format. - my $name = &unarmor_name($1); - if (&is_exist_page($name) and ($name ne $form{mypage})) { - push(@updates, $_); + /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d \[\[(\S+?)\]\]/; + my $name = $1; + if ($name ne $form{mypage}) { + push @updates, $_; } } if (&is_exist_page($form{mypage})) { - unshift(@updates, $update); + unshift @updates, $update; } splice(@updates, $maxrecent + 1); $database{$RecentChanges} = join("\n", @updates); @@ -871,7 +908,7 @@ # Get the subject of the page. my $subject = $database{$page}; - $subject =~ s#^SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; + $subject =~ s#^(?:\#\?)?SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s; $subject =~ s/\r?\n.*//s; return "$delim$subject".$option{tail}; } @@ -1130,6 +1167,7 @@ sub get_now { my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat); + my (@week) = qw(日 月 火 水 木 金 土); my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); $year += 1900; $mon++; @@ -1137,9 +1175,9 @@ $day = "0$day" if $day < 10; $hour = "0$hour" if $hour < 10; $min = "0$min" if $min < 10; - $sec = "0$sec" if $sec < 10; + #$sec = "0$sec" if $sec < 10; $weekday = $week[$weekday]; - return "$year-$mon-$day ($weekday) $hour:$min:$sec"; + return "$year-$mon-$day ($weekday) $hour:$min"; } # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]] @@ -1230,26 +1268,24 @@ sub do_comment { my ($content) = $database{$form{mypage}}; my $datestr = &get_now; - my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'' : "; - #if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) { - # ; - #} else { - # $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/; - #} + my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'': "; + my $anchor = 0; + $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; if ($i == $form{comment_index}) { if ($embed eq $embed_comment) { - $embed = "- $datestr$namestr$form{mymsg}\n$embed"; $o = 1; + $embed = "- [$anchor] $datestr$namestr$form{mymsg}\n$embed"; $o = 1; } else { - $embed .= "\n- $datestr$namestr$form{mymsg}"; $o = 1; + $embed .= "\n- [$anchor] $datestr$namestr$form{mymsg}"; $o = 1; } } $i++; $embed; }ge; unless ($o) { - $content .= "- $datestr$namestr$form{mymsg}\n"; + $content .= "- [$anchor] $datestr$namestr$form{mymsg}\n"; } if ($form{mymsg}) { $form{mymsg} = $content; @@ -1265,6 +1301,7 @@ sub embedded_to_html { my ($embedded) = @_; if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) { + unless ($main::_EMBEDED) { my $lastmodified = &get_info($form{mypage}, $info_LastModified); return <<"EOD";

    @@ -1279,6 +1316,18 @@
    EOD + } else { + return <<"EOD"; +
    + + + $embed_comment_Name_Prompt + + + +
    +EOD + } } elsif ($embedded =~ /$embed_command{searched}/) { return get_search_result ($1); # Walrus add (5) start @@ -1286,9 +1335,29 @@ $_ = &make_interwiki_box($1, $2); return ($_) ? $_ : $embedded; # Walrus add (5) end - } else { - return $embedded; + } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) { + my ($name, $r) = ($1, ''); + if ($main::_EMBEDED != 1) { + my ($content, $cf) = ($database{$name}, 'SuikaWiki/0.9'); + $cf = $1 if $content =~ s!^(?:[\#<]\?|/\*\s*)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:[^0-9.][^\x0D\x0A]*)?)[\x0D\x0A]+!!s; + if ($cf =~ m!^(?:\#\?)?SuikaWiki/0.9(?:$|\s)!) { + $main::_EMBEDED = 1; + $r = &text_to_html ($content, content_format => $cf); + $main::_EMBEDED = 0; + } elsif (length $content) { + $r = "
    @{[&escape ($content)]}
    "; + } else { + $r = &text_to_html ("[[$name]]", content_format => 'SuikaWiki/0.9'); + } + } else { ## nested #EMBED + $r = &text_to_html ("[INS[\n[[$name]] の埋め込みは (入り組んでいるので) 解決されませんでした。\n]INS]\n", content_format => 'SuikaWiki/0.9'); } + return qq(
    $r
    ); + } elsif ($embedded =~ /^\[\[\#randomlink:(.+)\]\]$/) { + return qq($1); + } else { + return $embedded; + } } # Walrus add (5) start @@ -1439,7 +1508,7 @@ my $count = 0; foreach (split(/\n/, $recentchanges)) { last if ($count >= 15); - /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format. + /^\- \d\d\d\d\-\d\d\-\d\d \([^)]+\) \d\d:\d\d:\d\d (\S+)/; # date format. my $title = &unarmor_name($1); my $escaped_title = &escape($title); my $link = $modifier_rss_link . '?' . &encode($title); @@ -1507,28 +1576,29 @@ } sub get_site_name () { my @lines = grep /[^#]/, split /[\x0D\x0A]+/, &main::__get_database('RefererSiteName'); - my %item; + my @item; for (@lines) { next if /^#/; my ($uri, $name) = split /\s+/, $_, 2; $uri =~ s/\$/\\\$/g; $uri =~ s/\@/\\\@/g; $uri =~ s/\//\\\//g; - $name =~ s![()/\\]!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; - $item{$uri} = qq(q($name)); + $name =~ s!([()/\\])!\\$1!g; $name =~ s/\$([0-9]+)/).__decode (\${$1}).q(/g; + push @item, [$uri, qq(q($name))]; } - %item; + @item; } sub list_html ($) { my $page = shift; my %list = get ($page); my $r = ''; - my %name = get_site_name; + my @name = get_site_name; for my $uri (sort keys %list) { my $title; - for my $regex (keys %name) { - if ($uri =~ /$regex/) { + for my $item (@name) { + if ($uri =~ /$item->[0]/) { $title = $uri; - eval qq{\$title =~ s/^.*$regex.*\$/$name{$regex}/e} or die $@; + eval qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e} + or die $@ ;#. qq{\$title =~ s/^.*$item->[0].*\$/$item->[1]/e}; last; } }