]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/conditional.pm
In all=no conditionals, depend on the influences, not the test pagespec
[ikiwiki.git] / IkiWiki / Plugin / conditional.pm
index 4f3577b34fe7807f11762d80d971f9f1357f5f6f..b450f1a0a1cea267e3e2791376142c67438f03b9 100644 (file)
@@ -4,7 +4,6 @@ package IkiWiki::Plugin::conditional;
 use warnings;
 use strict;
 use IkiWiki 3.00;
-use UNIVERSAL;
 
 sub import {
        hook(type => "getsetup", id => "conditional", call => \&getsetup);
@@ -16,6 +15,7 @@ sub getsetup {
                plugin => {
                        safe => 1,
                        rebuild => undef,
+                       section => "widget",
                },
 }
 
@@ -29,29 +29,27 @@ sub preprocess_if (@) {
        }
 
        my $result=0;
-       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} =~ /^([\s\!()]*((enabled|sourcepage|destpage|included)\([^)]*\)|(and|or))[\s\!()]*)+$/) {
-               add_depends($params{page}, "($params{test}) and $params{page}");
+       if ((exists $params{all} && ! IkiWiki::yesno($params{all})) ||
+           # An optimisation to avoid needless looping over every page
+           # for simple uses of some of the tests.
+           $params{test} =~ /^([\s\!()]*((enabled|sourcepage|destpage|included)\([^)]*\)|(and|or))[\s\!()]*)+$/) {
                $result=pagespec_match($params{page}, $params{test},
                                location => $params{page},
                                sourcepage => $params{page},
                                destpage => $params{destpage});
+               my $i = $result->influences;
+               foreach my $k (keys %$i) {
+                       # minor optimization: influences are always simple dependencies
+                       $IkiWiki::depends_simple{$params{page}}{lc $k} |= $i->{$k};
+               }
        }
        else {
-               add_depends($params{page}, $params{test});
-
-               foreach my $page (keys %pagesources) {
-                       if (pagespec_match($page, $params{test}, 
-                                       location => $params{page},
-                                       sourcepage => $params{page},
-                                       destpage => $params{destpage})) {
-                               $result=1;
-                               last;
-                       }
-               }
+               $result=pagespec_match_list($params{page}, $params{test},
+                       # stop after first match
+                       num => 1,
+                       sourcepage => $params{page},
+                       destpage => $params{destpage},
+               );
        }
 
        my $ret;
@@ -64,8 +62,7 @@ sub preprocess_if (@) {
        else {
                $ret="";
        }
-       return IkiWiki::preprocess($params{page}, $params{destpage}, 
-               IkiWiki::filter($params{page}, $params{destpage}, $ret));
+       return IkiWiki::preprocess($params{page}, $params{destpage}, $ret);
 }
 
 package IkiWiki::PageSpec;
@@ -87,6 +84,8 @@ sub match_sourcepage ($$;@) {
        shift;
        my $glob=shift;
        my %params=@_;
+       
+       $glob=derel($glob, $params{location});
 
        return IkiWiki::FailReason->new("cannot match sourcepage") unless exists $params{sourcepage};
        if (match_glob($params{sourcepage}, $glob, @_)) {
@@ -102,6 +101,8 @@ sub match_destpage ($$;@) {
        my $glob=shift;
        my %params=@_;
        
+       $glob=derel($glob, $params{location});
+
        return IkiWiki::FailReason->new("cannot match destpage") unless exists $params{destpage};
        if (match_glob($params{destpage}, $glob, @_)) {
                return IkiWiki::SuccessReason->new("destpage matches $glob");