From 3ebd4e0b45a8a6bd4c12604a3bb683dcb3a60eb8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 14:04:46 -0400 Subject: Add genwrapper hook, that can be used to add code into the C wrapper. --- IkiWiki/Plugin/skeleton.pm.example | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index 573510191..ddf2996d6 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -39,6 +39,7 @@ sub import { hook(type => "renamepage", id => "skeleton", call => \&renamepage); hook(type => "rename", id => "skeleton", call => \&rename); hook(type => "savestate", id => "skeleton", call => \&savestate); + hook(type => "genwrapper", id => "skeleton", call => \&genwrapper); } sub getopt () { @@ -239,4 +240,8 @@ sub savestate () { debug("skeleton plugin running in savestate"); } +sub genwrapper () { + debug("skeleton plugin running in genwrapper"); +} + 1 -- cgit v1.2.3 From 2f22ee85e547dfe408fc0ec520aed6a6e137e136 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 3 May 2010 12:15:40 -0400 Subject: Add ACTIONS variable to page.tmpl, which allows plugins to add arbitrary links to the action bar without modifying the template further. (COMMENTSLINK and DISCUSSIONLINK could be folded into this, but are kept separate for now to avoid breaking modified templates.) --- IkiWiki/Plugin/skeleton.pm.example | 9 +++++++++ IkiWiki/Render.pm | 9 ++++++++- debian/changelog | 4 ++++ doc/plugins/write.mdwn | 9 +++++++++ templates/page.tmpl | 9 +++++++-- 5 files changed, 37 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index ddf2996d6..a404e24af 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -24,6 +24,7 @@ sub import { hook(type => "format", id => "skeleton", call => \&format); hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate); hook(type => "templatefile", id => "skeleton", call => \&templatefile); + hook(type => "pageactions", id => "skeleton", call => \&pageactions); hook(type => "delete", id => "skeleton", call => \&delete); hook(type => "change", id => "skeleton", call => \&change); hook(type => "cgi", id => "skeleton", call => \&cgi); @@ -146,6 +147,14 @@ sub templatefile (@) { debug("skeleton plugin running as a templatefile hook"); } +sub pageactions (@) { + my %params=@_; + my $page=$params{page}; + + debug("skeleton plugin running as a pageactions hook"); + return (); +} + sub delete (@) { my @files=@_; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index cf6943e7d..a824ba539 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -112,7 +112,14 @@ sub genpage ($$) { } } - if ($actions) { + my @actions; + run_hooks(pageactions => sub { + push @actions, map { { action => $_ } } + grep { defined } shift->(page => $page); + }); + $template->param(actions => \@actions); + + if ($actions || @actions) { $template->param(have_actions => 1); } diff --git a/debian/changelog b/debian/changelog index 789fda1ce..e03375bd3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,10 @@ ikiwiki (3.20100502) UNRELEASED; urgency=low * In html5 mode, use all the nice new semantic tags. Care was taken to not change the id/class named used in the CSS, so only CSS that refers to tag types needed to be changed. + * Add ACTIONS variable to page.tmpl, which allows plugins to add arbitrary + links to the action bar without modifying the template further. + (COMMENTSLINK and DISCUSSIONLINK could be folded into this, but + are kept separate for now to avoid breaking modified templates.) -- Joey Hess Sun, 02 May 2010 13:22:50 -0400 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 5e7042c3b..3b1d770eb 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -319,6 +319,15 @@ should return the name of the template file to use (relative to the template directory), or undef if it doesn't want to change the default ("page.tmpl"). +### pageactions + + hook(type => "pageactions", id => "foo", call => \&pageactions); + +This hook allows plugins to add arbitrary actions to the action bar on a +page (next to Edit, RecentChanges, etc). The hook is passed a "page" +parameter, and can return a list of html fragments to add to the action +bar. + ### sanitize hook(type => "sanitize", id => "foo", call => \&sanitize); diff --git a/templates/page.tmpl b/templates/page.tmpl index 195ce7886..8a9911fae 100644 --- a/templates/page.tmpl +++ b/templates/page.tmpl @@ -66,11 +66,16 @@
  • Preferences
  • + + +
  • +
    +
    -

  • +
  • -

  • +
  • -- cgit v1.2.3 From 121e2ffc2f25bf264a68d35e80a9386995fa9e5a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 6 May 2010 23:07:08 -0400 Subject: Renamed postscan hook to indexhtml, to reflect its changed position. Probably only the search plugin uses it, so this seemed safe. --- IkiWiki/Plugin/search.pm | 2 +- IkiWiki/Plugin/skeleton.pm.example | 6 +++--- IkiWiki/Render.pm | 2 +- debian/changelog | 2 ++ doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn | 2 +- doc/plugins/po/discussion.mdwn | 2 +- doc/plugins/write.mdwn | 6 +++--- 7 files changed, 12 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index 9e875c79c..b1f4747fe 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -10,7 +10,7 @@ sub import { hook(type => "getsetup", id => "search", call => \&getsetup); hook(type => "checkconfig", id => "search", call => \&checkconfig); hook(type => "pagetemplate", id => "search", call => \&pagetemplate); - hook(type => "postscan", id => "search", call => \&index); + hook(type => "indexhtml", id => "search", call => \&index); hook(type => "delete", id => "search", call => \&delete); hook(type => "cgi", id => "search", call => \&cgi); } diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index a404e24af..34713c73b 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -20,7 +20,7 @@ sub import { hook(type => "scan", id => "skeleton", call => \&scan); hook(type => "htmlize", id => "skeleton", call => \&htmlize); hook(type => "sanitize", id => "skeleton", call => \&sanitize); - hook(type => "postscan", id => "skeleton", call => \&postscan); + hook(type => "indexhtml", id => "skeleton", call => \&indexhtml); hook(type => "format", id => "skeleton", call => \&format); hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate); hook(type => "templatefile", id => "skeleton", call => \&templatefile); @@ -118,10 +118,10 @@ sub sanitize (@) { return $params{content}; } -sub postscan (@) { +sub indexhtml (@) { my %params=@_; - debug("skeleton plugin running as postscan"); + debug("skeleton plugin running as indexhtml"); } sub format (@) { diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index e5ba0079b..30e3d4199 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -62,7 +62,7 @@ sub genpage ($$) { my $page=shift; my $content=shift; - run_hooks(postscan => sub { + run_hooks(indexhtml => sub { shift->(page => $page, content => $content); }); diff --git a/debian/changelog b/debian/changelog index 77fd13826..eb67c2bde 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ ikiwiki (3.20100505) UNRELEASED; urgency=low * If you have a locally customised page.tmpl, it needs to be updated to set when BASEURL or FORCEBAREURL is set. * Gave comment and page editing forms some CSS and accessability love. + * Renamed postscan hook to indexhtml, to reflect its changed position, + and typical use. -- Joey Hess Wed, 05 May 2010 18:07:29 -0400 diff --git a/doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn b/doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn index be14e5126..c6e3cd4fd 100644 --- a/doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn +++ b/doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn @@ -144,7 +144,7 @@ So, looking at your meta branch: --[[Joey]] has no title, then A will display the link as "B". Now page B is modified and a title is added. Nothing updates "A". The added overhead of rebuilding every page that links to B when B is - changed (as the `postscan` hook of the po plugin does) is IMHO a killer. + changed (as the `indexhtml` hook of the po plugin does) is IMHO a killer. That could be hundreds or thousands of pages, making interactive editing way slow. This is probably the main reason I had not attempted this whole thing myself. IMHO this calls for some kind of intellegent dependency diff --git a/doc/plugins/po/discussion.mdwn b/doc/plugins/po/discussion.mdwn index ab822e76c..27683f1ea 100644 --- a/doc/plugins/po/discussion.mdwn +++ b/doc/plugins/po/discussion.mdwn @@ -513,7 +513,7 @@ finish it at some point in the first quarter of 2009. --[[intrigeri]] >>>> >>>>> Done. --[[intrigeri]] >>> -> * I'm very fearful of the `add_depends` in `postscan`. +> * I'm very fearful of the `add_depends` in `indexhtml`. > Does this make every page depend on every page that links > to it? Won't this absurdly bloat the dependency pagespecs > and slow everything down? And since nicepagetitle is given diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 3b1d770eb..7180237a4 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -39,7 +39,7 @@ built. Now that it knows what pages it needs to build, ikiwiki runs two compile passes. First, it runs `scan` hooks, which collect metadata about the pages. Then it runs a page rendering pipeline, by calling in turn these -hooks: `filter`, `preprocess`, `linkify`, `htmlize`, `postscan`, +hooks: `filter`, `preprocess`, `linkify`, `htmlize`, `indexhtml`, `pagetemplate`, `sanitize`, `format`. After all necessary pages are built, it calls the `change` hook. Finally, @@ -282,9 +282,9 @@ like `Makefile` that have no extension. If `hook` is passed an optional "longname" parameter, this value is used when prompting a user to choose a page type on the edit page form. -### postscan +### indexhtml - hook(type => "postscan", id => "foo", call => \&postscan); + hook(type => "indexhtml", id => "foo", call => \&indexhtml); This hook is called once the page has been converted to html (but before the generated html is put in a template). The most common use is to -- cgit v1.2.3 From cfcc79ed4c9f11ef8af2ae19e3bb402289e9ea39 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 18 Jun 2010 16:15:57 -0400 Subject: needsbuild hook is passed an array ref --- IkiWiki/Plugin/skeleton.pm.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index 34713c73b..adffc91c9 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -70,7 +70,7 @@ sub refresh () { debug("skeleton plugin refresh"); } -sub needsbuild () { +sub needsbuild ($) { debug("skeleton plugin needsbuild"); } -- cgit v1.2.3 From d420a4bdecddcc297eebb233dae8d69ba45c8e1a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 14 Jul 2010 14:47:17 -0400 Subject: add section to getsetup info --- IkiWiki/Plugin/skeleton.pm.example | 1 + 1 file changed, 1 insertion(+) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index adffc91c9..c3a3b0c01 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -52,6 +52,7 @@ sub getsetup () { plugin => { safe => 1, rebuild => undef, + section => "misc", }, skeleton => { type => "boolean", -- cgit v1.2.3 From c401b6958af7e12c1c2c46f870691bfb0a998fd3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 26 Jul 2010 16:24:17 -0400 Subject: Add new disable hook, allowing plugins to perform cleanup after they have been disabled. --- IkiWiki.pm | 17 ++++++++++------- IkiWiki/Plugin/skeleton.pm.example | 5 +++++ IkiWiki/Setup.pm | 24 ++++++++++++++++++++++++ debian/changelog | 2 ++ doc/plugins/write.mdwn | 7 +++++++ 5 files changed, 48 insertions(+), 7 deletions(-) (limited to 'IkiWiki/Plugin/skeleton.pm.example') diff --git a/IkiWiki.pm b/IkiWiki.pm index cfa4f5f03..e08d02922 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1596,6 +1596,12 @@ sub loadindex () { if (exists $index->{version} && ! ref $index->{version}) { $pages=$index->{page}; %wikistate=%{$index->{state}}; + # Handle plugins that got disabled by loading a new setup. + if (exists $config{setupfile}) { + require IkiWiki::Setup; + IkiWiki::Setup::disabled_plugins( + grep { ! $loaded_plugins{$_} } keys %wikistate); + } } else { $pages=$index; @@ -1663,11 +1669,7 @@ sub loadindex () { sub saveindex () { run_hooks(savestate => sub { shift->() }); - my %hookids; - foreach my $type (keys %hooks) { - $hookids{$_}=1 foreach keys %{$hooks{$type}}; - } - my @hookids=keys %hookids; + my @plugins=keys %loaded_plugins; if (! -d $config{wikistatedir}) { mkdir($config{wikistatedir}); @@ -1701,7 +1703,7 @@ sub saveindex () { } if (exists $pagestate{$page}) { - foreach my $id (@hookids) { + foreach my $id (@plugins) { foreach my $key (keys %{$pagestate{$page}{$id}}) { $index{page}{$src}{state}{$id}{$key}=$pagestate{$page}{$id}{$key}; } @@ -1710,7 +1712,8 @@ sub saveindex () { } $index{state}={}; - foreach my $id (@hookids) { + foreach my $id (@plugins) { + $index{state}{$id}={}; # used to detect disabled plugins foreach my $key (keys %{$wikistate{$id}}) { $index{state}{$id}{$key}=$wikistate{$id}{$key}; } diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index c3a3b0c01..a57a2c8fe 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -41,6 +41,7 @@ sub import { hook(type => "rename", id => "skeleton", call => \&rename); hook(type => "savestate", id => "skeleton", call => \&savestate); hook(type => "genwrapper", id => "skeleton", call => \&genwrapper); + hook(type => "disable", id => "skeleton", call => \&disable); } sub getopt () { @@ -254,4 +255,8 @@ sub genwrapper () { debug("skeleton plugin running in genwrapper"); } +sub savestate () { + debug("skeleton plugin running in disable"); +} + 1 diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index 7af744f6a..f34571bcf 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -124,6 +124,28 @@ sub merge ($) { } } +sub disabled_plugins (@) { + # Handles running disable hooks of plugins that were enabled + # previously, but got disabled when a new setup file was loaded. + if (exists $config{setupfile} && @_) { + # Fork a child to load the disabled plugins. + my $pid=fork(); + if ($pid == 0) { + foreach my $plugin (@_) { + print STDERR "** plugin $plugin disabled\n"; + eval { IkiWiki::loadplugin($plugin, 1) }; + if (exists $IkiWiki::hooks{disable}{$plugin}{call}) { + eval { $IkiWiki::hooks{disable}{$plugin}{call}->() }; + } + } + exit(0); + } + else { + waitpid $pid, 0; + } + } +} + sub getsetup () { # Gets all available setup data from all plugins. Returns an # ordered list of [plugin, setup] pairs. @@ -134,6 +156,7 @@ sub getsetup () { $config{syslog}=undef; # Load all plugins, so that all setup options are available. + my %original_loaded_plugins=%IkiWiki::loaded_plugins; my @plugins=IkiWiki::listplugins(); foreach my $plugin (@plugins) { eval { IkiWiki::loadplugin($plugin, 1) }; @@ -141,6 +164,7 @@ sub getsetup () { my @s=eval { $IkiWiki::hooks{checkconfig}{$plugin}{call}->() }; } } + %IkiWiki::loaded_plugins=%original_loaded_plugins; my %sections; foreach my $plugin (@plugins) { diff --git a/debian/changelog b/debian/changelog index 167d02c6f..5645b34d4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ ikiwiki (3.20100723) UNRELEASED; urgency=low * git: Fix gitweb historyurl examples so "diff to current" links work. (Thanks jrayhawk) * meta: Allow syntax closer to html meta to be used. + * Add new disable hook, allowing plugins to perform cleanup after they + have been disabled. -- Joey Hess Fri, 23 Jul 2010 14:00:32 -0400 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 2e3902388..10b4df835 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -600,6 +600,13 @@ function of the ikiwiki wrapper when it is being generated. The code runs before anything else -- in particular it runs before the suid wrapper has sanitized its environment. +### disable + + hook(type => "disable", id => "foo", call => \&disable); + +This hook is only run when a previously enabled plugin gets disabled +during ikiwiki setup. Plugins can use this to perform cleanups. + ## Exported variables Several variables are exported to your plugin when you `use IkiWiki;` -- cgit v1.2.3