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