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 ($$) { #{{{
658 run_hooks(filter => sub {
659 $content=shift->(page => $page, content => $content);
665 sub indexlink () { #{{{
666 return "<a href=\"$config{url}\">$config{wikiname}</a>";
669 sub lockwiki () { #{{{
670 # Take an exclusive lock on the wiki to prevent multiple concurrent
671 # run issues. The lock will be dropped on program exit.
672 if (! -d $config{wikistatedir}) {
673 mkdir($config{wikistatedir});
675 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
676 error ("cannot write to $config{wikistatedir}/lockfile: $!");
677 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
678 debug("wiki seems to be locked, waiting for lock");
679 my $wait=600; # arbitrary, but don't hang forever to
680 # prevent process pileup
682 return if flock(WIKILOCK, 2 | 4);
685 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
689 sub unlockwiki () { #{{{
693 sub commit_hook_enabled () { #{{{
694 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
695 error ("cannot write to $config{wikistatedir}/commitlock: $!");
696 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
704 sub disable_commit_hook () { #{{{
705 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
706 error ("cannot write to $config{wikistatedir}/commitlock: $!");
707 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
708 error("failed to get commit lock");
712 sub enable_commit_hook () { #{{{
716 sub loadindex () { #{{{
717 open (IN, "$config{wikistatedir}/index") || return;
719 $_=possibly_foolish_untaint($_);
724 foreach my $i (split(/ /, $_)) {
725 my ($item, $val)=split(/=/, $i, 2);
726 push @{$items{$item}}, decode_entities($val);
729 next unless exists $items{src}; # skip bad lines for now
731 my $page=pagename($items{src}[0]);
732 if (! $config{rebuild}) {
733 $pagesources{$page}=$items{src}[0];
734 $pagemtime{$page}=$items{mtime}[0];
735 $oldlinks{$page}=[@{$items{link}}];
736 $links{$page}=[@{$items{link}}];
737 $depends{$page}=$items{depends}[0] if exists $items{depends};
738 $destsources{$_}=$page foreach @{$items{dest}};
739 $renderedfiles{$page}=[@{$items{dest}}];
740 $oldrenderedfiles{$page}=[@{$items{dest}}];
741 $pagecase{lc $page}=$page;
743 $pagectime{$page}=$items{ctime}[0];
748 sub saveindex () { #{{{
749 run_hooks(savestate => sub { shift->() });
751 if (! -d $config{wikistatedir}) {
752 mkdir($config{wikistatedir});
754 my $newfile="$config{wikistatedir}/index.new";
755 my $cleanup = sub { unlink($newfile) };
756 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
757 foreach my $page (keys %pagemtime) {
758 next unless $pagemtime{$page};
759 my $line="mtime=$pagemtime{$page} ".
760 "ctime=$pagectime{$page} ".
761 "src=$pagesources{$page}";
762 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
764 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
765 if (exists $depends{$page}) {
766 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
768 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
770 close OUT || error("failed saving to $newfile: $!", $cleanup);
771 rename($newfile, "$config{wikistatedir}/index") ||
772 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
775 sub template_file ($) { #{{{
778 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
779 return "$dir/$template" if -e "$dir/$template";
784 sub template_params (@) { #{{{
785 my $filename=template_file(shift);
787 if (! defined $filename) {
792 require HTML::Template;
795 my $text_ref = shift;
796 $$text_ref=&Encode::decode_utf8($$text_ref);
798 filename => $filename,
799 loop_context_vars => 1,
800 die_on_bad_params => 0,
803 return wantarray ? @ret : {@ret};
806 sub template ($;@) { #{{{
807 HTML::Template->new(template_params(@_));
810 sub misctemplate ($$;@) { #{{{
814 my $template=template("misc.tmpl");
817 indexlink => indexlink(),
818 wikiname => $config{wikiname},
819 pagebody => $pagebody,
820 baseurl => baseurl(),
823 run_hooks(pagetemplate => sub {
824 shift->(page => "", destpage => "", template => $template);
826 return $template->output;
832 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
833 error "hook requires type, call, and id parameters";
836 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
838 $hooks{$param{type}}{$param{id}}=\%param;
841 sub run_hooks ($$) { # {{{
842 # Calls the given sub for each hook of the given type,
843 # passing it the hook function to call.
847 if (exists $hooks{$type}) {
849 foreach my $id (keys %{$hooks{$type}}) {
850 if ($hooks{$type}{$id}{last}) {
854 $sub->($hooks{$type}{$id}{call});
856 foreach my $id (@deferred) {
857 $sub->($hooks{$type}{$id}{call});
862 sub globlist_to_pagespec ($) { #{{{
863 my @globlist=split(' ', shift);
866 foreach my $glob (@globlist) {
867 if ($glob=~/^!(.*)/) {
875 my $spec=join(" or ", @spec);
877 my $skip=join(" and ", @skip);
879 $spec="$skip and ($spec)";
888 sub is_globlist ($) { #{{{
890 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
893 sub safequote ($) { #{{{
899 sub add_depends ($$) { #{{{
903 if (! exists $depends{$page}) {
904 $depends{$page}=$pagespec;
907 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
911 sub file_pruned ($$) { #{{{
913 my $file=File::Spec->canonpath(shift);
914 my $base=File::Spec->canonpath(shift);
915 $file=~s#^\Q$base\E/*##;
917 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
922 # Only use gettext in the rare cases it's needed.
923 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
924 if (! $gettext_obj) {
926 use Locale::gettext q{textdomain};
927 Locale::gettext->domain('ikiwiki')
935 return $gettext_obj->get(shift);
942 sub pagespec_merge ($$) { #{{{
946 return $a if $a eq $b;
948 # Support for old-style GlobLists.
949 if (is_globlist($a)) {
950 $a=globlist_to_pagespec($a);
952 if (is_globlist($b)) {
953 $b=globlist_to_pagespec($b);
956 return "($a) or ($b)";
959 sub pagespec_translate ($) { #{{{
960 # This assumes that $page is in scope in the function
961 # that evalulates the translated pagespec code.
964 # Support for old-style GlobLists.
965 if (is_globlist($spec)) {
966 $spec=globlist_to_pagespec($spec);
969 # Convert spec to perl code.
971 while ($spec=~m/\s*(\!|\(|\)|\w+\([^\)]+\)|[^\s()]+)\s*/ig) {
973 if (lc $word eq "and") {
976 elsif (lc $word eq "or") {
979 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
982 elsif ($word =~ /^(\w+)\((.*)\)$/) {
983 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
984 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
991 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
998 sub pagespec_match ($$;@) { #{{{
1003 # Backwards compatability with old calling convention.
1005 unshift @params, "location";
1008 my $ret=eval pagespec_translate($spec);
1009 return IkiWiki::FailReason->new("syntax error") if $@;
1013 package IkiWiki::FailReason;
1016 '""' => sub { ${$_[0]} },
1018 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1023 bless \$_[1], $_[0];
1026 package IkiWiki::SuccessReason;
1029 '""' => sub { ${$_[0]} },
1031 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1036 bless \$_[1], $_[0];
1039 package IkiWiki::PageSpec;
1041 sub match_glob ($$;@) { #{{{
1046 my $from=exists $params{location} ? $params{location} : "";
1049 if ($glob =~ m!^\./!) {
1050 $from=~s!/?[^/]+$!!;
1052 $glob="$from/$glob" if length $from;
1055 # turn glob into safe regexp
1056 $glob=quotemeta($glob);
1060 if ($page=~/^$glob$/i) {
1061 return IkiWiki::SuccessReason->new("$glob matches $page");
1064 return IkiWiki::FailReason->new("$glob does not match $page");
1068 sub match_link ($$;@) { #{{{
1073 my $from=exists $params{location} ? $params{location} : "";
1076 if ($link =~ m!^\.! && defined $from) {
1077 $from=~s!/?[^/]+$!!;
1079 $link="$from/$link" if length $from;
1082 my $links = $IkiWiki::links{$page} or return undef;
1083 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1084 my $bestlink = IkiWiki::bestlink($from, $link);
1085 return IkiWiki::FailReason->new("no such link") unless length $bestlink;
1086 foreach my $p (@$links) {
1087 return IkiWiki::SuccessReason->new("$page links to $link")
1088 if $bestlink eq IkiWiki::bestlink($page, $p);
1090 return IkiWiki::FailReason->new("$page does not link to $link");
1093 sub match_backlink ($$;@) { #{{{
1094 match_link($_[1], $_[0], @_);
1097 sub match_created_before ($$;@) { #{{{
1101 if (exists $IkiWiki::pagectime{$testpage}) {
1102 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1103 IkiWiki::SuccessReason->new("$page created before $testpage");
1106 IkiWiki::FailReason->new("$page not created before $testpage");
1110 return IkiWiki::FailReason->new("$testpage has no ctime");
1114 sub match_created_after ($$;@) { #{{{
1118 if (exists $IkiWiki::pagectime{$testpage}) {
1119 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1120 IkiWiki::SuccessReason->new("$page created after $testpage");
1123 IkiWiki::FailReason->new("$page not created after $testpage");
1127 return IkiWiki::FailReason->new("$testpage has no ctime");
1131 sub match_creation_day ($$;@) { #{{{
1132 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1133 return IkiWiki::SuccessReason->new("creation_day matched");
1136 return IkiWiki::FailReason->new("creation_day did not match");
1140 sub match_creation_month ($$;@) { #{{{
1141 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1142 return IkiWiki::SuccessReason->new("creation_month matched");
1145 return IkiWiki::FailReason->new("creation_month did not match");
1149 sub match_creation_year ($$;@) { #{{{
1150 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1151 return IkiWiki::SuccessReason->new("creation_year matched");
1154 return IkiWiki::FailReason->new("creation_year did not match");
1158 sub match_user ($$;@) { #{{{
1163 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1164 if ($user eq $params{user}) {
1165 return IkiWiki::SuccessReason->new("user is $user")
1168 return IkiWiki::FailReason->new("user is not $user");