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