]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
add pagespec/sorting to underlay
[ikiwiki.git] / IkiWiki.pm
index e6efe18891069f128ff19ab87de717218b0a8797..fd7e2352474400c04eb7bdc4b4dd79746d570da6 100644 (file)
@@ -13,26 +13,32 @@ use open qw{:utf8 :std};
 
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
            %pagestate %wikistate %renderedfiles %oldrenderedfiles
-           %pagesources %destsources %depends %hooks %forcerebuild
-           $gettext_obj %loaded_plugins};
+           %pagesources %destsources %depends %depends_simple %hooks
+           %forcerebuild %loaded_plugins};
 
 use Exporter q{import};
-our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
-                 pagespec_match_list bestlink htmllink readfile writefile
-                pagetype srcfile pagename displaytime will_render gettext urlto
-                targetpage add_underlay pagetitle titlepage linkpage
-                newpagefile inject add_link
+our @EXPORT = qw(hook debug error template htmlpage deptype
+                 add_depends pagespec_match pagespec_match_list bestlink
+                htmllink readfile writefile pagetype srcfile pagename
+                displaytime will_render gettext urlto targetpage
+                add_underlay pagetitle titlepage linkpage newpagefile
+                inject add_link
                  %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
 our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
 
+# Page dependency types.
+our $DEPEND_CONTENT=1;
+our $DEPEND_PRESENCE=2;
+our $DEPEND_LINKS=4;
+
 # Optimisation.
 use Memoize;
 memoize("abs2rel");
 memoize("pagespec_translate");
-memoize("file_pruned");
+memoize("template_file");
 
 sub getsetup () {
        wikiname => {
@@ -149,6 +155,13 @@ sub getsetup () {
                safe => 0, # path
                rebuild => 1,
        },
+       templatedirs => {
+               type => "internal",
+               default => [],
+               description => "additional directories containing template files",
+               safe => 0,
+               rebuild => 0,
+       },
        underlaydir => {
                type => "string",
                default => "$installdir/share/ikiwiki/basewiki",
@@ -157,6 +170,13 @@ sub getsetup () {
                safe => 0, # path
                rebuild => 0,
        },
+       underlaydirbase => {
+               type => "internal",
+               default => "$installdir/share/ikiwiki",
+               description => "parent directory containing additional underlays",
+               safe => 0,
+               rebuild => 0,
+       },
        wrappers => {
                type => "internal",
                default => [],
@@ -213,6 +233,13 @@ sub getsetup () {
                safe => 1,
                rebuild => 1,
        },
+       discussionpage => {
+               type => "string",
+               default => gettext("Discussion"),
+               description => "name of Discussion pages",
+               safe => 1,
+               rebuild => 1,
+       },
        sslcookie => {
                type => "boolean",
                default => 0,
@@ -322,7 +349,7 @@ sub getsetup () {
                        qr/\.x?html?$/, qr/\.ikiwiki-new$/,
                        qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
                        qr/(^|\/)_MTN\//, qr/(^|\/)_darcs\//,
-                       qr/\.dpkg-tmp$/],
+                       qr/(^|\/)CVS\//, qr/\.dpkg-tmp$/],
                description => "regexps of source files to ignore",
                safe => 0,
                rebuild => 1,
@@ -342,7 +369,7 @@ sub getsetup () {
        },
        web_commit_regexp => {
                type => "internal",
-               default => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
+               default => qr/^web commit (by (.*?(?=: |$))|from ([0-9a-fA-F:.]+[0-9a-fA-F])):?(.*)/,
                description => "regexp to parse web commits from logs",
                safe => 0,
                rebuild => 0,
@@ -452,7 +479,7 @@ sub checkconfig () {
        if (defined $config{locale}) {
                if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
                        $ENV{LANG}=$config{locale};
-                       $gettext_obj=undef;
+                       define_gettext();
                }
        }
                
@@ -522,12 +549,12 @@ sub loadplugins () {
        }
        
        if ($config{rcs}) {
-               if (exists $IkiWiki::hooks{rcs}) {
+               if (exists $hooks{rcs}) {
                        error(gettext("cannot use multiple rcs plugins"));
                }
                loadplugin($config{rcs});
        }
-       if (! exists $IkiWiki::hooks{rcs}) {
+       if (! exists $hooks{rcs}) {
                loadplugin("norcs");
        }
 
@@ -647,9 +674,15 @@ sub pagetype ($) {
        return;
 }
 
+my %pagename_cache;
+
 sub pagename ($) {
        my $file=shift;
 
+       if (exists $pagename_cache{$file}) {
+               return $pagename_cache{$file};
+       }
+
        my $type=pagetype($file);
        my $page=$file;
        $page=~s/\Q.$type\E*$//
@@ -658,6 +691,8 @@ sub pagename ($) {
        if ($config{indexpages} && $page=~/(.*)\/index$/) {
                $page=$1;
        }
+
+       $pagename_cache{$file} = $page;
        return $page;
 }
 
@@ -715,7 +750,7 @@ sub add_underlay ($) {
        my $dir=shift;
 
        if ($dir !~ /^\//) {
-               $dir="$config{underlaydir}/../$dir";
+               $dir="$config{underlaydirbase}/$dir";
        }
 
        if (! grep { $_ eq $dir } @{$config{underlaydirs}}) {
@@ -1056,6 +1091,41 @@ sub htmllink ($$$;@) {
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
 }
 
+sub openiduser ($) {
+       my $user=shift;
+
+       if ($user =~ m!^https?://! &&
+           eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
+               my $display;
+
+               if (Net::OpenID::VerifiedIdentity->can("DisplayOfURL")) {
+                       # this works in at least 2.x
+                       $display = Net::OpenID::VerifiedIdentity::DisplayOfURL($user);
+               }
+               else {
+                       # this only works in 1.x
+                       my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
+                       $display=$oid->display;
+               }
+
+               # Convert "user.somehost.com" to "user [somehost.com]"
+               # (also "user.somehost.co.uk")
+               if ($display !~ /\[/) {
+                       $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
+               }
+               # Convert "http://somehost.com/user" to "user [somehost.com]".
+               # (also "https://somehost.com/user/")
+               if ($display !~ /\[/) {
+                       $display=~s/^https?:\/\/(.+)\/([^\/]+)\/?$/$2 [$1]/;
+               }
+               $display=~s!^https?://!!; # make sure this is removed
+               eval q{use CGI 'escapeHTML'};
+               error($@) if $@;
+               return escapeHTML($display);
+       }
+       return;
+}
+
 sub userlink ($) {
        my $user=shift;
 
@@ -1206,9 +1276,10 @@ sub preprocess ($$$;$$) {
                                        );
                                };
                                if ($@) {
-                                       chomp $@;
+                                       my $error=$@;
+                                       chomp $error;
                                        $ret="[[!$command <span class=\"error\">".
-                                               gettext("Error").": $@"."</span>]]";
+                                               gettext("Error").": $error"."</span>]]";
                                }
                        }
                        else {
@@ -1246,7 +1317,7 @@ sub preprocess ($$$;$$) {
                                                |
                                                "[^"]+"         # single-quoted value
                                                |
-                                               [^\s\]]+        # unquoted value
+                                               [^"\s\]]+       # unquoted value
                                        )
                                        \s*                     # whitespace or end
                                                                # of directive
@@ -1269,7 +1340,7 @@ sub preprocess ($$$;$$) {
                                                |
                                                "[^"]+"         # single-quoted value
                                                |
-                                               [^\s\]]+        # unquoted value
+                                               [^"\s\]]+       # unquoted value
                                        )
                                        \s*                     # whitespace or end
                                                                # of directive
@@ -1339,7 +1410,7 @@ sub check_content (@) {
                foreach my $line (split("\n", $params{content})) {
                        push @diff, $line if ! exists $old{$_};
                }
-               $params{content}=join("\n", @diff);
+               $params{diff}=join("\n", @diff);
        }
 
        my $ok;
@@ -1417,7 +1488,8 @@ sub loadindex () {
        %oldrenderedfiles=%pagectime=();
        if (! $config{rebuild}) {
                %pagesources=%pagemtime=%oldlinks=%links=%depends=
-               %destsources=%renderedfiles=%pagecase=%pagestate=();
+               %destsources=%renderedfiles=%pagecase=%pagestate=
+               %depends_simple=();
        }
        my $in;
        if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
@@ -1457,7 +1529,27 @@ sub loadindex () {
                                $links{$page}=$d->{links};
                                $oldlinks{$page}=[@{$d->{links}}];
                        }
-                       if (exists $d->{depends}) {
+                       if (ref $d->{depends_simple} eq 'ARRAY') {
+                               # old format
+                               $depends_simple{$page}={
+                                       map { $_ => 1 } @{$d->{depends_simple}}
+                               };
+                       }
+                       elsif (exists $d->{depends_simple}) {
+                               $depends_simple{$page}=$d->{depends_simple};
+                       }
+                       if (exists $d->{dependslist}) {
+                               # old format
+                               $depends{$page}={
+                                       map { $_ => $DEPEND_CONTENT }
+                                               @{$d->{dependslist}}
+                               };
+                       }
+                       elsif (exists $d->{depends} && ! ref $d->{depends}) {
+                               # old format
+                               $depends{$page}={$d->{depends} => $DEPEND_CONTENT };
+                       }
+                       elsif (exists $d->{depends}) {
                                $depends{$page}=$d->{depends};
                        }
                        if (exists $d->{state}) {
@@ -1507,6 +1599,10 @@ sub saveindex () {
                        $index{page}{$src}{depends} = $depends{$page};
                }
 
+               if (exists $depends_simple{$page}) {
+                       $index{page}{$src}{depends_simple} = $depends_simple{$page};
+               }
+
                if (exists $pagestate{$page}) {
                        foreach my $id (@hookids) {
                                foreach my $key (keys %{$pagestate{$page}{$id}}) {
@@ -1536,7 +1632,8 @@ sub saveindex () {
 sub template_file ($) {
        my $template=shift;
 
-       foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
+       foreach my $dir ($config{templatedir}, @{$config{templatedirs}},
+                        "$installdir/share/ikiwiki/templates") {
                return "$dir/$template" if -e "$dir/$template";
        }
        return;
@@ -1671,61 +1768,97 @@ sub rcs_receive () {
        $hooks{rcs}{rcs_receive}{call}->();
 }
 
-sub safequote ($) {
-       my $s=shift;
-       $s=~s/[{}]//g;
-       return "q{$s}";
-}
-
-sub add_depends ($$) {
+sub add_depends ($$;$) {
        my $page=shift;
        my $pagespec=shift;
-       
-       return unless pagespec_valid($pagespec);
+       my $deptype=shift || $DEPEND_CONTENT;
+
+       # Is the pagespec a simple page name?
+       if ($pagespec =~ /$config{wiki_file_regexp}/ &&
+           $pagespec !~ /[\s*?()!]/) {
+               $depends_simple{$page}{lc $pagespec} |= $deptype;
+               return 1;
+       }
+
+       # Analyse the pagespec, and match it against all pages
+       # to get a list of influences, and add explicit dependencies
+       # for those.
+       #my $sub=pagespec_translate($pagespec);
+       #return if $@;
+       #foreach my $p (keys %pagesources) {
+       #       my $r=$sub->($p, location => $page );
+       #       my %i=$r->influences;
+       #       foreach my $i (keys %i) {
+       #               $depends_simple{$page}{lc $i} |= $i{$i};
+       #       }
+       #}
+       print STDERR "warning: use of add_depends; influences not tracked\n";
+
+       $depends{$page}{$pagespec} |= $deptype;
+       return 1;
+}
 
-       if (! exists $depends{$page}) {
-               $depends{$page}=$pagespec;
-       }
-       else {
-               $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
+sub deptype (@) {
+       my $deptype=0;
+       foreach my $type (@_) {
+               if ($type eq 'presence') {
+                       $deptype |= $DEPEND_PRESENCE;
+               }
+               elsif ($type eq 'links') { 
+                       $deptype |= $DEPEND_LINKS;
+               }
+               elsif ($type eq 'content') {
+                       $deptype |= $DEPEND_CONTENT;
+               }
        }
-
-       return 1;
+       return $deptype;
 }
 
-sub file_pruned ($$) {
-       require File::Spec;
-       my $file=File::Spec->canonpath(shift);
-       my $base=File::Spec->canonpath(shift);
-       $file =~ s#^\Q$base\E/+##;
+sub file_pruned ($;$) {
+       my $file=shift;
+       if (@_) {
+               require File::Spec;
+               $file=File::Spec->canonpath($file);
+               my $base=File::Spec->canonpath(shift);
+               return if $file eq $base;
+               $file =~ s#^\Q$base\E/+##;
+       }
 
        my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
-       return $file =~ m/$regexp/ && $file ne $base;
+       return $file =~ m/$regexp/;
 }
 
-sub gettext {
-       # Only use gettext in the rare cases it's needed.
+sub define_gettext () {
+       # If translation is needed, redefine the gettext function to do it.
+       # Otherwise, it becomes a quick no-op.
+       no warnings 'redefine';
        if ((exists $ENV{LANG} && length $ENV{LANG}) ||
            (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) ||
            (exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES})) {
-               if (! $gettext_obj) {
-                       $gettext_obj=eval q{
+               *gettext=sub {
+                       my $gettext_obj=eval q{
                                use Locale::gettext q{textdomain};
                                Locale::gettext->domain('ikiwiki')
                        };
-                       if ($@) {
-                               print STDERR "$@";
-                               $gettext_obj=undef;
+
+                       if ($gettext_obj) {
+                               $gettext_obj->get(shift);
+                       }
+                       else {
                                return shift;
                        }
-               }
-               return $gettext_obj->get(shift);
+               };
        }
        else {
-               return shift;
+               *gettext=sub { return shift };
        }
 }
 
+sub gettext {
+       define_gettext();
+       gettext(@_);
+}
+
 sub yesno ($) {
        my $val=shift;
 
@@ -1765,19 +1898,12 @@ sub add_link ($$) {
                unless grep { $_ eq $link } @{$links{$page}};
 }
 
-sub pagespec_merge ($$) {
-       my $a=shift;
-       my $b=shift;
-
-       return $a if $a eq $b;
-       return "($a) or ($b)";
-}
-
 sub pagespec_translate ($) {
        my $spec=shift;
 
        # Convert spec to perl code.
        my $code="";
+       my @data;
        while ($spec=~m{
                \s*             # ignore whitespace
                (               # 1: match a single word
@@ -1792,27 +1918,30 @@ sub pagespec_translate ($) {
                        [^\s()]+        # any other text
                )
                \s*             # ignore whitespace
-       }igx) {
+       }gx) {
                my $word=$1;
                if (lc $word eq 'and') {
-                       $code.=' &&';
+                       $code.=' &';
                }
                elsif (lc $word eq 'or') {
-                       $code.=' ||';
+                       $code.=' |';
                }
                elsif ($word eq "(" || $word eq ")" || $word eq "!") {
                        $code.=' '.$word;
                }
                elsif ($word =~ /^(\w+)\((.*)\)$/) {
                        if (exists $IkiWiki::PageSpec::{"match_$1"}) {
-                               $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@_)";
+                               push @data, $2;
+                               $code.="IkiWiki::PageSpec::match_$1(\$page, \$data[$#data], \@_)";
                        }
                        else {
-                               $code.="IkiWiki::ErrorReason->new(".safequote(qq{unknown function in pagespec "$word"}).")";
+                               push @data, qq{unknown function in pagespec "$word"};
+                               $code.="IkiWiki::ErrorReason->new(\$data[$#data])";
                        }
                }
                else {
-                       $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@_)";
+                       push @data, $word;
+                       $code.=" IkiWiki::PageSpec::match_glob(\$page, \$data[$#data], \@_)";
                }
        }
 
@@ -1841,27 +1970,95 @@ sub pagespec_match ($$;@) {
 }
 
 sub pagespec_match_list ($$;@) {
-       my $pages=shift;
-       my $spec=shift;
-       my @params=@_;
+       my $page=shift;
+       my $pagespec=shift;
+       my %params=@_;
 
-       my $sub=pagespec_translate($spec);
-       error "syntax error in pagespec \"$spec\""
+       # Backwards compatability with old calling convention.
+       if (ref $page) {
+               print STDERR "warning: a plugin (".caller().") is using pagespec_match_list in an obsolete way, and needs to be updated\n";
+               $params{list}=$page;
+               $page=$params{location}; # ugh!
+       }
+
+       my $sub=pagespec_translate($pagespec);
+       error "syntax error in pagespec \"$pagespec\""
                if $@ || ! defined $sub;
+
+       my @candidates;
+       if (exists $params{limit}) {
+               @candidates=grep { $params{limit}->($_) } keys %pagesources;
+       }
+       else {
+               @candidates=keys %pagesources;
+       }
+
+       if (defined $params{sort}) {
+               my $f;
+               if ($params{sort} eq 'title') {
+                       $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) };
+               }
+               elsif ($params{sort} eq 'title_natural') {
+                       eval q{use Sort::Naturally};
+                       if ($@) {
+                               error(gettext("Sort::Naturally needed for title_natural sort"));
+                       }
+                       $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) };
+                }
+               elsif ($params{sort} eq 'mtime') {
+                       $f=sub { $pagemtime{$b} <=> $pagemtime{$a} };
+               }
+               elsif ($params{sort} eq 'age') {
+                       $f=sub { $pagectime{$b} <=> $pagectime{$a} };
+               }
+               else {
+                       error sprintf(gettext("unknown sort type %s"), $params{sort});
+               }
+               @candidates = sort { &$f } @candidates;
+       }
+
+       @candidates=reverse(@candidates) if $params{reverse};
        
-       my @ret;
-       my $r;
-       foreach my $page (@$pages) {
-               $r=$sub->($page, @params);
-               push @ret, $page if $r;
+       my @matches;
+       my $firstfail;
+       my $count=0;
+       foreach my $p (@candidates) {
+               my $r=$sub->($p, location => $page);
+               if ($r) {
+                       push @matches, [$p, $r];
+                       last if defined $params{num} && ++$count == $params{num};
+               }
+               elsif (! defined $firstfail) {
+                       $firstfail=$r;
+               }
        }
+       
+       $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT);
 
-       if (! @ret && defined $r && $r->isa("IkiWiki::ErrorReason")) {
-               error(sprintf(gettext("cannot match pages: %s"), $r));
+       my @ret;
+       if (@matches) {
+               # Add all influences from successful matches.
+               foreach my $m (@matches) {
+                       push @ret, $m->[0];
+                       my %i=$m->[1]->influences;
+                       foreach my $i (keys %i) {
+                               $depends_simple{$page}{lc $i} |= $i{$i};
+                       }
+               }
        }
-       else {
-               return @ret;
+       elsif (defined $firstfail) {
+               # Add influences from one failure. (Which one should not
+               # matter; all should have the same influences.)
+               my %i=$firstfail->influences;
+               foreach my $i (keys %i) {
+                       $depends_simple{$page}{lc $i} |= $i{$i};
+               }
+
+               error(sprintf(gettext("cannot match pages: %s"), $firstfail))
+                       if $firstfail->isa("IkiWiki::ErrorReason");
        }
+
+       return @ret;
 }
 
 sub pagespec_valid ($) {
@@ -1881,36 +2078,54 @@ sub glob2re ($) {
 package IkiWiki::FailReason;
 
 use overload (
-       '""'    => sub { ${$_[0]} },
+       '""'    => sub { $_[0][0] },
        '0+'    => sub { 0 },
        '!'     => sub { bless $_[0], 'IkiWiki::SuccessReason'},
+       '&'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
+       '|'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
        fallback => 1,
 );
 
-sub new {
-       my $class = shift;
-       my $value = shift;
-       return bless \$value, $class;
-}
-
-package IkiWiki::ErrorReason;
-
-our @ISA = 'IkiWiki::FailReason';
+our @ISA = 'IkiWiki::SuccessReason';
 
 package IkiWiki::SuccessReason;
 
 use overload (
-       '""'    => sub { ${$_[0]} },
+       '""'    => sub { $_[0][0] },
        '0+'    => sub { 1 },
        '!'     => sub { bless $_[0], 'IkiWiki::FailReason'},
+       '&'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
+       '|'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
        fallback => 1,
 );
 
 sub new {
        my $class = shift;
        my $value = shift;
-       return bless \$value, $class;
-};
+       return bless [$value, {@_}], $class;
+}
+
+sub influences {
+       my $this=shift;
+       if (! @_) {
+               return %{$this->[1]};
+       }
+       else {
+               $this->[1]={@_};
+       }
+}
+
+sub merge_influences {
+       my $this=shift;
+       my $other=shift;
+       foreach my $influence (keys %{$other->[1]}) {
+               $this->[1]{$influence} |= $other->[1]{$influence};
+       }
+}
+
+package IkiWiki::ErrorReason;
+
+our @ISA = 'IkiWiki::FailReason';
 
 package IkiWiki::PageSpec;
 
@@ -1961,27 +2176,30 @@ sub match_link ($$;@) {
        my $from=exists $params{location} ? $params{location} : '';
 
        my $links = $IkiWiki::links{$page};
-       return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links};
+       return IkiWiki::FailReason->new("$page has no links")
+               unless $links && @{$links};
        my $bestlink = IkiWiki::bestlink($from, $link);
        foreach my $p (@{$links}) {
                if (length $bestlink) {
-                       return IkiWiki::SuccessReason->new("$page links to $link")
+                       return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS)
                                if $bestlink eq IkiWiki::bestlink($page, $p);
                }
                else {
-                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
+                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS)
                                if match_glob($p, $link, %params);
-                       $p=~s/^\///;
+                       my ($p_rel)=$p=~/^\/?(.*)/;
                        $link=~s/^\///;
-                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
-                               if match_glob($p, $link, %params);
+                       return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS)
+                               if match_glob($p_rel, $link, %params);
                }
        }
        return IkiWiki::FailReason->new("$page does not link to $link");
 }
 
 sub match_backlink ($$;@) {
-       return match_link($_[1], $_[0], @_);
+       my $ret=match_link($_[1], $_[0], @_);
+       $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS);
+       return $ret;
 }
 
 sub match_created_before ($$;@) {
@@ -1993,14 +2211,14 @@ sub match_created_before ($$;@) {
 
        if (exists $IkiWiki::pagectime{$testpage}) {
                if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
-                       return IkiWiki::SuccessReason->new("$page created before $testpage");
+                       return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
                else {
-                       return IkiWiki::FailReason->new("$page not created before $testpage");
+                       return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
        }
        else {
-               return IkiWiki::FailReason->new("$testpage has no ctime");
+               return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
        }
 }
 
@@ -2013,14 +2231,14 @@ sub match_created_after ($$;@) {
 
        if (exists $IkiWiki::pagectime{$testpage}) {
                if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
-                       return IkiWiki::SuccessReason->new("$page created after $testpage");
+                       return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
                else {
-                       return IkiWiki::FailReason->new("$page not created after $testpage");
+                       return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
        }
        else {
-               return IkiWiki::FailReason->new("$testpage has no ctime");
+               return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
        }
 }