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?)");
698 sub unlockwiki () { #{{{
702 sub commit_hook_enabled () { #{{{
703 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
704 error ("cannot write to $config{wikistatedir}/commitlock: $!");
705 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
713 sub disable_commit_hook () { #{{{
714 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
715 error ("cannot write to $config{wikistatedir}/commitlock: $!");
716 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
717 error("failed to get commit lock");
721 sub enable_commit_hook () { #{{{
725 sub loadindex () { #{{{
726 open (IN, "$config{wikistatedir}/index") || return;
728 $_=possibly_foolish_untaint($_);
733 foreach my $i (split(/ /, $_)) {
734 my ($item, $val)=split(/=/, $i, 2);
735 push @{$items{$item}}, decode_entities($val);
738 next unless exists $items{src}; # skip bad lines for now
740 my $page=pagename($items{src}[0]);
741 if (! $config{rebuild}) {
742 $pagesources{$page}=$items{src}[0];
743 $pagemtime{$page}=$items{mtime}[0];
744 $oldlinks{$page}=[@{$items{link}}];
745 $links{$page}=[@{$items{link}}];
746 $depends{$page}=$items{depends}[0] if exists $items{depends};
747 $destsources{$_}=$page foreach @{$items{dest}};
748 $renderedfiles{$page}=[@{$items{dest}}];
749 $pagecase{lc $page}=$page;
751 $oldrenderedfiles{$page}=[@{$items{dest}}];
752 $pagectime{$page}=$items{ctime}[0];
757 sub saveindex () { #{{{
758 run_hooks(savestate => sub { shift->() });
760 if (! -d $config{wikistatedir}) {
761 mkdir($config{wikistatedir});
763 my $newfile="$config{wikistatedir}/index.new";
764 my $cleanup = sub { unlink($newfile) };
765 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
766 foreach my $page (keys %pagemtime) {
767 next unless $pagemtime{$page};
768 my $line="mtime=$pagemtime{$page} ".
769 "ctime=$pagectime{$page} ".
770 "src=$pagesources{$page}";
771 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
773 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
774 if (exists $depends{$page}) {
775 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
777 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
779 close OUT || error("failed saving to $newfile: $!", $cleanup);
780 rename($newfile, "$config{wikistatedir}/index") ||
781 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
784 sub template_file ($) { #{{{
787 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
788 return "$dir/$template" if -e "$dir/$template";
793 sub template_params (@) { #{{{
794 my $filename=template_file(shift);
796 if (! defined $filename) {
801 require HTML::Template;
804 my $text_ref = shift;
805 $$text_ref=&Encode::decode_utf8($$text_ref);
807 filename => $filename,
808 loop_context_vars => 1,
809 die_on_bad_params => 0,
812 return wantarray ? @ret : {@ret};
815 sub template ($;@) { #{{{
816 HTML::Template->new(template_params(@_));
819 sub misctemplate ($$;@) { #{{{
823 my $template=template("misc.tmpl");
826 indexlink => indexlink(),
827 wikiname => $config{wikiname},
828 pagebody => $pagebody,
829 baseurl => baseurl(),
832 run_hooks(pagetemplate => sub {
833 shift->(page => "", destpage => "", template => $template);
835 return $template->output;
841 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
842 error "hook requires type, call, and id parameters";
845 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
847 $hooks{$param{type}}{$param{id}}=\%param;
850 sub run_hooks ($$) { # {{{
851 # Calls the given sub for each hook of the given type,
852 # passing it the hook function to call.
856 if (exists $hooks{$type}) {
858 foreach my $id (keys %{$hooks{$type}}) {
859 if ($hooks{$type}{$id}{last}) {
863 $sub->($hooks{$type}{$id}{call});
865 foreach my $id (@deferred) {
866 $sub->($hooks{$type}{$id}{call});
871 sub globlist_to_pagespec ($) { #{{{
872 my @globlist=split(' ', shift);
875 foreach my $glob (@globlist) {
876 if ($glob=~/^!(.*)/) {
884 my $spec=join(" or ", @spec);
886 my $skip=join(" and ", @skip);
888 $spec="$skip and ($spec)";
897 sub is_globlist ($) { #{{{
899 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
902 sub safequote ($) { #{{{
908 sub add_depends ($$) { #{{{
912 if (! exists $depends{$page}) {
913 $depends{$page}=$pagespec;
916 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
920 sub file_pruned ($$) { #{{{
922 my $file=File::Spec->canonpath(shift);
923 my $base=File::Spec->canonpath(shift);
924 $file=~s#^\Q$base\E/*##;
926 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
931 # Only use gettext in the rare cases it's needed.
932 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
933 if (! $gettext_obj) {
935 use Locale::gettext q{textdomain};
936 Locale::gettext->domain('ikiwiki')
944 return $gettext_obj->get(shift);
951 sub pagespec_merge ($$) { #{{{
955 return $a if $a eq $b;
957 # Support for old-style GlobLists.
958 if (is_globlist($a)) {
959 $a=globlist_to_pagespec($a);
961 if (is_globlist($b)) {
962 $b=globlist_to_pagespec($b);
965 return "($a) or ($b)";
968 sub pagespec_translate ($) { #{{{
969 # This assumes that $page is in scope in the function
970 # that evalulates the translated pagespec code.
973 # Support for old-style GlobLists.
974 if (is_globlist($spec)) {
975 $spec=globlist_to_pagespec($spec);
978 # Convert spec to perl code.
980 while ($spec=~m/\s*(\!|\(|\)|\w+\([^\)]+\)|[^\s()]+)\s*/ig) {
982 if (lc $word eq "and") {
985 elsif (lc $word eq "or") {
988 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
991 elsif ($word =~ /^(\w+)\((.*)\)$/) {
992 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
993 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
1000 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
1007 sub pagespec_match ($$;@) { #{{{
1012 # Backwards compatability with old calling convention.
1014 unshift @params, "location";
1017 my $ret=eval pagespec_translate($spec);
1018 return IkiWiki::FailReason->new("syntax error") if $@;
1022 package IkiWiki::FailReason;
1025 '""' => sub { ${$_[0]} },
1027 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1032 bless \$_[1], $_[0];
1035 package IkiWiki::SuccessReason;
1038 '""' => sub { ${$_[0]} },
1040 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1045 bless \$_[1], $_[0];
1048 package IkiWiki::PageSpec;
1050 sub match_glob ($$;@) { #{{{
1055 my $from=exists $params{location} ? $params{location} : "";
1058 if ($glob =~ m!^\./!) {
1059 $from=~s!/?[^/]+$!!;
1061 $glob="$from/$glob" if length $from;
1064 # turn glob into safe regexp
1065 $glob=quotemeta($glob);
1069 if ($page=~/^$glob$/i) {
1070 return IkiWiki::SuccessReason->new("$glob matches $page");
1073 return IkiWiki::FailReason->new("$glob does not match $page");
1077 sub match_link ($$;@) { #{{{
1082 my $from=exists $params{location} ? $params{location} : "";
1085 if ($link =~ m!^\.! && defined $from) {
1086 $from=~s!/?[^/]+$!!;
1088 $link="$from/$link" if length $from;
1091 my $links = $IkiWiki::links{$page} or return undef;
1092 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1093 my $bestlink = IkiWiki::bestlink($from, $link);
1094 return IkiWiki::FailReason->new("no such link") unless length $bestlink;
1095 foreach my $p (@$links) {
1096 return IkiWiki::SuccessReason->new("$page links to $link")
1097 if $bestlink eq IkiWiki::bestlink($page, $p);
1099 return IkiWiki::FailReason->new("$page does not link to $link");
1102 sub match_backlink ($$;@) { #{{{
1103 match_link($_[1], $_[0], @_);
1106 sub match_created_before ($$;@) { #{{{
1110 if (exists $IkiWiki::pagectime{$testpage}) {
1111 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1112 IkiWiki::SuccessReason->new("$page created before $testpage");
1115 IkiWiki::FailReason->new("$page not created before $testpage");
1119 return IkiWiki::FailReason->new("$testpage has no ctime");
1123 sub match_created_after ($$;@) { #{{{
1127 if (exists $IkiWiki::pagectime{$testpage}) {
1128 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1129 IkiWiki::SuccessReason->new("$page created after $testpage");
1132 IkiWiki::FailReason->new("$page not created after $testpage");
1136 return IkiWiki::FailReason->new("$testpage has no ctime");
1140 sub match_creation_day ($$;@) { #{{{
1141 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1142 return IkiWiki::SuccessReason->new("creation_day matched");
1145 return IkiWiki::FailReason->new("creation_day did not match");
1149 sub match_creation_month ($$;@) { #{{{
1150 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1151 return IkiWiki::SuccessReason->new("creation_month matched");
1154 return IkiWiki::FailReason->new("creation_month did not match");
1158 sub match_creation_year ($$;@) { #{{{
1159 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1160 return IkiWiki::SuccessReason->new("creation_year matched");
1163 return IkiWiki::FailReason->new("creation_year did not match");
1167 sub match_user ($$;@) { #{{{
1172 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1173 if ($user eq $params{user}) {
1174 return IkiWiki::SuccessReason->new("user is $user")
1177 return IkiWiki::FailReason->new("user is not $user");