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