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}],
97 account_creation_password => "",
100 sub checkconfig () { #{{{
101 # locale stuff; avoid LC_ALL since it overrides everything
102 if (defined $ENV{LC_ALL}) {
103 $ENV{LANG} = $ENV{LC_ALL};
106 if (defined $config{locale}) {
107 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
108 $ENV{LANG}=$config{locale};
113 if ($config{w3mmode}) {
114 eval q{use Cwd q{abs_path}};
116 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
117 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
118 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
119 unless $config{cgiurl} =~ m!file:///!;
120 $config{url}="file://".$config{destdir};
123 if ($config{cgi} && ! length $config{url}) {
124 error(gettext("Must specify url to wiki with --url when using --cgi"));
127 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
128 unless exists $config{wikistatedir};
131 eval qq{use IkiWiki::Rcs::$config{rcs}};
133 error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
137 require IkiWiki::Rcs::Stub;
140 run_hooks(checkconfig => sub { shift->() });
143 sub loadplugins () { #{{{
144 if (defined $config{libdir}) {
145 unshift @INC, $config{libdir};
148 loadplugin($_) foreach @{$config{plugin}};
150 run_hooks(getopt => sub { shift->() });
151 if (grep /^-/, @ARGV) {
152 print STDERR "Unknown option: $_\n"
153 foreach grep /^-/, @ARGV;
158 sub loadplugin ($) { #{{{
161 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
163 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
166 error("Failed to load plugin $mod: $@");
170 sub error ($;$) { #{{{
174 print "Content-type: text/html\n\n";
175 print misctemplate(gettext("Error"),
176 "<p>".gettext("Error").": $message</p>");
178 log_message('err' => $message) if $config{syslog};
179 if (defined $cleaner) {
186 return unless $config{verbose};
187 log_message(debug => @_);
191 sub log_message ($$) { #{{{
194 if ($config{syslog}) {
197 Sys::Syslog::setlogsock('unix');
198 Sys::Syslog::openlog('ikiwiki', '', 'user');
202 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
205 elsif (! $config{cgi}) {
213 sub possibly_foolish_untaint ($) { #{{{
215 my ($untainted)=$tainted=~/(.*)/s;
219 sub basename ($) { #{{{
226 sub dirname ($) { #{{{
233 sub pagetype ($) { #{{{
236 if ($page =~ /\.([^.]+)$/) {
237 return $1 if exists $hooks{htmlize}{$1};
242 sub pagename ($) { #{{{
245 my $type=pagetype($file);
247 $page=~s/\Q.$type\E*$// if defined $type;
251 sub targetpage ($$) { #{{{
255 if (! $config{usedirs} || $page =~ /^index$/ ) {
256 return $page.".".$ext;
258 return $page."/index.".$ext;
262 sub htmlpage ($) { #{{{
265 return targetpage($page, $config{htmlext});
268 sub srcfile ($) { #{{{
271 return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
272 return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
273 error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
276 sub readfile ($;$$) { #{{{
282 error("cannot read a symlink ($file)");
286 open (IN, $file) || error("failed to read $file: $!");
287 binmode(IN) if ($binary);
288 return \*IN if $wantfd;
290 close IN || error("failed to read $file: $!");
294 sub writefile ($$$;$$) { #{{{
295 my $file=shift; # can include subdirs
296 my $destdir=shift; # directory to put file in
302 while (length $test) {
303 if (-l "$destdir/$test") {
304 error("cannot write to a symlink ($test)");
306 $test=dirname($test);
308 my $newfile="$destdir/$file.ikiwiki-new";
310 error("cannot write to a symlink ($newfile)");
313 my $dir=dirname($newfile);
316 foreach my $s (split(m!/+!, $dir)) {
319 mkdir($d) || error("failed to create directory $d: $!");
324 my $cleanup = sub { unlink($newfile) };
325 open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup);
326 binmode(OUT) if ($binary);
328 $writer->(\*OUT, $cleanup);
331 print OUT $content or error("failed writing to $newfile: $!", $cleanup);
333 close OUT || error("failed saving $newfile: $!", $cleanup);
334 rename($newfile, "$destdir/$file") ||
335 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
339 sub will_render ($$;$) { #{{{
344 # Important security check.
345 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
346 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
347 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
350 if (! $clear || $cleared{$page}) {
351 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
354 foreach my $old (@{$renderedfiles{$page}}) {
355 delete $destsources{$old};
357 $renderedfiles{$page}=[$dest];
360 $destsources{$dest}=$page;
363 sub bestlink ($$) { #{{{
368 if ($link=~s/^\/+//) {
375 $l.="/" if length $l;
378 if (exists $links{$l}) {
381 elsif (exists $pagecase{lc $l}) {
382 return $pagecase{lc $l};
384 } while $cwd=~s!/?[^/]+$!!;
386 if (length $config{userdir}) {
387 my $l = "$config{userdir}/".lc($link);
388 if (exists $links{$l}) {
391 elsif (exists $pagecase{lc $l}) {
392 return $pagecase{lc $l};
396 #print STDERR "warning: page $page, broken link: $link\n";
400 sub isinlinableimage ($) { #{{{
403 $file=~/\.(png|gif|jpg|jpeg)$/i;
406 sub pagetitle ($;$) { #{{{
411 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
414 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
420 sub titlepage ($) { #{{{
422 $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
426 sub linkpage ($) { #{{{
428 $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
432 sub cgiurl (@) { #{{{
435 return $config{cgiurl}."?".
436 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
439 sub baseurl (;$) { #{{{
442 return "$config{url}/" if ! defined $page;
444 $page=htmlpage($page);
446 $page=~s/[^\/]+\//..\//g;
450 sub abs2rel ($$) { #{{{
451 # Work around very innefficient behavior in File::Spec if abs2rel
452 # is passed two relative paths. It's much faster if paths are
453 # absolute! (Debian bug #376658; fixed in debian unstable now)
458 my $ret=File::Spec->abs2rel($path, $base);
459 $ret=~s/^// if defined $ret;
463 sub displaytime ($) { #{{{
466 # strftime doesn't know about encodings, so make sure
467 # its output is properly treated as utf8
468 return decode_utf8(POSIX::strftime(
469 $config{timeformat}, localtime($time)));
472 sub beautify_url ($) { #{{{
475 $url =~ s!/index.$config{htmlext}$!/!;
476 $url =~ s!^$!./!; # Browsers don't like empty links...
481 sub urlto ($$) { #{{{
486 return beautify_url(baseurl($from));
489 if (! $destsources{$to}) {
493 my $link = abs2rel($to, dirname(htmlpage($from)));
495 return beautify_url($link);
498 sub htmllink ($$$;@) { #{{{
499 my $lpage=shift; # the page doing the linking
500 my $page=shift; # the page that will contain the link (different for inline)
505 if (! $opts{forcesubpage}) {
506 $bestlink=bestlink($lpage, $link);
509 $bestlink="$lpage/".lc($link);
513 if (defined $opts{linktext}) {
514 $linktext=$opts{linktext};
517 $linktext=pagetitle(basename($link));
520 return "<span class=\"selflink\">$linktext</span>"
521 if length $bestlink && $page eq $bestlink;
523 if (! $destsources{$bestlink}) {
524 $bestlink=htmlpage($bestlink);
526 if (! $destsources{$bestlink}) {
527 return $linktext unless length $config{cgiurl};
528 return "<span><a href=\"".
531 page => pagetitle(lc($link), 1),
534 "\">?</a>$linktext</span>"
538 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
539 $bestlink=beautify_url($bestlink);
541 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
542 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
545 if (defined $opts{anchor}) {
546 $bestlink.="#".$opts{anchor};
549 return "<a href=\"$bestlink\">$linktext</a>";
552 sub htmlize ($$$) { #{{{
557 if (exists $hooks{htmlize}{$type}) {
558 $content=$hooks{htmlize}{$type}{call}->(
564 error("htmlization of $type not supported");
567 run_hooks(sanitize => sub {
577 sub linkify ($$$) { #{{{
578 my $lpage=shift; # the page containing the links
579 my $page=shift; # the page the link will end up on (different for inline)
582 $content =~ s{(\\?)$config{wiki_link_regexp}}{
585 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
586 : htmllink($lpage, $page, linkpage($3),
587 anchor => $4, linktext => pagetitle($2)))
589 ? "[[$3".($4 ? "#$4" : "")."]]"
590 : htmllink($lpage, $page, linkpage($3),
598 our $preprocess_preview=0;
599 sub preprocess ($$$;$$) { #{{{
600 my $page=shift; # the page the data comes from
601 my $destpage=shift; # the page the data will appear in (different for inline)
606 # Using local because it needs to be set within any nested calls
608 local $preprocess_preview=$preview if defined $preview;
614 if (length $escape) {
615 return "\\[[$command $params]]";
617 elsif (exists $hooks{preprocess}{$command}) {
618 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
619 # Note: preserve order of params, some plugins may
620 # consider it significant.
623 (?:(\w+)=)? # 1: named parameter key?
625 """(.*?)""" # 2: triple-quoted value
627 "([^"]+)" # 3: single-quoted value
629 (\S+) # 4: unquoted value
631 (?:\s+|$) # delimiter to next param
649 push @params, $key, $val;
652 push @params, $val, '';
655 if ($preprocessing{$page}++ > 3) {
656 # Avoid loops of preprocessed pages preprocessing
657 # other pages that preprocess them, etc.
658 #translators: The first parameter is a
659 #translators: preprocessor directive name,
660 #translators: the second a page name, the
661 #translators: third a number.
662 return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
663 $command, $page, $preprocessing{$page}).
666 my $ret=$hooks{preprocess}{$command}{call}->(
669 destpage => $destpage,
670 preview => $preprocess_preview,
672 $preprocessing{$page}--;
676 return "\\[[$command $params]]";
682 \[\[ # directive open
685 ( # 3: the parameters..
687 (?:\w+=)? # named parameter key?
689 """.*?""" # triple-quoted value
691 "[^"]+" # single-quoted value
693 [^\s\]]+ # unquoted value
695 \s* # whitespace or end
698 *) # 0 or more parameters
699 \]\] # directive closed
700 }{$handle->($1, $2, $3)}sexg;
704 sub filter ($$$) { #{{{
709 run_hooks(filter => sub {
710 $content=shift->(page => $page, destpage => $destpage,
711 content => $content);
717 sub indexlink () { #{{{
718 return "<a href=\"$config{url}\">$config{wikiname}</a>";
721 sub lockwiki (;$) { #{{{
722 my $wait=@_ ? shift : 1;
723 # Take an exclusive lock on the wiki to prevent multiple concurrent
724 # run issues. The lock will be dropped on program exit.
725 if (! -d $config{wikistatedir}) {
726 mkdir($config{wikistatedir});
728 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
729 error ("cannot write to $config{wikistatedir}/lockfile: $!");
730 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
732 debug("wiki seems to be locked, waiting for lock");
733 my $wait=600; # arbitrary, but don't hang forever to
734 # prevent process pileup
736 return if flock(WIKILOCK, 2 | 4);
739 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
748 sub unlockwiki () { #{{{
752 sub commit_hook_enabled () { #{{{
753 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
754 error ("cannot write to $config{wikistatedir}/commitlock: $!");
755 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
763 sub disable_commit_hook () { #{{{
764 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
765 error ("cannot write to $config{wikistatedir}/commitlock: $!");
766 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
767 error("failed to get commit lock");
771 sub enable_commit_hook () { #{{{
775 sub loadindex () { #{{{
776 open (IN, "$config{wikistatedir}/index") || return;
778 $_=possibly_foolish_untaint($_);
783 foreach my $i (split(/ /, $_)) {
784 my ($item, $val)=split(/=/, $i, 2);
785 push @{$items{$item}}, decode_entities($val);
788 next unless exists $items{src}; # skip bad lines for now
790 my $page=pagename($items{src}[0]);
791 if (! $config{rebuild}) {
792 $pagesources{$page}=$items{src}[0];
793 $pagemtime{$page}=$items{mtime}[0];
794 $oldlinks{$page}=[@{$items{link}}];
795 $links{$page}=[@{$items{link}}];
796 $depends{$page}=$items{depends}[0] if exists $items{depends};
797 $destsources{$_}=$page foreach @{$items{dest}};
798 $renderedfiles{$page}=[@{$items{dest}}];
799 $pagecase{lc $page}=$page;
801 $oldrenderedfiles{$page}=[@{$items{dest}}];
802 $pagectime{$page}=$items{ctime}[0];
807 sub saveindex () { #{{{
808 run_hooks(savestate => sub { shift->() });
810 if (! -d $config{wikistatedir}) {
811 mkdir($config{wikistatedir});
813 my $newfile="$config{wikistatedir}/index.new";
814 my $cleanup = sub { unlink($newfile) };
815 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
816 foreach my $page (keys %pagemtime) {
817 next unless $pagemtime{$page};
818 my $line="mtime=$pagemtime{$page} ".
819 "ctime=$pagectime{$page} ".
820 "src=$pagesources{$page}";
821 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
823 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
824 if (exists $depends{$page}) {
825 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
827 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
829 close OUT || error("failed saving to $newfile: $!", $cleanup);
830 rename($newfile, "$config{wikistatedir}/index") ||
831 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
834 sub template_file ($) { #{{{
837 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
838 return "$dir/$template" if -e "$dir/$template";
843 sub template_params (@) { #{{{
844 my $filename=template_file(shift);
846 if (! defined $filename) {
853 my $text_ref = shift;
854 $$text_ref=&Encode::decode_utf8($$text_ref);
856 filename => $filename,
857 loop_context_vars => 1,
858 die_on_bad_params => 0,
861 return wantarray ? @ret : {@ret};
864 sub template ($;@) { #{{{
865 require HTML::Template;
866 HTML::Template->new(template_params(@_));
869 sub misctemplate ($$;@) { #{{{
873 my $template=template("misc.tmpl");
876 indexlink => indexlink(),
877 wikiname => $config{wikiname},
878 pagebody => $pagebody,
879 baseurl => baseurl(),
882 run_hooks(pagetemplate => sub {
883 shift->(page => "", destpage => "", template => $template);
885 return $template->output;
891 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
892 error "hook requires type, call, and id parameters";
895 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
897 $hooks{$param{type}}{$param{id}}=\%param;
900 sub run_hooks ($$) { # {{{
901 # Calls the given sub for each hook of the given type,
902 # passing it the hook function to call.
906 if (exists $hooks{$type}) {
908 foreach my $id (keys %{$hooks{$type}}) {
909 if ($hooks{$type}{$id}{last}) {
913 $sub->($hooks{$type}{$id}{call});
915 foreach my $id (@deferred) {
916 $sub->($hooks{$type}{$id}{call});
921 sub globlist_to_pagespec ($) { #{{{
922 my @globlist=split(' ', shift);
925 foreach my $glob (@globlist) {
926 if ($glob=~/^!(.*)/) {
934 my $spec=join(" or ", @spec);
936 my $skip=join(" and ", @skip);
938 $spec="$skip and ($spec)";
947 sub is_globlist ($) { #{{{
949 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
952 sub safequote ($) { #{{{
958 sub add_depends ($$) { #{{{
962 if (! exists $depends{$page}) {
963 $depends{$page}=$pagespec;
966 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
970 sub file_pruned ($$) { #{{{
972 my $file=File::Spec->canonpath(shift);
973 my $base=File::Spec->canonpath(shift);
974 $file=~s#^\Q$base\E/*##;
976 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
981 # Only use gettext in the rare cases it's needed.
982 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
983 if (! $gettext_obj) {
985 use Locale::gettext q{textdomain};
986 Locale::gettext->domain('ikiwiki')
994 return $gettext_obj->get(shift);
1001 sub pagespec_merge ($$) { #{{{
1005 return $a if $a eq $b;
1007 # Support for old-style GlobLists.
1008 if (is_globlist($a)) {
1009 $a=globlist_to_pagespec($a);
1011 if (is_globlist($b)) {
1012 $b=globlist_to_pagespec($b);
1015 return "($a) or ($b)";
1018 sub pagespec_translate ($) { #{{{
1019 # This assumes that $page is in scope in the function
1020 # that evalulates the translated pagespec code.
1023 # Support for old-style GlobLists.
1024 if (is_globlist($spec)) {
1025 $spec=globlist_to_pagespec($spec);
1028 # Convert spec to perl code.
1031 \s* # ignore whitespace
1032 ( # 1: match a single word
1039 \w+\([^\)]+\) # command(params)
1041 [^\s()]+ # any other text
1043 \s* # ignore whitespace
1046 if (lc $word eq "and") {
1049 elsif (lc $word eq "or") {
1052 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
1055 elsif ($word =~ /^(\w+)\((.*)\)$/) {
1056 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
1057 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
1064 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
1071 sub pagespec_match ($$;@) { #{{{
1076 # Backwards compatability with old calling convention.
1078 unshift @params, "location";
1081 my $ret=eval pagespec_translate($spec);
1082 return IkiWiki::FailReason->new("syntax error") if $@;
1086 package IkiWiki::FailReason;
1089 '""' => sub { ${$_[0]} },
1091 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1096 bless \$_[1], $_[0];
1099 package IkiWiki::SuccessReason;
1102 '""' => sub { ${$_[0]} },
1104 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1109 bless \$_[1], $_[0];
1112 package IkiWiki::PageSpec;
1114 sub match_glob ($$;@) { #{{{
1119 my $from=exists $params{location} ? $params{location} : "";
1122 if ($glob =~ m!^\./!) {
1123 $from=~s#/?[^/]+$##;
1125 $glob="$from/$glob" if length $from;
1128 # turn glob into safe regexp
1129 $glob=quotemeta($glob);
1133 if ($page=~/^$glob$/i) {
1134 return IkiWiki::SuccessReason->new("$glob matches $page");
1137 return IkiWiki::FailReason->new("$glob does not match $page");
1141 sub match_link ($$;@) { #{{{
1146 my $from=exists $params{location} ? $params{location} : "";
1149 if ($link =~ m!^\.! && defined $from) {
1150 $from=~s#/?[^/]+$##;
1152 $link="$from/$link" if length $from;
1155 my $links = $IkiWiki::links{$page} or return undef;
1156 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1157 my $bestlink = IkiWiki::bestlink($from, $link);
1158 foreach my $p (@$links) {
1159 if (length $bestlink) {
1160 return IkiWiki::SuccessReason->new("$page links to $link")
1161 if $bestlink eq IkiWiki::bestlink($page, $p);
1164 return IkiWiki::SuccessReason->new("$page links to page matching $link")
1165 if match_glob($p, $link, %params);
1168 return IkiWiki::FailReason->new("$page does not link to $link");
1171 sub match_backlink ($$;@) { #{{{
1172 match_link($_[1], $_[0], @_);
1175 sub match_created_before ($$;@) { #{{{
1179 if (exists $IkiWiki::pagectime{$testpage}) {
1180 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1181 IkiWiki::SuccessReason->new("$page created before $testpage");
1184 IkiWiki::FailReason->new("$page not created before $testpage");
1188 return IkiWiki::FailReason->new("$testpage has no ctime");
1192 sub match_created_after ($$;@) { #{{{
1196 if (exists $IkiWiki::pagectime{$testpage}) {
1197 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1198 IkiWiki::SuccessReason->new("$page created after $testpage");
1201 IkiWiki::FailReason->new("$page not created after $testpage");
1205 return IkiWiki::FailReason->new("$testpage has no ctime");
1209 sub match_creation_day ($$;@) { #{{{
1210 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1211 return IkiWiki::SuccessReason->new("creation_day matched");
1214 return IkiWiki::FailReason->new("creation_day did not match");
1218 sub match_creation_month ($$;@) { #{{{
1219 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1220 return IkiWiki::SuccessReason->new("creation_month matched");
1223 return IkiWiki::FailReason->new("creation_month did not match");
1227 sub match_creation_year ($$;@) { #{{{
1228 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1229 return IkiWiki::SuccessReason->new("creation_year matched");
1232 return IkiWiki::FailReason->new("creation_year did not match");
1236 sub match_user ($$;@) { #{{{
1241 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1242 if ($user eq $params{user}) {
1243 return IkiWiki::SuccessReason->new("user is $user")
1246 return IkiWiki::FailReason->new("user is not $user");