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 signinedit
73 lockedit conditional}],
83 sub checkconfig () { #{{{
84 # locale stuff; avoid LC_ALL since it overrides everything
85 if (defined $ENV{LC_ALL}) {
86 $ENV{LANG} = $ENV{LC_ALL};
89 if (defined $config{locale}) {
90 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
91 $ENV{LANG}=$config{locale};
96 if ($config{w3mmode}) {
97 eval q{use Cwd q{abs_path}};
99 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
100 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
101 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
102 unless $config{cgiurl} =~ m!file:///!;
103 $config{url}="file://".$config{destdir};
106 if ($config{cgi} && ! length $config{url}) {
107 error(gettext("Must specify url to wiki with --url when using --cgi"));
110 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
111 unless exists $config{wikistatedir};
114 eval qq{require IkiWiki::Rcs::$config{rcs}};
116 error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
120 require IkiWiki::Rcs::Stub;
123 run_hooks(checkconfig => sub { shift->() });
126 sub loadplugins () { #{{{
127 loadplugin($_) foreach @{$config{plugin}};
129 run_hooks(getopt => sub { shift->() });
130 if (grep /^-/, @ARGV) {
131 print STDERR "Unknown option: $_\n"
132 foreach grep /^-/, @ARGV;
137 sub loadplugin ($) { #{{{
140 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
142 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
145 error("Failed to load plugin $mod: $@");
149 sub error ($;$) { #{{{
153 print "Content-type: text/html\n\n";
154 print misctemplate(gettext("Error"),
155 "<p>".gettext("Error").": $message</p>");
157 log_message('err' => $message) if $config{syslog};
158 if (defined $cleaner) {
165 return unless $config{verbose};
166 log_message(debug => @_);
170 sub log_message ($$) { #{{{
173 if ($config{syslog}) {
176 Sys::Syslog::setlogsock('unix');
177 Sys::Syslog::openlog('ikiwiki', '', 'user');
181 Sys::Syslog::syslog($type, "%s", join(" ", @_));
184 elsif (! $config{cgi}) {
192 sub possibly_foolish_untaint ($) { #{{{
194 my ($untainted)=$tainted=~/(.*)/;
198 sub basename ($) { #{{{
205 sub dirname ($) { #{{{
212 sub pagetype ($) { #{{{
215 if ($page =~ /\.([^.]+)$/) {
216 return $1 if exists $hooks{htmlize}{$1};
221 sub pagename ($) { #{{{
224 my $type=pagetype($file);
226 $page=~s/\Q.$type\E*$// if defined $type;
230 sub targetpage ($$) { #{{{
234 if (! $config{usedirs} || $page =~ /^index$/ ) {
235 return $page.".".$ext;
237 return $page."/index.".$ext;
241 sub htmlpage ($) { #{{{
244 return targetpage($page, "html");
247 sub srcfile ($) { #{{{
250 return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
251 return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
252 error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
255 sub readfile ($;$$) { #{{{
261 error("cannot read a symlink ($file)");
265 open (IN, $file) || error("failed to read $file: $!");
266 binmode(IN) if ($binary);
267 return \*IN if $wantfd;
269 close IN || error("failed to read $file: $!");
273 sub writefile ($$$;$$) { #{{{
274 my $file=shift; # can include subdirs
275 my $destdir=shift; # directory to put file in
281 while (length $test) {
282 if (-l "$destdir/$test") {
283 error("cannot write to a symlink ($test)");
285 $test=dirname($test);
287 my $newfile="$destdir/$file.ikiwiki-new";
289 error("cannot write to a symlink ($newfile)");
292 my $dir=dirname($newfile);
295 foreach my $s (split(m!/+!, $dir)) {
298 mkdir($d) || error("failed to create directory $d: $!");
303 my $cleanup = sub { unlink($newfile) };
304 open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup);
305 binmode(OUT) if ($binary);
307 $writer->(\*OUT, $cleanup);
310 print OUT $content or error("failed writing to $newfile: $!", $cleanup);
312 close OUT || error("failed saving $newfile: $!", $cleanup);
313 rename($newfile, "$destdir/$file") ||
314 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
318 sub will_render ($$;$) { #{{{
323 # Important security check.
324 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
325 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
326 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
329 if (! $clear || $cleared{$page}) {
330 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
333 foreach my $old (@{$renderedfiles{$page}}) {
334 delete $destsources{$old};
336 $renderedfiles{$page}=[$dest];
339 $destsources{$dest}=$page;
342 sub bestlink ($$) { #{{{
347 if ($link=~s/^\/+//) {
354 $l.="/" if length $l;
357 if (exists $links{$l}) {
360 elsif (exists $pagecase{lc $l}) {
361 return $pagecase{lc $l};
363 } while $cwd=~s!/?[^/]+$!!;
365 if (length $config{userdir}) {
366 my $l = "$config{userdir}/".lc($link);
367 if (exists $links{$l}) {
370 elsif (exists $pagecase{lc $l}) {
371 return $pagecase{lc $l};
375 #print STDERR "warning: page $page, broken link: $link\n";
379 sub isinlinableimage ($) { #{{{
382 $file=~/\.(png|gif|jpg|jpeg)$/i;
385 sub pagetitle ($;$) { #{{{
390 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
393 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
399 sub titlepage ($) { #{{{
401 $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
405 sub linkpage ($) { #{{{
407 $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
411 sub cgiurl (@) { #{{{
414 return $config{cgiurl}."?".
415 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
418 sub baseurl (;$) { #{{{
421 return "$config{url}/" if ! defined $page;
423 $page=htmlpage($page);
425 $page=~s/[^\/]+\//..\//g;
429 sub abs2rel ($$) { #{{{
430 # Work around very innefficient behavior in File::Spec if abs2rel
431 # is passed two relative paths. It's much faster if paths are
432 # absolute! (Debian bug #376658; fixed in debian unstable now)
437 my $ret=File::Spec->abs2rel($path, $base);
438 $ret=~s/^// if defined $ret;
442 sub displaytime ($) { #{{{
445 # strftime doesn't know about encodings, so make sure
446 # its output is properly treated as utf8
447 return decode_utf8(POSIX::strftime(
448 $config{timeformat}, localtime($time)));
451 sub beautify_url ($) { #{{{
454 $url =~ s!/index.html$!/!;
455 $url =~ s!^$!./!; # Browsers don't like empty links...
460 sub urlto ($$) { #{{{
465 return beautify_url(baseurl($from));
468 if (! $destsources{$to}) {
472 my $link = abs2rel($to, dirname(htmlpage($from)));
474 return beautify_url($link);
477 sub htmllink ($$$;@) { #{{{
478 my $lpage=shift; # the page doing the linking
479 my $page=shift; # the page that will contain the link (different for inline)
484 if (! $opts{forcesubpage}) {
485 $bestlink=bestlink($lpage, $link);
488 $bestlink="$lpage/".lc($link);
492 if (defined $opts{linktext}) {
493 $linktext=$opts{linktext};
496 $linktext=pagetitle(basename($link));
499 return "<span class=\"selflink\">$linktext</span>"
500 if length $bestlink && $page eq $bestlink;
502 if (! $destsources{$bestlink}) {
503 $bestlink=htmlpage($bestlink);
505 if (! $destsources{$bestlink}) {
506 return $linktext unless length $config{cgiurl};
507 return "<span><a href=\"".
510 page => pagetitle(lc($link), 1),
513 "\">?</a>$linktext</span>"
517 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
518 $bestlink=beautify_url($bestlink);
520 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
521 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
524 if (defined $opts{anchor}) {
525 $bestlink.="#".$opts{anchor};
528 return "<a href=\"$bestlink\">$linktext</a>";
531 sub htmlize ($$$) { #{{{
536 if (exists $hooks{htmlize}{$type}) {
537 $content=$hooks{htmlize}{$type}{call}->(
543 error("htmlization of $type not supported");
546 run_hooks(sanitize => sub {
556 sub linkify ($$$) { #{{{
557 my $lpage=shift; # the page containing the links
558 my $page=shift; # the page the link will end up on (different for inline)
561 $content =~ s{(\\?)$config{wiki_link_regexp}}{
564 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
565 : htmllink($lpage, $page, linkpage($3),
566 anchor => $4, linktext => pagetitle($2)))
568 ? "[[$3".($4 ? "#$4" : "")."]]"
569 : htmllink($lpage, $page, linkpage($3),
577 our $preprocess_preview=0;
578 sub preprocess ($$$;$$) { #{{{
579 my $page=shift; # the page the data comes from
580 my $destpage=shift; # the page the data will appear in (different for inline)
585 # Using local because it needs to be set within any nested calls
587 local $preprocess_preview=$preview if defined $preview;
593 if (length $escape) {
594 return "[[$command $params]]";
596 elsif (exists $hooks{preprocess}{$command}) {
597 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
598 # Note: preserve order of params, some plugins may
599 # consider it significant.
601 while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
618 push @params, $key, $val;
621 push @params, $val, '';
624 if ($preprocessing{$page}++ > 3) {
625 # Avoid loops of preprocessed pages preprocessing
626 # other pages that preprocess them, etc.
627 #translators: The first parameter is a
628 #translators: preprocessor directive name,
629 #translators: the second a page name, the
630 #translators: third a number.
631 return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
632 $command, $page, $preprocessing{$page}).
635 my $ret=$hooks{preprocess}{$command}{call}->(
638 destpage => $destpage,
639 preview => $preprocess_preview,
641 $preprocessing{$page}--;
645 return "[[$command $params]]";
649 $content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
653 sub filter ($$) { #{{{
657 run_hooks(filter => sub {
658 $content=shift->(page => $page, content => $content);
664 sub indexlink () { #{{{
665 return "<a href=\"$config{url}\">$config{wikiname}</a>";
668 sub lockwiki () { #{{{
669 # Take an exclusive lock on the wiki to prevent multiple concurrent
670 # run issues. The lock will be dropped on program exit.
671 if (! -d $config{wikistatedir}) {
672 mkdir($config{wikistatedir});
674 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
675 error ("cannot write to $config{wikistatedir}/lockfile: $!");
676 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
677 debug("wiki seems to be locked, waiting for lock");
678 my $wait=600; # arbitrary, but don't hang forever to
679 # prevent process pileup
681 return if flock(WIKILOCK, 2 | 4);
684 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
688 sub unlockwiki () { #{{{
692 sub commit_hook_enabled () { #{{{
693 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
694 error ("cannot write to $config{wikistatedir}/commitlock: $!");
695 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
703 sub disable_commit_hook () { #{{{
704 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
705 error ("cannot write to $config{wikistatedir}/commitlock: $!");
706 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
707 error("failed to get commit lock");
711 sub enable_commit_hook () { #{{{
715 sub loadindex () { #{{{
716 open (IN, "$config{wikistatedir}/index") || return;
718 $_=possibly_foolish_untaint($_);
723 foreach my $i (split(/ /, $_)) {
724 my ($item, $val)=split(/=/, $i, 2);
725 push @{$items{$item}}, decode_entities($val);
728 next unless exists $items{src}; # skip bad lines for now
730 my $page=pagename($items{src}[0]);
731 if (! $config{rebuild}) {
732 $pagesources{$page}=$items{src}[0];
733 $pagemtime{$page}=$items{mtime}[0];
734 $oldlinks{$page}=[@{$items{link}}];
735 $links{$page}=[@{$items{link}}];
736 $depends{$page}=$items{depends}[0] if exists $items{depends};
737 $destsources{$_}=$page foreach @{$items{dest}};
738 $renderedfiles{$page}=[@{$items{dest}}];
739 $oldrenderedfiles{$page}=[@{$items{dest}}];
740 $pagecase{lc $page}=$page;
742 $pagectime{$page}=$items{ctime}[0];
747 sub saveindex () { #{{{
748 run_hooks(savestate => sub { shift->() });
750 if (! -d $config{wikistatedir}) {
751 mkdir($config{wikistatedir});
753 my $newfile="$config{wikistatedir}/index.new";
754 my $cleanup = sub { unlink($newfile) };
755 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
756 foreach my $page (keys %pagemtime) {
757 next unless $pagemtime{$page};
758 my $line="mtime=$pagemtime{$page} ".
759 "ctime=$pagectime{$page} ".
760 "src=$pagesources{$page}";
761 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
763 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
764 if (exists $depends{$page}) {
765 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
767 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
769 close OUT || error("failed saving to $newfile: $!", $cleanup);
770 rename($newfile, "$config{wikistatedir}/index") ||
771 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
774 sub template_file ($) { #{{{
777 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
778 return "$dir/$template" if -e "$dir/$template";
783 sub template_params (@) { #{{{
784 my $filename=template_file(shift);
786 if (! defined $filename) {
791 require HTML::Template;
794 my $text_ref = shift;
795 $$text_ref=&Encode::decode_utf8($$text_ref);
797 filename => $filename,
798 loop_context_vars => 1,
799 die_on_bad_params => 0,
802 return wantarray ? @ret : {@ret};
805 sub template ($;@) { #{{{
806 HTML::Template->new(template_params(@_));
809 sub misctemplate ($$;@) { #{{{
813 my $template=template("misc.tmpl");
816 indexlink => indexlink(),
817 wikiname => $config{wikiname},
818 pagebody => $pagebody,
819 baseurl => baseurl(),
822 run_hooks(pagetemplate => sub {
823 shift->(page => "", destpage => "", template => $template);
825 return $template->output;
831 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
832 error "hook requires type, call, and id parameters";
835 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
837 $hooks{$param{type}}{$param{id}}=\%param;
840 sub run_hooks ($$) { # {{{
841 # Calls the given sub for each hook of the given type,
842 # passing it the hook function to call.
846 if (exists $hooks{$type}) {
848 foreach my $id (keys %{$hooks{$type}}) {
849 if ($hooks{$type}{$id}{last}) {
853 $sub->($hooks{$type}{$id}{call});
855 foreach my $id (@deferred) {
856 $sub->($hooks{$type}{$id}{call});
861 sub globlist_to_pagespec ($) { #{{{
862 my @globlist=split(' ', shift);
865 foreach my $glob (@globlist) {
866 if ($glob=~/^!(.*)/) {
874 my $spec=join(" or ", @spec);
876 my $skip=join(" and ", @skip);
878 $spec="$skip and ($spec)";
887 sub is_globlist ($) { #{{{
889 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
892 sub safequote ($) { #{{{
898 sub add_depends ($$) { #{{{
902 if (! exists $depends{$page}) {
903 $depends{$page}=$pagespec;
906 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
910 sub file_pruned ($$) { #{{{
912 my $file=File::Spec->canonpath(shift);
913 my $base=File::Spec->canonpath(shift);
914 $file=~s#^\Q$base\E/*##;
916 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
921 # Only use gettext in the rare cases it's needed.
922 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
923 if (! $gettext_obj) {
925 use Locale::gettext q{textdomain};
926 Locale::gettext->domain('ikiwiki')
934 return $gettext_obj->get(shift);
941 sub pagespec_merge ($$) { #{{{
945 return $a if $a eq $b;
947 # Support for old-style GlobLists.
948 if (is_globlist($a)) {
949 $a=globlist_to_pagespec($a);
951 if (is_globlist($b)) {
952 $b=globlist_to_pagespec($b);
955 return "($a) or ($b)";
958 sub pagespec_translate ($) { #{{{
959 # This assumes that $page is in scope in the function
960 # that evalulates the translated pagespec code.
963 # Support for old-style GlobLists.
964 if (is_globlist($spec)) {
965 $spec=globlist_to_pagespec($spec);
968 # Convert spec to perl code.
970 while ($spec=~m/\s*(\!|\(|\)|\w+\([^\)]+\)|[^\s()]+)\s*/ig) {
972 if (lc $word eq "and") {
975 elsif (lc $word eq "or") {
978 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
981 elsif ($word =~ /^(\w+)\((.*)\)$/) {
982 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
983 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
990 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
997 sub pagespec_match ($$;@) { #{{{
1002 # Backwards compatability with old calling convention.
1004 unshift @params, "location";
1007 my $ret=eval pagespec_translate($spec);
1008 return IkiWiki::FailReason->new("syntax error") if $@;
1012 package IkiWiki::FailReason;
1015 '""' => sub { return ${$_[0]} },
1016 '0+' => sub { return 0 },
1017 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1022 bless \$_[1], $_[0];
1025 package IkiWiki::SuccessReason;
1028 '""' => sub { return ${$_[0]} },
1029 '0+' => sub { return 1 },
1030 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1035 bless \$_[1], $_[0];
1038 package IkiWiki::PageSpec;
1040 sub match_glob ($$;@) { #{{{
1045 my $from=exists $params{location} ? $params{location} : "";
1048 if ($glob =~ m!^\./!) {
1049 $from=~s!/?[^/]+$!!;
1051 $glob="$from/$glob" if length $from;
1054 # turn glob into safe regexp
1055 $glob=quotemeta($glob);
1059 if ($page=~/^$glob$/i) {
1060 return IkiWiki::SuccessReason->new("$glob matches $page");
1063 return IkiWiki::FailReason->new("$glob does not match $page");
1067 sub match_link ($$;@) { #{{{
1072 my $from=exists $params{location} ? $params{location} : "";
1075 if ($link =~ m!^\.! && defined $from) {
1076 $from=~s!/?[^/]+$!!;
1078 $link="$from/$link" if length $from;
1081 my $links = $IkiWiki::links{$page} or return undef;
1082 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1083 my $bestlink = IkiWiki::bestlink($from, $link);
1084 return IkiWiki::FailReason->new("no such link") unless length $bestlink;
1085 foreach my $p (@$links) {
1086 return IkiWiki::SuccessReason->new("$page links to $link")
1087 if $bestlink eq IkiWiki::bestlink($page, $p);
1089 return IkiWiki::FailReason->new("$page does not link to $link");
1092 sub match_backlink ($$;@) { #{{{
1093 match_link($_[1], $_[0], @_);
1096 sub match_created_before ($$;@) { #{{{
1100 if (exists $IkiWiki::pagectime{$testpage}) {
1101 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1102 IkiWiki::SuccessReason->new("$page created before $testpage");
1105 IkiWiki::FailReason->new("$page not created before $testpage");
1109 return IkiWiki::FailReason->new("$testpage has no ctime");
1113 sub match_created_after ($$;@) { #{{{
1117 if (exists $IkiWiki::pagectime{$testpage}) {
1118 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1119 IkiWiki::SuccessReason->new("$page created after $testpage");
1122 IkiWiki::FailReason->new("$page not created after $testpage");
1126 return IkiWiki::FailReason->new("$testpage has no ctime");
1130 sub match_creation_day ($$;@) { #{{{
1131 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1132 return IkiWiki::SuccessReason->new("creation_day matched");
1135 return IkiWiki::FailReason->new("creation_day did not match");
1139 sub match_creation_month ($$;@) { #{{{
1140 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1141 return IkiWiki::SuccessReason->new("creation_month matched");
1144 return IkiWiki::FailReason->new("creation_month did not match");
1148 sub match_creation_year ($$;@) { #{{{
1149 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1150 return IkiWiki::SuccessReason->new("creation_year matched");
1153 return IkiWiki::FailReason->new("creation_year did not match");
1157 sub match_user ($$;@) { #{{{
1162 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1163 if ($user eq $params{user}) {
1164 return IkiWiki::SuccessReason->new("user is $user")
1167 return IkiWiki::FailReason->new("user is not $user");