ikiwiki/ todo/ plugin data storage

ikiwiki currently stores some key data in .ikiwiki/index. Some plugins need a way to store additional data, and ideally it would be something managed by ikiwiki instead of ad-hoc because:

The aggregate plugin is a use-case: of 324 lines, 70 are data storage and another 10 handle deletion. Also, it's able to use a format very like ikiwiki's, but it does need to store some lists in there, which complicates it some and means that a very naive translation between a big per-page hash and the .index won't be good enough.

The current ikiwiki index format is not very flexible, although it is at least fairly easy and inexpensive to parse as well as hand-edit.

Would this do: ?

Hmm, that's potentially a lot of function calls per page eave load/save though.. For less function calls, only call each hook once per load/save, and it is passed/returns a big hash of pages and the values for each page. (Which probably means %state=@_ for load and return %state for save.)

It may also be better to just punt on lists, and require plugins that need even lists to encode them. Especially since in many cases, join(" ", @list) will do. Er hmm, if I do that though, I'm actually back to a big global %page_data that plugins can just toss data into, arn't I? So maybe that's %the right approach after all, hmm.. Except that needing to decode/encode list data all the time when using it would quite suck, so no, let's not do that.

Note that for the aggregate plugin to use this, it will need some changes:

If I do this, I might as well also:


The calendar plugin could use plugin data storage to record which pages have a calendar for the current time. Then ensure they are rebuilt at least once a day. Currently, it needs a cron job to rebuild the whole wiki every day; with this enhancement, the cron job would only rebuild the few pages that really need it.


New design:

%Ikiwiki::state is an exported hash that stores per-page state. Set with $state{$page}{id}{key}=$value. The id is the same id passed to hook().

This is stored in the index like:

src=foo.mdwn dest=bar.mdwn id_key=value [...]

The underscore ensures that there's no conflict with ikiwiki's own state variables. (Note that id and key need to be encoded here.)

Plugins are reponsible for deleting old state info, though ikiwiki will handle deleting it if a page is removed.

Ikiwiki needs to know when it can drop state for plugins that are no longer enabled. This is done via hook() -- if a plugin registers a hook ikiwiki knows it's still active, and preserves the state for the hook id. If not, that state will be dropped.

done!! Now to use it..