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",
76 gitorigin_branch => "origin",
77 gitmaster_branch => "master",
81 templatedir => "$installdir/share/ikiwiki/templates",
82 underlaydir => "$installdir/share/ikiwiki/basewiki",
86 plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
87 lockedit conditional}],
95 account_creation_password => "",
98 sub checkconfig () { #{{{
99 # locale stuff; avoid LC_ALL since it overrides everything
100 if (defined $ENV{LC_ALL}) {
101 $ENV{LANG} = $ENV{LC_ALL};
104 if (defined $config{locale}) {
105 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
106 $ENV{LANG}=$config{locale};
111 if ($config{w3mmode}) {
112 eval q{use Cwd q{abs_path}};
114 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
115 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
116 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
117 unless $config{cgiurl} =~ m!file:///!;
118 $config{url}="file://".$config{destdir};
121 if ($config{cgi} && ! length $config{url}) {
122 error(gettext("Must specify url to wiki with --url when using --cgi"));
125 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
126 unless exists $config{wikistatedir};
129 eval qq{use IkiWiki::Rcs::$config{rcs}};
131 error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
135 require IkiWiki::Rcs::Stub;
138 run_hooks(checkconfig => sub { shift->() });
141 sub loadplugins () { #{{{
142 loadplugin($_) foreach @{$config{plugin}};
144 run_hooks(getopt => sub { shift->() });
145 if (grep /^-/, @ARGV) {
146 print STDERR "Unknown option: $_\n"
147 foreach grep /^-/, @ARGV;
152 sub loadplugin ($) { #{{{
155 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
157 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
160 error("Failed to load plugin $mod: $@");
164 sub error ($;$) { #{{{
168 print "Content-type: text/html\n\n";
169 print misctemplate(gettext("Error"),
170 "<p>".gettext("Error").": $message</p>");
172 log_message('err' => $message) if $config{syslog};
173 if (defined $cleaner) {
180 return unless $config{verbose};
181 log_message(debug => @_);
185 sub log_message ($$) { #{{{
188 if ($config{syslog}) {
191 Sys::Syslog::setlogsock('unix');
192 Sys::Syslog::openlog('ikiwiki', '', 'user');
196 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
199 elsif (! $config{cgi}) {
207 sub possibly_foolish_untaint ($) { #{{{
209 my ($untainted)=$tainted=~/(.*)/s;
213 sub basename ($) { #{{{
220 sub dirname ($) { #{{{
227 sub pagetype ($) { #{{{
230 if ($page =~ /\.([^.]+)$/) {
231 return $1 if exists $hooks{htmlize}{$1};
236 sub pagename ($) { #{{{
239 my $type=pagetype($file);
241 $page=~s/\Q.$type\E*$// if defined $type;
245 sub targetpage ($$) { #{{{
249 if (! $config{usedirs} || $page =~ /^index$/ ) {
250 return $page.".".$ext;
252 return $page."/index.".$ext;
256 sub htmlpage ($) { #{{{
259 return targetpage($page, "html");
262 sub srcfile ($) { #{{{
265 return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
266 return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
267 error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
270 sub readfile ($;$$) { #{{{
276 error("cannot read a symlink ($file)");
280 open (IN, $file) || error("failed to read $file: $!");
281 binmode(IN) if ($binary);
282 return \*IN if $wantfd;
284 close IN || error("failed to read $file: $!");
288 sub writefile ($$$;$$) { #{{{
289 my $file=shift; # can include subdirs
290 my $destdir=shift; # directory to put file in
296 while (length $test) {
297 if (-l "$destdir/$test") {
298 error("cannot write to a symlink ($test)");
300 $test=dirname($test);
302 my $newfile="$destdir/$file.ikiwiki-new";
304 error("cannot write to a symlink ($newfile)");
307 my $dir=dirname($newfile);
310 foreach my $s (split(m!/+!, $dir)) {
313 mkdir($d) || error("failed to create directory $d: $!");
318 my $cleanup = sub { unlink($newfile) };
319 open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup);
320 binmode(OUT) if ($binary);
322 $writer->(\*OUT, $cleanup);
325 print OUT $content or error("failed writing to $newfile: $!", $cleanup);
327 close OUT || error("failed saving $newfile: $!", $cleanup);
328 rename($newfile, "$destdir/$file") ||
329 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
333 sub will_render ($$;$) { #{{{
338 # Important security check.
339 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
340 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
341 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
344 if (! $clear || $cleared{$page}) {
345 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
348 foreach my $old (@{$renderedfiles{$page}}) {
349 delete $destsources{$old};
351 $renderedfiles{$page}=[$dest];
354 $destsources{$dest}=$page;
357 sub bestlink ($$) { #{{{
362 if ($link=~s/^\/+//) {
369 $l.="/" if length $l;
372 if (exists $links{$l}) {
375 elsif (exists $pagecase{lc $l}) {
376 return $pagecase{lc $l};
378 } while $cwd=~s!/?[^/]+$!!;
380 if (length $config{userdir}) {
381 my $l = "$config{userdir}/".lc($link);
382 if (exists $links{$l}) {
385 elsif (exists $pagecase{lc $l}) {
386 return $pagecase{lc $l};
390 #print STDERR "warning: page $page, broken link: $link\n";
394 sub isinlinableimage ($) { #{{{
397 $file=~/\.(png|gif|jpg|jpeg)$/i;
400 sub pagetitle ($;$) { #{{{
405 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
408 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
414 sub titlepage ($) { #{{{
416 $title=~s/([^-[:alnum:]:+\/.])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
420 sub linkpage ($) { #{{{
422 $link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
426 sub cgiurl (@) { #{{{
429 return $config{cgiurl}."?".
430 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
433 sub baseurl (;$) { #{{{
436 return "$config{url}/" if ! defined $page;
438 $page=htmlpage($page);
440 $page=~s/[^\/]+\//..\//g;
444 sub abs2rel ($$) { #{{{
445 # Work around very innefficient behavior in File::Spec if abs2rel
446 # is passed two relative paths. It's much faster if paths are
447 # absolute! (Debian bug #376658; fixed in debian unstable now)
452 my $ret=File::Spec->abs2rel($path, $base);
453 $ret=~s/^// if defined $ret;
457 sub displaytime ($) { #{{{
460 # strftime doesn't know about encodings, so make sure
461 # its output is properly treated as utf8
462 return decode_utf8(POSIX::strftime(
463 $config{timeformat}, localtime($time)));
466 sub beautify_url ($) { #{{{
469 $url =~ s!/index.html$!/!;
470 $url =~ s!^$!./!; # Browsers don't like empty links...
475 sub urlto ($$) { #{{{
480 return beautify_url(baseurl($from));
483 if (! $destsources{$to}) {
487 my $link = abs2rel($to, dirname(htmlpage($from)));
489 return beautify_url($link);
492 sub htmllink ($$$;@) { #{{{
493 my $lpage=shift; # the page doing the linking
494 my $page=shift; # the page that will contain the link (different for inline)
499 if (! $opts{forcesubpage}) {
500 $bestlink=bestlink($lpage, $link);
503 $bestlink="$lpage/".lc($link);
507 if (defined $opts{linktext}) {
508 $linktext=$opts{linktext};
511 $linktext=pagetitle(basename($link));
514 return "<span class=\"selflink\">$linktext</span>"
515 if length $bestlink && $page eq $bestlink;
517 if (! $destsources{$bestlink}) {
518 $bestlink=htmlpage($bestlink);
520 if (! $destsources{$bestlink}) {
521 return $linktext unless length $config{cgiurl};
522 return "<span><a href=\"".
525 page => pagetitle(lc($link), 1),
528 "\">?</a>$linktext</span>"
532 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
533 $bestlink=beautify_url($bestlink);
535 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
536 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
539 if (defined $opts{anchor}) {
540 $bestlink.="#".$opts{anchor};
543 return "<a href=\"$bestlink\">$linktext</a>";
546 sub htmlize ($$$) { #{{{
551 if (exists $hooks{htmlize}{$type}) {
552 $content=$hooks{htmlize}{$type}{call}->(
558 error("htmlization of $type not supported");
561 run_hooks(sanitize => sub {
571 sub linkify ($$$) { #{{{
572 my $lpage=shift; # the page containing the links
573 my $page=shift; # the page the link will end up on (different for inline)
576 $content =~ s{(\\?)$config{wiki_link_regexp}}{
579 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
580 : htmllink($lpage, $page, linkpage($3),
581 anchor => $4, linktext => pagetitle($2)))
583 ? "[[$3".($4 ? "#$4" : "")."]]"
584 : htmllink($lpage, $page, linkpage($3),
592 our $preprocess_preview=0;
593 sub preprocess ($$$;$$) { #{{{
594 my $page=shift; # the page the data comes from
595 my $destpage=shift; # the page the data will appear in (different for inline)
600 # Using local because it needs to be set within any nested calls
602 local $preprocess_preview=$preview if defined $preview;
608 if (length $escape) {
609 return "[[$command $params]]";
611 elsif (exists $hooks{preprocess}{$command}) {
612 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
613 # Note: preserve order of params, some plugins may
614 # consider it significant.
617 (?:(\w+)=)? # 1: named parameter key?
619 """(.*?)""" # 2: triple-quoted value
621 "([^"]+)" # 3: single-quoted value
623 (\S+) # 4: unquoted value
625 (?:\s+|$) # delimiter to next param
643 push @params, $key, $val;
646 push @params, $val, '';
649 if ($preprocessing{$page}++ > 3) {
650 # Avoid loops of preprocessed pages preprocessing
651 # other pages that preprocess them, etc.
652 #translators: The first parameter is a
653 #translators: preprocessor directive name,
654 #translators: the second a page name, the
655 #translators: third a number.
656 return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
657 $command, $page, $preprocessing{$page}).
660 my $ret=$hooks{preprocess}{$command}{call}->(
663 destpage => $destpage,
664 preview => $preprocess_preview,
666 $preprocessing{$page}--;
670 return "\\[[$command $params]]";
676 \[\[ # directive open
679 ( # 3: the parameters..
681 (?:\w+=)? # named parameter key?
683 """.*?""" # triple-quoted value
685 "[^"]+" # single-quoted value
687 [^\s\]]+ # unquoted value
689 \s* # whitespace or end
692 *) # 0 or more parameters
693 \]\] # directive closed
694 }{$handle->($1, $2, $3)}sexg;
698 sub filter ($$$) { #{{{
703 run_hooks(filter => sub {
704 $content=shift->(page => $page, destpage => $destpage,
705 content => $content);
711 sub indexlink () { #{{{
712 return "<a href=\"$config{url}\">$config{wikiname}</a>";
715 sub lockwiki (;$) { #{{{
716 my $wait=@_ ? shift : 1;
717 # Take an exclusive lock on the wiki to prevent multiple concurrent
718 # run issues. The lock will be dropped on program exit.
719 if (! -d $config{wikistatedir}) {
720 mkdir($config{wikistatedir});
722 open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
723 error ("cannot write to $config{wikistatedir}/lockfile: $!");
724 if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
726 debug("wiki seems to be locked, waiting for lock");
727 my $wait=600; # arbitrary, but don't hang forever to
728 # prevent process pileup
730 return if flock(WIKILOCK, 2 | 4);
733 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
742 sub unlockwiki () { #{{{
746 sub commit_hook_enabled () { #{{{
747 open(COMMITLOCK, "+>$config{wikistatedir}/commitlock") ||
748 error ("cannot write to $config{wikistatedir}/commitlock: $!");
749 if (! flock(COMMITLOCK, 1 | 4)) { # LOCK_SH | LOCK_NB to test
757 sub disable_commit_hook () { #{{{
758 open(COMMITLOCK, ">$config{wikistatedir}/commitlock") ||
759 error ("cannot write to $config{wikistatedir}/commitlock: $!");
760 if (! flock(COMMITLOCK, 2)) { # LOCK_EX
761 error("failed to get commit lock");
765 sub enable_commit_hook () { #{{{
769 sub loadindex () { #{{{
770 open (IN, "$config{wikistatedir}/index") || return;
772 $_=possibly_foolish_untaint($_);
777 foreach my $i (split(/ /, $_)) {
778 my ($item, $val)=split(/=/, $i, 2);
779 push @{$items{$item}}, decode_entities($val);
782 next unless exists $items{src}; # skip bad lines for now
784 my $page=pagename($items{src}[0]);
785 if (! $config{rebuild}) {
786 $pagesources{$page}=$items{src}[0];
787 $pagemtime{$page}=$items{mtime}[0];
788 $oldlinks{$page}=[@{$items{link}}];
789 $links{$page}=[@{$items{link}}];
790 $depends{$page}=$items{depends}[0] if exists $items{depends};
791 $destsources{$_}=$page foreach @{$items{dest}};
792 $renderedfiles{$page}=[@{$items{dest}}];
793 $pagecase{lc $page}=$page;
795 $oldrenderedfiles{$page}=[@{$items{dest}}];
796 $pagectime{$page}=$items{ctime}[0];
801 sub saveindex () { #{{{
802 run_hooks(savestate => sub { shift->() });
804 if (! -d $config{wikistatedir}) {
805 mkdir($config{wikistatedir});
807 my $newfile="$config{wikistatedir}/index.new";
808 my $cleanup = sub { unlink($newfile) };
809 open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup);
810 foreach my $page (keys %pagemtime) {
811 next unless $pagemtime{$page};
812 my $line="mtime=$pagemtime{$page} ".
813 "ctime=$pagectime{$page} ".
814 "src=$pagesources{$page}";
815 $line.=" dest=$_" foreach @{$renderedfiles{$page}};
817 $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
818 if (exists $depends{$page}) {
819 $line.=" depends=".encode_entities($depends{$page}, " \t\n");
821 print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup);
823 close OUT || error("failed saving to $newfile: $!", $cleanup);
824 rename($newfile, "$config{wikistatedir}/index") ||
825 error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup);
828 sub template_file ($) { #{{{
831 foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
832 return "$dir/$template" if -e "$dir/$template";
837 sub template_params (@) { #{{{
838 my $filename=template_file(shift);
840 if (! defined $filename) {
847 my $text_ref = shift;
848 $$text_ref=&Encode::decode_utf8($$text_ref);
850 filename => $filename,
851 loop_context_vars => 1,
852 die_on_bad_params => 0,
855 return wantarray ? @ret : {@ret};
858 sub template ($;@) { #{{{
859 require HTML::Template;
860 HTML::Template->new(template_params(@_));
863 sub misctemplate ($$;@) { #{{{
867 my $template=template("misc.tmpl");
870 indexlink => indexlink(),
871 wikiname => $config{wikiname},
872 pagebody => $pagebody,
873 baseurl => baseurl(),
876 run_hooks(pagetemplate => sub {
877 shift->(page => "", destpage => "", template => $template);
879 return $template->output;
885 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
886 error "hook requires type, call, and id parameters";
889 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
891 $hooks{$param{type}}{$param{id}}=\%param;
894 sub run_hooks ($$) { # {{{
895 # Calls the given sub for each hook of the given type,
896 # passing it the hook function to call.
900 if (exists $hooks{$type}) {
902 foreach my $id (keys %{$hooks{$type}}) {
903 if ($hooks{$type}{$id}{last}) {
907 $sub->($hooks{$type}{$id}{call});
909 foreach my $id (@deferred) {
910 $sub->($hooks{$type}{$id}{call});
915 sub globlist_to_pagespec ($) { #{{{
916 my @globlist=split(' ', shift);
919 foreach my $glob (@globlist) {
920 if ($glob=~/^!(.*)/) {
928 my $spec=join(" or ", @spec);
930 my $skip=join(" and ", @skip);
932 $spec="$skip and ($spec)";
941 sub is_globlist ($) { #{{{
943 $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
946 sub safequote ($) { #{{{
952 sub add_depends ($$) { #{{{
956 if (! exists $depends{$page}) {
957 $depends{$page}=$pagespec;
960 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
964 sub file_pruned ($$) { #{{{
966 my $file=File::Spec->canonpath(shift);
967 my $base=File::Spec->canonpath(shift);
968 $file=~s#^\Q$base\E/*##;
970 my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
975 # Only use gettext in the rare cases it's needed.
976 if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
977 if (! $gettext_obj) {
979 use Locale::gettext q{textdomain};
980 Locale::gettext->domain('ikiwiki')
988 return $gettext_obj->get(shift);
995 sub pagespec_merge ($$) { #{{{
999 return $a if $a eq $b;
1001 # Support for old-style GlobLists.
1002 if (is_globlist($a)) {
1003 $a=globlist_to_pagespec($a);
1005 if (is_globlist($b)) {
1006 $b=globlist_to_pagespec($b);
1009 return "($a) or ($b)";
1012 sub pagespec_translate ($) { #{{{
1013 # This assumes that $page is in scope in the function
1014 # that evalulates the translated pagespec code.
1017 # Support for old-style GlobLists.
1018 if (is_globlist($spec)) {
1019 $spec=globlist_to_pagespec($spec);
1022 # Convert spec to perl code.
1025 \s* # ignore whitespace
1026 ( # 1: match a single word
1033 \w+\([^\)]+\) # command(params)
1035 [^\s()]+ # any other text
1037 \s* # ignore whitespace
1040 if (lc $word eq "and") {
1043 elsif (lc $word eq "or") {
1046 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
1049 elsif ($word =~ /^(\w+)\((.*)\)$/) {
1050 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
1051 $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
1058 $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
1065 sub pagespec_match ($$;@) { #{{{
1070 # Backwards compatability with old calling convention.
1072 unshift @params, "location";
1075 my $ret=eval pagespec_translate($spec);
1076 return IkiWiki::FailReason->new("syntax error") if $@;
1080 package IkiWiki::FailReason;
1083 '""' => sub { ${$_[0]} },
1085 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
1090 bless \$_[1], $_[0];
1093 package IkiWiki::SuccessReason;
1096 '""' => sub { ${$_[0]} },
1098 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
1103 bless \$_[1], $_[0];
1106 package IkiWiki::PageSpec;
1108 sub match_glob ($$;@) { #{{{
1113 my $from=exists $params{location} ? $params{location} : "";
1116 if ($glob =~ m!^\./!) {
1117 $from=~s#/?[^/]+$##;
1119 $glob="$from/$glob" if length $from;
1122 # turn glob into safe regexp
1123 $glob=quotemeta($glob);
1127 if ($page=~/^$glob$/i) {
1128 return IkiWiki::SuccessReason->new("$glob matches $page");
1131 return IkiWiki::FailReason->new("$glob does not match $page");
1135 sub match_link ($$;@) { #{{{
1140 my $from=exists $params{location} ? $params{location} : "";
1143 if ($link =~ m!^\.! && defined $from) {
1144 $from=~s#/?[^/]+$##;
1146 $link="$from/$link" if length $from;
1149 my $links = $IkiWiki::links{$page} or return undef;
1150 return IkiWiki::FailReason->new("$page has no links") unless @$links;
1151 my $bestlink = IkiWiki::bestlink($from, $link);
1152 foreach my $p (@$links) {
1153 if (length $bestlink) {
1154 return IkiWiki::SuccessReason->new("$page links to $link")
1155 if $bestlink eq IkiWiki::bestlink($page, $p);
1158 return IkiWiki::SuccessReason->new("$page links to page matching $link")
1159 if match_glob($p, $link, %params);
1162 return IkiWiki::FailReason->new("$page does not link to $link");
1165 sub match_backlink ($$;@) { #{{{
1166 match_link($_[1], $_[0], @_);
1169 sub match_created_before ($$;@) { #{{{
1173 if (exists $IkiWiki::pagectime{$testpage}) {
1174 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
1175 IkiWiki::SuccessReason->new("$page created before $testpage");
1178 IkiWiki::FailReason->new("$page not created before $testpage");
1182 return IkiWiki::FailReason->new("$testpage has no ctime");
1186 sub match_created_after ($$;@) { #{{{
1190 if (exists $IkiWiki::pagectime{$testpage}) {
1191 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
1192 IkiWiki::SuccessReason->new("$page created after $testpage");
1195 IkiWiki::FailReason->new("$page not created after $testpage");
1199 return IkiWiki::FailReason->new("$testpage has no ctime");
1203 sub match_creation_day ($$;@) { #{{{
1204 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
1205 return IkiWiki::SuccessReason->new("creation_day matched");
1208 return IkiWiki::FailReason->new("creation_day did not match");
1212 sub match_creation_month ($$;@) { #{{{
1213 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
1214 return IkiWiki::SuccessReason->new("creation_month matched");
1217 return IkiWiki::FailReason->new("creation_month did not match");
1221 sub match_creation_year ($$;@) { #{{{
1222 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
1223 return IkiWiki::SuccessReason->new("creation_year matched");
1226 return IkiWiki::FailReason->new("creation_year did not match");
1230 sub match_user ($$;@) { #{{{
1235 return IkiWiki::FailReason->new("cannot match user") unless exists $params{user};
1236 if ($user eq $params{user}) {
1237 return IkiWiki::SuccessReason->new("user is $user")
1240 return IkiWiki::FailReason->new("user is not $user");