8 use URI::Escape q{uri_escape_utf8};
10 use open qw{:utf8 :std};
12 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
13 %renderedfiles %oldrenderedfiles %pagesources %destsources
14 %depends %hooks %forcerebuild $gettext_obj};
16 use Exporter q{import};
17 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
18 bestlink htmllink readfile writefile pagetype srcfile pagename
19 displaytime will_render gettext urlto targetpage
20 %config %links %renderedfiles %pagesources %destsources);
21 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
22 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
23 my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
28 memoize("pagespec_translate");
29 memoize("file_pruned");
31 sub defaultconfig () { #{{{
32 wiki_file_prune_regexps => [qr/\.\./, qr/^\./, qr/\/\./,
33 qr/\.x?html?$/, qr/\.ikiwiki-new$/,
34 qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
36 wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]#]+)(?:#([^\s\]]+))?\]\]/,
37 wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
38 web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
42 default_pageext => "mdwn",
62 gitorigin_branch => "origin",
63 gitmaster_branch => "master",
67 templatedir => "$installdir/share/ikiwiki/templates",
68 underlaydir => "$installdir/share/ikiwiki/basewiki",
72 plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
73 lockedit conditional}],
81 account_creation_password => "",
84 sub checkconfig () { #{{{
85 # locale stuff; avoid LC_ALL since it overrides everything
86 if (defined $ENV{LC_ALL}) {
87 $ENV{LANG} = $ENV{LC_ALL};
90 if (defined $config{locale}) {
91 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
92 $ENV{LANG}=$config{locale};
97 if ($config{w3mmode}) {
98 eval q{use Cwd q{abs_path}};
100 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
101 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
102 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
103 unless $config{cgiurl} =~ m!file:///!;
104 $config{url}="file://".$config{destdir};
107 if ($config{cgi} && ! length $config{url}) {
108 error(gettext("Must specify url to wiki with --url when using --cgi"));
111 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
112 unless exists $config{wikistatedir};
115 eval qq{require IkiWiki::Rcs::$config{rcs}};
117 error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
121 require IkiWiki::Rcs::Stub;
124 run_hooks(checkconfig => sub { shift->() });
127 sub loadplugins () { #{{{
128 loadplugin($_) foreach @{$config{plugin}};
130 run_hooks(getopt => sub { shift->() });
131 if (grep /^-/, @ARGV) {
132 print STDERR "Unknown option: $_\n"
133 foreach grep /^-/, @ARGV;
138 sub loadplugin ($) { #{{{
141 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
143 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
146 error("Failed to load plugin $mod: $@");
150 sub error ($;$) { #{{{
154 print "Content-type: text/html\n\n";
155 print misctemplate(gettext("Error"),
156 "<p>".gettext("Error").": $message</p>");
158 log_message('err' => $message) if $config{syslog};
159 if (defined $cleaner) {
166 return unless $config{verbose};
167 log_message(debug => @_);
171 sub log_message ($$) { #{{{
174 if ($config{syslog}) {
177 Sys::Syslog::setlogsock('unix');
178 Sys::Syslog::openlog('ikiwiki', '', 'user');
182 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
185 elsif (! $config{cgi}) {
193 sub possibly_foolish_untaint ($) { #{{{
195 my ($untainted)=$tainted=~/(.*)/;
199 sub basename ($) { #{{{
206 sub dirname ($) { #{{{
213 sub pagetype ($) { #{{{
216 if ($page =~ /\.([^.]+)$/) {
217 return $1 if exists $hooks{htmlize}{$1};
222 sub pagename ($) { #{{{
225 my $type=pagetype($file);
227 $page=~s/\Q.$type\E*$// if defined $type;
231 sub targetpage ($$) { #{{{
235 if (! $config{usedirs} || $page =~ /^index$/ ) {
236 return $page.".".$ext;
238 return $page."/index.".$ext;
242 sub htmlpage ($) { #{{{
245 return targetpage($page, "html");
248 sub srcfile ($) { #{{{
251 return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
252 return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
253 error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
256 sub readfile ($;$$) { #{{{
262 error("cannot read a symlink ($file)");
266 open (IN, $file) || error("failed to read $file: $!");
267 binmode(IN) if ($binary);
268 return \*IN if $wantfd;
270 close IN || error("failed to read $file: $!");
274 sub writefile ($$$;$$) { #{{{
275 my $file=shift; # can include subdirs
276 my $destdir=shift; # directory to put file in
282 while (length $test) {
283 if (-l "$destdir/$test") {
284 error("cannot write to a symlink ($test)");
286 $test=dirname($test);
288 my $newfile="$destdir/$file.ikiwiki-new";
290 error("cannot write to a symlink ($newfile)");
293 my $dir=dirname($newfile);
296 foreach my $s (split(m!/+!, $dir)) {
299 mkdir($d) || error("failed to create directory $d: $!");
304 my $cleanup = sub { unlink($newfile) };
305 open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup);
306 binmode(OUT) if ($binary);
308 $writer->(\*OUT, $cleanup);
311 print OUT $content or error("failed writing to $newfile: $!", $cleanup);
313 close OUT || error("failed saving $newfile: $!", $cleanup);
314 rename($newfile, "$destdir/$file") ||
315 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
319 sub will_render ($$;$) { #{{{
324 # Important security check.
325 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
326 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
327 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
330 if (! $clear || $cleared{$page}) {
331 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
334 foreach my $old (@{$renderedfiles{$page}}) {
335 delete $destsources{$old};
337 $renderedfiles{$page}=[$dest];
340 $destsources{$dest}=$page;
343 sub bestlink ($$) { #{{{
348 if ($link=~s/^\/+//) {
355 $l.="/" if length $l;
358 if (exists $links{$l}) {
361 elsif (exists $pagecase{lc $l}) {
362 return $pagecase{lc $l};
364 } while $cwd=~s!/?[^/]+$!!;
366 if (length $config{userdir}) {
367 my $l = "$config{userdir}/".lc($link);
368 if (exists $links{$l}) {
371 elsif (exists $pagecase{lc $l}) {
372 return $pagecase{lc $l};
376 #print STDERR "warning: page $page, broken link: $link\n";
380 sub isinlinableimage ($) { #{{{
383 $file=~/\.(png|gif|jpg|jpeg)$/i;
386 sub pagetitle ($;$) { #{{{
391 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
394 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
400 sub titlepage ($) { #{{{
402 $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
406 sub linkpage ($) { #{{{
408 $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
412 sub cgiurl (@) { #{{{
415 return $config{cgiurl}."?".
416 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
419 sub baseurl (;$) { #{{{
422 return "$config{url}/" if ! defined $page;
424 $page=htmlpage($page);
426 $page=~s/[^\/]+\//..\//g;
430 sub abs2rel ($$) { #{{{
431 # Work around very innefficient behavior in File::Spec if abs2rel
432 # is passed two relative paths. It's much faster if paths are
433 # absolute! (Debian bug #376658; fixed in debian unstable now)
438 my $ret=File::Spec->abs2rel($path, $base);
439 $ret=~s/^// if defined $ret;
443 sub displaytime ($) { #{{{
446 # strftime doesn't know about encodings, so make sure
447 # its output is properly treated as utf8
448 return decode_utf8(POSIX::strftime(
449 $config{timeformat}, localtime($time)));
452 sub beautify_url ($) { #{{{
455 $url =~ s!/index.html$!/!;
456 $url =~ s!^$!./!; # Browsers don't like empty links...
461 sub urlto ($$) { #{{{
466 return beautify_url(baseurl($from));
469 if (! $destsources{$to}) {
473 my $link = abs2rel($to, dirname(htmlpage($from)));
475 return beautify_url($link);
478 sub htmllink ($$$;@) { #{{{
479 my $lpage=shift; # the page doing the linking
480 my $page=shift; # the page that will contain the link (different for inline)
485 if (! $opts{forcesubpage}) {
486 $bestlink=bestlink($lpage, $link);
489 $bestlink="$lpage/".lc($link);
493 if (defined $opts{linktext}) {
494 $linktext=$opts{linktext};
497 $linktext=pagetitle(basename($link));
500 return "<span class=\"selflink\">$linktext</span>"
501 if length $bestlink && $page eq $bestlink;
503 if (! $destsources{$bestlink}) {
504 $bestlink=htmlpage($bestlink);
506 if (! $destsources{$bestlink}) {
507 return $linktext unless length $config{cgiurl};
508 return "<span><a href=\"".
511 page => pagetitle(lc($link), 1),
514 "\">?</a>$linktext</span>"
518 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
519 $bestlink=beautify_url($bestlink);
521 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
522 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
525 if (defined $opts{anchor}) {
526 $bestlink.="#".$opts{anchor};
529 return "<a href=\"$bestlink\">$linktext</a>";
532 sub htmlize ($$$) { #{{{
537 if (exists $hooks{htmlize}{$type}) {
538 $content=$hooks{htmlize}{$type}{call}->(
544 error("htmlization of $type not supported");
547 run_hooks(sanitize => sub {
557 sub linkify ($$$) { #{{{
558 my $lpage=shift; # the page containing the links
559 my $page=shift; # the page the link will end up on (different for inline)
562 $content =~ s{(\\?)$config{wiki_link_regexp}}{
565 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
566 : htmllink($lpage, $page, linkpage($3),
567 anchor => $4, linktext => pagetitle($2)))
569 ? "[[$3".($4 ? "#$4" : "")."]]"
570 : htmllink($lpage, $page, linkpage($3),
578 our $preprocess_preview=0;
579 sub preprocess ($$$;$$) { #{{{
580 my $page=shift; # the page the data comes from
581 my $destpage=shift; # the page the data will appear in (different for inline)
586 # Using local because it needs to be set within any nested calls
588 local $preprocess_preview=$preview if defined $preview;
594 if (length $escape) {
595 return "[[$command $params]]";
597 elsif (exists $hooks{preprocess}{$command}) {
598 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
599 # Note: preserve order of params, some plugins may
600 # consider it significant.
602 while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
619 push @params, $key, $val;
622 push @params, $val, '';
625 if ($preprocessing{$page}++ > 3) {
626 # Avoid loops of preprocessed pages preprocessing
627 # other pages that preprocess them, etc.
628 #translators: The first parameter is a
629 #translators: preprocessor directive name,
630 #translators: the second a page name, the
631 #translators: third a number.
632 return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
633 $command, $page, $preprocessing{$page}).
636 my $ret=$hooks{preprocess}{$command}{call}->(
639 destpage => $destpage,
640 preview => $preprocess_preview,
642 $preprocessing{$page}--;
646 return "[[$command $params]]";
650 $content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
654 sub filter ($$$) { #{{{
659 run_hooks(filter => sub {
660 $content=shift->(page => $page, destpage => $destpage,
661 content => $content);
667 sub indexlink () { #{{{
668 return "<a href=\"$config{url}\">$config{wikiname}</a>";
671 sub lockwiki (;$) { #{{{
672 my $wait=@_ ? shift : 1;
673 # Take an exclusive lock on the wiki to prevent multiple concurrent
674 # run issues. The lock will be dropped on program exit.
675 if (! -d $config{wikistatedir}) {
676 mkdir($config{wikistatedir});
678 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
679 error ("cannot write to $config{wikistatedir}/lockfile: $!");
680 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
682 debug("wiki seems to be locked, waiting for lock");
683 my $wait=600; # arbitrary, but don't hang forever to
684 # prevent process pileup
686 return if flock(WIKILOCK, 2 | 4);
689 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
692 debug("wiki is locked");
699 sub unlockwiki () { #{{{
703 sub commit_hook_enabled () { #{{{
704 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
705 error ("cannot write to $config{wikistatedir}/commitlock: $!");
706 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
714 sub disable_commit_hook () { #{{{
715 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
716 error ("cannot write to $config{wikistatedir}/commitlock: $!");
717 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
718 error("failed to get commit lock");
722 sub enable_commit_hook () { #{{{
726 sub loadindex () { #{{{
727 open (IN, "$config{wikistatedir}/index") || return;
729 $_=possibly_foolish_untaint($_);
734 foreach my $i (split(/ /, $_)) {
735 my ($item, $val)=split(/=/, $i, 2);
736 push @{$items{$item}}, decode_entities($val);
739 next unless exists $items{src}; # skip bad lines for now
741 my $page=pagename($items{src}[0]);
742 if (! $config{rebuild}) {
743 $pagesources{$page}=$items{src}[0];
744 $pagemtime{$page}=$items{mtime}[0];
745 $oldlinks{$page}=[@{$items{link}}];
746 $links{$page}=[@{$items{link}}];
747 $depends{$page}=$items{depends}[0] if exists $items{depends};
748 $destsources{$_}=$page foreach @{$items{dest}};
749 $renderedfiles{$page}=[@{$items{dest}}];
750 $oldrenderedfiles{$page}=[@{$items{dest}}];
751 $pagecase{lc $page}=$page;
753 $pagectime{$page}=$items{ctime}[0];
758 sub saveindex () { #{{{
759 run_hooks(savestate => sub { shift->() });
761 if (! -d $config{wikistatedir}) {
762 mkdir($config{wikistatedir});
764 my $newfile="$config{wikistatedir}/index.new";
765 my $cleanup = sub { unlink($newfile) };
766 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
767 foreach my $page (keys %pagemtime) {
768 next unless $pagemtime{$page};
769 my $line="mtime=$pagemtime{$page} ".
770 "ctime=$pagectime{$page} ".
771 "src=$pagesources{$page}";
772 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
774 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
775 if (exists $depends{$page}) {
776 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
778 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
780 close OUT || error("failed saving to $newfile: $!", $cleanup);
781 rename($newfile, "$config{wikistatedir}/index") ||
782 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
785 sub template_file ($) { #{{{
788 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
789 return "$dir/$template" if -e "$dir/$template";
794 sub template_params (@) { #{{{
795 my $filename=template_file(shift);
797 if (! defined $filename) {
802 require HTML::Template;
805 my $text_ref = shift;
806 $$text_ref=&Encode::decode_utf8($$text_ref);
808 filename => $filename,
809 loop_context_vars => 1,
810 die_on_bad_params => 0,
813 return wantarray ? @ret : {@ret};
816 sub template ($;@) { #{{{
817 HTML::Template->new(template_params(@_));
820 sub misctemplate ($$;@) { #{{{
824 my $template=template("misc.tmpl");
827 indexlink => indexlink(),
828 wikiname => $config{wikiname},
829 pagebody => $pagebody,
830 baseurl => baseurl(),
833 run_hooks(pagetemplate => sub {
834 shift->(page => "", destpage => "", template => $template);
836 return $template->output;
842 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
843 error "hook requires type, call, and id parameters";
846 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
848 $hooks{$param{type}}{$param{id}}=\%param;
851 sub run_hooks ($$) { # {{{
852 # Calls the given sub for each hook of the given type,
853 # passing it the hook function to call.
857 if (exists $hooks{$type}) {
859 foreach my $id (keys %{$hooks{$type}}) {
860 if ($hooks{$type}{$id}{last}) {
864 $sub->($hooks{$type}{$id}{call});
866 foreach my $id (@deferred) {
867 $sub->($hooks{$type}{$id}{call});
872 sub globlist_to_pagespec ($) { #{{{
873 my @globlist=split(' ', shift);
876 foreach my $glob (@globlist) {
877 if ($glob=~/^!(.*)/) {
885 my $spec=join(" or ", @spec);
887 my $skip=join(" and ", @skip);
889 $spec="$skip and ($spec)";
898 sub is_globlist ($) { #{{{
900 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
903 sub safequote ($) { #{{{
909 sub add_depends ($$) { #{{{
913 if (! exists $depends{$page}) {
914 $depends{$page}=$pagespec;
917 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
921 sub file_pruned ($$) { #{{{
923 my $file=File::Spec->canonpath(shift);
924 my $base=File::Spec->canonpath(shift);
925 $file=~s#^\Q$base\E/*##;
927 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
932 # Only use gettext in the rare cases it's needed.
933 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
934 if (! $gettext_obj) {
936 use Locale::gettext q{textdomain};
937 Locale::gettext->domain('ikiwiki')
945 return $gettext_obj->get(shift);
952 sub pagespec_merge ($$) { #{{{
956 return $a if $a eq $b;
958 # Support for old-style GlobLists.
959 if (is_globlist($a)) {
960 $a=globlist_to_pagespec($a);
962 if (is_globlist($b)) {
963 $b=globlist_to_pagespec($b);
966 return "($a) or ($b)";
969 sub pagespec_translate ($) { #{{{
970 # This assumes that $page is in scope in the function
971 # that evalulates the translated pagespec code.
974 # Support for old-style GlobLists.
975 if (is_globlist($spec)) {
976 $spec=globlist_to_pagespec($spec);
979 # Convert spec to perl code.
981 while ($spec=~m/\s*(\!|\(|\)|\w+\([^\)]+\)|[^\s()]+)\s*/ig) {
983 if (lc $word eq "and") {
986 elsif (lc $word eq "or") {
989 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
992 elsif ($word =~ /^(\w+)\((.*)\)$/) {
993 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
994 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
1001 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
1008 sub pagespec_match ($$;@) { #{{{
1013 # Backwards compatability with old calling convention.
1015 unshift @params, "location";
1018 my $ret=eval pagespec_translate($spec);
1019 return IkiWiki::FailReason->new("syntax error") if $@;
1023 package IkiWiki::FailReason;
1026 '""' => sub { ${$_[0]} },
1028 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1033 bless \$_[1], $_[0];
1036 package IkiWiki::SuccessReason;
1039 '""' => sub { ${$_[0]} },
1041 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1046 bless \$_[1], $_[0];
1049 package IkiWiki::PageSpec;
1051 sub match_glob ($$;@) { #{{{
1056 my $from=exists $params{location} ? $params{location} : "";
1059 if ($glob =~ m!^\./!) {
1060 $from=~s!/?[^/]+$!!;
1062 $glob="$from/$glob" if length $from;
1065 # turn glob into safe regexp
1066 $glob=quotemeta($glob);
1070 if ($page=~/^$glob$/i) {
1071 return IkiWiki::SuccessReason->new("$glob matches $page");
1074 return IkiWiki::FailReason->new("$glob does not match $page");
1078 sub match_link ($$;@) { #{{{
1083 my $from=exists $params{location} ? $params{location} : "";
1086 if ($link =~ m!^\.! && defined $from) {
1087 $from=~s!/?[^/]+$!!;
1089 $link="$from/$link" if length $from;
1092 my $links = $IkiWiki::links{$page} or return undef;
1093 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1094 my $bestlink = IkiWiki::bestlink($from, $link);
1095 return IkiWiki::FailReason->new("no such link") unless length $bestlink;
1096 foreach my $p (@$links) {
1097 return IkiWiki::SuccessReason->new("$page links to $link")
1098 if $bestlink eq IkiWiki::bestlink($page, $p);
1100 return IkiWiki::FailReason->new("$page does not link to $link");
1103 sub match_backlink ($$;@) { #{{{
1104 match_link($_[1], $_[0], @_);
1107 sub match_created_before ($$;@) { #{{{
1111 if (exists $IkiWiki::pagectime{$testpage}) {
1112 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1113 IkiWiki::SuccessReason->new("$page created before $testpage");
1116 IkiWiki::FailReason->new("$page not created before $testpage");
1120 return IkiWiki::FailReason->new("$testpage has no ctime");
1124 sub match_created_after ($$;@) { #{{{
1128 if (exists $IkiWiki::pagectime{$testpage}) {
1129 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1130 IkiWiki::SuccessReason->new("$page created after $testpage");
1133 IkiWiki::FailReason->new("$page not created after $testpage");
1137 return IkiWiki::FailReason->new("$testpage has no ctime");
1141 sub match_creation_day ($$;@) { #{{{
1142 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1143 return IkiWiki::SuccessReason->new("creation_day matched");
1146 return IkiWiki::FailReason->new("creation_day did not match");
1150 sub match_creation_month ($$;@) { #{{{
1151 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1152 return IkiWiki::SuccessReason->new("creation_month matched");
1155 return IkiWiki::FailReason->new("creation_month did not match");
1159 sub match_creation_year ($$;@) { #{{{
1160 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1161 return IkiWiki::SuccessReason->new("creation_year matched");
1164 return IkiWiki::FailReason->new("creation_year did not match");
1168 sub match_user ($$;@) { #{{{
1173 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1174 if ($user eq $params{user}) {
1175 return IkiWiki::SuccessReason->new("user is $user")
1178 return IkiWiki::FailReason->new("user is not $user");