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