X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/63995039bee70bbc1209addfd0095d2ae8342fd7..1fb1d6c1830a3d80bd6940bc2b24ca4f673e1bed:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 92993fd95..4fefadf09 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -55,8 +55,8 @@ sub parentlinks ($) { #{{{ my $path=""; my $title=$config{wikiname}; - return if $page eq 'index'; # toplevel foreach my $dir (split("/", $page)) { + next if $dir eq 'index'; push @ret, { url => urlto($path, $page), page => $title }; $path.="/".$dir; $title=pagetitle($dir); @@ -64,12 +64,19 @@ sub parentlinks ($) { #{{{ return @ret; } #}}} -sub genpage ($$$) { #{{{ +sub genpage ($$) { #{{{ my $page=shift; my $content=shift; - my $mtime=shift; - my $template=template("page.tmpl", blind_cache => 1); + my $templatefile; + run_hooks(templatefile => sub { + return if defined $templatefile; + my $file=shift->(page => $page); + if (defined $file && defined template_file($file)) { + $templatefile=$file; + } + }); + my $template=template(defined $templatefile ? $templatefile : 'page.tmpl', blind_cache => 1); my $actions=0; if (length $config{cgiurl}) { @@ -121,7 +128,7 @@ sub genpage ($$$) { #{{{ content => $content, backlinks => $backlinks, more_backlinks => $more_backlinks, - mtime => displaytime($mtime), + mtime => displaytime($pagemtime{$page}), baseurl => baseurl($page), ); @@ -159,7 +166,7 @@ sub scan ($) { #{{{ # Always needs to be done, since filters might add links # to the content. - $content=filter($page, $content); + $content=filter($page, $page, $content); my @links; while ($content =~ /(? 1, - wanted => sub { - $_=decode_utf8($_); - if (file_pruned($_, $config{underlaydir})) { - $File::Find::prune=1; - } - elsif (! -d $_ && ! -l $_) { - my ($f)=/$config{wiki_file_regexp}/; # untaint - if (! defined $f) { - warn(sprintf(gettext("skipping bad filename %s"), $_)."\n"); + foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) { + find({ + no_chdir => 1, + wanted => sub { + $_=decode_utf8($_); + if (file_pruned($_, $dir)) { + $File::Find::prune=1; } - else { - # Don't add pages that are in the - # srcdir. - $f=~s/^\Q$config{underlaydir}\E\/?//; - if (! -e "$config{srcdir}/$f" && - ! -l "$config{srcdir}/$f") { - my $page=pagename($f); - if (! $exists{$page}) { - push @files, $f; - $exists{$page}=1; + elsif (! -d $_ && ! -l $_) { + my ($f)=/$config{wiki_file_regexp}/; # untaint + if (! defined $f) { + warn(sprintf(gettext("skipping bad filename %s"), $_)."\n"); + } + else { + $f=~s/^\Q$dir\E\/?//; + # avoid underlaydir + # override attacks; see + # security.mdwn + if (! -e "$config{srcdir}/$f" && + ! -l "$config{srcdir}/$f") { + my $page=pagename($f); + if (! $exists{$page}) { + push @files, $f; + $exists{$page}=1; + } } } } - } - }, - }, $config{underlaydir}); + }, + }, $dir); + }; my %rendered; @@ -320,6 +343,11 @@ sub refresh () { #{{{ prune($config{destdir}."/".$_) foreach @{$oldrenderedfiles{$page}}; delete $pagesources{$page}; + foreach (keys %destsources) { + if ($destsources{$_} eq $page) { + delete $destsources{$_}; + } + } } } @@ -338,7 +366,7 @@ sub refresh () { #{{{ } run_hooks(needsbuild => sub { shift->(\@needsbuild) }); - # scan and rendder files + # scan and render files foreach my $file (@needsbuild) { debug(sprintf(gettext("scanning %s"), $file)); scan($file); @@ -454,12 +482,13 @@ sub commandline_render () { #{{{ my $content=readfile($srcfile); my $page=pagename($file); $pagesources{$page}=$file; - $content=filter($page, $content); + $content=filter($page, $page, $content); $content=preprocess($page, $page, $content); $content=linkify($page, $page, $content); $content=htmlize($page, $type, $content); + $pagemtime{$page}=mtime($srcfile); - print genpage($page, $content, mtime($srcfile)); + print genpage($page, $content); exit 0; } #}}}