diff options
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/CGI.pm | 12 | ||||
-rw-r--r-- | IkiWiki/Plugin/404.pm | 3 | ||||
-rw-r--r-- | IkiWiki/Plugin/attachment.pm | 6 | ||||
-rw-r--r-- | IkiWiki/Plugin/comments.pm | 32 | ||||
-rw-r--r-- | IkiWiki/Plugin/getsource.pm | 3 | ||||
-rw-r--r-- | IkiWiki/Plugin/goto.pm | 3 | ||||
-rw-r--r-- | IkiWiki/Plugin/inline.pm | 2 | ||||
-rw-r--r-- | IkiWiki/Plugin/linkmap.pm | 25 | ||||
-rw-r--r-- | IkiWiki/Plugin/monotone.pm | 2 | ||||
-rw-r--r-- | IkiWiki/Plugin/pagestats.pm | 10 | ||||
-rw-r--r-- | IkiWiki/Plugin/remove.pm | 6 | ||||
-rw-r--r-- | IkiWiki/Plugin/rename.pm | 9 | ||||
-rw-r--r-- | IkiWiki/Plugin/toc.pm | 11 |
13 files changed, 90 insertions, 34 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 9277223f0..866711a71 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -235,11 +235,15 @@ sub cgi_prefs ($$) { showform($form, $buttons, $session, $q); } -sub cgi_custom_failure ($$) { - my $header=shift; +sub cgi_custom_failure ($$$) { + my $q=shift; + my $httpstatus=shift; my $message=shift; - print $header; + print $q->header( + -status => $httpstatus, + -charset => 'utf-8', + ); print $message; # Internet Explod^Hrer won't show custom 404 responses @@ -274,7 +278,7 @@ sub check_banned ($$) { $session->delete(); cgi_savesession($session); cgi_custom_failure( - $q->header(-status => "403 Forbidden"), + $q, "403 Forbidden", gettext("You are banned.")); } } diff --git a/IkiWiki/Plugin/404.pm b/IkiWiki/Plugin/404.pm index bae9e15d1..85486e559 100644 --- a/IkiWiki/Plugin/404.pm +++ b/IkiWiki/Plugin/404.pm @@ -69,7 +69,8 @@ sub cgi ($) { if (exists $ENV{REDIRECT_STATUS} && $ENV{REDIRECT_STATUS} eq '404') { - my $page = cgi_page_from_404($ENV{REDIRECT_URL}, + my $page = cgi_page_from_404( + Encode::decode_utf8($ENV{REDIRECT_URL}), $config{url}, $config{usedirs}); IkiWiki::Plugin::goto::cgi_goto($cgi, $page); } diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 087c315a9..cbe6efc21 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -112,7 +112,7 @@ sub formbuilder (@) { return if ! defined $form->field("do") || ($form->field("do") ne "edit" && $form->field("do") ne "create") ; - my $filename=$q->param('attachment'); + my $filename=Encode::decode_utf8($q->param('attachment')); if (defined $filename && length $filename && ($form->submitted eq "Upload Attachment" || $form->submitted eq "Save Page")) { my $session=$params{session}; @@ -189,9 +189,10 @@ sub formbuilder (@) { IkiWiki::saveindex(); } elsif ($form->submitted eq "Insert Links") { - my $page=quotemeta($q->param("page")); + my $page=quotemeta(Encode::decode_utf8($q->param("page"))); my $add=""; foreach my $f ($q->param("attachment_select")) { + $f=Encode::decode_utf8($f); $f=~s/^$page\///; $add.="[[$f]]\n"; } @@ -230,6 +231,7 @@ sub attachment_list ($) { link => htmllink($page, $page, $f, noimageinline => 1), size => IkiWiki::Plugin::filecheck::humansize((stat(_))[7]), mtime => displaytime($IkiWiki::pagemtime{$f}), + mtime_raw => $IkiWiki::pagemtime{$f}, }; } } diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 517e16f9f..6340fc2cb 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -377,8 +377,6 @@ sub editcomment ($$) { IkiWiki::check_canedit($page, $cgi, $session); $postcomment=0; - my $location=unique_comment_location($page, $config{srcdir}); - my $content = "[[!comment format=$type\n"; # FIXME: handling of double quotes probably wrong? @@ -410,8 +408,11 @@ sub editcomment ($$) { my $subject = $form->field('subject'); if (defined $subject && length $subject) { $subject =~ s/"/"/g; - $content .= " subject=\"$subject\"\n"; } + else { + $subject = "comment ".(num_comments($page, $config{srcdir}) + 1); + } + $content .= " subject=\"$subject\"\n"; $content .= " date=\"" . decode_utf8(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime)) . "\"\n"; @@ -421,6 +422,8 @@ sub editcomment ($$) { $editcontent =~ s/"/\\"/g; $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n"; + my $location=unique_comment_location($page, $content, $config{srcdir}); + # This is essentially a simplified version of editpage: # - the user does not control the page that's created, only the parent # - it's always a create operation, never an edit @@ -458,7 +461,7 @@ sub editcomment ($$) { if (! $ok) { my $penddir=$config{wikistatedir}."/comments_pending"; - $location=unique_comment_location($page, $penddir); + $location=unique_comment_location($page, $content, $penddir); writefile("$location._comment", $penddir, $content); IkiWiki::printheader($session); print IkiWiki::misctemplate(gettext(gettext("comment stored for moderation")), @@ -554,7 +557,7 @@ sub commentmoderation ($$) { if ($action eq 'Accept') { my $content=eval { readfile($file) }; next if $@; # file vanished since form was displayed - my $dest=unique_comment_location($page, $config{srcdir})."._comment"; + my $dest=unique_comment_location($page, $content, $config{srcdir})."._comment"; writefile($dest, $config{srcdir}, $content); if ($config{rcs} and $config{comments_commit}) { IkiWiki::rcs_add($dest); @@ -813,15 +816,28 @@ sub pagetemplate (@) { } } -sub unique_comment_location ($) { +sub num_comments ($$) { my $page=shift; my $dir=shift; + my @comments=glob("$dir/$page/$config{comments_pagename}*._comment"); + return @comments; +} + +sub unique_comment_location ($$$) { + my $page=shift; + + eval q{use Digest::MD5 'md5_hex'}; + error($@) if $@; + my $content_md5=md5_hex(shift); + + my $dir=shift; + my $location; - my $i = 0; + my $i = num_comments($page, $dir); do { $i++; - $location = "$page/$config{comments_pagename}$i"; + $location = "$page/$config{comments_pagename}${i}_${content_md5}"; } while (-e "$dir/$location._comment"); return $location; diff --git a/IkiWiki/Plugin/getsource.pm b/IkiWiki/Plugin/getsource.pm index ae9ea3cc7..d1555430e 100644 --- a/IkiWiki/Plugin/getsource.pm +++ b/IkiWiki/Plugin/getsource.pm @@ -58,7 +58,8 @@ sub cgi_getsource ($) { if (! exists $pagesources{$page}) { IkiWiki::cgi_custom_failure( - $cgi->header(-status => "404 Not Found"), + $cgi, + "404 Not Found", IkiWiki::misctemplate(gettext("missing page"), "<p>". sprintf(gettext("The page %s does not exist."), diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm index 2e2dc04a1..439552f62 100644 --- a/IkiWiki/Plugin/goto.pm +++ b/IkiWiki/Plugin/goto.pm @@ -51,7 +51,8 @@ sub cgi_goto ($;$) { if (! length $link) { IkiWiki::cgi_custom_failure( - $q->header(-status => "404 Not Found"), + $q, + "404 Not Found", IkiWiki::misctemplate(gettext("missing page"), "<p>". sprintf(gettext("The page %s does not exist."), diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 93dc0149e..17d1611db 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -209,7 +209,7 @@ sub preprocess_inline (@) { if ($params{show}) { $num=$params{show}; } - if ($params{feedshow} && $num < $params{feedshow}) { + if ($params{feedshow} && $num < $params{feedshow} && $num > 0) { $num=$params{feedshow}; } if ($params{skip} && $num) { diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 9540bd112..28acbda32 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -49,6 +49,7 @@ sub genmap ($) { my $mapnum=shift; return "" unless exists $maps{$mapnum}; my %params=%{$maps{$mapnum}}; + my $connected=IkiWiki::yesno($params{connected}); # Get all the items to map. my %mapitems = map { $_ => urlto($_, $params{destpage}) } @@ -79,24 +80,38 @@ sub genmap ($) { print OUT "charset=\"utf-8\";\n"; print OUT "ratio=compress;\nsize=\"".($params{width}+0).", ".($params{height}+0)."\";\n" if defined $params{width} and defined $params{height}; + my %shown; + my $show=sub { + my $item=shift; + if (! $shown{$item}) { + print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n"; + $shown{$item}=1; + } + }; foreach my $item (keys %mapitems) { - print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n"; + $show->($item) unless $connected; foreach my $link (map { bestlink($item, $_) } @{$links{$item}}) { - print OUT "\"$item\" -> \"$link\";\n" - if $mapitems{$link}; + next unless length $link and $mapitems{$link}; + foreach my $endpoint ($item, $link) { + $show->($endpoint); + } + print OUT "\"$item\" -> \"$link\";\n"; } } print OUT "}\n"; - close OUT; + close OUT || error gettext("failed to run dot"); local $/=undef; my $ret="<object data=\"".urlto($dest, $params{destpage}). "\" type=\"image/png\" usemap=\"#linkmap$mapnum\">\n". <IN>. "</object>"; - close IN; + close IN || error gettext("failed to run dot"); waitpid $pid, 0; + if ($?) { + error gettext("failed to run dot"); + } $SIG{PIPE}="DEFAULT"; error gettext("failed to run dot") if $sigpipe; diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index 05c5a514d..c717ceefb 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -228,7 +228,7 @@ sub read_certs ($$) { my @ret; my $line = $results[0]; - while ($line =~ m/\s+key\s"(.*?)"\nsignature\s"(ok|bad|unknown)"\n\s+name\s"(.*?)"\n\s+value\s"(.*?)"\n\s+trust\s"(trusted|untrusted)"\n/sg) { + while ($line =~ m/\s+key\s["\[](.*?)[\]"]\nsignature\s"(ok|bad|unknown)"\n\s+name\s"(.*?)"\n\s+value\s"(.*?)"\n\s+trust\s"(trusted|untrusted)"\n/sg) { push @ret, { key => $1, signature => $2, diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 47638210a..4313aa271 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -63,6 +63,16 @@ sub preprocess (@) { $max = $counts{$page} if $counts{$page} > $max; } + if (exists $params{show}) { + my $i=0; + my %show; + foreach my $key (sort { $counts{$b} <=> $counts{$a} } keys %counts) { + last if ++$i > $params{show}; + $show{$key}=$counts{$key}; + } + %counts=%show; + } + if ($style eq 'table') { return "<table class='pageStats'>\n". join("\n", map { diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm index cbc8a0f2c..2b8cf0414 100644 --- a/IkiWiki/Plugin/remove.pm +++ b/IkiWiki/Plugin/remove.pm @@ -166,7 +166,7 @@ sub formbuilder (@) { removal_confirm($q, $session, 0, $form->field("page")); } elsif ($form->submitted eq "Remove Attachments") { - my @selected=$q->param("attachment_select"); + my @selected=map { Encode::decode_utf8($_) } $q->param("attachment_select"); if (! @selected) { error(gettext("Please select the attachments to remove.")); } @@ -187,7 +187,7 @@ sub sessioncgi ($$) { postremove($session); } elsif ($form->submitted eq 'Remove' && $form->validate) { - my @pages=$q->param("page"); + my @pages=$form->field("page"); # Validate removal by checking that the page exists, # and that the user is allowed to edit(/remove) it. @@ -237,7 +237,7 @@ sub sessioncgi ($$) { } } else { - removal_confirm($q, $session, 0, $q->param("page")); + removal_confirm($q, $session, 0, $form->field("page")); } exit 0; diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index c3e03496f..8213d21f6 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -235,6 +235,7 @@ sub formbuilder (@) { if (defined $form->field("do") && ($form->field("do") eq "edit" || $form->field("do") eq "create")) { + IkiWiki::decode_form_utf8($form); my $q=$params{cgi}; my $session=$params{session}; @@ -242,7 +243,7 @@ sub formbuilder (@) { rename_start($q, $session, 0, $form->field("page")); } elsif ($form->submitted eq "Rename Attachment") { - my @selected=$q->param("attachment_select"); + my @selected=map { Encode::decode_utf8($_) } $q->param("attachment_select"); if (@selected > 1) { error(gettext("Only one attachment can be renamed at a time.")); } @@ -278,7 +279,7 @@ sub sessioncgi ($$) { if ($q->param("do") eq 'rename') { my $session=shift; - my ($form, $buttons)=rename_form($q, $session, $q->param("page")); + my ($form, $buttons)=rename_form($q, $session, Encode::decode_utf8($q->param("page"))); IkiWiki::decode_form_utf8($form); if ($form->submitted eq 'Cancel') { @@ -290,9 +291,9 @@ sub sessioncgi ($$) { # These untaints are safe because of the checks # performed in check_canrename later. - my $src=$q->param("page"); + my $src=$form->field("page"); my $srcfile=IkiWiki::possibly_foolish_untaint($pagesources{$src}); - my $dest=IkiWiki::possibly_foolish_untaint(titlepage($q->param("new_name"))); + my $dest=IkiWiki::possibly_foolish_untaint(titlepage($form->field("new_name"))); my $destfile=$dest; if (! $q->param("attachment")) { my $type=$q->param('type'); diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm index a585564e7..b8537d3eb 100644 --- a/IkiWiki/Plugin/toc.pm +++ b/IkiWiki/Plugin/toc.pm @@ -53,8 +53,8 @@ sub format (@) { my $page=""; my $index=""; my %anchors; - my $curlevel; - my $startlevel=0; + my $startlevel=($params{startlevel} ? $params{startlevel} : 0); + my $curlevel=$startlevel-1; my $liststarted=0; my $indent=sub { "\t" x $curlevel }; $p->handler(start => sub { @@ -65,12 +65,17 @@ sub format (@) { my $anchor="index".++$anchors{$level}."h$level"; $page.="$text<a name=\"$anchor\"></a>"; - # Take the first header level seen as the topmost level, + # Unless we're given startlevel as a parameter, + # take the first header level seen as the topmost level, # even if there are higher levels seen later on. if (! $startlevel) { $startlevel=$level; $curlevel=$startlevel-1; } + elsif (defined $params{startlevel} && + $level < $params{startlevel}) { + return; + } elsif ($level < $startlevel) { $level=$startlevel; } |