Add %wikistate, which is like %pagestate except not specific to a given page, and is preserved across rebuilds.

master
Joey Hess 2008-09-27 16:45:27 -04:00
parent 61426a7186
commit a5d3acd37c
4 changed files with 28 additions and 8 deletions

View File

@ -12,16 +12,16 @@ use Storable;
use open qw{:utf8 :std}; use open qw{:utf8 :std};
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%pagestate %renderedfiles %oldrenderedfiles %pagesources %pagestate %wikistate %renderedfiles %oldrenderedfiles
%destsources %depends %hooks %forcerebuild $gettext_obj %pagesources %destsources %depends %hooks %forcerebuild
%loaded_plugins}; $gettext_obj %loaded_plugins};
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 will_render gettext urlto targetpage displaytime will_render gettext urlto targetpage
add_underlay pagetitle titlepage linkpage add_underlay pagetitle titlepage linkpage
%config %links %pagestate %renderedfiles %config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources); %pagesources %destsources);
our $VERSION = 2.00; # plugin interface version, next is ikiwiki version our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
@ -1318,9 +1318,11 @@ sub loadindex () { #{{{
my $pages; my $pages;
if (exists $index->{version} && ! ref $index->{version}) { if (exists $index->{version} && ! ref $index->{version}) {
$pages=$index->{page}; $pages=$index->{page};
%wikistate=%{$index->{state}};
} }
else { else {
$pages=$index; $pages=$index;
%wikistate=();
} }
foreach my $src (keys %$pages) { foreach my $src (keys %$pages) {
@ -1368,6 +1370,7 @@ sub saveindex () { #{{{
my $newfile="$config{wikistatedir}/indexdb.new"; my $newfile="$config{wikistatedir}/indexdb.new";
my $cleanup = sub { unlink($newfile) }; my $cleanup = sub { unlink($newfile) };
open (my $out, '>', $newfile) || error("cannot write to $newfile: $!", $cleanup); open (my $out, '>', $newfile) || error("cannot write to $newfile: $!", $cleanup);
my %index; my %index;
foreach my $page (keys %pagemtime) { foreach my $page (keys %pagemtime) {
next unless $pagemtime{$page}; next unless $pagemtime{$page};
@ -1392,6 +1395,14 @@ sub saveindex () { #{{{
} }
} }
} }
$index{state}={};
foreach my $id (@hookids) {
foreach my $key (keys %{$wikistate{$id}}) {
$index{state}{$id}{$key}=$wikistate{$id}{$key};
}
}
$index{version}="3"; $index{version}="3";
my $ret=Storable::nstore_fd(\%index, $out); my $ret=Storable::nstore_fd(\%index, $out);
return if ! defined $ret || ! $ret; return if ! defined $ret || ! $ret;

4
debian/changelog vendored
View File

@ -19,10 +19,10 @@ ikiwiki (2.66) UNRELEASED; urgency=low
untidied content if tidy crashes. In either case, it seems best to tidy untidied content if tidy crashes. In either case, it seems best to tidy
the content to nothing. the content to nothing.
* htmltidy: Avoid spewing tidy errors to stderr. * htmltidy: Avoid spewing tidy errors to stderr.
* Add %wikistate, which is like %pagestate except not specific to a given
page, and is preserved across rebuilds.
* Reorganize index file, add a format version field. Upgrades to the new * Reorganize index file, add a format version field. Upgrades to the new
index format should be transparent. index format should be transparent.
* Add %wikistate, which is like %pagestate except not specific to a given
page, and is preserved across rebuilds.
-- Joey Hess <joeyh@debian.org> Thu, 25 Sep 2008 13:45:55 -0400 -- Joey Hess <joeyh@debian.org> Thu, 25 Sep 2008 13:45:55 -0400

View File

@ -467,6 +467,15 @@ When pages are deleted, ikiwiki automatically deletes their pagestate too.
Note that page state does not persist across wiki rebuilds, only across Note that page state does not persist across wiki rebuilds, only across
wiki updates. wiki updates.
### %wikistate
The `%wikistate` hash can be used by a plugin to store persistant state
that is not bound to any one page. To set a value, use
`$wikistate{$id}{$key}=$value, where `$value` is anything Storable can
serialize, `$key` is any string you like, and `$id` must be the same as the
"id" parameter passed to `hook()` when registering the plugin, so that the
state can be dropped if the plugin is no longer used.
### Other variables ### Other variables
If your plugin needs to access data about other pages in the wiki. It can If your plugin needs to access data about other pages in the wiki. It can

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-09-27 16:35-0400\n" "POT-Creation-Date: 2008-09-27 16:40-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -910,7 +910,7 @@ msgstr ""
msgid "preprocessing loop detected on %s at depth %i" msgid "preprocessing loop detected on %s at depth %i"
msgstr "" msgstr ""
#: ../IkiWiki.pm:1624 #: ../IkiWiki.pm:1632
msgid "yes" msgid "yes"
msgstr "" msgstr ""