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