X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/bbe971881a7a3c03dfdb5312215c434e35eff94e..38d7e71c654f27cd2691537742e84b8113f1ad3c:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 833fcaaff..8e8336b99 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -5,7 +5,6 @@ package IkiWiki; use warnings; use strict; use IkiWiki; -use Encode; my (%backlinks, %rendered); our %brokenlinks; @@ -94,7 +93,8 @@ sub genpage ($$) { } if (defined $config{historyurl} && length $config{historyurl}) { my $u=$config{historyurl}; - $u=~s/\[\[file\]\]/$pagesources{$page}/g; + my $p=uri_escape_utf8($pagesources{$page}); + $u=~s/\[\[file\]\]/$p/g; $template->param(historyurl => $u); $actions++; } @@ -174,15 +174,15 @@ sub scan ($) { } delete $typedlinks{$page}; + # Preprocess in scan-only mode. + preprocess($page, $page, $content, 1); + run_hooks(scan => sub { shift->( page => $page, content => $content, ); }); - - # Preprocess in scan-only mode. - preprocess($page, $page, $content, 1); } else { will_render($file, $file, 1); @@ -292,12 +292,17 @@ sub find_src_files () { eval q{use File::Find}; error($@) if $@; - my ($page, $dir, $underlay); + eval q{use Cwd}; + die $@ if $@; + my $origdir=getcwd(); + my $abssrcdir=Cwd::abs_path($config{srcdir}); + + my ($page, $underlay); my $helper=sub { my $file=decode_utf8($_); return if -l $file || -d _; - $file=~s/^\Q$dir\E\/?//; + $file=~s/^\.\///; return if ! length $file; $page = pagename($file); if (! exists $pagesources{$page} && @@ -314,7 +319,7 @@ sub find_src_files () { if ($underlay) { # avoid underlaydir override attacks; see security.mdwn - if (! -l "$config{srcdir}/$f" && ! -e _) { + if (! -l "$abssrcdir/$f" && ! -e _) { if (! $pages{$page}) { push @files, $f; $pages{$page}=1; @@ -330,17 +335,24 @@ sub find_src_files () { } }; + chdir($config{srcdir}) || die "chdir $config{srcdir}: $!"; find({ no_chdir => 1, wanted => $helper, - }, $dir=$config{srcdir}); + }, '.'); + chdir($origdir) || die "chdir $origdir: $!"; + $underlay=1; foreach (@{$config{underlaydirs}}, $config{underlaydir}) { - find({ - no_chdir => 1, - wanted => $helper, - }, $dir=$_); + if (chdir($_)) { + find({ + no_chdir => 1, + wanted => $helper, + }, '.'); + chdir($origdir) || die "chdir: $!"; + } }; + return \@files, \%pages; } @@ -353,6 +365,35 @@ sub find_new_files ($) { foreach my $file (@$files) { my $page=pagename($file); + + if ($config{rcs} && $config{gettime} && + -e "$config{srcdir}/$file") { + if (! $times_noted) { + debug(sprintf(gettext("querying %s for file creation and modification times.."), $config{rcs})); + $times_noted=1; + } + + eval { + my $ctime=rcs_getctime($file); + if ($ctime > 0) { + $pagectime{$page}=$ctime; + } + }; + if ($@) { + print STDERR $@; + } + my $mtime; + eval { + $mtime=rcs_getmtime($file); + }; + if ($@) { + print STDERR $@; + } + elsif ($mtime > 0) { + utime($mtime, $mtime, "$config{srcdir}/$file"); + } + } + if (exists $pagesources{$page} && $pagesources{$page} ne $file) { # the page has changed its type $forcerebuild{$page}=1; @@ -362,34 +403,8 @@ sub find_new_files ($) { if (isinternal($page)) { push @internal_new, $file; } - elsif ($config{rcs}) { + else { push @new, $file; - if ($config{gettime} && -e "$config{srcdir}/$file") { - if (! $times_noted) { - debug(sprintf(gettext("querying %s for file creation and modification times.."), $config{rcs})); - $times_noted=1; - } - - eval { - my $ctime=rcs_getctime("$config{srcdir}/$file"); - if ($ctime > 0) { - $pagectime{$page}=$ctime; - } - }; - if ($@) { - print STDERR $@; - } - my $mtime; - eval { - $mtime=rcs_getmtime("$config{srcdir}/$file"); - }; - if ($@) { - print STDERR $@; - } - elsif ($mtime > 0) { - utime($mtime, $mtime, "$config{srcdir}/$file"); - } - } } $pagecase{lc $page}=$page; if (! exists $pagectime{$page}) { @@ -442,6 +457,7 @@ sub remove_del (@) { } delete $pagecase{lc $page}; + $delpagesources{$page}=$pagesources{$page}; delete $pagesources{$page}; } } @@ -743,7 +759,10 @@ sub refresh () { my ($new, $internal_new)=find_new_files($files); my ($del, $internal_del)=find_del_files($pages); my ($changed, $internal_changed)=find_changed($files); - run_hooks(needsbuild => sub { shift->($changed) }); + run_hooks(needsbuild => sub { + my $ret=shift->($changed, [@$del, @$internal_del]); + $changed=$ret if ref $ret eq 'ARRAY'; + }); my $oldlink_targets=calculate_old_links($changed, $del); foreach my $file (@$changed) {