* 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.master
parent
118c481766
commit
cefbe6210f
36
IkiWiki.pm
36
IkiWiki.pm
|
@ -8,14 +8,15 @@ use HTML::Entities;
|
||||||
use open qw{:utf8 :std};
|
use open qw{:utf8 :std};
|
||||||
|
|
||||||
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
|
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
|
||||||
%renderedfiles %pagesources %depends %hooks %forcerebuild};
|
%renderedfiles %oldrenderedfiles %pagesources %depends %hooks
|
||||||
|
%forcerebuild};
|
||||||
|
|
||||||
use Exporter q{import};
|
use Exporter q{import};
|
||||||
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
|
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
|
||||||
bestlink htmllink readfile writefile pagetype srcfile pagename
|
bestlink htmllink readfile writefile pagetype srcfile pagename
|
||||||
displaytime
|
displaytime
|
||||||
%config %links %renderedfiles %pagesources);
|
%config %links %renderedfiles %pagesources);
|
||||||
our $VERSION = 1.00;
|
our $VERSION = 1.01;
|
||||||
|
|
||||||
# Optimisation.
|
# Optimisation.
|
||||||
use Memoize;
|
use Memoize;
|
||||||
|
@ -261,6 +262,25 @@ sub writefile ($$$;$) { #{{{
|
||||||
close OUT;
|
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 ($$) { #{{{
|
sub bestlink ($$) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $link=shift;
|
my $link=shift;
|
||||||
|
@ -366,10 +386,10 @@ sub htmllink ($$$;$$$) { #{{{
|
||||||
# TODO BUG: %renderedfiles may not have it, if the linked to page
|
# 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
|
# 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.
|
# 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);
|
$bestlink=htmlpage($bestlink);
|
||||||
}
|
}
|
||||||
if (! grep { $_ eq $bestlink } values %renderedfiles) {
|
if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) {
|
||||||
return "<span><a href=\"".
|
return "<span><a href=\"".
|
||||||
cgiurl(do => "create", page => lc($link), from => $page).
|
cgiurl(do => "create", page => lc($link), from => $page).
|
||||||
"\">?</a>$linktext</span>"
|
"\">?</a>$linktext</span>"
|
||||||
|
@ -529,6 +549,7 @@ sub loadindex () { #{{{
|
||||||
chomp;
|
chomp;
|
||||||
my %items;
|
my %items;
|
||||||
$items{link}=[];
|
$items{link}=[];
|
||||||
|
$items{dest}=[];
|
||||||
foreach my $i (split(/ /, $_)) {
|
foreach my $i (split(/ /, $_)) {
|
||||||
my ($item, $val)=split(/=/, $i, 2);
|
my ($item, $val)=split(/=/, $i, 2);
|
||||||
push @{$items{$item}}, decode_entities($val);
|
push @{$items{$item}}, decode_entities($val);
|
||||||
|
@ -543,7 +564,8 @@ sub loadindex () { #{{{
|
||||||
$oldlinks{$page}=[@{$items{link}}];
|
$oldlinks{$page}=[@{$items{link}}];
|
||||||
$links{$page}=[@{$items{link}}];
|
$links{$page}=[@{$items{link}}];
|
||||||
$depends{$page}=$items{depends}[0] if exists $items{depends};
|
$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;
|
$pagecase{lc $page}=$page;
|
||||||
}
|
}
|
||||||
$pagectime{$page}=$items{ctime}[0];
|
$pagectime{$page}=$items{ctime}[0];
|
||||||
|
@ -563,8 +585,8 @@ sub saveindex () { #{{{
|
||||||
next unless $oldpagemtime{$page};
|
next unless $oldpagemtime{$page};
|
||||||
my $line="mtime=$oldpagemtime{$page} ".
|
my $line="mtime=$oldpagemtime{$page} ".
|
||||||
"ctime=$pagectime{$page} ".
|
"ctime=$pagectime{$page} ".
|
||||||
"src=$pagesources{$page} ".
|
"src=$pagesources{$page}";
|
||||||
"dest=$renderedfiles{$page}";
|
$line.=" dest=$_" foreach @{$renderedfiles{$page}};
|
||||||
$line.=" link=$_" foreach @{$links{$page}};
|
$line.=" link=$_" foreach @{$links{$page}};
|
||||||
if (exists $depends{$page}) {
|
if (exists $depends{$page}) {
|
||||||
$line.=" depends=".encode_entities($depends{$page}, " \t\n");
|
$line.=" depends=".encode_entities($depends{$page}, " \t\n");
|
||||||
|
|
|
@ -4,7 +4,7 @@ package IkiWiki::Plugin::inline;
|
||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use IkiWiki;
|
use IkiWiki 1.00;
|
||||||
use IkiWiki::Render; # for displaytime
|
use IkiWiki::Render; # for displaytime
|
||||||
use URI;
|
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) {
|
if ($config{rss} && $rss) {
|
||||||
|
will_render($params{page}, rsspage($params{page}));
|
||||||
writefile(rsspage($params{page}), $config{destdir},
|
writefile(rsspage($params{page}), $config{destdir},
|
||||||
genrss($desc, $params{page}, @list));
|
genrss($desc, $params{page}, @list));
|
||||||
$toping{$params{page}}=1 unless $config{rebuild};
|
$toping{$params{page}}=1 unless $config{rebuild};
|
||||||
|
@ -233,9 +231,7 @@ sub genrss ($$@) { #{{{
|
||||||
my $itemtemplate=template("rssitem.tmpl", blind_cache => 1);
|
my $itemtemplate=template("rssitem.tmpl", blind_cache => 1);
|
||||||
my $content="";
|
my $content="";
|
||||||
foreach my $p (@pages) {
|
foreach my $p (@pages) {
|
||||||
next unless exists $renderedfiles{$p};
|
my $u=URI->new(encode_utf8($config{url}."/".htmlpage($p)));
|
||||||
|
|
||||||
my $u=URI->new(encode_utf8("$config{url}/$renderedfiles{$p}"));
|
|
||||||
|
|
||||||
$itemtemplate->param(
|
$itemtemplate->param(
|
||||||
title => pagetitle(basename($p)),
|
title => pagetitle(basename($p)),
|
||||||
|
|
|
@ -57,12 +57,10 @@ sub genmap ($) { #{{{
|
||||||
|
|
||||||
# Use ikiwiki's function to create the file, this makes sure needed
|
# Use ikiwiki's function to create the file, this makes sure needed
|
||||||
# subdirs are there and does some sanity checking.
|
# 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.
|
# 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 $pid;
|
||||||
my $sigpipe=0;;
|
my $sigpipe=0;;
|
||||||
$SIG{PIPE}=sub { $sigpipe=1 };
|
$SIG{PIPE}=sub { $sigpipe=1 };
|
||||||
|
|
|
@ -63,7 +63,8 @@ sub change (@) { #{{{
|
||||||
debug("updating hyperestraier search index");
|
debug("updating hyperestraier search index");
|
||||||
estcmd("gather -cm -bc -cl -sd",
|
estcmd("gather -cm -bc -cl -sd",
|
||||||
map {
|
map {
|
||||||
Encode::encode_utf8($config{destdir}."/".$renderedfiles{pagename($_)})
|
Encode::encode_utf8($config{destdir}."/".$_)
|
||||||
|
foreach @{$renderedfiles{pagename($_)}};
|
||||||
} @_
|
} @_
|
||||||
);
|
);
|
||||||
estcfg();
|
estcfg();
|
||||||
|
|
|
@ -113,17 +113,6 @@ sub genpage ($$$) { #{{{
|
||||||
return $content;
|
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 ($) { #{{{
|
sub mtime ($) { #{{{
|
||||||
my $file=shift;
|
my $file=shift;
|
||||||
|
|
||||||
|
@ -157,6 +146,7 @@ sub render ($) { #{{{
|
||||||
my $content=readfile($srcfile);
|
my $content=readfile($srcfile);
|
||||||
my $page=pagename($file);
|
my $page=pagename($file);
|
||||||
delete $depends{$page};
|
delete $depends{$page};
|
||||||
|
will_render($page, htmlpage($page), 1);
|
||||||
|
|
||||||
$content=filter($page, $content);
|
$content=filter($page, $content);
|
||||||
|
|
||||||
|
@ -166,20 +156,17 @@ sub render ($) { #{{{
|
||||||
$content=linkify($page, $page, $content);
|
$content=linkify($page, $page, $content);
|
||||||
$content=htmlize($page, $type, $content);
|
$content=htmlize($page, $type, $content);
|
||||||
|
|
||||||
check_overwrite("$config{destdir}/".htmlpage($page), $page);
|
|
||||||
writefile(htmlpage($page), $config{destdir},
|
writefile(htmlpage($page), $config{destdir},
|
||||||
genpage($page, $content, mtime($srcfile)));
|
genpage($page, $content, mtime($srcfile)));
|
||||||
$oldpagemtime{$page}=time;
|
$oldpagemtime{$page}=time;
|
||||||
$renderedfiles{$page}=htmlpage($page);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $content=readfile($srcfile, 1);
|
my $content=readfile($srcfile, 1);
|
||||||
$links{$file}=[];
|
$links{$file}=[];
|
||||||
delete $depends{$file};
|
delete $depends{$file};
|
||||||
check_overwrite("$config{destdir}/$file", $file);
|
will_render($file, $file, 1);
|
||||||
writefile($file, $config{destdir}, $content, 1);
|
writefile($file, $config{destdir}, $content, 1);
|
||||||
$oldpagemtime{$file}=time;
|
$oldpagemtime{$file}=time;
|
||||||
$renderedfiles{$file}=$file;
|
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
@ -269,9 +256,10 @@ sub refresh () { #{{{
|
||||||
if (! $exists{$page}) {
|
if (! $exists{$page}) {
|
||||||
debug("removing old page $page");
|
debug("removing old page $page");
|
||||||
push @del, $pagesources{$page};
|
push @del, $pagesources{$page};
|
||||||
prune($config{destdir}."/".$renderedfiles{$page});
|
$renderedfiles{$page}=[];
|
||||||
delete $renderedfiles{$page};
|
|
||||||
$oldpagemtime{$page}=0;
|
$oldpagemtime{$page}=0;
|
||||||
|
prune($config{destdir}."/".$_)
|
||||||
|
foreach @{$oldrenderedfiles{$page}};
|
||||||
delete $pagesources{$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) {
|
if (@del) {
|
||||||
run_hooks(delete => sub { shift->(@del) });
|
run_hooks(delete => sub { shift->(@del) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
ikiwiki (1.22) unstable; urgency=low
|
||||||
|
|
||||||
Due to some changes in the CSS, wikis should be rebuilt on upgrade to this
|
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
|
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.
|
to force a rebuild.
|
||||||
|
|
||||||
If you have modified versions of ikiwiki's html templates, you will need
|
If you have modified versions of ikiwiki's html templates, you will need
|
||||||
|
|
|
@ -5,8 +5,17 @@ ikiwiki (1.29) UNRELEASED; urgency=low
|
||||||
using HTTP Authentication instead of ikiwiki's built in authentication.
|
using HTTP Authentication instead of ikiwiki's built in authentication.
|
||||||
Useful for eg, large sites with their own previously existing user auth
|
Useful for eg, large sites with their own previously existing user auth
|
||||||
setup. Closes: #384534
|
setup. Closes: #384534
|
||||||
|
* 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> Mon, 2 Oct 2006 18:50:29 -0400
|
-- Joey Hess <joeyh@debian.org> Sun, 8 Oct 2006 16:53:17 -0400
|
||||||
|
|
||||||
ikiwiki (1.28) unstable; urgency=low
|
ikiwiki (1.28) unstable; urgency=low
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
|
|
||||||
# Change this when some incompatible change is made that requires
|
# Change this when some incompatible change is made that requires
|
||||||
# rebuilding all wikis.
|
# rebuilding all wikis.
|
||||||
firstcompat=1.22
|
firstcompat=1.29
|
||||||
|
|
||||||
if [ "$1" = configure ] && \
|
if [ "$1" = configure ] && \
|
||||||
dpkg --compare-versions "$2" lt "$firstcompat"; then
|
dpkg --compare-versions "$2" lt "$firstcompat"; then
|
||||||
|
|
|
@ -2,3 +2,5 @@ If a page stops inlining anthing, its rss feed file will linger around and
|
||||||
not be deleted.
|
not be deleted.
|
||||||
|
|
||||||
(The linkmap plugin has the same problem with the png files it creates.)
|
(The linkmap plugin has the same problem with the png files it creates.)
|
||||||
|
|
||||||
|
[[bugs/done]]
|
||||||
|
|
|
@ -43,9 +43,9 @@ Benefits of not scaling:
|
||||||
1. Avoids any security issues with imagemagick.
|
1. Avoids any security issues with imagemagick.
|
||||||
2. Avoids issue of how to clean up old scaled images that are no longer being
|
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
|
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
|
3. Makes clicking on thumbnails display the full version really fast, since
|
||||||
it's cached. :-)
|
it's cached. :-)
|
||||||
|
|
||||||
|
|
||||||
--[[Joey]]
|
--[[Joey]]
|
||||||
|
|
|
@ -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
|
* `%links` lists the names of each page that a page links to, in an array
|
||||||
reference.
|
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.
|
* `%pagesources` contains the name of the source file for a page.
|
||||||
|
|
||||||
### Library functions
|
### 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.
|
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($)`
|
#### `pagetype($)`
|
||||||
|
|
||||||
Given the name of a source file, returns the type of page it is, if it's
|
Given the name of a source file, returns the type of page it is, if it's
|
||||||
|
|
|
@ -19,7 +19,7 @@ sub linkify ($$$$) {
|
||||||
foreach my $page (@existing_pages) {
|
foreach my $page (@existing_pages) {
|
||||||
$IkiWiki::pagecase{lc $page}=$page;
|
$IkiWiki::pagecase{lc $page}=$page;
|
||||||
$links{$page}=[];
|
$links{$page}=[];
|
||||||
$renderedfiles{"$page.mdwn"}=$page;
|
$renderedfiles{"$page.mdwn"}=[$page];
|
||||||
}
|
}
|
||||||
%config=IkiWiki::defaultconfig();
|
%config=IkiWiki::defaultconfig();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue