summaryrefslogtreecommitdiff
path: root/IkiWiki/Render.pm
blob: a6b0f0617256db4aff42a38c92da43d0c3085b72 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. use Encode;
  7. my (%backlinks, %rendered);
  8. our %brokenlinks;
  9. my $links_calculated=0;
  10. sub calculate_links () {
  11. return if $links_calculated;
  12. %backlinks=%brokenlinks=();
  13. foreach my $page (keys %links) {
  14. foreach my $link (@{$links{$page}}) {
  15. my $bestlink=bestlink($page, $link);
  16. if (length $bestlink) {
  17. $backlinks{$bestlink}{$page}=1
  18. if $bestlink ne $page;
  19. }
  20. else {
  21. push @{$brokenlinks{$link}}, $page;
  22. }
  23. }
  24. }
  25. $links_calculated=1;
  26. }
  27. sub backlink_pages ($) {
  28. my $page=shift;
  29. calculate_links();
  30. return keys %{$backlinks{$page}};
  31. }
  32. sub backlinks ($) {
  33. my $page=shift;
  34. my @links;
  35. foreach my $p (backlink_pages($page)) {
  36. my $href=urlto($p, $page);
  37. # Trim common dir prefixes from both pages.
  38. my $p_trimmed=$p;
  39. my $page_trimmed=$page;
  40. my $dir;
  41. 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
  42. defined $dir &&
  43. $p_trimmed=~s/^\Q$dir\E// &&
  44. $page_trimmed=~s/^\Q$dir\E//;
  45. push @links, { url => $href, page => pagetitle($p_trimmed) };
  46. }
  47. return @links;
  48. }
  49. sub genpage ($$) {
  50. my $page=shift;
  51. my $content=shift;
  52. run_hooks(postscan => sub {
  53. shift->(page => $page, content => $content);
  54. });
  55. my $templatefile;
  56. run_hooks(templatefile => sub {
  57. return if defined $templatefile;
  58. my $file=shift->(page => $page);
  59. if (defined $file && defined template_file($file)) {
  60. $templatefile=$file;
  61. }
  62. });
  63. my $template=template(defined $templatefile ? $templatefile : 'page.tmpl', blind_cache => 1);
  64. my $actions=0;
  65. if (length $config{cgiurl}) {
  66. if (IkiWiki->can("cgi_editpage")) {
  67. $template->param(editurl => cgiurl(do => "edit", page => $page));
  68. $actions++;
  69. }
  70. if (exists $hooks{auth}) {
  71. $template->param(prefsurl => cgiurl(do => "prefs"));
  72. $actions++;
  73. }
  74. }
  75. if (defined $config{historyurl} && length $config{historyurl}) {
  76. my $u=$config{historyurl};
  77. $u=~s/\[\[file\]\]/$pagesources{$page}/g;
  78. $template->param(historyurl => $u);
  79. $actions++;
  80. }
  81. if ($config{discussion}) {
  82. if ($page !~ /.*\/\Q$config{discussionpage}\E$/i &&
  83. (length $config{cgiurl} ||
  84. exists $links{$page."/".$config{discussionpage}})) {
  85. $template->param(discussionlink => htmllink($page, $page, $config{discussionpage}, noimageinline => 1, forcesubpage => 1));
  86. $actions++;
  87. }
  88. }
  89. if ($actions) {
  90. $template->param(have_actions => 1);
  91. }
  92. my @backlinks=sort { $a->{page} cmp $b->{page} } backlinks($page);
  93. my ($backlinks, $more_backlinks);
  94. if (@backlinks <= $config{numbacklinks} || ! $config{numbacklinks}) {
  95. $backlinks=\@backlinks;
  96. $more_backlinks=[];
  97. }
  98. else {
  99. $backlinks=[@backlinks[0..$config{numbacklinks}-1]];
  100. $more_backlinks=[@backlinks[$config{numbacklinks}..$#backlinks]];
  101. }
  102. $template->param(
  103. title => $page eq 'index'
  104. ? $config{wikiname}
  105. : pagetitle(basename($page)),
  106. wikiname => $config{wikiname},
  107. content => $content,
  108. backlinks => $backlinks,
  109. more_backlinks => $more_backlinks,
  110. mtime => displaytime($pagemtime{$page}),
  111. ctime => displaytime($pagectime{$page}),
  112. baseurl => baseurl($page),
  113. );
  114. run_hooks(pagetemplate => sub {
  115. shift->(page => $page, destpage => $page, template => $template);
  116. });
  117. $content=$template->output;
  118. run_hooks(format => sub {
  119. $content=shift->(
  120. page => $page,
  121. content => $content,
  122. );
  123. });
  124. return $content;
  125. }
  126. sub scan ($) {
  127. my $file=shift;
  128. debug(sprintf(gettext("scanning %s"), $file));
  129. my $type=pagetype($file);
  130. if (defined $type) {
  131. my $srcfile=srcfile($file);
  132. my $content=readfile($srcfile);
  133. my $page=pagename($file);
  134. will_render($page, htmlpage($page), 1);
  135. if ($config{discussion}) {
  136. # Discussion links are a special case since they're
  137. # not in the text of the page, but on its template.
  138. $links{$page}=[ $page."/".lc($config{discussionpage}) ];
  139. }
  140. else {
  141. $links{$page}=[];
  142. }
  143. delete $typedlinks{$page};
  144. run_hooks(scan => sub {
  145. shift->(
  146. page => $page,
  147. content => $content,
  148. );
  149. });
  150. # Preprocess in scan-only mode.
  151. preprocess($page, $page, $content, 1);
  152. }
  153. else {
  154. will_render($file, $file, 1);
  155. }
  156. }
  157. sub fast_file_copy (@) {
  158. my $srcfile=shift;
  159. my $destfile=shift;
  160. my $srcfd=shift;
  161. my $destfd=shift;
  162. my $cleanup=shift;
  163. my $blksize = 16384;
  164. my ($len, $buf, $written);
  165. while ($len = sysread $srcfd, $buf, $blksize) {
  166. if (! defined $len) {
  167. next if $! =~ /^Interrupted/;
  168. error("failed to read $srcfile: $!", $cleanup);
  169. }
  170. my $offset = 0;
  171. while ($len) {
  172. defined($written = syswrite $destfd, $buf, $len, $offset)
  173. or error("failed to write $destfile: $!", $cleanup);
  174. $len -= $written;
  175. $offset += $written;
  176. }
  177. }
  178. }
  179. sub render ($$) {
  180. my $file=shift;
  181. return if $rendered{$file};
  182. debug(shift);
  183. $rendered{$file}=1;
  184. my $type=pagetype($file);
  185. my $srcfile=srcfile($file);
  186. if (defined $type) {
  187. my $page=pagename($file);
  188. delete $depends{$page};
  189. delete $depends_simple{$page};
  190. will_render($page, htmlpage($page), 1);
  191. return if $type=~/^_/;
  192. my $content=htmlize($page, $page, $type,
  193. linkify($page, $page,
  194. preprocess($page, $page,
  195. filter($page, $page,
  196. readfile($srcfile)))));
  197. my $output=htmlpage($page);
  198. writefile($output, $config{destdir}, genpage($page, $content));
  199. }
  200. else {
  201. delete $depends{$file};
  202. delete $depends_simple{$file};
  203. will_render($file, $file, 1);
  204. if ($config{hardlink}) {
  205. # only hardlink if owned by same user
  206. my @stat=stat($srcfile);
  207. if ($stat[4] == $>) {
  208. prep_writefile($file, $config{destdir});
  209. unlink($config{destdir}."/".$file);
  210. if (link($srcfile, $config{destdir}."/".$file)) {
  211. return;
  212. }
  213. }
  214. # if hardlink fails, fall back to copying
  215. }
  216. my $srcfd=readfile($srcfile, 1, 1);
  217. writefile($file, $config{destdir}, undef, 1, sub {
  218. fast_file_copy($srcfile, $file, $srcfd, @_);
  219. });
  220. }
  221. }
  222. sub prune ($) {
  223. my $file=shift;
  224. unlink($file);
  225. my $dir=dirname($file);
  226. while (rmdir($dir)) {
  227. $dir=dirname($dir);
  228. }
  229. }
  230. sub srcdir_check () {
  231. # security check, avoid following symlinks in the srcdir path by default
  232. my $test=$config{srcdir};
  233. while (length $test) {
  234. if (-l $test && ! $config{allow_symlinks_before_srcdir}) {
  235. error(sprintf(gettext("symlink found in srcdir path (%s) -- set allow_symlinks_before_srcdir to allow this"), $test));
  236. }
  237. unless ($test=~s/\/+$//) {
  238. $test=dirname($test);
  239. }
  240. }
  241. }
  242. sub find_src_files () {
  243. my @files;
  244. my %pages;
  245. eval q{use File::Find};
  246. error($@) if $@;
  247. find({
  248. no_chdir => 1,
  249. wanted => sub {
  250. my $file=decode_utf8($_);
  251. $file=~s/^\Q$config{srcdir}\E\/?//;
  252. return if -l $_ || -d _ || ! length $file;
  253. my $page = pagename($file);
  254. if (! exists $pagesources{$page} &&
  255. file_pruned($file)) {
  256. $File::Find::prune=1;
  257. return;
  258. }
  259. my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
  260. if (! defined $f) {
  261. warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
  262. }
  263. else {
  264. push @files, $f;
  265. if ($pages{$page}) {
  266. debug(sprintf(gettext("%s has multiple possible source pages"), $page));
  267. }
  268. $pages{$page}=1;
  269. }
  270. },
  271. }, $config{srcdir});
  272. foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
  273. find({
  274. no_chdir => 1,
  275. wanted => sub {
  276. my $file=decode_utf8($_);
  277. $file=~s/^\Q$dir\E\/?//;
  278. return if -l $_ || -d _ || ! length $file;
  279. my $page=pagename($file);
  280. if (! exists $pagesources{$page} &&
  281. file_pruned($file)) {
  282. $File::Find::prune=1;
  283. return;
  284. }
  285. my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
  286. if (! defined $f) {
  287. warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
  288. }
  289. else {
  290. # avoid underlaydir override
  291. # attacks; see security.mdwn
  292. if (! -l "$config{srcdir}/$f" &&
  293. ! -e _) {
  294. if (! $pages{$page}) {
  295. push @files, $f;
  296. $pages{$page}=1;
  297. }
  298. }
  299. }
  300. },
  301. }, $dir);
  302. };
  303. return \@files, \%pages;
  304. }
  305. sub find_new_files ($) {
  306. my $files=shift;
  307. my @new;
  308. my @internal_new;
  309. my $times_noted;
  310. foreach my $file (@$files) {
  311. my $page=pagename($file);
  312. if (exists $pagesources{$page} && $pagesources{$page} ne $file) {
  313. # the page has changed its type
  314. $forcerebuild{$page}=1;
  315. }
  316. $pagesources{$page}=$file;
  317. if (! $pagemtime{$page}) {
  318. if (isinternal($page)) {
  319. push @internal_new, $file;
  320. }
  321. elsif ($config{rcs}) {
  322. if (! $times_noted) {
  323. debug(sprintf(gettext("querying %s for file creation and modification times.."), $config{rcs}));
  324. $times_noted=1;
  325. }
  326. push @new, $file;
  327. if ($config{gettime} && -e "$config{srcdir}/$file") {
  328. eval {
  329. my $ctime=rcs_getctime("$config{srcdir}/$file");
  330. if ($ctime > 0) {
  331. $pagectime{$page}=$ctime;
  332. }
  333. };
  334. if ($@) {
  335. print STDERR $@;
  336. }
  337. my $mtime;
  338. eval {
  339. $mtime=rcs_getmtime("$config{srcdir}/$file");
  340. };
  341. if ($@) {
  342. print STDERR $@;
  343. }
  344. elsif ($mtime > 0) {
  345. utime($mtime, $mtime, "$config{srcdir}/$file");
  346. }
  347. }
  348. }
  349. $pagecase{lc $page}=$page;
  350. if (! exists $pagectime{$page}) {
  351. $pagectime{$page}=(srcfile_stat($file))[10];
  352. }
  353. }
  354. }
  355. return \@new, \@internal_new;
  356. }
  357. sub find_del_files ($) {
  358. my $pages=shift;
  359. my @del;
  360. my @internal_del;
  361. foreach my $page (keys %pagemtime) {
  362. if (! $pages->{$page}) {
  363. if (isinternal($page)) {
  364. push @internal_del, $pagesources{$page};
  365. }
  366. else {
  367. push @del, $pagesources{$page};
  368. }
  369. $links{$page}=[];
  370. delete $typedlinks{$page};
  371. $renderedfiles{$page}=[];
  372. $pagemtime{$page}=0;
  373. }
  374. }
  375. return \@del, \@internal_del;
  376. }
  377. sub remove_del (@) {
  378. foreach my $file (@_) {
  379. my $page=pagename($file);
  380. if (! isinternal($page)) {
  381. debug(sprintf(gettext("removing old page %s"), $page));
  382. }
  383. foreach my $old (@{$oldrenderedfiles{$page}}) {
  384. prune($config{destdir}."/".$old);
  385. }
  386. foreach my $source (keys %destsources) {
  387. if ($destsources{$source} eq $page) {
  388. delete $destsources{$source};
  389. }
  390. }
  391. delete $pagecase{lc $page};
  392. delete $pagesources{$page};
  393. }
  394. }
  395. sub find_changed ($) {
  396. my $files=shift;
  397. my @changed;
  398. my @internal_changed;
  399. foreach my $file (@$files) {
  400. my $page=pagename($file);
  401. my ($srcfile, @stat)=srcfile_stat($file);
  402. if (! exists $pagemtime{$page} ||
  403. $stat[9] > $pagemtime{$page} ||
  404. $forcerebuild{$page}) {
  405. $pagemtime{$page}=$stat[9];
  406. if (isinternal($page)) {
  407. # Preprocess internal page in scan-only mode.
  408. preprocess($page, $page, readfile($srcfile), 1);
  409. push @internal_changed, $file;
  410. }
  411. else {
  412. push @changed, $file;
  413. }
  414. }
  415. }
  416. return \@changed, \@internal_changed;
  417. }
  418. sub calculate_old_links ($$) {
  419. my ($changed, $del)=@_;
  420. my %oldlink_targets;
  421. foreach my $file (@$changed, @$del) {
  422. my $page=pagename($file);
  423. if (exists $oldlinks{$page}) {
  424. foreach my $l (@{$oldlinks{$page}}) {
  425. $oldlink_targets{$page}{$l}=bestlink($page, $l);
  426. }
  427. }
  428. }
  429. return \%oldlink_targets;
  430. }
  431. sub derender_internal ($) {
  432. my $file=shift;
  433. my $page=pagename($file);
  434. delete $depends{$page};
  435. delete $depends_simple{$page};
  436. foreach my $old (@{$renderedfiles{$page}}) {
  437. delete $destsources{$old};
  438. }
  439. $renderedfiles{$page}=[];
  440. }
  441. sub render_linkers ($) {
  442. my $f=shift;
  443. my $p=pagename($f);
  444. foreach my $page (keys %{$backlinks{$p}}) {
  445. my $file=$pagesources{$page};
  446. render($file, sprintf(gettext("building %s, which links to %s"), $file, $p));
  447. }
  448. }
  449. sub remove_unrendered () {
  450. foreach my $src (keys %rendered) {
  451. my $page=pagename($src);
  452. foreach my $file (@{$oldrenderedfiles{$page}}) {
  453. if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
  454. debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page));
  455. prune($config{destdir}."/".$file);
  456. }
  457. }
  458. }
  459. }
  460. sub link_types_changed ($$) {
  461. # each is of the form { type => { link => 1 } }
  462. my $new = shift;
  463. my $old = shift;
  464. return 0 if !defined $new && !defined $old;
  465. return 1 if !defined $new || !defined $old;
  466. while (my ($type, $links) = each %$new) {
  467. foreach my $link (keys %$links) {
  468. return 1 unless exists $old->{$type}{$link};
  469. }
  470. }
  471. while (my ($type, $links) = each %$old) {
  472. foreach my $link (keys %$links) {
  473. return 1 unless exists $new->{$type}{$link};
  474. }
  475. }
  476. return 0;
  477. }
  478. sub calculate_changed_links ($$$) {
  479. my ($changed, $del, $oldlink_targets)=@_;
  480. my (%backlinkchanged, %linkchangers);
  481. foreach my $file (@$changed, @$del) {
  482. my $page=pagename($file);
  483. if (exists $links{$page}) {
  484. foreach my $l (@{$links{$page}}) {
  485. my $target=bestlink($page, $l);
  486. if (! exists $oldlink_targets->{$page}{$l} ||
  487. $target ne $oldlink_targets->{$page}{$l}) {
  488. $backlinkchanged{$target}=1;
  489. $linkchangers{lc($page)}=1;
  490. }
  491. delete $oldlink_targets->{$page}{$l};
  492. }
  493. }
  494. if (exists $oldlink_targets->{$page} &&
  495. %{$oldlink_targets->{$page}}) {
  496. foreach my $target (values %{$oldlink_targets->{$page}}) {
  497. $backlinkchanged{$target}=1;
  498. }
  499. $linkchangers{lc($page)}=1;
  500. }
  501. # we currently assume that changing the type of a link doesn't
  502. # change backlinks
  503. if (!exists $linkchangers{lc($page)}) {
  504. if (link_types_changed($typedlinks{$page}, $oldtypedlinks{$page})) {
  505. $linkchangers{lc($page)}=1;
  506. }
  507. }
  508. }
  509. return \%backlinkchanged, \%linkchangers;
  510. }
  511. sub render_dependent ($$$$$$$) {
  512. my ($files, $new, $internal_new, $del, $internal_del,
  513. $internal_changed, $linkchangers)=@_;
  514. my @changed=(keys %rendered, @$del);
  515. my @exists_changed=(@$new, @$del);
  516. my %lc_changed = map { lc(pagename($_)) => 1 } @changed;
  517. my %lc_exists_changed = map { lc(pagename($_)) => 1 } @exists_changed;
  518. foreach my $f (@$files) {
  519. next if $rendered{$f};
  520. my $p=pagename($f);
  521. my $reason = undef;
  522. if (exists $depends_simple{$p}) {
  523. foreach my $d (keys %{$depends_simple{$p}}) {
  524. if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT &&
  525. $lc_changed{$d})
  526. ||
  527. ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE &&
  528. $lc_exists_changed{$d})
  529. ||
  530. ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_LINKS &&
  531. $linkchangers->{$d})
  532. ) {
  533. $reason = $d;
  534. last;
  535. }
  536. }
  537. }
  538. if (exists $depends{$p} && ! defined $reason) {
  539. foreach my $dep (keys %{$depends{$p}}) {
  540. my $sub=pagespec_translate($dep);
  541. next unless defined $sub;
  542. # only consider internal files
  543. # if the page explicitly depends
  544. # on such files
  545. my $internal_dep=$dep =~ /internal\(/;
  546. my $in=sub {
  547. my $list=shift;
  548. my $type=shift;
  549. foreach my $file (@$list) {
  550. next if $file eq $f;
  551. my $page=pagename($file);
  552. if ($sub->($page, location => $p)) {
  553. if ($type == $IkiWiki::DEPEND_LINKS) {
  554. next unless $linkchangers->{lc($page)};
  555. }
  556. return $page;
  557. }
  558. }
  559. return undef;
  560. };
  561. if ($depends{$p}{$dep} & $IkiWiki::DEPEND_CONTENT) {
  562. last if $reason =
  563. $in->(\@changed, $IkiWiki::DEPEND_CONTENT);
  564. last if $internal_dep && ($reason =
  565. $in->($internal_new, $IkiWiki::DEPEND_CONTENT) ||
  566. $in->($internal_del, $IkiWiki::DEPEND_CONTENT) ||
  567. $in->($internal_changed, $IkiWiki::DEPEND_CONTENT));
  568. }
  569. if ($depends{$p}{$dep} & $IkiWiki::DEPEND_PRESENCE) {
  570. last if $reason =
  571. $in->(\@exists_changed, $IkiWiki::DEPEND_PRESENCE);
  572. last if $internal_dep && ($reason =
  573. $in->($internal_new, $IkiWiki::DEPEND_PRESENCE) ||
  574. $in->($internal_del, $IkiWiki::DEPEND_PRESENCE));
  575. }
  576. if ($depends{$p}{$dep} & $IkiWiki::DEPEND_LINKS) {
  577. last if $reason =
  578. $in->(\@changed, $IkiWiki::DEPEND_LINKS);
  579. last if $internal_dep && ($reason =
  580. $in->($internal_new, $IkiWiki::DEPEND_LINKS) ||
  581. $in->($internal_del, $IkiWiki::DEPEND_LINKS) ||
  582. $in->($internal_changed, $IkiWiki::DEPEND_LINKS));
  583. }
  584. }
  585. }
  586. if (defined $reason) {
  587. render($f, sprintf(gettext("building %s, which depends on %s"), $f, $reason));
  588. return 1;
  589. }
  590. }
  591. return 0;
  592. }
  593. sub render_backlinks ($) {
  594. my $backlinkchanged=shift;
  595. foreach my $link (keys %$backlinkchanged) {
  596. my $linkfile=$pagesources{$link};
  597. if (defined $linkfile) {
  598. render($linkfile, sprintf(gettext("building %s, to update its backlinks"), $linkfile));
  599. }
  600. }
  601. }
  602. sub refresh () {
  603. srcdir_check();
  604. run_hooks(refresh => sub { shift->() });
  605. my ($files, $pages)=find_src_files();
  606. my ($new, $internal_new)=find_new_files($files);
  607. my ($del, $internal_del)=find_del_files($pages);
  608. my ($changed, $internal_changed)=find_changed($files);
  609. run_hooks(needsbuild => sub { shift->($changed) });
  610. my $oldlink_targets=calculate_old_links($changed, $del);
  611. foreach my $file (@$changed) {
  612. scan($file);
  613. }
  614. calculate_links();
  615. remove_del(@$del, @$internal_del);
  616. foreach my $file (@$changed) {
  617. render($file, sprintf(gettext("building %s"), $file));
  618. }
  619. foreach my $file (@$internal_new, @$internal_del, @$internal_changed) {
  620. derender_internal($file);
  621. }
  622. my ($backlinkchanged, $linkchangers)=calculate_changed_links($changed,
  623. $del, $oldlink_targets);
  624. foreach my $file (@$new, @$del) {
  625. render_linkers($file);
  626. }
  627. if (@$changed || @$internal_changed ||
  628. @$del || @$internal_del || @$internal_new) {
  629. 1 while render_dependent($files, $new, $internal_new,
  630. $del, $internal_del, $internal_changed,
  631. $linkchangers);
  632. }
  633. render_backlinks($backlinkchanged);
  634. remove_unrendered();
  635. if (@$del) {
  636. run_hooks(delete => sub { shift->(@$del) });
  637. }
  638. if (%rendered) {
  639. run_hooks(change => sub { shift->(keys %rendered) });
  640. }
  641. }
  642. sub clean_rendered {
  643. lockwiki();
  644. loadindex();
  645. remove_unrendered();
  646. foreach my $page (keys %oldrenderedfiles) {
  647. foreach my $file (@{$oldrenderedfiles{$page}}) {
  648. prune($config{destdir}."/".$file);
  649. }
  650. }
  651. }
  652. sub commandline_render () {
  653. lockwiki();
  654. loadindex();
  655. unlockwiki();
  656. my $srcfile=possibly_foolish_untaint($config{render});
  657. my $file=$srcfile;
  658. $file=~s/\Q$config{srcdir}\E\/?//;
  659. my $type=pagetype($file);
  660. die sprintf(gettext("ikiwiki: cannot build %s"), $srcfile)."\n" unless defined $type;
  661. my $content=readfile($srcfile);
  662. my $page=pagename($file);
  663. $pagesources{$page}=$file;
  664. $content=filter($page, $page, $content);
  665. $content=preprocess($page, $page, $content);
  666. $content=linkify($page, $page, $content);
  667. $content=htmlize($page, $page, $type, $content);
  668. $pagemtime{$page}=(stat($srcfile))[9];
  669. $pagectime{$page}=$pagemtime{$page} if ! exists $pagectime{$page};
  670. print genpage($page, $content);
  671. exit 0;
  672. }
  673. 1