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