From 127bceef5b4799e58cb068043e49ed16a3ec840d Mon Sep 17 00:00:00 2001 From: joey Date: Wed, 9 May 2007 00:31:49 +0000 Subject: [PATCH] * Add all=no option to conditional, can be used to form conditionals that do not need to examine every page in the wiki. * Use this to simplify the goodstuff detection in the plugin template. --- IkiWiki/Plugin/conditional.pm | 16 ++++++++++------ IkiWiki/Plugin/testpagespec.pm | 2 +- debian/changelog | 5 ++++- doc/plugins/conditional.mdwn | 10 ++++++++-- doc/templates/plugin.mdwn | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index a7ed6590e..6c14361f7 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -13,15 +13,19 @@ sub import { #{{{ sub preprocess_if (@) { #{{{ my %params=@_; - if (! exists $params{test} || ! exists $params{then}) { - return "[[if ".gettext('"test" and "then" parameters are required')."]]"; + foreach my $param (qw{test then}) { + if (! exists $params{$param}) { + return "[[if ".sprintf(gettext('%s parameter is required'), $param)."]]"; + } } my $result=0; - # An optimisation to avoid needless looping over every page - # and adding of dependencies for simple uses of some of the - # tests. - if ($params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) { + if ((exists $params{all} && lc $params{all} eq "no") || + # An optimisation to avoid needless looping over every page + # and adding of dependencies for simple uses of some of the + # tests. + $params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) { + add_depends($params{page}, "$params{test} and $params{page}"); $result=pagespec_match($params{page}, $params{test}, location => $params{page}, sourcepage => $params{page}, diff --git a/IkiWiki/Plugin/testpagespec.pm b/IkiWiki/Plugin/testpagespec.pm index 77fab497e..f9ec90d87 100644 --- a/IkiWiki/Plugin/testpagespec.pm +++ b/IkiWiki/Plugin/testpagespec.pm @@ -14,7 +14,7 @@ sub preprocess (@) { #{{{ foreach my $param (qw{match pagespec}) { if (! exists $params{$param}) { - return "[[testpagespec missing $param parameter]]"; + return "[[testpagespec $param parameter is required]]"; } } diff --git a/debian/changelog b/debian/changelog index deb7fd04e..e3863fbd2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,8 +9,11 @@ ikiwiki (2.1) UNRELEASED; urgency=low in. * Make testpagespec more robust, including checking for missing/bad parameters. + * Add all=no option to conditional, can be used to form conditionals that do + not need to examine every page in the wiki. + * Use this to simplify the goodstuff detection in the plugin template. - -- Joey Hess Tue, 08 May 2007 17:21:13 -0400 + -- Joey Hess Tue, 08 May 2007 20:12:25 -0400 ikiwiki (2.00) unstable; urgency=low diff --git a/doc/plugins/conditional.mdwn b/doc/plugins/conditional.mdwn index a8dd21589..ba1cf9bb2 100644 --- a/doc/plugins/conditional.mdwn +++ b/doc/plugins/conditional.mdwn @@ -18,8 +18,14 @@ quotes to be included. The `test` is a [[PageSpec]]; if it matches any page in the wiki then it succeeds. So you can do things like testing for the existence of a page or pages, testing to see if any pages were created in a given month, and so -on. The regular [[PageSpec]] syntax is expanded with the following -additional tests: +on. + +If you want the [[PageSpec]] to only match against the page that +contains the conditional, rather than matching against all pages in the +wiki, set the "all" parameter to "no". + +The regular [[PageSpec]] syntax is expanded with the following additional +tests: * enabled(plugin) diff --git a/doc/templates/plugin.mdwn b/doc/templates/plugin.mdwn index cb67902ea..b8421fafb 100644 --- a/doc/templates/plugin.mdwn +++ b/doc/templates/plugin.mdwn @@ -3,7 +3,7 @@ Plugin:
Author:
Included in ikiwiki: [[if test="sourcepage(plugins/contrib/*)" then="""no""" else="""yes"""]]
Enabled by default: yesno
-Included in [[/plugins/goodstuff]]: [[if test="backlink(plugins/goodstuff) and glob(plugins/) and !sourcepage(plugins/contrib/*)" then="""yes""" else="""no"""]]
+Included in [[/plugins/goodstuff]]: [[if test="backlink(plugins/goodstuff)" all=no then="""yes""" else="""no"""]]
Currently enabled: [[if test="enabled()" then="yes" else="no"]]
[[if test="sourcepage(plugins/contrib/*)" then="""[[meta title=" (third party plugin)"]]"""]] -- 2.44.0