]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki.pm
* Work on firming up the plugin interface:
[ikiwiki.git] / IkiWiki.pm
1 #!/usr/bin/perl
2
3 package IkiWiki;
4 use warnings;
5 use strict;
6 use Encode;
7 use HTML::Entities;
8 use open qw{:utf8 :std};
9
10 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
11             %renderedfiles %pagesources %depends %hooks %forcerebuild};
12
13 use Exporter q{import};
14 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
15                  bestlink htmllink readfile writefile pagetype srcfile pagename
16                  %config %links %renderedfiles %pagesources);
17
18 # Optimisation.
19 use Memoize;
20 memoize("abs2rel");
21 memoize("pagespec_translate");
22
23 my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
24
25 sub defaultconfig () { #{{{
26         wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$)},
27         wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/,
28         wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
29         verbose => 0,
30         syslog => 0,
31         wikiname => "wiki",
32         default_pageext => "mdwn",
33         cgi => 0,
34         rcs => 'svn',
35         notify => 0,
36         url => '',
37         cgiurl => '',
38         historyurl => '',
39         diffurl => '',
40         anonok => 0,
41         rss => 0,
42         discussion => 1,
43         rebuild => 0,
44         refresh => 0,
45         getctime => 0,
46         w3mmode => 0,
47         wrapper => undef,
48         wrappermode => undef,
49         svnrepo => undef,
50         svnpath => "trunk",
51         srcdir => undef,
52         destdir => undef,
53         pingurl => [],
54         templatedir => "$installdir/share/ikiwiki/templates",
55         underlaydir => "$installdir/share/ikiwiki/basewiki",
56         setup => undef,
57         adminuser => undef,
58         adminemail => undef,
59         plugin => [qw{mdwn inline htmlscrubber}],
60         timeformat => '%c',
61         locale => undef,
62         sslcookie => 0,
63 } #}}}
64    
65 sub checkconfig () { #{{{
66         # locale stuff; avoid LC_ALL since it overrides everything
67         if (defined $ENV{LC_ALL}) {
68                 $ENV{LANG} = $ENV{LC_ALL};
69                 delete $ENV{LC_ALL};
70         }
71         if (defined $config{locale}) {
72                 eval q{use POSIX};
73                 $ENV{LANG} = $config{locale}
74                         if POSIX::setlocale(&POSIX::LC_TIME, $config{locale});
75         }
76
77         if ($config{w3mmode}) {
78                 eval q{use Cwd q{abs_path}};
79                 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
80                 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
81                 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
82                         unless $config{cgiurl} =~ m!file:///!;
83                 $config{url}="file://".$config{destdir};
84         }
85
86         if ($config{cgi} && ! length $config{url}) {
87                 error("Must specify url to wiki with --url when using --cgi\n");
88         }
89         if ($config{rss} && ! length $config{url}) {
90                 error("Must specify url to wiki with --url when using --rss\n");
91         }
92         
93         $config{wikistatedir}="$config{srcdir}/.ikiwiki"
94                 unless exists $config{wikistatedir};
95         
96         if ($config{rcs}) {
97                 eval qq{require IkiWiki::Rcs::$config{rcs}};
98                 if ($@) {
99                         error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@");
100                 }
101         }
102         else {
103                 require IkiWiki::Rcs::Stub;
104         }
105
106         run_hooks(checkconfig => sub { shift->() });
107 } #}}}
108
109 sub loadplugins () { #{{{
110         foreach my $plugin (@{$config{plugin}}) {
111                 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
112                 eval qq{use $mod};
113                 if ($@) {
114                         error("Failed to load plugin $mod: $@");
115                 }
116         }
117         run_hooks(getopt => sub { shift->() });
118         if (grep /^-/, @ARGV) {
119                 print STDERR "Unknown option: $_\n"
120                         foreach grep /^-/, @ARGV;
121                 usage();
122         }
123 } #}}}
124
125 sub error ($) { #{{{
126         if ($config{cgi}) {
127                 print "Content-type: text/html\n\n";
128                 print misctemplate("Error", "<p>Error: @_</p>");
129         }
130         log_message(error => @_);
131         exit(1);
132 } #}}}
133
134 sub debug ($) { #{{{
135         return unless $config{verbose};
136         log_message(debug => @_);
137 } #}}}
138
139 my $log_open=0;
140 sub log_message ($$) { #{{{
141         my $type=shift;
142
143         if ($config{syslog}) {
144                 require Sys::Syslog;
145                 unless ($log_open) {
146                         Sys::Syslog::setlogsock('unix');
147                         Sys::Syslog::openlog('ikiwiki', '', 'user');
148                         $log_open=1;
149                 }
150                 eval {
151                         Sys::Syslog::syslog($type, join(" ", @_));
152                 }
153         }
154         elsif (! $config{cgi}) {
155                 print "@_\n";
156         }
157         else {
158                 print STDERR "@_\n";
159         }
160 } #}}}
161
162 sub possibly_foolish_untaint ($) { #{{{
163         my $tainted=shift;
164         my ($untainted)=$tainted=~/(.*)/;
165         return $untainted;
166 } #}}}
167
168 sub basename ($) { #{{{
169         my $file=shift;
170
171         $file=~s!.*/+!!;
172         return $file;
173 } #}}}
174
175 sub dirname ($) { #{{{
176         my $file=shift;
177
178         $file=~s!/*[^/]+$!!;
179         return $file;
180 } #}}}
181
182 sub pagetype ($) { #{{{
183         my $page=shift;
184         
185         if ($page =~ /\.([^.]+)$/) {
186                 return $1 if exists $hooks{htmlize}{$1};
187         }
188         return undef;
189 } #}}}
190
191 sub pagename ($) { #{{{
192         my $file=shift;
193
194         my $type=pagetype($file);
195         my $page=$file;
196         $page=~s/\Q.$type\E*$// if defined $type;
197         return $page;
198 } #}}}
199
200 sub htmlpage ($) { #{{{
201         my $page=shift;
202
203         return $page.".html";
204 } #}}}
205
206 sub srcfile ($) { #{{{
207         my $file=shift;
208
209         return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
210         return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
211         error("internal error: $file cannot be found");
212 } #}}}
213
214 sub readfile ($;$) { #{{{
215         my $file=shift;
216         my $binary=shift;
217
218         if (-l $file) {
219                 error("cannot read a symlink ($file)");
220         }
221         
222         local $/=undef;
223         open (IN, $file) || error("failed to read $file: $!");
224         binmode(IN) if ($binary);
225         my $ret=<IN>;
226         close IN;
227         return $ret;
228 } #}}}
229
230 sub writefile ($$$;$) { #{{{
231         my $file=shift; # can include subdirs
232         my $destdir=shift; # directory to put file in
233         my $content=shift;
234         my $binary=shift;
235         
236         my $test=$file;
237         while (length $test) {
238                 if (-l "$destdir/$test") {
239                         error("cannot write to a symlink ($test)");
240                 }
241                 $test=dirname($test);
242         }
243
244         my $dir=dirname("$destdir/$file");
245         if (! -d $dir) {
246                 my $d="";
247                 foreach my $s (split(m!/+!, $dir)) {
248                         $d.="$s/";
249                         if (! -d $d) {
250                                 mkdir($d) || error("failed to create directory $d: $!");
251                         }
252                 }
253         }
254         
255         open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
256         binmode(OUT) if ($binary);
257         print OUT $content;
258         close OUT;
259 } #}}}
260
261 sub bestlink ($$) { #{{{
262         my $page=shift;
263         my $link=shift;
264         
265         my $cwd=$page;
266         do {
267                 my $l=$cwd;
268                 $l.="/" if length $l;
269                 $l.=$link;
270
271                 if (exists $links{$l}) {
272                         return $l;
273                 }
274                 elsif (exists $pagecase{lc $l}) {
275                         return $pagecase{lc $l};
276                 }
277         } while $cwd=~s!/?[^/]+$!!;
278
279         #print STDERR "warning: page $page, broken link: $link\n";
280         return "";
281 } #}}}
282
283 sub isinlinableimage ($) { #{{{
284         my $file=shift;
285         
286         $file=~/\.(png|gif|jpg|jpeg)$/i;
287 } #}}}
288
289 sub pagetitle ($) { #{{{
290         my $page=shift;
291         $page=~s/__(\d+)__/&#$1;/g;
292         $page=~y/_/ /;
293         return $page;
294 } #}}}
295
296 sub titlepage ($) { #{{{
297         my $title=shift;
298         $title=~y/ /_/;
299         $title=~s/([^-[:alnum:]_:+\/.])/"__".ord($1)."__"/eg;
300         return $title;
301 } #}}}
302
303 sub cgiurl (@) { #{{{
304         my %params=@_;
305
306         return $config{cgiurl}."?".join("&amp;", map "$_=$params{$_}", keys %params);
307 } #}}}
308
309 sub baseurl (;$) { #{{{
310         my $page=shift;
311
312         return "$config{url}/" if ! defined $page;
313         
314         $page=~s/[^\/]+$//;
315         $page=~s/[^\/]+\//..\//g;
316         return $page;
317 } #}}}
318
319 sub abs2rel ($$) { #{{{
320         # Work around very innefficient behavior in File::Spec if abs2rel
321         # is passed two relative paths. It's much faster if paths are
322         # absolute!
323         my $path="/".shift;
324         my $base="/".shift;
325
326         require File::Spec;
327         my $ret=File::Spec->abs2rel($path, $base);
328         $ret=~s/^// if defined $ret;
329         return $ret;
330 } #}}}
331
332 sub displaytime ($) { #{{{
333         my $time=shift;
334
335         eval q{use POSIX};
336         # strftime doesn't know about encodings, so make sure
337         # its output is properly treated as utf8
338         return decode_utf8(POSIX::strftime(
339                         $config{timeformat}, localtime($time)));
340 } #}}}
341
342 sub htmllink ($$$;$$$) { #{{{
343         my $lpage=shift; # the page doing the linking
344         my $page=shift; # the page that will contain the link (different for inline)
345         my $link=shift;
346         my $noimageinline=shift; # don't turn links into inline html images
347         my $forcesubpage=shift; # force a link to a subpage
348         my $linktext=shift; # set to force the link text to something
349
350         my $bestlink;
351         if (! $forcesubpage) {
352                 $bestlink=bestlink($lpage, $link);
353         }
354         else {
355                 $bestlink="$lpage/".lc($link);
356         }
357
358         $linktext=pagetitle(basename($link)) unless defined $linktext;
359         
360         return "<span class=\"selflink\">$linktext</span>"
361                 if length $bestlink && $page eq $bestlink;
362         
363         # TODO BUG: %renderedfiles may not have it, if the linked to page
364         # was also added and isn't yet rendered! Note that this bug is
365         # masked by the bug that makes all new files be rendered twice.
366         if (! grep { $_ eq $bestlink } values %renderedfiles) {
367                 $bestlink=htmlpage($bestlink);
368         }
369         if (! grep { $_ eq $bestlink } values %renderedfiles) {
370                 return "<span><a href=\"".
371                         cgiurl(do => "create", page => lc($link), from => $page).
372                         "\">?</a>$linktext</span>"
373         }
374         
375         $bestlink=abs2rel($bestlink, dirname($page));
376         
377         if (! $noimageinline && isinlinableimage($bestlink)) {
378                 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
379         }
380         return "<a href=\"$bestlink\">$linktext</a>";
381 } #}}}
382
383 sub htmlize ($$$) { #{{{
384         my $page=shift;
385         my $type=shift;
386         my $content=shift;
387
388         if (exists $hooks{htmlize}{$type}) {
389                 $content=$hooks{htmlize}{$type}{call}->(
390                         page => $page,
391                         content => $content,
392                 );
393         }
394         else {
395                 error("htmlization of $type not supported");
396         }
397
398         run_hooks(sanitize => sub {
399                 $content=shift->(
400                         page => $page,
401                         content => $content,
402                 );
403         });
404
405         return $content;
406 } #}}}
407
408 sub linkify ($$$) { #{{{
409         my $lpage=shift; # the page containing the links
410         my $page=shift; # the page the link will end up on (different for inline)
411         my $content=shift;
412
413         $content =~ s{(\\?)$config{wiki_link_regexp}}{
414                 $2 ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2)))
415                    : ( $1 ? "[[$3]]" :    htmllink($lpage, $page, titlepage($3)))
416         }eg;
417         
418         return $content;
419 } #}}}
420
421 my %preprocessing;
422 sub preprocess ($$$) { #{{{
423         my $page=shift; # the page the data comes from
424         my $destpage=shift; # the page the data will appear in (different for inline)
425         my $content=shift;
426
427         my $handle=sub {
428                 my $escape=shift;
429                 my $command=shift;
430                 my $params=shift;
431                 if (length $escape) {
432                         return "[[$command $params]]";
433                 }
434                 elsif (exists $hooks{preprocess}{$command}) {
435                         # Note: preserve order of params, some plugins may
436                         # consider it significant.
437                         my @params;
438                         while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
439                                 my $key=$1;
440                                 my $val;
441                                 if (defined $2) {
442                                         $val=$2;
443                                         $val=~s/\r\n/\n/mg;
444                                         $val=~s/^\n+//g;
445                                         $val=~s/\n+$//g;
446                                 }
447                                 elsif (defined $3) {
448                                         $val=$3;
449                                 }
450                                 elsif (defined $4) {
451                                         $val=$4;
452                                 }
453
454                                 if (defined $key) {
455                                         push @params, $key, $val;
456                                 }
457                                 else {
458                                         push @params, $val, '';
459                                 }
460                         }
461                         if ($preprocessing{$page}++ > 3) {
462                                 # Avoid loops of preprocessed pages preprocessing
463                                 # other pages that preprocess them, etc.
464                                 return "[[$command preprocessing loop detected on $page at depth $preprocessing{$page}]]";
465                         }
466                         my $ret=$hooks{preprocess}{$command}{call}->(
467                                 @params,
468                                 page => $page,
469                                 destpage => $destpage,
470                         );
471                         $preprocessing{$page}--;
472                         return $ret;
473                 }
474                 else {
475                         return "[[$command $params]]";
476                 }
477         };
478         
479         $content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
480         return $content;
481 } #}}}
482
483 sub filter ($$) {
484         my $page=shift;
485         my $content=shift;
486
487         run_hooks(filter => sub {
488                 $content=shift->(page => $page, content => $content);
489         });
490
491         return $content;
492 }
493
494 sub indexlink () { #{{{
495         return "<a href=\"$config{url}\">$config{wikiname}</a>";
496 } #}}}
497
498 sub lockwiki () { #{{{
499         # Take an exclusive lock on the wiki to prevent multiple concurrent
500         # run issues. The lock will be dropped on program exit.
501         if (! -d $config{wikistatedir}) {
502                 mkdir($config{wikistatedir});
503         }
504         open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
505                 error ("cannot write to $config{wikistatedir}/lockfile: $!");
506         if (! flock(WIKILOCK, 2 | 4)) {
507                 debug("wiki seems to be locked, waiting for lock");
508                 my $wait=600; # arbitrary, but don't hang forever to 
509                               # prevent process pileup
510                 for (1..600) {
511                         return if flock(WIKILOCK, 2 | 4);
512                         sleep 1;
513                 }
514                 error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
515         }
516 } #}}}
517
518 sub unlockwiki () { #{{{
519         close WIKILOCK;
520 } #}}}
521
522 sub loadindex () { #{{{
523         open (IN, "$config{wikistatedir}/index") || return;
524         while (<IN>) {
525                 $_=possibly_foolish_untaint($_);
526                 chomp;
527                 my %items;
528                 $items{link}=[];
529                 foreach my $i (split(/ /, $_)) {
530                         my ($item, $val)=split(/=/, $i, 2);
531                         push @{$items{$item}}, decode_entities($val);
532                 }
533
534                 next unless exists $items{src}; # skip bad lines for now
535
536                 my $page=pagename($items{src}[0]);
537                 if (! $config{rebuild}) {
538                         $pagesources{$page}=$items{src}[0];
539                         $oldpagemtime{$page}=$items{mtime}[0];
540                         $oldlinks{$page}=[@{$items{link}}];
541                         $links{$page}=[@{$items{link}}];
542                         $depends{$page}=$items{depends}[0] if exists $items{depends};
543                         $renderedfiles{$page}=$items{dest}[0];
544                         $pagecase{lc $page}=$page;
545                 }
546                 $pagectime{$page}=$items{ctime}[0];
547         }
548         close IN;
549 } #}}}
550
551 sub saveindex () { #{{{
552         run_hooks(savestate => sub { shift->() });
553
554         if (! -d $config{wikistatedir}) {
555                 mkdir($config{wikistatedir});
556         }
557         open (OUT, ">$config{wikistatedir}/index") || 
558                 error("cannot write to $config{wikistatedir}/index: $!");
559         foreach my $page (keys %oldpagemtime) {
560                 next unless $oldpagemtime{$page};
561                 my $line="mtime=$oldpagemtime{$page} ".
562                         "ctime=$pagectime{$page} ".
563                         "src=$pagesources{$page} ".
564                         "dest=$renderedfiles{$page}";
565                 $line.=" link=$_" foreach @{$links{$page}};
566                 if (exists $depends{$page}) {
567                         $line.=" depends=".encode_entities($depends{$page}, " \t\n");
568                 }
569                 print OUT $line."\n";
570         }
571         close OUT;
572 } #}}}
573
574 sub template_params (@) { #{{{
575         my $filename=shift;
576         
577         require HTML::Template;
578         return filter => sub {
579                         my $text_ref = shift;
580                         $$text_ref=&Encode::decode_utf8($$text_ref);
581                 },
582                 filename => "$config{templatedir}/$filename",
583                 loop_context_vars => 1,
584                 die_on_bad_params => 0,
585                 @_;
586 } #}}}
587
588 sub template ($;@) { #{{{
589         HTML::Template->new(template_params(@_));
590 } #}}}
591
592 sub misctemplate ($$) { #{{{
593         my $title=shift;
594         my $pagebody=shift;
595         
596         my $template=template("misc.tmpl");
597         $template->param(
598                 title => $title,
599                 indexlink => indexlink(),
600                 wikiname => $config{wikiname},
601                 pagebody => $pagebody,
602         baseurl => baseurl(),
603         );
604         return $template->output;
605 }#}}}
606
607 sub hook (@) { # {{{
608         my %param=@_;
609         
610         if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
611                 error "hook requires type, call, and id parameters";
612         }
613         
614         $hooks{$param{type}}{$param{id}}=\%param;
615 } # }}}
616
617 sub run_hooks ($$) { # {{{
618         # Calls the given sub for each hook of the given type,
619         # passing it the hook function to call.
620         my $type=shift;
621         my $sub=shift;
622
623         if (exists $hooks{$type}) {
624                 foreach my $id (keys %{$hooks{$type}}) {
625                         $sub->($hooks{$type}{$id}{call});
626                 }
627         }
628 } #}}}
629
630 sub globlist_to_pagespec ($) { #{{{
631         my @globlist=split(' ', shift);
632
633         my (@spec, @skip);
634         foreach my $glob (@globlist) {
635                 if ($glob=~/^!(.*)/) {
636                         push @skip, $glob;
637                 }
638                 else {
639                         push @spec, $glob;
640                 }
641         }
642
643         my $spec=join(" or ", @spec);
644         if (@skip) {
645                 my $skip=join(" and ", @skip);
646                 if (length $spec) {
647                         $spec="$skip and ($spec)";
648                 }
649                 else {
650                         $spec=$skip;
651                 }
652         }
653         return $spec;
654 } #}}}
655
656 sub is_globlist ($) { #{{{
657         my $s=shift;
658         $s=~/[^\s]+\s+([^\s]+)/ && $1 ne "and" && $1 ne "or";
659 } #}}}
660
661 sub safequote ($) { #{{{
662         my $s=shift;
663         $s=~s/[{}]//g;
664         return "q{$s}";
665 } #}}}
666
667 sub pagespec_merge ($$) { #{{{
668         my $a=shift;
669         my $b=shift;
670
671         return $a if $a eq $b;
672
673         # Support for old-style GlobLists.
674         if (is_globlist($a)) {
675                 $a=globlist_to_pagespec($a);
676         }
677         if (is_globlist($b)) {
678                 $b=globlist_to_pagespec($b);
679         }
680
681         return "($a) or ($b)";
682 } #}}}
683
684 sub pagespec_translate ($) { #{{{
685         # This assumes that $page is in scope in the function
686         # that evalulates the translated pagespec code.
687         my $spec=shift;
688
689         # Support for old-style GlobLists.
690         if (is_globlist($spec)) {
691                 $spec=globlist_to_pagespec($spec);
692         }
693
694         # Convert spec to perl code.
695         my $code="";
696         while ($spec=~m/\s*(\!|\(|\)|\w+\([^\)]+\)|[^\s()]+)\s*/ig) {
697                 my $word=$1;
698                 if (lc $word eq "and") {
699                         $code.=" &&";
700                 }
701                 elsif (lc $word eq "or") {
702                         $code.=" ||";
703                 }
704                 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
705                         $code.=" ".$word;
706                 }
707                 elsif ($word =~ /^(link|backlink|created_before|created_after|creation_month|creation_year|creation_day)\((.+)\)$/) {
708                         $code.=" match_$1(\$page, ".safequote($2).")";
709                 }
710                 else {
711                         $code.=" match_glob(\$page, ".safequote($word).")";
712                 }
713         }
714
715         return $code;
716 } #}}}
717
718 sub add_depends ($$) { #{{{
719         my $page=shift;
720         my $pagespec=shift;
721         
722         if (! exists $depends{$page}) {
723                 $depends{$page}=$pagespec;
724         }
725         else {
726                 $depends{$page}=pagespec_merge($depends{$page}, $pagespec);
727         }
728 } # }}}
729
730 sub pagespec_match ($$) { #{{{
731         my $page=shift;
732         my $spec=shift;
733
734         return eval pagespec_translate($spec);
735 } #}}}
736
737 sub match_glob ($$) { #{{{
738         my $page=shift;
739         my $glob=shift;
740
741         # turn glob into safe regexp
742         $glob=quotemeta($glob);
743         $glob=~s/\\\*/.*/g;
744         $glob=~s/\\\?/./g;
745
746         return $page=~/^$glob$/i;
747 } #}}}
748
749 sub match_link ($$) { #{{{
750         my $page=shift;
751         my $link=lc(shift);
752
753         my $links = $links{$page} or return undef;
754         foreach my $p (@$links) {
755                 return 1 if lc $p eq $link;
756         }
757         return 0;
758 } #}}}
759
760 sub match_backlink ($$) { #{{{
761         match_link(pop, pop);
762 } #}}}
763
764 sub match_created_before ($$) { #{{{
765         my $page=shift;
766         my $testpage=shift;
767
768         if (exists $pagectime{$testpage}) {
769                 return $pagectime{$page} < $pagectime{$testpage};
770         }
771         else {
772                 return 0;
773         }
774 } #}}}
775
776 sub match_created_after ($$) { #{{{
777         my $page=shift;
778         my $testpage=shift;
779
780         if (exists $pagectime{$testpage}) {
781                 return $pagectime{$page} > $pagectime{$testpage};
782         }
783         else {
784                 return 0;
785         }
786 } #}}}
787
788 sub match_creation_day ($$) { #{{{
789         return ((gmtime($pagectime{shift()}))[3] == shift);
790 } #}}}
791
792 sub match_creation_month ($$) { #{{{
793         return ((gmtime($pagectime{shift()}))[4] + 1 == shift);
794 } #}}}
795
796 sub match_creation_year ($$) { #{{{
797         return ((gmtime($pagectime{shift()}))[5] + 1900 == shift);
798 } #}}}
799
800 1