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{
37 \[\[ # beginning of link
39 ([^\]\|]+) # 1: link text
43 ([^\s\]#]+) # 2: page to link to
45 \# # '#', beginning of anchor
46 ([^\s\]]+) # 3: anchor text
51 wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
52 web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
56 default_pageext => "mdwn",
77 gitorigin_branch => "origin",
78 gitmaster_branch => "master",
82 templatedir => "$installdir/share/ikiwiki/templates",
83 underlaydir => "$installdir/share/ikiwiki/basewiki",
87 plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
88 lockedit conditional}],
96 account_creation_password => "",
99 sub checkconfig () { #{{{
100 # locale stuff; avoid LC_ALL since it overrides everything
101 if (defined $ENV{LC_ALL}) {
102 $ENV{LANG} = $ENV{LC_ALL};
105 if (defined $config{locale}) {
106 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
107 $ENV{LANG}=$config{locale};
112 if ($config{w3mmode}) {
113 eval q{use Cwd q{abs_path}};
115 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
116 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
117 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
118 unless $config{cgiurl} =~ m!file:///!;
119 $config{url}="file://".$config{destdir};
122 if ($config{cgi} && ! length $config{url}) {
123 error(gettext("Must specify url to wiki with --url when using --cgi"));
126 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
127 unless exists $config{wikistatedir};
130 eval qq{use IkiWiki::Rcs::$config{rcs}};
132 error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
136 require IkiWiki::Rcs::Stub;
139 run_hooks(checkconfig => sub { shift->() });
142 sub loadplugins () { #{{{
143 loadplugin($_) foreach @{$config{plugin}};
145 run_hooks(getopt => sub { shift->() });
146 if (grep /^-/, @ARGV) {
147 print STDERR "Unknown option: $_\n"
148 foreach grep /^-/, @ARGV;
153 sub loadplugin ($) { #{{{
156 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
158 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
161 error("Failed to load plugin $mod: $@");
165 sub error ($;$) { #{{{
169 print "Content-type: text/html\n\n";
170 print misctemplate(gettext("Error"),
171 "<p>".gettext("Error").": $message</p>");
173 log_message('err' => $message) if $config{syslog};
174 if (defined $cleaner) {
181 return unless $config{verbose};
182 log_message(debug => @_);
186 sub log_message ($$) { #{{{
189 if ($config{syslog}) {
192 Sys::Syslog::setlogsock('unix');
193 Sys::Syslog::openlog('ikiwiki', '', 'user');
197 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
200 elsif (! $config{cgi}) {
208 sub possibly_foolish_untaint ($) { #{{{
210 my ($untainted)=$tainted=~/(.*)/s;
214 sub basename ($) { #{{{
221 sub dirname ($) { #{{{
228 sub pagetype ($) { #{{{
231 if ($page =~ /\.([^.]+)$/) {
232 return $1 if exists $hooks{htmlize}{$1};
237 sub pagename ($) { #{{{
240 my $type=pagetype($file);
242 $page=~s/\Q.$type\E*$// if defined $type;
246 sub targetpage ($$) { #{{{
250 if (! $config{usedirs} || $page =~ /^index$/ ) {
251 return $page.".".$ext;
253 return $page."/index.".$ext;
257 sub htmlpage ($) { #{{{
260 return targetpage($page, $config{htmlext});
263 sub srcfile ($) { #{{{
266 return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
267 return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
268 error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
271 sub readfile ($;$$) { #{{{
277 error("cannot read a symlink ($file)");
281 open (IN, $file) || error("failed to read $file: $!");
282 binmode(IN) if ($binary);
283 return \*IN if $wantfd;
285 close IN || error("failed to read $file: $!");
289 sub writefile ($$$;$$) { #{{{
290 my $file=shift; # can include subdirs
291 my $destdir=shift; # directory to put file in
297 while (length $test) {
298 if (-l "$destdir/$test") {
299 error("cannot write to a symlink ($test)");
301 $test=dirname($test);
303 my $newfile="$destdir/$file.ikiwiki-new";
305 error("cannot write to a symlink ($newfile)");
308 my $dir=dirname($newfile);
311 foreach my $s (split(m!/+!, $dir)) {
314 mkdir($d) || error("failed to create directory $d: $!");
319 my $cleanup = sub { unlink($newfile) };
320 open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup);
321 binmode(OUT) if ($binary);
323 $writer->(\*OUT, $cleanup);
326 print OUT $content or error("failed writing to $newfile: $!", $cleanup);
328 close OUT || error("failed saving $newfile: $!", $cleanup);
329 rename($newfile, "$destdir/$file") ||
330 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
334 sub will_render ($$;$) { #{{{
339 # Important security check.
340 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
341 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
342 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
345 if (! $clear || $cleared{$page}) {
346 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
349 foreach my $old (@{$renderedfiles{$page}}) {
350 delete $destsources{$old};
352 $renderedfiles{$page}=[$dest];
355 $destsources{$dest}=$page;
358 sub bestlink ($$) { #{{{
363 if ($link=~s/^\/+//) {
370 $l.="/" if length $l;
373 if (exists $links{$l}) {
376 elsif (exists $pagecase{lc $l}) {
377 return $pagecase{lc $l};
379 } while $cwd=~s!/?[^/]+$!!;
381 if (length $config{userdir}) {
382 my $l = "$config{userdir}/".lc($link);
383 if (exists $links{$l}) {
386 elsif (exists $pagecase{lc $l}) {
387 return $pagecase{lc $l};
391 #print STDERR "warning: page $page, broken link: $link\n";
395 sub isinlinableimage ($) { #{{{
398 $file=~/\.(png|gif|jpg|jpeg)$/i;
401 sub pagetitle ($;$) { #{{{
406 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
409 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
415 sub titlepage ($) { #{{{
417 $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
421 sub linkpage ($) { #{{{
423 $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
427 sub cgiurl (@) { #{{{
430 return $config{cgiurl}."?".
431 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
434 sub baseurl (;$) { #{{{
437 return "$config{url}/" if ! defined $page;
439 $page=htmlpage($page);
441 $page=~s/[^\/]+\//..\//g;
445 sub abs2rel ($$) { #{{{
446 # Work around very innefficient behavior in File::Spec if abs2rel
447 # is passed two relative paths. It's much faster if paths are
448 # absolute! (Debian bug #376658; fixed in debian unstable now)
453 my $ret=File::Spec->abs2rel($path, $base);
454 $ret=~s/^// if defined $ret;
458 sub displaytime ($) { #{{{
461 # strftime doesn't know about encodings, so make sure
462 # its output is properly treated as utf8
463 return decode_utf8(POSIX::strftime(
464 $config{timeformat}, localtime($time)));
467 sub beautify_url ($) { #{{{
470 $url =~ s!/index.$config{htmlext}$!/!;
471 $url =~ s!^$!./!; # Browsers don't like empty links...
476 sub urlto ($$) { #{{{
481 return beautify_url(baseurl($from));
484 if (! $destsources{$to}) {
488 my $link = abs2rel($to, dirname(htmlpage($from)));
490 return beautify_url($link);
493 sub htmllink ($$$;@) { #{{{
494 my $lpage=shift; # the page doing the linking
495 my $page=shift; # the page that will contain the link (different for inline)
500 if (! $opts{forcesubpage}) {
501 $bestlink=bestlink($lpage, $link);
504 $bestlink="$lpage/".lc($link);
508 if (defined $opts{linktext}) {
509 $linktext=$opts{linktext};
512 $linktext=pagetitle(basename($link));
515 return "<span class=\"selflink\">$linktext</span>"
516 if length $bestlink && $page eq $bestlink;
518 if (! $destsources{$bestlink}) {
519 $bestlink=htmlpage($bestlink);
521 if (! $destsources{$bestlink}) {
522 return $linktext unless length $config{cgiurl};
523 return "<span><a href=\"".
526 page => pagetitle(lc($link), 1),
529 "\">?</a>$linktext</span>"
533 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
534 $bestlink=beautify_url($bestlink);
536 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
537 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
540 if (defined $opts{anchor}) {
541 $bestlink.="#".$opts{anchor};
544 return "<a href=\"$bestlink\">$linktext</a>";
547 sub htmlize ($$$) { #{{{
552 if (exists $hooks{htmlize}{$type}) {
553 $content=$hooks{htmlize}{$type}{call}->(
559 error("htmlization of $type not supported");
562 run_hooks(sanitize => sub {
572 sub linkify ($$$) { #{{{
573 my $lpage=shift; # the page containing the links
574 my $page=shift; # the page the link will end up on (different for inline)
577 $content =~ s{(\\?)$config{wiki_link_regexp}}{
580 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
581 : htmllink($lpage, $page, linkpage($3),
582 anchor => $4, linktext => pagetitle($2)))
584 ? "[[$3".($4 ? "#$4" : "")."]]"
585 : htmllink($lpage, $page, linkpage($3),
593 our $preprocess_preview=0;
594 sub preprocess ($$$;$$) { #{{{
595 my $page=shift; # the page the data comes from
596 my $destpage=shift; # the page the data will appear in (different for inline)
601 # Using local because it needs to be set within any nested calls
603 local $preprocess_preview=$preview if defined $preview;
609 if (length $escape) {
610 return "\\[[$command $params]]";
612 elsif (exists $hooks{preprocess}{$command}) {
613 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
614 # Note: preserve order of params, some plugins may
615 # consider it significant.
618 (?:(\w+)=)? # 1: named parameter key?
620 """(.*?)""" # 2: triple-quoted value
622 "([^"]+)" # 3: single-quoted value
624 (\S+) # 4: unquoted value
626 (?:\s+|$) # delimiter to next param
644 push @params, $key, $val;
647 push @params, $val, '';
650 if ($preprocessing{$page}++ > 3) {
651 # Avoid loops of preprocessed pages preprocessing
652 # other pages that preprocess them, etc.
653 #translators: The first parameter is a
654 #translators: preprocessor directive name,
655 #translators: the second a page name, the
656 #translators: third a number.
657 return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
658 $command, $page, $preprocessing{$page}).
661 my $ret=$hooks{preprocess}{$command}{call}->(
664 destpage => $destpage,
665 preview => $preprocess_preview,
667 $preprocessing{$page}--;
671 return "\\[[$command $params]]";
677 \[\[ # directive open
680 ( # 3: the parameters..
682 (?:\w+=)? # named parameter key?
684 """.*?""" # triple-quoted value
686 "[^"]+" # single-quoted value
688 [^\s\]]+ # unquoted value
690 \s* # whitespace or end
693 *) # 0 or more parameters
694 \]\] # directive closed
695 }{$handle->($1, $2, $3)}sexg;
699 sub filter ($$$) { #{{{
704 run_hooks(filter => sub {
705 $content=shift->(page => $page, destpage => $destpage,
706 content => $content);
712 sub indexlink () { #{{{
713 return "<a href=\"$config{url}\">$config{wikiname}</a>";
716 sub lockwiki (;$) { #{{{
717 my $wait=@_ ? shift : 1;
718 # Take an exclusive lock on the wiki to prevent multiple concurrent
719 # run issues. The lock will be dropped on program exit.
720 if (! -d $config{wikistatedir}) {
721 mkdir($config{wikistatedir});
723 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
724 error ("cannot write to $config{wikistatedir}/lockfile: $!");
725 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
727 debug("wiki seems to be locked, waiting for lock");
728 my $wait=600; # arbitrary, but don't hang forever to
729 # prevent process pileup
731 return if flock(WIKILOCK, 2 | 4);
734 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
743 sub unlockwiki () { #{{{
747 sub commit_hook_enabled () { #{{{
748 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
749 error ("cannot write to $config{wikistatedir}/commitlock: $!");
750 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
758 sub disable_commit_hook () { #{{{
759 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
760 error ("cannot write to $config{wikistatedir}/commitlock: $!");
761 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
762 error("failed to get commit lock");
766 sub enable_commit_hook () { #{{{
770 sub loadindex () { #{{{
771 open (IN, "$config{wikistatedir}/index") || return;
773 $_=possibly_foolish_untaint($_);
778 foreach my $i (split(/ /, $_)) {
779 my ($item, $val)=split(/=/, $i, 2);
780 push @{$items{$item}}, decode_entities($val);
783 next unless exists $items{src}; # skip bad lines for now
785 my $page=pagename($items{src}[0]);
786 if (! $config{rebuild}) {
787 $pagesources{$page}=$items{src}[0];
788 $pagemtime{$page}=$items{mtime}[0];
789 $oldlinks{$page}=[@{$items{link}}];
790 $links{$page}=[@{$items{link}}];
791 $depends{$page}=$items{depends}[0] if exists $items{depends};
792 $destsources{$_}=$page foreach @{$items{dest}};
793 $renderedfiles{$page}=[@{$items{dest}}];
794 $pagecase{lc $page}=$page;
796 $oldrenderedfiles{$page}=[@{$items{dest}}];
797 $pagectime{$page}=$items{ctime}[0];
802 sub saveindex () { #{{{
803 run_hooks(savestate => sub { shift->() });
805 if (! -d $config{wikistatedir}) {
806 mkdir($config{wikistatedir});
808 my $newfile="$config{wikistatedir}/index.new";
809 my $cleanup = sub { unlink($newfile) };
810 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
811 foreach my $page (keys %pagemtime) {
812 next unless $pagemtime{$page};
813 my $line="mtime=$pagemtime{$page} ".
814 "ctime=$pagectime{$page} ".
815 "src=$pagesources{$page}";
816 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
818 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
819 if (exists $depends{$page}) {
820 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
822 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
824 close OUT || error("failed saving to $newfile: $!", $cleanup);
825 rename($newfile, "$config{wikistatedir}/index") ||
826 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
829 sub template_file ($) { #{{{
832 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
833 return "$dir/$template" if -e "$dir/$template";
838 sub template_params (@) { #{{{
839 my $filename=template_file(shift);
841 if (! defined $filename) {
848 my $text_ref = shift;
849 $$text_ref=&Encode::decode_utf8($$text_ref);
851 filename => $filename,
852 loop_context_vars => 1,
853 die_on_bad_params => 0,
856 return wantarray ? @ret : {@ret};
859 sub template ($;@) { #{{{
860 require HTML::Template;
861 HTML::Template->new(template_params(@_));
864 sub misctemplate ($$;@) { #{{{
868 my $template=template("misc.tmpl");
871 indexlink => indexlink(),
872 wikiname => $config{wikiname},
873 pagebody => $pagebody,
874 baseurl => baseurl(),
877 run_hooks(pagetemplate => sub {
878 shift->(page => "", destpage => "", template => $template);
880 return $template->output;
886 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
887 error "hook requires type, call, and id parameters";
890 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
892 $hooks{$param{type}}{$param{id}}=\%param;
895 sub run_hooks ($$) { # {{{
896 # Calls the given sub for each hook of the given type,
897 # passing it the hook function to call.
901 if (exists $hooks{$type}) {
903 foreach my $id (keys %{$hooks{$type}}) {
904 if ($hooks{$type}{$id}{last}) {
908 $sub->($hooks{$type}{$id}{call});
910 foreach my $id (@deferred) {
911 $sub->($hooks{$type}{$id}{call});
916 sub globlist_to_pagespec ($) { #{{{
917 my @globlist=split(' ', shift);
920 foreach my $glob (@globlist) {
921 if ($glob=~/^!(.*)/) {
929 my $spec=join(" or ", @spec);
931 my $skip=join(" and ", @skip);
933 $spec="$skip and ($spec)";
942 sub is_globlist ($) { #{{{
944 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
947 sub safequote ($) { #{{{
953 sub add_depends ($$) { #{{{
957 if (! exists $depends{$page}) {
958 $depends{$page}=$pagespec;
961 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
965 sub file_pruned ($$) { #{{{
967 my $file=File::Spec->canonpath(shift);
968 my $base=File::Spec->canonpath(shift);
969 $file=~s#^\Q$base\E/*##;
971 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
976 # Only use gettext in the rare cases it's needed.
977 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
978 if (! $gettext_obj) {
980 use Locale::gettext q{textdomain};
981 Locale::gettext->domain('ikiwiki')
989 return $gettext_obj->get(shift);
996 sub pagespec_merge ($$) { #{{{
1000 return $a if $a eq $b;
1002 # Support for old-style GlobLists.
1003 if (is_globlist($a)) {
1004 $a=globlist_to_pagespec($a);
1006 if (is_globlist($b)) {
1007 $b=globlist_to_pagespec($b);
1010 return "($a) or ($b)";
1013 sub pagespec_translate ($) { #{{{
1014 # This assumes that $page is in scope in the function
1015 # that evalulates the translated pagespec code.
1018 # Support for old-style GlobLists.
1019 if (is_globlist($spec)) {
1020 $spec=globlist_to_pagespec($spec);
1023 # Convert spec to perl code.
1026 \s* # ignore whitespace
1027 ( # 1: match a single word
1034 \w+\([^\)]+\) # command(params)
1036 [^\s()]+ # any other text
1038 \s* # ignore whitespace
1041 if (lc $word eq "and") {
1044 elsif (lc $word eq "or") {
1047 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
1050 elsif ($word =~ /^(\w+)\((.*)\)$/) {
1051 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
1052 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
1059 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
1066 sub pagespec_match ($$;@) { #{{{
1071 # Backwards compatability with old calling convention.
1073 unshift @params, "location";
1076 my $ret=eval pagespec_translate($spec);
1077 return IkiWiki::FailReason->new("syntax error") if $@;
1081 package IkiWiki::FailReason;
1084 '""' => sub { ${$_[0]} },
1086 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1091 bless \$_[1], $_[0];
1094 package IkiWiki::SuccessReason;
1097 '""' => sub { ${$_[0]} },
1099 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1104 bless \$_[1], $_[0];
1107 package IkiWiki::PageSpec;
1109 sub match_glob ($$;@) { #{{{
1114 my $from=exists $params{location} ? $params{location} : "";
1117 if ($glob =~ m!^\./!) {
1118 $from=~s#/?[^/]+$##;
1120 $glob="$from/$glob" if length $from;
1123 # turn glob into safe regexp
1124 $glob=quotemeta($glob);
1128 if ($page=~/^$glob$/i) {
1129 return IkiWiki::SuccessReason->new("$glob matches $page");
1132 return IkiWiki::FailReason->new("$glob does not match $page");
1136 sub match_link ($$;@) { #{{{
1141 my $from=exists $params{location} ? $params{location} : "";
1144 if ($link =~ m!^\.! && defined $from) {
1145 $from=~s#/?[^/]+$##;
1147 $link="$from/$link" if length $from;
1150 my $links = $IkiWiki::links{$page} or return undef;
1151 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1152 my $bestlink = IkiWiki::bestlink($from, $link);
1153 foreach my $p (@$links) {
1154 if (length $bestlink) {
1155 return IkiWiki::SuccessReason->new("$page links to $link")
1156 if $bestlink eq IkiWiki::bestlink($page, $p);
1159 return IkiWiki::SuccessReason->new("$page links to page matching $link")
1160 if match_glob($p, $link, %params);
1163 return IkiWiki::FailReason->new("$page does not link to $link");
1166 sub match_backlink ($$;@) { #{{{
1167 match_link($_[1], $_[0], @_);
1170 sub match_created_before ($$;@) { #{{{
1174 if (exists $IkiWiki::pagectime{$testpage}) {
1175 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1176 IkiWiki::SuccessReason->new("$page created before $testpage");
1179 IkiWiki::FailReason->new("$page not created before $testpage");
1183 return IkiWiki::FailReason->new("$testpage has no ctime");
1187 sub match_created_after ($$;@) { #{{{
1191 if (exists $IkiWiki::pagectime{$testpage}) {
1192 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1193 IkiWiki::SuccessReason->new("$page created after $testpage");
1196 IkiWiki::FailReason->new("$page not created after $testpage");
1200 return IkiWiki::FailReason->new("$testpage has no ctime");
1204 sub match_creation_day ($$;@) { #{{{
1205 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1206 return IkiWiki::SuccessReason->new("creation_day matched");
1209 return IkiWiki::FailReason->new("creation_day did not match");
1213 sub match_creation_month ($$;@) { #{{{
1214 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1215 return IkiWiki::SuccessReason->new("creation_month matched");
1218 return IkiWiki::FailReason->new("creation_month did not match");
1222 sub match_creation_year ($$;@) { #{{{
1223 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1224 return IkiWiki::SuccessReason->new("creation_year matched");
1227 return IkiWiki::FailReason->new("creation_year did not match");
1231 sub match_user ($$;@) { #{{{
1236 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1237 if ($user eq $params{user}) {
1238 return IkiWiki::SuccessReason->new("user is $user")
1241 return IkiWiki::FailReason->new("user is not $user");