From 7f80e52543891690e3136855bc29917e6b431aba Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 9 Nov 2008 15:31:57 -0500 Subject: Fix the link() pagespec to match links that are internally recorded as absolute. This fixes a problem exposed by the recent change to tags (a2839de9362187b67b0e3a564461e272e64fd9b4). That recorded tag links as absolute by including a leading slash in the link. The same could also be done with an absolute wikilink. In either case, link() would not match such links, unless the leading slash was included in the link to match. But that's not right, because pagespecs match absolute by default. So strip the leading slash. Note that to keep any existing `link(/foo)` pagespecs working after this change, the leading slash is removed from there, too. --- t/pagespec_match.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/pagespec_match.t b/t/pagespec_match.t index c61d16122..7c0ac235b 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 56; +use Test::More tests => 58; BEGIN { use_ok("IkiWiki"); } @@ -40,6 +40,7 @@ $links{"bugs/bar"}=[qw{done}]; $links{"done"}=[]; $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}]; $links{"examples/softwaresite/bugs/done"}=[]; +$links{"ook"}=[qw{/blog/tags/foo}]; ok(pagespec_match("foo", "link(bar)"), "link"); ok(pagespec_match("foo", "link(ba?)"), "glob link"); @@ -55,6 +56,8 @@ ok(pagespec_match("bar", "backlink(foo)"), "backlink"); ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink"); ok(! pagespec_match("bar", ""), "empty pagespec should match nothing"); ok(! pagespec_match("bar", " "), "blank pagespec should match nothing"); +ok(pagespec_match("ook", "link(blog/tags/foo)"), "link internal absolute success"); +ok(pagespec_match("ook", "link(/blog/tags/foo)"), "link explicit absolute success"); $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006 $IkiWiki::pagectime{bar}=1154532695; # after -- cgit v1.2.3 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 +++++++++++++++++++++++++++++++++++++++++++ doc/plugins/aggregate.mdwn | 6 ++--- doc/plugins/htmlbalance.mdwn | 9 +++++++ doc/plugins/htmltidy.mdwn | 3 ++- t/htmlbalance.t | 13 ++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 IkiWiki/Plugin/htmlbalance.pm create mode 100644 doc/plugins/htmlbalance.mdwn create mode 100755 t/htmlbalance.t (limited to 't') 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 diff --git a/doc/plugins/aggregate.mdwn b/doc/plugins/aggregate.mdwn index c40a6dc22..6fc87853b 100644 --- a/doc/plugins/aggregate.mdwn +++ b/doc/plugins/aggregate.mdwn @@ -9,9 +9,9 @@ New users of aggregate should enable the `aggregateinternal => 1` option in the .setup file. If you don't do so, you will need to enable the [[html]] plugin as well as aggregate itself, since feed entries will be stored as HTML. -The [[meta]] and [[tag]] plugins are also recommended. The -[[htmltidy]] plugin is suggested, since feeds can easily contain html -problems, some of which tidy can fix. +The [[meta]] and [[tag]] plugins are also recommended. Either the +[[htmltidy]] or [[htmlbalance]] plugin is suggested, since feeds can easily +contain html problems, some of which these plugins can fix. You will need to run ikiwiki periodically from a cron job, passing it the --aggregate parameter, to make it check for new posts. Here's an example diff --git a/doc/plugins/htmlbalance.mdwn b/doc/plugins/htmlbalance.mdwn new file mode 100644 index 000000000..7cdb1f950 --- /dev/null +++ b/doc/plugins/htmlbalance.mdwn @@ -0,0 +1,9 @@ +[[!template id=plugin name=htmlbalance author="Simon McVittie"]] +[[!tag type/html]] + +This plugin ensures that the HTML emitted by ikiwiki contains well-balanced +HTML tags, by parsing it with HTML::TreeBuilder and re-serializing it. This +acts as a lighter-weight alternative to [[plugins/htmltidy]]; it doesn't +ensure validity, but it does at least ensure that formatting from a +blog post pulled in by \[[![[ikiwiki/directive/inline]]]] doesn't +leak into the rest of the page. diff --git a/doc/plugins/htmltidy.mdwn b/doc/plugins/htmltidy.mdwn index f675a01ae..580e56f59 100644 --- a/doc/plugins/htmltidy.mdwn +++ b/doc/plugins/htmltidy.mdwn @@ -7,4 +7,5 @@ emitted by ikiwiki. Besides being nicely formatted, this helps ensure that even if users enter suboptimal html, your wiki generates valid html. Note that since tidy is an external program, that is run each time a page -is built, this plugin will slow ikiwiki down somewhat. +is built, this plugin will slow ikiwiki down somewhat. [[plugins/htmlbalance]] +might provide a faster alternative. diff --git a/t/htmlbalance.t b/t/htmlbalance.t new file mode 100755 index 000000000..cd124e473 --- /dev/null +++ b/t/htmlbalance.t @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 7; + +BEGIN { use_ok("IkiWiki::Plugin::htmlbalance"); } + +is(IkiWiki::Plugin::htmlbalance::sanitize(content => "

"), "
"); +is(IkiWiki::Plugin::htmlbalance::sanitize(content => "

hello world

"), "

hello world

"); +is(IkiWiki::Plugin::htmlbalance::sanitize(content => ""), ""); +is(IkiWiki::Plugin::htmlbalance::sanitize(content => "foo "), "foo "); +is(IkiWiki::Plugin::htmlbalance::sanitize(content => " foo "), " foo "); +is(IkiWiki::Plugin::htmlbalance::sanitize(content => "a>"), "a>"); -- cgit v1.2.3 From 43039d7d86ea66578743867a0b1d484e65816bb2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Nov 2008 14:22:11 -0500 Subject: modify to skip tests if the neccessary perl modules are not available --- t/htmlbalance.t | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/htmlbalance.t b/t/htmlbalance.t index cd124e473..783ed9841 100755 --- a/t/htmlbalance.t +++ b/t/htmlbalance.t @@ -1,9 +1,20 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 7; -BEGIN { use_ok("IkiWiki::Plugin::htmlbalance"); } +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"}; + } + else { + eval q{use Test::More tests => 7}; + } + use_ok("IkiWiki::Plugin::htmlbalance"); +} is(IkiWiki::Plugin::htmlbalance::sanitize(content => "

"), "
"); is(IkiWiki::Plugin::htmlbalance::sanitize(content => "

hello world

"), "

hello world

"); -- 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 't') 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 c42f174e655526bfaace70b31f9cbc79e2e1be9a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:24:53 +0000 Subject: beautify_urlpath: add a regression test --- t/beautify_urlpath.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 t/beautify_urlpath.t (limited to 't') diff --git a/t/beautify_urlpath.t b/t/beautify_urlpath.t new file mode 100755 index 000000000..b9d3493a2 --- /dev/null +++ b/t/beautify_urlpath.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 7; + +BEGIN { use_ok("IkiWiki"); } + +$IkiWiki::config{usedirs} = 1; +$IkiWiki::config{htmlext} = "HTML"; +is(IkiWiki::beautify_urlpath("foo/bar"), "./foo/bar"); +is(IkiWiki::beautify_urlpath("../badger"), "../badger"); +is(IkiWiki::beautify_urlpath("./bleh"), "./bleh"); +is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/"); +is(IkiWiki::beautify_urlpath("index.HTML"), "./"); +$IkiWiki::config{usedirs} = 0; +is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/index.HTML"); -- cgit v1.2.3 From f0c76aa51ca7a1dbfb8fcfa679baa114e563b895 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 16:37:20 +0000 Subject: Add a regression test for &openiduser --- t/openiduser.t | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 t/openiduser.t (limited to 't') diff --git a/t/openiduser.t b/t/openiduser.t new file mode 100755 index 000000000..fe4d2b445 --- /dev/null +++ b/t/openiduser.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl +use warnings; +use strict; + +BEGIN { + eval q{ + use Net::OpenID::VerifiedIdentity; + }; + if ($@) { + eval q{use Test::More skip_all => "Net::OpenID::VerifiedIdentity not available"}; + } + else { + eval q{use Test::More tests => 9}; + } + use_ok("IkiWiki::Plugin::openid"); +} + +# Some typical examples: + +is(IkiWiki::openiduser('http://josephturian.blogspot.com'), 'josephturian [blogspot.com]'); +is(IkiWiki::openiduser('http://yam655.livejournal.com/'), 'yam655 [livejournal.com]'); +is(IkiWiki::openiduser('http://id.mayfirst.org/jamie/'), 'jamie [id.mayfirst.org]'); + +# and some less typical ones taken from the ikiwiki commit history + +is(IkiWiki::openiduser('http://thm.id.fedoraproject.org/'), 'thm [id.fedoraproject.org]'); +is(IkiWiki::openiduser('http://dtrt.org/'), 'dtrt.org'); +is(IkiWiki::openiduser('http://alcopop.org/me/openid/'), 'openid [alcopop.org/me]'); +is(IkiWiki::openiduser('http://id.launchpad.net/882/bielawski1'), 'bielawski1 [id.launchpad.net/882]'); +is(IkiWiki::openiduser('http://technorati.com/people/technorati/drajt'), 'drajt [technorati.com/people/technorati]'); -- cgit v1.2.3 From 5b67c54b2276f053ea0a427597334e0808694727 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 21 Dec 2008 12:59:11 -0500 Subject: add another test --- t/beautify_urlpath.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/beautify_urlpath.t b/t/beautify_urlpath.t index b9d3493a2..94b923d3b 100755 --- a/t/beautify_urlpath.t +++ b/t/beautify_urlpath.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 7; +use Test::More tests => 8; BEGIN { use_ok("IkiWiki"); } @@ -12,5 +12,6 @@ is(IkiWiki::beautify_urlpath("../badger"), "../badger"); is(IkiWiki::beautify_urlpath("./bleh"), "./bleh"); is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/"); is(IkiWiki::beautify_urlpath("index.HTML"), "./"); +is(IkiWiki::beautify_urlpath("../index.HTML"), "../"); $IkiWiki::config{usedirs} = 0; is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/index.HTML"); -- cgit v1.2.3 From 13d77c369e5c2856fad78e48b0e39e4e76d1d5aa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 21 Dec 2008 13:46:00 -0500 Subject: avoid an uninitialized value warning --- t/openiduser.t | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't') diff --git a/t/openiduser.t b/t/openiduser.t index fe4d2b445..52d879484 100755 --- a/t/openiduser.t +++ b/t/openiduser.t @@ -17,7 +17,14 @@ BEGIN { # Some typical examples: +# This test, when run by Test::Harness using perl -w, exposes a warning in +# Net::OpenID::VerifiedIdentity. Normally that warning is not displayed, as +# that module does not use warnings. To avoid cluttering the test output, +# disable the -w switch temporarily. +$^W=0; is(IkiWiki::openiduser('http://josephturian.blogspot.com'), 'josephturian [blogspot.com]'); +$^W=1; + is(IkiWiki::openiduser('http://yam655.livejournal.com/'), 'yam655 [livejournal.com]'); is(IkiWiki::openiduser('http://id.mayfirst.org/jamie/'), 'jamie [id.mayfirst.org]'); -- cgit v1.2.3 From a4ebfe8fe8cec39bbd05fb46ef48b0f2d41a7d0c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 23 Dec 2008 16:55:33 -0500 Subject: fix to use prefix directives --- t/tinyblog/index.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/tinyblog/index.mdwn b/t/tinyblog/index.mdwn index 010c85de1..72ba7846a 100644 --- a/t/tinyblog/index.mdwn +++ b/t/tinyblog/index.mdwn @@ -1 +1 @@ -[[inline pages="post" rss=yes]] +[[!inline pages="post" rss=yes]] -- cgit v1.2.3 From c61c99fc7730dd05bdb56216b115448ccc27bfcd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 23 Dec 2008 16:56:56 -0500 Subject: fix to use prefix directives --- t/basewiki_brokenlinks/index.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/basewiki_brokenlinks/index.mdwn b/t/basewiki_brokenlinks/index.mdwn index 0a6b2c39e..41768f782 100644 --- a/t/basewiki_brokenlinks/index.mdwn +++ b/t/basewiki_brokenlinks/index.mdwn @@ -1 +1 @@ -[[brokenlinks ]] +[[!brokenlinks ]] -- cgit v1.2.3 From c07a95ed8ecb84a2e7018c93c3d031f03bd25926 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 23 Dec 2008 17:11:04 -0500 Subject: remove globlist support No transition code implemented, but I will probably make a 2.x release that warns about found globlists. --- IkiWiki.pm | 45 -------------------------------------------- doc/ikiwiki/pagespec.mdwn | 19 ------------------- doc/plugins/contrib.mdwn | 2 +- doc/tips/upgrade_to_3.0.mdwn | 17 +++++++++++++++++ t/pagespec_match.t | 11 +---------- t/pagespec_merge.t | 12 ++++++------ 6 files changed, 25 insertions(+), 81 deletions(-) (limited to 't') diff --git a/IkiWiki.pm b/IkiWiki.pm index 759bfbc65..f6adb360a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1596,37 +1596,6 @@ sub rcs_receive () { $hooks{rcs}{rcs_receive}{call}->(); } -sub globlist_to_pagespec ($) { - my @globlist=split(' ', shift); - - my (@spec, @skip); - foreach my $glob (@globlist) { - if ($glob=~/^!(.*)/) { - push @skip, $glob; - } - else { - push @spec, $glob; - } - } - - my $spec=join(' or ', @spec); - if (@skip) { - my $skip=join(' and ', @skip); - if (length $spec) { - $spec="$skip and ($spec)"; - } - else { - $spec=$skip; - } - } - return $spec; -} - -sub is_globlist ($) { - my $s=shift; - return ( $s =~ /[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or" ); -} - sub safequote ($) { my $s=shift; $s=~s/[{}]//g; @@ -1718,26 +1687,12 @@ sub pagespec_merge ($$) { my $b=shift; return $a if $a eq $b; - - # Support for old-style GlobLists. - if (is_globlist($a)) { - $a=globlist_to_pagespec($a); - } - if (is_globlist($b)) { - $b=globlist_to_pagespec($b); - } - return "($a) or ($b)"; } sub pagespec_translate ($) { my $spec=shift; - # Support for old-style GlobLists. - if (is_globlist($spec)) { - $spec=globlist_to_pagespec($spec); - } - # Convert spec to perl code. my $code=""; while ($spec=~m{ diff --git a/doc/ikiwiki/pagespec.mdwn b/doc/ikiwiki/pagespec.mdwn index d4dd265cc..86abe5745 100644 --- a/doc/ikiwiki/pagespec.mdwn +++ b/doc/ikiwiki/pagespec.mdwn @@ -72,22 +72,3 @@ filenames of the pages in the wiki, so a pagespec "foo" used on page "a/b" will not match a page named "a/foo" or "a/b/foo". To match relative to the directory of the page containing the pagespec, you can use "./". For example, "./foo" on page "a/b" matches page "a/foo". - -## Old syntax - -The old PageSpec syntax was called a "GlobList", and worked differently in -two ways: - -1. "and" and "or" were not used; any page matching any item from the list - matched. -2. If an item was prefixed with "`!`", then no page matching that item - matched, even if it matched an earlier list item. - -For example, here is the old way to match all pages except for the SandBox -and Discussion pages: - - * !SandBox !*/Discussion - -Using this old syntax is still supported. However, the old syntax is -deprecated and will be removed at some point, and using the new syntax is -recommended. diff --git a/doc/plugins/contrib.mdwn b/doc/plugins/contrib.mdwn index 7a28edaba..e22b13f71 100644 --- a/doc/plugins/contrib.mdwn +++ b/doc/plugins/contrib.mdwn @@ -2,6 +2,6 @@ Contributed [[plugins]]: (See [[install]] for installation help.) -[[!inline pages="plugins/contrib/* !*/Discussion" +[[!inline pages="plugins/contrib/* and !*/Discussion" feedpages="created_after(plugins/contrib/navbar)" archive="yes" rootpage="plugins/contrib" postformtext="Add a new plugin named:" show=0]] diff --git a/doc/tips/upgrade_to_3.0.mdwn b/doc/tips/upgrade_to_3.0.mdwn index 6c74d4fc9..bd47e96e5 100644 --- a/doc/tips/upgrade_to_3.0.mdwn +++ b/doc/tips/upgrade_to_3.0.mdwn @@ -49,6 +49,23 @@ Be sure to modify the find to list all pages in the wiki if you're using other markup than markdown. You will probably want to commit the changes when you're done too. +## GlobLists + +In 3.0, the old "GlobList" syntax for [[PageSpecs|ikiwiki/PageSpec]] is no +longer supported. A GlobList contains multiple term, but does not separate +them with "and" or "or": + + sandbox !*/Discussion + +To convert this to a modern PageSpec, simply add "and" or "or" as +appropriate between terms: + + sandbox and !*/Discussion + +GlobLists have been deprecated for more than two years. If your wiki dates +to the ikiwiki 1.0 era, you should check it for any that might have lurked +unnoticed in it since back then. + ## aggregateinternal If your wiki uses the [[aggregate|plugins/aggregate]] plugin, it will start diff --git a/t/pagespec_match.t b/t/pagespec_match.t index 7c0ac235b..69cf361de 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 58; +use Test::More tests => 51; BEGIN { use_ok("IkiWiki"); } @@ -77,12 +77,3 @@ ok(! pagespec_match("foo", "no_such_function(foo)"), "foo"); my $ret=pagespec_match("foo", "(invalid"); ok(! $ret, "syntax error"); ok($ret =~ /syntax error/, "error message"); - -# old style globlists -ok(pagespec_match("foo", "foo bar"), "simple list"); -ok(pagespec_match("bar", "foo bar"), "simple list 2"); -ok(pagespec_match("foo", "f?? !foz")); -ok(! pagespec_match("foo", "f?? !foo")); -ok(! pagespec_match("foo", "* !foo")); -ok(! pagespec_match("foo", "foo !foo")); -ok(! pagespec_match("foo.png", "* !*.*")); diff --git a/t/pagespec_merge.t b/t/pagespec_merge.t index cbb06219c..9e38d5761 100755 --- a/t/pagespec_merge.t +++ b/t/pagespec_merge.t @@ -28,17 +28,17 @@ ok(same("!foo", "!bar", "foo"), "double inversion failed match"); ok(same("!foo", "!bar", "bar"), "double inversion failed match 2"); ok(same("*", "!bar", "foo"), "glob+inversion match"); ok(same("*", "!bar", "bar"), "matching glob and matching inversion"); -ok(same("* !foo", "!bar", "bar"), "matching glob and matching inversion"); -ok(same("* !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion"); -ok(same("* !foo", "!foo", "foo"), "matching glob with matching inversion and matching inversion"); +ok(same("* and !foo", "!bar", "bar"), "matching glob and matching inversion"); +ok(same("* and !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion"); +ok(same("* and !foo", "!foo", "foo"), "matching glob with matching inversion and matching inversion"); ok(same("b??", "!b??", "bar"), "matching glob and matching inverted glob"); ok(same("f?? !f??", "!bar", "bar"), "matching glob and matching inverted glob"); ok(same("b??", "!b?z", "bar"), "matching glob and non-matching inverted glob"); ok(same("f?? !f?z", "!bar", "bar"), "matching glob and non-matching inverted glob"); ok(same("!foo bar baz", "!bar", "bar"), "matching list and matching inversion"); ok(pagespec_match("foo/Discussion", - IkiWiki::pagespec_merge("* !*/Discussion", "*/Discussion")), "should match"); -ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1"); -ok(same("*/Discussion", "* !*/Discussion", "foo/Discussion"), "Discussion merge 2"); + IkiWiki::pagespec_merge("* and !*/Discussion", "*/Discussion")), "should match"); +ok(same("* and !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1"); +ok(same("*/Discussion", "* and !*/Discussion", "foo/Discussion"), "Discussion merge 2"); ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/Discussion"), "bidirectional merge 1"); ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/bar"), "bidirectional merge 2"); -- cgit v1.2.3 From b0a03fef656989ccf2552262ab8230f980821861 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 3 Jan 2009 12:52:47 -0500 Subject: yesno: Always accept English even when localised. It seems to be a failing of i18n in unix that the translation stops at the commands and the parameters to them, and ikiwiki is no exception with its currently untranslated directives. So the little bit that's translated sticks out like a sore thumb. It also breaks building of wikis if a different locale happens to be set. I suppose the best thing to do is either give up on the localisation of this part completly, or make it recognise English in addition to the locale. I've tenatively chosen the latter. (Also accept 1 and 0 as input.) --- IkiWiki.pm | 2 +- debian/changelog | 2 ++ t/yesno.t | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 t/yesno.t (limited to 't') diff --git a/IkiWiki.pm b/IkiWiki.pm index e509a7c2f..7eef4c320 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1658,7 +1658,7 @@ sub gettext { sub yesno ($) { my $val=shift; - return (defined $val && lc($val) eq gettext("yes")); + return (defined $val && (lc($val) eq gettext("yes") || lc($val) eq "yes" || $val eq "1")); } sub inject { diff --git a/debian/changelog b/debian/changelog index 0f2c75787..f892dc524 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ ikiwiki (3.01) UNRELEASED; urgency=low * ikiwiki-makerepo: Fix injecting of empty mercurial and bzr repositories. Closes: #510518 * Fix documentation about git hook to use right name. Closes: #510393 + * yesno: Always accept English even when localised. + * yesno: Also accept 1 and 0 as input. -- Joey Hess Fri, 02 Jan 2009 14:12:16 -0500 diff --git a/t/yesno.t b/t/yesno.t new file mode 100755 index 000000000..60a8c071d --- /dev/null +++ b/t/yesno.t @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 10; + +BEGIN { use_ok("IkiWiki"); } + +# note: yesno always accepts English even if localized. +# So no need to bother setting locale to C. + +ok(IkiWiki::yesno("yes") == 1); +ok(IkiWiki::yesno("Yes") == 1); +ok(IkiWiki::yesno("YES") == 1); + +ok(IkiWiki::yesno("no") == 0); +ok(IkiWiki::yesno("No") == 0); +ok(IkiWiki::yesno("NO") == 0); + +ok(IkiWiki::yesno("1") == 1); +ok(IkiWiki::yesno("0") == 0); +ok(IkiWiki::yesno("mooooooooooo") == 0); -- cgit v1.2.3 From 7ee92cab4095fb22d77a0b0100a472c6901eb519 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 16 Jan 2009 22:39:11 -0500 Subject: blogspam: New plugin, adding spam filtering for page editing / comment posting using the BlogSpam.net API. --- IkiWiki/Plugin/blogspam.pm | 111 +++++++++++++++++++++++++++++++++++++ debian/changelog | 2 + doc/plugins/blogspam.mdwn | 23 ++++++++ doc/todo/anti-spam_protection.mdwn | 11 ++++ t/syntax.t | 4 +- 5 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 IkiWiki/Plugin/blogspam.pm create mode 100644 doc/plugins/blogspam.mdwn (limited to 't') diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm new file mode 100644 index 000000000..6e68a9856 --- /dev/null +++ b/IkiWiki/Plugin/blogspam.pm @@ -0,0 +1,111 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::blogspam; + +use warnings; +use strict; +use IkiWiki 3.00; +require RPC::XML; +require RPC::XML::Client; + +my $defaulturl='http://test.blogspam.net:8888/'; + +sub import { + hook(type => "getsetup", id => "blogspam", call => \&getsetup); + hook(type => "checkcontent", id => "blogspam", call => \&checkcontent); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 0, + }, + blogspam_pagespec => { + type => 'pagespec', + example => 'postcomment(*)', + description => 'PageSpec of pages to check for spam', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 0, + }, + blogspam_options => { + type => "string", + example => "blacklist=1.2.3.4,blacklist=8.7.6.5,max-links=10", + description => "options to send to blogspam server", + link => "http://blogspam.net/api/testComment.html#options", + safe => 1, + rebuild => 0, + }, + blogspam_server => { + type => "string", + default => $defaulturl, + description => "blogspam server XML-RPC url", + safe => 1, + rebuild => 0, + }, +} + +sub checkcontent (@) { + my %params=@_; + + if (exists $config{blogspam_pagespec}) { + return undef + if ! pagespec_match($params{page}, $config{blogspam_pagespec}, + location => $params{page}); + } + + my $url=$defaulturl; + $url = $params{blogspam_server} if exists $params{blogspam_server}; + my $client = RPC::XML::Client->new($url); + + my @options = split(",", $params{blogspam_options}) + if exists $params{blogspam_options}; + + # Allow short comments and whitespace-only edits, unless the user + # has overridden min-words themselves. + push @options, "min-words=0" + unless grep /^min-words=/i, @options; + # Wiki pages can have a lot of urls, unless the user specifically + # wants to limit them. + push @options, "exclude=lotsaurls" + unless grep /^max-links/i, @options; + # Unless the user specified a size check, disable such checking. + push @options, "exclude=size" + unless grep /^(?:max|min)-size/i, @options; + # This test has absurd false positives on words like "alpha" + # and "buy". + push @options, "exclude=stopwords"; + + # blogspam API does not have a field for author url, so put it in + # the content to be checked. + if (exists $params{url}) { + $params{content}.="\n".$params{url}; + } + + my $res = $client->send_request('testComment', { + ip => $ENV{REMOTE_ADDR}, + comment => $params{content}, + subject => defined $params{subject} ? $params{subject} : "", + name => defined $params{author} ? $params{author} : "", + options => join(",", @options), + site => $config{url}, + version => "ikiwiki ".$IkiWiki::version, + }); + + if (! ref $res || ! defined $res->value) { + debug("failed to get response from blogspam server ($url)"); + return undef; + } + elsif ($res->value =~ /^SPAM:(.*)/) { + return gettext("Sorry, but that looks like spam to blogspam: ").$1; + } + elsif ($res->value ne 'OK') { + debug(gettext("blogspam server failure: ").$res->value); + return undef; + } + else { + return undef; + } +} + +1 diff --git a/debian/changelog b/debian/changelog index b75fe6afc..cb362d6e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -20,6 +20,8 @@ ikiwiki (3.02) UNRELEASED; urgency=low in blogging. * checkcontent: New hook, can be used to implement arbitrary content filters, including spam filters. + * blogspam: New plugin, adding spam filtering for page editing / comment + posting using the BlogSpam.net API. -- Joey Hess Tue, 06 Jan 2009 15:02:52 -0500 diff --git a/doc/plugins/blogspam.mdwn b/doc/plugins/blogspam.mdwn new file mode 100644 index 000000000..307d4646d --- /dev/null +++ b/doc/plugins/blogspam.mdwn @@ -0,0 +1,23 @@ +[[!template id=plugin name=blogspam author="[[Joey]]"]] +[[!tag type/auth]] + +This plugin adds antispam support to ikiwiki, using the +[blogspam.net](http://blogspam.net/) API. Both page edits and +[[comment|comments]] postings can be checked for spam. Currently, +detected spam is not saved for human review, it is just rejected. + +You can control how content is tested via the `blogspam_options` +setting. By default, the options are configured in a way that is +appropriate for wiki content. This includes turning off some of the +more problimatic tests. + +The `blogspam_pagespec` setting is a [[ikiwiki/PageSpec]] that can be +used to configure which pages are checked for spam. The default is to check +all edits. If you only want to check [[comments]] (not wiki page edits), +set it to "postcomment(*)". + +By default, the blogspam.net server is used to do the spam checking. To +change this, the `blogspam_server` option can be set to the url for a +different server implementing the same API. Note that content is sent +unencrypted over the internet to the server, and the server sees +the full text of the content. diff --git a/doc/todo/anti-spam_protection.mdwn b/doc/todo/anti-spam_protection.mdwn index cb45faee5..b0524be5f 100644 --- a/doc/todo/anti-spam_protection.mdwn +++ b/doc/todo/anti-spam_protection.mdwn @@ -17,3 +17,14 @@ Cheers, You might look at the Wikipedia page on "Spam\_in\_blogs" for more ideas. In particular, would it be possible to force a subset of the pages (by regex, but you'd choose the regex to match those pages which are publicly writable) to use rel="nofollow" in all links. > I just wanted to leave a link here to the [[todo/require_CAPTCHA_to_edit]] plugin patch. Unfortunately that plugin currently interacts badly with the openid plugin. -- [[Will]] + + +--- + +Ikiwiki now has a checkcontent hook that plugins can use to see content +that is being entered and check it for spam/whatever. + +There is a blogspam plugin that uses the blogspam.org service +to check for common spam signatures. --[[Joey]] + +[[done]] diff --git a/t/syntax.t b/t/syntax.t index d09d17f7f..9d5cbc373 100755 --- a/t/syntax.t +++ b/t/syntax.t @@ -5,8 +5,8 @@ use Test::More; my @progs="ikiwiki.in"; my @libs="IkiWiki.pm"; -# monotone, external, amazon_s3 skipped since they need perl modules -push @libs, map { chomp; $_ } `find IkiWiki -type f -name \\*.pm | grep -v monotone.pm | grep -v external.pm | grep -v amazon_s3.pm`; +# monotone, external, blogspam, amazon_s3 skipped since they need perl modules +push @libs, map { chomp; $_ } `find IkiWiki -type f -name \\*.pm | grep -v monotone.pm | grep -v external.pm | grep -v blogspam.pm | grep -v amazon_s3.pm`; push @libs, 'IkiWiki/Plugin/skeleton.pm.example'; plan(tests => (@progs + @libs)); -- cgit v1.2.3 From cd2ddb57a5a20e308cee912e26f2383733c11b3c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Jan 2009 14:56:48 -0500 Subject: load rpc xml lib on the fly This way, enabling the plugin via websetup is safe, it can't leave ikiwiki in a broken state. --- IkiWiki/Plugin/blogspam.pm | 11 +++++++++-- t/syntax.t | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 't') diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm index 6e68a9856..4005e9f2a 100644 --- a/IkiWiki/Plugin/blogspam.pm +++ b/IkiWiki/Plugin/blogspam.pm @@ -4,8 +4,6 @@ package IkiWiki::Plugin::blogspam; use warnings; use strict; use IkiWiki 3.00; -require RPC::XML; -require RPC::XML::Client; my $defaulturl='http://test.blogspam.net:8888/'; @@ -47,6 +45,15 @@ sub getsetup () { sub checkcontent (@) { my %params=@_; + + eval q{ + use RPC::XML; + use RPC::XML::Client; + }; + if ($@) { + warn($@); + return undef; + } if (exists $config{blogspam_pagespec}) { return undef diff --git a/t/syntax.t b/t/syntax.t index 9d5cbc373..d09d17f7f 100755 --- a/t/syntax.t +++ b/t/syntax.t @@ -5,8 +5,8 @@ use Test::More; my @progs="ikiwiki.in"; my @libs="IkiWiki.pm"; -# monotone, external, blogspam, amazon_s3 skipped since they need perl modules -push @libs, map { chomp; $_ } `find IkiWiki -type f -name \\*.pm | grep -v monotone.pm | grep -v external.pm | grep -v blogspam.pm | grep -v amazon_s3.pm`; +# monotone, external, amazon_s3 skipped since they need perl modules +push @libs, map { chomp; $_ } `find IkiWiki -type f -name \\*.pm | grep -v monotone.pm | grep -v external.pm | grep -v amazon_s3.pm`; push @libs, 'IkiWiki/Plugin/skeleton.pm.example'; plan(tests => (@progs + @libs)); -- cgit v1.2.3 From 8322b8c9c82941c4052bcc8a0d1824a92d6426a0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 31 Jan 2009 18:07:42 +0000 Subject: CGI: add cgi_page_from_404(), which remaps a path like $REDIRECT_URL to an IkiWiki page name Also add a regression test --- IkiWiki/CGI.pm | 40 ++++++++++++++++++++++++++++++++++++++++ t/cgi_page_from_404.t | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 t/cgi_page_from_404.t (limited to 't') diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index fe8457262..82cad40c8 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -332,6 +332,46 @@ sub cgi_goto ($;$) { exit; } +sub cgi_page_from_404 ($$$) { + my $path = shift; + my $baseurl = shift; + my $usedirs = shift; + + # fail if missing from environment or whatever + return undef unless defined $path; + return undef unless defined $baseurl; + + # with usedirs on, path is like /~fred/foo/bar/ or /~fred/foo/bar or + # /~fred/foo/bar/index.html + # with usedirs off, path is like /~fred/foo/bar.html + # baseurl is like 'http://people.example.com/~fred' + + # convert baseurl to ~fred + unless ($baseurl =~ s{^https?://[^/]+/?}{}) { + return undef; + } + + # convert path to /~fred/foo/bar + if ($usedirs) { + $path =~ s/\/*(?:index\.$config{htmlext})?$//; + } + else { + $path =~ s/\.$config{htmlext}$//; + } + + # remove /~fred/ + unless ($path =~ s{^/*\Q$baseurl\E/*}{}) { + return undef; + } + + # special case for the index + unless ($path) { + return 'index'; + } + + return $path; +} + sub cgi (;$$) { my $q=shift; my $session=shift; diff --git a/t/cgi_page_from_404.t b/t/cgi_page_from_404.t new file mode 100755 index 000000000..adbbdf874 --- /dev/null +++ b/t/cgi_page_from_404.t @@ -0,0 +1,43 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 18; + +BEGIN { use_ok("IkiWiki"); } +BEGIN { use_ok("IkiWiki::CGI"); } + +sub cgi_page_from_404 { return IkiWiki::cgi_page_from_404(shift, shift, shift); } + +$IkiWiki::config{htmlext} = 'html'; + +is(cgi_page_from_404('/', 'http://example.com', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index'); +is(cgi_page_from_404('/', 'http://example.com/', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0), + 'foo'); -- cgit v1.2.3 From 46b880f8390ac82d746add01de38a05155743374 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 31 Jan 2009 22:32:10 +0000 Subject: Split apache404 into an independent plugin Also make it ignore the 'do' parameter at Joey's suggestion, to have one less thing to remember when configuring. --- IkiWiki/CGI.pm | 49 +------------------------- IkiWiki/Plugin/apache404.pm | 76 ++++++++++++++++++++++++++++++++++++++++ doc/plugins/apache404.mdwn | 11 ++++++ doc/tips/apache_404_handler.mdwn | 10 ------ t/apache404.t | 45 ++++++++++++++++++++++++ t/cgi_page_from_404.t | 43 ----------------------- 6 files changed, 133 insertions(+), 101 deletions(-) create mode 100644 IkiWiki/Plugin/apache404.pm create mode 100644 doc/plugins/apache404.mdwn delete mode 100644 doc/tips/apache_404_handler.mdwn create mode 100755 t/apache404.t delete mode 100755 t/cgi_page_from_404.t (limited to 't') diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 8734cdd49..e75ebcd27 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -338,46 +338,6 @@ sub cgi_goto ($;$) { exit; } -sub cgi_page_from_404 ($$$) { - my $path = shift; - my $baseurl = shift; - my $usedirs = shift; - - # fail if missing from environment or whatever - return undef unless defined $path; - return undef unless defined $baseurl; - - # with usedirs on, path is like /~fred/foo/bar/ or /~fred/foo/bar or - # /~fred/foo/bar/index.html - # with usedirs off, path is like /~fred/foo/bar.html - # baseurl is like 'http://people.example.com/~fred' - - # convert baseurl to ~fred - unless ($baseurl =~ s{^https?://[^/]+/?}{}) { - return undef; - } - - # convert path to /~fred/foo/bar - if ($usedirs) { - $path =~ s/\/*(?:index\.$config{htmlext})?$//; - } - else { - $path =~ s/\.$config{htmlext}$//; - } - - # remove /~fred/ - unless ($path =~ s{^/*\Q$baseurl\E/*}{}) { - return undef; - } - - # special case for the index - unless ($path) { - return 'index'; - } - - return $path; -} - sub cgi (;$$) { my $q=shift; my $session=shift; @@ -409,14 +369,7 @@ sub cgi (;$$) { # commenter are for compatibility with any saved URLs if ($do eq 'goto' || $do eq 'recentchanges_link' || $do eq 'commenter') { - my $page = undef; - - if ($ENV{REDIRECT_STATUS} eq '404') { - $page = cgi_page_from_404($ENV{REDIRECT_URL}, - $config{url}, $config{usedirs}); - } - - cgi_goto($q, $page); + cgi_goto($q); } # Need to lock the wiki before getting a session. diff --git a/IkiWiki/Plugin/apache404.pm b/IkiWiki/Plugin/apache404.pm new file mode 100644 index 000000000..3ac6b3af5 --- /dev/null +++ b/IkiWiki/Plugin/apache404.pm @@ -0,0 +1,76 @@ +#!/usr/bin/perl +# Copyright © 2009 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation +package IkiWiki::Plugin::apache404; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "cgi", id => 'apache404', call => \&cgi); +} + +sub getsetup () { + return + plugin => { + # not really a matter of safety, but enabling/disabling + # through a web interface is useless - it needs web + # server admin action too + safe => 0, + rebuild => 0, + } +} + +sub cgi_page_from_404 ($$$) { + my $path = shift; + my $baseurl = shift; + my $usedirs = shift; + + # fail if missing from environment or whatever + return undef unless defined $path; + return undef unless defined $baseurl; + + # with usedirs on, path is like /~fred/foo/bar/ or /~fred/foo/bar or + # /~fred/foo/bar/index.html + # with usedirs off, path is like /~fred/foo/bar.html + # baseurl is like 'http://people.example.com/~fred' + + # convert baseurl to ~fred + unless ($baseurl =~ s{^https?://[^/]+/?}{}) { + return undef; + } + + # convert path to /~fred/foo/bar + if ($usedirs) { + $path =~ s/\/*(?:index\.$config{htmlext})?$//; + } + else { + $path =~ s/\.$config{htmlext}$//; + } + + # remove /~fred/ + unless ($path =~ s{^/*\Q$baseurl\E/*}{}) { + return undef; + } + + # special case for the index + unless ($path) { + return 'index'; + } + + return $path; +} + +sub cgi ($) { + my $cgi=shift; + + if ($ENV{REDIRECT_STATUS} eq '404') { + my $page = cgi_page_from_404($ENV{REDIRECT_URL}, + $config{url}, $config{usedirs}); + IkiWiki::cgi_goto($cgi, $page); + } +} + +1; diff --git a/doc/plugins/apache404.mdwn b/doc/plugins/apache404.mdwn new file mode 100644 index 000000000..bab8fb59d --- /dev/null +++ b/doc/plugins/apache404.mdwn @@ -0,0 +1,11 @@ +[[!template id=plugin name=apache404 author="[[Simon_McVittie|smcv]]"]] +[[!tag type/useful]] + +This plugin lets you use the IkiWiki CGI script as an Apache 404 handler, +to give the behaviour of various other wiki engines where visiting a +nonexistent page provides you with a link to create it. + +To achieve this, put something like this in the wiki's Apache configuration +file: + + ErrorDocument 404 /cgi-bin/ikiwiki.cgi diff --git a/doc/tips/apache_404_handler.mdwn b/doc/tips/apache_404_handler.mdwn deleted file mode 100644 index 0fda759e7..000000000 --- a/doc/tips/apache_404_handler.mdwn +++ /dev/null @@ -1,10 +0,0 @@ -[[!meta title="Apache 404 handler"]] - -Sufficiently recent versions of IkiWiki can be used as an Apache 404 handler, -to give the behaviour of various other wiki engines where visiting a -nonexistent page provides you with a link to create it. - -To achieve this, put something like this in the wiki's Apache configuration -file: - - ErrorDocument 404 /cgi-bin/ikiwiki.cgi?do=goto diff --git a/t/apache404.t b/t/apache404.t new file mode 100755 index 000000000..00fc35250 --- /dev/null +++ b/t/apache404.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 17; + +BEGIN { use_ok("IkiWiki::Plugin::apache404"); } + +sub cgi_page_from_404 { + return IkiWiki::Plugin::apache404::cgi_page_from_404(shift, shift, + shift); +} + +$IkiWiki::config{htmlext} = 'html'; + +is(cgi_page_from_404('/', 'http://example.com', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index'); +is(cgi_page_from_404('/', 'http://example.com/', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0), + 'foo'); diff --git a/t/cgi_page_from_404.t b/t/cgi_page_from_404.t deleted file mode 100755 index adbbdf874..000000000 --- a/t/cgi_page_from_404.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 18; - -BEGIN { use_ok("IkiWiki"); } -BEGIN { use_ok("IkiWiki::CGI"); } - -sub cgi_page_from_404 { return IkiWiki::cgi_page_from_404(shift, shift, shift); } - -$IkiWiki::config{htmlext} = 'html'; - -is(cgi_page_from_404('/', 'http://example.com', 1), 'index'); -is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index'); -is(cgi_page_from_404('/', 'http://example.com/', 1), 'index'); -is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index'); - -is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0), - 'foo/bar'); - -is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0), - 'foo/bar'); - -is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0), - 'foo'); -- cgit v1.2.3 From 3b83e520182a83e4ae6c61ab7b360b0eb939469f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 31 Jan 2009 19:26:36 -0500 Subject: rename apache404 -> 404 This may already work with other web servers that have copied apache's interface, and it should be easy to add support to it for web servers that use some other interface. So, make the name more general. --- IkiWiki/Plugin/404.pm | 77 +++++++++++++++++++++++++++++++++++++++++++++ IkiWiki/Plugin/apache404.pm | 77 --------------------------------------------- debian/changelog | 2 +- debian/copyright | 2 +- doc/plugins/404.mdwn | 11 +++++++ doc/plugins/apache404.mdwn | 11 ------- doc/plugins/goto.mdwn | 2 +- doc/tips/dot_cgi.mdwn | 9 +++--- t/404.t | 44 ++++++++++++++++++++++++++ t/apache404.t | 45 -------------------------- 10 files changed, 139 insertions(+), 141 deletions(-) create mode 100644 IkiWiki/Plugin/404.pm delete mode 100644 IkiWiki/Plugin/apache404.pm create mode 100644 doc/plugins/404.mdwn delete mode 100644 doc/plugins/apache404.mdwn create mode 100755 t/404.t delete mode 100755 t/apache404.t (limited to 't') diff --git a/IkiWiki/Plugin/404.pm b/IkiWiki/Plugin/404.pm new file mode 100644 index 000000000..5550ea7d1 --- /dev/null +++ b/IkiWiki/Plugin/404.pm @@ -0,0 +1,77 @@ +#!/usr/bin/perl +# Copyright © 2009 Simon McVittie +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation +package IkiWiki::Plugin::404; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "cgi", id => '404', call => \&cgi); + IkiWiki::loadplugin("goto"); +} + +sub getsetup () { + return + plugin => { + # not really a matter of safety, but enabling/disabling + # through a web interface is useless - it needs web + # server admin action too + safe => 0, + rebuild => 0, + } +} + +sub cgi_page_from_404 ($$$) { + my $path = shift; + my $baseurl = shift; + my $usedirs = shift; + + # fail if missing from environment or whatever + return undef unless defined $path; + return undef unless defined $baseurl; + + # with usedirs on, path is like /~fred/foo/bar/ or /~fred/foo/bar or + # /~fred/foo/bar/index.html + # with usedirs off, path is like /~fred/foo/bar.html + # baseurl is like 'http://people.example.com/~fred' + + # convert baseurl to ~fred + unless ($baseurl =~ s{^https?://[^/]+/?}{}) { + return undef; + } + + # convert path to /~fred/foo/bar + if ($usedirs) { + $path =~ s/\/*(?:index\.$config{htmlext})?$//; + } + else { + $path =~ s/\.$config{htmlext}$//; + } + + # remove /~fred/ + unless ($path =~ s{^/*\Q$baseurl\E/*}{}) { + return undef; + } + + # special case for the index + unless ($path) { + return 'index'; + } + + return $path; +} + +sub cgi ($) { + my $cgi=shift; + + if ($ENV{REDIRECT_STATUS} eq '404') { + my $page = cgi_page_from_404($ENV{REDIRECT_URL}, + $config{url}, $config{usedirs}); + IkiWiki::Plugin::goto::cgi_goto($cgi, $page); + } +} + +1; diff --git a/IkiWiki/Plugin/apache404.pm b/IkiWiki/Plugin/apache404.pm deleted file mode 100644 index e7ce70435..000000000 --- a/IkiWiki/Plugin/apache404.pm +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/perl -# Copyright © 2009 Simon McVittie -# Licensed under the GNU GPL, version 2, or any later version published by the -# Free Software Foundation -package IkiWiki::Plugin::apache404; - -use warnings; -use strict; -use IkiWiki 3.00; - -sub import { - hook(type => "cgi", id => 'apache404', call => \&cgi); - IkiWiki::loadplugin("goto"); -} - -sub getsetup () { - return - plugin => { - # not really a matter of safety, but enabling/disabling - # through a web interface is useless - it needs web - # server admin action too - safe => 0, - rebuild => 0, - } -} - -sub cgi_page_from_404 ($$$) { - my $path = shift; - my $baseurl = shift; - my $usedirs = shift; - - # fail if missing from environment or whatever - return undef unless defined $path; - return undef unless defined $baseurl; - - # with usedirs on, path is like /~fred/foo/bar/ or /~fred/foo/bar or - # /~fred/foo/bar/index.html - # with usedirs off, path is like /~fred/foo/bar.html - # baseurl is like 'http://people.example.com/~fred' - - # convert baseurl to ~fred - unless ($baseurl =~ s{^https?://[^/]+/?}{}) { - return undef; - } - - # convert path to /~fred/foo/bar - if ($usedirs) { - $path =~ s/\/*(?:index\.$config{htmlext})?$//; - } - else { - $path =~ s/\.$config{htmlext}$//; - } - - # remove /~fred/ - unless ($path =~ s{^/*\Q$baseurl\E/*}{}) { - return undef; - } - - # special case for the index - unless ($path) { - return 'index'; - } - - return $path; -} - -sub cgi ($) { - my $cgi=shift; - - if ($ENV{REDIRECT_STATUS} eq '404') { - my $page = cgi_page_from_404($ENV{REDIRECT_URL}, - $config{url}, $config{usedirs}); - IkiWiki::Plugin::goto::cgi_goto($cgi, $page); - } -} - -1; diff --git a/debian/changelog b/debian/changelog index f3927f121..be32d3abf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ ikiwiki (3.04) UNRELEASED; urgency=low - * apache404: New plugin which lets you use the IkiWiki CGI script as + * 404: New plugin which lets you use the IkiWiki CGI script as an Apache 404 handler, to give the behaviour of various other wiki engines where visiting a nonexistent page provides you with a link to create it. (smcv) diff --git a/debian/copyright b/debian/copyright index bdfbaa573..f589b4a8f 100644 --- a/debian/copyright +++ b/debian/copyright @@ -118,7 +118,7 @@ Copyright: © 2008 Simon McVittie License: GPL-2+ -Files: apache404.pm +Files: 404.pm Copyright: © 2009 Simon McVittie License: GPL-2+ diff --git a/doc/plugins/404.mdwn b/doc/plugins/404.mdwn new file mode 100644 index 000000000..8d36279c8 --- /dev/null +++ b/doc/plugins/404.mdwn @@ -0,0 +1,11 @@ +[[!template id=plugin name=404 author="[[Simon_McVittie|smcv]]"]] +[[!tag type/useful]] + +This plugin lets you use the IkiWiki CGI script as an Apache 404 handler, +to give the behaviour of various other wiki engines where visiting a +nonexistent page provides you with a link to create it. + +To achieve this, put something like this in the wiki's Apache configuration +file: + + ErrorDocument 404 /cgi-bin/ikiwiki.cgi diff --git a/doc/plugins/apache404.mdwn b/doc/plugins/apache404.mdwn deleted file mode 100644 index bab8fb59d..000000000 --- a/doc/plugins/apache404.mdwn +++ /dev/null @@ -1,11 +0,0 @@ -[[!template id=plugin name=apache404 author="[[Simon_McVittie|smcv]]"]] -[[!tag type/useful]] - -This plugin lets you use the IkiWiki CGI script as an Apache 404 handler, -to give the behaviour of various other wiki engines where visiting a -nonexistent page provides you with a link to create it. - -To achieve this, put something like this in the wiki's Apache configuration -file: - - ErrorDocument 404 /cgi-bin/ikiwiki.cgi diff --git a/doc/plugins/goto.mdwn b/doc/plugins/goto.mdwn index 21dda16b2..9c401c5d2 100644 --- a/doc/plugins/goto.mdwn +++ b/doc/plugins/goto.mdwn @@ -2,7 +2,7 @@ [[!tag type/useful]] This plugin adds a `do=goto` mode for the IkiWiki CGI script. It's mainly -for internal use by the [[apache404]], [[comments]] and [[recentchanges]] +for internal use by the [[404]], [[comments]] and [[recentchanges]] plugins, which enable it automatically. With this plugin enabled you can link to `ikiwiki.cgi?do=goto&page=some/where` diff --git a/doc/tips/dot_cgi.mdwn b/doc/tips/dot_cgi.mdwn index ffcbf95d4..04d7a9721 100644 --- a/doc/tips/dot_cgi.mdwn +++ b/doc/tips/dot_cgi.mdwn @@ -26,11 +26,10 @@ configuration changes should work anywhere. Or, if you've put it in a `~/public_html`, edit `/etc/apache2/mods-available/userdir.conf`. -You may also want to enable the [[plugins/apache404]] -plugin. To make apache use it, the apache config file -will need a further modification to make it use ikiwiki's CGI -as the apache 404 handler. Something like this, with -the path adjusted to where you've put the CGI: +* You may also want to enable the [[plugins/404]] plugin. + To make apache use it, the apache config file will need a further + modification to make it use ikiwiki's CGI as the apache 404 handler. + Something like this, with the path adjusted to where you've put the CGI: ErrorDocument 404 /cgi-bin/ikiwiki.cgi diff --git a/t/404.t b/t/404.t new file mode 100755 index 000000000..0bb3c6063 --- /dev/null +++ b/t/404.t @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 17; + +BEGIN { use_ok("IkiWiki::Plugin::404"); } + +sub cgi_page_from_404 { + return IkiWiki::Plugin::404::cgi_page_from_404(shift, shift, shift); +} + +$IkiWiki::config{htmlext} = 'html'; + +is(cgi_page_from_404('/', 'http://example.com', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index'); +is(cgi_page_from_404('/', 'http://example.com/', 1), 'index'); +is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1), + 'foo/bar'); +is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0), + 'foo/bar'); + +is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1), + 'foo'); +is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0), + 'foo'); diff --git a/t/apache404.t b/t/apache404.t deleted file mode 100755 index 00fc35250..000000000 --- a/t/apache404.t +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 17; - -BEGIN { use_ok("IkiWiki::Plugin::apache404"); } - -sub cgi_page_from_404 { - return IkiWiki::Plugin::apache404::cgi_page_from_404(shift, shift, - shift); -} - -$IkiWiki::config{htmlext} = 'html'; - -is(cgi_page_from_404('/', 'http://example.com', 1), 'index'); -is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index'); -is(cgi_page_from_404('/', 'http://example.com/', 1), 'index'); -is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index'); - -is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0), - 'foo/bar'); - -is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1), - 'foo/bar'); -is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0), - 'foo/bar'); - -is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1), - 'foo'); -is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0), - 'foo'); -- cgit v1.2.3 From 8c8b18935b84bcfbf06649c9683e236e39f75df3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Feb 2009 18:22:51 -0500 Subject: fix pagetype test File had wrong name, and made wrong assumption about what pagetype does for bare files. --- t/pagetype.mdwn | 14 -------------- t/pagetype.t | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) delete mode 100755 t/pagetype.mdwn create mode 100755 t/pagetype.t (limited to 't') diff --git a/t/pagetype.mdwn b/t/pagetype.mdwn deleted file mode 100755 index 76cacd8f7..000000000 --- a/t/pagetype.mdwn +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 5; - -BEGIN { use_ok("IkiWiki"); } - -# Used internally. -$IkiWiki::hooks{htmlize}{mdwn}=1; - -is(pagetype("foo.mdwn"), "mdwn"); -is(pagetype("foo/bar.mdwn"), "mdwn"); -is(pagename("foo.png"), undef); -is(pagename("foo"), undef); diff --git a/t/pagetype.t b/t/pagetype.t new file mode 100755 index 000000000..2df59387a --- /dev/null +++ b/t/pagetype.t @@ -0,0 +1,17 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 6; + +BEGIN { use_ok("IkiWiki"); } + +# Used internally. +$IkiWiki::hooks{htmlize}{mdwn}=1; + +is(pagetype("foo.mdwn"), "mdwn"); +is(pagetype("foo/bar.mdwn"), "mdwn"); + +# bare files get the full filename as page name +is(pagename("foo.png"), "foo.png"); +is(pagename("foo/bar.png"), "foo/bar.png"); +is(pagename("foo"), "foo"); -- cgit v1.2.3 From c1907ded879f75ef07c5bbab26b84042bafc1b17 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Feb 2009 18:28:43 -0500 Subject: fix pagename, pagetype tests Put tests in right file. Set internal variable to hash, the functions expect that. --- t/pagename.t | 5 ++++- t/pagetype.t | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 't') diff --git a/t/pagename.t b/t/pagename.t index c7f1ce180..43f574e98 100755 --- a/t/pagename.t +++ b/t/pagename.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 5; +use Test::More tests => 6; BEGIN { use_ok("IkiWiki"); } @@ -10,5 +10,8 @@ $IkiWiki::hooks{htmlize}{mdwn}{call}=sub {}; is(pagename("foo.mdwn"), "foo"); is(pagename("foo/bar.mdwn"), "foo/bar"); + +# bare files get the full filename as page name is(pagename("foo.png"), "foo.png"); +is(pagename("foo/bar.png"), "foo/bar.png"); is(pagename("foo"), "foo"); diff --git a/t/pagetype.t b/t/pagetype.t index 2df59387a..bb06a1568 100755 --- a/t/pagetype.t +++ b/t/pagetype.t @@ -6,12 +6,10 @@ use Test::More tests => 6; BEGIN { use_ok("IkiWiki"); } # Used internally. -$IkiWiki::hooks{htmlize}{mdwn}=1; +$IkiWiki::hooks{htmlize}{mdwn}={}; is(pagetype("foo.mdwn"), "mdwn"); is(pagetype("foo/bar.mdwn"), "mdwn"); - -# bare files get the full filename as page name -is(pagename("foo.png"), "foo.png"); -is(pagename("foo/bar.png"), "foo/bar.png"); -is(pagename("foo"), "foo"); +is(pagetype("foo.png"), undef); +is(pagetype("foo/bar.png"), undef); +is(pagetype("foo"), undef); -- cgit v1.2.3 From 9ecb0036a32c6930d9400040161c3b9e41ef9b1f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Feb 2009 18:31:57 -0500 Subject: add keepextension tests --- t/pagename.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/pagename.t b/t/pagename.t index 43f574e98..488e341fa 100755 --- a/t/pagename.t +++ b/t/pagename.t @@ -1,12 +1,13 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 6; +use Test::More tests => 8; BEGIN { use_ok("IkiWiki"); } # Used internally. -$IkiWiki::hooks{htmlize}{mdwn}{call}=sub {}; +$IkiWiki::hooks{htmlize}{mdwn}={}; +$IkiWiki::hooks{htmlize}{txt}={keepextension => 1}; is(pagename("foo.mdwn"), "foo"); is(pagename("foo/bar.mdwn"), "foo/bar"); @@ -15,3 +16,7 @@ is(pagename("foo/bar.mdwn"), "foo/bar"); is(pagename("foo.png"), "foo.png"); is(pagename("foo/bar.png"), "foo/bar.png"); is(pagename("foo"), "foo"); + +# keepextension preserves the extension in the page name +is(pagename("foo.txt"), "foo.txt"); +is(pagename("foo/bar.txt"), "foo/bar.txt"); -- cgit v1.2.3 From 66dc253437e7ce2e3e8984513b3ecf96603d6670 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Feb 2009 18:38:45 -0500 Subject: Add noextension parameter to htmlize hooks to support, eg, Makefile. --- IkiWiki.pm | 23 ++++++++++++++--------- debian/changelog | 1 + doc/plugins/write.mdwn | 7 ++++++- doc/todo/Allow_filenames_that_are_all_type.mdwn | 4 ++++ t/pagename.t | 23 ++++++++++++++++++----- t/pagetype.t | 15 --------------- 6 files changed, 43 insertions(+), 30 deletions(-) delete mode 100755 t/pagetype.t (limited to 't') diff --git a/IkiWiki.pm b/IkiWiki.pm index ce1ceb351..f580d1f0d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -627,27 +627,32 @@ sub dirname ($) { return $file; } -sub pagetype ($) { +sub isinternal ($) { my $page=shift; + return exists $pagesources{$page} && + $pagesources{$page} =~ /\._([^.]+)$/; +} + +sub pagetype ($) { + my $file=shift; - if ($page =~ /\.([^.]+)$/) { + if ($file =~ /\.([^.]+)$/) { return $1 if exists $hooks{htmlize}{$1}; } + elsif ($hooks{htmlize}{basename($file)}{noextension}) { + return basename($file); + } return; } -sub isinternal ($) { - my $page=shift; - return exists $pagesources{$page} && - $pagesources{$page} =~ /\._([^.]+)$/; -} - sub pagename ($) { my $file=shift; my $type=pagetype($file); my $page=$file; - $page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{keepextension}; + $page=~s/\Q.$type\E*$// + if defined $type && !$hooks{htmlize}{$type}{keepextension} + && !$hooks{htmlize}{$type}{noextension}; if ($config{indexpages} && $page=~/(.*)\/index$/) { $page=$1; } diff --git a/debian/changelog b/debian/changelog index b644ac99c..810c59f4e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ ikiwiki (3.05) UNRELEASED; urgency=low directives, and other links on templates affect the page using the template reliably. * goto: Fix redirect to comments. + * Add noextension parameter to htmlize hooks to support, eg, Makefile. -- Joey Hess Sun, 15 Feb 2009 20:11:57 -0500 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 2e907938f..696bc6bc3 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -189,9 +189,14 @@ The function is passed named parameters: "page" and "content" and should return the htmlized content. If `hook` is passed an optional "keepextension" parameter, set to a true -value, then this extension will not be stripped from the source filename when +value, then the extension will not be stripped from the source filename when generating the page. +If `hook` is passed an optional "noextension" parameter, set to a true +value, then the id parameter specifies not a filename extension, but +a whole filename that can be htmlized. This is useful for files +like `Makefile` that have no extension. + ### pagetemplate hook(type => "pagetemplate", id => "foo", call => \&pagetemplate); diff --git a/doc/todo/Allow_filenames_that_are_all_type.mdwn b/doc/todo/Allow_filenames_that_are_all_type.mdwn index e165da7dc..bebbcafa8 100644 --- a/doc/todo/Allow_filenames_that_are_all_type.mdwn +++ b/doc/todo/Allow_filenames_that_are_all_type.mdwn @@ -22,6 +22,10 @@ lost because it didn't have its own bug to track it. Now it does :). -- [[Will >> >> So, yeah, I think this patch is complete. :) -- [[Will]] +>>> Thanks, [[applied|done]], but I added a noextension parameter, +>>> since having keepextension allow files with no extension didn't make +>>> sense. Also, made it work for pages in subdirs.. --[[Joey]] + diff --git a/IkiWiki.pm b/IkiWiki.pm index 8d728c9..1bd46a9 100644 --- a/IkiWiki.pm diff --git a/t/pagename.t b/t/pagename.t index 488e341fa..540d10f4c 100755 --- a/t/pagename.t +++ b/t/pagename.t @@ -1,22 +1,35 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 8; +use Test::More tests => 19; BEGIN { use_ok("IkiWiki"); } -# Used internally. +# define mdwn as an extension $IkiWiki::hooks{htmlize}{mdwn}={}; -$IkiWiki::hooks{htmlize}{txt}={keepextension => 1}; - +is(pagetype("foo.mdwn"), "mdwn"); is(pagename("foo.mdwn"), "foo"); +is(pagetype("foo/bar.mdwn"), "mdwn"); is(pagename("foo/bar.mdwn"), "foo/bar"); -# bare files get the full filename as page name +# bare files get the full filename as page name, undef type +is(pagetype("foo.png"), undef); is(pagename("foo.png"), "foo.png"); +is(pagetype("foo/bar.png"), undef); is(pagename("foo/bar.png"), "foo/bar.png"); +is(pagetype("foo"), undef); is(pagename("foo"), "foo"); # keepextension preserves the extension in the page name +$IkiWiki::hooks{htmlize}{txt}={keepextension => 1}; is(pagename("foo.txt"), "foo.txt"); +is(pagetype("foo.txt"), "txt"); is(pagename("foo/bar.txt"), "foo/bar.txt"); +is(pagetype("foo/bar.txt"), "txt"); + +# noextension makes extensionless files be treated as first-class pages +$IkiWiki::hooks{htmlize}{Makefile}={noextension =>1}; +is(pagetype("Makefile"), "Makefile"); +is(pagename("Makefile"), "Makefile"); +is(pagetype("foo/Makefile"), "Makefile"); +is(pagename("foo/Makefile"), "foo/Makefile"); diff --git a/t/pagetype.t b/t/pagetype.t deleted file mode 100755 index bb06a1568..000000000 --- a/t/pagetype.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 6; - -BEGIN { use_ok("IkiWiki"); } - -# Used internally. -$IkiWiki::hooks{htmlize}{mdwn}={}; - -is(pagetype("foo.mdwn"), "mdwn"); -is(pagetype("foo/bar.mdwn"), "mdwn"); -is(pagetype("foo.png"), undef); -is(pagetype("foo/bar.png"), undef); -is(pagetype("foo"), undef); -- cgit v1.2.3 From 8a119839464fbfdf6fc3e8c302fa3d9cac7eab6b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 4 Apr 2009 14:58:34 -0400 Subject: Fix git test suite to use a bare repo. This works around an enormous (and, in this context, enormously confusing) message that git has begun to print when one attempts to push changes into a non-bare repo. As a bonus, it now tests whether ikiwiki-makerepo works. --- debian/changelog | 5 +++-- t/git.t | 19 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 't') diff --git a/debian/changelog b/debian/changelog index 6c30c8ff5..fab20985d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -ikiwiki (3.09) UNRELEASED; urgency=low +ikiwiki (3.09) unstable; urgency=low * inline: Add title_natural sort order, using Sort::Naturally (chrysn) @@ -13,8 +13,9 @@ ikiwiki (3.09) UNRELEASED; urgency=low * Fix documentation of anonok_pagespec. Closes: #521793 * Add missing suggests on libtext-textile-perl. Closes: #522039 * recentchanges: change to using do=goto links for user links. + * Fix git test suite to use a bare repo. - -- Joey Hess Thu, 19 Mar 2009 15:32:49 -0400 + -- Joey Hess Sat, 04 Apr 2009 14:33:49 -0400 ikiwiki (3.08) unstable; urgency=low diff --git a/t/git.t b/t/git.t index b3aa6a80b..f1c24b359 100755 --- a/t/git.t +++ b/t/git.t @@ -3,19 +3,17 @@ use warnings; use strict; my $dir; -my $gitrepo; BEGIN { $dir="/tmp/ikiwiki-test-git.$$"; - $gitrepo="$dir/repo"; my $git=`which git`; chomp $git; - if (! -x $git || ! mkdir($dir) || ! mkdir($gitrepo)) { + if (! -x $git || ! mkdir($dir)) { eval q{ - use Test::More skip_all => "git not available or could not make test dirs" + use Test::More skip_all => "git not available or could not make test dir" } } } -use Test::More tests => 16; +use Test::More tests => 18; BEGIN { use_ok("IkiWiki"); } @@ -25,17 +23,16 @@ $config{srcdir} = "$dir/src"; IkiWiki::loadplugins(); IkiWiki::checkconfig(); -system "cd $gitrepo && git init >/dev/null 2>&1"; -system "cd $gitrepo && echo dummy > dummy; git add . >/dev/null 2>&1"; -system "cd $gitrepo && git commit -m Initial >/dev/null 2>&1"; -system "git clone -l -s $gitrepo $config{srcdir} >/dev/null 2>&1"; +ok (mkdir($config{srcdir})); +is (system("./ikiwiki-makerepo git $config{srcdir} $dir/repo"), 0); my @changes; @changes = IkiWiki::rcs_recentchanges(3); is($#changes, 0); # counts for dummy commit during repo creation -is($changes[0]{message}[0]{"line"}, "Initial"); -is($changes[0]{pages}[0]{"page"}, "dummy"); +# ikiwiki-makerepo's first commit is setting up the .gitignore +is($changes[0]{message}[0]{"line"}, "initial commit"); +is($changes[0]{pages}[0]{"page"}, ".gitignore"); # Web commit my $test1 = readfile("t/test1.mdwn"); -- cgit v1.2.3