From e7a840ed9a817cf4db59c90e680afd89e146b581 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 16 Nov 2008 18:11:39 +0000 Subject: htmlbalance: new plugin that balances tags by parsing and re-serializing --- IkiWiki/Plugin/htmlbalance.pm | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 IkiWiki/Plugin/htmlbalance.pm (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm new file mode 100644 index 000000000..667d73b6c --- /dev/null +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -0,0 +1,57 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::htmlbalance; + +# htmlbalance: Parse and re-serialize HTML to ensure balanced tags +# +# Copyright 2008 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { #{{{ + hook(type => "getsetup", id => "htmlbalance", call => \&getsetup); + hook(type => "sanitize", id => "htmlbalance", call => \&sanitize); +} # }}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + +sub sanitize (@) { #{{{ + my %params=@_; + my $ret = ''; + + eval { + use HTML::TreeBuilder; + use XML::Atom::Util qw(encode_xml); + }; + + if ($@) { + error($@); + return $params{content}; + } + + my $tree = HTML::TreeBuilder->new_from_content($params{content}); + my @nodes = $tree->disembowel(); + foreach my $node (@nodes) { + if (ref $node) { + $ret .= $node->as_XML(); + chomp $ret; + $node->delete(); + } + else { + $ret .= encode_xml($node); + } + } + $tree->delete(); + return $ret; +} # }}} + +1 -- cgit v1.2.3 From e8a945845bd0774c2280da53f8a976c48547ede4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Nov 2008 14:19:15 -0500 Subject: use perl modules up front The old code actually did the same thing, just obfuscated -- since the eval use wasn't quoted, it used the modules on load. Thus, the error (not to mentioned the return) was bypassed, and it just failed on load. But that seems like the right thing to do, really, so just made it clearer that's what happens. --- IkiWiki/Plugin/htmlbalance.pm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm index 667d73b6c..8f43d5dac 100644 --- a/IkiWiki/Plugin/htmlbalance.pm +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -10,6 +10,8 @@ package IkiWiki::Plugin::htmlbalance; use warnings; use strict; use IkiWiki 2.00; +use HTML::TreeBuilder; +use XML::Atom::Util qw(encode_xml); sub import { #{{{ hook(type => "getsetup", id => "htmlbalance", call => \&getsetup); @@ -28,16 +30,6 @@ sub sanitize (@) { #{{{ my %params=@_; my $ret = ''; - eval { - use HTML::TreeBuilder; - use XML::Atom::Util qw(encode_xml); - }; - - if ($@) { - error($@); - return $params{content}; - } - my $tree = HTML::TreeBuilder->new_from_content($params{content}); my @nodes = $tree->disembowel(); foreach my $node (@nodes) { -- cgit v1.2.3 From 181bdbe1a9a8a1eb07259466361d98bdc1378499 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Nov 2008 14:27:11 -0500 Subject: use HTML::Entities --- IkiWiki/Plugin/htmlbalance.pm | 4 ++-- doc/plugins/htmlbalance/discussion.mdwn | 2 ++ t/htmlbalance.t | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm index 8f43d5dac..3a2d62d15 100644 --- a/IkiWiki/Plugin/htmlbalance.pm +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -11,7 +11,7 @@ use warnings; use strict; use IkiWiki 2.00; use HTML::TreeBuilder; -use XML::Atom::Util qw(encode_xml); +use HTML::Entities; sub import { #{{{ hook(type => "getsetup", id => "htmlbalance", call => \&getsetup); @@ -39,7 +39,7 @@ sub sanitize (@) { #{{{ $node->delete(); } else { - $ret .= encode_xml($node); + $ret .= encode_entities($node); } } $tree->delete(); diff --git a/doc/plugins/htmlbalance/discussion.mdwn b/doc/plugins/htmlbalance/discussion.mdwn index bad052f1c..c66528a4f 100644 --- a/doc/plugins/htmlbalance/discussion.mdwn +++ b/doc/plugins/htmlbalance/discussion.mdwn @@ -2,6 +2,8 @@ Would it be possible to use [[!cpan HTML::Entities]] rather than `XML::Atom::Util` for encoding entities? The former is already an ikiwiki dependency (via [[!cpan HTML::Parser]]). +> Now switched to HTML::Entities --[[Joey]] + I also wonder if there's any benefit to using this plugin aside from with aggregate. Perhaps a small one but aggregate seems like the main case.. wondering if it would be better to just have aggregate balanace the html diff --git a/t/htmlbalance.t b/t/htmlbalance.t index 783ed9841..e5a5db0ee 100755 --- a/t/htmlbalance.t +++ b/t/htmlbalance.t @@ -5,10 +5,9 @@ use strict; BEGIN { eval q{ use HTML::TreeBuilder; - use XML::Atom::Util qw(encode_xml); }; if ($@) { - eval q{use Test::More skip_all => "HTML::TreeBuilder or XML::Atom::Util not available"}; + eval q{use Test::More skip_all => "HTML::TreeBuilder not available"}; } else { eval q{use Test::More tests => 7}; -- cgit v1.2.3 From 75f262f44dc1b192644252171e77cab90cc7322c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Nov 2008 15:56:15 -0500 Subject: call decode_utf8 inside eval holger reported that decode_utf8 was crashing with perl 5.8.8. Earlier, I thought that passing 0 to the function avoided this with old perls, but that was apparently not enough, it still crashes. So, put it inside the eval, so we can at least recover from it crashing. --- IkiWiki/Plugin/aggregate.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index c9c2880c5..f256b3ac1 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -496,15 +496,19 @@ sub aggregate (@) { #{{{ # that contains invalid UTF-8 sequences. Convert # feed to ascii to try to work around. $feed->{message}.=" ".sprintf(gettext("(invalid UTF-8 stripped from feed)")); - $content=Encode::decode_utf8($content, 0); - $f=eval{XML::Feed->parse(\$content)}; + $f=eval { + $content=Encode::decode_utf8($content, 0); + XML::Feed->parse(\$content) + }; } if ($@) { # Another possibility is badly escaped entities. $feed->{message}.=" ".sprintf(gettext("(feed entities escaped)")); $content=~s/\&(?!amp)(\w+);/&$1;/g; - $content=Encode::decode_utf8($content, 0); - $f=eval{XML::Feed->parse(\$content)}; + $f=eval { + $content=Encode::decode_utf8($content, 0); + XML::Feed->parse(\$content) + }; } if ($@) { $feed->{message}=gettext("feed crashed XML::Feed!")." ($@)"; -- cgit v1.2.3 From 15269fed646bf14692061e634969c98b614daaad Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Nov 2008 02:43:17 -0500 Subject: improve escaping of wikilinks and preprocessor directives The old method failed for '[' x 3. --- IkiWiki/Plugin/aggregate.pm | 8 +++----- IkiWiki/Plugin/recentchanges.pm | 3 ++- IkiWiki/Plugin/recentchangesdiff.pm | 3 ++- debian/changelog | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index f256b3ac1..6cdbbc0e9 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -610,7 +610,7 @@ sub add_page (@) { #{{{ my $template=template($feed->{template}, blind_cache => 1); $template->param(title => $params{title}) if defined $params{title} && length($params{title}); - $template->param(content => htmlescape(htmlabs($params{content}, + $template->param(content => wikiescape(htmlabs($params{content}, defined $params{base} ? $params{base} : $feed->{feedurl}))); $template->param(name => $feed->{name}); $template->param(url => $feed->{url}); @@ -637,11 +637,9 @@ sub add_page (@) { #{{{ } } #}}} -sub htmlescape ($) { #{{{ +sub wikiescape ($) { #{{{ # escape accidental wikilinks and preprocessor stuff - my $html=shift; - $html=~s/(? "getsetup", id => "recentchanges", call => \&getsetup); @@ -163,7 +164,7 @@ sub store ($$$) { #{{{ if (ref $change->{message}) { foreach my $field (@{$change->{message}}) { if (exists $field->{line}) { - $field->{line} =~ s/(?{line} = encode_entities($field->{line}, '\[\]'); } } } diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm index 36acef72e..bc793bada 100644 --- a/IkiWiki/Plugin/recentchangesdiff.pm +++ b/IkiWiki/Plugin/recentchangesdiff.pm @@ -4,6 +4,7 @@ package IkiWiki::Plugin::recentchangesdiff; use warnings; use strict; use IkiWiki 2.00; +use HTML::Entities; my $maxlines=200; @@ -39,7 +40,7 @@ sub pagetemplate (@) { #{{{ $diff=join("", @lines); } # escape links and preprocessor stuff - $diff =~ s/(?param(diff => $diff); } } diff --git a/debian/changelog b/debian/changelog index 294cae6dc..eeb9fe6ce 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ ikiwiki (2.71) UNRELEASED; urgency=low * htmlbalance: New plugin contributed by Simon McVittie. * Change deb dependencies to list Text::Markdown before markdown (really this time). + * Improve escaping of wikilinks and preprocessor directives in content + produced by aggregate and recentchanges. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 -- cgit v1.2.3 From e307eeda3d55446f4bdeb2ac48f4fef0c24b1f3d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Nov 2008 02:48:24 -0500 Subject: html escaping complication Can't escape things to entities if the template then escapes the entities. (aggregate doesn't have this problem.) --- IkiWiki/Plugin/recentchanges.pm | 4 +++- IkiWiki/Plugin/recentchangesdiff.pm | 2 ++ templates/change.tmpl | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 39a123ccf..4d7023c1c 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -160,10 +160,12 @@ sub store ($$$) { #{{{ ); } - # escape wikilinks and preprocessor stuff in commit messages if (ref $change->{message}) { foreach my $field (@{$change->{message}}) { if (exists $field->{line}) { + # escape html + $field->{line} = encode_entities($field->{line}); + # escape links and preprocessor stuff $field->{line} = encode_entities($field->{line}, '\[\]'); } } diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm index bc793bada..08cec3f5a 100644 --- a/IkiWiki/Plugin/recentchangesdiff.pm +++ b/IkiWiki/Plugin/recentchangesdiff.pm @@ -39,6 +39,8 @@ sub pagetemplate (@) { #{{{ else { $diff=join("", @lines); } + # escape html + $diff = encode_entities($diff); # escape links and preprocessor stuff $diff = encode_entities($diff, '\[\]'); $template->param(diff => $diff); diff --git a/templates/change.tmpl b/templates/change.tmpl index 0aebae61e..0e61a80f4 100644 --- a/templates/change.tmpl +++ b/templates/change.tmpl @@ -32,14 +32,14 @@
-
+
-
+
 
-- cgit v1.2.3 From a990afd2f735381c81684c8faac011bbdafd09ee Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Nov 2008 13:46:03 -0500 Subject: avoid uninitialized value warning --- IkiWiki/Plugin/aggregate.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index 6cdbbc0e9..adaa619ab 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -535,7 +535,7 @@ sub aggregate (@) { #{{{ copyright => $f->copyright, title => defined $entry->title ? decode_entities($entry->title) : "untitled", link => $entry->link, - content => defined $c ? $c->body : "", + content => (defined $c && defined $c->body) ? $c->body : "", guid => defined $entry->id ? $entry->id : time."_".$feed->{name}, ctime => $entry->issued ? ($entry->issued->epoch || time) : time, base => (defined $c && $c->can("base")) ? $c->base : undef, -- cgit v1.2.3 From 38f5e3ba6944ab67bff87fdbb2cc50606b806085 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Dec 2008 13:50:51 -0500 Subject: move feedpages application up I wanted this nearer to the top, but decided to put it after the add_depends. Reasoning: It's possible with a combinaton of feedpages and show options to make @list and @feedlist contain completly differing sets of pages. We want to add_depends all pages in both sets. We could combine the two lists and add_depends that, but it's slightly more efficient to defer reducing @feedlist, and add_depends whichever list is longer. --- IkiWiki/Plugin/inline.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 7fe5a4dcf..0c8f50384 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -232,6 +232,10 @@ sub preprocess_inline (@) { #{{{ # that if they are removed or otherwise changed, the inline will be # sure to be updated. add_depends($params{page}, join(" or ", $#list >= $#feedlist ? @list : @feedlist)); + + if ($feeds && exists $params{feedpages}) { + @feedlist=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @feedlist; + } my $feednum=""; @@ -364,10 +368,6 @@ sub preprocess_inline (@) { #{{{ } if ($feeds) { - if (exists $params{feedpages}) { - @feedlist=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @feedlist; - } - if ($rss) { my $rssp=rsspage($params{destpage}).$feednum; will_render($params{destpage}, $rssp); -- cgit v1.2.3 From 63eb9d834e2f7e08535473934e169cfe7d7debe6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Dec 2008 14:04:38 -0500 Subject: inline: Support emptyfeeds=no option to skip generating empty feeds. --- IkiWiki/Plugin/inline.pm | 10 ++++++++-- debian/changelog | 1 + doc/ikiwiki/directive/inline.mdwn | 4 +++- doc/todo/inline_plugin:_hide_feed_buttons_if_empty.mdwn | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 0c8f50384..5e4df95f4 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -161,6 +161,7 @@ sub preprocess_inline (@) { #{{{ my $atom=(($config{atom} || $config{allowatom}) && exists $params{atom}) ? yesno($params{atom}) : $config{atom}; my $quick=exists $params{quick} ? yesno($params{quick}) : 0; my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick; + my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1; my $feedonly=yesno($params{feedonly}); if (! exists $params{show} && ! $archive) { $params{show}=10; @@ -289,8 +290,13 @@ sub preprocess_inline (@) { #{{{ gettext("Add a new post titled:")); } $ret.=$formtemplate->output; + + # The post form includes the feed buttons, so + # emptyfeeds cannot be hidden. + $emptyfeeds=1; } - elsif ($feeds && !$params{preview}) { + elsif ($feeds && !$params{preview} && + ! (! $emptyfeeds && ! @feedlist)) { # Add feed buttons. my $linktemplate=template("feedlink.tmpl", blind_cache => 1); $linktemplate->param(rssurl => $rssurl) if $rss; @@ -367,7 +373,7 @@ sub preprocess_inline (@) { #{{{ } } - if ($feeds) { + if ($feeds && ! (! $emptyfeeds && ! @feedlist)) { if ($rss) { my $rssp=rsspage($params{destpage}).$feednum; will_render($params{destpage}, $rssp); diff --git a/debian/changelog b/debian/changelog index 8d2b6661f..7f6844366 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,7 @@ ikiwiki (2.71) UNRELEASED; urgency=low * Fix handling of wrappergroup option. * Correct --dumpsetup to include the srcdir in the setup file. * German translation update from Kai Wasserbäch. Closes: #507056 + * inline: Support emptyfeeds=no option to skip generating empty feeds. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn index 9889cda11..82b532e0c 100644 --- a/doc/ikiwiki/directive/inline.mdwn +++ b/doc/ikiwiki/directive/inline.mdwn @@ -73,6 +73,8 @@ Here are some less often needed parameters: configured to `allowatom`, set to "yes" to enable. * `feeds` - controls generation of all types of feeds. Set to "no" to disable generating any feeds. +* `emptyfeeds` - Set to "no" to disable generation of empty feeds. + Has no effect if `rootpage` or `postform` is set. * `template` - Specifies the template to fill out to display each inlined page. By default the `inlinepage` template is used, while the `archivepage` template is used for archives. Set this parameter to @@ -97,7 +99,7 @@ Here are some less often needed parameters: in the blog. The format string is passed to the strftime(3) function. * `feedpages` - A [[PageSpec]] of inlined pages to include in the rss/atom feeds. The default is the same as the `pages` value above, and only pages - matches by that value are included, but some of those can be excluded by + matched by that value are included, but some of those can be excluded by specifying a tighter [[PageSpec]] here. * `guid` - If a URI is given here (perhaps a UUID prefixed with `urn:uuid:`), the Atom feed will have this as its ``. The default is to use the URL diff --git a/doc/todo/inline_plugin:_hide_feed_buttons_if_empty.mdwn b/doc/todo/inline_plugin:_hide_feed_buttons_if_empty.mdwn index f998d5654..d046c0cd0 100644 --- a/doc/todo/inline_plugin:_hide_feed_buttons_if_empty.mdwn +++ b/doc/todo/inline_plugin:_hide_feed_buttons_if_empty.mdwn @@ -2,3 +2,6 @@ drop the rss/atom buttons for comments when there are none yet This seems to me like something that applies to the [[plugins/inline]] plugin in general, rather than the [[plugins/contrib/comments]] plugin specifically. --[[smcv]] + +>> [[done]] as emptyfeeds option, not on by default for inline, but I think +>> it should be for comments --[[Joey]] -- cgit v1.2.3 From b67632cdcdd333cf0a88d03c0f7e6e62921f32c3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Dec 2008 15:01:26 -0500 Subject: inline: Support feedfile option to change the filename of the feed generated. --- IkiWiki.pm | 8 ++- IkiWiki/Plugin/inline.pm | 63 ++++++++++-------- debian/changelog | 2 + doc/ikiwiki/directive/inline.mdwn | 5 ++ doc/plugins/write.mdwn | 6 +- ...line_plugin:_ability_to_override_feed_name.mdwn | 2 + po/de.po | 74 +++++++++++----------- po/fr.po | 71 +++++++++++---------- po/ikiwiki.pot | 52 +++++++-------- 9 files changed, 156 insertions(+), 127 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki.pm b/IkiWiki.pm index 2ad2f792d..1c68c2cb3 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -666,11 +666,15 @@ sub newpagefile ($$) { #{{{ } } #}}} -sub targetpage ($$) { #{{{ +sub targetpage ($$;$) { #{{{ my $page=shift; my $ext=shift; + my $filename=shift; - if (! $config{usedirs} || $page eq 'index') { + if (defined $filename) { + return $page."/".$filename.".".$ext; + } + elsif (! $config{usedirs} || $page eq 'index') { return $page.".".$ext; } else { diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 5e4df95f4..17cc46e0e 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -26,8 +26,7 @@ sub import { #{{{ # Hook to change to do pinging since it's called late. # This ensures each page only pings once and prevents slow # pings interrupting page builds. - hook(type => "change", id => "inline", - call => \&IkiWiki::pingurl); + hook(type => "change", id => "inline", call => \&IkiWiki::pingurl); } # }}} sub getopt () { #{{{ @@ -238,28 +237,46 @@ sub preprocess_inline (@) { #{{{ @feedlist=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @feedlist; } - my $feednum=""; - - my $feedid=join("\0", map { $_."\0".$params{$_} } sort keys %params); - if (exists $knownfeeds{$feedid}) { - $feednum=$knownfeeds{$feedid}; - } - else { - if (exists $page_numfeeds{$params{destpage}}) { - if ($feeds) { - $feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}}; + my ($feedbase, $feednum); + if ($feeds) { + # Ensure that multiple feeds on a page go to unique files. + + # Feedfile can lead to conflicts if usedirs is not enabled, + # so avoid supporting it in that case. + delete $params{feedfile} if ! $config{usedirs}; + # Tight limits on legal feedfiles, to avoid security issues + # and conflicts. + if (defined $params{feedfile}) { + if ($params{feedfile} =~ /\// || + $params{feedfile} !~ /$config{wiki_file_regexp}/) { + error("illegal feedfile"); } + $params{feedfile}=possibly_foolish_untaint($params{feedfile}); + } + $feedbase=targetpage($params{destpage}, "", $params{feedfile}); + + my $feedid=join("\0", $feedbase, map { $_."\0".$params{$_} } sort keys %params); + if (exists $knownfeeds{$feedid}) { + $feednum=$knownfeeds{$feedid}; } else { - $feednum=$knownfeeds{$feedid}=""; - if ($feeds) { - $page_numfeeds{$params{destpage}}=1; + if (exists $page_numfeeds{$params{destpage}}{$feedbase}) { + if ($feeds) { + $feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}}{$feedbase}; + } + } + else { + $feednum=$knownfeeds{$feedid}=""; + if ($feeds) { + $page_numfeeds{$params{destpage}}{$feedbase}=1; + } } } } - my $rssurl=basename(rsspage($params{destpage}).$feednum) if $feeds && $rss; - my $atomurl=basename(atompage($params{destpage}).$feednum) if $feeds && $atom; + my $rssurl=basename($feedbase."rss".$feednum) if $feeds && $rss; + my $atomurl=basename($feedbase."atom".$feednum) if $feeds && $atom; + my $ret=""; if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} || @@ -375,7 +392,7 @@ sub preprocess_inline (@) { #{{{ if ($feeds && ! (! $emptyfeeds && ! @feedlist)) { if ($rss) { - my $rssp=rsspage($params{destpage}).$feednum; + my $rssp=$feedbase."rss".$feednum; will_render($params{destpage}, $rssp); if (! $params{preview}) { writefile($rssp, $config{destdir}, @@ -386,7 +403,7 @@ sub preprocess_inline (@) { #{{{ } } if ($atom) { - my $atomp=atompage($params{destpage}).$feednum; + my $atomp=$feedbase."atom".$feednum; will_render($params{destpage}, $atomp); if (! $params{preview}) { writefile($atomp, $config{destdir}, @@ -475,14 +492,6 @@ sub absolute_urls ($$) { #{{{ return $content; } #}}} -sub rsspage ($) { #{{{ - return targetpage(shift, "rss"); -} #}}} - -sub atompage ($) { #{{{ - return targetpage(shift, "atom"); -} #}}} - sub genfeed ($$$$$@) { #{{{ my $feedtype=shift; my $feedurl=shift; diff --git a/debian/changelog b/debian/changelog index 7f6844366..1ff78d749 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ ikiwiki (2.71) UNRELEASED; urgency=low * Correct --dumpsetup to include the srcdir in the setup file. * German translation update from Kai Wasserbäch. Closes: #507056 * inline: Support emptyfeeds=no option to skip generating empty feeds. + * inline: Support feedfile option to change the filename of the feed + generated. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn index 82b532e0c..40670e1e7 100644 --- a/doc/ikiwiki/directive/inline.mdwn +++ b/doc/ikiwiki/directive/inline.mdwn @@ -104,6 +104,11 @@ Here are some less often needed parameters: * `guid` - If a URI is given here (perhaps a UUID prefixed with `urn:uuid:`), the Atom feed will have this as its ``. The default is to use the URL of the page containing the `inline` directive. +* `feedfile` - Can be used to change the name of the file generated for the + feed. This is particularly useful if a page contains multiple feeds. + For example, set "feedfile=feed" to cause it to generate `page/feed.atom` + and/or `page/feed.rss`. This option is not supported if the wiki is + configured not to use `usedirs`. [[!meta robots="noindex, follow"]] diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index abcabbdc3..b6fa96f91 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -696,11 +696,15 @@ This can be called when creating a new page, to determine what filename to save the page to. It's passed a page name, and its type, and returns the name of the file to create, relative to the srcdir. -#### `targetpage($$)` +#### `targetpage($$;$)` Passed a page and an extension, returns the filename that page will be rendered to. +Optionally, a third parameter can be passed, to specify the preferred +filename of the page. For example, `targetpage("foo", "rss", "feed")` +will yield something like `foo/feed.rss`. + ## Miscellaneous ### Internal use pages diff --git a/doc/todo/inline_plugin:_ability_to_override_feed_name.mdwn b/doc/todo/inline_plugin:_ability_to_override_feed_name.mdwn index 71bc3bdd6..df5bf9194 100644 --- a/doc/todo/inline_plugin:_ability_to_override_feed_name.mdwn +++ b/doc/todo/inline_plugin:_ability_to_override_feed_name.mdwn @@ -25,3 +25,5 @@ could perhaps change it to `/sandbox-comments.atom` or > Particularly for the non-usedirs case, where a page `sandbox/comments` > would produce the same feed as sandbox with `feedname=comments`. > --[[Joey]] + +> [[done]] as feedfile option --[[Joey]] diff --git a/po/de.po b/po/de.po index 55234a909..d49d0c6ca 100644 --- a/po/de.po +++ b/po/de.po @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: ikiwiki 2.70\n" -"Report-Msgid-Bugs-To: ikiwiki@packages.debian.org\n" -"POT-Creation-Date: 2008-10-31 16:37-0400\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2008-12-11 14:46-0500\n" "PO-Revision-Date: 2008-11-20 19:58+0100\n" "Last-Translator: Kai Wasserbäch \n" "Language-Team: German \n" @@ -47,7 +47,7 @@ msgstr "Einstellungen gespeichert." msgid "You are banned." msgstr "Sie sind ausgeschlossen worden." -#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1182 +#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1204 msgid "Error" msgstr "Fehler" @@ -110,16 +110,16 @@ msgstr "Feed nicht gefunden" msgid "(invalid UTF-8 stripped from feed)" msgstr "(ungültiges UTF-8-Zeichen wurde aus dem Feed entfernt)" -#: ../IkiWiki/Plugin/aggregate.pm:504 +#: ../IkiWiki/Plugin/aggregate.pm:506 #, perl-format msgid "(feed entities escaped)" msgstr "(Feed-Entitäten maskiert)" -#: ../IkiWiki/Plugin/aggregate.pm:510 +#: ../IkiWiki/Plugin/aggregate.pm:514 msgid "feed crashed XML::Feed!" msgstr "Feed führte zum Absturz von XML::Feed!" -#: ../IkiWiki/Plugin/aggregate.pm:590 +#: ../IkiWiki/Plugin/aggregate.pm:595 #, perl-format msgid "creating new page %s" msgstr "erstelle neue Seite %s" @@ -128,7 +128,7 @@ msgstr "erstelle neue Seite %s" msgid "deleting bucket.." msgstr "Lösche Bucket..." -#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:206 +#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:208 msgid "done" msgstr "fertig" @@ -171,7 +171,7 @@ msgid "automatic index generation" msgstr "automatische Index-Erstellung" #: ../IkiWiki/Plugin/brokenlinks.pm:33 ../IkiWiki/Plugin/editpage.pm:261 -#: ../IkiWiki/Plugin/inline.pm:327 ../IkiWiki/Plugin/opendiscussion.pm:26 +#: ../IkiWiki/Plugin/inline.pm:344 ../IkiWiki/Plugin/opendiscussion.pm:26 #: ../IkiWiki/Plugin/orphans.pm:37 ../IkiWiki/Render.pm:79 #: ../IkiWiki/Render.pm:149 msgid "discussion" @@ -245,11 +245,11 @@ msgstr "»edittemplate« %s registriert für %s" msgid "failed to process" msgstr "Bearbeitung fehlgeschlagen" -#: ../IkiWiki/Plugin/format.pm:22 +#: ../IkiWiki/Plugin/format.pm:20 msgid "must specify format and text" msgstr "Format und Text muss spezifiziert werden" -#: ../IkiWiki/Plugin/format.pm:25 +#: ../IkiWiki/Plugin/format.pm:23 #, perl-format msgid "unsupported page format %s" msgstr "nicht unterstütztes Seitenformat %s" @@ -276,7 +276,8 @@ msgstr "Es ist Ihnen nicht erlaubt, Dateizugriffsrechte zu ändern" #: ../IkiWiki/Plugin/google.pm:27 #, perl-format msgid "Must specify %s when using the google search plugin" -msgstr "%s muss angegeben werden, wenn die Google-Sucherweiterung verwandt wird" +msgstr "" +"%s muss angegeben werden, wenn die Google-Sucherweiterung verwandt wird" #: ../IkiWiki/Plugin/google.pm:31 msgid "Failed to parse url, cannot determine domain name" @@ -320,17 +321,17 @@ msgstr "Größenänderung fehlgeschlagen: %s" msgid "failed to determine size of image %s" msgstr "Größe des Bildes %s konnte nicht festgestellt werden." -#: ../IkiWiki/Plugin/inline.pm:93 +#: ../IkiWiki/Plugin/inline.pm:92 msgid "Must specify url to wiki with --url when using --rss or --atom" msgstr "" "Die URL zum Wiki muss mit --url angegeben werden, wenn --rss oder --atom " "genutzt wird" -#: ../IkiWiki/Plugin/inline.pm:139 +#: ../IkiWiki/Plugin/inline.pm:138 msgid "page editing not allowed" msgstr "Seitenbearbeitungen sind nicht erlaubt" -#: ../IkiWiki/Plugin/inline.pm:156 +#: ../IkiWiki/Plugin/inline.pm:155 msgid "missing pages parameter" msgstr "Fehlender Seitenparameter" @@ -339,20 +340,20 @@ msgstr "Fehlender Seitenparameter" msgid "unknown sort type %s" msgstr "Unbekannter Sortierungstyp %s" -#: ../IkiWiki/Plugin/inline.pm:285 +#: ../IkiWiki/Plugin/inline.pm:297 msgid "Add a new post titled:" msgstr "Füge einen neuen Beitrag hinzu. Titel:" -#: ../IkiWiki/Plugin/inline.pm:301 +#: ../IkiWiki/Plugin/inline.pm:318 #, perl-format msgid "nonexistant template %s" msgstr "nicht-vorhandene Vorlage %s" -#: ../IkiWiki/Plugin/inline.pm:335 ../IkiWiki/Render.pm:83 +#: ../IkiWiki/Plugin/inline.pm:352 ../IkiWiki/Render.pm:83 msgid "Discussion" msgstr "Diskussion" -#: ../IkiWiki/Plugin/inline.pm:572 +#: ../IkiWiki/Plugin/inline.pm:577 msgid "RPC::XML::Client not found, not pinging" msgstr "RPC::XML::Client nicht gefunden, führe Ping nicht aus" @@ -568,20 +569,18 @@ msgstr "Unzulässiger Prozentwert (%s)" #: ../IkiWiki/Plugin/progress.pm:59 msgid "need either `percent` or `totalpages` and `donepages` parameters" -msgstr "" -"Benötige entweder »percent«- oder »totalpages«- und " -"»donepages«-Parameter" +msgstr "Benötige entweder »percent«- oder »totalpages«- und »donepages«-Parameter" -#: ../IkiWiki/Plugin/recentchanges.pm:100 +#: ../IkiWiki/Plugin/recentchanges.pm:101 msgid "missing page" msgstr "fehlende Seite" -#: ../IkiWiki/Plugin/recentchanges.pm:102 +#: ../IkiWiki/Plugin/recentchanges.pm:103 #, perl-format msgid "The page %s does not exist." msgstr "Die Seite %s existiert nicht." -#: ../IkiWiki/Plugin/recentchangesdiff.pm:36 +#: ../IkiWiki/Plugin/recentchangesdiff.pm:37 msgid "(Diff truncated)" msgstr "(Diff beschnitten)" @@ -593,7 +592,8 @@ msgstr "%s existiert nicht" #: ../IkiWiki/Plugin/remove.pm:38 #, perl-format msgid "%s is not in the srcdir, so it cannot be deleted" -msgstr "%s ist nicht im Quellverzeichnis und kann deshalb nicht gelöscht werden" +msgstr "" +"%s ist nicht im Quellverzeichnis und kann deshalb nicht gelöscht werden" #: ../IkiWiki/Plugin/remove.pm:41 ../IkiWiki/Plugin/rename.pm:45 #, perl-format @@ -928,19 +928,19 @@ msgstr "Dateiname des Wrappers nicht angegeben" #. translators: The first parameter is a filename, and the second is #. translators: a (probably not translated) error message. -#: ../IkiWiki/Wrapper.pm:79 +#: ../IkiWiki/Wrapper.pm:97 #, perl-format msgid "failed to write %s: %s" msgstr "Schreiben von %s fehlgeschlagen: %s" #. translators: The parameter is a C filename. -#: ../IkiWiki/Wrapper.pm:135 +#: ../IkiWiki/Wrapper.pm:154 #, perl-format msgid "failed to compile %s" msgstr "Erzeugen von %s fehlgeschlagen" #. translators: The parameter is a filename. -#: ../IkiWiki/Wrapper.pm:155 +#: ../IkiWiki/Wrapper.pm:174 #, perl-format msgid "successfully generated %s" msgstr "%s wurde erfolgreich erstellt" @@ -953,43 +953,43 @@ msgstr "Benutzung: ikiwiki [Optionen] Quelle Ziel" msgid " ikiwiki --setup configfile" msgstr " ikiwiki --setup Konfigurationsdatei " -#: ../ikiwiki.in:90 +#: ../ikiwiki.in:91 msgid "usage: --set var=value" msgstr "Benutzung: --set Variable=Wert" -#: ../ikiwiki.in:138 +#: ../ikiwiki.in:139 msgid "generating wrappers.." msgstr "erzeuge Wrapper..." -#: ../ikiwiki.in:195 +#: ../ikiwiki.in:197 msgid "rebuilding wiki.." msgstr "erzeuge Wiki neu..." -#: ../ikiwiki.in:198 +#: ../ikiwiki.in:200 msgid "refreshing wiki.." msgstr "aktualisiere Wiki..." -#: ../IkiWiki.pm:466 +#: ../IkiWiki.pm:480 msgid "Must specify url to wiki with --url when using --cgi" msgstr "" "Es muss eine URL zum Wiki mit --url angegeben werden, wenn --cgi verwandt " "wird" -#: ../IkiWiki.pm:512 +#: ../IkiWiki.pm:526 msgid "cannot use multiple rcs plugins" msgstr "Kann nicht mehrere Versionskontrollsystem-Erweiterungen verwenden" -#: ../IkiWiki.pm:541 +#: ../IkiWiki.pm:555 #, perl-format msgid "failed to load external plugin needed for %s plugin: %s" msgstr "Laden der für %s benötigten externen Erweiterung fehlgeschlagen: %s" -#: ../IkiWiki.pm:1165 +#: ../IkiWiki.pm:1187 #, perl-format msgid "preprocessing loop detected on %s at depth %i" msgstr "Präprozessorschleife auf %s in Tiefe %i erkannt" -#: ../IkiWiki.pm:1678 +#: ../IkiWiki.pm:1688 msgid "yes" msgstr "ja" diff --git a/po/fr.po b/po/fr.po index b8e84f930..ebc21fd9a 100644 --- a/po/fr.po +++ b/po/fr.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: ikiwiki 2.70 \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-10-31 16:37-0400\n" +"POT-Creation-Date: 2008-12-11 14:46-0500\n" "PO-Revision-Date: 2008-11-19 21:53+0100\n" "Last-Translator: Philippe Batailler \n" "Language-Team: French \n" @@ -49,7 +49,7 @@ msgstr "Les préférences ont été enregistrées." msgid "You are banned." msgstr "Vous avez été banni." -#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1182 +#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1204 msgid "Error" msgstr "Erreur" @@ -112,16 +112,16 @@ msgstr "Flux introuvable " msgid "(invalid UTF-8 stripped from feed)" msgstr "(chaîne UTF-8 non valable supprimée du flux)" -#: ../IkiWiki/Plugin/aggregate.pm:504 +#: ../IkiWiki/Plugin/aggregate.pm:506 #, perl-format msgid "(feed entities escaped)" msgstr "(échappement des entités de flux)" -#: ../IkiWiki/Plugin/aggregate.pm:510 +#: ../IkiWiki/Plugin/aggregate.pm:514 msgid "feed crashed XML::Feed!" msgstr "Plantage du flux XML::Feed !" -#: ../IkiWiki/Plugin/aggregate.pm:590 +#: ../IkiWiki/Plugin/aggregate.pm:595 #, perl-format msgid "creating new page %s" msgstr "Création de la nouvelle page %s" @@ -130,7 +130,7 @@ msgstr "Création de la nouvelle page %s" msgid "deleting bucket.." msgstr "suppression du compartiment S3 (« bucket »)..." -#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:206 +#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:208 msgid "done" msgstr "Terminé" @@ -173,7 +173,7 @@ msgid "automatic index generation" msgstr "génération de l'index automatique" #: ../IkiWiki/Plugin/brokenlinks.pm:33 ../IkiWiki/Plugin/editpage.pm:261 -#: ../IkiWiki/Plugin/inline.pm:327 ../IkiWiki/Plugin/opendiscussion.pm:26 +#: ../IkiWiki/Plugin/inline.pm:344 ../IkiWiki/Plugin/opendiscussion.pm:26 #: ../IkiWiki/Plugin/orphans.pm:37 ../IkiWiki/Render.pm:79 #: ../IkiWiki/Render.pm:149 msgid "discussion" @@ -247,11 +247,11 @@ msgstr "edittemplate %s enregistré pour %s" msgid "failed to process" msgstr "Échec du traitement" -#: ../IkiWiki/Plugin/format.pm:22 +#: ../IkiWiki/Plugin/format.pm:20 msgid "must specify format and text" msgstr "le format et le texte doivent être indiqués" -#: ../IkiWiki/Plugin/format.pm:25 +#: ../IkiWiki/Plugin/format.pm:23 #, perl-format msgid "unsupported page format %s" msgstr "format de page non reconnu %s" @@ -321,17 +321,17 @@ msgstr "Échec du redimensionnement : %s" msgid "failed to determine size of image %s" msgstr "Échec de la détermination de la taille de l'image : %s" -#: ../IkiWiki/Plugin/inline.pm:93 +#: ../IkiWiki/Plugin/inline.pm:92 msgid "Must specify url to wiki with --url when using --rss or --atom" msgstr "" "Vous devez indiquer l'URL du wiki par --url lors de l'utilisation de --rss " "ou --atom" -#: ../IkiWiki/Plugin/inline.pm:139 +#: ../IkiWiki/Plugin/inline.pm:138 msgid "page editing not allowed" msgstr "Modification de page interdite" -#: ../IkiWiki/Plugin/inline.pm:156 +#: ../IkiWiki/Plugin/inline.pm:155 msgid "missing pages parameter" msgstr "paramètre « pages » manquant" @@ -340,20 +340,20 @@ msgstr "paramètre « pages » manquant" msgid "unknown sort type %s" msgstr "Type de tri %s inconnu" -#: ../IkiWiki/Plugin/inline.pm:285 +#: ../IkiWiki/Plugin/inline.pm:297 msgid "Add a new post titled:" msgstr "Ajouter un nouvel article dont le titre est :" -#: ../IkiWiki/Plugin/inline.pm:301 +#: ../IkiWiki/Plugin/inline.pm:318 #, perl-format msgid "nonexistant template %s" msgstr "Le modèle de page %s n'existe pas" -#: ../IkiWiki/Plugin/inline.pm:335 ../IkiWiki/Render.pm:83 +#: ../IkiWiki/Plugin/inline.pm:352 ../IkiWiki/Render.pm:83 msgid "Discussion" msgstr "Discussion" -#: ../IkiWiki/Plugin/inline.pm:572 +#: ../IkiWiki/Plugin/inline.pm:577 msgid "RPC::XML::Client not found, not pinging" msgstr "RPC::XML::Client introuvable, pas de réponse au ping" @@ -573,16 +573,16 @@ msgid "need either `percent` or `totalpages` and `donepages` parameters" msgstr "" "L'un des paramètres « percent », « totalpages » ou « donepages » est nécessaire." -#: ../IkiWiki/Plugin/recentchanges.pm:100 +#: ../IkiWiki/Plugin/recentchanges.pm:101 msgid "missing page" msgstr "Page manquante" -#: ../IkiWiki/Plugin/recentchanges.pm:102 +#: ../IkiWiki/Plugin/recentchanges.pm:103 #, perl-format msgid "The page %s does not exist." msgstr "La page %s n'existe pas." -#: ../IkiWiki/Plugin/recentchangesdiff.pm:36 +#: ../IkiWiki/Plugin/recentchangesdiff.pm:37 msgid "(Diff truncated)" msgstr "(fichier de différences tronqué)" @@ -820,12 +820,14 @@ msgstr "" #: ../IkiWiki/Plugin/websetup.pm:433 #, perl-format msgid "

Error: %s exited nonzero (%s)" -msgstr "

Erreur : %s s'est terminé, valeur de sortie nonzero (%s)" +msgstr "" +"

Erreur : %s s'est terminé, valeur de sortie nonzero (%s)" #: ../IkiWiki/Receive.pm:35 #, perl-format msgid "cannot determine id of untrusted committer %s" -msgstr "Impossible de déterminer l'identifiant de %s, (enregistrement non fiable)" +msgstr "" +"Impossible de déterminer l'identifiant de %s, (enregistrement non fiable)" #: ../IkiWiki/Receive.pm:85 #, perl-format @@ -929,19 +931,19 @@ msgstr "Le nom du fichier CGI n'a pas été indiqué" #. translators: The first parameter is a filename, and the second is #. translators: a (probably not translated) error message. -#: ../IkiWiki/Wrapper.pm:79 +#: ../IkiWiki/Wrapper.pm:97 #, perl-format msgid "failed to write %s: %s" msgstr "Échec de l'écriture de %s : %s" #. translators: The parameter is a C filename. -#: ../IkiWiki/Wrapper.pm:135 +#: ../IkiWiki/Wrapper.pm:154 #, perl-format msgid "failed to compile %s" msgstr "Échec de la compilation de %s" #. translators: The parameter is a filename. -#: ../IkiWiki/Wrapper.pm:155 +#: ../IkiWiki/Wrapper.pm:174 #, perl-format msgid "successfully generated %s" msgstr "%s a été créé avec succès" @@ -954,41 +956,42 @@ msgstr "Syntaxe : ikiwiki [options] source destination" msgid " ikiwiki --setup configfile" msgstr " ikiwiki --setup fichier de configuration" -#: ../ikiwiki.in:90 +#: ../ikiwiki.in:91 msgid "usage: --set var=value" msgstr "Syntaxe : -- set var=valeur" -#: ../ikiwiki.in:138 +#: ../ikiwiki.in:139 msgid "generating wrappers.." msgstr "Création des fichiers CGI..." -#: ../ikiwiki.in:195 +#: ../ikiwiki.in:197 msgid "rebuilding wiki.." msgstr "Reconstruction du wiki..." -#: ../ikiwiki.in:198 +#: ../ikiwiki.in:200 msgid "refreshing wiki.." msgstr "Rafraîchissement du wiki..." -#: ../IkiWiki.pm:466 +#: ../IkiWiki.pm:480 msgid "Must specify url to wiki with --url when using --cgi" -msgstr "Vous devez indiquer l'URL du wiki par --url lors de l'utilisation de --cgi" +msgstr "" +"Vous devez indiquer l'URL du wiki par --url lors de l'utilisation de --cgi" -#: ../IkiWiki.pm:512 +#: ../IkiWiki.pm:526 msgid "cannot use multiple rcs plugins" msgstr "impossible d'utiliser plusieurs systèmes de contrôle des versions" -#: ../IkiWiki.pm:541 +#: ../IkiWiki.pm:555 #, perl-format msgid "failed to load external plugin needed for %s plugin: %s" msgstr "Impossible de charger le greffon externe nécessaire au greffon %s : %s" -#: ../IkiWiki.pm:1165 +#: ../IkiWiki.pm:1187 #, perl-format msgid "preprocessing loop detected on %s at depth %i" msgstr "une boucle de pré traitement a été détectée sur %s à hauteur de %i" -#: ../IkiWiki.pm:1678 +#: ../IkiWiki.pm:1688 msgid "yes" msgstr "oui" diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index feb36c742..11c865363 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-11-11 20:48-0500\n" +"POT-Creation-Date: 2008-12-11 14:46-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -48,7 +48,7 @@ msgstr "" msgid "You are banned." msgstr "" -#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1189 +#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1204 msgid "Error" msgstr "" @@ -111,16 +111,16 @@ msgstr "" msgid "(invalid UTF-8 stripped from feed)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:504 +#: ../IkiWiki/Plugin/aggregate.pm:506 #, perl-format msgid "(feed entities escaped)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:510 +#: ../IkiWiki/Plugin/aggregate.pm:514 msgid "feed crashed XML::Feed!" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:591 +#: ../IkiWiki/Plugin/aggregate.pm:595 #, perl-format msgid "creating new page %s" msgstr "" @@ -129,7 +129,7 @@ msgstr "" msgid "deleting bucket.." msgstr "" -#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:206 +#: ../IkiWiki/Plugin/amazon_s3.pm:38 ../ikiwiki.in:208 msgid "done" msgstr "" @@ -172,7 +172,7 @@ msgid "automatic index generation" msgstr "" #: ../IkiWiki/Plugin/brokenlinks.pm:33 ../IkiWiki/Plugin/editpage.pm:261 -#: ../IkiWiki/Plugin/inline.pm:327 ../IkiWiki/Plugin/opendiscussion.pm:26 +#: ../IkiWiki/Plugin/inline.pm:344 ../IkiWiki/Plugin/opendiscussion.pm:26 #: ../IkiWiki/Plugin/orphans.pm:37 ../IkiWiki/Render.pm:79 #: ../IkiWiki/Render.pm:149 msgid "discussion" @@ -320,15 +320,15 @@ msgstr "" msgid "failed to determine size of image %s" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:93 +#: ../IkiWiki/Plugin/inline.pm:92 msgid "Must specify url to wiki with --url when using --rss or --atom" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:139 +#: ../IkiWiki/Plugin/inline.pm:138 msgid "page editing not allowed" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:156 +#: ../IkiWiki/Plugin/inline.pm:155 msgid "missing pages parameter" msgstr "" @@ -337,20 +337,20 @@ msgstr "" msgid "unknown sort type %s" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:285 +#: ../IkiWiki/Plugin/inline.pm:297 msgid "Add a new post titled:" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:301 +#: ../IkiWiki/Plugin/inline.pm:318 #, perl-format msgid "nonexistant template %s" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:335 ../IkiWiki/Render.pm:83 +#: ../IkiWiki/Plugin/inline.pm:352 ../IkiWiki/Render.pm:83 msgid "Discussion" msgstr "" -#: ../IkiWiki/Plugin/inline.pm:572 +#: ../IkiWiki/Plugin/inline.pm:577 msgid "RPC::XML::Client not found, not pinging" msgstr "" @@ -563,16 +563,16 @@ msgstr "" msgid "need either `percent` or `totalpages` and `donepages` parameters" msgstr "" -#: ../IkiWiki/Plugin/recentchanges.pm:100 +#: ../IkiWiki/Plugin/recentchanges.pm:101 msgid "missing page" msgstr "" -#: ../IkiWiki/Plugin/recentchanges.pm:102 +#: ../IkiWiki/Plugin/recentchanges.pm:103 #, perl-format msgid "The page %s does not exist." msgstr "" -#: ../IkiWiki/Plugin/recentchangesdiff.pm:36 +#: ../IkiWiki/Plugin/recentchangesdiff.pm:37 msgid "(Diff truncated)" msgstr "" @@ -935,41 +935,41 @@ msgstr "" msgid " ikiwiki --setup configfile" msgstr "" -#: ../ikiwiki.in:90 +#: ../ikiwiki.in:91 msgid "usage: --set var=value" msgstr "" -#: ../ikiwiki.in:138 +#: ../ikiwiki.in:139 msgid "generating wrappers.." msgstr "" -#: ../ikiwiki.in:195 +#: ../ikiwiki.in:197 msgid "rebuilding wiki.." msgstr "" -#: ../ikiwiki.in:198 +#: ../ikiwiki.in:200 msgid "refreshing wiki.." msgstr "" -#: ../IkiWiki.pm:473 +#: ../IkiWiki.pm:480 msgid "Must specify url to wiki with --url when using --cgi" msgstr "" -#: ../IkiWiki.pm:519 +#: ../IkiWiki.pm:526 msgid "cannot use multiple rcs plugins" msgstr "" -#: ../IkiWiki.pm:548 +#: ../IkiWiki.pm:555 #, perl-format msgid "failed to load external plugin needed for %s plugin: %s" msgstr "" -#: ../IkiWiki.pm:1172 +#: ../IkiWiki.pm:1187 #, perl-format msgid "preprocessing loop detected on %s at depth %i" msgstr "" -#: ../IkiWiki.pm:1673 +#: ../IkiWiki.pm:1688 msgid "yes" msgstr "" -- cgit v1.2.3 From f77f7a02a6f235e02c4729f6f56e7c43bd8a33fb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Sep 2008 19:33:45 +0100 Subject: Add initial version of a postcomment plugin (temporarily namespaced as smcvpostcomment) --- IkiWiki/Plugin/smcvpostcomment.pm | 299 +++++++++++++++++++++++++++++++++ templates/smcvpostcomment_comment.tmpl | 10 ++ templates/smcvpostcomment_display.tmpl | 24 +++ templates/smcvpostcomment_embed.tmpl | 11 ++ templates/smcvpostcomment_form.tmpl | 20 +++ 5 files changed, 364 insertions(+) create mode 100644 IkiWiki/Plugin/smcvpostcomment.pm create mode 100644 templates/smcvpostcomment_comment.tmpl create mode 100644 templates/smcvpostcomment_display.tmpl create mode 100644 templates/smcvpostcomment_embed.tmpl create mode 100644 templates/smcvpostcomment_form.tmpl (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm new file mode 100644 index 000000000..cb55ff94f --- /dev/null +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -0,0 +1,299 @@ +#!/usr/bin/perl +# Copyright © 2006-2008 Joey Hess +# Copyright © 2008 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation +package IkiWiki::Plugin::smcvpostcomment; + +use warnings; +use strict; +use IkiWiki 2.00; +use IkiWiki::Plugin::mdwn; +use CGI 'escapeHTML'; + +use constant PLUGIN => "smcvpostcomment"; +use constant PREVIEW => "Preview"; +use constant POST_COMMENT => "Post comment"; +use constant CANCEL => "Cancel"; + +sub import { #{{{ + hook(type => "getsetup", id => PLUGIN, call => \&getsetup); + hook(type => "preprocess", id => PLUGIN, call => \&preprocess); + hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); + hook(type => "htmlize", id => "_".PLUGIN, + call => \&IkiWiki::Plugin::mdwn::htmlize); + IkiWiki::loadplugin("inline"); +} # }}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + +# Somewhat based on IkiWiki::Plugin::inline blog posting support +sub preprocess (@) { #{{{ + my %params=@_; + + unless (length $config{cgiurl}) { + error("this plugin makes no sense if you have no CGI"); + } + + my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", + blind_cache => 1); + $formtemplate->param(cgiurl => $config{cgiurl}); + $formtemplate->param(page => $params{page}); + + if ($params{preview}) { + $formtemplate->param("disabled" => + 'not available during Preview'); + } + + debug("page $params{page} => destpage $params{page}"); + + # I'm reasonably sure that this counts as abuse of [[!inline]] + return $formtemplate->output . "\n" . + IkiWiki::preprocess_inline( + pages => "internal(/$params{page}/comment_*)", + template => PLUGIN . "_display", + show => 0, + reverse => "yes", + page => $params{page}, + destpage => $params{destpage}, + preview => $params{preview}); +} # }}} + +# FIXME: logic taken from editpage, should be common code? +sub getcgiuser ($) { # {{{ + my $session = shift; + my $user = $session->param('name'); + $user = $ENV{REMOTE_ADDR} unless defined $user; + debug("getcgiuser() -> $user"); + return $user; +} # }}} + +# FIXME: logic adapted from recentchanges, should be common code? +sub linkuser ($) { # {{{ + my $user = shift; + my $oiduser = eval { IkiWiki::openiduser($user) }; + + if (defined $oiduser) { + return ($user, $oiduser); + } + else { + my $page = bestlink('', (length $config{userdir} + ? "$config{userdir}/" + : "").$user); + return (urlto($page, undef, 1), $user); + } +} # }}} + +# FIXME: taken from IkiWiki::Plugin::editpage, should be common? +sub checksessionexpiry ($$) { # {{{ + my $session = shift; + my $sid = shift; + + if (defined $session->param("name")) { + if (! defined $sid || $sid ne $session->id) { + error(gettext("Your login session has expired.")); + } + } +} # }}} + +# Mostly cargo-culted from IkiWiki::plugin::editpage +sub sessioncgi ($$) { #{{{ + my $cgi=shift; + my $session=shift; + + my $do = $cgi->param('do'); + return unless $do eq PLUGIN; + + # These are theoretically configurable, but currently hard-coded + my $allow_wikilinks = 0; + my $allow_directives = 0; + my $commit_comments = 1; + + IkiWiki::decode_cgi_utf8($cgi); + + eval q{use CGI::FormBuilder}; + error($@) if $@; + + my @buttons = (POST_COMMENT, PREVIEW, CANCEL); + my $form = CGI::FormBuilder->new( + fields => [qw{do sid page subject body}], + charset => 'utf-8', + method => 'POST', + required => [qw{body}], + javascript => 0, + params => $cgi, + action => $config{cgiurl}, + header => 0, + table => 0, + template => scalar IkiWiki::template_params(PLUGIN . '_form.tmpl'), + # wtf does this do in editpage? + wikiname => $config{wikiname}, + ); + + IkiWiki::decode_form_utf8($form); + IkiWiki::run_hooks(formbuilder_setup => sub { + shift->(title => PLUGIN, form => $form, cgi => $cgi, + session => $session, buttons => \@buttons); + }); + IkiWiki::decode_form_utf8($form); + + $form->field(name => 'do', type => 'hidden'); + $form->field(name => 'sid', type => 'hidden', value => $session->id, + force => 1); + $form->field(name => 'page', type => 'hidden'); + $form->field(name => 'subject', type => 'text', size => 80); + $form->field(name => 'body', type => 'textarea', rows => 5, + cols => 80); + + # The untaint is OK (as in editpage) because we're about to pass + # it to file_pruned anyway + my $page = $form->field('page'); + $page = IkiWiki::possibly_foolish_untaint($page); + if (!defined $page || !length $page || + IkiWiki::file_pruned($page, $config{srcdir})) { + error ("bad page name"); + } + + # FIXME: is this right? Or should we be using the candidate subpage + # (whatever that might mean) as the base URL? + my $baseurl = urlto($page, undef, 1); + + $form->title(sprintf(gettext("commenting on %s"), + IkiWiki::pagetitle($page))); + + $form->tmpl_param('helponformattinglink', + htmllink($page, $page, 'ikiwiki/formatting', + noimageinline => 1, + linktext => 'FormattingHelp')); + + if (not exists $pagesources{$page}) { + error ("page '$page' doesn't exist, so you can't comment"); + } + + if ($form->submitted eq CANCEL) { + # bounce back to the page they wanted to comment on, and exit. + # CANCEL need not be considered in future + IkiWiki::redirect($cgi, urlto($page, undef, 1)); + exit; + } + + my ($authorurl, $author) = linkuser(getcgiuser($session)); + + my $body = $form->field('body'); + $body =~ s/\r\n/\n/g; + $body =~ s/\r/\n/g; + $body .= "\n" if $body !~ /\n$/; + + $body =~ s/\[\[([^!])/[[$1/g unless $allow_wikilinks; + $body =~ s/\[\[!/[[!/g unless $allow_directives; + + # In this template, the [[!meta]] directives should stay at the end, + # so that they will override anything the user specifies. (For + # instance, [[!meta author="I can fake the author"]]...) + my $content_tmpl = template(PLUGIN . '_comment.tmpl'); + $content_tmpl->param(author => $author); + $content_tmpl->param(authorurl => $authorurl); + $content_tmpl->param(subject => $form->field('subject')); + $content_tmpl->param(body => $body); + + my $content = $content_tmpl->output; + + # 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 + # - this means that conflicts should never happen + # - this means that if they do, rocks fall and everyone dies + + if ($form->submitted eq PREVIEW) { + my $fake = "$page/_" . PLUGIN . "hypothetical"; + my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, + IkiWiki::filter($fake, $page, + $content), + 0, 1))); + IkiWiki::run_hooks(format => sub { + $preview = shift->(page => $page, + content => $preview); + }); + + my $template = template(PLUGIN . "_display.tmpl"); + $template->param(content => $preview); + $template->param(title => $form->field('subject')); + $template->param(ctime => displaytime(time)); + $template->param(author => $author); + $template->param(authorurl => $authorurl); + + $form->tmpl_param(page_preview => $template->output); + } + else { + $form->tmpl_param(page_preview => ""); + } + + if ($form->submitted eq POST_COMMENT && $form->validate) { + # Let's get posting. We don't check_canedit here because + # that somewhat defeats the point of this plugin. + + checksessionexpiry($session, $cgi->param('sid')); + + # FIXME: check that the wiki is locked right now, because + # if it's not, there are mad race conditions! + + # FIXME: rather a simplistic way to make the comments... + my $i = 0; + my $file; + do { + $i++; + $file = "$page/comment_${i}._" . PLUGIN; + } while (-e "$config{srcdir}/$file"); + + # FIXME: could probably do some sort of graceful retry + # if I could be bothered + writefile($file, $config{srcdir}, $content); + + my $conflict; + + if ($config{rcs} and $commit_comments) { + my $message = "Added a comment"; + if (defined $form->field('subject') && + length $form->field('subject')) { + $message = "Added a comment: " . + $form->field('subject'); + } + + IkiWiki::rcs_add($file); + IkiWiki::disable_commit_hook(); + $conflict = IkiWiki::rcs_commit_staged($message, + $session->param('name'), $ENV{REMOTE_ADDR}); + IkiWiki::enable_commit_hook(); + IkiWiki::rcs_update(); + } + + # Now we need a refresh + require IkiWiki::Render; + IkiWiki::refresh(); + IkiWiki::saveindex(); + + # this should never happen, unless a committer deliberately + # breaks it or something + error($conflict) if defined $conflict; + + # Bounce back to where we were, but defeat broken caches + my $anticache = "?updated=$page/comment_$i"; + IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); + } + else { + IkiWiki::showform ($form, \@buttons, $session, $cgi, + forcebaseurl => $baseurl); + } + + exit; +} #}}} + +1 diff --git a/templates/smcvpostcomment_comment.tmpl b/templates/smcvpostcomment_comment.tmpl new file mode 100644 index 000000000..8c89458f3 --- /dev/null +++ b/templates/smcvpostcomment_comment.tmpl @@ -0,0 +1,10 @@ + + +[[!meta title=""]] + + +[[!meta author=""]] + + +[[!meta authorurl=""]] + diff --git a/templates/smcvpostcomment_display.tmpl b/templates/smcvpostcomment_display.tmpl new file mode 100644 index 000000000..32618d94d --- /dev/null +++ b/templates/smcvpostcomment_display.tmpl @@ -0,0 +1,24 @@ +

+ +
+Posted by + + + + + + + + + + +() +
+ +
+ +
+ +
+ +
diff --git a/templates/smcvpostcomment_embed.tmpl b/templates/smcvpostcomment_embed.tmpl new file mode 100644 index 000000000..2db055d51 --- /dev/null +++ b/templates/smcvpostcomment_embed.tmpl @@ -0,0 +1,11 @@ +
+
+ + +disabled="disabled" /> + + + +
+
diff --git a/templates/smcvpostcomment_form.tmpl b/templates/smcvpostcomment_form.tmpl new file mode 100644 index 000000000..9bce62396 --- /dev/null +++ b/templates/smcvpostcomment_form.tmpl @@ -0,0 +1,20 @@ + + + + + +Subject:
+
+
+ + + + +
+
+Page preview: +
+
+ +
+
-- cgit v1.2.3 From bd8c4674a89945d4748537fbbb15464d9963c299 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 15 Nov 2008 14:11:24 +0000 Subject: smcvpostcomment: use gettext where appropriate --- IkiWiki/Plugin/smcvpostcomment.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index cb55ff94f..1255cfde1 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -38,7 +38,8 @@ sub preprocess (@) { #{{{ my %params=@_; unless (length $config{cgiurl}) { - error("this plugin makes no sense if you have no CGI"); + error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), + PLUGIN)); } my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", @@ -48,15 +49,15 @@ sub preprocess (@) { #{{{ if ($params{preview}) { $formtemplate->param("disabled" => - 'not available during Preview'); + gettext('not available during Preview')); } - debug("page $params{page} => destpage $params{page}"); + debug("page $params{page} => destpage $params{destpage}"); # I'm reasonably sure that this counts as abuse of [[!inline]] return $formtemplate->output . "\n" . IkiWiki::preprocess_inline( - pages => "internal(/$params{page}/comment_*)", + pages => "internal($params{page}/_comment_*)", template => PLUGIN . "_display", show => 0, reverse => "yes", @@ -157,7 +158,7 @@ sub sessioncgi ($$) { #{{{ $page = IkiWiki::possibly_foolish_untaint($page); if (!defined $page || !length $page || IkiWiki::file_pruned($page, $config{srcdir})) { - error ("bad page name"); + error(gettext("bad page name")); } # FIXME: is this right? Or should we be using the candidate subpage @@ -173,7 +174,9 @@ sub sessioncgi ($$) { #{{{ linktext => 'FormattingHelp')); if (not exists $pagesources{$page}) { - error ("page '$page' doesn't exist, so you can't comment"); + error(sprintf(gettext( + "page '%s' doesn't exist, so you can't comment"), + $page)); } if ($form->submitted eq CANCEL) { @@ -260,11 +263,10 @@ sub sessioncgi ($$) { #{{{ my $conflict; if ($config{rcs} and $commit_comments) { - my $message = "Added a comment"; + my $message = gettext("Added a comment"); if (defined $form->field('subject') && length $form->field('subject')) { - $message = "Added a comment: " . - $form->field('subject'); + $message .= ": ".$form->field('subject'); } IkiWiki::rcs_add($file); -- cgit v1.2.3 From 49835784d8908e07fabf4200e35adcd98b73a00c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 15 Nov 2008 14:12:26 +0000 Subject: smcvpostcomment: use better names for special comment files --- IkiWiki/Plugin/smcvpostcomment.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 1255cfde1..3e3c2ca93 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -253,7 +253,7 @@ sub sessioncgi ($$) { #{{{ my $file; do { $i++; - $file = "$page/comment_${i}._" . PLUGIN; + $file = "$page/_comment_${i}._" . PLUGIN; } while (-e "$config{srcdir}/$file"); # FIXME: could probably do some sort of graceful retry @@ -287,7 +287,7 @@ sub sessioncgi ($$) { #{{{ error($conflict) if defined $conflict; # Bounce back to where we were, but defeat broken caches - my $anticache = "?updated=$page/comment_$i"; + my $anticache = "?updated=$page/_comment_$i"; IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); } else { -- cgit v1.2.3 From e65c7b73af6dcb9f8dc0435f17ea3beeab66f175 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 15 Nov 2008 14:12:42 +0000 Subject: smcvpostcomment: load inline plugin more forcibly --- IkiWiki/Plugin/smcvpostcomment.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 3e3c2ca93..9d3f3e858 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -8,6 +8,7 @@ package IkiWiki::Plugin::smcvpostcomment; use warnings; use strict; use IkiWiki 2.00; +use IkiWiki::Plugin::inline; use IkiWiki::Plugin::mdwn; use CGI 'escapeHTML'; -- cgit v1.2.3 From 42b15f763394279ec5a9b4f51031b30470c4dc92 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 15 Nov 2008 14:12:57 +0000 Subject: smcvpostcomment: avoid warnings if form field 'body' is undef --- IkiWiki/Plugin/smcvpostcomment.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 9d3f3e858..367f2d9b3 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -189,7 +189,7 @@ sub sessioncgi ($$) { #{{{ my ($authorurl, $author) = linkuser(getcgiuser($session)); - my $body = $form->field('body'); + my $body = $form->field('body') || ''; $body =~ s/\r\n/\n/g; $body =~ s/\r/\n/g; $body .= "\n" if $body !~ /\n$/; -- cgit v1.2.3 From 29862a8cc8fb9818bbc219955c2b0c5e64a640ce Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 15 Nov 2008 14:13:10 +0000 Subject: smcvpostcomment: explain what $fake is for --- IkiWiki/Plugin/smcvpostcomment.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 367f2d9b3..f224944d5 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -215,6 +215,8 @@ sub sessioncgi ($$) { #{{{ # - this means that if they do, rocks fall and everyone dies if ($form->submitted eq PREVIEW) { + # $fake is a location that has the same number of slashes + # as the eventual location of this comment. my $fake = "$page/_" . PLUGIN . "hypothetical"; my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', IkiWiki::linkify($page, $page, -- cgit v1.2.3 From 798dea20330d06690fcff11cf46aa64605b375d1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 16 Nov 2008 18:11:55 +0000 Subject: smcvpostcomment: reduce length of subject field --- IkiWiki/Plugin/smcvpostcomment.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index f224944d5..59f0e8cfc 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -149,7 +149,7 @@ sub sessioncgi ($$) { #{{{ $form->field(name => 'sid', type => 'hidden', value => $session->id, force => 1); $form->field(name => 'page', type => 'hidden'); - $form->field(name => 'subject', type => 'text', size => 80); + $form->field(name => 'subject', type => 'text', size => 72); $form->field(name => 'body', type => 'textarea', rows => 5, cols => 80); -- cgit v1.2.3 From 660a4ef151bd3da5135c9baa5b782ca373546d16 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 16 Nov 2008 18:23:23 +0000 Subject: smcvpostcomment: always allow wikilinks, and do access control wikilinks are harmless, so we might as well allow them. Access control for this plugin is a bit odd, since we specifically don't want to allow comments to be edited - so the check is whether the user is allowed to edit a deliberately invalid page name, page/commented/on[smcvpostcomment]. You can put smcvpostcomment(*) or smcvpostcomment(some/subdir/*) in $config{anonok_pagespec} or the opposite in $config{locked_pages} to allow "editing" (really just posting) comments. --- IkiWiki/Plugin/smcvpostcomment.pm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 59f0e8cfc..43b1d3e6f 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -113,7 +113,6 @@ sub sessioncgi ($$) { #{{{ return unless $do eq PLUGIN; # These are theoretically configurable, but currently hard-coded - my $allow_wikilinks = 0; my $allow_directives = 0; my $commit_comments = 1; @@ -187,15 +186,24 @@ sub sessioncgi ($$) { #{{{ exit; } + IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); + my ($authorurl, $author) = linkuser(getcgiuser($session)); my $body = $form->field('body') || ''; $body =~ s/\r\n/\n/g; $body =~ s/\r/\n/g; - $body .= "\n" if $body !~ /\n$/; + $body = "\n" if $body !~ /\n$/; + + unless ($allow_directives) { + # don't allow new-style directives at all + $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; - $body =~ s/\[\[([^!])/[[$1/g unless $allow_wikilinks; - $body =~ s/\[\[!/[[!/g unless $allow_directives; + # don't allow [[ unless it begins an old-style + # wikilink, if prefix_directives is off + $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g + unless $config{prefix_directives}; + } # In this template, the [[!meta]] directives should stay at the end, # so that they will override anything the user specifies. (For @@ -301,4 +309,16 @@ sub sessioncgi ($$) { #{{{ exit; } #}}} +package IkiWiki::PageSpec; + +sub match_smcvpostcomment ($$;@) { + my $page = shift; + my $glob = shift; + + unless ($page =~ s/\[smcvpostcomment\]$//) { + return IkiWiki::FailReason->new("not posting a comment"); + } + return match_glob($page, $glob); +} + 1 -- cgit v1.2.3 From 1bd1b03766704bbf2271e87cf4a68978827f31fb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 09:10:06 +0000 Subject: smcvpostcomment: remove HTML if not allowed --- IkiWiki/Plugin/smcvpostcomment.pm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 43b1d3e6f..07f008e5e 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -205,6 +205,12 @@ sub sessioncgi ($$) { #{{{ unless $config{prefix_directives}; } + unless ($allow_html) { + $body =~ s/&(\w|#)/&$1/g; + $body =~ s//>/g; + } + # In this template, the [[!meta]] directives should stay at the end, # so that they will override anything the user specifies. (For # instance, [[!meta author="I can fake the author"]]...) -- cgit v1.2.3 From d18adfb1adedff996dfea9b20a3f1765addbec04 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 09:08:54 +0000 Subject: smcvpostcomment: indicate in form whether HTML and directives are allowed --- IkiWiki/Plugin/smcvpostcomment.pm | 4 +++- templates/smcvpostcomment_form.tmpl | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 07f008e5e..2b9f1e5dc 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -171,7 +171,9 @@ sub sessioncgi ($$) { #{{{ $form->tmpl_param('helponformattinglink', htmllink($page, $page, 'ikiwiki/formatting', noimageinline => 1, - linktext => 'FormattingHelp')); + linktext => 'FormattingHelp'), + allowhtml => $allow_html, + allowdirectives => $allow_directives); if (not exists $pagesources{$page}) { error(sprintf(gettext( diff --git a/templates/smcvpostcomment_form.tmpl b/templates/smcvpostcomment_form.tmpl index 9bce62396..7f138a450 100644 --- a/templates/smcvpostcomment_form.tmpl +++ b/templates/smcvpostcomment_form.tmpl @@ -6,8 +6,10 @@ Subject:


- - +
+HTML is not allowed.
+IkiWiki directives ([[!directive]]) are not allowed.
+
-- cgit v1.2.3 From bb4eb07bdd97ce91a4d28539ebbd1c937241c7a4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 09:09:52 +0000 Subject: smcvpostcomment: make allowhtml etc. configurable, and don't allow commenting on pages where comments have never been allowed --- IkiWiki/Plugin/smcvpostcomment.pm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 2b9f1e5dc..562dc9ed5 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -43,6 +43,14 @@ sub preprocess (@) { #{{{ PLUGIN)); } + my $page = $params{page}; + $pagestate{$page}{PLUGIN()}{comments} = 1; + $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); + $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); + $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} + ? IkiWiki::yesno($params{commit}) + : 1; + my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", blind_cache => 1); $formtemplate->param(cgiurl => $config{cgiurl}); @@ -112,10 +120,6 @@ sub sessioncgi ($$) { #{{{ my $do = $cgi->param('do'); return unless $do eq PLUGIN; - # These are theoretically configurable, but currently hard-coded - my $allow_directives = 0; - my $commit_comments = 1; - IkiWiki::decode_cgi_utf8($cgi); eval q{use CGI::FormBuilder}; @@ -161,6 +165,12 @@ sub sessioncgi ($$) { #{{{ error(gettext("bad page name")); } + my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; + my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; + my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} + ? $pagestate{$page}{PLUGIN()}{commit} + : 1; + # FIXME: is this right? Or should we be using the candidate subpage # (whatever that might mean) as the base URL? my $baseurl = urlto($page, undef, 1); @@ -180,6 +190,11 @@ sub sessioncgi ($$) { #{{{ "page '%s' doesn't exist, so you can't comment"), $page)); } + if (not $pagestate{$page}{PLUGIN()}{comments}) { + error(sprintf(gettext( + "comments are not enabled on page '%s'"), + $page)); + } if ($form->submitted eq CANCEL) { # bounce back to the page they wanted to comment on, and exit. -- cgit v1.2.3 From 442e4e7e120be14980a0431e98784dc0ad52eee6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 09:10:50 +0000 Subject: smcvpostcomment: allow inlining to be disabled, and pass through atom etc. better --- IkiWiki/Plugin/smcvpostcomment.pm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 562dc9ed5..6bd3b2970 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -63,16 +63,28 @@ sub preprocess (@) { #{{{ debug("page $params{page} => destpage $params{destpage}"); - # I'm reasonably sure that this counts as abuse of [[!inline]] - return $formtemplate->output . "\n" . - IkiWiki::preprocess_inline( + my $posts = ''; + unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { + my @args = ( pages => "internal($params{page}/_comment_*)", template => PLUGIN . "_display", show => 0, reverse => "yes", + # special stuff passed through page => $params{page}, destpage => $params{destpage}, - preview => $params{preview}); + preview => $params{preview}, + ); + push @args, atom => $params{atom} if defined $params{atom}; + push @args, rss => $params{rss} if defined $params{rss}; + push @args, feeds => $params{feeds} if defined $params{feeds}; + push @args, feedshow => $params{feedshow} if defined $params{feedshow}; + push @args, timeformat => $params{timeformat} if defined $params{timeformat}; + push @args, feedonly => $params{feedonly} if defined $params{feedonly}; + $posts = "\n" . IkiWiki::preprocess_inline(@args); + } + + return $formtemplate->output . $posts; } # }}} # FIXME: logic taken from editpage, should be common code? -- cgit v1.2.3 From f49603bf8638ab539151114445e0b132fb518941 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 10:41:50 +0000 Subject: smcvpostcomment: import other plugins lazily and remove unnecessary use of CGI --- IkiWiki/Plugin/smcvpostcomment.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 6bd3b2970..40ffe8164 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -8,9 +8,6 @@ package IkiWiki::Plugin::smcvpostcomment; use warnings; use strict; use IkiWiki 2.00; -use IkiWiki::Plugin::inline; -use IkiWiki::Plugin::mdwn; -use CGI 'escapeHTML'; use constant PLUGIN => "smcvpostcomment"; use constant PREVIEW => "Preview"; @@ -24,6 +21,13 @@ sub import { #{{{ hook(type => "htmlize", id => "_".PLUGIN, call => \&IkiWiki::Plugin::mdwn::htmlize); IkiWiki::loadplugin("inline"); + IkiWiki::loadplugin("mdwn"); +} # }}} + +sub htmlize { # {{{ + eval { use IkiWiki::Plugin::mdwn; }; + error($@) if ($@); + return IkiWiki::Plugin::mdwn::htmlize(@_) } # }}} sub getsetup () { #{{{ @@ -65,6 +69,8 @@ sub preprocess (@) { #{{{ my $posts = ''; unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { + eval { use IkiWiki::Plugin::inline; }; + error($@) if ($@); my @args = ( pages => "internal($params{page}/_comment_*)", template => PLUGIN . "_display", -- cgit v1.2.3 From b7db3444a5d8e31bb1df60c3617f1038d93e099e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 10:42:01 +0000 Subject: smcvpostcomment: allow commenting to be closed --- IkiWiki/Plugin/smcvpostcomment.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm index 40ffe8164..22958c84a 100644 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ b/IkiWiki/Plugin/smcvpostcomment.pm @@ -48,7 +48,9 @@ sub preprocess (@) { #{{{ } my $page = $params{page}; - $pagestate{$page}{PLUGIN()}{comments} = 1; + $pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} + ? (not IkiWiki::yesno($params{closed})) + : 1; $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} @@ -60,7 +62,11 @@ sub preprocess (@) { #{{{ $formtemplate->param(cgiurl => $config{cgiurl}); $formtemplate->param(page => $params{page}); - if ($params{preview}) { + if (not $pagestate{$page}{PLUGIN()}{comments}) { + $formtemplate->param("disabled" => + gettext('comments are closed')); + } + elsif ($params{preview}) { $formtemplate->param("disabled" => gettext('not available during Preview')); } -- cgit v1.2.3 From 3c9ccb406b2260c149be387508a097fe6fdb3c93 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 17 Nov 2008 11:16:31 +0000 Subject: Rename smcvpostcomment plugin to postcomment to propose for inclusion --- IkiWiki/Plugin/postcomment.pm | 371 +++++++++++++++++++++++++++++++++ IkiWiki/Plugin/smcvpostcomment.pm | 371 --------------------------------- doc/style.css | 8 +- templates/postcomment_comment.tmpl | 10 + templates/postcomment_display.tmpl | 24 +++ templates/postcomment_embed.tmpl | 7 + templates/postcomment_form.tmpl | 25 +++ templates/smcvpostcomment_comment.tmpl | 10 - templates/smcvpostcomment_display.tmpl | 24 --- templates/smcvpostcomment_embed.tmpl | 7 - templates/smcvpostcomment_form.tmpl | 25 --- 11 files changed, 441 insertions(+), 441 deletions(-) create mode 100644 IkiWiki/Plugin/postcomment.pm delete mode 100644 IkiWiki/Plugin/smcvpostcomment.pm create mode 100644 templates/postcomment_comment.tmpl create mode 100644 templates/postcomment_display.tmpl create mode 100644 templates/postcomment_embed.tmpl create mode 100644 templates/postcomment_form.tmpl delete mode 100644 templates/smcvpostcomment_comment.tmpl delete mode 100644 templates/smcvpostcomment_display.tmpl delete mode 100644 templates/smcvpostcomment_embed.tmpl delete mode 100644 templates/smcvpostcomment_form.tmpl (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/postcomment.pm b/IkiWiki/Plugin/postcomment.pm new file mode 100644 index 000000000..480ca58a5 --- /dev/null +++ b/IkiWiki/Plugin/postcomment.pm @@ -0,0 +1,371 @@ +#!/usr/bin/perl +# Copyright © 2006-2008 Joey Hess +# Copyright © 2008 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation +package IkiWiki::Plugin::postcomment; + +use warnings; +use strict; +use IkiWiki 2.00; + +use constant PLUGIN => "postcomment"; +use constant PREVIEW => "Preview"; +use constant POST_COMMENT => "Post comment"; +use constant CANCEL => "Cancel"; + +sub import { #{{{ + hook(type => "getsetup", id => PLUGIN, call => \&getsetup); + hook(type => "preprocess", id => PLUGIN, call => \&preprocess); + hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); + hook(type => "htmlize", id => "_".PLUGIN, + call => \&IkiWiki::Plugin::mdwn::htmlize); + IkiWiki::loadplugin("inline"); + IkiWiki::loadplugin("mdwn"); +} # }}} + +sub htmlize { # {{{ + eval { use IkiWiki::Plugin::mdwn; }; + error($@) if ($@); + return IkiWiki::Plugin::mdwn::htmlize(@_) +} # }}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + +# Somewhat based on IkiWiki::Plugin::inline blog posting support +sub preprocess (@) { #{{{ + my %params=@_; + + unless (length $config{cgiurl}) { + error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), + PLUGIN)); + } + + my $page = $params{page}; + $pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} + ? (not IkiWiki::yesno($params{closed})) + : 1; + $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); + $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); + $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} + ? IkiWiki::yesno($params{commit}) + : 1; + + my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", + blind_cache => 1); + $formtemplate->param(cgiurl => $config{cgiurl}); + $formtemplate->param(page => $params{page}); + + if (not $pagestate{$page}{PLUGIN()}{comments}) { + $formtemplate->param("disabled" => + gettext('comments are closed')); + } + elsif ($params{preview}) { + $formtemplate->param("disabled" => + gettext('not available during Preview')); + } + + debug("page $params{page} => destpage $params{destpage}"); + + my $posts = ''; + unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { + eval { use IkiWiki::Plugin::inline; }; + error($@) if ($@); + my @args = ( + pages => "internal($params{page}/_comment_*)", + template => PLUGIN . "_display", + show => 0, + reverse => "yes", + # special stuff passed through + page => $params{page}, + destpage => $params{destpage}, + preview => $params{preview}, + ); + push @args, atom => $params{atom} if defined $params{atom}; + push @args, rss => $params{rss} if defined $params{rss}; + push @args, feeds => $params{feeds} if defined $params{feeds}; + push @args, feedshow => $params{feedshow} if defined $params{feedshow}; + push @args, timeformat => $params{timeformat} if defined $params{timeformat}; + push @args, feedonly => $params{feedonly} if defined $params{feedonly}; + $posts = "\n" . IkiWiki::preprocess_inline(@args); + } + + return $formtemplate->output . $posts; +} # }}} + +# FIXME: logic taken from editpage, should be common code? +sub getcgiuser ($) { # {{{ + my $session = shift; + my $user = $session->param('name'); + $user = $ENV{REMOTE_ADDR} unless defined $user; + debug("getcgiuser() -> $user"); + return $user; +} # }}} + +# FIXME: logic adapted from recentchanges, should be common code? +sub linkuser ($) { # {{{ + my $user = shift; + my $oiduser = eval { IkiWiki::openiduser($user) }; + + if (defined $oiduser) { + return ($user, $oiduser); + } + else { + my $page = bestlink('', (length $config{userdir} + ? "$config{userdir}/" + : "").$user); + return (urlto($page, undef, 1), $user); + } +} # }}} + +# FIXME: taken from IkiWiki::Plugin::editpage, should be common? +sub checksessionexpiry ($$) { # {{{ + my $session = shift; + my $sid = shift; + + if (defined $session->param("name")) { + if (! defined $sid || $sid ne $session->id) { + error(gettext("Your login session has expired.")); + } + } +} # }}} + +# Mostly cargo-culted from IkiWiki::plugin::editpage +sub sessioncgi ($$) { #{{{ + my $cgi=shift; + my $session=shift; + + my $do = $cgi->param('do'); + return unless $do eq PLUGIN; + + IkiWiki::decode_cgi_utf8($cgi); + + eval q{use CGI::FormBuilder}; + error($@) if $@; + + my @buttons = (POST_COMMENT, PREVIEW, CANCEL); + my $form = CGI::FormBuilder->new( + fields => [qw{do sid page subject body}], + charset => 'utf-8', + method => 'POST', + required => [qw{body}], + javascript => 0, + params => $cgi, + action => $config{cgiurl}, + header => 0, + table => 0, + template => scalar IkiWiki::template_params(PLUGIN . '_form.tmpl'), + # wtf does this do in editpage? + wikiname => $config{wikiname}, + ); + + IkiWiki::decode_form_utf8($form); + IkiWiki::run_hooks(formbuilder_setup => sub { + shift->(title => PLUGIN, form => $form, cgi => $cgi, + session => $session, buttons => \@buttons); + }); + IkiWiki::decode_form_utf8($form); + + $form->field(name => 'do', type => 'hidden'); + $form->field(name => 'sid', type => 'hidden', value => $session->id, + force => 1); + $form->field(name => 'page', type => 'hidden'); + $form->field(name => 'subject', type => 'text', size => 72); + $form->field(name => 'body', type => 'textarea', rows => 5, + cols => 80); + + # The untaint is OK (as in editpage) because we're about to pass + # it to file_pruned anyway + my $page = $form->field('page'); + $page = IkiWiki::possibly_foolish_untaint($page); + if (!defined $page || !length $page || + IkiWiki::file_pruned($page, $config{srcdir})) { + error(gettext("bad page name")); + } + + my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; + my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; + my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} + ? $pagestate{$page}{PLUGIN()}{commit} + : 1; + + # FIXME: is this right? Or should we be using the candidate subpage + # (whatever that might mean) as the base URL? + my $baseurl = urlto($page, undef, 1); + + $form->title(sprintf(gettext("commenting on %s"), + IkiWiki::pagetitle($page))); + + $form->tmpl_param('helponformattinglink', + htmllink($page, $page, 'ikiwiki/formatting', + noimageinline => 1, + linktext => 'FormattingHelp'), + allowhtml => $allow_html, + allowdirectives => $allow_directives); + + if (not exists $pagesources{$page}) { + error(sprintf(gettext( + "page '%s' doesn't exist, so you can't comment"), + $page)); + } + if (not $pagestate{$page}{PLUGIN()}{comments}) { + error(sprintf(gettext( + "comments are not enabled on page '%s'"), + $page)); + } + + if ($form->submitted eq CANCEL) { + # bounce back to the page they wanted to comment on, and exit. + # CANCEL need not be considered in future + IkiWiki::redirect($cgi, urlto($page, undef, 1)); + exit; + } + + IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); + + my ($authorurl, $author) = linkuser(getcgiuser($session)); + + my $body = $form->field('body') || ''; + $body =~ s/\r\n/\n/g; + $body =~ s/\r/\n/g; + $body = "\n" if $body !~ /\n$/; + + unless ($allow_directives) { + # don't allow new-style directives at all + $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; + + # don't allow [[ unless it begins an old-style + # wikilink, if prefix_directives is off + $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g + unless $config{prefix_directives}; + } + + unless ($allow_html) { + $body =~ s/&(\w|#)/&$1/g; + $body =~ s//>/g; + } + + # In this template, the [[!meta]] directives should stay at the end, + # so that they will override anything the user specifies. (For + # instance, [[!meta author="I can fake the author"]]...) + my $content_tmpl = template(PLUGIN . '_comment.tmpl'); + $content_tmpl->param(author => $author); + $content_tmpl->param(authorurl => $authorurl); + $content_tmpl->param(subject => $form->field('subject')); + $content_tmpl->param(body => $body); + + my $content = $content_tmpl->output; + + # 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 + # - this means that conflicts should never happen + # - this means that if they do, rocks fall and everyone dies + + if ($form->submitted eq PREVIEW) { + # $fake is a location that has the same number of slashes + # as the eventual location of this comment. + my $fake = "$page/_" . PLUGIN . "hypothetical"; + my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, + IkiWiki::filter($fake, $page, + $content), + 0, 1))); + IkiWiki::run_hooks(format => sub { + $preview = shift->(page => $page, + content => $preview); + }); + + my $template = template(PLUGIN . "_display.tmpl"); + $template->param(content => $preview); + $template->param(title => $form->field('subject')); + $template->param(ctime => displaytime(time)); + $template->param(author => $author); + $template->param(authorurl => $authorurl); + + $form->tmpl_param(page_preview => $template->output); + } + else { + $form->tmpl_param(page_preview => ""); + } + + if ($form->submitted eq POST_COMMENT && $form->validate) { + # Let's get posting. We don't check_canedit here because + # that somewhat defeats the point of this plugin. + + checksessionexpiry($session, $cgi->param('sid')); + + # FIXME: check that the wiki is locked right now, because + # if it's not, there are mad race conditions! + + # FIXME: rather a simplistic way to make the comments... + my $i = 0; + my $file; + do { + $i++; + $file = "$page/_comment_${i}._" . PLUGIN; + } while (-e "$config{srcdir}/$file"); + + # FIXME: could probably do some sort of graceful retry + # if I could be bothered + writefile($file, $config{srcdir}, $content); + + my $conflict; + + if ($config{rcs} and $commit_comments) { + my $message = gettext("Added a comment"); + if (defined $form->field('subject') && + length $form->field('subject')) { + $message .= ": ".$form->field('subject'); + } + + IkiWiki::rcs_add($file); + IkiWiki::disable_commit_hook(); + $conflict = IkiWiki::rcs_commit_staged($message, + $session->param('name'), $ENV{REMOTE_ADDR}); + IkiWiki::enable_commit_hook(); + IkiWiki::rcs_update(); + } + + # Now we need a refresh + require IkiWiki::Render; + IkiWiki::refresh(); + IkiWiki::saveindex(); + + # this should never happen, unless a committer deliberately + # breaks it or something + error($conflict) if defined $conflict; + + # Bounce back to where we were, but defeat broken caches + my $anticache = "?updated=$page/_comment_$i"; + IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); + } + else { + IkiWiki::showform ($form, \@buttons, $session, $cgi, + forcebaseurl => $baseurl); + } + + exit; +} #}}} + +package IkiWiki::PageSpec; + +sub match_postcomment ($$;@) { + my $page = shift; + my $glob = shift; + + unless ($page =~ s/\[postcomment\]$//) { + return IkiWiki::FailReason->new("not posting a comment"); + } + return match_glob($page, $glob); +} + +1 diff --git a/IkiWiki/Plugin/smcvpostcomment.pm b/IkiWiki/Plugin/smcvpostcomment.pm deleted file mode 100644 index 22958c84a..000000000 --- a/IkiWiki/Plugin/smcvpostcomment.pm +++ /dev/null @@ -1,371 +0,0 @@ -#!/usr/bin/perl -# Copyright © 2006-2008 Joey Hess -# Copyright © 2008 Simon McVittie -# Licensed under the GNU GPL, version 2, or any later version published by the -# Free Software Foundation -package IkiWiki::Plugin::smcvpostcomment; - -use warnings; -use strict; -use IkiWiki 2.00; - -use constant PLUGIN => "smcvpostcomment"; -use constant PREVIEW => "Preview"; -use constant POST_COMMENT => "Post comment"; -use constant CANCEL => "Cancel"; - -sub import { #{{{ - hook(type => "getsetup", id => PLUGIN, call => \&getsetup); - hook(type => "preprocess", id => PLUGIN, call => \&preprocess); - hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); - hook(type => "htmlize", id => "_".PLUGIN, - call => \&IkiWiki::Plugin::mdwn::htmlize); - IkiWiki::loadplugin("inline"); - IkiWiki::loadplugin("mdwn"); -} # }}} - -sub htmlize { # {{{ - eval { use IkiWiki::Plugin::mdwn; }; - error($@) if ($@); - return IkiWiki::Plugin::mdwn::htmlize(@_) -} # }}} - -sub getsetup () { #{{{ - return - plugin => { - safe => 1, - rebuild => undef, - }, -} #}}} - -# Somewhat based on IkiWiki::Plugin::inline blog posting support -sub preprocess (@) { #{{{ - my %params=@_; - - unless (length $config{cgiurl}) { - error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), - PLUGIN)); - } - - my $page = $params{page}; - $pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} - ? (not IkiWiki::yesno($params{closed})) - : 1; - $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); - $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); - $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} - ? IkiWiki::yesno($params{commit}) - : 1; - - my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", - blind_cache => 1); - $formtemplate->param(cgiurl => $config{cgiurl}); - $formtemplate->param(page => $params{page}); - - if (not $pagestate{$page}{PLUGIN()}{comments}) { - $formtemplate->param("disabled" => - gettext('comments are closed')); - } - elsif ($params{preview}) { - $formtemplate->param("disabled" => - gettext('not available during Preview')); - } - - debug("page $params{page} => destpage $params{destpage}"); - - my $posts = ''; - unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { - eval { use IkiWiki::Plugin::inline; }; - error($@) if ($@); - my @args = ( - pages => "internal($params{page}/_comment_*)", - template => PLUGIN . "_display", - show => 0, - reverse => "yes", - # special stuff passed through - page => $params{page}, - destpage => $params{destpage}, - preview => $params{preview}, - ); - push @args, atom => $params{atom} if defined $params{atom}; - push @args, rss => $params{rss} if defined $params{rss}; - push @args, feeds => $params{feeds} if defined $params{feeds}; - push @args, feedshow => $params{feedshow} if defined $params{feedshow}; - push @args, timeformat => $params{timeformat} if defined $params{timeformat}; - push @args, feedonly => $params{feedonly} if defined $params{feedonly}; - $posts = "\n" . IkiWiki::preprocess_inline(@args); - } - - return $formtemplate->output . $posts; -} # }}} - -# FIXME: logic taken from editpage, should be common code? -sub getcgiuser ($) { # {{{ - my $session = shift; - my $user = $session->param('name'); - $user = $ENV{REMOTE_ADDR} unless defined $user; - debug("getcgiuser() -> $user"); - return $user; -} # }}} - -# FIXME: logic adapted from recentchanges, should be common code? -sub linkuser ($) { # {{{ - my $user = shift; - my $oiduser = eval { IkiWiki::openiduser($user) }; - - if (defined $oiduser) { - return ($user, $oiduser); - } - else { - my $page = bestlink('', (length $config{userdir} - ? "$config{userdir}/" - : "").$user); - return (urlto($page, undef, 1), $user); - } -} # }}} - -# FIXME: taken from IkiWiki::Plugin::editpage, should be common? -sub checksessionexpiry ($$) { # {{{ - my $session = shift; - my $sid = shift; - - if (defined $session->param("name")) { - if (! defined $sid || $sid ne $session->id) { - error(gettext("Your login session has expired.")); - } - } -} # }}} - -# Mostly cargo-culted from IkiWiki::plugin::editpage -sub sessioncgi ($$) { #{{{ - my $cgi=shift; - my $session=shift; - - my $do = $cgi->param('do'); - return unless $do eq PLUGIN; - - IkiWiki::decode_cgi_utf8($cgi); - - eval q{use CGI::FormBuilder}; - error($@) if $@; - - my @buttons = (POST_COMMENT, PREVIEW, CANCEL); - my $form = CGI::FormBuilder->new( - fields => [qw{do sid page subject body}], - charset => 'utf-8', - method => 'POST', - required => [qw{body}], - javascript => 0, - params => $cgi, - action => $config{cgiurl}, - header => 0, - table => 0, - template => scalar IkiWiki::template_params(PLUGIN . '_form.tmpl'), - # wtf does this do in editpage? - wikiname => $config{wikiname}, - ); - - IkiWiki::decode_form_utf8($form); - IkiWiki::run_hooks(formbuilder_setup => sub { - shift->(title => PLUGIN, form => $form, cgi => $cgi, - session => $session, buttons => \@buttons); - }); - IkiWiki::decode_form_utf8($form); - - $form->field(name => 'do', type => 'hidden'); - $form->field(name => 'sid', type => 'hidden', value => $session->id, - force => 1); - $form->field(name => 'page', type => 'hidden'); - $form->field(name => 'subject', type => 'text', size => 72); - $form->field(name => 'body', type => 'textarea', rows => 5, - cols => 80); - - # The untaint is OK (as in editpage) because we're about to pass - # it to file_pruned anyway - my $page = $form->field('page'); - $page = IkiWiki::possibly_foolish_untaint($page); - if (!defined $page || !length $page || - IkiWiki::file_pruned($page, $config{srcdir})) { - error(gettext("bad page name")); - } - - my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} - ? $pagestate{$page}{PLUGIN()}{commit} - : 1; - - # FIXME: is this right? Or should we be using the candidate subpage - # (whatever that might mean) as the base URL? - my $baseurl = urlto($page, undef, 1); - - $form->title(sprintf(gettext("commenting on %s"), - IkiWiki::pagetitle($page))); - - $form->tmpl_param('helponformattinglink', - htmllink($page, $page, 'ikiwiki/formatting', - noimageinline => 1, - linktext => 'FormattingHelp'), - allowhtml => $allow_html, - allowdirectives => $allow_directives); - - if (not exists $pagesources{$page}) { - error(sprintf(gettext( - "page '%s' doesn't exist, so you can't comment"), - $page)); - } - if (not $pagestate{$page}{PLUGIN()}{comments}) { - error(sprintf(gettext( - "comments are not enabled on page '%s'"), - $page)); - } - - if ($form->submitted eq CANCEL) { - # bounce back to the page they wanted to comment on, and exit. - # CANCEL need not be considered in future - IkiWiki::redirect($cgi, urlto($page, undef, 1)); - exit; - } - - IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); - - my ($authorurl, $author) = linkuser(getcgiuser($session)); - - my $body = $form->field('body') || ''; - $body =~ s/\r\n/\n/g; - $body =~ s/\r/\n/g; - $body = "\n" if $body !~ /\n$/; - - unless ($allow_directives) { - # don't allow new-style directives at all - $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; - - # don't allow [[ unless it begins an old-style - # wikilink, if prefix_directives is off - $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g - unless $config{prefix_directives}; - } - - unless ($allow_html) { - $body =~ s/&(\w|#)/&$1/g; - $body =~ s//>/g; - } - - # In this template, the [[!meta]] directives should stay at the end, - # so that they will override anything the user specifies. (For - # instance, [[!meta author="I can fake the author"]]...) - my $content_tmpl = template(PLUGIN . '_comment.tmpl'); - $content_tmpl->param(author => $author); - $content_tmpl->param(authorurl => $authorurl); - $content_tmpl->param(subject => $form->field('subject')); - $content_tmpl->param(body => $body); - - my $content = $content_tmpl->output; - - # 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 - # - this means that conflicts should never happen - # - this means that if they do, rocks fall and everyone dies - - if ($form->submitted eq PREVIEW) { - # $fake is a location that has the same number of slashes - # as the eventual location of this comment. - my $fake = "$page/_" . PLUGIN . "hypothetical"; - my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', - IkiWiki::linkify($page, $page, - IkiWiki::preprocess($page, $page, - IkiWiki::filter($fake, $page, - $content), - 0, 1))); - IkiWiki::run_hooks(format => sub { - $preview = shift->(page => $page, - content => $preview); - }); - - my $template = template(PLUGIN . "_display.tmpl"); - $template->param(content => $preview); - $template->param(title => $form->field('subject')); - $template->param(ctime => displaytime(time)); - $template->param(author => $author); - $template->param(authorurl => $authorurl); - - $form->tmpl_param(page_preview => $template->output); - } - else { - $form->tmpl_param(page_preview => ""); - } - - if ($form->submitted eq POST_COMMENT && $form->validate) { - # Let's get posting. We don't check_canedit here because - # that somewhat defeats the point of this plugin. - - checksessionexpiry($session, $cgi->param('sid')); - - # FIXME: check that the wiki is locked right now, because - # if it's not, there are mad race conditions! - - # FIXME: rather a simplistic way to make the comments... - my $i = 0; - my $file; - do { - $i++; - $file = "$page/_comment_${i}._" . PLUGIN; - } while (-e "$config{srcdir}/$file"); - - # FIXME: could probably do some sort of graceful retry - # if I could be bothered - writefile($file, $config{srcdir}, $content); - - my $conflict; - - if ($config{rcs} and $commit_comments) { - my $message = gettext("Added a comment"); - if (defined $form->field('subject') && - length $form->field('subject')) { - $message .= ": ".$form->field('subject'); - } - - IkiWiki::rcs_add($file); - IkiWiki::disable_commit_hook(); - $conflict = IkiWiki::rcs_commit_staged($message, - $session->param('name'), $ENV{REMOTE_ADDR}); - IkiWiki::enable_commit_hook(); - IkiWiki::rcs_update(); - } - - # Now we need a refresh - require IkiWiki::Render; - IkiWiki::refresh(); - IkiWiki::saveindex(); - - # this should never happen, unless a committer deliberately - # breaks it or something - error($conflict) if defined $conflict; - - # Bounce back to where we were, but defeat broken caches - my $anticache = "?updated=$page/_comment_$i"; - IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); - } - else { - IkiWiki::showform ($form, \@buttons, $session, $cgi, - forcebaseurl => $baseurl); - } - - exit; -} #}}} - -package IkiWiki::PageSpec; - -sub match_smcvpostcomment ($$;@) { - my $page = shift; - my $glob = shift; - - unless ($page =~ s/\[smcvpostcomment\]$//) { - return IkiWiki::FailReason->new("not posting a comment"); - } - return match_glob($page, $glob); -} - -1 diff --git a/doc/style.css b/doc/style.css index 896ac2b01..21ea9492c 100644 --- a/doc/style.css +++ b/doc/style.css @@ -373,7 +373,7 @@ span.color { padding: 2px; } -.smcvpostcomment-display .author { font-weight: bold; } -.smcvpostcomment-display { border: 1px inset #999; margin: 3px; padding: 3px; } -.smcvpostcomment-header { font-style: italic; } -.smcvpostcomment-subject { font-weight: bold; border-bottom: 1px solid #999; } +.postcomment-display .author { font-weight: bold; } +.postcomment-display { border: 1px inset #999; margin: 3px; padding: 3px; } +.postcomment-header { font-style: italic; } +.postcomment-subject { font-weight: bold; border-bottom: 1px solid #999; } diff --git a/templates/postcomment_comment.tmpl b/templates/postcomment_comment.tmpl new file mode 100644 index 000000000..8c89458f3 --- /dev/null +++ b/templates/postcomment_comment.tmpl @@ -0,0 +1,10 @@ + + +[[!meta title=""]] + + +[[!meta author=""]] + + +[[!meta authorurl=""]] + diff --git a/templates/postcomment_display.tmpl b/templates/postcomment_display.tmpl new file mode 100644 index 000000000..d3eabb3a1 --- /dev/null +++ b/templates/postcomment_display.tmpl @@ -0,0 +1,24 @@ +
+ +
+Posted by + + + + + + + + + + +() +
+ +
+ +
+ +
+ +
diff --git a/templates/postcomment_embed.tmpl b/templates/postcomment_embed.tmpl new file mode 100644 index 000000000..eae741214 --- /dev/null +++ b/templates/postcomment_embed.tmpl @@ -0,0 +1,7 @@ +
+ +[Posting comments disabled: ] + +Post a comment + +
diff --git a/templates/postcomment_form.tmpl b/templates/postcomment_form.tmpl new file mode 100644 index 000000000..293f0f17e --- /dev/null +++ b/templates/postcomment_form.tmpl @@ -0,0 +1,25 @@ +
+ + + + + +Subject:
+
+
+
+HTML is not allowed.
+IkiWiki directives ([[!directive]]) are not allowed.
+ + + +
+
+Comment preview: +
+
+ +
+
+ +
diff --git a/templates/smcvpostcomment_comment.tmpl b/templates/smcvpostcomment_comment.tmpl deleted file mode 100644 index 8c89458f3..000000000 --- a/templates/smcvpostcomment_comment.tmpl +++ /dev/null @@ -1,10 +0,0 @@ - - -[[!meta title=""]] - - -[[!meta author=""]] - - -[[!meta authorurl=""]] - diff --git a/templates/smcvpostcomment_display.tmpl b/templates/smcvpostcomment_display.tmpl deleted file mode 100644 index 1b67f9094..000000000 --- a/templates/smcvpostcomment_display.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -
- -
-Posted by - - - - - - - - - - -() -
- -
- -
- -
- -
diff --git a/templates/smcvpostcomment_embed.tmpl b/templates/smcvpostcomment_embed.tmpl deleted file mode 100644 index db35e4da7..000000000 --- a/templates/smcvpostcomment_embed.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -
- -[Posting comments disabled: ] - -Post a comment - -
diff --git a/templates/smcvpostcomment_form.tmpl b/templates/smcvpostcomment_form.tmpl deleted file mode 100644 index 43fc9b65a..000000000 --- a/templates/smcvpostcomment_form.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -
- - - - - -Subject:
-
-
-
-HTML is not allowed.
-IkiWiki directives ([[!directive]]) are not allowed.
- - - -
-
-Comment preview: -
-
- -
-
- -
-- cgit v1.2.3 From 3d4aa065d6a689a017c98e7ea8b80da0b65ae361 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:17:18 +0000 Subject: postcomment: Rename plugin to comments, use *._comment files The PageSpec is still called "postcomment" since that's what it means. --- IkiWiki/Plugin/comments.pm | 369 ++++++++++++++++++++++++++++++++++++ IkiWiki/Plugin/postcomment.pm | 371 ------------------------------------- doc/style.css | 8 +- templates/comments_comment.tmpl | 10 + templates/comments_display.tmpl | 24 +++ templates/comments_embed.tmpl | 7 + templates/comments_form.tmpl | 25 +++ templates/postcomment_comment.tmpl | 10 - templates/postcomment_display.tmpl | 24 --- templates/postcomment_embed.tmpl | 7 - templates/postcomment_form.tmpl | 25 --- 11 files changed, 439 insertions(+), 441 deletions(-) create mode 100644 IkiWiki/Plugin/comments.pm delete mode 100644 IkiWiki/Plugin/postcomment.pm create mode 100644 templates/comments_comment.tmpl create mode 100644 templates/comments_display.tmpl create mode 100644 templates/comments_embed.tmpl create mode 100644 templates/comments_form.tmpl delete mode 100644 templates/postcomment_comment.tmpl delete mode 100644 templates/postcomment_display.tmpl delete mode 100644 templates/postcomment_embed.tmpl delete mode 100644 templates/postcomment_form.tmpl (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm new file mode 100644 index 000000000..b57735545 --- /dev/null +++ b/IkiWiki/Plugin/comments.pm @@ -0,0 +1,369 @@ +#!/usr/bin/perl +# Copyright © 2006-2008 Joey Hess +# Copyright © 2008 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation +package IkiWiki::Plugin::comments; + +use warnings; +use strict; +use IkiWiki 2.00; + +use constant PREVIEW => "Preview"; +use constant POST_COMMENT => "Post comment"; +use constant CANCEL => "Cancel"; + +sub import { #{{{ + hook(type => "getsetup", id => 'comments', call => \&getsetup); + hook(type => "preprocess", id => 'comments', call => \&preprocess); + hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); + hook(type => "htmlize", id => "_comment", + call => \&IkiWiki::Plugin::mdwn::htmlize); + IkiWiki::loadplugin("inline"); + IkiWiki::loadplugin("mdwn"); +} # }}} + +sub htmlize { # {{{ + eval { use IkiWiki::Plugin::mdwn; }; + error($@) if ($@); + return IkiWiki::Plugin::mdwn::htmlize(@_) +} # }}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + +# Somewhat based on IkiWiki::Plugin::inline blog posting support +sub preprocess (@) { #{{{ + my %params=@_; + + unless (length $config{cgiurl}) { + error(gettext("[[!comments plugin requires CGI enabled]]")); + } + + my $page = $params{page}; + $pagestate{$page}{comments}{comments} = defined $params{closed} + ? (not IkiWiki::yesno($params{closed})) + : 1; + $pagestate{$page}{comments}{allowhtml} = IkiWiki::yesno($params{allowhtml}); + $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); + $pagestate{$page}{comments}{commit} = defined $params{commit} + ? IkiWiki::yesno($params{commit}) + : 1; + + my $formtemplate = IkiWiki::template("comments_embed.tmpl", + blind_cache => 1); + $formtemplate->param(cgiurl => $config{cgiurl}); + $formtemplate->param(page => $params{page}); + + if (not $pagestate{$page}{comments}{comments}) { + $formtemplate->param("disabled" => + gettext('comments are closed')); + } + elsif ($params{preview}) { + $formtemplate->param("disabled" => + gettext('not available during Preview')); + } + + debug("page $params{page} => destpage $params{destpage}"); + + my $posts = ''; + unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { + eval { use IkiWiki::Plugin::inline; }; + error($@) if ($@); + my @args = ( + pages => "internal($params{page}/_comment_*)", + template => "comments_display", + show => 0, + reverse => "yes", + # special stuff passed through + page => $params{page}, + destpage => $params{destpage}, + preview => $params{preview}, + ); + push @args, atom => $params{atom} if defined $params{atom}; + push @args, rss => $params{rss} if defined $params{rss}; + push @args, feeds => $params{feeds} if defined $params{feeds}; + push @args, feedshow => $params{feedshow} if defined $params{feedshow}; + push @args, timeformat => $params{timeformat} if defined $params{timeformat}; + push @args, feedonly => $params{feedonly} if defined $params{feedonly}; + $posts = "\n" . IkiWiki::preprocess_inline(@args); + } + + return $formtemplate->output . $posts; +} # }}} + +# FIXME: logic taken from editpage, should be common code? +sub getcgiuser ($) { # {{{ + my $session = shift; + my $user = $session->param('name'); + $user = $ENV{REMOTE_ADDR} unless defined $user; + debug("getcgiuser() -> $user"); + return $user; +} # }}} + +# FIXME: logic adapted from recentchanges, should be common code? +sub linkuser ($) { # {{{ + my $user = shift; + my $oiduser = eval { IkiWiki::openiduser($user) }; + + if (defined $oiduser) { + return ($user, $oiduser); + } + else { + my $page = bestlink('', (length $config{userdir} + ? "$config{userdir}/" + : "").$user); + return (urlto($page, undef, 1), $user); + } +} # }}} + +# FIXME: taken from IkiWiki::Plugin::editpage, should be common? +sub checksessionexpiry ($$) { # {{{ + my $session = shift; + my $sid = shift; + + if (defined $session->param("name")) { + if (! defined $sid || $sid ne $session->id) { + error(gettext("Your login session has expired.")); + } + } +} # }}} + +# Mostly cargo-culted from IkiWiki::plugin::editpage +sub sessioncgi ($$) { #{{{ + my $cgi=shift; + my $session=shift; + + my $do = $cgi->param('do'); + return unless $do eq 'comment'; + + IkiWiki::decode_cgi_utf8($cgi); + + eval q{use CGI::FormBuilder}; + error($@) if $@; + + my @buttons = (POST_COMMENT, PREVIEW, CANCEL); + my $form = CGI::FormBuilder->new( + fields => [qw{do sid page subject body}], + charset => 'utf-8', + method => 'POST', + required => [qw{body}], + javascript => 0, + params => $cgi, + action => $config{cgiurl}, + header => 0, + table => 0, + template => scalar IkiWiki::template_params('comments_form.tmpl'), + # wtf does this do in editpage? + wikiname => $config{wikiname}, + ); + + IkiWiki::decode_form_utf8($form); + IkiWiki::run_hooks(formbuilder_setup => sub { + shift->(title => "comment", form => $form, cgi => $cgi, + session => $session, buttons => \@buttons); + }); + IkiWiki::decode_form_utf8($form); + + $form->field(name => 'do', type => 'hidden'); + $form->field(name => 'sid', type => 'hidden', value => $session->id, + force => 1); + $form->field(name => 'page', type => 'hidden'); + $form->field(name => 'subject', type => 'text', size => 72); + $form->field(name => 'body', type => 'textarea', rows => 5, + cols => 80); + + # The untaint is OK (as in editpage) because we're about to pass + # it to file_pruned anyway + my $page = $form->field('page'); + $page = IkiWiki::possibly_foolish_untaint($page); + if (!defined $page || !length $page || + IkiWiki::file_pruned($page, $config{srcdir})) { + error(gettext("bad page name")); + } + + my $allow_directives = $pagestate{$page}{comments}{allowdirectives}; + my $allow_html = $pagestate{$page}{comments}{allowdirectives}; + my $commit_comments = defined $pagestate{$page}{comments}{commit} + ? $pagestate{$page}{comments}{commit} + : 1; + + # FIXME: is this right? Or should we be using the candidate subpage + # (whatever that might mean) as the base URL? + my $baseurl = urlto($page, undef, 1); + + $form->title(sprintf(gettext("commenting on %s"), + IkiWiki::pagetitle($page))); + + $form->tmpl_param('helponformattinglink', + htmllink($page, $page, 'ikiwiki/formatting', + noimageinline => 1, + linktext => 'FormattingHelp'), + allowhtml => $allow_html, + allowdirectives => $allow_directives); + + if (not exists $pagesources{$page}) { + error(sprintf(gettext( + "page '%s' doesn't exist, so you can't comment"), + $page)); + } + if (not $pagestate{$page}{comments}{comments}) { + error(sprintf(gettext( + "comments are not enabled on page '%s'"), + $page)); + } + + if ($form->submitted eq CANCEL) { + # bounce back to the page they wanted to comment on, and exit. + # CANCEL need not be considered in future + IkiWiki::redirect($cgi, urlto($page, undef, 1)); + exit; + } + + IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); + + my ($authorurl, $author) = linkuser(getcgiuser($session)); + + my $body = $form->field('body') || ''; + $body =~ s/\r\n/\n/g; + $body =~ s/\r/\n/g; + $body = "\n" if $body !~ /\n$/; + + unless ($allow_directives) { + # don't allow new-style directives at all + $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; + + # don't allow [[ unless it begins an old-style + # wikilink, if prefix_directives is off + $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g + unless $config{prefix_directives}; + } + + unless ($allow_html) { + $body =~ s/&(\w|#)/&$1/g; + $body =~ s//>/g; + } + + # In this template, the [[!meta]] directives should stay at the end, + # so that they will override anything the user specifies. (For + # instance, [[!meta author="I can fake the author"]]...) + my $content_tmpl = template('comments_comment.tmpl'); + $content_tmpl->param(author => $author); + $content_tmpl->param(authorurl => $authorurl); + $content_tmpl->param(subject => $form->field('subject')); + $content_tmpl->param(body => $body); + + my $content = $content_tmpl->output; + + # 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 + # - this means that conflicts should never happen + # - this means that if they do, rocks fall and everyone dies + + if ($form->submitted eq PREVIEW) { + # $fake is a location that has the same number of slashes + # as the eventual location of this comment. + my $fake = "$page/_comments_hypothetical"; + my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, + IkiWiki::filter($fake, $page, + $content), + 0, 1))); + IkiWiki::run_hooks(format => sub { + $preview = shift->(page => $page, + content => $preview); + }); + + my $template = template("comments_display.tmpl"); + $template->param(content => $preview); + $template->param(title => $form->field('subject')); + $template->param(ctime => displaytime(time)); + $template->param(author => $author); + $template->param(authorurl => $authorurl); + + $form->tmpl_param(page_preview => $template->output); + } + else { + $form->tmpl_param(page_preview => ""); + } + + if ($form->submitted eq POST_COMMENT && $form->validate) { + # Let's get posting. We don't check_canedit here because + # that somewhat defeats the point of this plugin. + + checksessionexpiry($session, $cgi->param('sid')); + + # FIXME: check that the wiki is locked right now, because + # if it's not, there are mad race conditions! + + # FIXME: rather a simplistic way to make the comments... + my $i = 0; + my $file; + do { + $i++; + $file = "$page/_comment_${i}._comment"; + } while (-e "$config{srcdir}/$file"); + + # FIXME: could probably do some sort of graceful retry + # if I could be bothered + writefile($file, $config{srcdir}, $content); + + my $conflict; + + if ($config{rcs} and $commit_comments) { + my $message = gettext("Added a comment"); + if (defined $form->field('subject') && + length $form->field('subject')) { + $message .= ": ".$form->field('subject'); + } + + IkiWiki::rcs_add($file); + IkiWiki::disable_commit_hook(); + $conflict = IkiWiki::rcs_commit_staged($message, + $session->param('name'), $ENV{REMOTE_ADDR}); + IkiWiki::enable_commit_hook(); + IkiWiki::rcs_update(); + } + + # Now we need a refresh + require IkiWiki::Render; + IkiWiki::refresh(); + IkiWiki::saveindex(); + + # this should never happen, unless a committer deliberately + # breaks it or something + error($conflict) if defined $conflict; + + # Bounce back to where we were, but defeat broken caches + my $anticache = "?updated=$page/_comment_$i"; + IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); + } + else { + IkiWiki::showform ($form, \@buttons, $session, $cgi, + forcebaseurl => $baseurl); + } + + exit; +} #}}} + +package IkiWiki::PageSpec; + +sub match_postcomment ($$;@) { + my $page = shift; + my $glob = shift; + + unless ($page =~ s/\[postcomment\]$//) { + return IkiWiki::FailReason->new("not posting a comment"); + } + return match_glob($page, $glob); +} + +1 diff --git a/IkiWiki/Plugin/postcomment.pm b/IkiWiki/Plugin/postcomment.pm deleted file mode 100644 index 480ca58a5..000000000 --- a/IkiWiki/Plugin/postcomment.pm +++ /dev/null @@ -1,371 +0,0 @@ -#!/usr/bin/perl -# Copyright © 2006-2008 Joey Hess -# Copyright © 2008 Simon McVittie -# Licensed under the GNU GPL, version 2, or any later version published by the -# Free Software Foundation -package IkiWiki::Plugin::postcomment; - -use warnings; -use strict; -use IkiWiki 2.00; - -use constant PLUGIN => "postcomment"; -use constant PREVIEW => "Preview"; -use constant POST_COMMENT => "Post comment"; -use constant CANCEL => "Cancel"; - -sub import { #{{{ - hook(type => "getsetup", id => PLUGIN, call => \&getsetup); - hook(type => "preprocess", id => PLUGIN, call => \&preprocess); - hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); - hook(type => "htmlize", id => "_".PLUGIN, - call => \&IkiWiki::Plugin::mdwn::htmlize); - IkiWiki::loadplugin("inline"); - IkiWiki::loadplugin("mdwn"); -} # }}} - -sub htmlize { # {{{ - eval { use IkiWiki::Plugin::mdwn; }; - error($@) if ($@); - return IkiWiki::Plugin::mdwn::htmlize(@_) -} # }}} - -sub getsetup () { #{{{ - return - plugin => { - safe => 1, - rebuild => undef, - }, -} #}}} - -# Somewhat based on IkiWiki::Plugin::inline blog posting support -sub preprocess (@) { #{{{ - my %params=@_; - - unless (length $config{cgiurl}) { - error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), - PLUGIN)); - } - - my $page = $params{page}; - $pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} - ? (not IkiWiki::yesno($params{closed})) - : 1; - $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); - $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); - $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} - ? IkiWiki::yesno($params{commit}) - : 1; - - my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", - blind_cache => 1); - $formtemplate->param(cgiurl => $config{cgiurl}); - $formtemplate->param(page => $params{page}); - - if (not $pagestate{$page}{PLUGIN()}{comments}) { - $formtemplate->param("disabled" => - gettext('comments are closed')); - } - elsif ($params{preview}) { - $formtemplate->param("disabled" => - gettext('not available during Preview')); - } - - debug("page $params{page} => destpage $params{destpage}"); - - my $posts = ''; - unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { - eval { use IkiWiki::Plugin::inline; }; - error($@) if ($@); - my @args = ( - pages => "internal($params{page}/_comment_*)", - template => PLUGIN . "_display", - show => 0, - reverse => "yes", - # special stuff passed through - page => $params{page}, - destpage => $params{destpage}, - preview => $params{preview}, - ); - push @args, atom => $params{atom} if defined $params{atom}; - push @args, rss => $params{rss} if defined $params{rss}; - push @args, feeds => $params{feeds} if defined $params{feeds}; - push @args, feedshow => $params{feedshow} if defined $params{feedshow}; - push @args, timeformat => $params{timeformat} if defined $params{timeformat}; - push @args, feedonly => $params{feedonly} if defined $params{feedonly}; - $posts = "\n" . IkiWiki::preprocess_inline(@args); - } - - return $formtemplate->output . $posts; -} # }}} - -# FIXME: logic taken from editpage, should be common code? -sub getcgiuser ($) { # {{{ - my $session = shift; - my $user = $session->param('name'); - $user = $ENV{REMOTE_ADDR} unless defined $user; - debug("getcgiuser() -> $user"); - return $user; -} # }}} - -# FIXME: logic adapted from recentchanges, should be common code? -sub linkuser ($) { # {{{ - my $user = shift; - my $oiduser = eval { IkiWiki::openiduser($user) }; - - if (defined $oiduser) { - return ($user, $oiduser); - } - else { - my $page = bestlink('', (length $config{userdir} - ? "$config{userdir}/" - : "").$user); - return (urlto($page, undef, 1), $user); - } -} # }}} - -# FIXME: taken from IkiWiki::Plugin::editpage, should be common? -sub checksessionexpiry ($$) { # {{{ - my $session = shift; - my $sid = shift; - - if (defined $session->param("name")) { - if (! defined $sid || $sid ne $session->id) { - error(gettext("Your login session has expired.")); - } - } -} # }}} - -# Mostly cargo-culted from IkiWiki::plugin::editpage -sub sessioncgi ($$) { #{{{ - my $cgi=shift; - my $session=shift; - - my $do = $cgi->param('do'); - return unless $do eq PLUGIN; - - IkiWiki::decode_cgi_utf8($cgi); - - eval q{use CGI::FormBuilder}; - error($@) if $@; - - my @buttons = (POST_COMMENT, PREVIEW, CANCEL); - my $form = CGI::FormBuilder->new( - fields => [qw{do sid page subject body}], - charset => 'utf-8', - method => 'POST', - required => [qw{body}], - javascript => 0, - params => $cgi, - action => $config{cgiurl}, - header => 0, - table => 0, - template => scalar IkiWiki::template_params(PLUGIN . '_form.tmpl'), - # wtf does this do in editpage? - wikiname => $config{wikiname}, - ); - - IkiWiki::decode_form_utf8($form); - IkiWiki::run_hooks(formbuilder_setup => sub { - shift->(title => PLUGIN, form => $form, cgi => $cgi, - session => $session, buttons => \@buttons); - }); - IkiWiki::decode_form_utf8($form); - - $form->field(name => 'do', type => 'hidden'); - $form->field(name => 'sid', type => 'hidden', value => $session->id, - force => 1); - $form->field(name => 'page', type => 'hidden'); - $form->field(name => 'subject', type => 'text', size => 72); - $form->field(name => 'body', type => 'textarea', rows => 5, - cols => 80); - - # The untaint is OK (as in editpage) because we're about to pass - # it to file_pruned anyway - my $page = $form->field('page'); - $page = IkiWiki::possibly_foolish_untaint($page); - if (!defined $page || !length $page || - IkiWiki::file_pruned($page, $config{srcdir})) { - error(gettext("bad page name")); - } - - my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} - ? $pagestate{$page}{PLUGIN()}{commit} - : 1; - - # FIXME: is this right? Or should we be using the candidate subpage - # (whatever that might mean) as the base URL? - my $baseurl = urlto($page, undef, 1); - - $form->title(sprintf(gettext("commenting on %s"), - IkiWiki::pagetitle($page))); - - $form->tmpl_param('helponformattinglink', - htmllink($page, $page, 'ikiwiki/formatting', - noimageinline => 1, - linktext => 'FormattingHelp'), - allowhtml => $allow_html, - allowdirectives => $allow_directives); - - if (not exists $pagesources{$page}) { - error(sprintf(gettext( - "page '%s' doesn't exist, so you can't comment"), - $page)); - } - if (not $pagestate{$page}{PLUGIN()}{comments}) { - error(sprintf(gettext( - "comments are not enabled on page '%s'"), - $page)); - } - - if ($form->submitted eq CANCEL) { - # bounce back to the page they wanted to comment on, and exit. - # CANCEL need not be considered in future - IkiWiki::redirect($cgi, urlto($page, undef, 1)); - exit; - } - - IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); - - my ($authorurl, $author) = linkuser(getcgiuser($session)); - - my $body = $form->field('body') || ''; - $body =~ s/\r\n/\n/g; - $body =~ s/\r/\n/g; - $body = "\n" if $body !~ /\n$/; - - unless ($allow_directives) { - # don't allow new-style directives at all - $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; - - # don't allow [[ unless it begins an old-style - # wikilink, if prefix_directives is off - $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g - unless $config{prefix_directives}; - } - - unless ($allow_html) { - $body =~ s/&(\w|#)/&$1/g; - $body =~ s//>/g; - } - - # In this template, the [[!meta]] directives should stay at the end, - # so that they will override anything the user specifies. (For - # instance, [[!meta author="I can fake the author"]]...) - my $content_tmpl = template(PLUGIN . '_comment.tmpl'); - $content_tmpl->param(author => $author); - $content_tmpl->param(authorurl => $authorurl); - $content_tmpl->param(subject => $form->field('subject')); - $content_tmpl->param(body => $body); - - my $content = $content_tmpl->output; - - # 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 - # - this means that conflicts should never happen - # - this means that if they do, rocks fall and everyone dies - - if ($form->submitted eq PREVIEW) { - # $fake is a location that has the same number of slashes - # as the eventual location of this comment. - my $fake = "$page/_" . PLUGIN . "hypothetical"; - my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', - IkiWiki::linkify($page, $page, - IkiWiki::preprocess($page, $page, - IkiWiki::filter($fake, $page, - $content), - 0, 1))); - IkiWiki::run_hooks(format => sub { - $preview = shift->(page => $page, - content => $preview); - }); - - my $template = template(PLUGIN . "_display.tmpl"); - $template->param(content => $preview); - $template->param(title => $form->field('subject')); - $template->param(ctime => displaytime(time)); - $template->param(author => $author); - $template->param(authorurl => $authorurl); - - $form->tmpl_param(page_preview => $template->output); - } - else { - $form->tmpl_param(page_preview => ""); - } - - if ($form->submitted eq POST_COMMENT && $form->validate) { - # Let's get posting. We don't check_canedit here because - # that somewhat defeats the point of this plugin. - - checksessionexpiry($session, $cgi->param('sid')); - - # FIXME: check that the wiki is locked right now, because - # if it's not, there are mad race conditions! - - # FIXME: rather a simplistic way to make the comments... - my $i = 0; - my $file; - do { - $i++; - $file = "$page/_comment_${i}._" . PLUGIN; - } while (-e "$config{srcdir}/$file"); - - # FIXME: could probably do some sort of graceful retry - # if I could be bothered - writefile($file, $config{srcdir}, $content); - - my $conflict; - - if ($config{rcs} and $commit_comments) { - my $message = gettext("Added a comment"); - if (defined $form->field('subject') && - length $form->field('subject')) { - $message .= ": ".$form->field('subject'); - } - - IkiWiki::rcs_add($file); - IkiWiki::disable_commit_hook(); - $conflict = IkiWiki::rcs_commit_staged($message, - $session->param('name'), $ENV{REMOTE_ADDR}); - IkiWiki::enable_commit_hook(); - IkiWiki::rcs_update(); - } - - # Now we need a refresh - require IkiWiki::Render; - IkiWiki::refresh(); - IkiWiki::saveindex(); - - # this should never happen, unless a committer deliberately - # breaks it or something - error($conflict) if defined $conflict; - - # Bounce back to where we were, but defeat broken caches - my $anticache = "?updated=$page/_comment_$i"; - IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); - } - else { - IkiWiki::showform ($form, \@buttons, $session, $cgi, - forcebaseurl => $baseurl); - } - - exit; -} #}}} - -package IkiWiki::PageSpec; - -sub match_postcomment ($$;@) { - my $page = shift; - my $glob = shift; - - unless ($page =~ s/\[postcomment\]$//) { - return IkiWiki::FailReason->new("not posting a comment"); - } - return match_glob($page, $glob); -} - -1 diff --git a/doc/style.css b/doc/style.css index 21ea9492c..70f31d325 100644 --- a/doc/style.css +++ b/doc/style.css @@ -373,7 +373,7 @@ span.color { padding: 2px; } -.postcomment-display .author { font-weight: bold; } -.postcomment-display { border: 1px inset #999; margin: 3px; padding: 3px; } -.postcomment-header { font-style: italic; } -.postcomment-subject { font-weight: bold; border-bottom: 1px solid #999; } +.comments-display .author { font-weight: bold; } +.comments-display { border: 1px inset #999; margin: 3px; padding: 3px; } +.comments-header { font-style: italic; } +.comments-subject { font-weight: bold; border-bottom: 1px solid #999; } diff --git a/templates/comments_comment.tmpl b/templates/comments_comment.tmpl new file mode 100644 index 000000000..8c89458f3 --- /dev/null +++ b/templates/comments_comment.tmpl @@ -0,0 +1,10 @@ + + +[[!meta title=""]] + + +[[!meta author=""]] + + +[[!meta authorurl=""]] + diff --git a/templates/comments_display.tmpl b/templates/comments_display.tmpl new file mode 100644 index 000000000..04e0613e0 --- /dev/null +++ b/templates/comments_display.tmpl @@ -0,0 +1,24 @@ +
+ +
+Posted by + + + + + + + + + + +() +
+ +
+ +
+ +
+ +
diff --git a/templates/comments_embed.tmpl b/templates/comments_embed.tmpl new file mode 100644 index 000000000..cbb9247f2 --- /dev/null +++ b/templates/comments_embed.tmpl @@ -0,0 +1,7 @@ +
+ +[Posting comments disabled: ] + +Post a comment + +
diff --git a/templates/comments_form.tmpl b/templates/comments_form.tmpl new file mode 100644 index 000000000..fbf49be34 --- /dev/null +++ b/templates/comments_form.tmpl @@ -0,0 +1,25 @@ +
+ + + + + +Subject:
+
+
+
+HTML is not allowed.
+IkiWiki directives ([[!directive]]) are not allowed.
+ + + +
+
+Comment preview: +
+
+ +
+
+ +
diff --git a/templates/postcomment_comment.tmpl b/templates/postcomment_comment.tmpl deleted file mode 100644 index 8c89458f3..000000000 --- a/templates/postcomment_comment.tmpl +++ /dev/null @@ -1,10 +0,0 @@ - - -[[!meta title=""]] - - -[[!meta author=""]] - - -[[!meta authorurl=""]] - diff --git a/templates/postcomment_display.tmpl b/templates/postcomment_display.tmpl deleted file mode 100644 index d3eabb3a1..000000000 --- a/templates/postcomment_display.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -
- -
-Posted by - - - - - - - - - - -() -
- -
- -
- -
- -
diff --git a/templates/postcomment_embed.tmpl b/templates/postcomment_embed.tmpl deleted file mode 100644 index eae741214..000000000 --- a/templates/postcomment_embed.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -
- -[Posting comments disabled: ] - -Post a comment - -
diff --git a/templates/postcomment_form.tmpl b/templates/postcomment_form.tmpl deleted file mode 100644 index 293f0f17e..000000000 --- a/templates/postcomment_form.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -
- - - - - -Subject:
-
-
-
-HTML is not allowed.
-IkiWiki directives ([[!directive]]) are not allowed.
- - - -
-
-Comment preview: -
-
- -
-
- -
-- cgit v1.2.3 From 57e40b9ce5345530f31f4d1b25a49ed18228a8dd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:25:10 +0000 Subject: Fix typo that led to comments being blanked --- IkiWiki/Plugin/comments.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index b57735545..9359e9487 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -232,7 +232,7 @@ sub sessioncgi ($$) { #{{{ my $body = $form->field('body') || ''; $body =~ s/\r\n/\n/g; $body =~ s/\r/\n/g; - $body = "\n" if $body !~ /\n$/; + $body .= "\n" if $body !~ /\n$/; unless ($allow_directives) { # don't allow new-style directives at all -- cgit v1.2.3 From ebe140201ed53ee4f8cf5998c69e20d5fef2ad16 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:29:16 +0000 Subject: comments: sanitize the body of each comment before posting it This should ensure that users can't "break out" from the enclosing
, making it impossible to forge comments (assuming htmlscrubber is enabled, and so is either htmlbalance or htmltidy). --- IkiWiki/Plugin/comments.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 9359e9487..c545a1335 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -250,6 +250,17 @@ sub sessioncgi ($$) { #{{{ $body =~ s/>/>/g; } + IkiWiki::run_hooks(sanitize => sub { + # $fake is a possible location for this comment. We don't + # know yet what the comment number *actually* is. + my $fake = "$page/_comment_1"; + $body=shift->( + page => $fake, + destpage => $fake, + content => $body, + ); + }); + # In this template, the [[!meta]] directives should stay at the end, # so that they will override anything the user specifies. (For # instance, [[!meta author="I can fake the author"]]...) @@ -268,9 +279,9 @@ sub sessioncgi ($$) { #{{{ # - this means that if they do, rocks fall and everyone dies if ($form->submitted eq PREVIEW) { - # $fake is a location that has the same number of slashes - # as the eventual location of this comment. - my $fake = "$page/_comments_hypothetical"; + # $fake is a possible location for this comment. We don't + # know yet what the comment number *actually* is. + my $fake = "$page/_comment_1"; my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, -- cgit v1.2.3 From 9d92fd5eb060678650e6ca5ce8af0a50600c6d2e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:43:11 +0000 Subject: comments: don't rely on mdwn getting loaded first --- IkiWiki/Plugin/comments.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index c545a1335..29dc06f32 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -17,8 +17,7 @@ sub import { #{{{ hook(type => "getsetup", id => 'comments', call => \&getsetup); hook(type => "preprocess", id => 'comments', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); - hook(type => "htmlize", id => "_comment", - call => \&IkiWiki::Plugin::mdwn::htmlize); + hook(type => "htmlize", id => "_comment", call => \&htmlize); IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("mdwn"); } # }}} -- cgit v1.2.3 From 4663f364bbc220bbdbf03582765b6d82f0bddc46 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:43:39 +0000 Subject: comments: load inline and mdwn lazily --- IkiWiki/Plugin/comments.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 29dc06f32..8122f9d51 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -23,7 +23,7 @@ sub import { #{{{ } # }}} sub htmlize { # {{{ - eval { use IkiWiki::Plugin::mdwn; }; + eval q{use IkiWiki::Plugin::mdwn}; error($@) if ($@); return IkiWiki::Plugin::mdwn::htmlize(@_) } # }}} @@ -72,7 +72,7 @@ sub preprocess (@) { #{{{ my $posts = ''; unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { - eval { use IkiWiki::Plugin::inline; }; + eval q{use IkiWiki::Plugin::inline}; error($@) if ($@); my @args = ( pages => "internal($params{page}/_comment_*)", -- cgit v1.2.3 From 249ea2ed7557e34614ef9f1f863cee9489798510 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:44:34 +0000 Subject: comments: remove allowhtml option, just switch it on all the time Now that posts are individually sanitized, that should be safe. --- IkiWiki/Plugin/comments.pm | 9 --------- templates/comments_form.tmpl | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 8122f9d51..f10400db1 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -48,7 +48,6 @@ sub preprocess (@) { #{{{ $pagestate{$page}{comments}{comments} = defined $params{closed} ? (not IkiWiki::yesno($params{closed})) : 1; - $pagestate{$page}{comments}{allowhtml} = IkiWiki::yesno($params{allowhtml}); $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); $pagestate{$page}{comments}{commit} = defined $params{commit} ? IkiWiki::yesno($params{commit}) @@ -187,7 +186,6 @@ sub sessioncgi ($$) { #{{{ } my $allow_directives = $pagestate{$page}{comments}{allowdirectives}; - my $allow_html = $pagestate{$page}{comments}{allowdirectives}; my $commit_comments = defined $pagestate{$page}{comments}{commit} ? $pagestate{$page}{comments}{commit} : 1; @@ -203,7 +201,6 @@ sub sessioncgi ($$) { #{{{ htmllink($page, $page, 'ikiwiki/formatting', noimageinline => 1, linktext => 'FormattingHelp'), - allowhtml => $allow_html, allowdirectives => $allow_directives); if (not exists $pagesources{$page}) { @@ -243,12 +240,6 @@ sub sessioncgi ($$) { #{{{ unless $config{prefix_directives}; } - unless ($allow_html) { - $body =~ s/&(\w|#)/&$1/g; - $body =~ s//>/g; - } - IkiWiki::run_hooks(sanitize => sub { # $fake is a possible location for this comment. We don't # know yet what the comment number *actually* is. diff --git a/templates/comments_form.tmpl b/templates/comments_form.tmpl index fbf49be34..59c03b4f0 100644 --- a/templates/comments_form.tmpl +++ b/templates/comments_form.tmpl @@ -8,7 +8,7 @@ Subject:



-HTML is not allowed.
+Formatting with Markdown and HTML are allowed.
IkiWiki directives ([[!directive]]) are not allowed.
-- cgit v1.2.3 From cb5aaa3cee8b35d6fc6e88a7449a9477a6587c7a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 11:25:13 +0000 Subject: htmlbalance: don't compact whitespace, and set misc other options Not compacting whitespace is the most important one: now that we run sanitize hooks on individual posted comments in the comments plugin, whitespace that is significant to Markdown (but not HTML) is lost. --- IkiWiki/Plugin/htmlbalance.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm index 3a2d62d15..dcd92055f 100644 --- a/IkiWiki/Plugin/htmlbalance.pm +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -30,7 +30,15 @@ sub sanitize (@) { #{{{ my %params=@_; my $ret = ''; - my $tree = HTML::TreeBuilder->new_from_content($params{content}); + my $tree = HTML::TreeBuilder->new(); + $tree->ignore_unknown(0); + $tree->ignore_ignorable_whitespace(0); + $tree->no_space_compacting(1); + $tree->p_strict(1); + $tree->store_comments(0); + $tree->store_declarations(0); + $tree->store_pis(0); + $tree->parse_content($params{content}); my @nodes = $tree->disembowel(); foreach my $node (@nodes) { if (ref $node) { -- cgit v1.2.3 From 9a6005a212f9be2395943f424e48270b24588fcd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Nov 2008 21:53:33 +0000 Subject: editpage: factor out checksessionexpiry into IkiWiki::CGI --- IkiWiki/CGI.pm | 14 ++++++++++++++ IkiWiki/Plugin/editpage.pm | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 4399d0dcb..a3486cbb4 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -296,6 +296,20 @@ sub cgi_getsession ($) { #{{{ return $session; } #}}} +# The session id is stored on the form and checked to +# guard against CSRF. But only if the user is logged in, +# as anonok can allow anonymous edits. +sub checksessionexpiry ($$) { # {{{ + my $session = shift; + my $sid = shift; + + if (defined $session->param("name")) { + if (! defined $sid || $sid ne $session->id) { + error(gettext("Your login session has expired.")); + } + } +} # }}} + sub cgi_savesession ($) { #{{{ my $session=shift; diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index fe2864bac..e4f0cdac0 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -340,16 +340,7 @@ sub cgi_editpage ($$) { #{{{ else { # save page check_canedit($page, $q, $session); - - # The session id is stored on the form and checked to - # guard against CSRF. But only if the user is logged in, - # as anonok can allow anonymous edits. - if (defined $session->param("name")) { - my $sid=$q->param('sid'); - if (! defined $sid || $sid ne $session->id) { - error(gettext("Your login session has expired.")); - } - } + checksessionexpiry($session, $q->param('sid')); my $exists=-e "$config{srcdir}/$file"; -- cgit v1.2.3 From 286dbb0541225dd4ff7db6ed958922f7512b789b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Nov 2008 21:54:31 +0000 Subject: comments: use CGI module's checksessionexpiry --- IkiWiki/Plugin/comments.pm | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index f10400db1..136dc258e 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -120,18 +120,6 @@ sub linkuser ($) { # {{{ } } # }}} -# FIXME: taken from IkiWiki::Plugin::editpage, should be common? -sub checksessionexpiry ($$) { # {{{ - my $session = shift; - my $sid = shift; - - if (defined $session->param("name")) { - if (! defined $sid || $sid ne $session->id) { - error(gettext("Your login session has expired.")); - } - } -} # }}} - # Mostly cargo-culted from IkiWiki::plugin::editpage sub sessioncgi ($$) { #{{{ my $cgi=shift; @@ -300,7 +288,7 @@ sub sessioncgi ($$) { #{{{ # Let's get posting. We don't check_canedit here because # that somewhat defeats the point of this plugin. - checksessionexpiry($session, $cgi->param('sid')); + IkiWiki::checksessionexpiry($session, $cgi->param('sid')); # FIXME: check that the wiki is locked right now, because # if it's not, there are mad race conditions! -- cgit v1.2.3 From 430ac61f2142bc92b12d16067ca7b40202d0c589 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 12:02:39 +0000 Subject: Embed comments into comments_embed.tmpl rather than concatenating in perl --- IkiWiki/Plugin/comments.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 136dc258e..acc3ffdb3 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -69,8 +69,8 @@ sub preprocess (@) { #{{{ debug("page $params{page} => destpage $params{destpage}"); - my $posts = ''; unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { + my $posts = ''; eval q{use IkiWiki::Plugin::inline}; error($@) if ($@); my @args = ( @@ -89,10 +89,11 @@ sub preprocess (@) { #{{{ push @args, feedshow => $params{feedshow} if defined $params{feedshow}; push @args, timeformat => $params{timeformat} if defined $params{timeformat}; push @args, feedonly => $params{feedonly} if defined $params{feedonly}; - $posts = "\n" . IkiWiki::preprocess_inline(@args); + $posts = IkiWiki::preprocess_inline(@args); + $formtemplate->param("comments" => $posts); } - return $formtemplate->output . $posts; + return $formtemplate->output; } # }}} # FIXME: logic taken from editpage, should be common code? -- cgit v1.2.3 From 3abfc1d71c914035deff75a4373041cb9962a471 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 12:03:05 +0000 Subject: comments: Use HTML entities to escape directives --- IkiWiki/Plugin/comments.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index acc3ffdb3..a68026ebc 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -221,11 +221,11 @@ sub sessioncgi ($$) { #{{{ unless ($allow_directives) { # don't allow new-style directives at all - $body =~ s/(^|[^\\])\[\[!/$1\\[[!/g; + $body =~ s/(^|[^\\])\[\[!/$1[[!/g; # don't allow [[ unless it begins an old-style # wikilink, if prefix_directives is off - $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1\\[[!/g + $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1[[!/g unless $config{prefix_directives}; } -- cgit v1.2.3 From 404792c61840c974faca9230ab9005c7b8dd30d1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 12:04:00 +0000 Subject: comments: add a stub pagetemplate hook to show the comments --- IkiWiki/Plugin/comments.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index a68026ebc..ea106a90f 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -18,6 +18,7 @@ sub import { #{{{ hook(type => "preprocess", id => 'comments', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); hook(type => "htmlize", id => "_comment", call => \&htmlize); + hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("mdwn"); } # }}} @@ -344,6 +345,21 @@ sub sessioncgi ($$) { #{{{ exit; } #}}} +sub pagetemplate (@) { #{{{ + my %params = @_; + + my $page = $params{page}; + my $template = $params{template}; + + if ($template->query(name => 'comments')) { + my $comments = undef; + + if (defined $comments && length $comments) { + $template->param(name => $comments); + } + } +} # }}} + package IkiWiki::PageSpec; sub match_postcomment ($$;@) { -- cgit v1.2.3 From c9bb8b03a43b735e1b9876f58a1499a1445d0663 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 12:05:24 +0000 Subject: comments: document what linkuser does --- IkiWiki/Plugin/comments.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index ea106a90f..25f1b62f0 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -107,6 +107,7 @@ sub getcgiuser ($) { # {{{ } # }}} # FIXME: logic adapted from recentchanges, should be common code? +# returns (author URL, pretty-printed version) sub linkuser ($) { # {{{ my $user = shift; my $oiduser = eval { IkiWiki::openiduser($user) }; -- cgit v1.2.3 From 4972baac4dde88b52983f10f4fed6117c71d4fad Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:07:28 +0000 Subject: comments: make preprocess a no-op --- IkiWiki/Plugin/comments.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 25f1b62f0..a7b166232 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -41,9 +41,7 @@ sub getsetup () { #{{{ sub preprocess (@) { #{{{ my %params=@_; - unless (length $config{cgiurl}) { - error(gettext("[[!comments plugin requires CGI enabled]]")); - } + return ""; my $page = $params{page}; $pagestate{$page}{comments}{comments} = defined $params{closed} -- cgit v1.2.3 From d35a2bd2ded70156250808684e859dbbc50f81db Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 12:11:18 +0000 Subject: comments: Add some global configuration --- IkiWiki/Plugin/comments.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index a7b166232..892b4af26 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -33,8 +33,54 @@ sub getsetup () { #{{{ return plugin => { safe => 1, + rebuild => 1, + }, + # Pages where comments are shown, but new comments are not + # allowed, will show "Comments are closed". + comments_shown_pagespec => { + type => 'pagespec', + example => 'blog/*', + default => '', + description => 'PageSpec for pages where comments will be shown inline', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 1, + }, + comments_open_pagespec => { + type => 'pagespec', + example => 'blog/* and created_after(close_old_comments)', + default => '', + description => 'PageSpec for pages where new comments can be posted', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 1, + }, + comments_pagename => { + type => 'string', + example => 'comment_', + default => 'comment_', + description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"', + safe => 0, # manual page moving will required rebuild => undef, }, + comments_allowdirectives => { + type => 'boolean', + default => 0, + example => 0, + description => 'Allow directives in newly posted comments?', + safe => 1, + rebuild => 0, + }, + comments_commit => { + type => 'boolean', + example => 1, + default => 1, + description => 'commit comments to the VCS', + # old uncommitted comments are likely to cause + # confusion if this is changed + safe => 0, + rebuild => 0, + }, } #}}} # Somewhat based on IkiWiki::Plugin::inline blog posting support -- cgit v1.2.3 From a9b0b3da5f002e38141c038e2ab3525b099d684b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:07:58 +0000 Subject: comments: use global configuration for allow_directives, commit, and pagename --- IkiWiki/Plugin/comments.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 892b4af26..80469f503 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -220,10 +220,9 @@ sub sessioncgi ($$) { #{{{ error(gettext("bad page name")); } - my $allow_directives = $pagestate{$page}{comments}{allowdirectives}; - my $commit_comments = defined $pagestate{$page}{comments}{commit} - ? $pagestate{$page}{comments}{commit} - : 1; + my $allow_directives = $config{comments_allowdirectives}; + my $commit_comments = $config{comments_commit}; + my $comments_pagename = $config{comments_pagename}; # FIXME: is this right? Or should we be using the candidate subpage # (whatever that might mean) as the base URL? -- cgit v1.2.3 From 49eabc676a170bfbd31ee51c27e02c20355554dc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:10:44 +0000 Subject: comments: use global config to decide whether commenting is allowed, and for name of page Also: * decide comment page name sooner * set permalink on it --- IkiWiki/Plugin/comments.pm | 77 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 80469f503..01ee481f5 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -237,24 +237,27 @@ sub sessioncgi ($$) { #{{{ linktext => 'FormattingHelp'), allowdirectives => $allow_directives); + if ($form->submitted eq CANCEL) { + # bounce back to the page they wanted to comment on, and exit. + # CANCEL need not be considered in future + IkiWiki::redirect($cgi, urlto($page, undef, 1)); + exit; + } + if (not exists $pagesources{$page}) { error(sprintf(gettext( "page '%s' doesn't exist, so you can't comment"), $page)); } - if (not $pagestate{$page}{comments}{comments}) { + + if (not pagespec_match($page, $config{comments_open_pagespec}, + location => $page)) { error(sprintf(gettext( - "comments are not enabled on page '%s'"), + "comments on page '%s' are closed"), $page)); } - if ($form->submitted eq CANCEL) { - # bounce back to the page they wanted to comment on, and exit. - # CANCEL need not be considered in future - IkiWiki::redirect($cgi, urlto($page, undef, 1)); - exit; - } - + IkiWiki::checksessionexpiry($session, $cgi->param('sid')); IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); my ($authorurl, $author) = linkuser(getcgiuser($session)); @@ -274,13 +277,24 @@ sub sessioncgi ($$) { #{{{ unless $config{prefix_directives}; } + # FIXME: check that the wiki is locked right now, because + # if it's not, there are mad race conditions! + + # FIXME: rather a simplistic way to make the comments... + my $i = 0; + my $file; + my $location; + do { + $i++; + $location = "$page/${comments_pagename}${i}"; + } while (-e "$config{srcdir}/$location._comment"); + + my $anchor = "${comments_pagename}${i}"; + IkiWiki::run_hooks(sanitize => sub { - # $fake is a possible location for this comment. We don't - # know yet what the comment number *actually* is. - my $fake = "$page/_comment_1"; $body=shift->( - page => $fake, - destpage => $fake, + page => $location, + destpage => $location, content => $body, ); }); @@ -293,6 +307,8 @@ sub sessioncgi ($$) { #{{{ $content_tmpl->param(authorurl => $authorurl); $content_tmpl->param(subject => $form->field('subject')); $content_tmpl->param(body => $body); + $content_tmpl->param(anchor => "$anchor"); + $content_tmpl->param(permalink => "$baseurl#$anchor"); my $content = $content_tmpl->output; @@ -303,14 +319,11 @@ sub sessioncgi ($$) { #{{{ # - this means that if they do, rocks fall and everyone dies if ($form->submitted eq PREVIEW) { - # $fake is a possible location for this comment. We don't - # know yet what the comment number *actually* is. - my $fake = "$page/_comment_1"; - my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', + my $preview = IkiWiki::htmlize($location, $page, 'mdwn', IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, - IkiWiki::filter($fake, $page, - $content), + IkiWiki::filter($location, + $page, $content), 0, 1))); IkiWiki::run_hooks(format => sub { $preview = shift->(page => $page, @@ -331,24 +344,10 @@ sub sessioncgi ($$) { #{{{ } if ($form->submitted eq POST_COMMENT && $form->validate) { - # Let's get posting. We don't check_canedit here because - # that somewhat defeats the point of this plugin. - - IkiWiki::checksessionexpiry($session, $cgi->param('sid')); - - # FIXME: check that the wiki is locked right now, because - # if it's not, there are mad race conditions! - - # FIXME: rather a simplistic way to make the comments... - my $i = 0; - my $file; - do { - $i++; - $file = "$page/_comment_${i}._comment"; - } while (-e "$config{srcdir}/$file"); + my $file = "$location._comment"; # FIXME: could probably do some sort of graceful retry - # if I could be bothered + # on error? Would require significant unwinding though writefile($file, $config{srcdir}, $content); my $conflict; @@ -357,7 +356,9 @@ sub sessioncgi ($$) { #{{{ my $message = gettext("Added a comment"); if (defined $form->field('subject') && length $form->field('subject')) { - $message .= ": ".$form->field('subject'); + $message = sprintf( + gettext("Added a comment: %s"), + $form->field('subject')); } IkiWiki::rcs_add($file); @@ -378,7 +379,7 @@ sub sessioncgi ($$) { #{{{ error($conflict) if defined $conflict; # Bounce back to where we were, but defeat broken caches - my $anticache = "?updated=$page/_comment_$i"; + my $anticache = "?updated=$page/${comments_pagename}${i}"; IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); } else { -- cgit v1.2.3 From 4ff161ba0b4b2fbb027ee2077330c08bd3a38073 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:11:14 +0000 Subject: comments: render comments/commenturl in page.tmpl --- IkiWiki/Plugin/comments.pm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 01ee481f5..33d8ca8e2 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -399,8 +399,48 @@ sub pagetemplate (@) { #{{{ if ($template->query(name => 'comments')) { my $comments = undef; + my $comments_pagename = $config{comments_pagename}; + + my $open = 0; + my $shown = pagespec_match($page, + $config{comments_shown_pagespec}, + location => $page); + + if (pagespec_match($page, "*/${comments_pagename}*", + location => $page)) { + $shown = 0; + $open = 0; + } + + if (length $config{cgiurl}) { + $open = pagespec_match($page, + $config{comments_open_pagespec}, + location => $page); + } + + if ($shown) { + eval q{use IkiWiki::Plugin::inline}; + error($@) if $@; + + my @args = ( + pages => "internal($page/${comments_pagename}*)", + template => 'comments_display', + show => 0, + reverse => 'yes', + page => $page, + destpage => $params{destpage}, + ); + $comments = IkiWiki::preprocess_inline(@args); + } + if (defined $comments && length $comments) { - $template->param(name => $comments); + $template->param(comments => $comments); + } + + if ($open) { + my $commenturl = IkiWiki::cgiurl(do => 'comment', + page => $page); + $template->param(commenturl => $commenturl); } } } # }}} -- cgit v1.2.3 From e66e2c2a7e2fdf2d80c20e61854480342d3fa8b4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:42:50 +0000 Subject: comments: Use a checkconfig hook to get the default value of comments_pagename --- IkiWiki/Plugin/comments.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 33d8ca8e2..4cd76c5d5 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -14,6 +14,7 @@ use constant POST_COMMENT => "Post comment"; use constant CANCEL => "Cancel"; sub import { #{{{ + hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); hook(type => "preprocess", id => 'comments', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); @@ -83,6 +84,12 @@ sub getsetup () { #{{{ }, } #}}} +sub checkconfig () { #{{{ + $config{comments_commit} = 1 unless defined $config{comments_commit}; + $config{comments_pagename} = 'comment_' + unless defined $config{comments_pagename}; +} #}}} + # Somewhat based on IkiWiki::Plugin::inline blog posting support sub preprocess (@) { #{{{ my %params=@_; -- cgit v1.2.3 From 24bfc3fdc52fd55703c6b618b768cfb0905456d3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:43:06 +0000 Subject: comments: record the time at which each comment was posted --- IkiWiki/Plugin/comments.pm | 1 + templates/comments_comment.tmpl | 3 +++ 2 files changed, 4 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 4cd76c5d5..58076938b 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -316,6 +316,7 @@ sub sessioncgi ($$) { #{{{ $content_tmpl->param(body => $body); $content_tmpl->param(anchor => "$anchor"); $content_tmpl->param(permalink => "$baseurl#$anchor"); + $content_tmpl->param(date => formattime(time, "%X %x")); my $content = $content_tmpl->output; diff --git a/templates/comments_comment.tmpl b/templates/comments_comment.tmpl index 56a28753e..8e6affb0d 100644 --- a/templates/comments_comment.tmpl +++ b/templates/comments_comment.tmpl @@ -15,6 +15,9 @@ [[!meta permalink=""]] + +[[!meta date=""]] +
-- cgit v1.2.3 From 80e84e32bf98ed76d0e207e414035b36b9232191 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:52:30 +0000 Subject: Delay checking for session expiry til we actually post a comment --- IkiWiki/Plugin/comments.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 58076938b..d149e5982 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -264,7 +264,6 @@ sub sessioncgi ($$) { #{{{ $page)); } - IkiWiki::checksessionexpiry($session, $cgi->param('sid')); IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); my ($authorurl, $author) = linkuser(getcgiuser($session)); @@ -354,6 +353,8 @@ sub sessioncgi ($$) { #{{{ if ($form->submitted eq POST_COMMENT && $form->validate) { my $file = "$location._comment"; + IkiWiki::checksessionexpiry($session, $cgi->param('sid')); + # FIXME: could probably do some sort of graceful retry # on error? Would require significant unwinding though writefile($file, $config{srcdir}, $content); -- cgit v1.2.3 From f88870f102e9578e0b44de056fec0bac2aff8b84 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 17:53:33 +0000 Subject: Qualify name of formattime() correctly --- IkiWiki/Plugin/comments.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index d149e5982..45b13168a 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -315,7 +315,7 @@ sub sessioncgi ($$) { #{{{ $content_tmpl->param(body => $body); $content_tmpl->param(anchor => "$anchor"); $content_tmpl->param(permalink => "$baseurl#$anchor"); - $content_tmpl->param(date => formattime(time, "%X %x")); + $content_tmpl->param(date => IkiWiki::formattime(time, "%X %x")); my $content = $content_tmpl->output; -- cgit v1.2.3 From 1d696aef2c6b364b55070b15dcc7084d0b09daaf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Nov 2008 18:31:11 +0000 Subject: comments: Duplicate logic and CGI hook from recentchanges to link user pages correctly --- IkiWiki/Plugin/comments.pm | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 45b13168a..8b82341c0 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -20,6 +20,7 @@ sub import { #{{{ hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); + hook(type => "cgi", id => "comments", call => \&linkcgi); IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("mdwn"); } # }}} @@ -157,7 +158,36 @@ sub getcgiuser ($) { # {{{ return $user; } # }}} -# FIXME: logic adapted from recentchanges, should be common code? +# This is exactly the same as recentchanges_link :-( +sub linkcgi ($) { #{{{ + my $cgi=shift; + if (defined $cgi->param('do') && $cgi->param('do') eq "commenter") { + + my $page=decode_utf8($cgi->param("page")); + if (!defined $page) { + error("missing page parameter"); + } + + IkiWiki::loadindex(); + + my $link=bestlink("", $page); + if (! length $link) { + print "Content-type: text/html\n\n"; + print IkiWiki::misctemplate(gettext(gettext("missing page")), + "

". + sprintf(gettext("The page %s does not exist."), + htmllink("", "", $page)). + "

"); + } + else { + IkiWiki::redirect($cgi, urlto($link, undef, 1)); + } + + exit; + } +} + +# FIXME: basically the same logic as recentchanges # returns (author URL, pretty-printed version) sub linkuser ($) { # {{{ my $user = shift; @@ -166,11 +196,15 @@ sub linkuser ($) { # {{{ if (defined $oiduser) { return ($user, $oiduser); } + # FIXME: it'd be good to avoid having such a link for anonymous + # posts else { - my $page = bestlink('', (length $config{userdir} - ? "$config{userdir}/" - : "").$user); - return (urlto($page, undef, 1), $user); + return (IkiWiki::cgiurl( + do => 'commenter', + page => (length $config{userdir} + ? "$config{userdir}/" + : "") + ).$user, $user); } } # }}} -- cgit v1.2.3 From 6a986a8a0bd20e82e128ce7e0aa9587437ae8325 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 10 Dec 2008 22:18:26 +0000 Subject: Remove dead code for preprocessing [[!comments]] --- IkiWiki/Plugin/comments.pm | 59 ---------------------------------------------- 1 file changed, 59 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 8b82341c0..73f8d6140 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -16,7 +16,6 @@ use constant CANCEL => "Cancel"; sub import { #{{{ hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); - hook(type => "preprocess", id => 'comments', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); @@ -91,64 +90,6 @@ sub checkconfig () { #{{{ unless defined $config{comments_pagename}; } #}}} -# Somewhat based on IkiWiki::Plugin::inline blog posting support -sub preprocess (@) { #{{{ - my %params=@_; - - return ""; - - my $page = $params{page}; - $pagestate{$page}{comments}{comments} = defined $params{closed} - ? (not IkiWiki::yesno($params{closed})) - : 1; - $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); - $pagestate{$page}{comments}{commit} = defined $params{commit} - ? IkiWiki::yesno($params{commit}) - : 1; - - my $formtemplate = IkiWiki::template("comments_embed.tmpl", - blind_cache => 1); - $formtemplate->param(cgiurl => $config{cgiurl}); - $formtemplate->param(page => $params{page}); - - if (not $pagestate{$page}{comments}{comments}) { - $formtemplate->param("disabled" => - gettext('comments are closed')); - } - elsif ($params{preview}) { - $formtemplate->param("disabled" => - gettext('not available during Preview')); - } - - debug("page $params{page} => destpage $params{destpage}"); - - unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) { - my $posts = ''; - eval q{use IkiWiki::Plugin::inline}; - error($@) if ($@); - my @args = ( - pages => "internal($params{page}/_comment_*)", - template => "comments_display", - show => 0, - reverse => "yes", - # special stuff passed through - page => $params{page}, - destpage => $params{destpage}, - preview => $params{preview}, - ); - push @args, atom => $params{atom} if defined $params{atom}; - push @args, rss => $params{rss} if defined $params{rss}; - push @args, feeds => $params{feeds} if defined $params{feeds}; - push @args, feedshow => $params{feedshow} if defined $params{feedshow}; - push @args, timeformat => $params{timeformat} if defined $params{timeformat}; - push @args, feedonly => $params{feedonly} if defined $params{feedonly}; - $posts = IkiWiki::preprocess_inline(@args); - $formtemplate->param("comments" => $posts); - } - - return $formtemplate->output; -} # }}} - # FIXME: logic taken from editpage, should be common code? sub getcgiuser ($) { # {{{ my $session = shift; -- cgit v1.2.3 From 9af0f04df3a9c589d63a4f8d95af06098f0474db Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 10 Dec 2008 23:53:04 +0000 Subject: comments: Save comments as a file with one big [[!comment]] directive. This delays all comment formatting until the last possible time, allows us to set metadata without worrying that commenters may be able to evade it, and means that changes to how a comment is saved can be handled gracefully. It also gives us somewhere to put the commenter's username or IP address for later reference. --- IkiWiki/Plugin/comments.pm | 146 +++++++++++++++++++++++++++++----------- templates/comments_comment.tmpl | 24 ------- 2 files changed, 108 insertions(+), 62 deletions(-) delete mode 100644 templates/comments_comment.tmpl (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 73f8d6140..13ced6ffd 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -8,6 +8,7 @@ package IkiWiki::Plugin::comments; use warnings; use strict; use IkiWiki 2.00; +use Encode; use constant PREVIEW => "Preview"; use constant POST_COMMENT => "Post comment"; @@ -16,18 +17,96 @@ use constant CANCEL => "Cancel"; sub import { #{{{ hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); + hook(type => "preprocess", id => 'comment', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); hook(type => "cgi", id => "comments", call => \&linkcgi); - IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("mdwn"); + IkiWiki::loadplugin("inline"); } # }}} sub htmlize { # {{{ - eval q{use IkiWiki::Plugin::mdwn}; - error($@) if ($@); - return IkiWiki::Plugin::mdwn::htmlize(@_) + my %params = @_; + return $params{content}; +} # }}} + +sub preprocess { # {{{ + my %params = @_; + my $page = $params{page}; + + my $format = $params{format}; + if (defined $format && !exists $IkiWiki::hooks{htmlize}{$format}) { + error(sprintf(gettext("unsupported page format %s"), $format)); + } + + my $content = $params{content}; + if (!defined $content) { + error(gettext("comment must have content")); + } + $content =~ s/\\"/"/g; + + $content = IkiWiki::filter($page, $params{destpage}, $content); + + if ($config{comments_allowdirectives}) { + $content = IkiWiki::preprocess($page, $params{destpage}, + $content); + } + + # no need to bother with htmlize if it's just HTML + $content = IkiWiki::htmlize($page, $params{destpage}, $format, + $content) if defined $format; + + IkiWiki::run_hooks(sanitize => sub { + $content = shift->( + page => $page, + destpage => $params{destpage}, + content => $content, + ); + }); + + # override any metadata + + if (defined $params{username}) { + my ($authorurl, $author) = linkuser($params{username}); + $pagestate{$page}{meta}{author} = $author; + $pagestate{$page}{meta}{authorurl} = $authorurl; + } + elsif (defined $params{ip}) { + $pagestate{$page}{meta}{author} = sprintf( + gettext("Anonymous (IP: %s)"), + $params{ip}); + delete $pagestate{$page}{meta}{authorurl}; + } + else { + $pagestate{$page}{meta}{author} = gettext("Anonymous"); + delete $pagestate{$page}{meta}{authorurl}; + } + + if (defined $params{subject}) { + $pagestate{$page}{meta}{title} = $params{subject}; + } + else { + delete $pagestate{$page}{meta}{title}; + } + + my $baseurl = urlto($params{destpage}, undef, 1); + my $anchor = ""; + my $comments_pagename = $config{comments_pagename}; + if ($params{page} =~ m/\/(\Q${comments_pagename}\E\d+)$/) { + $anchor = $1; + } + $pagestate{$page}{meta}{permalink} = "${baseurl}#${anchor}"; + + eval q{use Date::Parse}; + if (! $@) { + my $time = str2time($params{date}); + $IkiWiki::pagectime{$page} = $time if defined $time; + } + + # FIXME: hard-coded HTML (although it's just to set an ID) + return "
$content
" if $anchor; + return $content; } # }}} sub getsetup () { #{{{ @@ -143,9 +222,9 @@ sub linkuser ($) { # {{{ return (IkiWiki::cgiurl( do => 'commenter', page => (length $config{userdir} - ? "$config{userdir}/" - : "") - ).$user, $user); + ? "$config{userdir}/$user" + : "$user") + ), $user); } } # }}} @@ -246,17 +325,6 @@ sub sessioncgi ($$) { #{{{ my $body = $form->field('body') || ''; $body =~ s/\r\n/\n/g; $body =~ s/\r/\n/g; - $body .= "\n" if $body !~ /\n$/; - - unless ($allow_directives) { - # don't allow new-style directives at all - $body =~ s/(^|[^\\])\[\[!/$1[[!/g; - - # don't allow [[ unless it begins an old-style - # wikilink, if prefix_directives is off - $body =~ s/(^|[^\\])\[\[(?![^\n\s\]+]\]\])/$1[[!/g - unless $config{prefix_directives}; - } # FIXME: check that the wiki is locked right now, because # if it's not, there are mad race conditions! @@ -272,27 +340,29 @@ sub sessioncgi ($$) { #{{{ my $anchor = "${comments_pagename}${i}"; - IkiWiki::run_hooks(sanitize => sub { - $body=shift->( - page => $location, - destpage => $location, - content => $body, - ); - }); + $body =~ s/"/\\"/g; + my $content = "[[!comment format=mdwn\n"; + + # FIXME: handling of double quotes probably wrong? + if (defined $session->param('name')) { + my $username = $session->param('name'); + $username =~ s/"/"/g; + $content .= " username=\"$username\"\n"; + } + elsif (defined $ENV{REMOTE_ADDR}) { + my $ip = $ENV{REMOTE_ADDR}; + if ($ip =~ m/^([.0-9]+)$/) { + $content .= " ip=\"$1\"\n"; + } + } + + my $subject = $form->field('subject'); + $subject =~ s/"/"/g; + $content .= " subject=\"$subject\"\n"; + + $content .= " date=\"" . IkiWiki::formattime(time, '%X %x') . "\"\n"; - # In this template, the [[!meta]] directives should stay at the end, - # so that they will override anything the user specifies. (For - # instance, [[!meta author="I can fake the author"]]...) - my $content_tmpl = template('comments_comment.tmpl'); - $content_tmpl->param(author => $author); - $content_tmpl->param(authorurl => $authorurl); - $content_tmpl->param(subject => $form->field('subject')); - $content_tmpl->param(body => $body); - $content_tmpl->param(anchor => "$anchor"); - $content_tmpl->param(permalink => "$baseurl#$anchor"); - $content_tmpl->param(date => IkiWiki::formattime(time, "%X %x")); - - my $content = $content_tmpl->output; + $content .= " content=\"\"\"\n$body\n\"\"\"]]\n"; # This is essentially a simplified version of editpage: # - the user does not control the page that's created, only the parent diff --git a/templates/comments_comment.tmpl b/templates/comments_comment.tmpl deleted file mode 100644 index 8e6affb0d..000000000 --- a/templates/comments_comment.tmpl +++ /dev/null @@ -1,24 +0,0 @@ - -
- - - - -[[!meta title=""]] - - -[[!meta author=""]] - - -[[!meta authorurl=""]] - - -[[!meta permalink=""]] - - -[[!meta date=""]] - - - -
-
-- cgit v1.2.3 From edb69335f2ca5d42c62f6a4cce0b044da5ef88e8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 00:19:39 +0000 Subject: comments: instead of hard-coding mdwn, allow any supported page format --- IkiWiki/Plugin/comments.pm | 24 ++++++++++++++++++------ templates/comments_form.tmpl | 5 +++-- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 13ced6ffd..b45a4a97b 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -22,7 +22,6 @@ sub import { #{{{ hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); hook(type => "cgi", id => "comments", call => \&linkcgi); - IkiWiki::loadplugin("mdwn"); IkiWiki::loadplugin("inline"); } # }}} @@ -243,7 +242,7 @@ sub sessioncgi ($$) { #{{{ my @buttons = (POST_COMMENT, PREVIEW, CANCEL); my $form = CGI::FormBuilder->new( - fields => [qw{do sid page subject body}], + fields => [qw{do sid page subject body type}], charset => 'utf-8', method => 'POST', required => [qw{body}], @@ -264,13 +263,26 @@ sub sessioncgi ($$) { #{{{ }); IkiWiki::decode_form_utf8($form); + my $type = $form->param('type'); + if (defined $type && length $type && $IkiWiki::hooks{htmlize}{$type}) { + $type = possibly_foolish_untaint($type); + } + else { + $type = $config{default_pageext}; + } + my @page_types; + if (exists $IkiWiki::hooks{htmlize}) { + @page_types = grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}; + } + $form->field(name => 'do', type => 'hidden'); $form->field(name => 'sid', type => 'hidden', value => $session->id, force => 1); $form->field(name => 'page', type => 'hidden'); $form->field(name => 'subject', type => 'text', size => 72); - $form->field(name => 'body', type => 'textarea', rows => 5, - cols => 80); + $form->field(name => 'body', type => 'textarea', rows => 10); + $form->field(name => "type", value => $type, force => 1, + type => 'select', options => \@page_types); # The untaint is OK (as in editpage) because we're about to pass # it to file_pruned anyway @@ -341,7 +353,7 @@ sub sessioncgi ($$) { #{{{ my $anchor = "${comments_pagename}${i}"; $body =~ s/"/\\"/g; - my $content = "[[!comment format=mdwn\n"; + my $content = "[[!comment format=$type\n"; # FIXME: handling of double quotes probably wrong? if (defined $session->param('name')) { @@ -371,7 +383,7 @@ sub sessioncgi ($$) { #{{{ # - this means that if they do, rocks fall and everyone dies if ($form->submitted eq PREVIEW) { - my $preview = IkiWiki::htmlize($location, $page, 'mdwn', + my $preview = IkiWiki::htmlize($location, $page, '_comment', IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, IkiWiki::filter($location, diff --git a/templates/comments_form.tmpl b/templates/comments_form.tmpl index 59c03b4f0..e798fcdde 100644 --- a/templates/comments_form.tmpl +++ b/templates/comments_form.tmpl @@ -6,10 +6,11 @@ Subject:

+Page type:


-Formatting with Markdown and HTML are allowed.
-IkiWiki directives ([[!directive]]) are not allowed.
+A subset of HTML is allowed.
+IkiWiki directives ([[!directive]]) are not allowed in comments on this wiki.
-- cgit v1.2.3 From 44a7d77a301a1f219c99f3d861f0bce43cd779cf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 00:22:34 +0000 Subject: comments: rename main field to "editcontent" consistent with editpage This has the side-effect that Ikiwiki's default style.css gives the text box 100% width. --- IkiWiki/Plugin/comments.pm | 16 ++++++++-------- templates/comments_form.tmpl | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index b45a4a97b..46f71e2e7 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -242,10 +242,10 @@ sub sessioncgi ($$) { #{{{ my @buttons = (POST_COMMENT, PREVIEW, CANCEL); my $form = CGI::FormBuilder->new( - fields => [qw{do sid page subject body type}], + fields => [qw{do sid page subject editcontent type}], charset => 'utf-8', method => 'POST', - required => [qw{body}], + required => [qw{editcontent}], javascript => 0, params => $cgi, action => $config{cgiurl}, @@ -280,7 +280,7 @@ sub sessioncgi ($$) { #{{{ force => 1); $form->field(name => 'page', type => 'hidden'); $form->field(name => 'subject', type => 'text', size => 72); - $form->field(name => 'body', type => 'textarea', rows => 10); + $form->field(name => 'editcontent', type => 'textarea', rows => 10); $form->field(name => "type", value => $type, force => 1, type => 'select', options => \@page_types); @@ -334,9 +334,9 @@ sub sessioncgi ($$) { #{{{ my ($authorurl, $author) = linkuser(getcgiuser($session)); - my $body = $form->field('body') || ''; - $body =~ s/\r\n/\n/g; - $body =~ s/\r/\n/g; + my $editcontent = $form->field('editcontent') || ''; + $editcontent =~ s/\r\n/\n/g; + $editcontent =~ s/\r/\n/g; # FIXME: check that the wiki is locked right now, because # if it's not, there are mad race conditions! @@ -352,7 +352,7 @@ sub sessioncgi ($$) { #{{{ my $anchor = "${comments_pagename}${i}"; - $body =~ s/"/\\"/g; + $editcontent =~ s/"/\\"/g; my $content = "[[!comment format=$type\n"; # FIXME: handling of double quotes probably wrong? @@ -374,7 +374,7 @@ sub sessioncgi ($$) { #{{{ $content .= " date=\"" . IkiWiki::formattime(time, '%X %x') . "\"\n"; - $content .= " content=\"\"\"\n$body\n\"\"\"]]\n"; + $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n"; # This is essentially a simplified version of editpage: # - the user does not control the page that's created, only the parent diff --git a/templates/comments_form.tmpl b/templates/comments_form.tmpl index e798fcdde..9eddaadf5 100644 --- a/templates/comments_form.tmpl +++ b/templates/comments_form.tmpl @@ -5,7 +5,7 @@ Subject:
-
+
Page type:


-- cgit v1.2.3 From 0a69c7ed56ea244c62319c7a95ba7cfac9696e27 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 01:24:01 +0000 Subject: comments: Remove some dead code --- IkiWiki/Plugin/comments.pm | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 46f71e2e7..eb915b813 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -168,15 +168,6 @@ sub checkconfig () { #{{{ unless defined $config{comments_pagename}; } #}}} -# FIXME: logic taken from editpage, should be common code? -sub getcgiuser ($) { # {{{ - my $session = shift; - my $user = $session->param('name'); - $user = $ENV{REMOTE_ADDR} unless defined $user; - debug("getcgiuser() -> $user"); - return $user; -} # }}} - # This is exactly the same as recentchanges_link :-( sub linkcgi ($) { #{{{ my $cgi=shift; @@ -332,8 +323,6 @@ sub sessioncgi ($$) { #{{{ IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); - my ($authorurl, $author) = linkuser(getcgiuser($session)); - my $editcontent = $form->field('editcontent') || ''; $editcontent =~ s/\r\n/\n/g; $editcontent =~ s/\r/\n/g; @@ -398,8 +387,6 @@ sub sessioncgi ($$) { #{{{ $template->param(content => $preview); $template->param(title => $form->field('subject')); $template->param(ctime => displaytime(time)); - $template->param(author => $author); - $template->param(authorurl => $authorurl); $form->tmpl_param(page_preview => $template->output); } -- cgit v1.2.3 From a5889912b386eaa43774907c3844c90e3e3ca7c8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 01:33:43 +0000 Subject: comments: Optionally allow anonymous commenters to set their name/URL. Also provide a way for the comment template to pick up the verified username/IP. --- IkiWiki/Plugin/comments.pm | 126 +++++++++++++++++++++++++++++++++++++------ templates/comments_form.tmpl | 8 +++ 2 files changed, 119 insertions(+), 15 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index eb915b813..6bd18a5cf 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -30,6 +30,18 @@ sub htmlize { # {{{ return $params{content}; } # }}} +# FIXME: copied verbatim from meta +sub safeurl ($) { #{{{ + my $url=shift; + if (exists $IkiWiki::Plugin::htmlscrubber::{safe_url_regexp} && + defined $IkiWiki::Plugin::htmlscrubber::safe_url_regexp) { + return $url=~/$IkiWiki::Plugin::htmlscrubber::safe_url_regexp/; + } + else { + return 1; + } +} #}}} + sub preprocess { # {{{ my %params = @_; my $page = $params{page}; @@ -64,29 +76,55 @@ sub preprocess { # {{{ ); }); - # override any metadata + # set metadata, possibly overriding [[!meta]] directives from the + # comment itself + + my $commentuser; + my $commentip; + my $commentauthor; + my $commentauthorurl; if (defined $params{username}) { - my ($authorurl, $author) = linkuser($params{username}); - $pagestate{$page}{meta}{author} = $author; - $pagestate{$page}{meta}{authorurl} = $authorurl; + $commentuser = $params{username}; + ($commentauthorurl, $commentauthor) = + linkuser($params{username}); } elsif (defined $params{ip}) { - $pagestate{$page}{meta}{author} = sprintf( - gettext("Anonymous (IP: %s)"), - $params{ip}); - delete $pagestate{$page}{meta}{authorurl}; + $commentip = $params{ip}; + $commentauthor = sprintf( + gettext("Anonymous (IP: %s)"), $params{ip}); } else { - $pagestate{$page}{meta}{author} = gettext("Anonymous"); - delete $pagestate{$page}{meta}{authorurl}; + $commentauthor = gettext("Anonymous"); } - if (defined $params{subject}) { - $pagestate{$page}{meta}{title} = $params{subject}; + $pagestate{$page}{comments}{commentuser} = $commentuser; + $pagestate{$page}{comments}{commentip} = $commentip; + $pagestate{$page}{comments}{commentauthor} = $commentauthor; + $pagestate{$page}{comments}{commentauthorurl} = $commentauthorurl; + if (!defined $pagestate{$page}{meta}{author}) { + $pagestate{$page}{meta}{author} = $commentauthor; + } + if (!defined $pagestate{$page}{meta}{authorurl}) { + $pagestate{$page}{meta}{authorurl} = $commentauthorurl; + } + + if ($config{comments_allowauthor}) { + if (defined $params{claimedauthor}) { + $pagestate{$page}{meta}{author} = $params{claimedauthor}; + } + + if (defined $params{url} and safeurl($params{url})) { + $pagestate{$page}{meta}{authorurl} = $params{url}; + } } else { - delete $pagestate{$page}{meta}{title}; + $pagestate{$page}{meta}{author} = $commentauthor; + $pagestate{$page}{meta}{authorurl} = $commentauthorurl; + } + + if (defined $params{subject}) { + $pagestate{$page}{meta}{title} = $params{subject}; } my $baseurl = urlto($params{destpage}, undef, 1); @@ -146,7 +184,15 @@ sub getsetup () { #{{{ type => 'boolean', default => 0, example => 0, - description => 'Allow directives in newly posted comments?', + description => 'Interpret directives in comments?', + safe => 1, + rebuild => 0, + }, + comments_allowauthor => { + type => 'boolean', + default => 0, + example => 0, + description => 'Allow anonymous commenters to set an author name?', safe => 1, rebuild => 0, }, @@ -233,7 +279,7 @@ sub sessioncgi ($$) { #{{{ my @buttons = (POST_COMMENT, PREVIEW, CANCEL); my $form = CGI::FormBuilder->new( - fields => [qw{do sid page subject editcontent type}], + fields => [qw{do sid page subject editcontent type author url}], charset => 'utf-8', method => 'POST', required => [qw{editcontent}], @@ -266,6 +312,8 @@ sub sessioncgi ($$) { #{{{ @page_types = grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}; } + my $allow_author = $config{comments_allowauthor}; + $form->field(name => 'do', type => 'hidden'); $form->field(name => 'sid', type => 'hidden', value => $session->id, force => 1); @@ -275,6 +323,21 @@ sub sessioncgi ($$) { #{{{ $form->field(name => "type", value => $type, force => 1, type => 'select', options => \@page_types); + $form->tmpl_param(username => $session->param('name')); + + if ($allow_author and !defined $session->param('name')) { + $form->tmpl_param(allowauthor => 1); + $form->field(name => 'author', type => 'text', size => '40'); + $form->field(name => 'url', type => 'text', size => '40'); + } + else { + $form->tmpl_param(allowauthor => 0); + $form->field(name => 'author', type => 'hidden', value => '', + force => 1); + $form->field(name => 'url', type => 'hidden', value => '', + force => 1); + } + # The untaint is OK (as in editpage) because we're about to pass # it to file_pruned anyway my $page = $form->field('page'); @@ -357,6 +420,19 @@ sub sessioncgi ($$) { #{{{ } } + if ($allow_author) { + my $author = $form->field('author'); + if (length $author) { + $author =~ s/"/"/g; + $content .= " claimedauthor=\"$author\"\n"; + } + my $url = $form->field('url'); + if (length $url) { + $url =~ s/"/"/g; + $content .= " url=\"$url\"\n"; + } + } + my $subject = $form->field('subject'); $subject =~ s/"/"/g; $content .= " subject=\"$subject\"\n"; @@ -496,6 +572,26 @@ sub pagetemplate (@) { #{{{ $template->param(commenturl => $commenturl); } } + + if ($template->query(name => 'commentuser')) { + $template->param(commentuser => + $pagestate{$page}{comments}{commentuser}); + } + + if ($template->query(name => 'commentip')) { + $template->param(commentip => + $pagestate{$page}{comments}{commentip}); + } + + if ($template->query(name => 'commentauthor')) { + $template->param(commentauthor => + $pagestate{$page}{comments}{commentauthor}); + } + + if ($template->query(name => 'commentauthorurl')) { + $template->param(commentauthorurl => + $pagestate{$page}{comments}{commentauthorurl}); + } } # }}} package IkiWiki::PageSpec; diff --git a/templates/comments_form.tmpl b/templates/comments_form.tmpl index 9eddaadf5..88301fcdc 100644 --- a/templates/comments_form.tmpl +++ b/templates/comments_form.tmpl @@ -4,6 +4,14 @@ + +Signed in as
+ + + (optional)
+ (optional)
+
+
Subject:

Page type:
-- cgit v1.2.3 From fbf145ca3ff18985d0885ed939ee63123add9dbd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 02:03:07 +0000 Subject: comments: avoid warning if there's no subject --- IkiWiki/Plugin/comments.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 6bd18a5cf..d1105b366 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -434,8 +434,10 @@ sub sessioncgi ($$) { #{{{ } my $subject = $form->field('subject'); - $subject =~ s/"/"/g; - $content .= " subject=\"$subject\"\n"; + if (length $subject) { + $subject =~ s/"/"/g; + $content .= " subject=\"$subject\"\n"; + } $content .= " date=\"" . IkiWiki::formattime(time, '%X %x') . "\"\n"; -- cgit v1.2.3 From 1698364da0699d1494ee305162e33f48746057c0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 02:22:20 +0000 Subject: comments: fix invocation of possibly_foolish_untaint --- IkiWiki/Plugin/comments.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index d1105b366..4fa82f467 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -302,7 +302,7 @@ sub sessioncgi ($$) { #{{{ my $type = $form->param('type'); if (defined $type && length $type && $IkiWiki::hooks{htmlize}{$type}) { - $type = possibly_foolish_untaint($type); + $type = IkiWiki::possibly_foolish_untaint($type); } else { $type = $config{default_pageext}; -- cgit v1.2.3 From 3560460eb6dad82b7fc81278475433d326ec0628 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 02:29:11 +0000 Subject: comments: don't interpolate IP into anonymous user's "name" If an admin wants the IP in the comment display template they can still get it (the default template shows it). --- IkiWiki/Plugin/comments.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 4fa82f467..e43bbc49e 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -89,12 +89,10 @@ sub preprocess { # {{{ ($commentauthorurl, $commentauthor) = linkuser($params{username}); } - elsif (defined $params{ip}) { - $commentip = $params{ip}; - $commentauthor = sprintf( - gettext("Anonymous (IP: %s)"), $params{ip}); - } else { + if (defined $params{ip}) { + $commentip = $params{ip}; + } $commentauthor = gettext("Anonymous"); } -- cgit v1.2.3 From dd1fa13bce872141442ff134610e4b9175605a4e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 21:19:50 +0000 Subject: comments: Use new feedfile, emptyfeeds options to inline --- IkiWiki/Plugin/comments.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index e43bbc49e..888c9fd9c 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -558,6 +558,8 @@ sub pagetemplate (@) { #{{{ reverse => 'yes', page => $page, destpage => $params{destpage}, + feedfile => 'comments', + emptyfeeds => 'no', ); $comments = IkiWiki::preprocess_inline(@args); } -- cgit v1.2.3 From f2d5ead6af148ab214ceb5f55406a1f0691e4261 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Dec 2008 21:23:55 +0000 Subject: comments: Change internal-use-only directive from [[!comment]] to [[!_comment]] --- IkiWiki/Plugin/comments.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 888c9fd9c..9ea4a3f69 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -17,7 +17,7 @@ use constant CANCEL => "Cancel"; sub import { #{{{ hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); - hook(type => "preprocess", id => 'comment', call => \&preprocess); + hook(type => "preprocess", id => '_comment', call => \&preprocess); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); @@ -403,7 +403,7 @@ sub sessioncgi ($$) { #{{{ my $anchor = "${comments_pagename}${i}"; $editcontent =~ s/"/\\"/g; - my $content = "[[!comment format=$type\n"; + my $content = "[[!_comment format=$type\n"; # FIXME: handling of double quotes probably wrong? if (defined $session->param('name')) { -- cgit v1.2.3 From 8d3a3c6a1e2a5a2be4213c2ce80c02e8f31dc9b4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Dec 2008 17:31:57 -0500 Subject: simplifiy logic --- IkiWiki/Plugin/inline.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 17cc46e0e..d6ef6c54c 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -312,8 +312,7 @@ sub preprocess_inline (@) { #{{{ # emptyfeeds cannot be hidden. $emptyfeeds=1; } - elsif ($feeds && !$params{preview} && - ! (! $emptyfeeds && ! @feedlist)) { + elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) { # Add feed buttons. my $linktemplate=template("feedlink.tmpl", blind_cache => 1); $linktemplate->param(rssurl => $rssurl) if $rss; @@ -390,7 +389,7 @@ sub preprocess_inline (@) { #{{{ } } - if ($feeds && ! (! $emptyfeeds && ! @feedlist)) { + if ($feeds && ($emptyfeeds || @feedlist)) { if ($rss) { my $rssp=$feedbase."rss".$feednum; will_render($params{destpage}, $rssp); -- cgit v1.2.3 From 1942fc3bd652868ab8d6842c2bb2bdf52c0ad9fb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Dec 2008 11:02:41 +0000 Subject: comments: Store dates in GMT and in ISO-8601 The [[!_comment]] directive is a serialization format, not something for presentation to users, so we should use the least ambiguous possible representation. --- IkiWiki/Plugin/comments.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 9ea4a3f69..4ed696026 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -9,6 +9,7 @@ use warnings; use strict; use IkiWiki 2.00; use Encode; +use POSIX qw(strftime); use constant PREVIEW => "Preview"; use constant POST_COMMENT => "Post comment"; @@ -437,7 +438,7 @@ sub sessioncgi ($$) { #{{{ $content .= " subject=\"$subject\"\n"; } - $content .= " date=\"" . IkiWiki::formattime(time, '%X %x') . "\"\n"; + $content .= " date=\"" . decode_utf8(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime)) . "\"\n"; $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n"; -- cgit v1.2.3 From 88e8d4bf8d99b6df83deb680f1ed8685e6447875 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 14:06:45 -0500 Subject: meta: Pass info to htmlscrubber so htmlscrubber_skip can take effect. --- IkiWiki/Plugin/meta.pm | 13 +++--- debian/changelog | 1 + ...ubber__95__skip_setting.___40__patch__41__.mdwn | 53 +--------------------- 3 files changed, 9 insertions(+), 58 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 8d444109f..3991797c0 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -38,9 +38,10 @@ sub needsbuild (@) { #{{{ } } -sub scrub ($) { #{{{ +sub scrub ($$) { #{{{ if (IkiWiki::Plugin::htmlscrubber->can("sanitize")) { - return IkiWiki::Plugin::htmlscrubber::sanitize(content => shift); + return IkiWiki::Plugin::htmlscrubber::sanitize( + content => shift, destpage => shift); } else { return shift; @@ -137,7 +138,7 @@ sub preprocess (@) { #{{{ elsif ($key eq 'permalink') { if (safeurl($value)) { $pagestate{$page}{meta}{permalink}=$value; - push @{$metaheaders{$page}}, scrub(''); + push @{$metaheaders{$page}}, scrub('', $destpage); } } elsif ($key eq 'stylesheet') { @@ -206,7 +207,7 @@ sub preprocess (@) { #{{{ my $delay=int(exists $params{delay} ? $params{delay} : 0); my $redir=""; if (! $safe) { - $redir=scrub($redir); + $redir=scrub($redir, $destpage); } push @{$metaheaders{$page}}, $redir; } @@ -216,7 +217,7 @@ sub preprocess (@) { #{{{ join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params). - " />\n"); + " />\n", $destpage); } } elsif ($key eq 'robots') { @@ -225,7 +226,7 @@ sub preprocess (@) { #{{{ } else { push @{$metaheaders{$page}}, scrub(''); + '" content="'.encode_entities($value).'" />', $destpage); } return ""; diff --git a/debian/changelog b/debian/changelog index 1ff78d749..bf14860dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,7 @@ ikiwiki (2.71) UNRELEASED; urgency=low * inline: Support emptyfeeds=no option to skip generating empty feeds. * inline: Support feedfile option to change the filename of the feed generated. + * meta: Pass info to htmlscrubber so htmlscrubber_skip can take effect. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 diff --git a/doc/bugs/Meta_plugin_does_not_respect_htmlscrubber__95__skip_setting.___40__patch__41__.mdwn b/doc/bugs/Meta_plugin_does_not_respect_htmlscrubber__95__skip_setting.___40__patch__41__.mdwn index 9d67d6662..0e40da551 100644 --- a/doc/bugs/Meta_plugin_does_not_respect_htmlscrubber__95__skip_setting.___40__patch__41__.mdwn +++ b/doc/bugs/Meta_plugin_does_not_respect_htmlscrubber__95__skip_setting.___40__patch__41__.mdwn @@ -8,55 +8,4 @@ Setting htmlscrubber_skip to the pagespec should stop this getting scrubbed but Below is a patch to fix that. It seams to work but I am not sure of it is the correct thing to do. ---- meta.pm 2008-12-11 17:50:33.000000000 +0000 -+++ meta.pm.orig 2008-12-10 17:41:23.000000000 +0000 -@@ -38,9 +38,10 @@ - } - } - --sub scrub (@) { #{{{ -+sub scrub ($) { #{{{ - if (IkiWiki::Plugin::htmlscrubber->can("sanitize")) { -- return IkiWiki::Plugin::htmlscrubber::sanitize(content => shift, destpage => shift); -+ #return IkiWiki::Plugin::htmlscrubber::sanitize(content => shift); -+ return shift; - } - else { - return shift; -@@ -137,7 +138,7 @@ - elsif ($key eq 'permalink') { - if (safeurl($value)) { - $pagestate{$page}{meta}{permalink}=$value; -- push @{$metaheaders{$page}}, scrub('', $page); -+ push @{$metaheaders{$page}}, scrub(''); - } - } - elsif ($key eq 'stylesheet') { -@@ -206,7 +207,7 @@ - my $delay=int(exists $params{delay} ? $params{delay} : 0); - my $redir=""; - if (! $safe) { -- $redir=scrub($redir, $page); -+ $redir=scrub($redir); - } - push @{$metaheaders{$page}}, $redir; - } -@@ -216,7 +217,7 @@ - join(" ", map { - encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" - } keys %params). -- " />\n", $page); -+ " />\n"); - } - } - elsif ($key eq 'robots') { -@@ -225,7 +226,7 @@ - } - else { - push @{$metaheaders{$page}}, scrub('', $page); -+ '" content="'.encode_entities($value).'" />'); - } - - return ""; - +> [[done]], thanks for the patch --[[Joey]] -- cgit v1.2.3 From 473160c947f7c986ac692814190422ad85242346 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 11:25:13 +0000 Subject: htmlbalance: don't compact whitespace, and set misc other options Not compacting whitespace is the most important one: now that we run sanitize hooks on individual posted comments in the comments plugin, whitespace that is significant to Markdown (but not HTML) is lost. (cherry picked from commit cb5aaa3cee8b35d6fc6e88a7449a9477a6587c7a) --- IkiWiki/Plugin/htmlbalance.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm index 3a2d62d15..dcd92055f 100644 --- a/IkiWiki/Plugin/htmlbalance.pm +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -30,7 +30,15 @@ sub sanitize (@) { #{{{ my %params=@_; my $ret = ''; - my $tree = HTML::TreeBuilder->new_from_content($params{content}); + my $tree = HTML::TreeBuilder->new(); + $tree->ignore_unknown(0); + $tree->ignore_ignorable_whitespace(0); + $tree->no_space_compacting(1); + $tree->p_strict(1); + $tree->store_comments(0); + $tree->store_declarations(0); + $tree->store_pis(0); + $tree->parse_content($params{content}); my @nodes = $tree->disembowel(); foreach my $node (@nodes) { if (ref $node) { -- cgit v1.2.3 From 38c92e63bb012da98019faf9bc11037c5cbd5a99 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 14:59:23 -0500 Subject: move getsetup to usual place --- IkiWiki/Plugin/comments.pm | 124 ++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 62 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 4ed696026..8d333f05f 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -26,6 +26,68 @@ sub import { #{{{ IkiWiki::loadplugin("inline"); } # }}} +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => 1, + }, + # Pages where comments are shown, but new comments are not + # allowed, will show "Comments are closed". + comments_shown_pagespec => { + type => 'pagespec', + example => 'blog/*', + default => '', + description => 'PageSpec for pages where comments will be shown inline', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 1, + }, + comments_open_pagespec => { + type => 'pagespec', + example => 'blog/* and created_after(close_old_comments)', + default => '', + description => 'PageSpec for pages where new comments can be posted', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 1, + }, + comments_pagename => { + type => 'string', + example => 'comment_', + default => 'comment_', + description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"', + safe => 0, # manual page moving required + rebuild => undef, + }, + comments_allowdirectives => { + type => 'boolean', + default => 0, + example => 0, + description => 'Interpret directives in comments?', + safe => 1, + rebuild => 0, + }, + comments_allowauthor => { + type => 'boolean', + default => 0, + example => 0, + description => 'Allow anonymous commenters to set an author name?', + safe => 1, + rebuild => 0, + }, + comments_commit => { + type => 'boolean', + example => 1, + default => 1, + description => 'commit comments to the VCS', + # old uncommitted comments are likely to cause + # confusion if this is changed + safe => 0, + rebuild => 0, + }, +} #}}} + sub htmlize { # {{{ my %params = @_; return $params{content}; @@ -145,68 +207,6 @@ sub preprocess { # {{{ return $content; } # }}} -sub getsetup () { #{{{ - return - plugin => { - safe => 1, - rebuild => 1, - }, - # Pages where comments are shown, but new comments are not - # allowed, will show "Comments are closed". - comments_shown_pagespec => { - type => 'pagespec', - example => 'blog/*', - default => '', - description => 'PageSpec for pages where comments will be shown inline', - link => 'ikiwiki/PageSpec', - safe => 1, - rebuild => 1, - }, - comments_open_pagespec => { - type => 'pagespec', - example => 'blog/* and created_after(close_old_comments)', - default => '', - description => 'PageSpec for pages where new comments can be posted', - link => 'ikiwiki/PageSpec', - safe => 1, - rebuild => 1, - }, - comments_pagename => { - type => 'string', - example => 'comment_', - default => 'comment_', - description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"', - safe => 0, # manual page moving will required - rebuild => undef, - }, - comments_allowdirectives => { - type => 'boolean', - default => 0, - example => 0, - description => 'Interpret directives in comments?', - safe => 1, - rebuild => 0, - }, - comments_allowauthor => { - type => 'boolean', - default => 0, - example => 0, - description => 'Allow anonymous commenters to set an author name?', - safe => 1, - rebuild => 0, - }, - comments_commit => { - type => 'boolean', - example => 1, - default => 1, - description => 'commit comments to the VCS', - # old uncommitted comments are likely to cause - # confusion if this is changed - safe => 0, - rebuild => 0, - }, -} #}}} - sub checkconfig () { #{{{ $config{comments_commit} = 1 unless defined $config{comments_commit}; $config{comments_pagename} = 'comment_' -- cgit v1.2.3 From 0ced5995d531ed108a2eec8cee7a3586cd757add Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:05:26 -0500 Subject: get rid of the [postcomment] hack I think that using a flag variable is sorta cleaner. (This is untested.) --- IkiWiki/Plugin/comments.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 8d333f05f..0de7a6743 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -15,6 +15,8 @@ use constant PREVIEW => "Preview"; use constant POST_COMMENT => "Post comment"; use constant CANCEL => "Cancel"; +my $postcomment; + sub import { #{{{ hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); @@ -383,7 +385,11 @@ sub sessioncgi ($$) { #{{{ $page)); } - IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); + # Set a flag to indicate that we're posting a comment, + # so that postcomment() can tell it should match. + $postcomment=1; + IkiWiki::check_canedit($page, $cgi, $session); + $postcomment=0; my $editcontent = $form->field('editcontent') || ''; $editcontent =~ s/\r\n/\n/g; @@ -603,7 +609,7 @@ sub match_postcomment ($$;@) { my $page = shift; my $glob = shift; - unless ($page =~ s/\[postcomment\]$//) { + if (! $postcomment) { return IkiWiki::FailReason->new("not posting a comment"); } return match_glob($page, $glob); -- cgit v1.2.3 From 2a7849b8385c21dfa8a6f764a5e2cf8ea5f97070 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:08:06 -0500 Subject: avoid unnecessary variable --- IkiWiki/Plugin/comments.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 0de7a6743..f612f8947 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -558,7 +558,7 @@ sub pagetemplate (@) { #{{{ eval q{use IkiWiki::Plugin::inline}; error($@) if $@; - my @args = ( + $comments = IkiWiki::preprocess_inline( pages => "internal($page/${comments_pagename}*)", template => 'comments_display', show => 0, @@ -568,7 +568,6 @@ sub pagetemplate (@) { #{{{ feedfile => 'comments', emptyfeeds => 'no', ); - $comments = IkiWiki::preprocess_inline(@args); } if (defined $comments && length $comments) { -- cgit v1.2.3 From 18eeb068a6be7e45add2775a4014c85e3b41b465 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:10:17 -0500 Subject: don't explicitly use inline loadplugin("inline") should take care of that --- IkiWiki/Plugin/comments.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index f612f8947..4999c3f24 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -555,9 +555,6 @@ sub pagetemplate (@) { #{{{ } if ($shown) { - eval q{use IkiWiki::Plugin::inline}; - error($@) if $@; - $comments = IkiWiki::preprocess_inline( pages => "internal($page/${comments_pagename}*)", template => 'comments_display', -- cgit v1.2.3 From f3735891cad0ca00f72ca4c68d444ca61382ad4b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:13:07 -0500 Subject: whitespace --- IkiWiki/Plugin/comments.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 4999c3f24..6c8952d45 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -112,12 +112,12 @@ sub preprocess { # {{{ my $page = $params{page}; my $format = $params{format}; - if (defined $format && !exists $IkiWiki::hooks{htmlize}{$format}) { + if (defined $format && ! exists $IkiWiki::hooks{htmlize}{$format}) { error(sprintf(gettext("unsupported page format %s"), $format)); } my $content = $params{content}; - if (!defined $content) { + if (! defined $content) { error(gettext("comment must have content")); } $content =~ s/\\"/"/g; @@ -165,10 +165,10 @@ sub preprocess { # {{{ $pagestate{$page}{comments}{commentip} = $commentip; $pagestate{$page}{comments}{commentauthor} = $commentauthor; $pagestate{$page}{comments}{commentauthorurl} = $commentauthorurl; - if (!defined $pagestate{$page}{meta}{author}) { + if (! defined $pagestate{$page}{meta}{author}) { $pagestate{$page}{meta}{author} = $commentauthor; } - if (!defined $pagestate{$page}{meta}{authorurl}) { + if (! defined $pagestate{$page}{meta}{authorurl}) { $pagestate{$page}{meta}{authorurl} = $commentauthorurl; } @@ -221,7 +221,7 @@ sub linkcgi ($) { #{{{ if (defined $cgi->param('do') && $cgi->param('do') eq "commenter") { my $page=decode_utf8($cgi->param("page")); - if (!defined $page) { + if (! defined $page) { error("missing page parameter"); } @@ -310,7 +310,7 @@ sub sessioncgi ($$) { #{{{ } my @page_types; if (exists $IkiWiki::hooks{htmlize}) { - @page_types = grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}; + @page_types = grep { ! /^_/ } keys %{$IkiWiki::hooks{htmlize}}; } my $allow_author = $config{comments_allowauthor}; @@ -326,7 +326,7 @@ sub sessioncgi ($$) { #{{{ $form->tmpl_param(username => $session->param('name')); - if ($allow_author and !defined $session->param('name')) { + if ($allow_author and ! defined $session->param('name')) { $form->tmpl_param(allowauthor => 1); $form->field(name => 'author', type => 'text', size => '40'); $form->field(name => 'url', type => 'text', size => '40'); @@ -343,7 +343,7 @@ sub sessioncgi ($$) { #{{{ # it to file_pruned anyway my $page = $form->field('page'); $page = IkiWiki::possibly_foolish_untaint($page); - if (!defined $page || !length $page || + if (! defined $page || ! length $page || IkiWiki::file_pruned($page, $config{srcdir})) { error(gettext("bad page name")); } -- cgit v1.2.3 From 9557c7c8905f08361aabd1215fa3bc19badf9a4f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:19:01 -0500 Subject: move related code together --- IkiWiki/Plugin/comments.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 6c8952d45..c458ea9da 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -391,10 +391,6 @@ sub sessioncgi ($$) { #{{{ IkiWiki::check_canedit($page, $cgi, $session); $postcomment=0; - my $editcontent = $form->field('editcontent') || ''; - $editcontent =~ s/\r\n/\n/g; - $editcontent =~ s/\r/\n/g; - # FIXME: check that the wiki is locked right now, because # if it's not, there are mad race conditions! @@ -409,7 +405,6 @@ sub sessioncgi ($$) { #{{{ my $anchor = "${comments_pagename}${i}"; - $editcontent =~ s/"/\\"/g; my $content = "[[!_comment format=$type\n"; # FIXME: handling of double quotes probably wrong? @@ -446,6 +441,10 @@ sub sessioncgi ($$) { #{{{ $content .= " date=\"" . decode_utf8(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime)) . "\"\n"; + my $editcontent = $form->field('editcontent') || ''; + $editcontent =~ s/\r\n/\n/g; + $editcontent =~ s/\r/\n/g; + $editcontent =~ s/"/\\"/g; $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n"; # This is essentially a simplified version of editpage: -- cgit v1.2.3 From 928f6938d25c1d72ab81d75e8b67ab32e45df89c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:22:43 -0500 Subject: fix redefinition of $author --- IkiWiki/Plugin/comments.pm | 2 -- 1 file changed, 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index c458ea9da..972d069d5 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -403,8 +403,6 @@ sub sessioncgi ($$) { #{{{ $location = "$page/${comments_pagename}${i}"; } while (-e "$config{srcdir}/$location._comment"); - my $anchor = "${comments_pagename}${i}"; - my $content = "[[!_comment format=$type\n"; # FIXME: handling of double quotes probably wrong? -- cgit v1.2.3 From ef972a871bd61295068d7a105036924699c65540 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:25:12 -0500 Subject: remove fixme sessioncgi hooks are always called with the wiki locked --- IkiWiki/Plugin/comments.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 972d069d5..273561cad 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -391,9 +391,6 @@ sub sessioncgi ($$) { #{{{ IkiWiki::check_canedit($page, $cgi, $session); $postcomment=0; - # FIXME: check that the wiki is locked right now, because - # if it's not, there are mad race conditions! - # FIXME: rather a simplistic way to make the comments... my $i = 0; my $file; -- cgit v1.2.3 From 15ec55eff58d056704b7911d8ed3975a4f09d65c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Dec 2008 15:38:23 -0500 Subject: elide unnecessary variables --- IkiWiki/Plugin/comments.pm | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 273561cad..1eb256da9 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -192,8 +192,7 @@ sub preprocess { # {{{ my $baseurl = urlto($params{destpage}, undef, 1); my $anchor = ""; - my $comments_pagename = $config{comments_pagename}; - if ($params{page} =~ m/\/(\Q${comments_pagename}\E\d+)$/) { + if ($params{page} =~ m/\/(\Q$config{comments_pagename}\E\d+)$/) { $anchor = $1; } $pagestate{$page}{meta}{permalink} = "${baseurl}#${anchor}"; @@ -313,8 +312,6 @@ sub sessioncgi ($$) { #{{{ @page_types = grep { ! /^_/ } keys %{$IkiWiki::hooks{htmlize}}; } - my $allow_author = $config{comments_allowauthor}; - $form->field(name => 'do', type => 'hidden'); $form->field(name => 'sid', type => 'hidden', value => $session->id, force => 1); @@ -326,7 +323,8 @@ sub sessioncgi ($$) { #{{{ $form->tmpl_param(username => $session->param('name')); - if ($allow_author and ! defined $session->param('name')) { + if ($config{comments_allowauthor} and + ! defined $session->param('name')) { $form->tmpl_param(allowauthor => 1); $form->field(name => 'author', type => 'text', size => '40'); $form->field(name => 'url', type => 'text', size => '40'); @@ -348,10 +346,6 @@ sub sessioncgi ($$) { #{{{ error(gettext("bad page name")); } - my $allow_directives = $config{comments_allowdirectives}; - my $commit_comments = $config{comments_commit}; - my $comments_pagename = $config{comments_pagename}; - # FIXME: is this right? Or should we be using the candidate subpage # (whatever that might mean) as the base URL? my $baseurl = urlto($page, undef, 1); @@ -363,7 +357,7 @@ sub sessioncgi ($$) { #{{{ htmllink($page, $page, 'ikiwiki/formatting', noimageinline => 1, linktext => 'FormattingHelp'), - allowdirectives => $allow_directives); + allowdirectives => $config{allow_directives}); if ($form->submitted eq CANCEL) { # bounce back to the page they wanted to comment on, and exit. @@ -397,7 +391,7 @@ sub sessioncgi ($$) { #{{{ my $location; do { $i++; - $location = "$page/${comments_pagename}${i}"; + $location = "$page/$config{comments_pagename}$i"; } while (-e "$config{srcdir}/$location._comment"); my $content = "[[!_comment format=$type\n"; @@ -415,7 +409,7 @@ sub sessioncgi ($$) { #{{{ } } - if ($allow_author) { + if ($config{comments_allowauthor}) { my $author = $form->field('author'); if (length $author) { $author =~ s/"/"/g; @@ -482,7 +476,7 @@ sub sessioncgi ($$) { #{{{ my $conflict; - if ($config{rcs} and $commit_comments) { + if ($config{rcs} and $config{comments_commit}) { my $message = gettext("Added a comment"); if (defined $form->field('subject') && length $form->field('subject')) { @@ -509,7 +503,7 @@ sub sessioncgi ($$) { #{{{ error($conflict) if defined $conflict; # Bounce back to where we were, but defeat broken caches - my $anticache = "?updated=$page/${comments_pagename}${i}"; + my $anticache = "?updated=$page/$config{comments_pagename}$i"; IkiWiki::redirect($cgi, urlto($page, undef, 1).$anticache); } else { @@ -529,14 +523,12 @@ sub pagetemplate (@) { #{{{ if ($template->query(name => 'comments')) { my $comments = undef; - my $comments_pagename = $config{comments_pagename}; - my $open = 0; my $shown = pagespec_match($page, $config{comments_shown_pagespec}, location => $page); - if (pagespec_match($page, "*/${comments_pagename}*", + if (pagespec_match($page, "*/$config{comments_pagename}*", location => $page)) { $shown = 0; $open = 0; @@ -550,7 +542,7 @@ sub pagetemplate (@) { #{{{ if ($shown) { $comments = IkiWiki::preprocess_inline( - pages => "internal($page/${comments_pagename}*)", + pages => "internal($page/$config{comments_pagename}*)", template => 'comments_display', show => 0, reverse => 'yes', -- cgit v1.2.3 From b2366f764b799522c323730eee34d99afc70cad1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 13:56:10 -0500 Subject: rename: Fix double-escaping of page name in edit box. titlepage normally escapes, but so does formbuilder. --- IkiWiki/Plugin/rename.pm | 2 +- debian/changelog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index 7e55e271c..e4201cc94 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -111,7 +111,7 @@ sub rename_form ($$$) { #{{{ $f->field(name => "do", type => "hidden", value => "rename", force => 1); $f->field(name => "page", type => "hidden", value => $page, force => 1); - $f->field(name => "new_name", value => pagetitle($page), size => 60); + $f->field(name => "new_name", value => pagetitle($page, 1), size => 60); if (!$q->param("attachment")) { # insert the standard extensions my @page_types; diff --git a/debian/changelog b/debian/changelog index 76f00157d..b43144b36 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,7 @@ ikiwiki (2.71) UNRELEASED; urgency=low generated. * meta: Pass info to htmlscrubber so htmlscrubber_skip can take effect. * htmlbalance: don't compact whitespace, and set misc other options (smcv) + * rename: Fix double-escaping of page name in edit box. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 -- cgit v1.2.3 From f9b87a9f8b498f3a41614b159dcb278024be70dd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 13:59:12 -0500 Subject: monotone: When getting the log, tell monotone how many entries we want, rather than closing the pipe, which it dislikes. (thm) --- IkiWiki/Plugin/monotone.pm | 5 ++--- debian/changelog | 2 ++ ...mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index f31a8606b..3a8b267a3 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -525,13 +525,12 @@ sub rcs_recentchanges ($) { #{{{ my $child = open(MTNLOG, "-|"); if (! $child) { exec("mtn", "log", "--root=$config{mtnrootdir}", "--no-graph", - "--brief") || error("mtn log failed to run"); + "--brief", "--last=$num") || error("mtn log failed to run"); } - while (($num >= 0) and (my $line = )) { + while (my $line = ) { if ($line =~ m/^($sha1_pattern)/) { push @revs, $1; - $num -= 1; } } close MTNLOG || debug("mtn log exited $?"); diff --git a/debian/changelog b/debian/changelog index b43144b36..8f5783208 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,8 @@ ikiwiki (2.71) UNRELEASED; urgency=low * meta: Pass info to htmlscrubber so htmlscrubber_skip can take effect. * htmlbalance: don't compact whitespace, and set misc other options (smcv) * rename: Fix double-escaping of page name in edit box. + * monotone: When getting the log, tell monotone how many entries + we want, rather than closing the pipe, which it dislikes. (thm) -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 diff --git a/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn b/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn index 2167deac4..aa13ec339 100644 --- a/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn +++ b/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn @@ -19,3 +19,6 @@ When using monotone as revision control system, a "mtn: operation canceled: Brok } } close MTNLOG || debug("mtn log exited $?"); + +> Thanks for the patch, and for testing the monotone backend. +> applied [[done]] --[[Joey]] -- cgit v1.2.3 From 985b229be632126f376aaad7bd354d0d7d014464 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 14:26:08 -0500 Subject: checksessionexpiry: rework This function as factored out was a bit confusing, I think this makes more sense. --- IkiWiki/CGI.pm | 14 ++++++++------ IkiWiki/Plugin/comments.pm | 2 +- IkiWiki/Plugin/editpage.pm | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index a3486cbb4..a45e12e31 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -36,7 +36,7 @@ sub showform ($$$$;@) { #{{{ printheader($session); print misctemplate($form->title, $form->render(submit => $buttons), @_); -} +} #}}} sub redirect ($$) { #{{{ my $q=shift; @@ -273,7 +273,7 @@ sub check_banned ($$) { #{{{ exit; } } -} +} #}}} sub cgi_getsession ($) { #{{{ my $q=shift; @@ -296,14 +296,16 @@ sub cgi_getsession ($) { #{{{ return $session; } #}}} -# The session id is stored on the form and checked to -# guard against CSRF. But only if the user is logged in, -# as anonok can allow anonymous edits. +# To guard against CSRF, the user's session id (sid) +# can be stored on a form. This function will check +# (for logged in users) that the sid on the form matches +# the session id in the cookie. sub checksessionexpiry ($$) { # {{{ + my $q=shift; my $session = shift; - my $sid = shift; if (defined $session->param("name")) { + my $sid=$q->param('sid'); if (! defined $sid || $sid ne $session->id) { error(gettext("Your login session has expired.")); } diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 1eb256da9..b8748a1d6 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -468,7 +468,7 @@ sub sessioncgi ($$) { #{{{ if ($form->submitted eq POST_COMMENT && $form->validate) { my $file = "$location._comment"; - IkiWiki::checksessionexpiry($session, $cgi->param('sid')); + IkiWiki::checksessionexpiry($cgi, $session); # FIXME: could probably do some sort of graceful retry # on error? Would require significant unwinding though diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index e4f0cdac0..242624d77 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -340,7 +340,7 @@ sub cgi_editpage ($$) { #{{{ else { # save page check_canedit($page, $q, $session); - checksessionexpiry($session, $q->param('sid')); + checksessionexpiry($q, $session, $q->param('sid')); my $exists=-e "$config{srcdir}/$file"; -- cgit v1.2.3 From bb93fccf0690344aa77f9538a508959a6de09847 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 15:22:16 -0500 Subject: Coding style change: Remove explcit vim folding markers. --- IkiWiki.pm | 388 ++++++++++----------- IkiWiki/CGI.pm | 60 ++-- IkiWiki/Plugin/aggregate.pm | 108 +++--- IkiWiki/Plugin/amazon_s3.pm | 32 +- IkiWiki/Plugin/anonok.pm | 12 +- IkiWiki/Plugin/attachment.pm | 32 +- IkiWiki/Plugin/autoindex.pm | 16 +- IkiWiki/Plugin/brokenlinks.pm | 12 +- IkiWiki/Plugin/bzr.pm | 54 +-- IkiWiki/Plugin/calendar.pm | 30 +- IkiWiki/Plugin/camelcase.pm | 14 +- IkiWiki/Plugin/color.pm | 20 +- IkiWiki/Plugin/comments.pm | 38 +- IkiWiki/Plugin/conditional.pm | 28 +- IkiWiki/Plugin/creole.pm | 12 +- IkiWiki/Plugin/cutpaste.pm | 20 +- IkiWiki/Plugin/ddate.pm | 12 +- IkiWiki/Plugin/editdiff.pm | 16 +- IkiWiki/Plugin/editpage.pm | 16 +- IkiWiki/Plugin/edittemplate.pm | 24 +- IkiWiki/Plugin/embed.pm | 20 +- IkiWiki/Plugin/external.pm | 48 +-- IkiWiki/Plugin/favicon.pm | 12 +- IkiWiki/Plugin/filecheck.pm | 30 +- IkiWiki/Plugin/format.pm | 8 +- IkiWiki/Plugin/fortune.pm | 12 +- IkiWiki/Plugin/git.pm | 72 ++-- IkiWiki/Plugin/goodstuff.pm | 8 +- IkiWiki/Plugin/google.pm | 16 +- IkiWiki/Plugin/googlecalendar.pm | 20 +- IkiWiki/Plugin/graphviz.pm | 16 +- IkiWiki/Plugin/haiku.pm | 12 +- IkiWiki/Plugin/hnb.pm | 12 +- IkiWiki/Plugin/html.pm | 12 +- IkiWiki/Plugin/htmlbalance.pm | 12 +- IkiWiki/Plugin/htmlscrubber.pm | 16 +- IkiWiki/Plugin/htmltidy.pm | 12 +- IkiWiki/Plugin/httpauth.pm | 12 +- IkiWiki/Plugin/img.pm | 12 +- IkiWiki/Plugin/inline.pm | 54 +-- IkiWiki/Plugin/link.pm | 24 +- IkiWiki/Plugin/linkmap.pm | 20 +- IkiWiki/Plugin/listdirectives.pm | 20 +- IkiWiki/Plugin/lockedit.pm | 16 +- IkiWiki/Plugin/map.pm | 12 +- IkiWiki/Plugin/mdwn.pm | 12 +- IkiWiki/Plugin/mercurial.pm | 52 +-- IkiWiki/Plugin/meta.pm | 52 +-- IkiWiki/Plugin/mirrorlist.pm | 16 +- IkiWiki/Plugin/monotone.pm | 72 ++-- IkiWiki/Plugin/more.pm | 10 +- IkiWiki/Plugin/norcs.pm | 48 +-- IkiWiki/Plugin/opendiscussion.pm | 12 +- IkiWiki/Plugin/openid.pm | 28 +- IkiWiki/Plugin/orphans.pm | 12 +- IkiWiki/Plugin/otl.pm | 16 +- IkiWiki/Plugin/pagecount.pm | 12 +- IkiWiki/Plugin/pagestats.pm | 12 +- IkiWiki/Plugin/pagetemplate.pm | 16 +- IkiWiki/Plugin/parentlinks.pm | 16 +- IkiWiki/Plugin/passwordauth.pm | 26 +- IkiWiki/Plugin/pingee.pm | 12 +- IkiWiki/Plugin/pinger.pm | 16 +- IkiWiki/Plugin/poll.pm | 16 +- IkiWiki/Plugin/polygen.pm | 12 +- IkiWiki/Plugin/postsparkline.pm | 12 +- IkiWiki/Plugin/prettydate.pm | 16 +- IkiWiki/Plugin/progress.pm | 16 +- IkiWiki/Plugin/rawhtml.pm | 8 +- IkiWiki/Plugin/recentchanges.pm | 30 +- IkiWiki/Plugin/recentchangesdiff.pm | 12 +- IkiWiki/Plugin/relativedate.pm | 20 +- IkiWiki/Plugin/remove.pm | 34 +- IkiWiki/Plugin/rename.pm | 48 +-- IkiWiki/Plugin/search.pm | 40 +-- IkiWiki/Plugin/shortcut.pm | 20 +- IkiWiki/Plugin/sidebar.pm | 16 +- IkiWiki/Plugin/signinedit.pm | 12 +- IkiWiki/Plugin/skeleton.pm.example | 102 +++--- IkiWiki/Plugin/smiley.pm | 16 +- IkiWiki/Plugin/sparkline.pm | 12 +- IkiWiki/Plugin/svn.pm | 54 +-- IkiWiki/Plugin/table.pm | 26 +- IkiWiki/Plugin/tag.pm | 32 +- IkiWiki/Plugin/template.pm | 12 +- IkiWiki/Plugin/testpagespec.pm | 12 +- IkiWiki/Plugin/teximg.pm | 32 +- IkiWiki/Plugin/textile.pm | 12 +- IkiWiki/Plugin/tla.pm | 46 +-- IkiWiki/Plugin/toc.pm | 14 +- IkiWiki/Plugin/toggle.pm | 28 +- IkiWiki/Plugin/txt.pm | 4 +- IkiWiki/Plugin/typography.pm | 16 +- IkiWiki/Plugin/version.pm | 16 +- IkiWiki/Plugin/websetup.pm | 36 +- IkiWiki/Plugin/wikitext.pm | 12 +- IkiWiki/Receive.pm | 16 +- IkiWiki/Render.pm | 34 +- IkiWiki/Setup.pm | 12 +- IkiWiki/Setup/Automator.pm | 12 +- IkiWiki/Setup/Standard.pm | 16 +- IkiWiki/UserInfo.pm | 32 +- IkiWiki/Wrapper.pm | 4 +- debian/changelog | 1 + .../Allow_overriding_of_symlink_restriction.mdwn | 6 +- doc/bugs/Can__39__t_create_root_page.mdwn | 4 +- ...dency_in_eval_while_running_with_-T_switch.mdwn | 4 +- doc/bugs/Monotone_rcs_support.mdwn | 2 +- ..._blog_items_when_filename_contains_a_colon.mdwn | 8 +- doc/bugs/Problem_with_toc.pm_plug-in.mdwn | 4 +- doc/bugs/Problems_with_graphviz.pm_plug-in.mdwn | 14 +- .../RecentChanges_broken_with_empty_svnpath.mdwn | 2 +- ...itles_are_lower-cased_when_creating_a_page.mdwn | 2 +- ...n_and_a_directive_does_not_contain_a_space.mdwn | 4 +- ...celed:_Broken_pipe__34_____40__patch__41__.mdwn | 2 +- doc/bugs/git_stderr_output_causes_problems.mdwn | 2 +- ...plugin_should_pass_through_class_attribute.mdwn | 4 +- doc/bugs/inline_sort-by-title_issues.mdwn | 2 +- doc/bugs/mercurial_fail_to_add.mdwn | 2 +- doc/bugs/methodResponse_in_add__95__plugins.mdwn | 2 +- doc/bugs/multiple_pages_with_same_name.mdwn | 6 +- ...pec_parsing_chokes_on_function__40____41__.mdwn | 2 +- doc/bugs/prune_causing_taint_mode_failures.mdwn | 4 +- doc/bugs/quieten_mercurial.mdwn | 4 +- ..._for_locale_data_in_the_installed_location.mdwn | 2 +- doc/bugs/tbasewiki__95__brokenlinks.t_broken.mdwn | 6 +- doc/plugins/contrib/headinganchors.mdwn | 8 +- doc/plugins/contrib/siterel2pagerel.mdwn | 8 +- doc/plugins/contrib/unixauth.mdwn | 24 +- .../Add_DATE_parameter_for_use_in_templates.mdwn | 14 +- ...for_latest_Text::Markdown_as_found_on_CPAN.mdwn | 2 +- doc/todo/Allow_change_of_wiki_file_types.mdwn | 8 +- doc/todo/Allow_edittemplate_to_set_file_type.mdwn | 8 +- .../Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn | 8 +- doc/todo/Default_text_for_new_pages.mdwn | 8 +- ..._templates_inserted_by_the_template_plugin.mdwn | 2 +- ...nline_plugin_option_to_show_full_page_path.mdwn | 2 +- .../Move_teximg_latex_preamble_to_config_file.mdwn | 10 +- ...bitrary_date_to_be_used_by_calendar_plugin.mdwn | 12 +- doc/todo/Silence_monotone_warning.mdwn | 2 +- ...side_of_link__40____41___within_a_pagespec.mdwn | 4 +- doc/todo/Wrapper_config_with_multiline_regexp.mdwn | 4 +- .../add_forward_age_sorting_option_to_inline.mdwn | 2 +- .../discussion.mdwn | 20 +- doc/todo/blogpost_plugin.mdwn | 20 +- doc/todo/bzr.mdwn | 28 +- doc/todo/cas_authentication.mdwn | 14 +- doc/todo/color_plugin.mdwn | 20 +- doc/todo/darcs.mdwn | 26 +- doc/todo/datearchives-plugin.mdwn | 8 +- doc/todo/different_search_engine.mdwn | 40 +-- doc/todo/directive_docs.mdwn | 12 +- doc/todo/enable-htaccess-files.mdwn | 2 +- doc/todo/format_escape.mdwn | 16 +- .../fortune:_select_options_via_environment.mdwn | 4 +- doc/todo/index.html_allowed.mdwn | 10 +- doc/todo/inline:_numerical_ordering_by_title.mdwn | 22 +- .../language_definition_for_the_meta_plugin.mdwn | 4 +- doc/todo/meta_rcsid.mdwn | 2 +- doc/todo/missingparents.pm.mdwn | 44 +-- doc/todo/modify_page_filename_in_plugin.mdwn | 6 +- doc/todo/pagespec_relative_to_a_target.mdwn | 16 +- doc/todo/provide_sha1_for_git_diffurl.mdwn | 2 +- doc/todo/require_CAPTCHA_to_edit.mdwn | 22 +- doc/todo/source_link.mdwn | 14 +- doc/todo/structured_page_data.mdwn | 50 +-- .../supporting_comments_via_disussion_pages.mdwn | 12 +- doc/todo/syntax_highlighting.mdwn | 4 +- doc/todo/tidy_git__39__s_ctime_debug_output.mdwn | 2 +- doc/todo/tmplvars_plugin.mdwn | 12 +- doc/todo/tracking_bugs_with_dependencies.mdwn | 58 +-- ...turn_edittemplate_verbosity_off_by_default.mdwn | 6 +- doc/todo/using_meta_titles_for_parentlinks.html | 8 +- ...closures_for_values__41___in_ikiwiki.setup.mdwn | 8 +- ikiwiki.in | 12 +- 175 files changed, 1776 insertions(+), 1775 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki.pm b/IkiWiki.pm index 1c68c2cb3..d93ff7374 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -34,7 +34,7 @@ memoize("abs2rel"); memoize("pagespec_translate"); memoize("file_pruned"); -sub getsetup () { #{{{ +sub getsetup () { wikiname => { type => "string", default => "wiki", @@ -431,9 +431,9 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, -} #}}} +} -sub defaultconfig () { #{{{ +sub defaultconfig () { my %s=getsetup(); my @ret; foreach my $key (keys %s) { @@ -441,9 +441,9 @@ sub defaultconfig () { #{{{ } use Data::Dumper; return @ret; -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { # locale stuff; avoid LC_ALL since it overrides everything if (defined $ENV{LC_ALL}) { $ENV{LANG} = $ENV{LC_ALL}; @@ -490,9 +490,9 @@ sub checkconfig () { #{{{ run_hooks(checkconfig => sub { shift->() }); return 1; -} #}}} +} -sub listplugins () { #{{{ +sub listplugins () { my %ret; foreach my $dir (@INC, $config{libdir}) { @@ -510,9 +510,9 @@ sub listplugins () { #{{{ } return keys %ret; -} #}}} +} -sub loadplugins () { #{{{ +sub loadplugins () { if (defined $config{libdir} && length $config{libdir}) { unshift @INC, possibly_foolish_untaint($config{libdir}); } @@ -539,9 +539,9 @@ sub loadplugins () { #{{{ } return 1; -} #}}} +} -sub loadplugin ($) { #{{{ +sub loadplugin ($) { my $plugin=shift; return if grep { $_ eq $plugin} @{$config{disable_plugins}}; @@ -567,9 +567,9 @@ sub loadplugin ($) { #{{{ } $loaded_plugins{$plugin}=1; return 1; -} #}}} +} -sub error ($;$) { #{{{ +sub error ($;$) { my $message=shift; my $cleaner=shift; log_message('err' => $message) if $config{syslog}; @@ -577,15 +577,15 @@ sub error ($;$) { #{{{ $cleaner->(); } die $message."\n"; -} #}}} +} -sub debug ($) { #{{{ +sub debug ($) { return unless $config{verbose}; return log_message(debug => @_); -} #}}} +} my $log_open=0; -sub log_message ($$) { #{{{ +sub log_message ($$) { my $type=shift; if ($config{syslog}) { @@ -605,44 +605,44 @@ sub log_message ($$) { #{{{ else { return print STDERR "@_\n"; } -} #}}} +} -sub possibly_foolish_untaint ($) { #{{{ +sub possibly_foolish_untaint ($) { my $tainted=shift; my ($untainted)=$tainted=~/(.*)/s; return $untainted; -} #}}} +} -sub basename ($) { #{{{ +sub basename ($) { my $file=shift; $file=~s!.*/+!!; return $file; -} #}}} +} -sub dirname ($) { #{{{ +sub dirname ($) { my $file=shift; $file=~s!/*[^/]+$!!; return $file; -} #}}} +} -sub pagetype ($) { #{{{ +sub pagetype ($) { my $page=shift; if ($page =~ /\.([^.]+)$/) { return $1 if exists $hooks{htmlize}{$1}; } return; -} #}}} +} -sub isinternal ($) { #{{{ +sub isinternal ($) { my $page=shift; return exists $pagesources{$page} && $pagesources{$page} =~ /\._([^.]+)$/; -} #}}} +} -sub pagename ($) { #{{{ +sub pagename ($) { my $file=shift; my $type=pagetype($file); @@ -652,9 +652,9 @@ sub pagename ($) { #{{{ $page=$1; } return $page; -} #}}} +} -sub newpagefile ($$) { #{{{ +sub newpagefile ($$) { my $page=shift; my $type=shift; @@ -664,9 +664,9 @@ sub newpagefile ($$) { #{{{ else { return $page."/index.".$type; } -} #}}} +} -sub targetpage ($$;$) { #{{{ +sub targetpage ($$;$) { my $page=shift; my $ext=shift; my $filename=shift; @@ -680,15 +680,15 @@ sub targetpage ($$;$) { #{{{ else { return $page."/index.".$ext; } -} #}}} +} -sub htmlpage ($) { #{{{ +sub htmlpage ($) { my $page=shift; return targetpage($page, $config{htmlext}); -} #}}} +} -sub srcfile_stat { #{{{ +sub srcfile_stat { my $file=shift; my $nothrow=shift; @@ -698,13 +698,13 @@ sub srcfile_stat { #{{{ } error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow; return; -} #}}} +} -sub srcfile ($;$) { #{{{ +sub srcfile ($;$) { return (srcfile_stat(@_))[0]; -} #}}} +} -sub add_underlay ($) { #{{{ +sub add_underlay ($) { my $dir=shift; if ($dir !~ /^\//) { @@ -716,9 +716,9 @@ sub add_underlay ($) { #{{{ } return 1; -} #}}} +} -sub readfile ($;$$) { #{{{ +sub readfile ($;$$) { my $file=shift; my $binary=shift; my $wantfd=shift; @@ -738,9 +738,9 @@ sub readfile ($;$$) { #{{{ } close $in || error("failed to read $file: $!"); return $ret; -} #}}} +} -sub prep_writefile ($$) { #{{{ +sub prep_writefile ($$) { my $file=shift; my $destdir=shift; @@ -764,9 +764,9 @@ sub prep_writefile ($$) { #{{{ } return 1; -} #}}} +} -sub writefile ($$$;$$) { #{{{ +sub writefile ($$$;$$) { my $file=shift; # can include subdirs my $destdir=shift; # directory to put file in my $content=shift; @@ -794,10 +794,10 @@ sub writefile ($$$;$$) { #{{{ error("failed renaming $newfile to $destdir/$file: $!", $cleanup); return 1; -} #}}} +} my %cleared; -sub will_render ($$;$) { #{{{ +sub will_render ($$;$) { my $page=shift; my $dest=shift; my $clear=shift; @@ -821,9 +821,9 @@ sub will_render ($$;$) { #{{{ $destsources{$dest}=$page; return 1; -} #}}} +} -sub bestlink ($$) { #{{{ +sub bestlink ($$) { my $page=shift; my $link=shift; @@ -859,15 +859,15 @@ sub bestlink ($$) { #{{{ #print STDERR "warning: page $page, broken link: $link\n"; return ""; -} #}}} +} -sub isinlinableimage ($) { #{{{ +sub isinlinableimage ($) { my $file=shift; return $file =~ /\.(png|gif|jpg|jpeg)$/i; -} #}}} +} -sub pagetitle ($;$) { #{{{ +sub pagetitle ($;$) { my $page=shift; my $unescaped=shift; @@ -879,31 +879,31 @@ sub pagetitle ($;$) { #{{{ } return $page; -} #}}} +} -sub titlepage ($) { #{{{ +sub titlepage ($) { my $title=shift; # support use w/o %config set my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_"; $title=~s/([^$chars]|_)/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; return $title; -} #}}} +} -sub linkpage ($) { #{{{ +sub linkpage ($) { my $link=shift; my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_"; $link=~s/([^$chars])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; return $link; -} #}}} +} -sub cgiurl (@) { #{{{ +sub cgiurl (@) { my %params=@_; return $config{cgiurl}."?". join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params); -} #}}} +} -sub baseurl (;$) { #{{{ +sub baseurl (;$) { my $page=shift; return "$config{url}/" if ! defined $page; @@ -912,9 +912,9 @@ sub baseurl (;$) { #{{{ $page=~s/[^\/]+$//; $page=~s/[^\/]+\//..\//g; return $page; -} #}}} +} -sub abs2rel ($$) { #{{{ +sub abs2rel ($$) { # Work around very innefficient behavior in File::Spec if abs2rel # is passed two relative paths. It's much faster if paths are # absolute! (Debian bug #376658; fixed in debian unstable now) @@ -925,15 +925,15 @@ sub abs2rel ($$) { #{{{ my $ret=File::Spec->abs2rel($path, $base); $ret=~s/^// if defined $ret; return $ret; -} #}}} +} -sub displaytime ($;$) { #{{{ +sub displaytime ($;$) { # Plugins can override this function to mark up the time to # display. return ''.formattime(@_).''; -} #}}} +} -sub formattime ($;$) { #{{{ +sub formattime ($;$) { # Plugins can override this function to format the time. my $time=shift; my $format=shift; @@ -944,9 +944,9 @@ sub formattime ($;$) { #{{{ # strftime doesn't know about encodings, so make sure # its output is properly treated as utf8 return decode_utf8(POSIX::strftime($format, localtime($time))); -} #}}} +} -sub beautify_urlpath ($) { #{{{ +sub beautify_urlpath ($) { my $url=shift; if ($config{usedirs}) { @@ -960,9 +960,9 @@ sub beautify_urlpath ($) { #{{{ } return $url; -} #}}} +} -sub urlto ($$;$) { #{{{ +sub urlto ($$;$) { my $to=shift; my $from=shift; my $absolute=shift; @@ -982,9 +982,9 @@ sub urlto ($$;$) { #{{{ my $link = abs2rel($to, dirname(htmlpage($from))); return beautify_urlpath($link); -} #}}} +} -sub htmllink ($$$;@) { #{{{ +sub htmllink ($$$;@) { my $lpage=shift; # the page doing the linking my $page=shift; # the page that will contain the link (different for inline) my $link=shift; @@ -1047,9 +1047,9 @@ sub htmllink ($$$;@) { #{{{ } return "$linktext"; -} #}}} +} -sub userlink ($) { #{{{ +sub userlink ($) { my $user=shift; my $oiduser=eval { openiduser($user) }; @@ -1064,9 +1064,9 @@ sub userlink ($) { #{{{ length $config{userdir} ? $config{userdir}."/".$user : $user ), noimageinline => 1); } -} #}}} +} -sub htmlize ($$$$) { #{{{ +sub htmlize ($$$$) { my $page=shift; my $destpage=shift; my $type=shift; @@ -1101,9 +1101,9 @@ sub htmlize ($$$$) { #{{{ } return $content; -} #}}} +} -sub linkify ($$$) { #{{{ +sub linkify ($$$) { my $page=shift; my $destpage=shift; my $content=shift; @@ -1117,11 +1117,11 @@ sub linkify ($$$) { #{{{ }); return $content; -} #}}} +} our %preprocessing; our $preprocess_preview=0; -sub preprocess ($$$;$$) { #{{{ +sub preprocess ($$$;$$) { my $page=shift; # the page the data comes from my $destpage=shift; # the page the data will appear in (different for inline) my $content=shift; @@ -1274,9 +1274,9 @@ sub preprocess ($$$;$$) { #{{{ $content =~ s{$regex}{$handle->($1, $2, $3, $4)}eg; return $content; -} #}}} +} -sub filter ($$$) { #{{{ +sub filter ($$$) { my $page=shift; my $destpage=shift; my $content=shift; @@ -1287,15 +1287,15 @@ sub filter ($$$) { #{{{ }); return $content; -} #}}} +} -sub indexlink () { #{{{ +sub indexlink () { return "$config{wikiname}"; -} #}}} +} my $wikilock; -sub lockwiki () { #{{{ +sub lockwiki () { # Take an exclusive lock on the wiki to prevent multiple concurrent # run issues. The lock will be dropped on program exit. if (! -d $config{wikistatedir}) { @@ -1307,17 +1307,17 @@ sub lockwiki () { #{{{ error("failed to get lock"); } return 1; -} #}}} +} -sub unlockwiki () { #{{{ +sub unlockwiki () { POSIX::close($ENV{IKIWIKI_CGILOCK_FD}) if exists $ENV{IKIWIKI_CGILOCK_FD}; return close($wikilock) if $wikilock; return; -} #}}} +} my $commitlock; -sub commit_hook_enabled () { #{{{ +sub commit_hook_enabled () { open($commitlock, '+>', "$config{wikistatedir}/commitlock") || error("cannot write to $config{wikistatedir}/commitlock: $!"); if (! flock($commitlock, 1 | 4)) { # LOCK_SH | LOCK_NB to test @@ -1326,23 +1326,23 @@ sub commit_hook_enabled () { #{{{ } close($commitlock) || error("failed closing commitlock: $!"); return 1; -} #}}} +} -sub disable_commit_hook () { #{{{ +sub disable_commit_hook () { open($commitlock, '>', "$config{wikistatedir}/commitlock") || error("cannot write to $config{wikistatedir}/commitlock: $!"); if (! flock($commitlock, 2)) { # LOCK_EX error("failed to get commit lock"); } return 1; -} #}}} +} -sub enable_commit_hook () { #{{{ +sub enable_commit_hook () { return close($commitlock) if $commitlock; return; -} #}}} +} -sub loadindex () { #{{{ +sub loadindex () { %oldrenderedfiles=%pagectime=(); if (! $config{rebuild}) { %pagesources=%pagemtime=%oldlinks=%links=%depends= @@ -1402,9 +1402,9 @@ sub loadindex () { #{{{ $destsources{$_}=$page foreach @{$renderedfiles{$page}}; } return close($in); -} #}}} +} -sub saveindex () { #{{{ +sub saveindex () { run_hooks(savestate => sub { shift->() }); my %hookids; @@ -1460,18 +1460,18 @@ sub saveindex () { #{{{ error("failed renaming $newfile to $config{wikistatedir}/indexdb", $cleanup); return 1; -} #}}} +} -sub template_file ($) { #{{{ +sub template_file ($) { my $template=shift; foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") { return "$dir/$template" if -e "$dir/$template"; } return; -} #}}} +} -sub template_params (@) { #{{{ +sub template_params (@) { my $filename=template_file(shift); if (! defined $filename) { @@ -1490,14 +1490,14 @@ sub template_params (@) { #{{{ @_ ); return wantarray ? @ret : {@ret}; -} #}}} +} -sub template ($;@) { #{{{ +sub template ($;@) { require HTML::Template; return HTML::Template->new(template_params(@_)); -} #}}} +} -sub misctemplate ($$;@) { #{{{ +sub misctemplate ($$;@) { my $title=shift; my $pagebody=shift; @@ -1514,9 +1514,9 @@ sub misctemplate ($$;@) { #{{{ shift->(page => "", destpage => "", template => $template); }); return $template->output; -}#}}} +} -sub hook (@) { # {{{ +sub hook (@) { my %param=@_; if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) { @@ -1527,9 +1527,9 @@ sub hook (@) { # {{{ $hooks{$param{type}}{$param{id}}=\%param; return 1; -} # }}} +} -sub run_hooks ($$) { # {{{ +sub run_hooks ($$) { # Calls the given sub for each hook of the given type, # passing it the hook function to call. my $type=shift; @@ -1550,53 +1550,53 @@ sub run_hooks ($$) { # {{{ } return 1; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { $hooks{rcs}{rcs_update}{call}->(@_); -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { $hooks{rcs}{rcs_prepedit}{call}->(@_); -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { $hooks{rcs}{rcs_commit}{call}->(@_); -} #}}} +} -sub rcs_commit_staged ($$$) { #{{{ +sub rcs_commit_staged ($$$) { $hooks{rcs}{rcs_commit_staged}{call}->(@_); -} #}}} +} -sub rcs_add ($) { #{{{ +sub rcs_add ($) { $hooks{rcs}{rcs_add}{call}->(@_); -} #}}} +} -sub rcs_remove ($) { #{{{ +sub rcs_remove ($) { $hooks{rcs}{rcs_remove}{call}->(@_); -} #}}} +} -sub rcs_rename ($$) { #{{{ +sub rcs_rename ($$) { $hooks{rcs}{rcs_rename}{call}->(@_); -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { $hooks{rcs}{rcs_recentchanges}{call}->(@_); -} #}}} +} -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { $hooks{rcs}{rcs_diff}{call}->(@_); -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { $hooks{rcs}{rcs_getctime}{call}->(@_); -} #}}} +} -sub rcs_receive () { #{{{ +sub rcs_receive () { $hooks{rcs}{rcs_receive}{call}->(); -} #}}} +} -sub globlist_to_pagespec ($) { #{{{ +sub globlist_to_pagespec ($) { my @globlist=split(' ', shift); my (@spec, @skip); @@ -1620,20 +1620,20 @@ sub globlist_to_pagespec ($) { #{{{ } } return $spec; -} #}}} +} -sub is_globlist ($) { #{{{ +sub is_globlist ($) { my $s=shift; return ( $s =~ /[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or" ); -} #}}} +} -sub safequote ($) { #{{{ +sub safequote ($) { my $s=shift; $s=~s/[{}]//g; return "q{$s}"; -} #}}} +} -sub add_depends ($$) { #{{{ +sub add_depends ($$) { my $page=shift; my $pagespec=shift; @@ -1647,9 +1647,9 @@ sub add_depends ($$) { #{{{ } return 1; -} # }}} +} -sub file_pruned ($$) { #{{{ +sub file_pruned ($$) { require File::Spec; my $file=File::Spec->canonpath(shift); my $base=File::Spec->canonpath(shift); @@ -1657,9 +1657,9 @@ sub file_pruned ($$) { #{{{ my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')'; return $file =~ m/$regexp/ && $file ne $base; -} #}}} +} -sub gettext { #{{{ +sub gettext { # Only use gettext in the rare cases it's needed. if ((exists $ENV{LANG} && length $ENV{LANG}) || (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) || @@ -1680,15 +1680,15 @@ sub gettext { #{{{ else { return shift; } -} #}}} +} -sub yesno ($) { #{{{ +sub yesno ($) { my $val=shift; return (defined $val && lc($val) eq gettext("yes")); -} #}}} +} -sub inject { #{{{ +sub inject { # Injects a new function into the symbol table to replace an # exported function. my %params=@_; @@ -1711,9 +1711,9 @@ sub inject { #{{{ } use strict; use warnings; -} #}}} +} -sub pagespec_merge ($$) { #{{{ +sub pagespec_merge ($$) { my $a=shift; my $b=shift; @@ -1728,9 +1728,9 @@ sub pagespec_merge ($$) { #{{{ } return "($a) or ($b)"; -} #}}} +} -sub pagespec_translate ($) { #{{{ +sub pagespec_translate ($) { my $spec=shift; # Support for old-style GlobLists. @@ -1784,9 +1784,9 @@ sub pagespec_translate ($) { #{{{ no warnings; return eval 'sub { my $page=shift; '.$code.' }'; -} #}}} +} -sub pagespec_match ($$;@) { #{{{ +sub pagespec_match ($$;@) { my $page=shift; my $spec=shift; my @params=@_; @@ -1799,55 +1799,55 @@ sub pagespec_match ($$;@) { #{{{ my $sub=pagespec_translate($spec); return IkiWiki::FailReason->new("syntax error in pagespec \"$spec\"") if $@; return $sub->($page, @params); -} #}}} +} -sub pagespec_valid ($) { #{{{ +sub pagespec_valid ($) { my $spec=shift; my $sub=pagespec_translate($spec); return ! $@; -} #}}} +} -sub glob2re ($) { #{{{ +sub glob2re ($) { my $re=quotemeta(shift); $re=~s/\\\*/.*/g; $re=~s/\\\?/./g; return $re; -} #}}} +} package IkiWiki::FailReason; -use overload ( #{{{ +use overload ( '""' => sub { ${$_[0]} }, '0+' => sub { 0 }, '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'}, fallback => 1, -); #}}} +); -sub new { #{{{ +sub new { my $class = shift; my $value = shift; return bless \$value, $class; -} #}}} +} package IkiWiki::SuccessReason; -use overload ( #{{{ +use overload ( '""' => sub { ${$_[0]} }, '0+' => sub { 1 }, '!' => sub { bless $_[0], 'IkiWiki::FailReason'}, fallback => 1, -); #}}} +); -sub new { #{{{ +sub new { my $class = shift; my $value = shift; return bless \$value, $class; -}; #}}} +}; package IkiWiki::PageSpec; -sub match_glob ($$;@) { #{{{ +sub match_glob ($$;@) { my $page=shift; my $glob=shift; my %params=@_; @@ -1873,13 +1873,13 @@ sub match_glob ($$;@) { #{{{ else { return IkiWiki::FailReason->new("$glob does not match $page"); } -} #}}} +} -sub match_internal ($$;@) { #{{{ +sub match_internal ($$;@) { return match_glob($_[0], $_[1], @_, internal => 1) -} #}}} +} -sub match_link ($$;@) { #{{{ +sub match_link ($$;@) { my $page=shift; my $link=lc(shift); my %params=@_; @@ -1911,13 +1911,13 @@ sub match_link ($$;@) { #{{{ } } return IkiWiki::FailReason->new("$page does not link to $link"); -} #}}} +} -sub match_backlink ($$;@) { #{{{ +sub match_backlink ($$;@) { return match_link($_[1], $_[0], @_); -} #}}} +} -sub match_created_before ($$;@) { #{{{ +sub match_created_before ($$;@) { my $page=shift; my $testpage=shift; @@ -1932,9 +1932,9 @@ sub match_created_before ($$;@) { #{{{ else { return IkiWiki::FailReason->new("$testpage has no ctime"); } -} #}}} +} -sub match_created_after ($$;@) { #{{{ +sub match_created_after ($$;@) { my $page=shift; my $testpage=shift; @@ -1949,36 +1949,36 @@ sub match_created_after ($$;@) { #{{{ else { return IkiWiki::FailReason->new("$testpage has no ctime"); } -} #}}} +} -sub match_creation_day ($$;@) { #{{{ +sub match_creation_day ($$;@) { if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) { return IkiWiki::SuccessReason->new('creation_day matched'); } else { return IkiWiki::FailReason->new('creation_day did not match'); } -} #}}} +} -sub match_creation_month ($$;@) { #{{{ +sub match_creation_month ($$;@) { if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) { return IkiWiki::SuccessReason->new('creation_month matched'); } else { return IkiWiki::FailReason->new('creation_month did not match'); } -} #}}} +} -sub match_creation_year ($$;@) { #{{{ +sub match_creation_year ($$;@) { if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) { return IkiWiki::SuccessReason->new('creation_year matched'); } else { return IkiWiki::FailReason->new('creation_year did not match'); } -} #}}} +} -sub match_user ($$;@) { #{{{ +sub match_user ($$;@) { shift; my $user=shift; my %params=@_; @@ -1996,9 +1996,9 @@ sub match_user ($$;@) { #{{{ else { return IkiWiki::FailReason->new("user is $params{user}, not $user"); } -} #}}} +} -sub match_admin ($$;@) { #{{{ +sub match_admin ($$;@) { shift; shift; my %params=@_; @@ -2016,9 +2016,9 @@ sub match_admin ($$;@) { #{{{ else { return IkiWiki::FailReason->new("user is not an admin"); } -} #}}} +} -sub match_ip ($$;@) { #{{{ +sub match_ip ($$;@) { shift; my $ip=shift; my %params=@_; @@ -2033,6 +2033,6 @@ sub match_ip ($$;@) { #{{{ else { return IkiWiki::FailReason->new("IP is $params{ip}, not $ip"); } -} #}}} +} 1 diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index a45e12e31..81cb42d13 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -9,7 +9,7 @@ use IkiWiki::UserInfo; use open qw{:utf8 :std}; use Encode; -sub printheader ($) { #{{{ +sub printheader ($) { my $session=shift; if ($config{sslcookie}) { @@ -19,9 +19,9 @@ sub printheader ($) { #{{{ print $session->header(-charset => 'utf-8', -cookie => $session->cookie(-httponly => 1)); } -} #}}} +} -sub showform ($$$$;@) { #{{{ +sub showform ($$$$;@) { my $form=shift; my $buttons=shift; my $session=shift; @@ -36,9 +36,9 @@ sub showform ($$$$;@) { #{{{ printheader($session); print misctemplate($form->title, $form->render(submit => $buttons), @_); -} #}}} +} -sub redirect ($$) { #{{{ +sub redirect ($$) { my $q=shift; my $url=shift; if (! $config{w3mmode}) { @@ -48,9 +48,9 @@ sub redirect ($$) { #{{{ print "Content-type: text/plain\n"; print "W3m-control: GOTO $url\n\n"; } -} #}}} +} -sub decode_cgi_utf8 ($) { #{{{ +sub decode_cgi_utf8 ($) { # decode_form_utf8 method is needed for 5.10 if ($] < 5.01) { my $cgi = shift; @@ -58,9 +58,9 @@ sub decode_cgi_utf8 ($) { #{{{ $cgi->param($f, map { decode_utf8 $_ } $cgi->param($f)); } } -} #}}} +} -sub decode_form_utf8 ($) { #{{{ +sub decode_form_utf8 ($) { if ($] >= 5.01) { my $form = shift; foreach my $f ($form->field) { @@ -70,11 +70,11 @@ sub decode_form_utf8 ($) { #{{{ ); } } -} #}}} +} # Check if the user is signed in. If not, redirect to the signin form and # save their place to return to later. -sub needsignin ($$) { #{{{ +sub needsignin ($$) { my $q=shift; my $session=shift; @@ -85,9 +85,9 @@ sub needsignin ($$) { #{{{ cgi_savesession($session); exit; } -} #}}} +} -sub cgi_signin ($$) { #{{{ +sub cgi_signin ($$) { my $q=shift; my $session=shift; @@ -127,9 +127,9 @@ sub cgi_signin ($$) { #{{{ } showform($form, $buttons, $session, $q); -} #}}} +} -sub cgi_postsignin ($$) { #{{{ +sub cgi_postsignin ($$) { my $q=shift; my $session=shift; @@ -144,9 +144,9 @@ sub cgi_postsignin ($$) { #{{{ else { error(gettext("login failed, perhaps you need to turn on cookies?")); } -} #}}} +} -sub cgi_prefs ($$) { #{{{ +sub cgi_prefs ($$) { my $q=shift; my $session=shift; @@ -254,9 +254,9 @@ sub cgi_prefs ($$) { #{{{ } showform($form, $buttons, $session, $q); -} #}}} +} -sub check_banned ($$) { #{{{ +sub check_banned ($$) { my $q=shift; my $session=shift; @@ -273,9 +273,9 @@ sub check_banned ($$) { #{{{ exit; } } -} #}}} +} -sub cgi_getsession ($) { #{{{ +sub cgi_getsession ($) { my $q=shift; eval q{use CGI::Session; use HTML::Entities}; @@ -294,13 +294,13 @@ sub cgi_getsession ($) { #{{{ umask($oldmask); return $session; -} #}}} +} # To guard against CSRF, the user's session id (sid) # can be stored on a form. This function will check # (for logged in users) that the sid on the form matches # the session id in the cookie. -sub checksessionexpiry ($$) { # {{{ +sub checksessionexpiry ($$) { my $q=shift; my $session = shift; @@ -310,18 +310,18 @@ sub checksessionexpiry ($$) { # {{{ error(gettext("Your login session has expired.")); } } -} # }}} +} -sub cgi_savesession ($) { #{{{ +sub cgi_savesession ($) { my $session=shift; # Force session flush with safe umask. my $oldmask=umask(077); $session->flush; umask($oldmask); -} #}}} +} -sub cgi (;$$) { #{{{ +sub cgi (;$$) { my $q=shift; my $session=shift; @@ -391,16 +391,16 @@ sub cgi (;$$) { #{{{ else { error("unknown do parameter"); } -} #}}} +} # Does not need to be called directly; all errors will go through here. -sub cgierror ($) { #{{{ +sub cgierror ($) { my $message=shift; print "Content-type: text/html\n\n"; print misctemplate(gettext("Error"), "

".gettext("Error").": $message

"); die $@; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index adaa619ab..29bc6d0ce 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -14,7 +14,7 @@ use open qw{:utf8 :std}; my %feeds; my %guids; -sub import { #{{{ +sub import { hook(type => "getopt", id => "aggregate", call => \&getopt); hook(type => "getsetup", id => "aggregate", call => \&getsetup); hook(type => "checkconfig", id => "aggregate", call => \&checkconfig); @@ -26,9 +26,9 @@ sub import { #{{{ if (exists $config{aggregate_webtrigger} && $config{aggregate_webtrigger}) { hook(type => "cgi", id => "aggregate", call => \&cgi); } -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); @@ -36,9 +36,9 @@ sub getopt () { #{{{ "aggregate" => \$config{aggregate}, "aggregateinternal!" => \$config{aggregateinternal}, ); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -58,16 +58,16 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if ($config{aggregate} && ! ($config{post_commit} && IkiWiki::commit_hook_enabled())) { launchaggregation(); } -} #}}} +} -sub cgi ($) { #{{{ +sub cgi ($) { my $cgi=shift; if (defined $cgi->param('do') && @@ -90,9 +90,9 @@ sub cgi ($) { #{{{ } exit 0; } -} #}}} +} -sub launchaggregation () { #{{{ +sub launchaggregation () { # See if any feeds need aggregation. loadstate(); my @feeds=needsaggregate(); @@ -135,16 +135,16 @@ sub launchaggregation () { #{{{ unlockaggregate(); return 1; -} #}}} +} # Pages with extension _aggregated have plain html markup, pass through. -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; return $params{content}; -} #}}} +} # Used by ikiwiki-transition aggregateinternal. -sub migrate_to_internal { #{{{ +sub migrate_to_internal { if (! lockaggregate()) { error("an aggregation process is currently running"); } @@ -190,9 +190,9 @@ sub migrate_to_internal { #{{{ IkiWiki::unlockwiki; unlockaggregate(); -} #}}} +} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; loadstate(); @@ -206,9 +206,9 @@ sub needsbuild (@) { #{{{ markunseen($feed->{sourcepage}); } } -} # }}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; foreach my $required (qw{name url}) { @@ -265,9 +265,9 @@ sub preprocess (@) { #{{{ ($feed->{newposts} ? "; ".$feed->{newposts}. " ".gettext("new") : ""). ")"; -} # }}} +} -sub delete (@) { #{{{ +sub delete (@) { my @files=@_; # Remove feed data for removed pages. @@ -275,9 +275,9 @@ sub delete (@) { #{{{ my $page=pagename($file); markunseen($page); } -} #}}} +} -sub markunseen ($) { #{{{ +sub markunseen ($) { my $page=shift; foreach my $id (keys %feeds) { @@ -285,11 +285,11 @@ sub markunseen ($) { #{{{ $feeds{$id}->{unseen}=1; } } -} #}}} +} my $state_loaded=0; -sub loadstate () { #{{{ +sub loadstate () { return if $state_loaded; $state_loaded=1; if (-e "$config{wikistatedir}/aggregate") { @@ -323,9 +323,9 @@ sub loadstate () { #{{{ close IN; } -} #}}} +} -sub savestate () { #{{{ +sub savestate () { return unless $state_loaded; garbage_collect(); my $newfile="$config{wikistatedir}/aggregate.new"; @@ -350,9 +350,9 @@ sub savestate () { #{{{ close OUT || error("save $newfile: $!", $cleanup); rename($newfile, "$config{wikistatedir}/aggregate") || error("rename $newfile: $!", $cleanup); -} #}}} +} -sub garbage_collect () { #{{{ +sub garbage_collect () { foreach my $name (keys %feeds) { # remove any feeds that were not seen while building the pages # that used to contain them @@ -375,9 +375,9 @@ sub garbage_collect () { #{{{ delete $guid->{md5}; } } -} #}}} +} -sub mergestate () { #{{{ +sub mergestate () { # Load the current state in from disk, and merge into it # values from the state in memory that might have changed # during aggregation. @@ -407,15 +407,15 @@ sub mergestate () { #{{{ $guids{$guid}=$myguids{$guid}; } } -} #}}} +} -sub clearstate () { #{{{ +sub clearstate () { %feeds=(); %guids=(); $state_loaded=0; -} #}}} +} -sub expire () { #{{{ +sub expire () { foreach my $feed (values %feeds) { next unless $feed->{expireage} || $feed->{expirecount}; my $count=0; @@ -444,14 +444,14 @@ sub expire () { #{{{ } } } -} #}}} +} -sub needsaggregate () { #{{{ +sub needsaggregate () { return values %feeds if $config{rebuild}; return grep { time - $_->{lastupdate} >= $_->{updateinterval} } values %feeds; -} #}}} +} -sub aggregate (@) { #{{{ +sub aggregate (@) { eval q{use XML::Feed}; error($@) if $@; eval q{use URI::Fetch}; @@ -542,9 +542,9 @@ sub aggregate (@) { #{{{ ); } } -} #}}} +} -sub add_page (@) { #{{{ +sub add_page (@) { my %params=@_; my $feed=$params{feed}; @@ -635,21 +635,21 @@ sub add_page (@) { #{{{ # Dummy value for expiry code. $IkiWiki::pagectime{$guid->{page}}=time; } -} #}}} +} -sub wikiescape ($) { #{{{ +sub wikiescape ($) { # escape accidental wikilinks and preprocessor stuff return encode_entities(shift, '\[\]'); -} #}}} +} -sub urlabs ($$) { #{{{ +sub urlabs ($$) { my $url=shift; my $urlbase=shift; URI->new_abs($url, $urlbase)->as_string; -} #}}} +} -sub htmlabs ($$) { #{{{ +sub htmlabs ($$) { # Convert links in html from relative to absolute. # Note that this is a heuristic, which is not specified by the rss # spec and may not be right for all feeds. Also, see Debian @@ -685,15 +685,15 @@ sub htmlabs ($$) { #{{{ $p->eof; return $ret; -} #}}} +} -sub htmlfn ($) { #{{{ +sub htmlfn ($) { return shift().".".($config{aggregateinternal} ? "_aggregated" : $config{htmlext}); -} #}}} +} my $aggregatelock; -sub lockaggregate () { #{{{ +sub lockaggregate () { # Take an exclusive lock to prevent multiple concurrent aggregators. # Returns true if the lock was aquired. if (! -d $config{wikistatedir}) { @@ -706,11 +706,11 @@ sub lockaggregate () { #{{{ return 0; } return 1; -} #}}} +} -sub unlockaggregate () { #{{{ +sub unlockaggregate () { return close($aggregatelock) if $aggregatelock; return; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/amazon_s3.pm b/IkiWiki/Plugin/amazon_s3.pm index 597539c13..93c10b629 100644 --- a/IkiWiki/Plugin/amazon_s3.pm +++ b/IkiWiki/Plugin/amazon_s3.pm @@ -16,13 +16,13 @@ BEGIN { } }; -sub import { #{{{ +sub import { hook(type => "getopt", id => "amazon_s3", call => \&getopt); hook(type => "getsetup", id => "amazon_s3", call => \&getsetup); hook(type => "checkconfig", id => "amazon_s3", call => \&checkconfig); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); @@ -38,9 +38,9 @@ sub getopt () { #{{{ debug(gettext("done")); exit(0); }); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, @@ -88,9 +88,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub checkconfig { #{{{ +sub checkconfig { foreach my $field (qw{amazon_s3_key_id amazon_s3_key_file amazon_s3_bucket}) { if (! exists $config{$field} || ! defined $config{$field}) { @@ -101,11 +101,11 @@ sub checkconfig { #{{{ ! defined $config{amazon_s3_prefix}) { $config{amazon_s3_prefix}="wiki/"; } -} #}}} +} { my $bucket; -sub getbucket { #{{{ +sub getbucket { return $bucket if defined $bucket; open(IN, "<", $config{amazon_s3_key_file}) || error($config{amazon_s3_key_file}.": ".$!); @@ -138,11 +138,11 @@ sub getbucket { #{{{ } return $bucket; -} #}}} +} } # Given a file, return any S3 keys associated with it. -sub file2keys ($) { #{{{ +sub file2keys ($) { my $file=shift; my @keys; @@ -162,14 +162,14 @@ sub file2keys ($) { #{{{ } } return @keys; -} #}}} +} package IkiWiki; use File::MimeInfo; use Encode; # This is a wrapper around the real writefile. -sub writefile ($$$;$$) { #{{{ +sub writefile ($$$;$$) { my $file=shift; my $destdir=shift; my $content=shift; @@ -225,10 +225,10 @@ sub writefile ($$$;$$) { #{{{ } return $ret; -} #}}} +} # This is a wrapper around the real prune. -sub prune ($) { #{{{ +sub prune ($) { my $file=shift; my @keys=IkiWiki::Plugin::amazon_s3::file2keys($file); @@ -247,6 +247,6 @@ sub prune ($) { #{{{ } return $IkiWiki::Plugin::amazon_s3::subs{'IkiWiki::prune'}->($file); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/anonok.pm b/IkiWiki/Plugin/anonok.pm index 2be983693..1cbdfe4e5 100644 --- a/IkiWiki/Plugin/anonok.pm +++ b/IkiWiki/Plugin/anonok.pm @@ -5,12 +5,12 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "anonok", call => \&getsetup); hook(type => "canedit", id => "anonok", call => \&canedit); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -24,9 +24,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub canedit ($$$) { #{{{ +sub canedit ($$$) { my $page=shift; my $cgi=shift; my $session=shift; @@ -45,6 +45,6 @@ sub canedit ($$$) { #{{{ else { return ""; } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 44781165c..87da6cd4e 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -5,16 +5,16 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { add_underlay("javascript"); hook(type => "getsetup", id => "attachment", call => \&getsetup); hook(type => "checkconfig", id => "attachment", call => \&checkconfig); hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup); hook(type => "formbuilder", id => "attachment", call => \&formbuilder); IkiWiki::loadplugin("filecheck"); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -35,9 +35,9 @@ sub getsetup () { #{{{ safe => 0, # executed rebuild => 0, }, -} #}}} +} -sub check_canattach ($$;$) { #{{{ +sub check_canattach ($$;$) { my $session=shift; my $dest=shift; # where it's going to be put, under the srcdir my $file=shift; # the path to the attachment currently @@ -84,13 +84,13 @@ sub check_canattach ($$;$) { #{{{ else { return 1; } -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { $config{cgi_disable_uploads}=0; -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; my $q=$params{cgi}; @@ -153,9 +153,9 @@ sub formbuilder_setup (@) { #{{{ } } } -} #}}} +} -sub formbuilder (@) { #{{{ +sub formbuilder (@) { my %params=@_; my $form=$params{form}; my $q=$params{cgi}; @@ -253,9 +253,9 @@ sub formbuilder (@) { #{{{ # Generate the attachment list only after having added any new # attachments. $form->tmpl_param("attachment_list" => [attachment_list($form->field('page'))]); -} # }}} +} -sub attachment_location ($) { #{{{ +sub attachment_location ($) { my $page=shift; # Put the attachment in a subdir of the page it's attached @@ -264,9 +264,9 @@ sub attachment_location ($) { #{{{ $page.="/" if length $page; return $page; -} #}}} +} -sub attachment_list ($) { #{{{ +sub attachment_list ($) { my $page=shift; my $loc=attachment_location($page); @@ -287,6 +287,6 @@ sub attachment_list ($) { #{{{ # Sort newer attachments to the top of the list, so a newly-added # attachment appears just before the form used to add it. return sort { $b->{mtime_raw} <=> $a->{mtime_raw} || $a->{link} cmp $b->{link} } @ret; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index d1b3edb1f..bb08091ae 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -6,20 +6,20 @@ use strict; use IkiWiki 2.00; use Encode; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "autoindex", call => \&getsetup); hook(type => "refresh", id => "autoindex", call => \&refresh); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub genindex ($) { #{{{ +sub genindex ($) { my $page=shift; my $file=newpagefile($page, $config{default_pageext}); my $template=template("autoindex.tmpl"); @@ -28,9 +28,9 @@ sub genindex ($) { #{{{ if ($config{rcs}) { IkiWiki::rcs_add($file); } -} #}}} +} -sub refresh () { #{{{ +sub refresh () { eval q{use File::Find}; error($@) if $@; @@ -107,6 +107,6 @@ sub refresh () { #{{{ IkiWiki::enable_commit_hook(); } } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index 37752dd3e..1c52099bf 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -6,20 +6,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "brokenlinks", call => \&getsetup); hook(type => "preprocess", id => "brokenlinks", call => \&preprocess); -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; @@ -61,6 +61,6 @@ sub preprocess (@) { #{{{ } sort @broken) ."\n"; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/bzr.pm b/IkiWiki/Plugin/bzr.pm index 1054f5b3e..16c959069 100644 --- a/IkiWiki/Plugin/bzr.pm +++ b/IkiWiki/Plugin/bzr.pm @@ -7,7 +7,7 @@ use IkiWiki; use Encode; use open qw{:utf8 :std}; -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "bzr", call => \&checkconfig); hook(type => "getsetup", id => "bzr", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -20,18 +20,18 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (defined $config{bzr_wrapper} && length $config{bzr_wrapper}) { push @{$config{wrappers}}, { wrapper => $config{bzr_wrapper}, wrappermode => (defined $config{bzr_wrappermode} ? $config{bzr_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -65,9 +65,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub bzr_log ($) { #{{{ +sub bzr_log ($) { my $out = shift; my @infos = (); my $key = undef; @@ -99,20 +99,20 @@ sub bzr_log ($) { #{{{ close $out; return @infos; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { my @cmdline = ("bzr", "update", "--quiet", $config{srcdir}); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { return ""; -} #}}} +} -sub bzr_author ($$) { #{{{ +sub bzr_author ($$) { my ($user, $ipaddr) = @_; if (defined $user) { @@ -124,9 +124,9 @@ sub bzr_author ($$) { #{{{ else { return "Anonymous"; } -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { my ($file, $message, $rcstoken, $user, $ipaddr) = @_; $user = bzr_author($user, $ipaddr); @@ -143,7 +143,7 @@ sub rcs_commit ($$$;$$) { #{{{ } return undef; # success -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -164,27 +164,27 @@ sub rcs_commit_staged ($$$) { } return undef; # success -} #}}} +} -sub rcs_add ($) { # {{{ +sub rcs_add ($) { my ($file) = @_; my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_remove ($) { # {{{ +sub rcs_remove ($) { my ($file) = @_; my @cmdline = ("bzr", "rm", "--force", "--quiet", "$config{srcdir}/$file"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_rename ($$) { # {{{ +sub rcs_rename ($$) { my ($src, $dest) = @_; my $parent = IkiWiki::dirname($dest); @@ -196,9 +196,9 @@ sub rcs_rename ($$) { # {{{ if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { my ($num) = @_; my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num, @@ -253,9 +253,9 @@ sub rcs_recentchanges ($) { #{{{ } return @ret; -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my ($file) = @_; # XXX filename passes through the shell here, should try to avoid @@ -274,6 +274,6 @@ sub rcs_getctime ($) { #{{{ my $ctime = str2time($log[0]->{"timestamp"}); return $ctime; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 6d536a91b..88303fc44 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -29,13 +29,13 @@ my %linkcache; my $time=time; my @now=localtime($time); -sub import { #{{{ +sub import { hook(type => "getsetup", id => "calendar", call => \&getsetup); hook(type => "needsbuild", id => "calendar", call => \&needsbuild); hook(type => "preprocess", id => "calendar", call => \&preprocess); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -48,23 +48,23 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub is_leap_year (@) { #{{{ +sub is_leap_year (@) { my %params=@_; return ($params{year} % 4 == 0 && (($params{year} % 100 != 0) || $params{year} % 400 == 0)); -} #}}} +} -sub month_days { #{{{ +sub month_days { my %params=@_; my $days_in_month = (31,28,31,30,31,30,31,31,30,31,30,31)[$params{month}-1]; if ($params{month} == 2 && is_leap_year(%params)) { $days_in_month++; } return $days_in_month; -} #}}} +} -sub format_month (@) { #{{{ +sub format_month (@) { my %params=@_; my $pagespec = $params{pages}; @@ -215,9 +215,9 @@ EOF add_depends($params{page}, join(" or ", @list)); return $calendar; -} #}}} +} -sub format_year (@) { #{{{ +sub format_year (@) { my %params=@_; my $pagespec = $params{pages}; @@ -318,9 +318,9 @@ EOF EOF return $calendar; -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages} = "*" unless defined $params{pages}; $params{type} = "month" unless defined $params{type}; @@ -397,7 +397,7 @@ sub preprocess (@) { #{{{ return "\n
$calendar
\n"; } #}} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; foreach my $page (keys %pagestate) { if (exists $pagestate{$page}{calendar}{nextchange}) { @@ -415,6 +415,6 @@ sub needsbuild (@) { #{{{ } } } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/camelcase.pm b/IkiWiki/Plugin/camelcase.pm index 7881becd5..6c1fafb7b 100644 --- a/IkiWiki/Plugin/camelcase.pm +++ b/IkiWiki/Plugin/camelcase.pm @@ -22,21 +22,21 @@ my $link_regexp=qr{ ) }x; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "camelcase", call => \&getsetup); hook(type => "linkify", id => "camelcase", call => \&linkify); hook(type => "scan", id => "camelcase", call => \&scan); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }; -} #}}} +} -sub linkify (@) { #{{{ +sub linkify (@) { my %params=@_; my $page=$params{page}; my $destpage=$params{destpage}; @@ -46,9 +46,9 @@ sub linkify (@) { #{{{ }eg; return $params{content}; -} #}}} +} -sub scan (@) { #{{{ +sub scan (@) { my %params=@_; my $page=$params{page}; my $content=$params{content}; diff --git a/IkiWiki/Plugin/color.pm b/IkiWiki/Plugin/color.pm index ac702ff02..53d8389d2 100644 --- a/IkiWiki/Plugin/color.pm +++ b/IkiWiki/Plugin/color.pm @@ -7,12 +7,12 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "preprocess", id => "color", call => \&preprocess); hook(type => "format", id => "color", call => \&format); -} #}}} +} -sub preserve_style ($$$) { #{{{ +sub preserve_style ($$$) { my $foreground = shift; my $background = shift; my $text = shift; @@ -37,18 +37,18 @@ sub preserve_style ($$$) { #{{{ return $preserved; -} #}}} +} -sub replace_preserved_style ($) { #{{{ +sub replace_preserved_style ($) { my $content = shift; $content =~ s!((color: ([a-z]+|\#[0-9a-f]{3,6})?)?((; )?(background-color: ([a-z]+|\#[0-9a-f]{3,6})?)?)?)!!g; $content =~ s!!!g; return $content; -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params = @_; # Preprocess the text to expand any preprocessor directives @@ -57,13 +57,13 @@ sub preprocess (@) { #{{{ IkiWiki::filter($params{page}, $params{destpage}, $params{text})); return preserve_style($params{foreground}, $params{background}, $params{text}); -} #}}} +} -sub format (@) { #{{{ +sub format (@) { my %params = @_; $params{content} = replace_preserved_style($params{content}); return $params{content}; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index b8748a1d6..6184c6031 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -17,7 +17,7 @@ use constant CANCEL => "Cancel"; my $postcomment; -sub import { #{{{ +sub import { hook(type => "checkconfig", id => 'comments', call => \&checkconfig); hook(type => "getsetup", id => 'comments', call => \&getsetup); hook(type => "preprocess", id => '_comment', call => \&preprocess); @@ -26,9 +26,9 @@ sub import { #{{{ hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); hook(type => "cgi", id => "comments", call => \&linkcgi); IkiWiki::loadplugin("inline"); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -88,15 +88,15 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, -} #}}} +} -sub htmlize { # {{{ +sub htmlize { my %params = @_; return $params{content}; -} # }}} +} # FIXME: copied verbatim from meta -sub safeurl ($) { #{{{ +sub safeurl ($) { my $url=shift; if (exists $IkiWiki::Plugin::htmlscrubber::{safe_url_regexp} && defined $IkiWiki::Plugin::htmlscrubber::safe_url_regexp) { @@ -105,9 +105,9 @@ sub safeurl ($) { #{{{ else { return 1; } -} #}}} +} -sub preprocess { # {{{ +sub preprocess { my %params = @_; my $page = $params{page}; @@ -206,16 +206,16 @@ sub preprocess { # {{{ # FIXME: hard-coded HTML (although it's just to set an ID) return "
$content
" if $anchor; return $content; -} # }}} +} -sub checkconfig () { #{{{ +sub checkconfig () { $config{comments_commit} = 1 unless defined $config{comments_commit}; $config{comments_pagename} = 'comment_' unless defined $config{comments_pagename}; -} #}}} +} # This is exactly the same as recentchanges_link :-( -sub linkcgi ($) { #{{{ +sub linkcgi ($) { my $cgi=shift; if (defined $cgi->param('do') && $cgi->param('do') eq "commenter") { @@ -245,7 +245,7 @@ sub linkcgi ($) { #{{{ # FIXME: basically the same logic as recentchanges # returns (author URL, pretty-printed version) -sub linkuser ($) { # {{{ +sub linkuser ($) { my $user = shift; my $oiduser = eval { IkiWiki::openiduser($user) }; @@ -262,10 +262,10 @@ sub linkuser ($) { # {{{ : "$user") ), $user); } -} # }}} +} # Mostly cargo-culted from IkiWiki::plugin::editpage -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $cgi=shift; my $session=shift; @@ -512,9 +512,9 @@ sub sessioncgi ($$) { #{{{ } exit; -} #}}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params = @_; my $page = $params{page}; @@ -583,7 +583,7 @@ sub pagetemplate (@) { #{{{ $template->param(commentauthorurl => $pagestate{$page}{comments}{commentauthorurl}); } -} # }}} +} package IkiWiki::PageSpec; diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index e787424aa..66253e07d 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -6,20 +6,20 @@ use strict; use IkiWiki 2.00; use UNIVERSAL; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "conditional", call => \&getsetup); hook(type => "preprocess", id => "if", call => \&preprocess_if); -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess_if (@) { #{{{ +sub preprocess_if (@) { my %params=@_; foreach my $param (qw{test then}) { @@ -66,11 +66,11 @@ sub preprocess_if (@) { #{{{ } return IkiWiki::preprocess($params{page}, $params{destpage}, IkiWiki::filter($params{page}, $params{destpage}, $ret)); -} # }}} +} package IkiWiki::PageSpec; -sub match_enabled ($$;@) { #{{{ +sub match_enabled ($$;@) { shift; my $plugin=shift; @@ -81,9 +81,9 @@ sub match_enabled ($$;@) { #{{{ else { return IkiWiki::FailReason->new("$plugin is not enabled"); } -} #}}} +} -sub match_sourcepage ($$;@) { #{{{ +sub match_sourcepage ($$;@) { shift; my $glob=shift; my %params=@_; @@ -95,9 +95,9 @@ sub match_sourcepage ($$;@) { #{{{ else { return IkiWiki::FailReason->new("sourcepage does not match $glob"); } -} #}}} +} -sub match_destpage ($$;@) { #{{{ +sub match_destpage ($$;@) { shift; my $glob=shift; my %params=@_; @@ -109,9 +109,9 @@ sub match_destpage ($$;@) { #{{{ else { return IkiWiki::FailReason->new("destpage does not match $glob"); } -} #}}} +} -sub match_included ($$;@) { #{{{ +sub match_included ($$;@) { shift; shift; my %params=@_; @@ -123,6 +123,6 @@ sub match_included ($$;@) { #{{{ else { return IkiWiki::FailReason->new("page $params{sourcepage} is not included"); } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/creole.pm b/IkiWiki/Plugin/creole.pm index 7c729300d..3c46a48df 100644 --- a/IkiWiki/Plugin/creole.pm +++ b/IkiWiki/Plugin/creole.pm @@ -7,20 +7,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "creole", call => \&getsetup); hook(type => "htmlize", id => "creole", call => \&htmlize); -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; my $content = $params{content}; @@ -32,6 +32,6 @@ sub htmlize (@) { #{{{ creole_custombarelinks(); return creole_parse($content); -} # }}} +} 1 diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm index 92667a1ef..e579c1ea2 100644 --- a/IkiWiki/Plugin/cutpaste.pm +++ b/IkiWiki/Plugin/cutpaste.pm @@ -7,22 +7,22 @@ use IkiWiki 2.00; my %savedtext; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "cutpaste", call => \&getsetup); hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1); hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1); hook(type => "preprocess", id => "paste", call => \&preprocess_paste); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess_cut (@) { #{{{ +sub preprocess_cut (@) { my %params=@_; foreach my $param (qw{id text}) { @@ -35,9 +35,9 @@ sub preprocess_cut (@) { #{{{ $savedtext{$params{page}}->{$params{id}} = $params{text}; return "" if defined wantarray; -} # }}} +} -sub preprocess_copy (@) { #{{{ +sub preprocess_copy (@) { my %params=@_; foreach my $param (qw{id text}) { @@ -51,9 +51,9 @@ sub preprocess_copy (@) { #{{{ return IkiWiki::preprocess($params{page}, $params{destpage}, IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray; -} # }}} +} -sub preprocess_paste (@) { #{{{ +sub preprocess_paste (@) { my %params=@_; foreach my $param (qw{id}) { @@ -71,6 +71,6 @@ sub preprocess_paste (@) { #{{{ return IkiWiki::preprocess($params{page}, $params{destpage}, IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}})); -} # }}} +} 1; diff --git a/IkiWiki/Plugin/ddate.pm b/IkiWiki/Plugin/ddate.pm index c73317b2f..3470640dc 100644 --- a/IkiWiki/Plugin/ddate.pm +++ b/IkiWiki/Plugin/ddate.pm @@ -5,19 +5,19 @@ package IkiWiki::Plugin::ddate; use IkiWiki 2.00; no warnings; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "ddate", call => \&getsetup); -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub IkiWiki::formattime ($;$) { #{{{ +sub IkiWiki::formattime ($;$) { my $time=shift; my $format=shift; if (! defined $format) { @@ -36,6 +36,6 @@ sub IkiWiki::formattime ($;$) { #{{{ my $dt = DateTime->from_epoch(epoch => $time); my $dd = DateTime::Calendar::Discordian->from_object(object => $dt); return $dd->strftime($format); -} #}}} +} 5 diff --git a/IkiWiki/Plugin/editdiff.pm b/IkiWiki/Plugin/editdiff.pm index f5d7837fc..068b83b3c 100644 --- a/IkiWiki/Plugin/editdiff.pm +++ b/IkiWiki/Plugin/editdiff.pm @@ -8,21 +8,21 @@ use IkiWiki 2.00; use HTML::Entities; use IPC::Open2; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "editdiff", call => \&getsetup); hook(type => "formbuilder_setup", id => "editdiff", call => \&formbuilder_setup); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub diff ($$) { #{{{ +sub diff ($$) { my $orig=shift; my $content=shift; @@ -50,9 +50,9 @@ sub diff ($$) { #{{{ return "couldn't run diff\n" if $sigpipe; return "
".encode_entities($ret)."
"; -} #}}} +} -sub formbuilder_setup { #{{{ +sub formbuilder_setup { my %params=@_; my $form=$params{form}; @@ -72,6 +72,6 @@ sub formbuilder_setup { #{{{ my $diff = diff(srcfile($pagesources{$page}), $content); $form->tmpl_param("page_preview", $diff); } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 242624d77..9210d6ff8 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -6,19 +6,19 @@ use strict; use IkiWiki; use open qw{:utf8 :std}; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "editpage", call => \&getsetup); hook(type => "refresh", id => "editpage", call => \&refresh); hook(type => "sessioncgi", id => "editpage", call => \&IkiWiki::cgi_editpage); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} sub refresh () { if (exists $wikistate{editpage} && exists $wikistate{editpage}{previews}) { @@ -54,7 +54,7 @@ sub refresh () { # and other plugins use the functions below. package IkiWiki; -sub check_canedit ($$$;$) { #{{{ +sub check_canedit ($$$;$) { my $page=shift; my $q=shift; my $session=shift; @@ -79,9 +79,9 @@ sub check_canedit ($$$;$) { #{{{ } }); return $canedit; -} #}}} +} -sub cgi_editpage ($$) { #{{{ +sub cgi_editpage ($$) { my $q=shift; my $session=shift; @@ -453,6 +453,6 @@ sub cgi_editpage ($$) { #{{{ } exit; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 846b4e7c8..7c0e7c2f8 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm @@ -7,7 +7,7 @@ use IkiWiki 2.00; use HTML::Template; use Encode; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "edittemplate", call => \&getsetup); hook(type => "needsbuild", id => "edittemplate", @@ -16,17 +16,17 @@ sub import { #{{{ call => \&preprocess); hook(type => "formbuilder", id => "edittemplate", call => \&formbuilder); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; foreach my $page (keys %pagestate) { @@ -40,9 +40,9 @@ sub needsbuild (@) { #{{{ } } } -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; return "" if $params{page} ne $params{destpage}; @@ -62,9 +62,9 @@ sub preprocess (@) { #{{{ return sprintf(gettext("edittemplate %s registered for %s"), htmllink($params{page}, $params{destpage}, $link), $params{match}); -} # }}} +} -sub formbuilder (@) { #{{{ +sub formbuilder (@) { my %params=@_; my $form=$params{form}; @@ -103,9 +103,9 @@ sub formbuilder (@) { #{{{ } } } -} #}}} +} -sub filltemplate ($$) { #{{{ +sub filltemplate ($$) { my $template_page=shift; my $page=shift; @@ -136,6 +136,6 @@ sub filltemplate ($$) { #{{{ $template->param(name => $page); return $template->output; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/embed.pm b/IkiWiki/Plugin/embed.pm index 2a1637392..664c95763 100644 --- a/IkiWiki/Plugin/embed.pm +++ b/IkiWiki/Plugin/embed.pm @@ -43,35 +43,35 @@ my $safehtml=qr{( my @embedded; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "embed", call => \&getsetup); hook(type => "filter", id => "embed", call => \&filter); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub embed ($) { #{{{ +sub embed ($) { hook(type => "format", id => "embed", call => \&format) unless @embedded; push @embedded, shift; return "
"; -} #}}} +} -sub filter (@) { #{{{ +sub filter (@) { my %params=@_; $params{content} =~ s/$safehtml/embed($1)/eg; return $params{content}; -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; $params{content} =~ s/
<\/div>/$embedded[$1]/eg; return $params{content}; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/external.pm b/IkiWiki/Plugin/external.pm index 4ce9c8bab..2d540143f 100644 --- a/IkiWiki/Plugin/external.pm +++ b/IkiWiki/Plugin/external.pm @@ -14,7 +14,7 @@ use IO::Handle; my %plugins; -sub import { #{{{ +sub import { my $self=shift; my $plugin=shift; return unless defined $plugin; @@ -32,17 +32,17 @@ sub import { #{{{ $RPC::XML::ENCODING="utf-8"; rpc_call($plugins{$plugin}, "import"); -} #}}} +} -sub rpc_write ($$) { #{{{ +sub rpc_write ($$) { my $fh=shift; my $string=shift; $fh->print($string."\n"); $fh->flush; -} #}}} +} -sub rpc_call ($$;@) { #{{{ +sub rpc_call ($$;@) { my $plugin=shift; my $command=shift; @@ -131,12 +131,12 @@ sub rpc_call ($$;@) { #{{{ } return undef; -} #}}} +} package IkiWiki::RPC::XML; use Memoize; -sub getvar ($$$) { #{{{ +sub getvar ($$$) { my $plugin=shift; my $varname="IkiWiki::".shift; my $key=shift; @@ -145,9 +145,9 @@ sub getvar ($$$) { #{{{ my $ret=$varname->{$key}; use strict 'refs'; return $ret; -} #}}} +} -sub setvar ($$$;@) { #{{{ +sub setvar ($$$;@) { my $plugin=shift; my $varname="IkiWiki::".shift; my $key=shift; @@ -157,18 +157,18 @@ sub setvar ($$$;@) { #{{{ my $ret=$varname->{$key}=$value; use strict 'refs'; return $ret; -} #}}} +} -sub getstate ($$$$) { #{{{ +sub getstate ($$$$) { my $plugin=shift; my $page=shift; my $id=shift; my $key=shift; return $IkiWiki::pagestate{$page}{$id}{$key}; -} #}}} +} -sub setstate ($$$$;@) { #{{{ +sub setstate ($$$$;@) { my $plugin=shift; my $page=shift; my $id=shift; @@ -176,22 +176,22 @@ sub setstate ($$$$;@) { #{{{ my $value=shift; return $IkiWiki::pagestate{$page}{$id}{$key}=$value; -} #}}} +} -sub getargv ($) { #{{{ +sub getargv ($) { my $plugin=shift; return \@ARGV; -} #}}} +} -sub setargv ($@) { #{{{ +sub setargv ($@) { my $plugin=shift; my $array=shift; @ARGV=@$array; -} #}}} +} -sub inject ($@) { #{{{ +sub inject ($@) { # Bind a given perl function name to a particular RPC request. my $plugin=shift; my %params=@_; @@ -213,9 +213,9 @@ sub inject ($@) { #{{{ # the injected version. IkiWiki::inject(name => $params{name}, call => $sub); return 1; -} #}}} +} -sub hook ($@) { #{{{ +sub hook ($@) { # the call parameter is a function name to call, since XML RPC # cannot pass a function reference my $plugin=shift; @@ -227,13 +227,13 @@ sub hook ($@) { #{{{ IkiWiki::hook(%params, call => sub { IkiWiki::Plugin::external::rpc_call($plugin, $callback, @_); }); -} #}}} +} -sub pagespec_match ($@) { #{{{ +sub pagespec_match ($@) { # convert pagespec_match's return object into a XML RPC boolean my $plugin=shift; return RPC::XML::boolean->new(0 + IkiWiki::pagespec_march(@_)); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/favicon.pm b/IkiWiki/Plugin/favicon.pm index e9204dea9..68359a4aa 100644 --- a/IkiWiki/Plugin/favicon.pm +++ b/IkiWiki/Plugin/favicon.pm @@ -7,20 +7,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "favicon", call => \&getsetup); hook(type => "pagetemplate", id => "favicon", call => \&pagetemplate); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $template=$params{template}; @@ -28,6 +28,6 @@ sub pagetemplate (@) { #{{{ if ($template->query(name => "favicon")) { $template->param(favicon => "favicon.ico"); } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm index 27f764e3b..5040a185c 100644 --- a/IkiWiki/Plugin/filecheck.pm +++ b/IkiWiki/Plugin/filecheck.pm @@ -37,9 +37,9 @@ my %units=( #{{{ # size in bytes # ikiwiki, if you find you need larger data quantities, either modify # yourself to add them, or travel back in time to 2008 and kill me. # -- Joey -); #}}} +); -sub parsesize ($) { #{{{ +sub parsesize ($) { my $size=shift; no warnings; @@ -51,10 +51,10 @@ sub parsesize ($) { #{{{ } } return $base; -} #}}} +} # This is provided for other plugins that want to convert back the other way. -sub humansize ($) { #{{{ +sub humansize ($) { my $size=shift; foreach my $unit (reverse sort { $units{$a} <=> $units{$b} || $b cmp $a } keys %units) { @@ -63,11 +63,11 @@ sub humansize ($) { #{{{ } } return $size; # near zero, or negative -} #}}} +} package IkiWiki::PageSpec; -sub match_maxsize ($$;@) { #{{{ +sub match_maxsize ($$;@) { my $page=shift; my $maxsize=eval{IkiWiki::Plugin::filecheck::parsesize(shift)}; if ($@) { @@ -86,9 +86,9 @@ sub match_maxsize ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file not too large"); } -} #}}} +} -sub match_minsize ($$;@) { #{{{ +sub match_minsize ($$;@) { my $page=shift; my $minsize=eval{IkiWiki::Plugin::filecheck::parsesize(shift)}; if ($@) { @@ -107,9 +107,9 @@ sub match_minsize ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file not too small"); } -} #}}} +} -sub match_mimetype ($$;@) { #{{{ +sub match_mimetype ($$;@) { my $page=shift; my $wanted=shift; @@ -140,9 +140,9 @@ sub match_mimetype ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file MIME type is $mimetype"); } -} #}}} +} -sub match_virusfree ($$;@) { #{{{ +sub match_virusfree ($$;@) { my $page=shift; my $wanted=shift; @@ -182,9 +182,9 @@ sub match_virusfree ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file seems virusfree ($reason)"); } -} #}}} +} -sub match_ispage ($$;@) { #{{{ +sub match_ispage ($$;@) { my $filename=shift; if (defined IkiWiki::pagetype($filename)) { @@ -193,4 +193,4 @@ sub match_ispage ($$;@) { #{{{ else { return IkiWiki::FailReason->new("file is not a wiki page"); } -} #}}} +} diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index 1e21a0bdc..b4d3a3c5f 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -5,11 +5,11 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "preprocess", id => "format", call => \&preprocess); -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my $format=$_[0]; shift; shift; my $text=$_[0]; @@ -25,6 +25,6 @@ sub preprocess (@) { #{{{ return IkiWiki::htmlize($params{page}, $params{destpage}, $format, IkiWiki::preprocess($params{page}, $params{destpage}, $text)); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/fortune.pm b/IkiWiki/Plugin/fortune.pm index 456b63e9f..6a12f28fd 100644 --- a/IkiWiki/Plugin/fortune.pm +++ b/IkiWiki/Plugin/fortune.pm @@ -6,20 +6,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "fortune", call => \&getsetup); hook(type => "preprocess", id => "fortune", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { $ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games"; my $f = `fortune 2>/dev/null`; @@ -29,6 +29,6 @@ sub preprocess (@) { #{{{ else { return "
$f
\n"; } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 1a39d87e5..6a7f6c3ae 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -11,7 +11,7 @@ my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes my $no_chdir=0; -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "git", call => \&checkconfig); hook(type => "getsetup", id => "git", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -25,9 +25,9 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); hook(type => "rcs", id => "rcs_receive", call => \&rcs_receive); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (! defined $config{gitorigin_branch}) { $config{gitorigin_branch}="origin"; } @@ -49,9 +49,9 @@ sub checkconfig () { #{{{ wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -113,9 +113,9 @@ sub getsetup () { #{{{ safe => 0, # paranoia rebuild => 0, }, -} #}}} +} -sub safe_git (&@) { #{{{ +sub safe_git (&@) { # Start a child process safely without resorting /bin/sh. # Return command output or success state (in scalar context). @@ -152,9 +152,9 @@ sub safe_git (&@) { #{{{ sub run_or_die ($@) { safe_git(\&error, @_) } sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) } sub run_or_non ($@) { safe_git(undef, @_) } -#}}} -sub merge_past ($$$) { #{{{ + +sub merge_past ($$$) { # Unlike with Subversion, Git cannot make a 'svn merge -rN:M file'. # Git merge commands work with the committed changes, except in the # implicit case of '-m' of git checkout(1). So we should invent a @@ -246,9 +246,9 @@ sub merge_past ($$$) { #{{{ error("Git merge failed!\n$failure\n") if $failure; return $conflict; -} #}}} +} -sub parse_diff_tree ($@) { #{{{ +sub parse_diff_tree ($@) { # Parse the raw diff tree chunk and return the info hash. # See git-diff-tree(1) for the syntax. @@ -358,9 +358,9 @@ sub parse_diff_tree ($@) { #{{{ } return \%ci; -} #}}} +} -sub git_commit_info ($;$) { #{{{ +sub git_commit_info ($;$) { # Return an array of commit info hashes of num commits # starting from the given sha1sum. my ($sha1, $num) = @_; @@ -381,9 +381,9 @@ sub git_commit_info ($;$) { #{{{ warn "Cannot parse commit info for '$sha1' commit" if !@ci; return wantarray ? @ci : $ci[0]; -} #}}} +} -sub git_sha1 (;$) { #{{{ +sub git_sha1 (;$) { # Return head sha1sum (of given file). my $file = shift || q{--}; @@ -394,25 +394,25 @@ sub git_sha1 (;$) { #{{{ ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now } else { debug("Empty sha1sum for '$file'.") } return defined $sha1 ? $sha1 : q{}; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { # Update working directory. if (length $config{gitorigin_branch}) { run_or_cry('git', 'pull', $config{gitorigin_branch}); } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { # Return the commit sha1sum of the file when editing begins. # This will be later used in rcs_commit if a merge is required. my ($file) = @_; return git_sha1($file); -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { # Try to commit the page; returns undef on _success_ and # a version of the page with the rcs's conflict markers on # failure. @@ -431,7 +431,7 @@ sub rcs_commit ($$$;$$) { #{{{ rcs_add($file); return rcs_commit_staged($message, $user, $ipaddr); -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -472,29 +472,29 @@ sub rcs_commit_staged ($$$) { return undef; # success } -sub rcs_add ($) { # {{{ +sub rcs_add ($) { # Add file to archive. my ($file) = @_; run_or_cry('git', 'add', $file); -} #}}} +} -sub rcs_remove ($) { # {{{ +sub rcs_remove ($) { # Remove file from archive. my ($file) = @_; run_or_cry('git', 'rm', '-f', $file); -} #}}} +} -sub rcs_rename ($$) { # {{{ +sub rcs_rename ($$) { my ($src, $dest) = @_; run_or_cry('git', 'mv', '-f', $src, $dest); -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { # List of recent changes. my ($num) = @_; @@ -562,9 +562,9 @@ sub rcs_recentchanges ($) { #{{{ } return @rets; -} #}}} +} -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { my $rev=shift; my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint my @lines; @@ -579,9 +579,9 @@ sub rcs_diff ($) { #{{{ else { return join("", @lines); } -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my $file=shift; # Remove srcdir prefix $file =~ s/^\Q$config{srcdir}\E\/?//; @@ -592,9 +592,9 @@ sub rcs_getctime ($) { #{{{ debug("ctime for '$file': ". localtime($ctime)); return $ctime; -} #}}} +} -sub rcs_receive () { #{{{ +sub rcs_receive () { # The wiki may not be the only thing in the git repo. # Determine if it is in a subdirectory by examining the srcdir, # and its parents, looking for the .git directory. @@ -685,6 +685,6 @@ sub rcs_receive () { #{{{ } return reverse @rets; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/goodstuff.pm b/IkiWiki/Plugin/goodstuff.pm index a18e626d4..92bc8200a 100644 --- a/IkiWiki/Plugin/goodstuff.pm +++ b/IkiWiki/Plugin/goodstuff.pm @@ -24,19 +24,19 @@ my @bundle=qw{ toggle }; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "goodstuff", call => \&getsetup); foreach my $plugin (@bundle) { IkiWiki::loadplugin($plugin); } -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} 1 diff --git a/IkiWiki/Plugin/google.pm b/IkiWiki/Plugin/google.pm index 92b9b29eb..5394c5a6f 100644 --- a/IkiWiki/Plugin/google.pm +++ b/IkiWiki/Plugin/google.pm @@ -8,21 +8,21 @@ use URI; my $host; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "google", call => \&getsetup); hook(type => "checkconfig", id => "google", call => \&checkconfig); hook(type => "pagetemplate", id => "google", call => \&pagetemplate); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (! length $config{url}) { error(sprintf(gettext("Must specify %s when using the google search plugin"), "url")); } @@ -31,10 +31,10 @@ sub checkconfig () { #{{{ error(gettext("Failed to parse url, cannot determine domain name")); } $host=$uri->host; -} #}}} +} my $form; -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; my $template=$params{template}; @@ -49,6 +49,6 @@ sub pagetemplate (@) { #{{{ $template->param(searchform => $form); } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/googlecalendar.pm b/IkiWiki/Plugin/googlecalendar.pm index 81a3ad677..9e09d7dbb 100644 --- a/IkiWiki/Plugin/googlecalendar.pm +++ b/IkiWiki/Plugin/googlecalendar.pm @@ -5,24 +5,24 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "googlecalendar", call => \&getsetup); hook(type => "preprocess", id => "googlecalendar", call => \&preprocess); hook(type => "format", id => "googlecalendar", call => \&format); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; # Parse the html, looking for the url to embed for the calendar. @@ -35,21 +35,21 @@ sub preprocess (@) { #{{{ my ($width)=$params{html}=~m#width="(\d+)"#; return "
"; -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; $params{content}=~s/
<\/div>/gencal($1,$2,$3)/eg; return $params{content}; -} # }}} +} -sub gencal ($$$) { #{{{ +sub gencal ($$$) { my $url=shift; my $height=shift; my $width=shift; return qq{}; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/graphviz.pm b/IkiWiki/Plugin/graphviz.pm index 20b419413..23631da30 100644 --- a/IkiWiki/Plugin/graphviz.pm +++ b/IkiWiki/Plugin/graphviz.pm @@ -8,24 +8,24 @@ use strict; use IkiWiki 2.00; use IPC::Open2; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "graphviz", call => \&getsetup); hook(type => "preprocess", id => "graph", call => \&graph); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} my %graphviz_programs = ( "dot" => 1, "neato" => 1, "fdp" => 1, "twopi" => 1, "circo" => 1 ); -sub render_graph (\%) { #{{{ +sub render_graph (\%) { my %params = %{(shift)}; my $src = "$params{type} g {\n"; @@ -84,9 +84,9 @@ sub render_graph (\%) { #{{{ else { return "\n"; } -} #}}} +} -sub graph (@) { #{{{ +sub graph (@) { my %params=@_; $params{src} = "" unless defined $params{src}; $params{type} = "digraph" unless defined $params{type}; @@ -94,6 +94,6 @@ sub graph (@) { #{{{ error gettext("prog not a valid graphviz program") unless $graphviz_programs{$params{prog}}; return render_graph(%params); -} # }}} +} 1 diff --git a/IkiWiki/Plugin/haiku.pm b/IkiWiki/Plugin/haiku.pm index eb8b786e8..fe68c6eec 100644 --- a/IkiWiki/Plugin/haiku.pm +++ b/IkiWiki/Plugin/haiku.pm @@ -6,20 +6,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "haiku", call => \&getsetup); hook(type => "preprocess", id => "haiku", call => \&preprocess); -} # }}} +} -sub getsetup { #{{{ +sub getsetup { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; my $haiku; @@ -54,6 +54,6 @@ sub preprocess (@) { #{{{ $haiku=~s/\n/
\n/mg; return "\n\n

$haiku

\n\n"; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/hnb.pm b/IkiWiki/Plugin/hnb.pm index 40e4f9452..d5b5ce3b4 100644 --- a/IkiWiki/Plugin/hnb.pm +++ b/IkiWiki/Plugin/hnb.pm @@ -13,20 +13,20 @@ use strict; use IkiWiki 2.00; use File::Temp qw(:mktemp); -sub import { #{{{ +sub import { hook(type => "getsetup", id => "hnb", call => \&getsetup); hook(type => "htmlize", id => "hnb", call => \&htmlize); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params = @_; # hnb outputs version number etc. every time to STDOUT, so @@ -52,6 +52,6 @@ sub htmlize (@) { #{{{ $ret =~ s/.*//si; return $ret; -} #}}} +} 1; diff --git a/IkiWiki/Plugin/html.pm b/IkiWiki/Plugin/html.pm index b75207578..9b9547cca 100644 --- a/IkiWiki/Plugin/html.pm +++ b/IkiWiki/Plugin/html.pm @@ -6,7 +6,7 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "html", call => \&getsetup); hook(type => "htmlize", id => "html", call => \&htmlize); hook(type => "htmlize", id => "htm", call => \&htmlize); @@ -14,19 +14,19 @@ sub import { #{{{ # ikiwiki defaults to skipping .html files as a security measure; # make it process them so this plugin can take effect $config{wiki_file_prune_regexps} = [ grep { !m/\\\.x\?html\?\$/ } @{$config{wiki_file_prune_regexps}} ]; -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; return $params{content}; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm index dcd92055f..acbe40a5d 100644 --- a/IkiWiki/Plugin/htmlbalance.pm +++ b/IkiWiki/Plugin/htmlbalance.pm @@ -13,20 +13,20 @@ use IkiWiki 2.00; use HTML::TreeBuilder; use HTML::Entities; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "htmlbalance", call => \&getsetup); hook(type => "sanitize", id => "htmlbalance", call => \&sanitize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; my $ret = ''; @@ -52,6 +52,6 @@ sub sanitize (@) { #{{{ } $tree->delete(); return $ret; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/htmlscrubber.pm b/IkiWiki/Plugin/htmlscrubber.pm index 7398c8478..823b3d806 100644 --- a/IkiWiki/Plugin/htmlscrubber.pm +++ b/IkiWiki/Plugin/htmlscrubber.pm @@ -9,7 +9,7 @@ use IkiWiki 2.00; # Feel free to use it from other plugins. our $safe_url_regexp; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "htmlscrubber", call => \&getsetup); hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize); @@ -33,9 +33,9 @@ sub import { #{{{ # data is a special case. Allow data:image/*, but # disallow data:text/javascript and everything else. $safe_url_regexp=qr/^(?:(?:$uri_schemes):|data:image\/|[^:]+(?:$|\/))/i; -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -49,9 +49,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => undef, }, -} #}}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; if (exists $config{htmlscrubber_skip} && @@ -62,10 +62,10 @@ sub sanitize (@) { #{{{ } return scrubber()->scrub($params{content}); -} # }}} +} my $_scrubber; -sub scrubber { #{{{ +sub scrubber { return $_scrubber if defined $_scrubber; eval q{use HTML::Scrubber}; @@ -111,6 +111,6 @@ sub scrubber { #{{{ }], ); return $_scrubber; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm index 9ba5e9592..02438ebef 100644 --- a/IkiWiki/Plugin/htmltidy.pm +++ b/IkiWiki/Plugin/htmltidy.pm @@ -12,20 +12,20 @@ use strict; use IkiWiki 2.00; use IPC::Open2; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "tidy", call => \&getsetup); hook(type => "sanitize", id => "tidy", call => \&sanitize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; my $pid; @@ -49,6 +49,6 @@ sub sanitize (@) { #{{{ return "" if $sigpipe || ! defined $ret; return $ret; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/httpauth.pm b/IkiWiki/Plugin/httpauth.pm index fc0cffb1e..39edff615 100644 --- a/IkiWiki/Plugin/httpauth.pm +++ b/IkiWiki/Plugin/httpauth.pm @@ -6,26 +6,26 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "httpauth", call => \&getsetup); hook(type => "auth", id => "httpauth", call => \&auth); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub auth ($$) { #{{{ +sub auth ($$) { my $cgi=shift; my $session=shift; if (defined $cgi->remote_user()) { $session->param("name", $cgi->remote_user()); } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm index 7b89ab673..395890c0e 100644 --- a/IkiWiki/Plugin/img.pm +++ b/IkiWiki/Plugin/img.pm @@ -9,20 +9,20 @@ use IkiWiki 2.00; my %imgdefaults; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "img", call => \&getsetup); hook(type => "preprocess", id => "img", call => \&preprocess, scan => 1); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my ($image) = $_[0] =~ /$config{wiki_file_regexp}/; # untaint my %params=@_; @@ -149,6 +149,6 @@ sub preprocess (@) { #{{{ else { return $imgtag; } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index d6ef6c54c..d37db97ec 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -13,7 +13,7 @@ my %page_numfeeds; my @inline; my $nested=0; -sub import { #{{{ +sub import { hook(type => "getopt", id => "inline", call => \&getopt); hook(type => "getsetup", id => "inline", call => \&getsetup); hook(type => "checkconfig", id => "inline", call => \&checkconfig); @@ -27,9 +27,9 @@ sub import { #{{{ # This ensures each page only pings once and prevents slow # pings interrupting page builds. hook(type => "change", id => "inline", call => \&IkiWiki::pingurl); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); @@ -42,9 +42,9 @@ sub getopt () { #{{{ push @{$config{pingurl}}, $_[1]; }, ); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -85,9 +85,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (($config{rss} || $config{atom}) && ! length $config{url}) { error(gettext("Must specify url to wiki with --url when using --rss or --atom")); } @@ -100,9 +100,9 @@ sub checkconfig () { #{{{ if (! exists $config{pingurl}) { $config{pingurl}=[]; } -} #}}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; # Fill in the inline content generated earlier. This is actually an @@ -111,9 +111,9 @@ sub format (@) { #{{{ delete @inline[$1,] }eg; return $params{content}; -} #}}} +} -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $q=shift; my $session=shift; @@ -148,7 +148,7 @@ package IkiWiki; my %toping; my %feedlinks; -sub preprocess_inline (@) { #{{{ +sub preprocess_inline (@) { my %params=@_; if (! exists $params{pages}) { @@ -416,18 +416,18 @@ sub preprocess_inline (@) { #{{{ return $ret if $raw || $nested; push @inline, $ret; return "
\n\n"; -} #}}} +} -sub pagetemplate_inline (@) { #{{{ +sub pagetemplate_inline (@) { my %params=@_; my $page=$params{page}; my $template=$params{template}; $template->param(feedlinks => $feedlinks{$page}) if exists $feedlinks{$page} && $template->query(name => "feedlinks"); -} #}}} +} -sub get_inline_content ($$) { #{{{ +sub get_inline_content ($$) { my $page=shift; my $destpage=shift; @@ -446,9 +446,9 @@ sub get_inline_content ($$) { #{{{ else { return ""; } -} #}}} +} -sub date_822 ($) { #{{{ +sub date_822 ($) { my $time=shift; my $lc_time=POSIX::setlocale(&POSIX::LC_TIME); @@ -456,9 +456,9 @@ sub date_822 ($) { #{{{ my $ret=POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time)); POSIX::setlocale(&POSIX::LC_TIME, $lc_time); return $ret; -} #}}} +} -sub date_3339 ($) { #{{{ +sub date_3339 ($) { my $time=shift; my $lc_time=POSIX::setlocale(&POSIX::LC_TIME); @@ -466,9 +466,9 @@ sub date_3339 ($) { #{{{ my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time)); POSIX::setlocale(&POSIX::LC_TIME, $lc_time); return $ret; -} #}}} +} -sub absolute_urls ($$) { #{{{ +sub absolute_urls ($$) { # sucky sub because rss sucks my $content=shift; my $baseurl=shift; @@ -489,9 +489,9 @@ sub absolute_urls ($$) { #{{{ $content=~s/(output; -} #}}} +} -sub pingurl (@) { #{{{ +sub pingurl (@) { return unless @{$config{pingurl}} && %toping; eval q{require RPC::XML::Client}; @@ -624,6 +624,6 @@ sub pingurl (@) { #{{{ } exit 0; # daemon done -} #}}} +} 1 diff --git a/IkiWiki/Plugin/link.pm b/IkiWiki/Plugin/link.pm index 0638d4bdd..3799209d0 100644 --- a/IkiWiki/Plugin/link.pm +++ b/IkiWiki/Plugin/link.pm @@ -7,23 +7,23 @@ use IkiWiki 2.00; my $link_regexp; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "link", call => \&getsetup); hook(type => "checkconfig", id => "link", call => \&checkconfig); hook(type => "linkify", id => "link", call => \&linkify); hook(type => "scan", id => "link", call => \&scan); hook(type => "renamepage", id => "link", call => \&renamepage); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if ($config{prefix_directives}) { $link_regexp = qr{ \[\[(?=[^!]) # beginning of link @@ -58,9 +58,9 @@ sub checkconfig () { #{{{ \]\] # end of link }x, } -} #}}} +} -sub linkify (@) { #{{{ +sub linkify (@) { my %params=@_; my $page=$params{page}; my $destpage=$params{destpage}; @@ -78,9 +78,9 @@ sub linkify (@) { #{{{ }eg; return $params{content}; -} #}}} +} -sub scan (@) { #{{{ +sub scan (@) { my %params=@_; my $page=$params{page}; my $content=$params{content}; @@ -88,9 +88,9 @@ sub scan (@) { #{{{ while ($content =~ /(? "getsetup", id => "linkmap", call => \&getsetup); hook(type => "preprocess", id => "linkmap", call => \&preprocess); hook(type => "format", id => "linkmap", call => \&format); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} my $mapnum=0; my %maps; -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; @@ -39,17 +39,17 @@ sub preprocess (@) { #{{{ $mapnum++; $maps{$mapnum}=\%params; return "
"; -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; $params{content}=~s/
<\/div>/genmap($1)/eg; return $params{content}; -} # }}} +} -sub genmap ($) { #{{{ +sub genmap ($) { my $mapnum=shift; return "" unless exists $maps{$mapnum}; my %params=%{$maps{$mapnum}}; @@ -106,6 +106,6 @@ sub genmap ($) { #{{{ error gettext("failed to run dot") if $sigpipe; return $ret; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index 2ab3e4665..be82b0495 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -6,15 +6,15 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { add_underlay("directives"); hook(type => "getsetup", id => "listdirectives", call => \&getsetup); hook(type => "checkconfig", id => "listdirectives", call => \&checkconfig); hook(type => "needsbuild", id => "listdirectives", call => \&needsbuild); hook(type => "preprocess", id => "listdirectives", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -27,22 +27,22 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} my @fulllist; my @shortlist; my $pluginstring; -sub checkconfig () { #{{{ +sub checkconfig () { if (! defined $config{directive_description_dir}) { $config{directive_description_dir} = "ikiwiki/directive"; } else { $config{directive_description_dir} =~ s/\/+$//; } -} #}}} +} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; @fulllist = sort keys %{$IkiWiki::hooks{preprocess}}; @@ -63,9 +63,9 @@ sub needsbuild (@) { #{{{ } } } -} # }}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring; @@ -92,6 +92,6 @@ sub preprocess (@) { #{{{ $result .= ""; return $result; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/lockedit.pm b/IkiWiki/Plugin/lockedit.pm index f6cac6cdd..31a9e70cd 100644 --- a/IkiWiki/Plugin/lockedit.pm +++ b/IkiWiki/Plugin/lockedit.pm @@ -5,14 +5,14 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "lockedit", call => \&getsetup); hook(type => "canedit", id => "lockedit", call => \&canedit); hook(type => "formbuilder_setup", id => "lockedit", call => \&formbuilder_setup); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -26,9 +26,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub canedit ($$) { #{{{ +sub canedit ($$) { my $page=shift; my $cgi=shift; my $session=shift; @@ -70,9 +70,9 @@ sub canedit ($$) { #{{{ } return undef; -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; # XXX deprecated, should be removed eventually @@ -109,6 +109,6 @@ sub formbuilder_setup (@) { #{{{ } } } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 18c584a30..af14ef5de 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -11,20 +11,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "map", call => \&getsetup); hook(type => "preprocess", id => "map", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; @@ -144,6 +144,6 @@ sub preprocess (@) { #{{{ } $map .= "
\n"; return $map; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/mdwn.pm b/IkiWiki/Plugin/mdwn.pm index 6c1d2ef3c..0d5f398a0 100644 --- a/IkiWiki/Plugin/mdwn.pm +++ b/IkiWiki/Plugin/mdwn.pm @@ -6,12 +6,12 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "mdwn", call => \&getsetup); hook(type => "htmlize", id => "mdwn", call => \&htmlize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -24,10 +24,10 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} my $markdown_sub; -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; my $content = $params{content}; @@ -83,6 +83,6 @@ sub htmlize (@) { #{{{ $content=Encode::decode_utf8($content); return $content; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/mercurial.pm b/IkiWiki/Plugin/mercurial.pm index 7aceebcdb..82423286d 100644 --- a/IkiWiki/Plugin/mercurial.pm +++ b/IkiWiki/Plugin/mercurial.pm @@ -7,7 +7,7 @@ use IkiWiki; use Encode; use open qw{:utf8 :std}; -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "mercurial", call => \&checkconfig); hook(type => "getsetup", id => "mercurial", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -20,18 +20,18 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (exists $config{mercurial_wrapper} && length $config{mercurial_wrapper}) { push @{$config{wrappers}}, { wrapper => $config{mercurial_wrapper}, wrappermode => (defined $config{mercurial_wrappermode} ? $config{mercurial_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -65,9 +65,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub mercurial_log ($) { #{{{ +sub mercurial_log ($) { my $out = shift; my @infos; @@ -111,20 +111,20 @@ sub mercurial_log ($) { #{{{ close $out; return @infos; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { return ""; -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { my ($file, $message, $rcstoken, $user, $ipaddr) = @_; if (defined $user) { @@ -149,7 +149,7 @@ sub rcs_commit ($$$;$$) { #{{{ } return undef; # success -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -159,28 +159,28 @@ sub rcs_commit_staged ($$$) { error("rcs_commit_staged not implemented for mercurial"); # TODO } -sub rcs_add ($) { # {{{ +sub rcs_add ($) { my ($file) = @_; my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } -} #}}} +} -sub rcs_remove ($) { # {{{ +sub rcs_remove ($) { my ($file) = @_; error("rcs_remove not implemented for mercurial"); # TODO -} #}}} +} -sub rcs_rename ($$) { # {{{ +sub rcs_rename ($$) { my ($src, $dest) = @_; error("rcs_rename not implemented for mercurial"); # TODO -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { my ($num) = @_; my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num, @@ -225,13 +225,13 @@ sub rcs_recentchanges ($) { #{{{ } return @ret; -} #}}} +} -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { # TODO -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my ($file) = @_; # XXX filename passes through the shell here, should try to avoid @@ -251,6 +251,6 @@ sub rcs_getctime ($) { #{{{ my $ctime = str2time($log[0]->{"date"}); return $ctime; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 3991797c0..ea60be507 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -8,22 +8,22 @@ use IkiWiki 2.00; my %metaheaders; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "meta", call => \&getsetup); hook(type => "needsbuild", id => "meta", call => \&needsbuild); hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); hook(type => "pagetemplate", id => "meta", call => \&pagetemplate); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; foreach my $page (keys %pagestate) { if (exists $pagestate{$page}{meta}) { @@ -38,7 +38,7 @@ sub needsbuild (@) { #{{{ } } -sub scrub ($$) { #{{{ +sub scrub ($$) { if (IkiWiki::Plugin::htmlscrubber->can("sanitize")) { return IkiWiki::Plugin::htmlscrubber::sanitize( content => shift, destpage => shift); @@ -46,9 +46,9 @@ sub scrub ($$) { #{{{ else { return shift; } -} #}}} +} -sub safeurl ($) { #{{{ +sub safeurl ($) { my $url=shift; if (exists $IkiWiki::Plugin::htmlscrubber::{safe_url_regexp} && defined $IkiWiki::Plugin::htmlscrubber::safe_url_regexp) { @@ -57,9 +57,9 @@ sub safeurl ($) { #{{{ else { return 1; } -} #}}} +} -sub htmlize ($$$) { #{{{ +sub htmlize ($$$) { my $page = shift; my $destpage = shift; @@ -68,7 +68,7 @@ sub htmlize ($$$) { #{{{ IkiWiki::preprocess($page, $destpage, shift))); } -sub preprocess (@) { #{{{ +sub preprocess (@) { return "" unless @_; my %params=@_; my $key=shift; @@ -230,9 +230,9 @@ sub preprocess (@) { #{{{ } return ""; -} # }}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; my $destpage=$params{destpage}; @@ -260,9 +260,9 @@ sub pagetemplate (@) { #{{{ $template->param($field => htmlize($page, $destpage, $pagestate{$page}{meta}{$field})); } } -} # }}} +} -sub match { #{{{ +sub match { my $field=shift; my $page=shift; @@ -288,28 +288,28 @@ sub match { #{{{ else { return IkiWiki::FailReason->new("$page does not have a $field"); } -} #}}} +} package IkiWiki::PageSpec; -sub match_title ($$;@) { #{{{ +sub match_title ($$;@) { IkiWiki::Plugin::meta::match("title", @_); -} #}}} +} -sub match_author ($$;@) { #{{{ +sub match_author ($$;@) { IkiWiki::Plugin::meta::match("author", @_); -} #}}} +} -sub match_authorurl ($$;@) { #{{{ +sub match_authorurl ($$;@) { IkiWiki::Plugin::meta::match("authorurl", @_); -} #}}} +} -sub match_license ($$;@) { #{{{ +sub match_license ($$;@) { IkiWiki::Plugin::meta::match("license", @_); -} #}}} +} -sub match_copyright ($$;@) { #{{{ +sub match_copyright ($$;@) { IkiWiki::Plugin::meta::match("copyright", @_); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/mirrorlist.pm b/IkiWiki/Plugin/mirrorlist.pm index aab60c435..b726386f6 100644 --- a/IkiWiki/Plugin/mirrorlist.pm +++ b/IkiWiki/Plugin/mirrorlist.pm @@ -5,12 +5,12 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "mirrorlist", call => \&getsetup); hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -23,9 +23,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $template=$params{template}; @@ -34,9 +34,9 @@ sub pagetemplate (@) { #{{{ $value.=mirrorlist($params{page}); $template->param(extrafooter => $value); } -} # }}} +} -sub mirrorlist ($) { #{{{ +sub mirrorlist ($) { my $page=shift; return "

". (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")). @@ -49,6 +49,6 @@ sub mirrorlist ($) { #{{{ } keys %{$config{mirrorlist}} ). "

"; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index 3a8b267a3..38abb9a07 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -10,7 +10,7 @@ use Date::Format qw(time2str); my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate sha1sums -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "monotone", call => \&checkconfig); hook(type => "getsetup", id => "monotone", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -23,9 +23,9 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (!defined($config{mtnrootdir})) { $config{mtnrootdir} = $config{srcdir}; } @@ -61,9 +61,9 @@ sub checkconfig () { #{{{ wrappermode => (defined $config{mtn_wrappermode} ? $config{mtn_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -117,9 +117,9 @@ sub getsetup () { #{{{ safe => 0, # path rebuild => 0, }, -} #}}} +} -sub get_rev () { #{{{ +sub get_rev () { my $sha1 = `mtn --root=$config{mtnrootdir} automate get_base_revision_id`; ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now @@ -128,9 +128,9 @@ sub get_rev () { #{{{ } return $sha1; -} #}}} +} -sub get_rev_auto ($) { #{{{ +sub get_rev_auto ($) { my $automator=shift; my @results = $automator->call("get_base_revision_id"); @@ -142,9 +142,9 @@ sub get_rev_auto ($) { #{{{ } return $sha1; -} #}}} +} -sub mtn_merge ($$$$) { #{{{ +sub mtn_merge ($$$$) { my $leftRev=shift; my $rightRev=shift; my $branch=shift; @@ -172,9 +172,9 @@ sub mtn_merge ($$$$) { #{{{ debug("merged $leftRev, $rightRev to make $mergeRev"); return $mergeRev; -} #}}} +} -sub commit_file_to_new_rev ($$$$$$$$) { #{{{ +sub commit_file_to_new_rev ($$$$$$$$) { my $automator=shift; my $wsfilename=shift; my $oldFileID=shift; @@ -219,9 +219,9 @@ sub commit_file_to_new_rev ($$$$$$$$) { #{{{ debug("Added certs for rev: $newRevID"); return $newRevID; -} #}}} +} -sub read_certs ($$) { #{{{ +sub read_certs ($$) { my $automator=shift; my $rev=shift; my @results = $automator->call("certs", $rev); @@ -239,9 +239,9 @@ sub read_certs ($$) { #{{{ } return @ret; -} #}}} +} -sub get_changed_files ($$) { #{{{ +sub get_changed_files ($$) { my $automator=shift; my $rev=shift; @@ -261,9 +261,9 @@ sub get_changed_files ($$) { #{{{ } return @ret; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { chdir $config{srcdir} or error("Cannot chdir to $config{srcdir}: $!"); @@ -278,9 +278,9 @@ sub rcs_update () { #{{{ if (system("mtn", "--root=$config{mtnrootdir}", "update", "--quiet") != 0) { debug("monotone update failed"); } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { my $file=shift; chdir $config{srcdir} @@ -289,9 +289,9 @@ sub rcs_prepedit ($) { #{{{ # For monotone, return the revision of the file when # editing begins. return get_rev(); -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { # Tries to commit the page; returns undef on _success_ and # a version of the page with the rcs's conflict markers on failure. # The file is relative to the srcdir. @@ -434,7 +434,7 @@ sub rcs_commit ($$$;$$) { #{{{ } return undef # success -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -466,7 +466,7 @@ sub rcs_commit_staged ($$$) { } } -sub rcs_add ($) { #{{{ +sub rcs_add ($) { my $file=shift; chdir $config{srcdir} @@ -476,9 +476,9 @@ sub rcs_add ($) { #{{{ $file) != 0) { error("Monotone add failed"); } -} #}}} +} -sub rcs_remove ($) { # {{{ +sub rcs_remove ($) { my $file = shift; chdir $config{srcdir} @@ -495,9 +495,9 @@ sub rcs_remove ($) { # {{{ $file) != 0) { error("Monotone remove failed"); } -} #}}} +} -sub rcs_rename ($$) { # {{{ +sub rcs_rename ($$) { my ($src, $dest) = @_; chdir $config{srcdir} @@ -507,9 +507,9 @@ sub rcs_rename ($$) { # {{{ $src, $dest) != 0) { error("Monotone rename failed"); } -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { my $num=shift; my @ret; @@ -614,9 +614,9 @@ sub rcs_recentchanges ($) { #{{{ $automator->close(); return @ret; -} #}}} +} -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { my $rev=shift; my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint @@ -638,9 +638,9 @@ sub rcs_diff ($) { #{{{ else { return join("", @lines); } -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my $file=shift; chdir $config{srcdir} @@ -690,6 +690,6 @@ sub rcs_getctime ($) { #{{{ $date=str2time($date, 'UTC'); debug("found ctime ".localtime($date)." for $file"); return $date; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/more.pm b/IkiWiki/Plugin/more.pm index 4484441c3..f1216ad3d 100644 --- a/IkiWiki/Plugin/more.pm +++ b/IkiWiki/Plugin/more.pm @@ -7,20 +7,20 @@ use IkiWiki 2.00; my $linktext = gettext("more"); -sub import { #{{{ +sub import { hook(type => "getsetup", id => "more", call => \&getsetup); hook(type => "preprocess", id => "more", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{linktext} = $linktext unless defined $params{linktext}; diff --git a/IkiWiki/Plugin/norcs.pm b/IkiWiki/Plugin/norcs.pm index 58c26b633..bfe84c0e1 100644 --- a/IkiWiki/Plugin/norcs.pm +++ b/IkiWiki/Plugin/norcs.pm @@ -6,7 +6,7 @@ use warnings; use strict; use IkiWiki; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "norcs", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); @@ -18,51 +18,51 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin rebuild => 0, }, -} #}}} +} -sub rcs_update () { #{{{ -} #}}} +sub rcs_update () { +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { return "" -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { my ($file, $message, $rcstoken, $user, $ipaddr) = @_; return undef # success -} #}}} +} -sub rcs_commit_staged ($$$) { #{{{ +sub rcs_commit_staged ($$$) { my ($message, $user, $ipaddr)=@_; return undef # success -} #}}} +} -sub rcs_add ($) { #{{{ -} #}}} +sub rcs_add ($) { +} -sub rcs_remove ($) { #{{{ -} #}}} +sub rcs_remove ($) { +} -sub rcs_rename ($$) { #{{{ -} #}}} +sub rcs_rename ($$) { +} -sub rcs_recentchanges ($) { #{{{ -} #}}} +sub rcs_recentchanges ($) { +} -sub rcs_diff ($) { #{{{ -} #}}} +sub rcs_diff ($) { +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { error gettext("getctime not implemented"); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/opendiscussion.pm b/IkiWiki/Plugin/opendiscussion.pm index 96a74aee8..95220d7b3 100644 --- a/IkiWiki/Plugin/opendiscussion.pm +++ b/IkiWiki/Plugin/opendiscussion.pm @@ -5,20 +5,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "opendiscussion", call => \&getsetup); hook(type => "canedit", id => "opendiscussion", call => \&canedit); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub canedit ($$) { #{{{ +sub canedit ($$) { my $page=shift; my $cgi=shift; my $session=shift; @@ -26,6 +26,6 @@ sub canedit ($$) { #{{{ my $discussion=gettext("discussion"); return "" if $page=~/(\/|^)\Q$discussion\E$/; return undef; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index f12cbdaa3..2933c9ed9 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -6,22 +6,22 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getopt", id => "openid", call => \&getopt); hook(type => "getsetup", id => "openid", call => \&getsetup); hook(type => "auth", id => "openid", call => \&auth); hook(type => "formbuilder_setup", id => "openid", call => \&formbuilder_setup, last => 1); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); GetOptions("openidsignup=s" => \$config{openidsignup}); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -34,9 +34,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; @@ -92,7 +92,7 @@ sub formbuilder_setup (@) { #{{{ } } -sub validate ($$$;$) { #{{{ +sub validate ($$$;$) { my $q=shift; my $session=shift; my $openid_url=shift; @@ -121,9 +121,9 @@ sub validate ($$$;$) { #{{{ # eventually bounce them back to auth() IkiWiki::redirect($q, $check_url); exit 0; -} #}}} +} -sub auth ($$) { #{{{ +sub auth ($$) { my $q=shift; my $session=shift; @@ -147,9 +147,9 @@ sub auth ($$) { #{{{ # myopenid.com affiliate support validate($q, $session, $q->param('openid_identifier')); } -} #}}} +} -sub getobj ($$) { #{{{ +sub getobj ($$) { my $q=shift; my $session=shift; @@ -178,13 +178,13 @@ sub getobj ($$) { #{{{ consumer_secret => sub { return shift()+$secret }, required_root => $config{cgiurl}, ); -} #}}} +} package IkiWiki; # This is not used by this plugin, but this seems the best place to put it. # Used elsewhere to pretty-display the name of an openid user. -sub openiduser ($) { #{{{ +sub openiduser ($) { my $user=shift; if ($user =~ m!^https?://! && diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 32cbc5dd5..8e9ab0ff4 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -6,20 +6,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "orphans", call => \&getsetup); hook(type => "preprocess", id => "orphans", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; @@ -58,6 +58,6 @@ sub preprocess (@) { #{{{ "" } sort @orphans). "\n"; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/otl.pm b/IkiWiki/Plugin/otl.pm index ef76d6215..280b19db0 100644 --- a/IkiWiki/Plugin/otl.pm +++ b/IkiWiki/Plugin/otl.pm @@ -7,22 +7,22 @@ use strict; use IkiWiki 2.00; use open qw{:utf8 :std}; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "otl", call => \&getsetup); hook(type => "filter", id => "otl", call => \&filter); hook(type => "htmlize", id => "otl", call => \&htmlize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} -sub filter (@) { #{{{ +sub filter (@) { my %params=@_; # Munge up check boxes to look a little bit better. This is a hack. @@ -34,9 +34,9 @@ sub filter (@) { #{{{ $params{content}=~s/^(\s*)\[_\]\s/${1}$unchecked /mg; return $params{content}; -} # }}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; # Can't use open2 since otl2html doesn't play nice with buffering. @@ -95,6 +95,6 @@ sub htmlize (@) { #{{{ $ret=~s/.*//s; $ret=~s/ EODIV -} # }}} +} -sub format(@) { #{{{ +sub format(@) { my %params = @_; # If HTMLScrubber has removed the style attribute, then bring it back @@ -74,6 +74,6 @@ sub format(@) { #{{{ $params{content} =~ s!
($percentage_pattern)
!
$1
!g; return $params{content}; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/rawhtml.pm b/IkiWiki/Plugin/rawhtml.pm index 74ca13f3b..73093439d 100644 --- a/IkiWiki/Plugin/rawhtml.pm +++ b/IkiWiki/Plugin/rawhtml.pm @@ -6,17 +6,17 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "rawhtml", call => \&getsetup); $config{wiki_file_prune_regexps} = [ grep { !m/\\\.x\?html\?\$/ } @{$config{wiki_file_prune_regexps}} ]; -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # changes file types }, -} #}}} +} 1 diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 4d7023c1c..12577e9ef 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -7,16 +7,16 @@ use IkiWiki 2.00; use Encode; use HTML::Entities; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "recentchanges", call => \&getsetup); hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig); hook(type => "refresh", id => "recentchanges", call => \&refresh); hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate); hook(type => "htmlize", id => "_change", call => \&htmlize); hook(type => "cgi", id => "recentchanges", call => \&cgi); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -36,14 +36,14 @@ sub getsetup () { #{{{ safe => 1, rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage}; $config{recentchangesnum}=100 unless defined $config{recentchangesnum}; -} #}}} +} -sub refresh ($) { #{{{ +sub refresh ($) { my %seen; # add new changes @@ -57,10 +57,10 @@ sub refresh ($) { #{{{ unlink($config{srcdir}.'/'.$pagesources{$page}); } } -} #}}} +} # Enable the recentchanges link on wiki pages. -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $template=$params{template}; my $page=$params{page}; @@ -71,15 +71,15 @@ sub pagetemplate (@) { #{{{ $template->param(recentchangesurl => urlto($config{recentchangespage}, $page)); $template->param(have_actions => 1); } -} #}}} +} # Pages with extension _change have plain html markup, pass through. -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; return $params{content}; -} #}}} +} -sub cgi ($) { #{{{ +sub cgi ($) { my $cgi=shift; if (defined $cgi->param('do') && $cgi->param('do') eq "recentchanges_link") { # This is a link from a change page to some @@ -112,7 +112,7 @@ sub cgi ($) { #{{{ } } -sub store ($$$) { #{{{ +sub store ($$$) { my $change=shift; my $page="$config{recentchangespage}/change_".titlepage($change->{rev}); @@ -192,6 +192,6 @@ sub store ($$$) { #{{{ utime $change->{when}, $change->{when}, "$config{srcdir}/$file"; return $page; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm index 08cec3f5a..4dea9c26b 100644 --- a/IkiWiki/Plugin/recentchangesdiff.pm +++ b/IkiWiki/Plugin/recentchangesdiff.pm @@ -8,22 +8,22 @@ use HTML::Entities; my $maxlines=200; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "recentchangesdiff", call => \&getsetup); hook(type => "pagetemplate", id => "recentchangesdiff", call => \&pagetemplate); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $template=$params{template}; if ($config{rcs} && exists $params{rev} && length $params{rev} && @@ -46,6 +46,6 @@ sub pagetemplate (@) { #{{{ $template->param(diff => $diff); } } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index dc8f7d538..e5fa8e1a5 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -8,22 +8,22 @@ use IkiWiki 2.00; use POSIX; use Encode; -sub import { #{{{ +sub import { add_underlay("javascript"); hook(type => "getsetup", id => "relativedate", call => \&getsetup); hook(type => "format", id => "relativedate", call => \&format); inject(name => "IkiWiki::displaytime", call => \&mydisplaytime); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; if (! ($params{content}=~s!^()!$1.include_javascript($params{page})!em)) { @@ -31,9 +31,9 @@ sub format (@) { #{{{ $params{content}=include_javascript($params{page}, 1).$params{content}; } return $params{content}; -} # }}} +} -sub include_javascript ($;$) { #{{{ +sub include_javascript ($;$) { my $page=shift; my $absolute=shift; @@ -41,9 +41,9 @@ sub include_javascript ($;$) { #{{{ '" type="text/javascript" charset="utf-8">'."\n". ''; -} #}}} +} -sub mydisplaytime ($;$) { #{{{ +sub mydisplaytime ($;$) { my $time=shift; my $format=shift; @@ -55,6 +55,6 @@ sub mydisplaytime ($;$) { #{{{ return ''. IkiWiki::formattime($time, $format).''; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm index c512b3b97..781501662 100644 --- a/IkiWiki/Plugin/remove.pm +++ b/IkiWiki/Plugin/remove.pm @@ -5,23 +5,23 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "remove", call => \&getsetup); hook(type => "formbuilder_setup", id => "remove", call => \&formbuilder_setup); hook(type => "formbuilder", id => "remove", call => \&formbuilder); hook(type => "sessioncgi", id => "remove", call => \&sessioncgi); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub check_canremove ($$$) { #{{{ +sub check_canremove ($$$) { my $page=shift; my $q=shift; my $session=shift; @@ -54,9 +54,9 @@ sub check_canremove ($$$) { #{{{ error("renaming of attachments is not allowed"); } } -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; my $q=$params{cgi}; @@ -67,9 +67,9 @@ sub formbuilder_setup (@) { #{{{ push @{$params{buttons}}, "Remove" if $form->field("do") eq "edit"; $form->tmpl_param("field-remove" => ''); } -} #}}} +} -sub confirmation_form ($$) { #{{{ +sub confirmation_form ($$) { my $q=shift; my $session=shift; @@ -90,9 +90,9 @@ sub confirmation_form ($$) { #{{{ $f->field(name => "do", type => "hidden", value => "remove", force => 1); return $f, ["Remove", "Cancel"]; -} #}}} +} -sub removal_confirm ($$@) { #{{{ +sub removal_confirm ($$@) { my $q=shift; my $session=shift; my $attachment=shift; @@ -122,9 +122,9 @@ sub removal_confirm ($$@) { #{{{ IkiWiki::showform($f, $buttons, $session, $q); exit 0; -} #}}} +} -sub postremove ($) { #{{{ +sub postremove ($) { my $session=shift; # Load saved form state and return to edit form. @@ -132,9 +132,9 @@ sub postremove ($) { #{{{ $session->clear("postremove"); IkiWiki::cgi_savesession($session); IkiWiki::cgi($postremove, $session); -} #}}} +} -sub formbuilder (@) { #{{{ +sub formbuilder (@) { my %params=@_; my $form=$params{form}; @@ -154,9 +154,9 @@ sub formbuilder (@) { #{{{ removal_confirm($q, $session, 1, @selected); } } -} #}}} +} -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $q=shift; if ($q->param("do") eq 'remove') { diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index e4201cc94..b1bb15767 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -5,23 +5,23 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "rename", call => \&getsetup); hook(type => "formbuilder_setup", id => "rename", call => \&formbuilder_setup); hook(type => "formbuilder", id => "rename", call => \&formbuilder); hook(type => "sessioncgi", id => "rename", call => \&sessioncgi); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub check_canrename ($$$$$$) { #{{{ +sub check_canrename ($$$$$$) { my $src=shift; my $srcfile=shift; my $dest=shift; @@ -87,9 +87,9 @@ sub check_canrename ($$$$$$) { #{{{ IkiWiki::Plugin::attachment::check_canattach($session, $dest, $srcfile); } } -} #}}} +} -sub rename_form ($$$) { #{{{ +sub rename_form ($$$) { my $q=shift; my $session=shift; my $page=shift; @@ -145,9 +145,9 @@ sub rename_form ($$$) { #{{{ $f->field(name => "attachment", type => "hidden"); return $f, ["Rename", "Cancel"]; -} #}}} +} -sub rename_start ($$$$) { #{{{ +sub rename_start ($$$$) { my $q=shift; my $session=shift; my $attachment=shift; @@ -171,9 +171,9 @@ sub rename_start ($$$$) { #{{{ my ($f, $buttons)=rename_form($q, $session, $page); IkiWiki::showform($f, $buttons, $session, $q); exit 0; -} #}}} +} -sub postrename ($;$$$) { #{{{ +sub postrename ($;$$$) { my $session=shift; my $src=shift; my $dest=shift; @@ -204,9 +204,9 @@ sub postrename ($;$$$) { #{{{ } IkiWiki::cgi_editpage($postrename, $session); -} #}}} +} -sub formbuilder (@) { #{{{ +sub formbuilder (@) { my %params=@_; my $form=$params{form}; @@ -229,11 +229,11 @@ sub formbuilder (@) { #{{{ rename_start($q, $session, 1, $selected[0]); } } -} #}}} +} my $renamesummary; -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; my $q=$params{cgi}; @@ -248,9 +248,9 @@ sub formbuilder_setup (@) { #{{{ $form->tmpl_param(message => $renamesummary); } } -} #}}} +} -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $q=shift; if ($q->param("do") eq 'rename') { @@ -418,9 +418,9 @@ sub sessioncgi ($$) { #{{{ exit 0; } -} #}}} +} -sub renamepage_hook ($$$$) { #{{{ +sub renamepage_hook ($$$$) { my ($page, $src, $dest, $content)=@_; IkiWiki::run_hooks(renamepage => sub { @@ -433,9 +433,9 @@ sub renamepage_hook ($$$$) { #{{{ }); return $content; -}# }}} +} -sub do_rename ($$$) { #{{{ +sub do_rename ($$$) { my $rename=shift; my $q=shift; my $session=shift; @@ -460,9 +460,9 @@ sub do_rename ($$$) { #{{{ } } -} # }}} +} -sub fixlinks ($$$) { #{{{ +sub fixlinks ($$$) { my $rename=shift; my $session=shift; @@ -498,6 +498,6 @@ sub fixlinks ($$$) { #{{{ } return @fixedlinks; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index e40f4888c..cc2130ad5 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -6,16 +6,16 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "search", call => \&getsetup); hook(type => "checkconfig", id => "search", call => \&checkconfig); hook(type => "pagetemplate", id => "search", call => \&pagetemplate); hook(type => "postscan", id => "search", call => \&index); hook(type => "delete", id => "search", call => \&delete); hook(type => "cgi", id => "search", call => \&cgi); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -28,9 +28,9 @@ sub getsetup () { #{{{ safe => 0, # external program rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { foreach my $required (qw(url cgiurl)) { if (! length $config{$required}) { error(sprintf(gettext("Must specify %s when using the search plugin"), $required)); @@ -40,10 +40,10 @@ sub checkconfig () { #{{{ if (! defined $config{omega_cgi}) { $config{omega_cgi}="/usr/lib/cgi-bin/omega/omega"; } -} #}}} +} my $form; -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; my $template=$params{template}; @@ -58,11 +58,11 @@ sub pagetemplate (@) { #{{{ $template->param(searchform => $form); } -} #}}} +} my $scrubber; my $stemmer; -sub index (@) { #{{{ +sub index (@) { my %params=@_; setupfiles(); @@ -146,17 +146,17 @@ sub index (@) { #{{{ $doc->add_term($pageterm); $db->replace_document_by_term($pageterm, $doc); -} #}}} +} -sub delete (@) { #{{{ +sub delete (@) { my $db=xapiandb(); foreach my $page (@_) { my $pageterm=pageterm(pagename($page)); $db->delete_document_by_term($pageterm) if defined $pageterm; } -} #}}} +} -sub cgi ($) { #{{{ +sub cgi ($) { my $cgi=shift; if (defined $cgi->param('P')) { @@ -169,9 +169,9 @@ sub cgi ($) { #{{{ noimageinline => 1, linktext => "Help"); exec($config{omega_cgi}) || error("$config{omega_cgi} failed: $!"); } -} #}}} +} -sub pageterm ($) { #{{{ +sub pageterm ($) { my $page=shift; # 240 is the number used by omindex to decide when to hash an @@ -190,10 +190,10 @@ sub pageterm ($) { #{{{ else { return "U:".$page; } -} #}}} +} my $db; -sub xapiandb () { #{{{ +sub xapiandb () { if (! defined $db) { eval q{ use Search::Xapian; @@ -204,11 +204,11 @@ sub xapiandb () { #{{{ Search::Xapian::DB_CREATE_OR_OPEN()); } return $db; -} #}}} +} { my $setup=0; -sub setupfiles () { #{{{ +sub setupfiles () { if (! $setup and (! -e $config{wikistatedir}."/xapian" || $config{rebuild})) { writefile("omega.conf", $config{wikistatedir}."/xapian", "database_dir .\n". @@ -218,7 +218,7 @@ sub setupfiles () { #{{{ readfile(IkiWiki::template_file("searchquery.tmpl")))); $setup=1; } -} #}}} +} } 1 diff --git a/IkiWiki/Plugin/shortcut.pm b/IkiWiki/Plugin/shortcut.pm index dec8afdb5..33d158d3e 100644 --- a/IkiWiki/Plugin/shortcut.pm +++ b/IkiWiki/Plugin/shortcut.pm @@ -5,21 +5,21 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "shortcut", call => \&getsetup); hook(type => "checkconfig", id => "shortcut", call => \&checkconfig); hook(type => "preprocess", id => "shortcut", call => \&preprocess_shortcut); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (defined $config{srcdir}) { # Preprocess the shortcuts page to get all the available shortcuts # defined before other pages are rendered. @@ -29,9 +29,9 @@ sub checkconfig () { #{{{ } IkiWiki::preprocess("shortcuts", "shortcuts", readfile($srcfile)); } -} # }}} +} -sub preprocess_shortcut (@) { #{{{ +sub preprocess_shortcut (@) { my %params=@_; if (! defined $params{name} || ! defined $params{url}) { @@ -46,9 +46,9 @@ sub preprocess_shortcut (@) { #{{{ #translators: First parameter is the name of the shortcut, the second #translators: is an URL. return sprintf(gettext("shortcut %s points to %s"), $params{name}, $params{url}); -} # }}} +} -sub shortcut_expand ($$@) { #{{{ +sub shortcut_expand ($$@) { my $url=shift; my $desc=shift; my %params=@_; @@ -85,6 +85,6 @@ sub shortcut_expand ($$@) { #{{{ } return "$desc"; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 9697e1198..746fa93bb 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -8,20 +8,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "sidebar", call => \&getsetup); hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, }, -} #}}} +} -sub sidebar_content ($) { #{{{ +sub sidebar_content ($) { my $page=shift; my $sidebar_page=bestlink($page, "sidebar") || return; @@ -42,9 +42,9 @@ sub sidebar_content ($) { #{{{ IkiWiki::filter($sidebar_page, $page, $content)))); } -} # }}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; @@ -56,6 +56,6 @@ sub pagetemplate (@) { #{{{ $template->param(sidebar => $content); } } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/signinedit.pm b/IkiWiki/Plugin/signinedit.pm index ef7b9b428..321c93ed5 100644 --- a/IkiWiki/Plugin/signinedit.pm +++ b/IkiWiki/Plugin/signinedit.pm @@ -5,21 +5,21 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "signinedit", call => \&getsetup); hook(type => "canedit", id => "signinedit", call => \&canedit, last => 1); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 0, }, -} #}}} +} -sub canedit ($$$) { #{{{ +sub canedit ($$$) { my $page=shift; my $cgi=shift; my $session=shift; @@ -34,6 +34,6 @@ sub canedit ($$$) { #{{{ else { return ""; } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index f844ddb91..96c4a5d6b 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -8,7 +8,7 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getopt", id => "skeleton", call => \&getopt); hook(type => "getsetup", id => "skeleton", call => \&getsetup); hook(type => "checkconfig", id => "skeleton", call => \&checkconfig); @@ -34,13 +34,13 @@ sub import { #{{{ hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup); hook(type => "formbuilder", id => "skeleton", call => \&formbuilder); hook(type => "savestate", id => "skeleton", call => \&savestate); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { debug("skeleton plugin getopt"); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -53,155 +53,155 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { debug("skeleton plugin checkconfig"); -} #}}} +} -sub refresh () { #{{{ +sub refresh () { debug("skeleton plugin refresh"); -} #}}} +} -sub needsbuild () { #{{{ +sub needsbuild () { debug("skeleton plugin needsbuild"); -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; return "skeleton plugin result"; -} # }}} +} -sub filter (@) { #{{{ +sub filter (@) { my %params=@_; debug("skeleton plugin running as filter"); return $params{content}; -} # }}} +} -sub linkify (@) { #{{{ +sub linkify (@) { my %params=@_; debug("skeleton plugin running as linkify"); return $params{content}; -} # }}} +} sub scan (@) { #{{{a my %params=@_; debug("skeleton plugin running as scan"); -} # }}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; debug("skeleton plugin running as htmlize"); return $params{content}; -} # }}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; debug("skeleton plugin running as a sanitizer"); return $params{content}; -} # }}} +} -sub postscan (@) { #{{{ +sub postscan (@) { my %params=@_; debug("skeleton plugin running as postscan"); -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; debug("skeleton plugin running as a formatter"); return $params{content}; -} # }}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; my $template=$params{template}; debug("skeleton plugin running as a pagetemplate hook"); -} # }}} +} -sub templatefile (@) { #{{{ +sub templatefile (@) { my %params=@_; my $page=$params{page}; debug("skeleton plugin running as a templatefile hook"); -} # }}} +} -sub delete (@) { #{{{ +sub delete (@) { my @files=@_; debug("skeleton plugin told that files were deleted: @files"); -} #}}} +} -sub change (@) { #{{{ +sub change (@) { my @files=@_; debug("skeleton plugin told that changed files were rendered: @files"); -} #}}} +} -sub cgi ($) { #{{{ +sub cgi ($) { my $cgi=shift; debug("skeleton plugin running in cgi"); -} #}}} +} -sub auth ($$) { #{{{ +sub auth ($$) { my $cgi=shift; my $session=shift; debug("skeleton plugin running in auth"); -} #}}} +} -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $cgi=shift; my $session=shift; debug("skeleton plugin running in sessioncgi"); -} #}}} +} -sub canedit ($$$) { #{{{ +sub canedit ($$$) { my $page=shift; my $cgi=shift; my $session=shift; debug("skeleton plugin running in canedit"); -} #}}} +} -sub editcontent ($$$) { #{{{ +sub editcontent ($$$) { my %params=@_; debug("skeleton plugin running in editcontent"); return $params{content}; -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; debug("skeleton plugin running in formbuilder_setup"); -} # }}} +} -sub formbuilder (@) { #{{{ +sub formbuilder (@) { my %params=@_; debug("skeleton plugin running in formbuilder"); -} # }}} +} -sub savestate () { #{{{ +sub savestate () { debug("skeleton plugin running in savestate"); -} #}}} +} 1 diff --git a/IkiWiki/Plugin/smiley.pm b/IkiWiki/Plugin/smiley.pm index 2633b1ea1..70b8cef74 100644 --- a/IkiWiki/Plugin/smiley.pm +++ b/IkiWiki/Plugin/smiley.pm @@ -8,13 +8,13 @@ use IkiWiki 2.00; my %smileys; my $smiley_regexp; -sub import { #{{{ +sub import { add_underlay("smiley"); hook(type => "getsetup", id => "smiley", call => \&getsetup); hook(type => "sanitize", id => "smiley", call => \&sanitize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -22,9 +22,9 @@ sub getsetup () { #{{{ # removes the smileys, which would break links rebuild => 1, }, -} #}}} +} -sub build_regexp () { #{{{ +sub build_regexp () { my $list=readfile(srcfile("smileys.mdwn")); while ($list =~ m/^\s*\*\s+\\\\([^\s]+)\s+\[\[([^]]+)\]\]/mg) { my $smiley=$1; @@ -50,9 +50,9 @@ sub build_regexp () { #{{{ $smiley_regexp='('.join('|', map { quotemeta } reverse sort keys %smileys).')'; #debug($smiley_regexp); -} #}}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; build_regexp() unless defined $smiley_regexp; @@ -95,6 +95,6 @@ MATCH: while (m{(?:^|(?<=\s|>))(\\?)$smiley_regexp(?:(?=\s|<)|$)}g) { } return $_; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/sparkline.pm b/IkiWiki/Plugin/sparkline.pm index 901c2f683..dca755c63 100644 --- a/IkiWiki/Plugin/sparkline.pm +++ b/IkiWiki/Plugin/sparkline.pm @@ -14,20 +14,20 @@ my %locmap=( left => 'TEXT_LEFT', ); -sub import { #{{{ +sub import { hook(type => "getsetup", id => "sparkline", call => \&getsetup); hook(type => "preprocess", id => "sparkline", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; my $php; @@ -166,6 +166,6 @@ sub preprocess (@) { #{{{ } return 'graph'; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/svn.pm b/IkiWiki/Plugin/svn.pm index d738720be..fe55e7d08 100644 --- a/IkiWiki/Plugin/svn.pm +++ b/IkiWiki/Plugin/svn.pm @@ -6,7 +6,7 @@ use strict; use IkiWiki; use POSIX qw(setlocale LC_CTYPE); -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "svn", call => \&checkconfig); hook(type => "getsetup", id => "svn", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -19,9 +19,9 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (! defined $config{svnpath}) { $config{svnpath}="trunk"; } @@ -37,9 +37,9 @@ sub checkconfig () { #{{{ wrappermode => (defined $config{svn_wrappermode} ? $config{svn_wrappermode} : "04755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -87,7 +87,7 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} # svn needs LC_CTYPE set to a UTF-8 locale, so try to find one. Any will do. sub find_lc_ctype() { @@ -107,27 +107,27 @@ sub find_lc_ctype() { # fallback to the current locale return $current; -} # }}} +} $ENV{LC_CTYPE} = $ENV{LC_CTYPE} || find_lc_ctype(); -sub svn_info ($$) { #{{{ +sub svn_info ($$) { my $field=shift; my $file=shift; my $info=`LANG=C svn info $file`; my ($ret)=$info=~/^$field: (.*)$/m; return $ret; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { if (-d "$config{srcdir}/.svn") { if (system("svn", "update", "--quiet", $config{srcdir}) != 0) { warn("svn update failed\n"); } } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { # Prepares to edit a file under revision control. Returns a token # that must be passed into rcs_commit when the file is ready # for committing. @@ -140,9 +140,9 @@ sub rcs_prepedit ($) { #{{{ my $rev=svn_info("Revision", "$config{srcdir}/$file"); return defined $rev ? $rev : ""; } -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { # Tries to commit the page; returns undef on _success_ and # a version of the page with the rcs's conflict markers on failure. # The file is relative to the srcdir. @@ -185,7 +185,7 @@ sub rcs_commit ($$$;$$) { #{{{ } } return undef # success -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -209,7 +209,7 @@ sub rcs_commit_staged ($$$) { return undef # success } -sub rcs_add ($) { #{{{ +sub rcs_add ($) { # filename is relative to the root of the srcdir my $file=shift; @@ -224,9 +224,9 @@ sub rcs_add ($) { #{{{ warn("svn add failed\n"); } } -} #}}} +} -sub rcs_remove ($) { #{{{ +sub rcs_remove ($) { # filename is relative to the root of the srcdir my $file=shift; @@ -235,9 +235,9 @@ sub rcs_remove ($) { #{{{ warn("svn rm failed\n"); } } -} #}}} +} -sub rcs_rename ($$) { #{{{ +sub rcs_rename ($$) { # filenames relative to the root of the srcdir my ($src, $dest)=@_; @@ -258,9 +258,9 @@ sub rcs_rename ($$) { #{{{ warn("svn rename failed\n"); } } -} #}}} +} -sub rcs_recentchanges ($) { #{{{ +sub rcs_recentchanges ($) { my $num=shift; my @ret; @@ -341,14 +341,14 @@ sub rcs_recentchanges ($) { #{{{ } return @ret; -} #}}} +} -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { my $rev=IkiWiki::possibly_foolish_untaint(int(shift)); return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`; -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my $file=shift; my $svn_log_infoline=qr/^r\d+\s+\|\s+[^\s]+\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/; @@ -376,6 +376,6 @@ sub rcs_getctime ($) { #{{{ $date=str2time($date); debug("found ctime ".localtime($date)." for $file"); return $date; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/table.pm b/IkiWiki/Plugin/table.pm index e782fc238..b6f53f607 100644 --- a/IkiWiki/Plugin/table.pm +++ b/IkiWiki/Plugin/table.pm @@ -6,20 +6,20 @@ use strict; use Encode; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "table", call => \&getsetup); hook(type => "preprocess", id => "table", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params =( format => 'auto', header => 'row', @@ -102,16 +102,16 @@ sub preprocess (@) { #{{{ else { return $html; } -} #}}} +} -sub is_dsv_data ($) { #{{{ +sub is_dsv_data ($) { my $text = shift; my ($line) = split(/\n/, $text); return $line =~ m{.+\|}; } -sub split_csv ($$) { #{{{ +sub split_csv ($$) { my @text_lines = split(/\n/, shift); my $delimiter = shift; @@ -137,9 +137,9 @@ sub split_csv ($$) { #{{{ } return @data; -} #}}} +} -sub split_dsv ($$) { #{{{ +sub split_dsv ($$) { my @text_lines = split(/\n/, shift); my $delimiter = shift; $delimiter="|" unless defined $delimiter; @@ -150,9 +150,9 @@ sub split_dsv ($$) { #{{{ } return @data; -} #}}} +} -sub genrow ($@) { #{{{ +sub genrow ($@) { my %params=%{shift()}; my $elt = shift; my @data = @_; @@ -190,6 +190,6 @@ sub genrow ($@) { #{{{ push @ret, "\t\t"; return @ret; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index d725ef9b3..ecc77cbb1 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -8,22 +8,22 @@ use IkiWiki 2.00; my %tags; -sub import { #{{{ +sub import { hook(type => "getopt", id => "tag", call => \&getopt); hook(type => "getsetup", id => "tag", call => \&getsetup); hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1); hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1); hook(type => "pagetemplate", id => "tag", call => \&pagetemplate); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); GetOptions("tagbase=s" => \$config{tagbase}); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -36,9 +36,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub tagpage ($) { #{{{ +sub tagpage ($) { my $tag=shift; if ($tag !~ m{^\.?/} && @@ -48,18 +48,18 @@ sub tagpage ($) { #{{{ } return $tag; -} #}}} +} -sub taglink ($$$;@) { #{{{ +sub taglink ($$$;@) { my $page=shift; my $destpage=shift; my $tag=shift; my %opts=@_; return htmllink($page, $destpage, tagpage($tag), %opts); -} #}}} +} -sub preprocess_tag (@) { #{{{ +sub preprocess_tag (@) { if (! @_) { return ""; } @@ -77,9 +77,9 @@ sub preprocess_tag (@) { #{{{ } return ""; -} # }}} +} -sub preprocess_taglink (@) { #{{{ +sub preprocess_taglink (@) { if (! @_) { return ""; } @@ -102,9 +102,9 @@ sub preprocess_taglink (@) { #{{{ grep { $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview' } keys %params); -} # }}} +} -sub pagetemplate (@) { #{{{ +sub pagetemplate (@) { my %params=@_; my $page=$params{page}; my $destpage=$params{destpage}; @@ -123,6 +123,6 @@ sub pagetemplate (@) { #{{{ sort keys %{$tags{$page}}]); } } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm index c980df48f..1b7eb91bf 100644 --- a/IkiWiki/Plugin/template.pm +++ b/IkiWiki/Plugin/template.pm @@ -8,20 +8,20 @@ use IkiWiki 2.00; use HTML::Template; use Encode; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "template", call => \&getsetup); hook(type => "preprocess", id => "template", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; if (! exists $params{id}) { @@ -71,6 +71,6 @@ sub preprocess (@) { #{{{ return IkiWiki::preprocess($params{page}, $params{destpage}, IkiWiki::filter($params{page}, $params{destpage}, $template->output)); -} # }}} +} 1 diff --git a/IkiWiki/Plugin/testpagespec.pm b/IkiWiki/Plugin/testpagespec.pm index 9f9b50f01..a6e94dbbb 100644 --- a/IkiWiki/Plugin/testpagespec.pm +++ b/IkiWiki/Plugin/testpagespec.pm @@ -5,20 +5,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "testpagespec", call => \&getsetup); hook(type => "preprocess", id => "testpagespec", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; foreach my $param (qw{match pagespec}) { @@ -37,6 +37,6 @@ sub preprocess (@) { #{{{ else { return "no match: $ret"; } -} # }}} +} 1 diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm index 661d97b1f..57b23147e 100644 --- a/IkiWiki/Plugin/teximg.pm +++ b/IkiWiki/Plugin/teximg.pm @@ -21,12 +21,12 @@ EOPREFIX my $default_postfix = '\\end{document}'; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "teximg", call => \&getsetup); hook(type => "preprocess", id => "teximg", call => \&preprocess); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -52,9 +52,9 @@ sub getsetup () { #{{{ safe => 0, # Not sure how secure LaTeX is... rebuild => 1, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params = @_; my $height = $params{height}; @@ -76,9 +76,9 @@ sub preprocess (@) { #{{{ else { error gettext("code includes disallowed latex commands") } -} #}}} +} -sub check_height ($) { #{{{ +sub check_height ($) { # Since latex doesn't support unlimited scaling this function # returns the closest supported size. my $height =shift; @@ -95,9 +95,9 @@ sub check_height ($) { #{{{ } } return $ret; -} #}}} +} -sub create ($$$) { #{{{ +sub create ($$$) { # This function calls the image generating function and returns # the for the generated image. my $code = shift; @@ -127,9 +127,9 @@ sub create ($$$) { #{{{ else { error qq{}.gettext("failed to generate image from code").""; } -} #}}} +} -sub gen_image ($$$$) { #{{{ +sub gen_image ($$$$) { # Actually creates the image. my $code = shift; my $height = shift; @@ -180,18 +180,18 @@ sub gen_image ($$$$) { #{{{ return 0; } -} #}}} +} -sub create_tmp_dir ($) { #{{{ +sub create_tmp_dir ($) { # Create a temp directory, it will be removed when ikiwiki exits. my $base = shift; my $template = $base.".XXXXXXXXXX"; my $tmpdir = tempdir($template, TMPDIR => 1, CLEANUP => 1); return $tmpdir; -} #}}} +} -sub check ($) { #{{{ +sub check ($) { # Check if the code is ok my $code = shift; @@ -219,6 +219,6 @@ sub check ($) { #{{{ } } return 1; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/textile.pm b/IkiWiki/Plugin/textile.pm index bbd282f0c..d1b927b74 100644 --- a/IkiWiki/Plugin/textile.pm +++ b/IkiWiki/Plugin/textile.pm @@ -9,26 +9,26 @@ use strict; use IkiWiki 2.00; use Encode; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "textile", call => \&getsetup); hook(type => "htmlize", id => "txtl", call => \&htmlize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; my $content = decode_utf8(encode_utf8($params{content})); eval q{use Text::Textile}; return $content if $@; return Text::Textile::textile($content); -} # }}} +} 1 diff --git a/IkiWiki/Plugin/tla.pm b/IkiWiki/Plugin/tla.pm index 0a5c161b2..f4b20a6ec 100644 --- a/IkiWiki/Plugin/tla.pm +++ b/IkiWiki/Plugin/tla.pm @@ -5,7 +5,7 @@ use warnings; use strict; use IkiWiki; -sub import { #{{{ +sub import { hook(type => "checkconfig", id => "tla", call => \&checkconfig); hook(type => "getsetup", id => "tla", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -18,18 +18,18 @@ sub import { #{{{ hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (defined $config{tla_wrapper} && length $config{tla_wrapper}) { push @{$config{wrappers}}, { wrapper => $config{tla_wrapper}, wrappermode => (defined $config{tla_wrappermode} ? $config{tla_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # rcs plugin @@ -63,9 +63,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub quiet_system (@) { #{{{ +sub quiet_system (@) { # See Debian bug #385939. open (SAVEOUT, ">&STDOUT"); close STDOUT; @@ -75,17 +75,17 @@ sub quiet_system (@) { #{{{ open (STDOUT, ">&SAVEOUT"); close SAVEOUT; return $ret; -} #}}} +} -sub rcs_update () { #{{{ +sub rcs_update () { if (-d "$config{srcdir}/{arch}") { if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) { warn("tla replay failed\n"); } } -} #}}} +} -sub rcs_prepedit ($) { #{{{ +sub rcs_prepedit ($) { my $file=shift; if (-d "$config{srcdir}/{arch}") { @@ -94,9 +94,9 @@ sub rcs_prepedit ($) { #{{{ my $rev=`tla tree-id $config{srcdir}`; return defined $rev ? $rev : ""; } -} #}}} +} -sub rcs_commit ($$$;$$) { #{{{ +sub rcs_commit ($$$;$$) { my $file=shift; my $message=shift; my $rcstoken=shift; @@ -135,7 +135,7 @@ sub rcs_commit ($$$;$$) { #{{{ } } return undef # success -} #}}} +} sub rcs_commit_staged ($$$) { # Commits all staged changes. Changes can be staged using rcs_add, @@ -145,7 +145,7 @@ sub rcs_commit_staged ($$$) { error("rcs_commit_staged not implemented for tla"); # TODO } -sub rcs_add ($) { #{{{ +sub rcs_add ($) { my $file=shift; if (-d "$config{srcdir}/{arch}") { @@ -153,19 +153,19 @@ sub rcs_add ($) { #{{{ warn("tla add failed\n"); } } -} #}}} +} -sub rcs_remove ($) { # {{{ +sub rcs_remove ($) { my $file = shift; error("rcs_remove not implemented for tla"); # TODO -} #}}} +} sub rcs_rename ($$) { # {{{a my ($src, $dest) = @_; error("rcs_rename not implemented for tla"); # TODO -} #}}} +} sub rcs_recentchanges ($) { my $num=shift; @@ -239,7 +239,7 @@ sub rcs_recentchanges ($) { return @ret; } -sub rcs_diff ($) { #{{{ +sub rcs_diff ($) { my $rev=shift; my $logs = `tla logs -d $config{srcdir}`; my @changesets = reverse split(/\n/, $logs); @@ -251,9 +251,9 @@ sub rcs_diff ($) { #{{{ my $revminusone = $changesets[$i+1]; return `tla diff -d $config{srcdir} $revminusone`; -} #}}} +} -sub rcs_getctime ($) { #{{{ +sub rcs_getctime ($) { my $file=shift; eval q{use Date::Parse}; error($@) if $@; @@ -281,6 +281,6 @@ sub rcs_getctime ($) { #{{{ my $date=str2time($sdate, 'UTC'); debug("found ctime ".localtime($date)." for $file"); return $date; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm index dff9d9aa5..460837b1d 100644 --- a/IkiWiki/Plugin/toc.pm +++ b/IkiWiki/Plugin/toc.pm @@ -7,23 +7,23 @@ use strict; use IkiWiki 2.00; use HTML::Parser; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "toc", call => \&getsetup); hook(type => "preprocess", id => "toc", call => \&preprocess); hook(type => "format", id => "toc", call => \&format); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} my %tocpages; -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; if ($params{page} eq $params{destpage}) { @@ -40,9 +40,9 @@ sub preprocess (@) { #{{{ # right. return ""; } -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; my $content=$params{content}; diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 657d8d3c2..967b07fcc 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -5,7 +5,7 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { add_underlay("javascript"); hook(type => "getsetup", id => "toggle", call => \&getsetup); hook(type => "preprocess", id => "toggle", @@ -13,17 +13,17 @@ sub import { #{{{ hook(type => "preprocess", id => "toggleable", call => \&preprocess_toggleable); hook(type => "format", id => "toggle", call => \&format); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub genid ($$) { #{{{ +sub genid ($$) { my $page=shift; my $id=shift; @@ -35,16 +35,16 @@ sub genid ($$) { #{{{ $id="id$id"; } return $id; -} #}}} +} -sub preprocess_toggle (@) { #{{{ +sub preprocess_toggle (@) { my %params=(id => "default", text => "more", @_); my $id=genid($params{page}, $params{id}); return "$params{text}"; -} # }}} +} -sub preprocess_toggleable (@) { #{{{ +sub preprocess_toggleable (@) { my %params=(id => "default", text => "", open => "no", @_); # Preprocess the text to expand any preprocessor directives @@ -61,9 +61,9 @@ sub preprocess_toggleable (@) { #{{{ my ($indent)=$params{text}=~/( +)$/; $indent="" unless defined $indent; return "
\n\n$params{text}\n$indent
"; -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; if ($params{content}=~s!(
\s*)
!$1!g) { @@ -74,9 +74,9 @@ sub format (@) { #{{{ } } return $params{content}; -} # }}} +} -sub include_javascript ($;$) { #{{{ +sub include_javascript ($;$) { my $page=shift; my $absolute=shift; @@ -84,6 +84,6 @@ sub include_javascript ($;$) { #{{{ '" type="text/javascript" charset="utf-8">'."\n". ''; -} #}}} +} 1 diff --git a/IkiWiki/Plugin/txt.pm b/IkiWiki/Plugin/txt.pm index e157bf07e..d65bb2036 100644 --- a/IkiWiki/Plugin/txt.pm +++ b/IkiWiki/Plugin/txt.pm @@ -24,13 +24,13 @@ sub import { } } -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, -} #}}} +} # We use filter to convert raw text to HTML # (htmlize is called after other plugins insert HTML) diff --git a/IkiWiki/Plugin/typography.pm b/IkiWiki/Plugin/typography.pm index 27089b390..e395b2143 100644 --- a/IkiWiki/Plugin/typography.pm +++ b/IkiWiki/Plugin/typography.pm @@ -6,20 +6,20 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getopt", id => "typography", call => \&getopt); hook(type => "getsetup", id => "typography", call => \&getsetup); IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); GetOptions("typographyattributes=s" => \$config{typographyattributes}); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { eval q{use Text::Typography}; error($@) if $@; @@ -36,9 +36,9 @@ sub getsetup () { #{{{ safe => 1, rebuild => 1, }, -} #}}} +} -sub sanitize (@) { #{{{ +sub sanitize (@) { my %params=@_; eval q{use Text::Typography}; @@ -46,6 +46,6 @@ sub sanitize (@) { #{{{ my $attributes=defined $config{typographyattributes} ? $config{typographyattributes} : '3'; return Text::Typography::typography($params{content}, $attributes); -} # }}} +} 1 diff --git a/IkiWiki/Plugin/version.pm b/IkiWiki/Plugin/version.pm index 18e9613ae..3526dafde 100644 --- a/IkiWiki/Plugin/version.pm +++ b/IkiWiki/Plugin/version.pm @@ -6,21 +6,21 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "version", call => \&getsetup); hook(type => "needsbuild", id => "version", call => \&needsbuild); hook(type => "preprocess", id => "version", call => \&preprocess); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, rebuild => undef, }, -} #}}} +} -sub needsbuild (@) { #{{{ +sub needsbuild (@) { my $needsbuild=shift; foreach my $page (keys %pagestate) { if (exists $pagestate{$page}{version}{shown}) { @@ -36,11 +36,11 @@ sub needsbuild (@) { #{{{ } } } -} # }}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $pagestate{$params{destpage}}{version}{shown}=$IkiWiki::version; -} # }}} +} 1 diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm index 827ee3099..66dacfde3 100644 --- a/IkiWiki/Plugin/websetup.pm +++ b/IkiWiki/Plugin/websetup.pm @@ -5,15 +5,15 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "websetup", call => \&getsetup); hook(type => "checkconfig", id => "websetup", call => \&checkconfig); hook(type => "sessioncgi", id => "websetup", call => \&sessioncgi); hook(type => "formbuilder_setup", id => "websetup", call => \&formbuilder_setup); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -33,15 +33,15 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, -} #}}} +} -sub checkconfig () { #{{{ +sub checkconfig () { if (! exists $config{websetup_show_unsafe}) { $config{websetup_show_unsafe}=1; } -} #}}} +} -sub formatexample ($$) { #{{{ +sub formatexample ($$) { my $example=shift; my $value=shift; @@ -54,9 +54,9 @@ sub formatexample ($$) { #{{{ else { return ""; } -} #}}} +} -sub showfields ($$$@) { #{{{ +sub showfields ($$$@) { my $form=shift; my $plugin=shift; my $enabled=shift; @@ -207,16 +207,16 @@ sub showfields ($$$@) { #{{{ } return %enabledfields; -} #}}} +} -sub enable_plugin ($) { #{{{ +sub enable_plugin ($) { my $plugin=shift; $config{disable_plugins}=[grep { $_ ne $plugin } @{$config{disable_plugins}}]; push @{$config{add_plugins}}, $plugin; } -sub disable_plugin ($) { #{{{ +sub disable_plugin ($) { my $plugin=shift; if (grep { $_ eq $plugin } @{$config{add_plugins}}) { @@ -227,7 +227,7 @@ sub disable_plugin ($) { #{{{ } } -sub showform ($$) { #{{{ +sub showform ($$) { my $cgi=shift; my $session=shift; @@ -441,9 +441,9 @@ sub showform ($$) { #{{{ } IkiWiki::showform($form, $buttons, $session, $cgi); -} #}}} +} -sub sessioncgi ($$) { #{{{ +sub sessioncgi ($$) { my $cgi=shift; my $session=shift; @@ -451,9 +451,9 @@ sub sessioncgi ($$) { #{{{ showform($cgi, $session); exit; } -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; @@ -464,6 +464,6 @@ sub formbuilder_setup (@) { #{{{ exit; } } -} #}}} +} 1 diff --git a/IkiWiki/Plugin/wikitext.pm b/IkiWiki/Plugin/wikitext.pm index c47ccb7b1..50571e524 100644 --- a/IkiWiki/Plugin/wikitext.pm +++ b/IkiWiki/Plugin/wikitext.pm @@ -6,27 +6,27 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "getsetup", id => "wiki", call => \&getsetup); hook(type => "htmlize", id => "wiki", call => \&htmlize); -} # }}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 0, # format plugin rebuild => undef, }, -} #}}} +} -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; my $content = $params{content}; eval q{use Text::WikiFormat}; return $content if $@; return Text::WikiFormat::format($content, undef, { implicit_links => 0 }); -} # }}} +} 1 diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm index 72668d26a..37b6f2a62 100644 --- a/IkiWiki/Receive.pm +++ b/IkiWiki/Receive.pm @@ -6,21 +6,21 @@ use warnings; use strict; use IkiWiki; -sub getuser () { #{{{ +sub getuser () { my $user=(getpwuid(exists $ENV{CALLER_UID} ? $ENV{CALLER_UID} : $<))[0]; if (! defined $user) { error("cannot determine username for $<"); } return $user; -} #}}} +} -sub trusted () { #{{{ +sub trusted () { my $user=getuser(); return ! ref $config{untrusted_committers} || ! grep { $_ eq $user } @{$config{untrusted_committers}}; -} #}}} +} -sub gen_wrapper () { #{{{ +sub gen_wrapper () { # Test for commits from untrusted committers in the wrapper, to # avoid loading ikiwiki at all for trusted commits. @@ -43,9 +43,9 @@ EOF } EOF return $ret; -} #}}} +} -sub test () { #{{{ +sub test () { exit 0 if trusted(); IkiWiki::lockwiki(); @@ -130,6 +130,6 @@ sub test () { #{{{ } exit 0; -} #}}} +} 1 diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 389063d46..adae9f0d5 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -10,7 +10,7 @@ use Encode; my %backlinks; my $backlinks_calculated=0; -sub calculate_backlinks () { #{{{ +sub calculate_backlinks () { return if $backlinks_calculated; %backlinks=(); foreach my $page (keys %links) { @@ -22,9 +22,9 @@ sub calculate_backlinks () { #{{{ } } $backlinks_calculated=1; -} #}}} +} -sub backlinks ($) { #{{{ +sub backlinks ($) { my $page=shift; calculate_backlinks(); @@ -45,9 +45,9 @@ sub backlinks ($) { #{{{ push @links, { url => $href, page => pagetitle($p_trimmed) }; } return @links; -} #}}} +} -sub genpage ($$) { #{{{ +sub genpage ($$) { my $page=shift; my $content=shift; @@ -131,9 +131,9 @@ sub genpage ($$) { #{{{ }); return $content; -} #}}} +} -sub scan ($) { #{{{ +sub scan ($) { my $file=shift; my $type=pagetype($file); @@ -165,9 +165,9 @@ sub scan ($) { #{{{ else { will_render($file, $file, 1); } -} #}}} +} -sub fast_file_copy (@) { #{{{ +sub fast_file_copy (@) { my $srcfile=shift; my $destfile=shift; my $srcfd=shift; @@ -191,7 +191,7 @@ sub fast_file_copy (@) { #{{{ } } -sub render ($) { #{{{ +sub render ($) { my $file=shift; my $type=pagetype($file); @@ -233,9 +233,9 @@ sub render ($) { #{{{ fast_file_copy($srcfile, $file, $srcfd, @_); }); } -} #}}} +} -sub prune ($) { #{{{ +sub prune ($) { my $file=shift; unlink($file); @@ -243,9 +243,9 @@ sub prune ($) { #{{{ while (rmdir($dir)) { $dir=dirname($dir); } -} #}}} +} -sub refresh () { #{{{ +sub refresh () { # security check, avoid following symlinks in the srcdir path by default my $test=$config{srcdir}; while (length $test) { @@ -507,9 +507,9 @@ sub refresh () { #{{{ if (%rendered) { run_hooks(change => sub { shift->(keys %rendered) }); } -} #}}} +} -sub commandline_render () { #{{{ +sub commandline_render () { lockwiki(); loadindex(); unlockwiki(); @@ -532,6 +532,6 @@ sub commandline_render () { #{{{ print genpage($page, $content); exit 0; -} #}}} +} 1 diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index 77afdd608..6ee112096 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -10,7 +10,7 @@ use IkiWiki; use open qw{:utf8 :std}; use File::Spec; -sub load ($) { # {{{ +sub load ($) { my $setup=IkiWiki::possibly_foolish_untaint(shift); $config{setupfile}=File::Spec->rel2abs($setup); @@ -27,7 +27,7 @@ sub load ($) { # {{{ eval $code; error("$setup: ".$@) if $@; -} #}}} +} sub merge ($) { # Merge setup into existing config and untaint. @@ -71,9 +71,9 @@ sub merge ($) { wrappermode => (defined $config{cgi_wrappermode} ? $config{cgi_wrappermode} : "06755"), }; } -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { # Gets all available setup data from all plugins. Returns an # ordered list of [plugin, setup] pairs. my @ret; @@ -105,9 +105,9 @@ sub getsetup () { #{{{ $config{syslog}=$syslog; return @ret; -} #}}} +} -sub dump ($) { #{{{ +sub dump ($) { my $file=IkiWiki::possibly_foolish_untaint(shift); require IkiWiki::Setup::Standard; diff --git a/IkiWiki/Setup/Automator.pm b/IkiWiki/Setup/Automator.pm index 88e9f3d24..9f2380d52 100644 --- a/IkiWiki/Setup/Automator.pm +++ b/IkiWiki/Setup/Automator.pm @@ -10,20 +10,20 @@ use IkiWiki::UserInfo; use Term::ReadLine; use File::Path; -sub ask ($$) { #{{{ +sub ask ($$) { my ($question, $default)=@_; my $r=Term::ReadLine->new("ikiwiki"); $r->readline($question." ", $default); -} #}}} +} -sub prettydir ($) { #{{{ +sub prettydir ($) { my $dir=shift; $dir=~s/^\Q$ENV{HOME}\E\//~\//; return $dir; -} #}}} +} -sub import (@) { #{{{ +sub import (@) { my $this=shift; IkiWiki::Setup::merge({@_}); @@ -142,6 +142,6 @@ sub import (@) { #{{{ print "To modify settings, edit ".prettydir($config{dumpsetup})." and then run:\n"; print " ikiwiki -setup ".prettydir($config{dumpsetup})."\n"; exit 0; -} #}}} +} 1 diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index e6bff2826..951bcfc56 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -9,11 +9,11 @@ use warnings; use strict; use IkiWiki; -sub import { #{{{ +sub import { IkiWiki::Setup::merge($_[1]); -} #}}} +} -sub dumpline ($$$$) { #{{{ +sub dumpline ($$$$) { my $key=shift; my $value=shift; my $type=shift; @@ -55,9 +55,9 @@ sub dumpline ($$$$) { #{{{ } return "\t$prefix$key => $dumpedvalue,"; -} #}}} +} -sub dumpvalues ($@) { #{{{ +sub dumpvalues ($@) { my $setup=shift; my @ret; while (@_) { @@ -80,9 +80,9 @@ sub dumpvalues ($@) { #{{{ } } return @ret; -} #}}} +} -sub gendump ($) { #{{{ +sub gendump ($) { my $description=shift; my %setup=(%config); my @ret; @@ -112,6 +112,6 @@ sub gendump ($) { #{{{ push @ret, "}"; return @ret; -} #}}} +} 1 diff --git a/IkiWiki/UserInfo.pm b/IkiWiki/UserInfo.pm index dcf99da09..3423dc923 100644 --- a/IkiWiki/UserInfo.pm +++ b/IkiWiki/UserInfo.pm @@ -7,12 +7,12 @@ use strict; use Storable; use IkiWiki; -sub userinfo_retrieve () { #{{{ +sub userinfo_retrieve () { my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") }; return $userinfo; -} #}}} +} -sub userinfo_store ($) { #{{{ +sub userinfo_store ($) { my $userinfo=shift; my $newfile="$config{wikistatedir}/userdb.new"; @@ -26,9 +26,9 @@ sub userinfo_store ($) { #{{{ } } return $ret; -} #}}} +} -sub userinfo_get ($$) { #{{{ +sub userinfo_get ($$) { my $user=shift; my $field=shift; @@ -39,9 +39,9 @@ sub userinfo_get ($$) { #{{{ return ""; } return $userinfo->{$user}->{$field}; -} #}}} +} -sub userinfo_set ($$$) { #{{{ +sub userinfo_set ($$$) { my $user=shift; my $field=shift; my $value=shift; @@ -54,9 +54,9 @@ sub userinfo_set ($$$) { #{{{ $userinfo->{$user}->{$field}=$value; return userinfo_store($userinfo); -} #}}} +} -sub userinfo_setall ($$) { #{{{ +sub userinfo_setall ($$) { my $user=shift; my $info=shift; @@ -66,32 +66,32 @@ sub userinfo_setall ($$) { #{{{ } $userinfo->{$user}=$info; return userinfo_store($userinfo); -} #}}} +} -sub is_admin ($) { #{{{ +sub is_admin ($) { my $user_name=shift; return grep { $_ eq $user_name } @{$config{adminuser}}; -} #}}} +} # XXX deprecated, should be removed eventually -sub get_banned_users () { #{{{ +sub get_banned_users () { my @ret; my $userinfo=userinfo_retrieve(); foreach my $user (keys %{$userinfo}) { push @ret, $user if $userinfo->{$user}->{banned}; } return @ret; -} #}}} +} # XXX deprecated, should be removed eventually -sub set_banned_users (@) { #{{{ +sub set_banned_users (@) { my %banned=map { $_ => 1 } @_; my $userinfo=userinfo_retrieve(); foreach my $user (keys %{$userinfo}) { $userinfo->{$user}->{banned} = $banned{$user}; } return userinfo_store($userinfo); -} #}}} +} 1 diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 31e30ad2e..dd9971a34 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -8,7 +8,7 @@ use File::Spec; use Data::Dumper; use IkiWiki; -sub gen_wrapper () { #{{{ +sub gen_wrapper () { $config{srcdir}=File::Spec->rel2abs($config{srcdir}); $config{destdir}=File::Spec->rel2abs($config{destdir}); my $this=File::Spec->rel2abs($0); @@ -173,6 +173,6 @@ EOF #translators: The parameter is a filename. printf(gettext("successfully generated %s"), $wrapper); print "\n"; -} #}}} +} 1 diff --git a/debian/changelog b/debian/changelog index b884dd596..f7085169c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,7 @@ ikiwiki (2.71) UNRELEASED; urgency=low * rename: Fix double-escaping of page name in edit box. * monotone: When getting the log, tell monotone how many entries we want, rather than closing the pipe, which it dislikes. (thm) + * Coding style change: Remove explcit vim folding markers. -- Joey Hess Mon, 17 Nov 2008 14:02:10 -0500 diff --git a/doc/bugs/Allow_overriding_of_symlink_restriction.mdwn b/doc/bugs/Allow_overriding_of_symlink_restriction.mdwn index 07badd646..efdd9004e 100644 --- a/doc/bugs/Allow_overriding_of_symlink_restriction.mdwn +++ b/doc/bugs/Allow_overriding_of_symlink_restriction.mdwn @@ -34,9 +34,9 @@ Is there a huge objection to this patch? index 990fcaa..0fb78ba 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm - @@ -260,13 +260,15 @@ sub prune ($) { #{{{ + @@ -260,13 +260,15 @@ sub prune ($) { - sub refresh () { #{{{ + sub refresh () { # security check, avoid following symlinks in the srcdir path - my $test=$config{srcdir}; - while (length $test) { @@ -108,7 +108,7 @@ like this being accepted before I bothered. use IkiWiki; +use File::Spec; - sub gen_wrapper () { #{{{ + sub gen_wrapper () { - $config{srcdir}=abs_path($config{srcdir}); - $config{destdir}=abs_path($config{destdir}); - my $this=abs_path($0); diff --git a/doc/bugs/Can__39__t_create_root_page.mdwn b/doc/bugs/Can__39__t_create_root_page.mdwn index 60cbcd530..91c2eae60 100644 --- a/doc/bugs/Can__39__t_create_root_page.mdwn +++ b/doc/bugs/Can__39__t_create_root_page.mdwn @@ -33,7 +33,7 @@ This type of page name (with leading slash) also gets created by the aggregate p index 99cead6..23d9616 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm - @@ -305,9 +305,11 @@ sub cgi_editpage ($$) { #{{{ + @@ -305,9 +305,11 @@ sub cgi_editpage ($$) { my $page=$form->field('page'); $page=possibly_foolish_untaint($page); if (! defined $page || ! length $page || @@ -46,7 +46,7 @@ This type of page name (with leading slash) also gets created by the aggregate p my $baseurl=$config{url}."/".htmlpage($page); - @@ -425,6 +427,7 @@ sub cgi_editpage ($$) { #{{{ + @@ -425,6 +427,7 @@ sub cgi_editpage ($$) { $from ne $form->field('from') || file_pruned($from, $config{srcdir}) || $from=~/^\// || diff --git a/doc/bugs/Insecure_dependency_in_eval_while_running_with_-T_switch.mdwn b/doc/bugs/Insecure_dependency_in_eval_while_running_with_-T_switch.mdwn index 28b48e2c6..c3beb8219 100644 --- a/doc/bugs/Insecure_dependency_in_eval_while_running_with_-T_switch.mdwn +++ b/doc/bugs/Insecure_dependency_in_eval_while_running_with_-T_switch.mdwn @@ -53,7 +53,7 @@ I didn't apply your following old patch against `Ikiwiki.pm` file: + } + + return eval $newpagespec; - } #}}} + } package IkiWiki::PageSpec; @@ -83,7 +83,7 @@ to break the code I distribute in my backport ;) + my $ret=eval possibly_foolish_untaint(pagespec_translate($spec)); return IkiWiki::FailReason->new("syntax error") if $@; return $ret; - } #}}} + } >> Thanks a lot, Joey! It works :) >> diff --git a/doc/bugs/Monotone_rcs_support.mdwn b/doc/bugs/Monotone_rcs_support.mdwn index 3d1388312..8687e7983 100644 --- a/doc/bugs/Monotone_rcs_support.mdwn +++ b/doc/bugs/Monotone_rcs_support.mdwn @@ -11,7 +11,7 @@ diff --git a/IkiWiki/Rcs/monotone.pm b/IkiWiki/Rcs/monotone.pm index cde6029..34f8f96 100644 --- a/IkiWiki/Rcs/monotone.pm +++ b/IkiWiki/Rcs/monotone.pm -@@ -186,8 +186,9 @@ sub rcs_update () { #{{{ +@@ -186,8 +186,9 @@ sub rcs_update () { check_config(); if (defined($config{mtnsync}) && $config{mtnsync}) { diff --git a/doc/bugs/No_link_for_blog_items_when_filename_contains_a_colon.mdwn b/doc/bugs/No_link_for_blog_items_when_filename_contains_a_colon.mdwn index 019970899..bb3f92f9c 100644 --- a/doc/bugs/No_link_for_blog_items_when_filename_contains_a_colon.mdwn +++ b/doc/bugs/No_link_for_blog_items_when_filename_contains_a_colon.mdwn @@ -38,19 +38,19 @@ At the moment I see two possible solutions: +++ IkiWiki.pm 2008-07-21 20:41:35.000000000 +0200 @@ -477,13 +477,13 @@ - sub titlepage ($) { #{{{ + sub titlepage ($) { my $title=shift; - $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; + $title=~s/([^-[:alnum:]+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; return $title; - } #}}} + } - sub linkpage ($) { #{{{ + sub linkpage ($) { my $link=shift; - $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; + $link=~s/([^-[:alnum:]+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg; return $link; - } #}}} + } What do you think about that? Does the patch have any side-effects I didn't see? diff --git a/doc/bugs/Problem_with_toc.pm_plug-in.mdwn b/doc/bugs/Problem_with_toc.pm_plug-in.mdwn index 8ae347d42..6be5f89b5 100644 --- a/doc/bugs/Problem_with_toc.pm_plug-in.mdwn +++ b/doc/bugs/Problem_with_toc.pm_plug-in.mdwn @@ -9,7 +9,7 @@ Here is a patch for toc.pm for producing non-empty 'a' elements. --- IkiWiki/Plugin/toc.pm.orig Thu Jun 7 11:53:53 2007 +++ IkiWiki/Plugin/toc.pm Thu Jun 7 13:00:00 2007 - @@ -47,7 +47,7 @@ sub format (@) { #{{{ + @@ -47,7 +47,7 @@ sub format (@) { if ($tagname =~ /^h(\d+)$/i) { my $level=$1; my $anchor="index".++$anchors{$level}."h$level"; @@ -18,7 +18,7 @@ Here is a patch for toc.pm for producing non-empty 'a' elements. # Take the first header level seen as the topmost level, # even if there are higher levels seen later on. - @@ -90,6 +90,16 @@ sub format (@) { #{{{ + @@ -90,6 +90,16 @@ sub format (@) { "\n"; $p->handler(text => undef); }, "dtext"); diff --git a/doc/bugs/Problems_with_graphviz.pm_plug-in.mdwn b/doc/bugs/Problems_with_graphviz.pm_plug-in.mdwn index 9a26e505a..c9f698158 100644 --- a/doc/bugs/Problems_with_graphviz.pm_plug-in.mdwn +++ b/doc/bugs/Problems_with_graphviz.pm_plug-in.mdwn @@ -15,7 +15,7 @@ It also generates image URLs relative to the page being rendered, which means th --- IkiWiki/Plugin/graphviz.pm.orig 2007-07-27 11:35:05.000000000 +0200 +++ IkiWiki/Plugin/graphviz.pm 2007-07-27 11:36:02.000000000 +0200 - @@ -69,7 +69,12 @@ sub render_graph (\%) { #{{{ + @@ -69,7 +69,12 @@ sub render_graph (\%) { } } @@ -26,9 +26,9 @@ It also generates image URLs relative to the page being rendered, which means th + else { + return "\n"; + } - } #}}} + } - sub graph (@) { #{{{ + sub graph (@) { >> --[[HenrikBrixAndersen]] @@ -38,7 +38,7 @@ The patch below fixes these two issues. --- graphviz.pm.orig Thu Jun 7 15:45:16 2007 +++ graphviz.pm Fri Jun 8 12:03:38 2007 - @@ -41,7 +41,6 @@ sub render_graph (\%) { #{{{ + @@ -41,7 +41,6 @@ sub render_graph (\%) { $pid=open2(*IN, *OUT, "$params{prog} -Tpng"); # open2 doesn't respect "use open ':utf8'" @@ -46,7 +46,7 @@ The patch below fixes these two issues. binmode (OUT, ':utf8'); print OUT $src; - @@ -70,7 +69,12 @@ sub render_graph (\%) { #{{{ + @@ -70,7 +69,12 @@ sub render_graph (\%) { } } @@ -57,6 +57,6 @@ The patch below fixes these two issues. + else { + return "\n"; + } - } #}}} + } - sub graph (@) { #{{{ + sub graph (@) { diff --git a/doc/bugs/RecentChanges_broken_with_empty_svnpath.mdwn b/doc/bugs/RecentChanges_broken_with_empty_svnpath.mdwn index 836c39a71..c852df5e9 100644 --- a/doc/bugs/RecentChanges_broken_with_empty_svnpath.mdwn +++ b/doc/bugs/RecentChanges_broken_with_empty_svnpath.mdwn @@ -13,7 +13,7 @@ I can not see why this check is needed in the first place, so here's a patch for diff -upr ikiwiki-1.49.orig/IkiWiki/Rcs/svn.pm ikiwiki-1.49/IkiWiki/Rcs/svn.pm --- ikiwiki-1.49.orig/IkiWiki/Rcs/svn.pm Mon Apr 16 15:15:09 2007 +++ ikiwiki-1.49/IkiWiki/Rcs/svn.pm Mon Apr 16 15:15:47 2007 - @@ -176,7 +176,6 @@ sub rcs_recentchanges ($) { #{{{ + @@ -176,7 +176,6 @@ sub rcs_recentchanges ($) { } foreach (keys %{$logentry->{paths}}) { diff --git a/doc/bugs/Titles_are_lower-cased_when_creating_a_page.mdwn b/doc/bugs/Titles_are_lower-cased_when_creating_a_page.mdwn index cc53c0aea..f2c60309b 100644 --- a/doc/bugs/Titles_are_lower-cased_when_creating_a_page.mdwn +++ b/doc/bugs/Titles_are_lower-cased_when_creating_a_page.mdwn @@ -6,7 +6,7 @@ If I click on "Czars in Russia", I'd like Ikiwiki to create "Czars\_in\_Russia.m > --- a/IkiWiki.pm > +++ b/IkiWiki.pm -> @@ -584,7 +584,7 @@ sub htmllink ($$$;@) { #{{{ +> @@ -584,7 +584,7 @@ sub htmllink ($$$;@) { > return " cgiurl( > do => "create", diff --git a/doc/bugs/Warns_about_use_of_uninitialized_value_if_prefix__95__directives_is_on_and_a_directive_does_not_contain_a_space.mdwn b/doc/bugs/Warns_about_use_of_uninitialized_value_if_prefix__95__directives_is_on_and_a_directive_does_not_contain_a_space.mdwn index a30f110a4..efb5c70b8 100644 --- a/doc/bugs/Warns_about_use_of_uninitialized_value_if_prefix__95__directives_is_on_and_a_directive_does_not_contain_a_space.mdwn +++ b/doc/bugs/Warns_about_use_of_uninitialized_value_if_prefix__95__directives_is_on_and_a_directive_does_not_contain_a_space.mdwn @@ -6,7 +6,7 @@ In `IkiWiki::preprocess`, the last capturing group in the regex used to parse di index 241a7c0..d2c35a2 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -1167,7 +1167,8 @@ sub preprocess ($$$;$$) { #{{{ + @@ -1167,7 +1167,8 @@ sub preprocess ($$$;$$) { }sx; } @@ -14,6 +14,6 @@ In `IkiWiki::preprocess`, the last capturing group in the regex used to parse di + # $4 can be undef if the directive was \[[!foo]] + $content =~ s{$regex}{$handle->($1, $2, $3, ($4 or ""))}eg; return $content; - } #}}} + } [[cherry-picked|done]] --[[Joey]] diff --git a/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn b/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn index aa13ec339..b7f38fd29 100644 --- a/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn +++ b/doc/bugs/bugfix_for:___34__mtn:_operation_canceled:_Broken_pipe__34_____40__patch__41__.mdwn @@ -3,7 +3,7 @@ When using monotone as revision control system, a "mtn: operation canceled: Brok diff -up ikiwiki/IkiWiki/Plugin/monotone.pm.orig ikiwiki/IkiWiki/Plugin/monotone.pm --- ikiwiki/IkiWiki/Plugin/monotone.pm.orig 2008-11-12 23:45:24.000000000 +0100 +++ ikiwiki/IkiWiki/Plugin/monotone.pm 2008-12-16 12:41:38.000000000 +0100 - @@ -525,13 +525,12 @@ sub rcs_recentchanges ($) { #{{{ + @@ -525,13 +525,12 @@ sub rcs_recentchanges ($) { my $child = open(MTNLOG, "-|"); if (! $child) { exec("mtn", "log", "--root=$config{mtnrootdir}", "--no-graph", diff --git a/doc/bugs/git_stderr_output_causes_problems.mdwn b/doc/bugs/git_stderr_output_causes_problems.mdwn index 4146a5869..c25ef6927 100644 --- a/doc/bugs/git_stderr_output_causes_problems.mdwn +++ b/doc/bugs/git_stderr_output_causes_problems.mdwn @@ -6,7 +6,7 @@ Ikiwiki's git handling is sending a bunch of output to stderr. The following pa index 425536f..5734bb2 100644 --- a/IkiWiki/Rcs/git.pm +++ b/IkiWiki/Rcs/git.pm - @@ -24,6 +24,7 @@ sub _safe_git (&@) { #{{{ + @@ -24,6 +24,7 @@ sub _safe_git (&@) { if (!$pid) { # In child. # Git commands want to be in wc. diff --git a/doc/bugs/img_plugin_should_pass_through_class_attribute.mdwn b/doc/bugs/img_plugin_should_pass_through_class_attribute.mdwn index 2e67d6357..f72ecade2 100644 --- a/doc/bugs/img_plugin_should_pass_through_class_attribute.mdwn +++ b/doc/bugs/img_plugin_should_pass_through_class_attribute.mdwn @@ -26,7 +26,7 @@ And here's a patch to implement it. Will this survive markdown munging? It seems index 7226231..3eb1ae7 100644 --- a/Plugin/img.pm +++ b/Plugin/img.pm - @@ -93,9 +93,15 @@ sub preprocess (@) { #{{{ + @@ -93,9 +93,15 @@ sub preprocess (@) { $imgurl="$config{url}/$imglink"; } @@ -42,7 +42,7 @@ And here's a patch to implement it. Will this survive markdown munging? It seems + $result .= '/>'; + + return $result; - } #}}} + } 1 -- diff --git a/doc/bugs/inline_sort-by-title_issues.mdwn b/doc/bugs/inline_sort-by-title_issues.mdwn index 884846b32..ff4555067 100644 --- a/doc/bugs/inline_sort-by-title_issues.mdwn +++ b/doc/bugs/inline_sort-by-title_issues.mdwn @@ -23,7 +23,7 @@ And here is a [[patch]] for this. It makes `sort=title` actually sort on the ti index 9c336e7..99f6de3 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm - @@ -185,9 +185,12 @@ sub preprocess_inline (@) { #{{{ + @@ -185,9 +185,12 @@ sub preprocess_inline (@) { } } diff --git a/doc/bugs/mercurial_fail_to_add.mdwn b/doc/bugs/mercurial_fail_to_add.mdwn index dab40d684..3bbf4e5fd 100644 --- a/doc/bugs/mercurial_fail_to_add.mdwn +++ b/doc/bugs/mercurial_fail_to_add.mdwn @@ -6,7 +6,7 @@ Here is a patch that's seems to work, although I'm not quite sure what's wrong w --- mercurial.pm 2007-03-24 16:14:35.000000000 +0100 +++ /home/hbernard/mercurial.pm 2007-04-19 19:05:47.000000000 +0200 @@ -95,7 +95,7 @@ - sub rcs_add ($) { # {{{ + sub rcs_add ($) { my ($file) = @_; - my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$file"); diff --git a/doc/bugs/methodResponse_in_add__95__plugins.mdwn b/doc/bugs/methodResponse_in_add__95__plugins.mdwn index 8a88f4eda..c82b532db 100644 --- a/doc/bugs/methodResponse_in_add__95__plugins.mdwn +++ b/doc/bugs/methodResponse_in_add__95__plugins.mdwn @@ -26,7 +26,7 @@ index e476521..d43abd4 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -471,7 +471,11 @@ sub loadplugins () { #{{{ + @@ -471,7 +471,11 @@ sub loadplugins () { unshift @INC, possibly_foolish_untaint($config{libdir}); } diff --git a/doc/bugs/multiple_pages_with_same_name.mdwn b/doc/bugs/multiple_pages_with_same_name.mdwn index 5ddfb1f6b..20c38c062 100644 --- a/doc/bugs/multiple_pages_with_same_name.mdwn +++ b/doc/bugs/multiple_pages_with_same_name.mdwn @@ -28,14 +28,14 @@ Suggestions welcome. index 4e4da11..853f905 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -618,7 +618,7 @@ sub pagename ($) { #{{{ + @@ -618,7 +618,7 @@ sub pagename ($) { my $type=pagetype($file); my $page=$file; - $page=~s/\Q.$type\E*$// if defined $type; + $page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{leavesuffix}; return $page; - } #}}} + } diff --git a/t/pagename.t b/t/pagename.t index 96e6a87..58811b9 100755 @@ -61,7 +61,7 @@ I wonder if this patch will also be useful: index 752d176..3f1b67b 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm - @@ -279,7 +279,11 @@ sub refresh () { #{{{ + @@ -279,7 +279,11 @@ sub refresh () { else { $f=~s/^\Q$config{srcdir}\E\/?//; push @files, $f; diff --git a/doc/bugs/pagespec_parsing_chokes_on_function__40____41__.mdwn b/doc/bugs/pagespec_parsing_chokes_on_function__40____41__.mdwn index a2eba694c..78fed0e5d 100644 --- a/doc/bugs/pagespec_parsing_chokes_on_function__40____41__.mdwn +++ b/doc/bugs/pagespec_parsing_chokes_on_function__40____41__.mdwn @@ -54,7 +54,7 @@ case the user is given to rebuilding the wiki by hand. --Ethan + } return IkiWiki::FailReason->new("syntax error") if $@; return $ret; - } #}}} + } > Thanks, [[done]] --[[Joey]] diff --git a/doc/bugs/prune_causing_taint_mode_failures.mdwn b/doc/bugs/prune_causing_taint_mode_failures.mdwn index 1876d9129..5fc1d8b75 100644 --- a/doc/bugs/prune_causing_taint_mode_failures.mdwn +++ b/doc/bugs/prune_causing_taint_mode_failures.mdwn @@ -11,7 +11,7 @@ I've no idea what's happening (hey, I'm a C programmer), but I've hacked prune()
 use Scalar::Util qw(tainted);
 
-sub prune ($) { #{{{
+sub prune ($) {
         my $file=shift;
 
         unlink($file);
@@ -25,7 +25,7 @@ sub prune ($) { #{{{
                         $dir = $1;
                 }
         }
-} #}}}
+}
 
> Old versions of perl are known to have bugs with taint checking. diff --git a/doc/bugs/quieten_mercurial.mdwn b/doc/bugs/quieten_mercurial.mdwn index 26f833e5f..3fd75ea1b 100644 --- a/doc/bugs/quieten_mercurial.mdwn +++ b/doc/bugs/quieten_mercurial.mdwn @@ -6,7 +6,7 @@ messages which are then taken for CGI output, causing errors and general trouble @@ -55,7 +55,7 @@ } - sub rcs_update () { #{{{ + sub rcs_update () { - my @cmdline = ("hg", "-R", "$config{srcdir}", "update"); + my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update"); if (system(@cmdline) != 0) { @@ -22,7 +22,7 @@ messages which are then taken for CGI output, causing errors and general trouble if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; @@ -92,7 +92,7 @@ - sub rcs_add ($) { # {{{ + sub rcs_add ($) { my ($file) = @_; - my @cmdline = ("hg", "-R", "$config{srcdir}", "add", "$file"); diff --git a/doc/bugs/search_for_locale_data_in_the_installed_location.mdwn b/doc/bugs/search_for_locale_data_in_the_installed_location.mdwn index 0a2b1efea..dace2ca19 100644 --- a/doc/bugs/search_for_locale_data_in_the_installed_location.mdwn +++ b/doc/bugs/search_for_locale_data_in_the_installed_location.mdwn @@ -2,7 +2,7 @@ It seems like gettext only searches for locale information in /usr/share/locale, --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -1057,6 +1057,7 @@ sub gettext { #{{{ + @@ -1057,6 +1057,7 @@ sub gettext { $gettext_obj=undef; return shift; } diff --git a/doc/bugs/tbasewiki__95__brokenlinks.t_broken.mdwn b/doc/bugs/tbasewiki__95__brokenlinks.t_broken.mdwn index ac895896a..db3917d21 100644 --- a/doc/bugs/tbasewiki__95__brokenlinks.t_broken.mdwn +++ b/doc/bugs/tbasewiki__95__brokenlinks.t_broken.mdwn @@ -25,12 +25,12 @@ After some digging I found that HTML::Template is being required after the new s filter => sub { my $text_ref = shift; @@ -857,6 +856,7 @@ - } #}}} + } - sub template ($;@) { #{{{ + sub template ($;@) { + require HTML::Template; HTML::Template->new(template_params(@_)); - } #}}} + } **That** gave me: diff --git a/doc/plugins/contrib/headinganchors.mdwn b/doc/plugins/contrib/headinganchors.mdwn index ef2fa122a..c80cc0b49 100644 --- a/doc/plugins/contrib/headinganchors.mdwn +++ b/doc/plugins/contrib/headinganchors.mdwn @@ -12,9 +12,9 @@ rst and any other format that produces html. The code is available here: use strict; use IkiWiki 2.00; - sub import { #{{{ + sub import { hook(type => "sanitize", id => "headinganchors", call => \&headinganchors); - } # }}} + } sub text_to_anchor { my $str = shift; @@ -26,11 +26,11 @@ rst and any other format that produces html. The code is available here: return $str; } - sub headinganchors (@) { #{{{ + sub headinganchors (@) { my %params=@_; my $content=$params{content}; $content=~s{([^>]*)}{''.$2.''}gie; return $content; - } # }}} + } 1 diff --git a/doc/plugins/contrib/siterel2pagerel.mdwn b/doc/plugins/contrib/siterel2pagerel.mdwn index 956b6728f..9b09657bf 100644 --- a/doc/plugins/contrib/siterel2pagerel.mdwn +++ b/doc/plugins/contrib/siterel2pagerel.mdwn @@ -13,11 +13,11 @@ other format that produces html. The code is available here: use strict; use IkiWiki 2.00; - sub import { #{{{ + sub import { hook(type => "sanitize", id => "siterel2pagerel", call => \&siterel2pagerel); - } # }}} + } - sub siterel2pagerel (@) { #{{{ + sub siterel2pagerel (@) { my %params=@_; my $baseurl=IkiWiki::baseurl($params{page}); my $content=$params{content}; @@ -25,6 +25,6 @@ other format that produces html. The code is available here: $content=~s/( "getsetup", id => "unixauth", call => \&getsetup); hook(type => "formbuilder_setup", id => "unixauth", call => \&formbuilder_setup); hook(type => "formbuilder", id => "unixauth", call => \&formbuilder); hook(type => "sessioncgi", id => "unixauth", call => \&sessioncgi); - } # }}} + } - sub getsetup () { #{{{ + sub getsetup () { return unixauth_type => { type => "string", @@ -83,10 +83,10 @@ __Security__: [As with passwordauth](/security/#index14h2), be wary of sending u safe => 0, rebuild => 1, }, - } #}}} + } # Checks if a string matches a user's password, and returns true or false. - sub checkpassword ($$;$) { #{{{ + sub checkpassword ($$;$) { my $user=shift; my $password=shift; my $field=shift || "password"; @@ -131,9 +131,9 @@ __Security__: [As with passwordauth](/security/#index14h2), be wary of sending u } return $ret; - } #}}} + } - sub formbuilder_setup (@) { #{{{ + sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; @@ -204,7 +204,7 @@ __Security__: [As with passwordauth](/security/#index14h2), be wary of sending u } } - sub formbuilder (@) { #{{{ + sub formbuilder (@) { my %params=@_; my $form=$params{form}; @@ -225,12 +225,12 @@ __Security__: [As with passwordauth](/security/#index14h2), be wary of sending u my $user_name=$form->field('name'); } } - } #}}} + } - sub sessioncgi ($$) { #{{{ + sub sessioncgi ($$) { my $q=shift; my $session=shift; - } #}}} + } 1 diff --git a/doc/todo/Add_DATE_parameter_for_use_in_templates.mdwn b/doc/todo/Add_DATE_parameter_for_use_in_templates.mdwn index c908f57c8..8ecdf36d0 100644 --- a/doc/todo/Add_DATE_parameter_for_use_in_templates.mdwn +++ b/doc/todo/Add_DATE_parameter_for_use_in_templates.mdwn @@ -44,7 +44,7 @@ regenerate this one against that). %config %links %renderedfiles %pagesources %destsources); our $VERSION = 2.00; # plugin interface version, next is ikiwiki version our $version="2.1";my $installdir="/usr"; - @@ -70,6 +70,7 @@ sub defaultconfig () { #{{{ + @@ -70,6 +70,7 @@ sub defaultconfig () { plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit lockedit conditional}], timeformat => '%c', @@ -52,27 +52,27 @@ regenerate this one against that). locale => undef, sslcookie => 0, httpauth => 0, - @@ -447,6 +448,15 @@ sub displaytime ($) { #{{{ + @@ -447,6 +448,15 @@ sub displaytime ($) { $config{timeformat}, localtime($time))); - } #}}} + } - +sub displaydate ($) { #{{{ + +sub displaydate ($) { + my $time=shift; + + # strftime doesn't know about encodings, so make sure + # its output is properly treated as utf8 + return decode_utf8(POSIX::strftime( + $config{dateformat}, localtime($time))); - +} #}}} + +} + - sub beautify_url ($) { #{{{ + sub beautify_url ($) { my $url=shift; diff --git a/Plugin/inline.pm b/Plugin/inline.pm index 8f6ab51..7bd6147 100644 --- a/Plugin/inline.pm +++ b/Plugin/inline.pm - @@ -148,6 +148,7 @@ sub preprocess_inline (@) { #{{{ + @@ -148,6 +148,7 @@ sub preprocess_inline (@) { $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage})); $template->param(title => pagetitle(basename($page))); $template->param(ctime => displaytime($pagectime{$page})); diff --git a/doc/todo/Add_support_for_latest_Text::Markdown_as_found_on_CPAN.mdwn b/doc/todo/Add_support_for_latest_Text::Markdown_as_found_on_CPAN.mdwn index 222cd8c46..6b9fa0535 100644 --- a/doc/todo/Add_support_for_latest_Text::Markdown_as_found_on_CPAN.mdwn +++ b/doc/todo/Add_support_for_latest_Text::Markdown_as_found_on_CPAN.mdwn @@ -12,7 +12,7 @@ This patch allows IkiWiki to work with either of the two: --- IkiWiki/Plugin/mdwn.pm.orig 2008-03-08 11:33:50.000000000 +0100 +++ IkiWiki/Plugin/mdwn.pm 2008-03-08 13:37:21.000000000 +0100 - @@ -28,14 +28,20 @@ sub htmlize (@) { #{{{ + @@ -28,14 +28,20 @@ sub htmlize (@) { $markdown_sub=\&Markdown::Markdown; } else { diff --git a/doc/todo/Allow_change_of_wiki_file_types.mdwn b/doc/todo/Allow_change_of_wiki_file_types.mdwn index 8a398f2e0..19574b175 100644 --- a/doc/todo/Allow_change_of_wiki_file_types.mdwn +++ b/doc/todo/Allow_change_of_wiki_file_types.mdwn @@ -12,7 +12,7 @@ I was hoping that the [[plugins/rename]] plugin would allow web uses to change t index 527ee88..123b772 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm - @@ -43,7 +43,7 @@ sub check_canrename ($$$$$$$) { #{{{ + @@ -43,7 +43,7 @@ sub check_canrename ($$$$$$$) { # Dest checks can be omitted by passing undef. if (defined $dest) { @@ -21,7 +21,7 @@ I was hoping that the [[plugins/rename]] plugin would allow web uses to change t error(gettext("no change to the file name was specified")); } - @@ -54,7 +54,7 @@ sub check_canrename ($$$$$$$) { #{{{ + @@ -54,7 +54,7 @@ sub check_canrename ($$$$$$$) { } # Must not be a known source file. @@ -30,7 +30,7 @@ I was hoping that the [[plugins/rename]] plugin would allow web uses to change t error(sprintf(gettext("%s already exists"), htmllink("", "", $dest, noimageinline => 1))); } - @@ -97,6 +97,24 @@ sub rename_form ($$$) { #{{{ + @@ -97,6 +97,24 @@ sub rename_form ($$$) { $f->field(name => "do", type => "hidden", value => "rename", force => 1); $f->field(name => "page", type => "hidden", value => $page, force => 1); $f->field(name => "new_name", value => IkiWiki::pagetitle($page), size => 60); @@ -55,7 +55,7 @@ I was hoping that the [[plugins/rename]] plugin would allow web uses to change t $f->field(name => "attachment", type => "hidden"); return $f, ["Rename", "Cancel"]; - @@ -223,12 +241,19 @@ sub sessioncgi ($$) { #{{{ + @@ -223,12 +241,19 @@ sub sessioncgi ($$) { my $dest=IkiWiki::possibly_foolish_untaint(IkiWiki::titlepage($q->param("new_name"))); # The extension of dest is the same as src if it's diff --git a/doc/todo/Allow_edittemplate_to_set_file_type.mdwn b/doc/todo/Allow_edittemplate_to_set_file_type.mdwn index b49968c18..1b99a4e05 100644 --- a/doc/todo/Allow_edittemplate_to_set_file_type.mdwn +++ b/doc/todo/Allow_edittemplate_to_set_file_type.mdwn @@ -14,7 +14,7 @@ edittemplate there. --[[Joey]] index 98308de..c381940 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm - @@ -56,8 +56,14 @@ sub preprocess (@) { #{{{ + @@ -56,8 +56,14 @@ sub preprocess (@) { $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template}; @@ -28,10 +28,10 @@ edittemplate there. --[[Joey]] + + return sprintf(gettext("edittemplate: %s registered for %s"), + $linkHTML, $params{match}); - } # }}} + } - sub formbuilder (@) { #{{{ - @@ -89,6 +95,9 @@ sub formbuilder (@) { #{{{ + sub formbuilder (@) { + @@ -89,6 +95,9 @@ sub formbuilder (@) { if (pagespec_match($p, $pagespec, location => $registering_page)) { $form->field(name => "editcontent", value => filltemplate($pagestate{$registering_page}{edittemplate}{$pagespec}, $page)); diff --git a/doc/todo/Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn b/doc/todo/Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn index 73157a326..95c38f794 100644 --- a/doc/todo/Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn +++ b/doc/todo/Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn @@ -8,9 +8,9 @@ This patch adds function bestdir() which returns best directory from the directo +++ IkiWiki.pm (working copy) @@ -391,6 +391,35 @@ return ""; - } #}}} + } - +sub bestdir ($$) { #{{{ + +sub bestdir ($$) { + my $page=shift; + my $link=shift; + my $cwd=$page; @@ -37,9 +37,9 @@ This patch adds function bestdir() which returns best directory from the directo + } + + return ""; - +} #}}} + +} + - sub isinlinableimage ($) { #{{{ + sub isinlinableimage ($) { my $file=shift; ---- diff --git a/doc/todo/Default_text_for_new_pages.mdwn b/doc/todo/Default_text_for_new_pages.mdwn index 4a17bbf8b..a904f8287 100644 --- a/doc/todo/Default_text_for_new_pages.mdwn +++ b/doc/todo/Default_text_for_new_pages.mdwn @@ -15,7 +15,7 @@ Inline below is a [[patch]] that implements this: index bb21ed2..10c985c 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm - @@ -60,7 +60,7 @@ sub cgi_editpage ($$) { #{{{ + @@ -60,7 +60,7 @@ sub cgi_editpage ($$) { decode_cgi_utf8($q); @@ -24,7 +24,7 @@ Inline below is a [[patch]] that implements this: my @buttons=("Save Page", "Preview", "Cancel"); eval q{use CGI::FormBuilder}; error($@) if $@; - @@ -117,9 +117,20 @@ sub cgi_editpage ($$) { #{{{ + @@ -117,9 +117,20 @@ sub cgi_editpage ($$) { } else { $type=$form->param('type'); @@ -45,7 +45,7 @@ Inline below is a [[patch]] that implements this: elsif (defined $from && exists $pagesources{$from}) { # favor the type of linking page $type=pagetype($pagesources{$from}); - @@ -129,7 +140,7 @@ sub cgi_editpage ($$) { #{{{ + @@ -129,7 +140,7 @@ sub cgi_editpage ($$) { if (! $form->submitted) { $form->field(name => "rcsinfo", value => "", force => 1); } @@ -58,7 +58,7 @@ Inline below is a [[patch]] that implements this: index 8efef3f..075d7d8 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm - @@ -271,6 +271,7 @@ sub preprocess_inline (@) { #{{{ + @@ -271,6 +271,7 @@ sub preprocess_inline (@) { $rootpage=$params{page}; } $formtemplate->param(rootpage => $rootpage); diff --git a/doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn b/doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn index a644e236b..c71250b3a 100644 --- a/doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn +++ b/doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn @@ -94,7 +94,7 @@ most possible of these pages. > index a6e34fc..bb9dd8d 100644 > --- a/IkiWiki/Plugin/template.pm > +++ b/IkiWiki/Plugin/template.pm -> @@ -57,6 +57,8 @@ sub preprocess (@) { #{{{ +> @@ -57,6 +57,8 @@ sub preprocess (@) { > } > } > diff --git a/doc/todo/Inline_plugin_option_to_show_full_page_path.mdwn b/doc/todo/Inline_plugin_option_to_show_full_page_path.mdwn index 9f52a724a..691694009 100644 --- a/doc/todo/Inline_plugin_option_to_show_full_page_path.mdwn +++ b/doc/todo/Inline_plugin_option_to_show_full_page_path.mdwn @@ -19,7 +19,7 @@ Cheers, index 59eabb6..82913ba 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm - @@ -229,6 +229,7 @@ sub preprocess_inline (@) { #{{{ + @@ -229,6 +229,7 @@ sub preprocess_inline (@) { $template->param(content => $content); } $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage})); diff --git a/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn b/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn index d94d24ee4..3cedd5ae3 100644 --- a/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn +++ b/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn @@ -71,10 +71,10 @@ Happy TeXing. + +my $default_postfix = '\\end{document}'; + - sub import { #{{{ + sub import { hook(type => "getsetup", id => "teximg", call => \&getsetup); hook(type => "preprocess", id => "teximg", call => \&preprocess); - @@ -21,6 +33,26 @@ sub getsetup () { #{{{ + @@ -21,6 +33,26 @@ sub getsetup () { safe => 1, rebuild => undef, }, @@ -98,10 +98,10 @@ Happy TeXing. + safe => 0, # Not sure how secure LaTeX is... + rebuild => 1, + }, - } #}}} + } - sub preprocess (@) { #{{{ - @@ -105,25 +137,35 @@ sub gen_image ($$$$) { #{{{ + sub preprocess (@) { + @@ -105,25 +137,35 @@ sub gen_image ($$$$) { my $digest = shift; my $imagedir = shift; diff --git a/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn b/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn index a26433919..89167c084 100644 --- a/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn +++ b/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn @@ -42,13 +42,13 @@ Longer term plans: my %cache; my %linkcache; @@ -32,6 +34,7 @@ - sub import { #{{{ + sub import { hook(type => "needsbuild", id => "version", call => \&needsbuild); hook(type => "preprocess", id => "calendar", call => \&preprocess); + hook(type => "preprocess", id => "event", call => \&preprocess_event); - } #}}} + } - sub is_leap_year (@) { #{{{ + sub is_leap_year (@) { @@ -58,6 +61,7 @@ my $nmonth = $params{nmonth}; my $pyear = $params{pyear}; @@ -137,9 +137,9 @@ Longer term plans: # finish off the week @@ -304,6 +333,18 @@ return $calendar; - } #}}} + } - +sub preprocess_event (@) { #{{{ + +sub preprocess_event (@) { + my %params=@_; + # if now time is given, use now + $params{begin} = localtime($time) unless defined $params{begin}; @@ -151,7 +151,7 @@ Longer term plans: + return ""; +} #}} + - sub preprocess (@) { #{{{ + sub preprocess (@) { my %params=@_; $params{pages} = "*" unless defined $params{pages}; @@ -311,6 +352,8 @@ diff --git a/doc/todo/Silence_monotone_warning.mdwn b/doc/todo/Silence_monotone_warning.mdwn index e3f0224c2..d875900c5 100644 --- a/doc/todo/Silence_monotone_warning.mdwn +++ b/doc/todo/Silence_monotone_warning.mdwn @@ -4,7 +4,7 @@ A quick [[patch]] to silence a [[rcs/monotone]] warning I started seeing: index 4b9be31..9d4e280 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm - @@ -55,7 +55,7 @@ sub checkconfig () { #{{{ + @@ -55,7 +55,7 @@ sub checkconfig () { error("Monotone version too old, is $version but required 0.38"); } diff --git a/doc/todo/Support_wildcard_inside_of_link__40____41___within_a_pagespec.mdwn b/doc/todo/Support_wildcard_inside_of_link__40____41___within_a_pagespec.mdwn index 2837634d9..8320f72a6 100644 --- a/doc/todo/Support_wildcard_inside_of_link__40____41___within_a_pagespec.mdwn +++ b/doc/todo/Support_wildcard_inside_of_link__40____41___within_a_pagespec.mdwn @@ -20,7 +20,7 @@ That doesn't work in ikiwiki 2.1, but I have it index 38aa46a..cd42e8d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -1082,10 +1082,15 @@ sub match_link ($$;@) { #{{{ + @@ -1082,10 +1082,15 @@ sub match_link ($$;@) { my $links = $IkiWiki::links{$page} or return undef; return IkiWiki::FailReason->new("$page has no links") unless @$links; my $bestlink = IkiWiki::bestlink($from, $link); @@ -38,7 +38,7 @@ That doesn't work in ikiwiki 2.1, but I have it + } } return IkiWiki::FailReason->new("$page does not link to $link"); - } #}}} + } -- 1.5.1.1.g6aead diff --git a/doc/todo/Wrapper_config_with_multiline_regexp.mdwn b/doc/todo/Wrapper_config_with_multiline_regexp.mdwn index c0311bc92..7b4323de1 100644 --- a/doc/todo/Wrapper_config_with_multiline_regexp.mdwn +++ b/doc/todo/Wrapper_config_with_multiline_regexp.mdwn @@ -13,12 +13,12 @@ Second, the untainting of $configstring should allow newlines. +++ wiki-meta/perl/IkiWiki.pm Mon Jun 11 10:52:07 2007 @@ -205,7 +205,7 @@ - sub possibly_foolish_untaint ($) { #{{{ + sub possibly_foolish_untaint ($) { my $tainted=shift; - my ($untainted)=$tainted=~/(.*)/; + my ($untainted)=$tainted=~/(.*)/s; return $untainted; - } #}}} + } Modified: wiki-meta/perl/IkiWiki/Wrapper.pm diff --git a/doc/todo/add_forward_age_sorting_option_to_inline.mdwn b/doc/todo/add_forward_age_sorting_option_to_inline.mdwn index 684419f90..e91c5a42f 100644 --- a/doc/todo/add_forward_age_sorting_option_to_inline.mdwn +++ b/doc/todo/add_forward_age_sorting_option_to_inline.mdwn @@ -19,7 +19,7 @@ diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index d2e5832..9e52712 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm -@@ -194,6 +194,9 @@ sub preprocess_inline (@) { #{{{ +@@ -194,6 +194,9 @@ sub preprocess_inline (@) { elsif (! exists $params{sort} || $params{sort} eq 'age') { @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list; } diff --git a/doc/todo/automatic_use_of_syntax_plugin_on_source_code_files/discussion.mdwn b/doc/todo/automatic_use_of_syntax_plugin_on_source_code_files/discussion.mdwn index 467ec350e..dc6c0001e 100644 --- a/doc/todo/automatic_use_of_syntax_plugin_on_source_code_files/discussion.mdwn +++ b/doc/todo/automatic_use_of_syntax_plugin_on_source_code_files/discussion.mdwn @@ -17,13 +17,13 @@ Updated to use fix noted in [[bugs/multiple_pages_with_same_name]]. my %metaheaders; - sub import { #{{{ + sub import { hook(type => "getsetup", id => "sourcecode", call => \&getsetup); hook(type => "checkconfig", id => "sourcecode", call => \&checkconfig); hook(type => "pagetemplate", id => "sourcecode", call => \&pagetemplate); - } # }}} + } - sub getsetup () { #{{{ + sub getsetup () { return plugin => { safe => 1, @@ -57,9 +57,9 @@ Updated to use fix noted in [[bugs/multiple_pages_with_same_name]]. safe => 1, rebuild => 1, }, - } #}}} + } - sub checkconfig () { #{{{ + sub checkconfig () { if (! $config{sourcecode_lang}) { error("The sourcecode plugin requires a list of suffixes in the 'sourcecode_lang' config option"); } @@ -97,9 +97,9 @@ Updated to use fix noted in [[bugs/multiple_pages_with_same_name]]. error("Your installation of source-highlight cannot handle sourcecode language $lang!"); } } - } #}}} + } - sub htmlize (@) { #{{{ + sub htmlize (@) { my %params=@_; my $page = $params{page}; @@ -141,9 +141,9 @@ Updated to use fix noted in [[bugs/multiple_pages_with_same_name]]. } return '
'."\r\n".join("\r\n",@html)."\r\n
\n"; - } # }}} + } - sub pagetemplate (@) { #{{{ + sub pagetemplate (@) { my %params=@_; my $page=$params{page}; @@ -154,6 +154,6 @@ Updated to use fix noted in [[bugs/multiple_pages_with_same_name]]. my %seen; $template->param(meta => join("\n", grep { (! $seen{$_}) && ($seen{$_}=1) } @{$metaheaders{$page}})); } - } # }}} + } 1 diff --git a/doc/todo/blogpost_plugin.mdwn b/doc/todo/blogpost_plugin.mdwn index 60b1e2515..bb91ffd02 100644 --- a/doc/todo/blogpost_plugin.mdwn +++ b/doc/todo/blogpost_plugin.mdwn @@ -51,13 +51,13 @@ Index: IkiWiki/Plugin/blogpost.pm +use POSIX; +use IkiWiki 2.00; + -+sub import { #{{{ ++sub import { + hook(type => "checkconfig", id => "blogpost", call => \&checkconfig); + hook(type => "authcgi", id => "blogpost", call => \&authcgi); + hook(type => "canedit", id => "blogpost", call => \&canedit); -+} # }}} ++} + -+sub checkconfig () { #{{{ ++sub checkconfig () { + if (! defined $config{blogformat}){ + $config{blogformat} = 'posts/%Y/%m/%d/$title'; + } @@ -72,9 +72,9 @@ Index: IkiWiki/Plugin/blogpost.pm + if (! defined $config{blogusers}) { + $config{blogusers} = (); # disallow all posting by default + } -+} #}}} ++} + -+sub authcgi ($$) { #{{{ ++sub authcgi ($$) { + my $cgi=shift; + my $session=shift; + @@ -115,16 +115,16 @@ Index: IkiWiki/Plugin/blogpost.pm + $cgi->param("page", $page); + } + -+} #}}} ++} + -+sub blogpage ($) { #{{{ ++sub blogpage ($) { + my $title=shift; + my $page=POSIX::strftime $config{blogformat}, localtime; + $page =~ s/\$title/$title/; + return $page; -+} #}}} ++} + -+sub canedit ($$$) { #{{{ ++sub canedit ($$$) { + my $page=shift; + my $cgi=shift; + my $session=shift; @@ -136,7 +136,7 @@ Index: IkiWiki/Plugin/blogpost.pm + return "" if ($config{blogusers} eq "*" || + grep {$_ eq $user} $config{blogusers}); + return ("not allowed to blog, $user"); -+} #}}} ++} + +1 Index: IkiWiki.pm diff --git a/doc/todo/bzr.mdwn b/doc/todo/bzr.mdwn index 179ea2f24..a50c58d26 100644 --- a/doc/todo/bzr.mdwn +++ b/doc/todo/bzr.mdwn @@ -56,15 +56,15 @@ and rcs_getctime and rcs_notify aren't written at all. --[[bma]] return @ret; } - sub rcs_update () { #{{{ + sub rcs_update () { # Not needed. - } #}}} + } - sub rcs_prepedit ($) { #{{{ + sub rcs_prepedit ($) { return ""; - } #}}} + } - sub rcs_commit ($$$;$$) { #{{{ + sub rcs_commit ($$$;$$) { my ($file, $message, $rcstoken, $user, $ipaddr) = @_; if (defined $user) { @@ -95,18 +95,18 @@ and rcs_getctime and rcs_notify aren't written at all. --[[bma]] system("bzr","whoami",$olduser); return undef; # success - } #}}} + } - sub rcs_add ($) { # {{{ + sub rcs_add ($) { my ($file) = @_; my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } - } #}}} + } - sub rcs_recentchanges ($) { #{{{ + sub rcs_recentchanges ($) { my ($num) = @_; eval q{use CGI 'escapeHTML'}; @@ -153,15 +153,15 @@ and rcs_getctime and rcs_notify aren't written at all. --[[bma]] } return @ret; - } #}}} + } - sub rcs_notify () { #{{{ + sub rcs_notify () { # TODO - } #}}} + } - sub rcs_getctime ($) { #{{{ + sub rcs_getctime ($) { # TODO - } #}}} + } 1 diff --git a/doc/todo/cas_authentication.mdwn b/doc/todo/cas_authentication.mdwn index c8ffe7005..8bf7042df 100644 --- a/doc/todo/cas_authentication.mdwn +++ b/doc/todo/cas_authentication.mdwn @@ -43,11 +43,11 @@ follows) ? > the use of it: `eval q{use AuthCAS}; error $@ if $@` + - +sub import { #{{{ + +sub import { + hook(type => "getopt", id => "cas", call => \&getopt); + hook(type => "auth", id => "cas", call => \&auth); + hook(type => "formbuilder_setup", id => "cas", call => \&formbuilder_setup); - +} # }}} + +} > Could you please use tabs for indentation of program flow? @@ -61,15 +61,15 @@ follows) ? > Why would you want to make other auth plugins not work? Could a site not > legitimatly chose to use this and another auth method? - +sub getopt () { #{{{ + +sub getopt () { + eval q{use Getopt::Long}; + error($@) if $@; + Getopt::Long::Configure('pass_through'); + GetOptions("cas_url=s" => \$config{cas_url}); + GetOptions("ca_file=s" => \$config{ca_file}); - +} #}}} + +} + - +sub auth ($$) { #{{{ + +sub auth ($$) { + my $q=shift; + my $session=shift; + @@ -98,11 +98,11 @@ follows) ? + error("CAS failure: ".&AuthCAS::get_errors()); + } + } - +} #}}} + +} + +# I use formbuilder_setup and not formbuilder type in order to bypass the +# Logout processing done in IkiWiki::CGI::cgi_prefs() - +sub formbuilder_setup (@) { #{{{ + +sub formbuilder_setup (@) { + my %params=@_; + + my $form=$params{form}; diff --git a/doc/todo/color_plugin.mdwn b/doc/todo/color_plugin.mdwn index 69afe837d..19fba3b35 100644 --- a/doc/todo/color_plugin.mdwn +++ b/doc/todo/color_plugin.mdwn @@ -132,12 +132,12 @@ Of course, I'm open for discussion or exchange of ideas :) --[[Paweł|ptecza]] +use strict; +use IkiWiki 2.00; + - +sub import { #{{{ + +sub import { + hook(type => "preprocess", id => "color", call => \&preprocess); + hook(type => "format", id => "color", call => \&format); - +} #}}} + +} + - +sub preserve_style ($$$) { #{{{ + +sub preserve_style ($$$) { + my $foreground = shift; + my $background = shift; + my $text = shift; @@ -162,18 +162,18 @@ Of course, I'm open for discussion or exchange of ideas :) --[[Paweł|ptecza]] + + return $preserved; + - +} #}}} + +} + - +sub replace_preserved_style ($) { #{{{ + +sub replace_preserved_style ($) { + my $content = shift; + + $content =~ s!((color: ([a-z]+|\#[0-9a-f]{3,6})?)?((; )?(background-color: ([a-z]+|\#[0-9a-f]{3,6})?)?)?)!!g; + $content =~ s!!!g; + + return $content; - +} #}}} + +} + - +sub preprocess (@) { #{{{ + +sub preprocess (@) { + my %params = @_; + + # Preprocess the text to expand any preprocessor directives @@ -182,14 +182,14 @@ Of course, I'm open for discussion or exchange of ideas :) --[[Paweł|ptecza]] + IkiWiki::filter($params{page}, $params{destpage}, $params{text})); + + return preserve_style($params{foreground}, $params{background}, $params{text}); - +} #}}} + +} + - +sub format (@) { #{{{ + +sub format (@) { + my %params = @_; + + $params{content} = replace_preserved_style($params{content}); + return $params{content}; - +} #}}} + +} + +1 --- /dev/null 2008-06-21 02:02:15.000000000 +0200 diff --git a/doc/todo/darcs.mdwn b/doc/todo/darcs.mdwn index e5bf5ee27..882a41379 100644 --- a/doc/todo/darcs.mdwn +++ b/doc/todo/darcs.mdwn @@ -219,14 +219,14 @@ This is my ([bma](bma@bmalee.eu)) darcs.pm - it's messy (my Perl isn't up to muc package IkiWiki; - sub rcs_update () { #{{{ + sub rcs_update () { # Do nothing - there's nowhere to update *from*. - } #}}} + } - sub rcs_prepedit ($) { #{{{ - } #}}} + sub rcs_prepedit ($) { + } - sub rcs_commit ($$$;$$) { #{{{ + sub rcs_commit ($$$;$$) { my ($file, $message, $rcstoken, $user, $ipaddr) = @_; # $user should probably be a name and an email address, by darcs @@ -257,16 +257,16 @@ This is my ([bma](bma@bmalee.eu)) darcs.pm - it's messy (my Perl isn't up to muc return undef; # success - sub rcs_add ($) { # {{{ + sub rcs_add ($) { my ($file) = @_; my @cmdline = ("darcs", "add", "--repodir", "$config{srcdir}", "-a", "-q", "$file"); if (system(@cmdline) != 0) { warn "'@cmdline' failed: $!"; } - } #}}} + } - sub rcs_recentchanges ($) { #{{{ + sub rcs_recentchanges ($) { # TODO: This is horrible code. It doesn't work perfectly, and uses regexes # rather than parsing Darcs' XML output. my $num=shift; @@ -314,15 +314,15 @@ This is my ([bma](bma@bmalee.eu)) darcs.pm - it's messy (my Perl isn't up to muc } } return @ret; - } #}}} + } - sub rcs_notify () { #{{{ + sub rcs_notify () { # TODO - } #}}} + } - sub rcs_getctime ($) { #{{{ + sub rcs_getctime ($) { error gettext("getctime not implemented"); - } #}}} + } 1 diff --git a/doc/todo/datearchives-plugin.mdwn b/doc/todo/datearchives-plugin.mdwn index 5a5560d6c..5f33cde4c 100644 --- a/doc/todo/datearchives-plugin.mdwn +++ b/doc/todo/datearchives-plugin.mdwn @@ -17,11 +17,11 @@ Index: IkiWiki/Plugin/datearchives.pm +use strict; +use IkiWiki; + -+sub import { #{{{ ++sub import { + hook(type => "pagetemplate", id => "datearchives", call => \&pagetemplate, scan => 1); -+} # }}} ++} + -+sub pagetemplate (@) { #{{{ ++sub pagetemplate (@) { + my %args = @_; + my $dt; + eval { @@ -37,7 +37,7 @@ Index: IkiWiki/Plugin/datearchives.pm + $template->param(ctime => htmllink( $args{page}, $args{destpage}, $link, 0, 0, + $template->param('ctime'))); + } -+} # }}} ++} + +1 diff --git a/doc/todo/different_search_engine.mdwn b/doc/todo/different_search_engine.mdwn index 2f309dea5..9d0fc92c9 100644 --- a/doc/todo/different_search_engine.mdwn +++ b/doc/todo/different_search_engine.mdwn @@ -126,7 +126,7 @@ Index: IkiWiki/Plugin/search.pm + $PLUCENE_DIR = $config{wikistatedir}.'/plucene'; +} + - sub import { #{{{ + sub import { - hook(type => "getopt", id => "hyperestraier", - call => \&getopt); - hook(type => "checkconfig", id => "hyperestraier", @@ -142,14 +142,14 @@ Index: IkiWiki/Plugin/search.pm call => \&change); - hook(type => "cgi", id => "hyperestraier", - call => \&cgi); - } # }}} + } --sub getopt () { #{{{ +-sub getopt () { - eval q{use Getopt::Long}; - error($@) if $@; - Getopt::Long::Configure('pass_through'); - GetOptions("estseek=s" => \$config{estseek}); --} #}}} +-} +sub writer { + init(); @@ -165,20 +165,20 @@ Index: IkiWiki/Plugin/search.pm + grep { defined pagetype($_) } @_; +} + - sub checkconfig () { #{{{ + sub checkconfig () { foreach my $required (qw(url cgiurl)) { if (! length $config{$required}) { @@ -36,112 +58,55 @@ } - } #}}} + } -my $form; --sub pagetemplate (@) { #{{{ +-sub pagetemplate (@) { - my %params=@_; - my $page=$params{page}; - my $template=$params{template}; +#my $form; -+#sub pagetemplate (@) { #{{{ ++#sub pagetemplate (@) { +# my %params=@_; +# my $page=$params{page}; +# my $template=$params{template}; @@ -193,7 +193,7 @@ Index: IkiWiki/Plugin/search.pm +# +# $template->param(searchform => $form); +# } -+#} #}}} ++#} - # Add search box to page header. - if ($template->query(name => "searchform")) { @@ -205,9 +205,9 @@ Index: IkiWiki/Plugin/search.pm - - $template->param(searchform => $form); - } --} #}}} +-} - - sub delete (@) { #{{{ + sub delete (@) { - debug(gettext("cleaning hyperestraier search index")); - estcmd("purge -cl"); - estcfg(); @@ -219,9 +219,9 @@ Index: IkiWiki/Plugin/search.pm + $reader->delete_term( Plucene::Index::Term->new({ field => "id", text => $_ })); + } + $reader->close; - } #}}} + } - sub change (@) { #{{{ + sub change (@) { - debug(gettext("updating hyperestraier search index")); - estcmd("gather -cm -bc -cl -sd", - map { @@ -250,9 +250,9 @@ Index: IkiWiki/Plugin/search.pm + $doc->add(Plucene::Document::Field->UnStored('text' => $data)); + $writer->add_document($doc); + } - } #}}} + } - --sub cgi ($) { #{{{ +-sub cgi ($) { - my $cgi=shift; - - if (defined $cgi->param('phrase') || defined $cgi->param("navi")) { @@ -260,10 +260,10 @@ Index: IkiWiki/Plugin/search.pm - chdir("$config{wikistatedir}/hyperestraier") || error("chdir: $!"); - exec("./".IkiWiki::basename($config{cgiurl})) || error("estseek.cgi failed"); - } --} #}}} +-} - -my $configured=0; --sub estcfg () { #{{{ +-sub estcfg () { - return if $configured; - $configured=1; - @@ -301,9 +301,9 @@ Index: IkiWiki/Plugin/search.pm - unlink($cgi); - my $estseek = defined $config{estseek} ? $config{estseek} : '/usr/lib/estraier/estseek.cgi'; - symlink($estseek, $cgi) || error("symlink $estseek $cgi: $!"); --} # }}} +-} - --sub estcmd ($;@) { #{{{ +-sub estcmd ($;@) { - my @params=split(' ', shift); - push @params, "-cl", "$config{wikistatedir}/hyperestraier"; - if (@_) { @@ -323,7 +323,7 @@ Index: IkiWiki/Plugin/search.pm - open(STDOUT, "/dev/null"); # shut it up (closing won't work) - exec("estcmd", @params) || error("can't run estcmd"); - } --} #}}} +-} - -1 +1; diff --git a/doc/todo/directive_docs.mdwn b/doc/todo/directive_docs.mdwn index 1f6307381..2baa61b40 100644 --- a/doc/todo/directive_docs.mdwn +++ b/doc/todo/directive_docs.mdwn @@ -40,15 +40,15 @@ defined them: --[[Joey]] index e476521..afe982a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -493,6 +493,7 @@ sub loadplugins () { #{{{ + @@ -493,6 +493,7 @@ sub loadplugins () { return 1; - } #}}} + } +my $loading_plugin; - sub loadplugin ($) { #{{{ + sub loadplugin ($) { my $plugin=shift; - @@ -502,14 +503,18 @@ sub loadplugin ($) { #{{{ + @@ -502,14 +503,18 @@ sub loadplugin ($) { "$installdir/lib/ikiwiki") { if (defined $dir && -x "$dir/plugins/$plugin") { require IkiWiki::Plugin::external; @@ -67,7 +67,7 @@ defined them: --[[Joey]] if ($@) { error("Failed to load plugin $mod: $@"); } - @@ -1429,6 +1434,9 @@ sub hook (@) { # {{{ + @@ -1429,6 +1434,9 @@ sub hook (@) { return if $param{no_override} && exists $hooks{$param{type}}{$param{id}}; @@ -76,4 +76,4 @@ defined them: --[[Joey]] + $hooks{$param{type}}{$param{id}}=\%param; return 1; - } # }}} + } diff --git a/doc/todo/enable-htaccess-files.mdwn b/doc/todo/enable-htaccess-files.mdwn index b3c174fba..e3b295123 100644 --- a/doc/todo/enable-htaccess-files.mdwn +++ b/doc/todo/enable-htaccess-files.mdwn @@ -5,7 +5,7 @@ @@ -26,7 +26,7 @@ memoize("file_pruned"); - sub defaultconfig () { #{{{ + sub defaultconfig () { - wiki_file_prune_regexps => [qr/\.\./, qr/^\./, qr/\/\./, + wiki_file_prune_regexps => [qr/\.\./, qr/^\.(?!htaccess)/, qr/\/\.(?!htaccess)/, qr/\.x?html?$/, qr/\.ikiwiki-new$/, diff --git a/doc/todo/format_escape.mdwn b/doc/todo/format_escape.mdwn index 8dfe05581..574883d1b 100644 --- a/doc/todo/format_escape.mdwn +++ b/doc/todo/format_escape.mdwn @@ -141,13 +141,13 @@ Index: IkiWiki/Plugin/rst.pm print html[html.find('')+6:html.find('')].strip(); "; - sub import { #{{{ + sub import { hook(type => "htmlize", id => "rst", call => \&htmlize); + hook(type => "htmlescape", id => "rst", call => \&htmlescape); + hook(type => "htmlescapelink", id => "rst", call => \&htmlescapelink); - } # }}} + } -+sub htmlescapelink ($$;@) { #{{{ ++sub htmlescapelink ($$;@) { + my $url = shift; + my $text = shift; + my %params = @_; @@ -158,15 +158,15 @@ Index: IkiWiki/Plugin/rst.pm + else { + return "`$text <$url>`_"; + } -+} # }}} ++} + -+sub htmlescape ($) { #{{{ ++sub htmlescape ($) { + my $html=shift; + $html=~s/^/ /mg; + return ".. raw:: html\n\n".$html; -+} # }}} ++} + - sub htmlize (@) { #{{{ + sub htmlize (@) { my %params=@_; my $content=$params{content}; Index: doc/plugins/write.mdwn @@ -272,7 +272,7 @@ Index: IkiWiki.pm + return $hooks{htmlescapelink}{$type}{call}->($bestlink, $linktext); + } return "$linktext"; - } #}}} + } @@ -628,6 +640,14 @@ preview => $preprocess_preview, diff --git a/doc/todo/fortune:_select_options_via_environment.mdwn b/doc/todo/fortune:_select_options_via_environment.mdwn index f906312fe..ddacd91b5 100644 --- a/doc/todo/fortune:_select_options_via_environment.mdwn +++ b/doc/todo/fortune:_select_options_via_environment.mdwn @@ -14,9 +14,9 @@ package IkiWiki::Plugin::fortune; use warnings; - @@ -12,7 +18,13 @@ sub import { #{{{ + @@ -12,7 +18,13 @@ sub import { - sub preprocess (@) { #{{{ + sub preprocess (@) { $ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games"; - my $f = `fortune 2>/dev/null`; + my $f; diff --git a/doc/todo/index.html_allowed.mdwn b/doc/todo/index.html_allowed.mdwn index f030f9eea..f5e6f8cd7 100644 --- a/doc/todo/index.html_allowed.mdwn +++ b/doc/todo/index.html_allowed.mdwn @@ -91,15 +91,15 @@ page "A/B/index.html" is treated as "A/B". +++ ikidev/IkiWiki.pm 2007-02-25 15:05:22.328852000 -0800 @@ -192,6 +192,12 @@ return $untainted; - } #}}} + } - +sub titlename($;@) { #{{{ + +sub titlename($;@) { + my $page = shift; + $page =~ s!/index$!!; + return pagetitle(basename($page), @_); - +} #}}} + +} + - sub basename ($) { #{{{ + sub basename ($) { my $file=shift; @@ -117,7 +117,7 @@ diff -ru ikiwiki-2.4/IkiWiki.pm ikiwiki/IkiWiki.pm $page=~s/\Q.$type\E*$// if defined $type; + $page=~s/\/index$// if $page =~ /\/index$/; return $page; - } #}}} + } diff --git a/doc/todo/inline:_numerical_ordering_by_title.mdwn b/doc/todo/inline:_numerical_ordering_by_title.mdwn index 95511d998..3f6c8b598 100644 --- a/doc/todo/inline:_numerical_ordering_by_title.mdwn +++ b/doc/todo/inline:_numerical_ordering_by_title.mdwn @@ -155,11 +155,11 @@ Joey, have you forgotten about that request? ;) --[[Paweł|ptecza]] %config %links %pagestate %renderedfiles %pagesources %destsources); our $VERSION = 2.00; # plugin interface version, next is ikiwiki version - @@ -835,6 +835,42 @@ sub titlepage ($) { #{{{ + @@ -835,6 +835,42 @@ sub titlepage ($) { return $title; - } #}}} + } - +sub titlecmp ($$) { #{{{ + +sub titlecmp ($$) { + my $titleA=shift; + my $titleB=shift; + @@ -193,29 +193,29 @@ Joey, have you forgotten about that request? ;) --[[Paweł|ptecza]] + return -1 if (@listB); + + return 0; - +} #}}} + +} + - sub linkpage ($) { #{{{ + sub linkpage ($) { my $link=shift; my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_"; diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index 37752dd..ccaa399 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm - @@ -59,7 +59,7 @@ sub preprocess (@) { #{{{ + @@ -59,7 +59,7 @@ sub preprocess (@) { map { "
  • $_
  • " } - sort @broken) + sort titlecmp @broken) ."\n"; - } # }}} + } diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 8efef3f..263e7a6 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm - @@ -192,7 +192,7 @@ sub preprocess_inline (@) { #{{{ + @@ -192,7 +192,7 @@ sub preprocess_inline (@) { } if (exists $params{sort} && $params{sort} eq 'title') { @@ -228,20 +228,20 @@ Joey, have you forgotten about that request? ;) --[[Paweł|ptecza]] index b910758..10a1d87 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm - @@ -56,7 +56,7 @@ sub preprocess (@) { #{{{ + @@ -56,7 +56,7 @@ sub preprocess (@) { htmllink($params{page}, $params{destpage}, $_, noimageinline => 1). "" - } sort @orphans). + } sort titlecmp @orphans). "\n"; - } # }}} + } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index ceb7c84..00798e1 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm - @@ -89,7 +89,7 @@ sub genpage ($$) { #{{{ + @@ -89,7 +89,7 @@ sub genpage ($$) { $template->param(have_actions => 1); } diff --git a/doc/todo/language_definition_for_the_meta_plugin.mdwn b/doc/todo/language_definition_for_the_meta_plugin.mdwn index 33098c601..4ac4e2e25 100644 --- a/doc/todo/language_definition_for_the_meta_plugin.mdwn +++ b/doc/todo/language_definition_for_the_meta_plugin.mdwn @@ -54,7 +54,7 @@ This may be useful for sites with a few pages in different languages, but no ful my %authorurl; +my %lang; - sub import { #{{{ + sub import { hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); @@ -100,6 +101,11 @@ $meta{$page}.=' > Please resolve lang somewhere reusable rather than within meta plugin: It is certainly usable outside diff --git a/doc/todo/meta_rcsid.mdwn b/doc/todo/meta_rcsid.mdwn index 81a2c1328..158edea6e 100644 --- a/doc/todo/meta_rcsid.mdwn +++ b/doc/todo/meta_rcsid.mdwn @@ -26,7 +26,7 @@ of CVS/SVN-style keywords (like '$Id$', etc.) from the source file in the page t my %copyright; +my %rcsid; - sub import { #{{{ + sub import { hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); @@ -110,6 +111,9 @@ $meta{$page}.="\n"; diff --git a/doc/todo/missingparents.pm.mdwn b/doc/todo/missingparents.pm.mdwn index 0cc7137ba..c5f2ab535 100644 --- a/doc/todo/missingparents.pm.mdwn +++ b/doc/todo/missingparents.pm.mdwn @@ -82,15 +82,15 @@ Index: IkiWiki/Plugin/missingparents.pm +my %ownfiles; +my @pagespecs; + -+sub import { #{{{ ++sub import { + hook(type => "checkconfig", id => "missingparents", call => \&checkconfig); + hook(type => "needsdelete", id => "missingparents", call => \&needsdelete); + hook(type => "needsbuild", id => "missingparents", call => \&needsbuild); + hook(type => "savestate", id => "missingparents", call => \&savestate); + hook(type => "preprocess", id => "missingparents", call => \&preprocess_missingparents); -+} # }}} ++} + -+sub checkconfig () { #{{{ ++sub checkconfig () { + IkiWiki::preprocess("missingparents", "missingparents", + readfile(srcfile("missingparents.mdwn"))); + loadstate(); @@ -99,9 +99,9 @@ Index: IkiWiki/Plugin/missingparents.pm + unlink $config{srcdir}.'/'.$file; + } + } -+} #}}} ++} + -+sub preprocess_missingparents (@) { #{{{ ++sub preprocess_missingparents (@) { + my %params=@_; + + if (! defined $params{pages} || ! defined $params{generate}) { @@ -115,10 +115,10 @@ Index: IkiWiki/Plugin/missingparents.pm + #translators: is text for pages that match that pagespec. + return sprintf(gettext("missingparents in %s will be %s"), + '`'.$params{pages}.'`', '`\\'.$params{generate}.'`'); -+} # }}} ++} + +my $state_loaded=0; -+sub loadstate() { #{{{ ++sub loadstate() { + my $filename = "$config{wikistatedir}/missingparents"; + if (-e $filename) { + open (IN, $filename) || @@ -132,9 +132,9 @@ Index: IkiWiki/Plugin/missingparents.pm + + $state_loaded=1; + } -+} #}}} ++} + -+sub savestate() { #{{{ ++sub savestate() { + my $filename = "$config{wikistatedir}/missingparents.new"; + my $cleanup = sub { unlink ($filename) }; + open (OUT, ">$filename") || error("open $filename: $!", $cleanup); @@ -143,9 +143,9 @@ Index: IkiWiki/Plugin/missingparents.pm + } + rename($filename, "$config{wikistatedir}/missingparents") || + error("rename $filename: $!", $cleanup); -+} #}}} ++} + -+sub needsdelete (@) { #{{{ ++sub needsdelete (@) { + my $files=shift; + + my @mydel; @@ -167,9 +167,9 @@ Index: IkiWiki/Plugin/missingparents.pm + foreach my $page (@mydel){ + push @{$files}, $page; + } -+} #}}} ++} + -+sub check_matches($) { #{{{ ++sub check_matches($) { + my $page = shift; + return if $IkiWiki::pagesources{$page}; + @@ -183,9 +183,9 @@ Index: IkiWiki/Plugin/missingparents.pm + return $output; + } + return ""; -+} #}}} ++} + -+sub needsbuild ($) { #{{{ ++sub needsbuild ($) { + my $files=shift; + my @new; + @@ -209,7 +209,7 @@ Index: IkiWiki/Plugin/missingparents.pm + $ownfiles{$file} = 1; + push @{$files}, $file; + } -+} #}}} ++} + +1 Index: IkiWiki.pm @@ -227,18 +227,18 @@ Index: IkiWiki.pm our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE @@ -330,6 +336,30 @@ error("failed renaming $newfile to $destdir/$file: $!", $cleanup); - } #}}} + } -+sub newpage($$) { #{{{ ++sub newpage($$) { + my $file=shift; + my $page=shift; + + $pagemtime{$page} = $pagectime{$page} = time; + $pagesources{$page} = $file; + $pagecase{lc $page} = $page; -+} #}}} ++} + -+sub delpage($) { #{{{ ++sub delpage($) { + my $page=shift; + $links{$page}=[]; + $renderedfiles{$page}=[]; @@ -251,10 +251,10 @@ Index: IkiWiki.pm + delete $destsources{$_}; + } + } -+} #}}} ++} + my %cleared; - sub will_render ($$;$) { #{{{ + sub will_render ($$;$) { my $page=shift; diff --git a/doc/todo/modify_page_filename_in_plugin.mdwn b/doc/todo/modify_page_filename_in_plugin.mdwn index 7c0a909eb..4099487a1 100644 --- a/doc/todo/modify_page_filename_in_plugin.mdwn +++ b/doc/todo/modify_page_filename_in_plugin.mdwn @@ -10,7 +10,7 @@ My solution is to allow plugins to provide a hook that sets the pagename. --[[/u +++ /usr/share/perl5/IkiWiki.pm 2008-10-07 11:57:26.000000000 -0400 @@ -196,11 +196,32 @@ - sub pagename ($) { #{{{ + sub pagename ($) { my $file=shift; my $type=pagetype($file); @@ -27,7 +27,7 @@ My solution is to allow plugins to provide a hook that sets the pagename. --[[/u $page=~s/\Q.$type\E*$// if defined $type; return $page; + } - } #}}} + } - sub htmlpage ($) { #{{{ + sub htmlpage ($) { diff --git a/doc/todo/pagespec_relative_to_a_target.mdwn b/doc/todo/pagespec_relative_to_a_target.mdwn index f7b248670..4757988e0 100644 --- a/doc/todo/pagespec_relative_to_a_target.mdwn +++ b/doc/todo/pagespec_relative_to_a_target.mdwn @@ -57,7 +57,7 @@ diff -urNX ignorepats ikiwiki/IkiWiki/Plugin/relative.pm ikidev/IkiWiki/Plugin/r + +package IkiWiki::PageSpec; + -+sub match_relative($$;@) { #{{{ ++sub match_relative($$;@) { + my $parent = shift; + my $spec = shift; + my %params = @_; @@ -69,21 +69,21 @@ diff -urNX ignorepats ikiwiki/IkiWiki/Plugin/relative.pm ikidev/IkiWiki/Plugin/r + } + } + return IkiWiki::FailReason->new("$parent can't match $spec against anything"); -+} #}}} ++} + -+sub match_has_child($$;@) { #{{{ ++sub match_has_child($$;@) { + my $page = shift; + my $childname = shift; + my $spec; -+ if ($childname) { #{{{ ++ if ($childname) { + $spec = "$page/$childname or $page/*/$childname"; -+ } #}}} -+ else { #{{{ ++ } ++ else { + $spec = "$page/*"; -+ } #}}} ++ } + + return match_relative($page, $spec, @_); -+} #}}} ++} + +1 diff --git a/doc/todo/provide_sha1_for_git_diffurl.mdwn b/doc/todo/provide_sha1_for_git_diffurl.mdwn index 9c8b340de..01aa512f8 100644 --- a/doc/todo/provide_sha1_for_git_diffurl.mdwn +++ b/doc/todo/provide_sha1_for_git_diffurl.mdwn @@ -10,7 +10,7 @@ diffurls of the following form: index 5bef928..164210d 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm - @@ -518,6 +518,7 @@ sub rcs_recentchanges ($) { #{{{ + @@ -518,6 +518,7 @@ sub rcs_recentchanges ($) { my $diffurl = defined $config{'diffurl'} ? $config{'diffurl'} : ""; $diffurl =~ s/\[\[file\]\]/$file/go; diff --git a/doc/todo/require_CAPTCHA_to_edit.mdwn b/doc/todo/require_CAPTCHA_to_edit.mdwn index 110b4167f..83ba07eb0 100644 --- a/doc/todo/require_CAPTCHA_to_edit.mdwn +++ b/doc/todo/require_CAPTCHA_to_edit.mdwn @@ -91,15 +91,15 @@ ignored. --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm -@@ -18,6 +18,7 @@ sub getopt () { #{{{ +@@ -18,6 +18,7 @@ sub getopt () { error($@) if $@; Getopt::Long::Configure('pass_through'); GetOptions("openidsignup=s" => \$config{openidsignup}); + GetOptions("openidneedscaptcha=s" => \$config{openidneedscaptcha}); - } #}}} + } - sub formbuilder_setup (@) { #{{{ -@@ -61,6 +62,7 @@ sub formbuilder_setup (@) { #{{{ + sub formbuilder_setup (@) { +@@ -61,6 +62,7 @@ sub formbuilder_setup (@) { # Skip all other required fields in this case. foreach my $field ($form->field) { next if $field eq "openid_url"; @@ -107,7 +107,7 @@ ignored. $form->field(name => $field, required => 0, validate => '/.*/'); } -@@ -96,6 +98,18 @@ sub validate ($$$;$) { #{{{ +@@ -96,6 +98,18 @@ sub validate ($$$;$) { } } @@ -152,19 +152,19 @@ use warnings; use strict; use IkiWiki 2.00; -sub import { #{{{ +sub import { hook(type => "formbuilder_setup", id => "recaptcha", call => \&formbuilder_setup); -} # }}} +} -sub getopt () { #{{{ +sub getopt () { eval q{use Getopt::Long}; error($@) if $@; Getopt::Long::Configure('pass_through'); GetOptions("reCaptchaPubKey=s" => \$config{reCaptchaPubKey}); GetOptions("reCaptchaPrivKey=s" => \$config{reCaptchaPrivKey}); -} #}}} +} -sub formbuilder_setup (@) { #{{{ +sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; @@ -274,7 +274,7 @@ EOTAGS }); } } -} # }}} +} # The following function is borrowed from # Captcha::reCAPTCHA by Andy Armstrong and are under the PERL Artistic License diff --git a/doc/todo/source_link.mdwn b/doc/todo/source_link.mdwn index 5d6cb89e8..b051361a8 100644 --- a/doc/todo/source_link.mdwn +++ b/doc/todo/source_link.mdwn @@ -31,13 +31,13 @@ I just implemented this. There is one [[patch]] to the default page template, a use IkiWiki; use open qw{:utf8 :std}; - sub import { #{{{ + sub import { hook(type => "getsetup", id => "getsource", call => \&getsetup); hook(type => "pagetemplate", id => "getsource", call => \&pagetemplate); hook(type => "sessioncgi", id => "getsource", call => \&cgi_getsource); - } # }}} + } - sub getsetup () { #{{{ + sub getsetup () { return plugin => { safe => 1, @@ -50,9 +50,9 @@ I just implemented this. There is one [[patch]] to the default page template, a safe => 1, rebuild => 0, }, - } #}}} + } - sub pagetemplate (@) { #{{{ + sub pagetemplate (@) { my %params=@_; my $page=$params{page}; @@ -62,9 +62,9 @@ I just implemented this. There is one [[patch]] to the default page template, a $template->param(getsourceurl => IkiWiki::cgiurl(do => "getsource", page => $page)); $template->param(have_actions => 1); } - } # }}} + } - sub cgi_getsource ($$) { #{{{ + sub cgi_getsource ($$) { my $cgi=shift; my $session=shift; diff --git a/doc/todo/structured_page_data.mdwn b/doc/todo/structured_page_data.mdwn index 2a196ed23..22f67cc0a 100644 --- a/doc/todo/structured_page_data.mdwn +++ b/doc/todo/structured_page_data.mdwn @@ -257,21 +257,21 @@ in a large number of other cases. use CGI::FormBuilder; use IkiWiki 2.00; - sub import { #{{{ + sub import { hook(type => "getsetup", id => "form", call => \&getsetup); hook(type => "htmlize", id => "form", call => \&htmlize); hook(type => "sessioncgi", id => "form", call => \&cgi_submit); - } # }}} + } - sub getsetup () { #{{{ + sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, - } #}}} + } - sub makeFormFromYAML ($$$) { #{{{ + sub makeFormFromYAML ($$$) { my $page = shift; my $YAMLString = shift; my $q = shift; @@ -350,9 +350,9 @@ in a large number of other cases. # IkiWiki::decode_form_utf8($form); return $form; - } #}}} + } - sub htmlize (@) { #{{{ + sub htmlize (@) { my %params=@_; my $content = $params{content}; my $page = $params{page}; @@ -360,9 +360,9 @@ in a large number of other cases. my $form = makeFormFromYAML($page, $content, undef); return $form->render(submit => 'Update Form'); - } # }}} + } - sub cgi_submit ($$) { #{{{ + sub cgi_submit ($$) { my $q=shift; my $session=shift; @@ -425,11 +425,11 @@ in a large number of other cases. } exit; - } #}}} + } package IkiWiki::PageSpec; - sub match_form_eq ($$;@) { #{{{ + sub match_form_eq ($$;@) { my $page=shift; my $argSet=shift; my @args=split(/,/, $argSet); @@ -460,7 +460,7 @@ in a large number of other cases. } else { return IkiWiki::FailReason->new("field value does not match"); } - } #}}} + } 1 @@ -476,22 +476,22 @@ in a large number of other cases. my $inTable = 0; - sub import { #{{{ + sub import { hook(type => "getsetup", id => "data", call => \&getsetup); hook(type => "needsbuild", id => "data", call => \&needsbuild); hook(type => "preprocess", id => "data", call => \&preprocess, scan => 1); hook(type => "preprocess", id => "datatable", call => \&preprocess_table, scan => 1); # does this need scan? - } # }}} + } - sub getsetup () { #{{{ + sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin }, - } #}}} + } - sub needsbuild (@) { #{{{ + sub needsbuild (@) { my $needsbuild=shift; foreach my $page (keys %pagestate) { if (exists $pagestate{$page}{data}) { @@ -506,7 +506,7 @@ in a large number of other cases. } } - sub preprocess (@) { #{{{ + sub preprocess (@) { my @argslist = @_; my %params=@argslist; @@ -546,9 +546,9 @@ in a large number of other cases. } return $html; - } # }}} + } - sub preprocess_table (@) { #{{{ + sub preprocess_table (@) { my %params=@_; my @lines; @@ -568,11 +568,11 @@ in a large number of other cases. push @lines, ''; return join("\n", @lines); - } #}}} + } package IkiWiki::PageSpec; - sub match_data_eq ($$;@) { #{{{ + sub match_data_eq ($$;@) { my $page=shift; my $argSet=shift; my @args=split(/,/, $argSet); @@ -592,9 +592,9 @@ in a large number of other cases. } else { return IkiWiki::FailReason->new("value does not match"); } - } #}}} + } - sub match_data_link ($$;@) { #{{{ + sub match_data_link ($$;@) { my $page=shift; my $argSet=shift; my @params=@_; @@ -618,6 +618,6 @@ in a large number of other cases. } return IkiWiki::FailReason->new("No data link on page $page with key $key matches glob $value"); - } #}}} + } 1 diff --git a/doc/todo/supporting_comments_via_disussion_pages.mdwn b/doc/todo/supporting_comments_via_disussion_pages.mdwn index 892db18a9..aae0b3008 100644 --- a/doc/todo/supporting_comments_via_disussion_pages.mdwn +++ b/doc/todo/supporting_comments_via_disussion_pages.mdwn @@ -91,14 +91,14 @@ Each comment is processed to something like this: use strict; use IkiWiki '1.02'; - sub import { #{{{ + sub import { hook(type => "formbuilder_setup", id => "comments", call => \&formbuilder_setup); hook(type => "preprocess", id => "blogcomment", call => \&preprocess); - } # }}} + } - sub formbuilder_setup (@) { #{{{ + sub formbuilder_setup (@) { my %params=@_; my $cgi = $params{cgi}; my $form = $params{form}; @@ -138,9 +138,9 @@ Each comment is processed to something like this: $content.=qq{[[!blogcomment from="""$name""" timestamp="""$timestamp""" subject="""$subject""" text="""$comment"""]]\n\n}; $content=~s/\n/\r\n/g; $form->field(name => "editcontent", value => $content, force => 1); - } # }}} + } - sub preprocess (@) { #{{{ + sub preprocess (@) { my %params=@_; my ($text, $date, $from, $subject, $r); @@ -159,7 +159,7 @@ Each comment is processed to something like this: $r .= "\n" . $text . "
    \n"; return $r; - } # }}} + } 1; diff --git a/doc/todo/syntax_highlighting.mdwn b/doc/todo/syntax_highlighting.mdwn index 2bdeb62be..3de3032b3 100644 --- a/doc/todo/syntax_highlighting.mdwn +++ b/doc/todo/syntax_highlighting.mdwn @@ -90,7 +90,7 @@ like this: index 8d728c9..1bd46a9 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -618,6 +618,8 @@ sub pagetype ($) { #{{{ + @@ -618,6 +618,8 @@ sub pagetype ($) { if ($page =~ /\.([^.]+)$/) { return $1 if exists $hooks{htmlize}{$1}; @@ -98,7 +98,7 @@ like this: + return $page; } return; - } #}}} + } ## format directive diff --git a/doc/todo/tidy_git__39__s_ctime_debug_output.mdwn b/doc/todo/tidy_git__39__s_ctime_debug_output.mdwn index aaa040ec7..bfc130d69 100644 --- a/doc/todo/tidy_git__39__s_ctime_debug_output.mdwn +++ b/doc/todo/tidy_git__39__s_ctime_debug_output.mdwn @@ -10,6 +10,6 @@ + debug("ctime for '$file': ". localtime($ctime)); return $ctime; - } #}}} + } [[!tag patch done]] diff --git a/doc/todo/tmplvars_plugin.mdwn b/doc/todo/tmplvars_plugin.mdwn index f7d06a579..644cf23aa 100644 --- a/doc/todo/tmplvars_plugin.mdwn +++ b/doc/todo/tmplvars_plugin.mdwn @@ -11,12 +11,12 @@ A simple plugin to allow per-page customization of a template by passing paramat my %tmplvars; - sub import { #{{{ + sub import { hook(type => "preprocess", id => "tmplvars", call => \&preprocess); hook(type => "pagetemplate", id => "tmplvars", call => \&pagetemplate); - } # }}} + } - sub preprocess (@) { #{{{ + sub preprocess (@) { my %params=@_; if ($params{page} eq $params{destpage}) { @@ -34,9 +34,9 @@ A simple plugin to allow per-page customization of a template by passing paramat } } - } # }}} + } - sub pagetemplate (@) { #{{{ + sub pagetemplate (@) { my %params=@_; my $template = $params{template}; @@ -47,6 +47,6 @@ A simple plugin to allow per-page customization of a template by passing paramat } return undef; - } # }}} + } 1 diff --git a/doc/todo/tracking_bugs_with_dependencies.mdwn b/doc/todo/tracking_bugs_with_dependencies.mdwn index 3af0458bd..2832e37aa 100644 --- a/doc/todo/tracking_bugs_with_dependencies.mdwn +++ b/doc/todo/tracking_bugs_with_dependencies.mdwn @@ -194,9 +194,9 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W index 4e4da11..8b3cdfe 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm - @@ -1550,7 +1550,16 @@ sub globlist_to_pagespec ($) { #{{{ + @@ -1550,7 +1550,16 @@ sub globlist_to_pagespec ($) { - sub is_globlist ($) { #{{{ + sub is_globlist ($) { my $s=shift; - return ( $s =~ /[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or" ); + return ! ($s =~ / @@ -209,19 +209,19 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W + ) | + (\s and \s) | (\s or \s) # or we find 'and' or 'or' somewhere + /xs); - } #}}} + } - sub safequote ($) { #{{{ - @@ -1631,7 +1640,7 @@ sub pagespec_merge ($$) { #{{{ + sub safequote ($) { + @@ -1631,7 +1640,7 @@ sub pagespec_merge ($$) { return "($a) or ($b)"; - } #}}} + } - -sub pagespec_translate ($) { #{{{ - +sub pagespec_makeperl ($) { #{{{ + -sub pagespec_translate ($) { + +sub pagespec_makeperl ($) { my $spec=shift; # Support for old-style GlobLists. - @@ -1650,12 +1659,14 @@ sub pagespec_translate ($) { #{{{ + @@ -1650,12 +1659,14 @@ sub pagespec_translate ($) { | \) # ) | @@ -238,7 +238,7 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W my $word=$1; if (lc $word eq 'and') { $code.=' &&'; - @@ -1666,16 +1677,23 @@ sub pagespec_translate ($) { #{{{ + @@ -1666,16 +1677,23 @@ sub pagespec_translate ($) { elsif ($word eq "(" || $word eq ")" || $word eq "!") { $code.=' '.$word; } @@ -265,14 +265,14 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W } } - @@ -1683,8 +1701,18 @@ sub pagespec_translate ($) { #{{{ + @@ -1683,8 +1701,18 @@ sub pagespec_translate ($) { $code=0; } + return 'sub { my $page=shift; my %params = @_; '.$code.' }'; - +} #}}} + +} + - +sub pagespec_translate ($) { #{{{ + +sub pagespec_translate ($) { + my $spec=shift; + + my $code = pagespec_makeperl($spec); @@ -282,19 +282,19 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W no warnings; - return eval 'sub { my $page=shift; '.$code.' }'; + return eval $code; - } #}}} + } - sub pagespec_match ($$;@) { #{{{ - @@ -1699,7 +1727,7 @@ sub pagespec_match ($$;@) { #{{{ + sub pagespec_match ($$;@) { + @@ -1699,7 +1727,7 @@ sub pagespec_match ($$;@) { my $sub=pagespec_translate($spec); return IkiWiki::FailReason->new("syntax error in pagespec \"$spec\"") if $@; - return $sub->($page, @params); + return $sub->($page, @params, specFuncs => {}); - } #}}} + } - sub pagespec_valid ($) { #{{{ - @@ -1748,11 +1776,78 @@ sub new { #{{{ + sub pagespec_valid ($) { + @@ -1748,11 +1776,78 @@ sub new { package IkiWiki::PageSpec; @@ -361,7 +361,7 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W + } +} + - sub match_glob ($$;@) { #{{{ + sub match_glob ($$;@) { my $page=shift; my $glob=shift; my %params=@_; @@ -373,9 +373,9 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W my $from=exists $params{location} ? $params{location} : ''; # relative matching - @@ -1782,11 +1877,12 @@ sub match_internal ($$;@) { #{{{ + @@ -1782,11 +1877,12 @@ sub match_internal ($$;@) { - sub match_link ($$;@) { #{{{ + sub match_link ($$;@) { my $page=shift; - my $link=lc(shift); + my $fulllink=shift; @@ -388,7 +388,7 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W # relative matching if ($link =~ m!^\.! && defined $from) { $from=~s#/?[^/]+$##; - @@ -1804,19 +1900,32 @@ sub match_link ($$;@) { #{{{ + @@ -1804,19 +1900,32 @@ sub match_link ($$;@) { } else { return IkiWiki::SuccessReason->new("$page links to page $p matching $link") @@ -397,9 +397,9 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W } } return IkiWiki::FailReason->new("$page does not link to $link"); - } #}}} + } - sub match_backlink ($$;@) { #{{{ + sub match_backlink ($$;@) { - return match_link($_[1], $_[0], @_); + my $page=shift; + my $backlink=shift; @@ -410,9 +410,9 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W + } + + return match_link($backlink, $page, @params); - } #}}} + } - sub match_created_before ($$;@) { #{{{ + sub match_created_before ($$;@) { my $page=shift; my $testpage=shift; + my @params=@_; @@ -423,8 +423,8 @@ account all comments above (which doesn't mean it is above reproach :) ). --[[W if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) { - @@ -1834,6 +1943,11 @@ sub match_created_before ($$;@) { #{{{ - sub match_created_after ($$;@) { #{{{ + @@ -1834,6 +1943,11 @@ sub match_created_before ($$;@) { + sub match_created_after ($$;@) { my $page=shift; my $testpage=shift; + my @params=@_; diff --git a/doc/todo/turn_edittemplate_verbosity_off_by_default.mdwn b/doc/todo/turn_edittemplate_verbosity_off_by_default.mdwn index 87e55685c..14bb43782 100644 --- a/doc/todo/turn_edittemplate_verbosity_off_by_default.mdwn +++ b/doc/todo/turn_edittemplate_verbosity_off_by_default.mdwn @@ -8,7 +8,7 @@ I think this (untested) patch might just do the trick: --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm - @@ -46,8 +46,13 @@ sub preprocess (@) { #{{{ + @@ -46,8 +46,13 @@ sub preprocess (@) { $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template}; @@ -21,9 +21,9 @@ I think this (untested) patch might just do the trick: + else { + return ''; + } - } # }}} + } - sub formbuilder (@) { #{{{ + sub formbuilder (@) { --[[madduck]] diff --git a/doc/todo/using_meta_titles_for_parentlinks.html b/doc/todo/using_meta_titles_for_parentlinks.html index d04e5a300..6da40a415 100644 --- a/doc/todo/using_meta_titles_for_parentlinks.html +++ b/doc/todo/using_meta_titles_for_parentlinks.html @@ -82,9 +82,9 @@ diff -c /usr/share/perl5/IkiWiki/Plugin/meta.pm.distrib /usr/share/perl5/IkiWiki *** 289,294 **** --- 290,319 ---- } - } #}}} + } -+ sub IkiWiki::pagetitle ($;$) { #{{{ ++ sub IkiWiki::pagetitle ($;$) { + my $page=shift; + my $unescaped=shift; + @@ -106,11 +106,11 @@ diff -c /usr/share/perl5/IkiWiki/Plugin/meta.pm.distrib /usr/share/perl5/IkiWiki + } + + return $page; -+ } #}}} ++ } + package IkiWiki::PageSpec; - sub match_title ($$;@) { #{{{ + sub match_title ($$;@) { diff --git a/doc/todo/varioki_--_add_template_variables___40__with_closures_for_values__41___in_ikiwiki.setup.mdwn b/doc/todo/varioki_--_add_template_variables___40__with_closures_for_values__41___in_ikiwiki.setup.mdwn index 492a32b36..b28469993 100644 --- a/doc/todo/varioki_--_add_template_variables___40__with_closures_for_values__41___in_ikiwiki.setup.mdwn +++ b/doc/todo/varioki_--_add_template_variables___40__with_closures_for_values__41___in_ikiwiki.setup.mdwn @@ -157,9 +157,9 @@ ManojSrivastava +=cut + + -+sub import { #{{{ ++sub import { + hook(type => "pagetemplate", id => "varioki", call => \&pagetemplate); -+} # }}} ++} + + +=pod @@ -175,7 +175,7 @@ ManojSrivastava + +=cut + -+sub pagetemplate (@) { #{{{ ++sub pagetemplate (@) { + my %params=@_; + my $page=$params{page}; + my $template=$params{template}; @@ -207,7 +207,7 @@ ManojSrivastava + $template->param("$var" =>"$value"); + } + } -+} # }}} ++} + +1; + diff --git a/ikiwiki.in b/ikiwiki.in index 473cbdbfd..32a24af84 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -9,12 +9,12 @@ use strict; use lib '.'; # For use in nonstandard directory, munged by Makefile. use IkiWiki; -sub usage () { #{{{ +sub usage () { die gettext("usage: ikiwiki [options] source dest"), "\n", gettext(" ikiwiki --setup configfile"), "\n"; -} #}}} +} -sub getconfig () { #{{{ +sub getconfig () { if (! exists $ENV{WRAPPED_OPTIONS}) { %config=defaultconfig(); eval q{use Getopt::Long}; @@ -123,9 +123,9 @@ sub getconfig () { #{{{ loadplugins(); checkconfig(); } -} #}}} +} -sub main () { #{{{ +sub main () { getconfig(); if ($config{setup}) { @@ -207,6 +207,6 @@ sub main () { #{{{ saveindex(); debug(gettext("done")); } -} #}}} +} main; -- cgit v1.2.3 From 9b837fd5ed984f0947bc3e1f4478384b3b1691fd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 17:05:49 -0500 Subject: fix default values for config settings defaults cannot be set in getsetup, do it in checkconfig to avoid uninitialized value warnings. --- IkiWiki/Plugin/comments.pm | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 6184c6031..83f67869c 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -39,7 +39,6 @@ sub getsetup () { comments_shown_pagespec => { type => 'pagespec', example => 'blog/*', - default => '', description => 'PageSpec for pages where comments will be shown inline', link => 'ikiwiki/PageSpec', safe => 1, @@ -48,7 +47,6 @@ sub getsetup () { comments_open_pagespec => { type => 'pagespec', example => 'blog/* and created_after(close_old_comments)', - default => '', description => 'PageSpec for pages where new comments can be posted', link => 'ikiwiki/PageSpec', safe => 1, @@ -56,7 +54,6 @@ sub getsetup () { }, comments_pagename => { type => 'string', - example => 'comment_', default => 'comment_', description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"', safe => 0, # manual page moving required @@ -64,7 +61,6 @@ sub getsetup () { }, comments_allowdirectives => { type => 'boolean', - default => 0, example => 0, description => 'Interpret directives in comments?', safe => 1, @@ -72,7 +68,6 @@ sub getsetup () { }, comments_allowauthor => { type => 'boolean', - default => 0, example => 0, description => 'Allow anonymous commenters to set an author name?', safe => 1, @@ -81,7 +76,6 @@ sub getsetup () { comments_commit => { type => 'boolean', example => 1, - default => 1, description => 'commit comments to the VCS', # old uncommitted comments are likely to cause # confusion if this is changed @@ -90,6 +84,17 @@ sub getsetup () { }, } +sub checkconfig () { + $config{comments_commit} = 1 + unless defined $config{comments_commit}; + $config{comments_shown_pagespec} = '' + unless defined $config{comments_shown_pagespec}; + $config{comments_open_pagespec} = '' + unless defined $config{comments_open_pagespec}; + $config{comments_pagename} = 'comment_' + unless defined $config{comments_pagename}; +} + sub htmlize { my %params = @_; return $params{content}; @@ -208,12 +213,6 @@ sub preprocess { return $content; } -sub checkconfig () { - $config{comments_commit} = 1 unless defined $config{comments_commit}; - $config{comments_pagename} = 'comment_' - unless defined $config{comments_pagename}; -} - # This is exactly the same as recentchanges_link :-( sub linkcgi ($) { my $cgi=shift; -- cgit v1.2.3 From 140c0bacbadc35de93cc685313123e9e51b45704 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 18:50:04 -0500 Subject: change around comments pagespecs I think it is clearer to have one pagespec that controls all pages with comments, and a separate pagespec that can be used to close new comments on a subset of those pages. --- IkiWiki/Plugin/comments.pm | 43 ++++++++++++++++++++----------------------- doc/plugins/comments.mdwn | 13 +++++++------ 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 83f67869c..6e257d1d9 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -34,20 +34,18 @@ sub getsetup () { safe => 1, rebuild => 1, }, - # Pages where comments are shown, but new comments are not - # allowed, will show "Comments are closed". - comments_shown_pagespec => { + comments_pagespec => { type => 'pagespec', - example => 'blog/*', - description => 'PageSpec for pages where comments will be shown inline', + example => 'blog/* and *!/Discussion', + description => 'PageSpec of pages where comments are allowed', link => 'ikiwiki/PageSpec', safe => 1, rebuild => 1, }, - comments_open_pagespec => { + comments_closed_pagespec => { type => 'pagespec', - example => 'blog/* and created_after(close_old_comments)', - description => 'PageSpec for pages where new comments can be posted', + example => 'blog/controversial or blog/flamewar', + description => 'PageSpec of pages where posting new comments is not allowed', link => 'ikiwiki/PageSpec', safe => 1, rebuild => 1, @@ -87,10 +85,10 @@ sub getsetup () { sub checkconfig () { $config{comments_commit} = 1 unless defined $config{comments_commit}; - $config{comments_shown_pagespec} = '' - unless defined $config{comments_shown_pagespec}; - $config{comments_open_pagespec} = '' - unless defined $config{comments_open_pagespec}; + $config{comments_pagespec} = '' + unless defined $config{comments_pagespec}; + $config{comments_closed_pagespec} = '' + unless defined $config{comments_closed_pagespec}; $config{comments_pagename} = 'comment_' unless defined $config{comments_pagename}; } @@ -371,7 +369,7 @@ sub sessioncgi ($$) { $page)); } - if (not pagespec_match($page, $config{comments_open_pagespec}, + if (pagespec_match($page, $config{comments_closed_pagespec}, location => $page)) { error(sprintf(gettext( "comments on page '%s' are closed"), @@ -523,22 +521,21 @@ sub pagetemplate (@) { my $comments = undef; my $open = 0; - my $shown = pagespec_match($page, - $config{comments_shown_pagespec}, - location => $page); + my $shown = 0; + if (pagespec_match($page, + $config{comments_pagespec}, + location => $page)) { + $shown = 1; + $open = length $config{cgiurl} > 0; + } - if (pagespec_match($page, "*/$config{comments_pagename}*", + if (pagespec_match($page, + "$config{comments_closed_pagespec} or */$config{comments_pagename}*", location => $page)) { $shown = 0; $open = 0; } - if (length $config{cgiurl}) { - $open = pagespec_match($page, - $config{comments_open_pagespec}, - location => $page); - } - if ($shown) { $comments = IkiWiki::preprocess_inline( pages => "internal($page/$config{comments_pagename}*)", diff --git a/doc/plugins/comments.mdwn b/doc/plugins/comments.mdwn index a81cab127..afaf2c7ae 100644 --- a/doc/plugins/comments.mdwn +++ b/doc/plugins/comments.mdwn @@ -23,12 +23,13 @@ Individual comments are stored as internal-use pages named something like There are some global options for the setup file: -* `comments_open_pagespec`: pages where new comments can be posted, e.g. - `blog/* and created_after(close_old_comments)` or `!*/discussion`. - You need to set this, since the default is to not add comments to any - pages. -* `comments_shown_pagespec`: pages where comments will be displayed inline, - e.g. `blog/*` or `!*/discussion`. +* `comments_pagespec`: [[ikiwiki/PageSpec]] of pages where comments are + allowed. The default is not to allow comments on any pages. To allow + comments to all posts to a blog, you could use `blog/* and !*/Discussion`. +* `comments_closed_pagespec`: [[ikiwiki/PageSpec]] of pages where + posting of new comments is closed, but any existing comments will still + be displayed. Often you will list a set of individual pages here. + For example: `blog/controversial or blog/flamewar` * `comments_pagename`: if this is e.g. `comment_` (the default), then comment pages will be named something like `page/comment_12` * `comments_allowdirectives`: if true (default false), comments may -- cgit v1.2.3 From 5feffc8b0b953856052c09dd431984e2e835b439 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 19:06:29 -0500 Subject: fix test when comments_closed_pagespec is empty --- IkiWiki/Plugin/comments.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 6e257d1d9..0b3007097 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -529,8 +529,13 @@ sub pagetemplate (@) { $open = length $config{cgiurl} > 0; } - if (pagespec_match($page, - "$config{comments_closed_pagespec} or */$config{comments_pagename}*", + if (pagespec_match($page, "*/$config{comments_pagename}*", + location => $page)) { + $shown = 0; + $open = 0; + } + if (length $config{comments_closed_pagespec} && + pagespec_match($page, $config{comments_closed_pagespec}, location => $page)) { $shown = 0; $open = 0; -- cgit v1.2.3 From cd7ac8f72a43a53aeca3b5e8daf906e990420016 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Dec 2008 19:38:02 -0500 Subject: add Comments link when displaying a page inline This link will supplant the usual Discussion link for pages that have comments enabled. --- IkiWiki/Plugin/comments.pm | 58 ++++++++++++++++++++++++++++------------------ templates/inlinepage.tmpl | 4 ++++ templates/page.tmpl | 6 ++--- 3 files changed, 41 insertions(+), 27 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 0b3007097..cb5a517a1 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -511,6 +511,24 @@ sub sessioncgi ($$) { exit; } +sub commentsshown ($) { + my $page=shift; + + return ! pagespec_match($page, "*/$config{comments_pagename}*", + location => $page) && + pagespec_match($page, $config{comments_pagespec}, + location => $page); +} + +sub commentsopen ($) { + my $page = shift; + + return length $config{cgiurl} > 0 && + (! length $config{comments_closed_pagespec} || + ! pagespec_match($page, $config{comments_closed_pagespec}, + location => $page)); +} + sub pagetemplate (@) { my %params = @_; @@ -518,29 +536,9 @@ sub pagetemplate (@) { my $template = $params{template}; if ($template->query(name => 'comments')) { - my $comments = undef; - - my $open = 0; - my $shown = 0; - if (pagespec_match($page, - $config{comments_pagespec}, - location => $page)) { - $shown = 1; - $open = length $config{cgiurl} > 0; - } - - if (pagespec_match($page, "*/$config{comments_pagename}*", - location => $page)) { - $shown = 0; - $open = 0; - } - if (length $config{comments_closed_pagespec} && - pagespec_match($page, $config{comments_closed_pagespec}, - location => $page)) { - $shown = 0; - $open = 0; - } + my $shown = commentsshown($page); + my $comments = undef; if ($shown) { $comments = IkiWiki::preprocess_inline( pages => "internal($page/$config{comments_pagename}*)", @@ -558,13 +556,27 @@ sub pagetemplate (@) { $template->param(comments => $comments); } - if ($open) { + if ($shown && commentsopen($page)) { my $commenturl = IkiWiki::cgiurl(do => 'comment', page => $page); $template->param(commenturl => $commenturl); } } + if ($template->query(name => 'commentslink')) { + # XXX Would be nice to say how many comments there are in + # the link. But, to update the number, blog pages + # would have to update whenever comments of any inlines + # page are added, which is not currently done. + if (commentsshown($page)) { + $template->param(commentslink => + htmllink($page, $params{destpage}, $page, + linktext => gettext("Comments"), + anchor => "comments", + noimageinline => 1)); + } + } + if ($template->query(name => 'commentuser')) { $template->param(commentuser => $pagestate{$page}{comments}{commentuser}); diff --git a/templates/inlinepage.tmpl b/templates/inlinepage.tmpl index 984d33cef..3c0b93315 100644 --- a/templates/inlinepage.tmpl +++ b/templates/inlinepage.tmpl @@ -58,9 +58,13 @@ License:
  • Edit
  • + +
  • +
  • +
    diff --git a/templates/page.tmpl b/templates/page.tmpl index ea50fb722..79c2b8b6e 100644 --- a/templates/page.tmpl +++ b/templates/page.tmpl @@ -70,18 +70,16 @@
    -
    -
    Comments on this page are closed.
    -
    - + +