Projects More |
PmWiki /
Custom Actionsadministrators (intermediate) With cookbook recipes, it is possible to define custom page actions for PmWiki. The correspondent code is executed whenever a parameter [[MyGroup/MyPage ?action=myaction]]
With such an action, you can alter the display and treatment of the current page - like in standard actions as Whereas a Custom Markup is primarily intended to generate a meaningful text replacement on the current page, a page action is triggered by a url parameter and thus can be used in links as a call to a PHP function, acting on the current page or wiki wide, for instance like:
However, if you want to use PmWiki's built-in functions for custom actions you have to be aware of the fact that cookbook recipes are included in The following example shows how to set up a custom action $HandleActions['myaction'] = 'HandleMyAction'; # if url contains action=myaction call HandleMyAction timely $HandleAuth['myaction'] = 'admin'; # authorization level $auth for HandleMyAction function HandleMyAction($pagename, $auth) { # parameters (signature) of handler function required by PmWiki global $Author; # get hold of current author name, e.g. for page history $old = RetrieveAuthPage('MyGroup.MyOtherPage', $auth); # get all information from page MyGroup.MyOtherPage $new = $old; # copy the page information to stay (e.g. page history) $new['text'] = "x".$old['text']; # ... some manipulation of the old wiki mark-up $Author='myactionbot'; # author name to appear in the page history for this manipulation $pn='MyGroup.MyOtherPage'; # need to call UpdatePage with variables (by reference) only UpdatePage($pn,$old,$new); # alter the actual wiki page HandleBrowse($pagename); # display the page specified in the url (e.g. MyGroup.MyPage) } Notes:
Category: PmWiki Developer
This page may have a more recent version on pmwiki.org: PmWiki:CustomActions, and a talk page: PmWiki:CustomActions-Talk. |