[dokuwiki] Re: Action Plugins

  • From: Chris Smith <chris@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Sat, 15 Apr 2006 10:47:56 +0100

No examples yet.

An action plugin has the potential to modify, replace or enhance any part of dokuwiki. However, besides the plugin itself an event is also required and that event may need to be wrapped around a particular default dokuwiki action. Right now there are very few (3) events so the scope for modification/enhancement is small.

The key to these working well is adding events to Dokuwiki in appropriate places and in a sensible and consistent manner.

For now, I'd think you should either:
- make suggestions for events, or
- suggest ideas where you would like to see ability to have a custom change dokuwiki behaviour, so that someone with more understanding of Dokuwiki internals can come up with an event to allow that.


Martin Tschofen wrote:

I'm wondering if that's the best way to override the way the index is
created. I want to be able to create a different index, perhaps a
visual site map via Graphviz.

Will that allow me to add new actions "do=sitemap" as well?...martin
The two events, 'ACTION_DISPATCH' and 'ACTION_TEMPLATE' would allow you to add a new sitemap command.

Your plugin could look something like:

register()
- register one event handlers, for ACTION_DISPATCH

action_dispatch handler would be something like:

// nothing to do, quit straight away and don't hold up dokuwiki
if ($data != "sitemap") return;

// register our handler for 'ACTION_TEMPLATE'
// we do that here to avoid have the handler process an action we know isn't present
global $EVENT_HANDLER;
$EVENT_HANDLER->register_hook('ACTION_TEMPLATE',$this,'action_template',NULL);


// prevent Dokuwiki normal processing of $ACT (it would clean the variable and destroy our 'sitemap' value.
$event->preventDefault();


// sitemap command belongs to us, there is no need to hold up Dokuwiki letting other plugins see if its for them
$event->stopPropagation();
return;


the action_template handler could then look something like

// sanity check, hand control back to dokuwiki as fast as possible if we don't have anything to do
// if ($data != "sitemap") return;


ptln("<h1>Sitemap</h1>");
....


Somethign similar would be required to replace the standard index function. With one change, the action dispatch handler should alter $ACT to a non-standard dokuwiki value. e.g. it will come in as "index", it should leave as "graphiz index". This is because (currently) the ACTION_TEMPLATE event fires when dokuwiki doesn't recognise the $ACT value - if it did recognise it (e.g. if it was 'index') it would generate its own index and never fire the ACTION_TEMPLATE event. This is different from ACTION_DISPATCH which occurs before Dokuwiki does any of its own processing.


There maybe an (strong) argument for changing ACTION_TEMPLATE location/behaviour. If so make it :)
One of the issues with organising events is that to arrange them sensibly may require changes to the associated Dokuwiki code, either functionalise more parts of it or to wrap large statement blocks in if() conditions. I don't want to propose those sort of changes right now.


I hope this helps.

Chris
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: