aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-10-08 21:56:50 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-10-08 21:56:50 +0000
commitcefbe6210f4e89984bb40062e4f9787b7372dd52 (patch)
tree5fd7195d25c124eef90e8d3e66b44ed1fbd8d644
parent118c481766669959c34c30a79aa2667cdcc7aebc (diff)
downloadikiwiki-cefbe6210f4e89984bb40062e4f9787b7372dd52.tar
ikiwiki-cefbe6210f4e89984bb40062e4f9787b7372dd52.tar.gz
* Change %renderedfiles to store an array of files rendered from a given
source file, to allow tracking of extra rendered files like rss feeds. * Note that plugins that accessed this variable will need to be updated! The plugin interface has been increased to version 1.01 for this change. * Add will_render function to the plugin interface, used to register that a page renders a destination file, and do some security checks. * Use will_render in the inline and linkmap plugins. * Previously but no longer rendered files will be cleaned up. * You will need to rebuild your wiki on upgrade to this version.
-rw-r--r--IkiWiki.pm36
-rw-r--r--IkiWiki/Plugin/inline.pm10
-rw-r--r--IkiWiki/Plugin/linkmap.pm6
-rw-r--r--IkiWiki/Plugin/search.pm3
-rw-r--r--IkiWiki/Render.pm33
-rw-r--r--debian/NEWS15
-rw-r--r--debian/changelog13
-rwxr-xr-xdebian/postinst2
-rw-r--r--doc/bugs/rss_feed_cleanup_on_delete.mdwn2
-rw-r--r--doc/plugins/contrib/img/discussion.mdwn4
-rw-r--r--doc/plugins/write.mdwn10
-rwxr-xr-xt/linkify.t2
12 files changed, 92 insertions, 44 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 5c62c7f9b..6c0bc1f60 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -8,14 +8,15 @@ use HTML::Entities;
use open qw{:utf8 :std};
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
- %renderedfiles %pagesources %depends %hooks %forcerebuild};
+ %renderedfiles %oldrenderedfiles %pagesources %depends %hooks
+ %forcerebuild};
use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime
%config %links %renderedfiles %pagesources);
-our $VERSION = 1.00;
+our $VERSION = 1.01;
# Optimisation.
use Memoize;
@@ -261,6 +262,25 @@ sub writefile ($$$;$) { #{{{
close OUT;
} #}}}
+sub will_render ($$;$) { #{{{
+ my $page=shift;
+ my $dest=shift;
+ my $clear=shift;
+
+ # Important security check.
+ if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
+ ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
+ error("$config{destdir}/$dest independently created, not overwriting with version from $page");
+ }
+
+ if (! $clear) {
+ $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
+ }
+ else {
+ $renderedfiles{$page}=[$dest];
+ }
+} #}}}
+
sub bestlink ($$) { #{{{
my $page=shift;
my $link=shift;
@@ -366,10 +386,10 @@ sub htmllink ($$$;$$$) { #{{{
# TODO BUG: %renderedfiles may not have it, if the linked to page
# was also added and isn't yet rendered! Note that this bug is
# masked by the bug that makes all new files be rendered twice.
- if (! grep { $_ eq $bestlink } values %renderedfiles) {
+ if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) {
$bestlink=htmlpage($bestlink);
}
- if (! grep { $_ eq $bestlink } values %renderedfiles) {
+ if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) {
return "<span><a href=\"".
cgiurl(do => "create", page => lc($link), from => $page).
"\">?</a>$linktext</span>"
@@ -529,6 +549,7 @@ sub loadindex () { #{{{
chomp;
my %items;
$items{link}=[];
+ $items{dest}=[];
foreach my $i (split(/ /, $_)) {
my ($item, $val)=split(/=/, $i, 2);
push @{$items{$item}}, decode_entities($val);
@@ -543,7 +564,8 @@ sub loadindex () { #{{{
$oldlinks{$page}=[@{$items{link}}];
$links{$page}=[@{$items{link}}];
$depends{$page}=$items{depends}[0] if exists $items{depends};
- $renderedfiles{$page}=$items{dest}[0];
+ $renderedfiles{$page}=[@{$items{dest}}];
+ $oldrenderedfiles{$page}=[@{$items{dest}}];
$pagecase{lc $page}=$page;
}
$pagectime{$page}=$items{ctime}[0];
@@ -563,8 +585,8 @@ sub saveindex () { #{{{
next unless $oldpagemtime{$page};
my $line="mtime=$oldpagemtime{$page} ".
"ctime=$pagectime{$page} ".
- "src=$pagesources{$page} ".
- "dest=$renderedfiles{$page}";
+ "src=$pagesources{$page}";
+ $line.=" dest=$_" foreach @{$renderedfiles{$page}};
$line.=" link=$_" foreach @{$links{$page}};
if (exists $depends{$page}) {
$line.=" depends=".encode_entities($depends{$page}, " \t\n");
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 868f3816f..c7cafee12 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -4,7 +4,7 @@ package IkiWiki::Plugin::inline;
use warnings;
use strict;
-use IkiWiki;
+use IkiWiki 1.00;
use IkiWiki::Render; # for displaytime
use URI;
@@ -154,10 +154,8 @@ sub preprocess_inline (@) { #{{{
}
}
- # TODO: should really add this to renderedfiles and call
- # check_overwrite, but currently renderedfiles
- # only supports listing one file per page.
if ($config{rss} && $rss) {
+ will_render($params{page}, rsspage($params{page}));
writefile(rsspage($params{page}), $config{destdir},
genrss($desc, $params{page}, @list));
$toping{$params{page}}=1 unless $config{rebuild};
@@ -233,9 +231,7 @@ sub genrss ($$@) { #{{{
my $itemtemplate=template("rssitem.tmpl", blind_cache => 1);
my $content="";
foreach my $p (@pages) {
- next unless exists $renderedfiles{$p};
-
- my $u=URI->new(encode_utf8("$config{url}/$renderedfiles{$p}"));
+ my $u=URI->new(encode_utf8($config{url}."/".htmlpage($p)));
$itemtemplate->param(
title => pagetitle(basename($p)),
diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
index 497b1ef43..d7dffc941 100644
--- a/IkiWiki/Plugin/linkmap.pm
+++ b/IkiWiki/Plugin/linkmap.pm
@@ -57,12 +57,10 @@ sub genmap ($) { #{{{
# Use ikiwiki's function to create the file, this makes sure needed
# subdirs are there and does some sanity checking.
- writefile("$params{page}.png", $config{destdir}, "");
+ will_render($params{page}, $params{page}.".png");
+ writefile($params{page}.".png", $config{destdir}, "");
# Run dot to create the graphic and get the map data.
- # TODO: should really add the png to renderedfiles and call
- # check_overwrite, but currently renderedfiles
- # only supports listing one file per page.
my $pid;
my $sigpipe=0;;
$SIG{PIPE}=sub { $sigpipe=1 };
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index 5a4dfd491..a57a84048 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -63,7 +63,8 @@ sub change (@) { #{{{
debug("updating hyperestraier search index");
estcmd("gather -cm -bc -cl -sd",
map {
- Encode::encode_utf8($config{destdir}."/".$renderedfiles{pagename($_)})
+ Encode::encode_utf8($config{destdir}."/".$_)
+ foreach @{$renderedfiles{pagename($_)}};
} @_
);
estcfg();
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 48a25bef7..deec539ae 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -113,17 +113,6 @@ sub genpage ($$$) { #{{{
return $content;
} #}}}
-sub check_overwrite ($$) { #{{{
- # Important security check. Make sure to call this before saving
- # any files to the source directory.
- my $dest=shift;
- my $src=shift;
-
- if (! exists $renderedfiles{$src} && -e $dest && ! $config{rebuild}) {
- error("$dest already exists and was not rendered from $src before");
- }
-} #}}}
-
sub mtime ($) { #{{{
my $file=shift;
@@ -157,6 +146,7 @@ sub render ($) { #{{{
my $content=readfile($srcfile);
my $page=pagename($file);
delete $depends{$page};
+ will_render($page, htmlpage($page), 1);
$content=filter($page, $content);
@@ -166,20 +156,17 @@ sub render ($) { #{{{
$content=linkify($page, $page, $content);
$content=htmlize($page, $type, $content);
- check_overwrite("$config{destdir}/".htmlpage($page), $page);
writefile(htmlpage($page), $config{destdir},
genpage($page, $content, mtime($srcfile)));
$oldpagemtime{$page}=time;
- $renderedfiles{$page}=htmlpage($page);
}
else {
my $content=readfile($srcfile, 1);
$links{$file}=[];
delete $depends{$file};
- check_overwrite("$config{destdir}/$file", $file);
+ will_render($file, $file, 1);
writefile($file, $config{destdir}, $content, 1);
$oldpagemtime{$file}=time;
- $renderedfiles{$file}=$file;
}
} #}}}
@@ -269,9 +256,10 @@ sub refresh () { #{{{
if (! $exists{$page}) {
debug("removing old page $page");
push @del, $pagesources{$page};
- prune($config{destdir}."/".$renderedfiles{$page});
- delete $renderedfiles{$page};
+ $renderedfiles{$page}=[];
$oldpagemtime{$page}=0;
+ prune($config{destdir}."/".$_)
+ foreach @{$oldrenderedfiles{$page}};
delete $pagesources{$page};
}
}
@@ -366,6 +354,17 @@ FILE: foreach my $file (@files) {
}
}
+ # Remove no longer rendered files.
+ foreach my $src (keys %rendered) {
+ my $page=pagename($src);
+ foreach my $file (@{$oldrenderedfiles{$page}}) {
+ if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
+ debug("removing $file, no longer rendered by $page");
+ prune($config{destdir}."/".$file);
+ }
+ }
+ }
+
if (@del) {
run_hooks(delete => sub { shift->(@del) });
}
diff --git a/debian/NEWS b/debian/NEWS
index a921d0c0e..f3556d622 100644
--- a/debian/NEWS
+++ b/debian/NEWS
@@ -1,8 +1,21 @@
+ikiwiki (1.29) unstable; urgency=low
+
+ Wikis need to be rebuilt on upgrade to this version. If you listed your wiki
+ in /etc/ikiwiki/wikilist this will be done automatically when the Debian
+ package is upgraded. Or use ikiwiki-mass-rebuild to force a rebuild.
+
+ There is a change to the plugin interface in this version. Plugins that use
+ %renderedfiles will need to be updated, as the hash's values are now arrays
+ of rendered files. Plugins that cause a page to render additional files
+ should use the new will_render function to register the files.
+
+ -- Joey Hess <joeyh@debian.org> Sun, 8 Oct 2006 17:27:56 -0400
+
ikiwiki (1.22) unstable; urgency=low
Due to some changes in the CSS, wikis should be rebuilt on upgrade to this
version. If you listed your wiki in /etc/ikiwiki/wikilist this will be done
- automatically when the Debian package is upgraded. Or use ikiiki-mass-rebuild
+ automatically when the Debian package is upgraded. Or use ikiwiki-mass-rebuild
to force a rebuild.
If you have modified versions of ikiwiki's html templates, you will need
diff --git a/debian/changelog b/debian/changelog
index b037b517a..758a81c47 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,8 +5,17 @@ ikiwiki (1.29) UNRELEASED; urgency=low
using HTTP Authentication instead of ikiwiki's built in authentication.
Useful for eg, large sites with their own previously existing user auth
setup. Closes: #384534
-
- -- Joey Hess <joeyh@debian.org> Mon, 2 Oct 2006 18:50:29 -0400
+ * Change %renderedfiles to store an array of files rendered from a given
+ source file, to allow tracking of extra rendered files like rss feeds.
+ * Note that plugins that accessed this variable will need to be updated!
+ The plugin interface has been increased to version 1.01 for this change.
+ * Add will_render function to the plugin interface, used to register that a
+ page renders a destination file, and do some security checks.
+ * Use will_render in the inline and linkmap plugins.
+ * Previously but no longer rendered files will be cleaned up.
+ * You will need to rebuild your wiki on upgrade to this version.
+
+ -- Joey Hess <joeyh@debian.org> Sun, 8 Oct 2006 16:53:17 -0400
ikiwiki (1.28) unstable; urgency=low
diff --git a/debian/postinst b/debian/postinst
index 006325b4a..96572ea62 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -4,7 +4,7 @@ set -e
# Change this when some incompatible change is made that requires
# rebuilding all wikis.
-firstcompat=1.22
+firstcompat=1.29
if [ "$1" = configure ] && \
dpkg --compare-versions "$2" lt "$firstcompat"; then
diff --git a/doc/bugs/rss_feed_cleanup_on_delete.mdwn b/doc/bugs/rss_feed_cleanup_on_delete.mdwn
index 32cdba0cc..fe0400ff8 100644
--- a/doc/bugs/rss_feed_cleanup_on_delete.mdwn
+++ b/doc/bugs/rss_feed_cleanup_on_delete.mdwn
@@ -2,3 +2,5 @@ If a page stops inlining anthing, its rss feed file will linger around and
not be deleted.
(The linkmap plugin has the same problem with the png files it creates.)
+
+[[bugs/done]]
diff --git a/doc/plugins/contrib/img/discussion.mdwn b/doc/plugins/contrib/img/discussion.mdwn
index c72752cf1..d4b38fb61 100644
--- a/doc/plugins/contrib/img/discussion.mdwn
+++ b/doc/plugins/contrib/img/discussion.mdwn
@@ -43,9 +43,9 @@ Benefits of not scaling:
1. Avoids any security issues with imagemagick.
2. Avoids issue of how to clean up old scaled images that are no longer being
used. (Granted, this is a general ikiwiki problem that will eventually
- be fixed in a general way.)
+ be fixed in a general way. (Update: now fixed in a general way, use the
+ will_render function.))
3. Makes clicking on thumbnails display the full version really fast, since
it's cached. :-)
-
--[[Joey]]
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 57521687e..8145a3562 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -197,7 +197,8 @@ use the following hashes, using a page name as the key:
* `%links` lists the names of each page that a page links to, in an array
reference.
-* `%renderedfiles` contains the name of the file rendered by a page.
+* `%renderedfiles` lists names of the files rendered by a page, in an array
+ reference.
* `%pagesources` contains the name of the source file for a page.
### Library functions
@@ -293,6 +294,13 @@ A failure to write the file will result in it dying with an error.
If the destination directory doesn't exist, it will first be created.
+### `will_render($$)`
+
+Given a page name and a destination file name (not including the base
+destination directory), register that the page will result in that file
+being rendered. It's important to call this before writing to any file in
+the destination directory.
+
#### `pagetype($)`
Given the name of a source file, returns the type of page it is, if it's
diff --git a/t/linkify.t b/t/linkify.t
index 74747e127..4de2b51ae 100755
--- a/t/linkify.t
+++ b/t/linkify.t
@@ -19,7 +19,7 @@ sub linkify ($$$$) {
foreach my $page (@existing_pages) {
$IkiWiki::pagecase{lc $page}=$page;
$links{$page}=[];
- $renderedfiles{"$page.mdwn"}=$page;
+ $renderedfiles{"$page.mdwn"}=[$page];
}
%config=IkiWiki::defaultconfig();