This is an old revision of the document!
Table of Contents
Actionlink Plugin
Compatible with DokuWiki
2010-11-07 "Anteater", 2011-05-25 "Rincewind", 2012-01-25 "Angua", 2012-10-13 "Adora Belle", "Weatherwax", 2013-12-08 "Binky", 2014-05-05 "Ponder Stibbons", 2014-09-29 "Hrun", 2015-08-10 "Detritus", 2016-06-26 "Elenor Of Tsort", 2017-02-19+
This plugin lets you use actionlinks in your wiki syntax. It's based on the DokuWiki's core function tpl_actionlink().
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Security warning (please read plugin security guidelines): When builing actionlinks for 'admin', 'login' etc. don't forget ~~NOCACHE~~
Syntax
Basic syntax:
{{actionlink>[action]|[title]}}
Where action can be one of this (after inc/template.php
):
- edit - edit/create/show
- history - old revisions
- recent - recent changes
- :recent, /recent - recent changes from the root namespace
- login - login/logout - if ACL enabled
- index - the index
- admin - admin page - if enough rights
- top - a 'back to top' link
- back - a 'back to parent' link - if available
- backlink - list of backlinks
- search - focus on the search field
- purge
- subscribe
- addtobook
- cite
- infomail
- export_odt
- export_pdf
(Of course, for these last commands to work, those plugins should be installed.)
The title element is optional. It lets you specify a custom string to be used instead of the default 'Edit this page', 'Old revisions', 'Recent changes', etc.
Examples
For example, syntax like this:
You can easily {{actionlink>edit|customise}} this page.
Will produce an output like this: 'You can easily customise this page', where 'customise' is a link to the 'Edit page' page.
Syntax like this:
{{actionlink>edit}}
Will simply create a 'Edit this page' link.
Installation
You can install this plugin using the plugin manager.
Sources: plugin-actionlink-2005-05-26.tar.gz(2kb) | plugin-actionlink-2005-05-26.zip(2kb) https://github.com/chang-zhao/actionlink
To install manually: create a folder actionlink
in lib/plugins
and put the code below in syntax.php
. The last version see here: https://github.com/chang-zhao/actionlink/blob/master/syntax.php
<?php /** * Action link plugin. Lets you use action links in your wiki syntax. * Based on the core function - tpl_actionlink(). * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * @author nowotny <nowotnypl@gmail.com> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); class syntax_plugin_actionlink extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'nowotny', 'email' => 'nowotnypl@gmail.com', 'date' => '2006-05-26', 'name' => 'Actionlink plugin', 'desc' => 'Actionlink plugin lets you use action links in your wiki syntax. Basic syntax: {{actionlink>action|title}}', 'url' => 'http://www.dokuwiki.org/plugin:actionlink', ); } function getType(){ return 'substition'; } function getSort(){ return 306; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{actionlink>.+?\}\}',$mode,'plugin_actionlink'); } function handle($match, $state, $pos, &$handler){ $match = substr($match,13, -2); $matches=explode('|', $match, 2); return array('action'=>hsc($matches[0]),'title'=>hsc($matches[1])); } function render($mode, &$renderer, $data){ if($mode == 'xhtml'){ if(!empty($data['action'])) $action=$data['action']; else $action=''; if(!empty($data['title'])) $title=$data['title']; global $ID; global $INFO; global $REV; global $ACT; global $conf; global $lang; global $auth; switch($action){ case 'edit': #most complicated type - we need to decide on current action if($ACT == 'show' || $ACT == 'search'){ if($INFO['writable']){ if($INFO['exists']){ if(!isset($title)) $title=$lang['btn_edit']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action edit" accesskey="e" rel="nofollow"'); }else{ if(!isset($title)) $title=$lang['btn_create']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action create" accesskey="e" rel="nofollow"'); } }else{ if(!isset($title)) $title=$lang['btn_source']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action source" accesskey="v" rel="nofollow"'); } }else{ if(!isset($title)) $title=$lang['btn_show']; $renderer->doc .=$this->tpll_link(wl($ID,'do=show'), $title, 'class="action show" accesskey="v" rel="nofollow"'); } return true; case 'history': if(!isset($title)) $title=$lang['btn_revs']; $renderer->doc .=$this->tpll_link(wl($ID,'do=revisions'),$title,'class="action revisions" accesskey="o"'); return true; case 'recent': if(!isset($title)) $title=$lang['btn_recent']; $renderer->doc .=$this->tpll_link(wl($ID,'do=recent'),$title,'class="action recent" accesskey="r"'); return true; case 'index': if(!isset($title)) $title=$lang['btn_index']; $renderer->doc .=$this->tpll_link(wl($ID,'do=index'),$title,'class="action index" accesskey="x"'); return true; case 'top': if(!isset($title)) $title=$lang['btn_top']; $renderer->doc .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$title.'</a>'; return true; case 'back': if ($ID = tpl_getparent($ID)) { if(!isset($title)) $title=$lang['btn_back']; $renderer->doc .=$this->tpll_link(wl($ID,'do=show'),$title,'class="action back" accesskey="b"'); return true; } return false; case 'login': if($conf['useacl']){ if($_SERVER['REMOTE_USER']){ if(!isset($title)) $title=$lang['btn_logout']; $renderer->doc .=$this->tpll_link(wl($ID,'do=logout'),$title,'class="action logout"'); }else{ if(!isset($title)) $title=$lang['btn_login']; $renderer->doc .=$this->tpll_link(wl($ID,'do=login'),$title,'class="action logout"'); } return true; } return false; case 'admin': if($INFO['perm'] == AUTH_ADMIN){ if(!isset($title)) $title=$lang['btn_admin']; $renderer->doc .=$this->tpll_link(wl($ID,'do=admin'),$title,'class="action admin"'); return true; } return false; case 'backlink': if(!isset($title)) $title=$lang['btn_backlink']; $renderer->doc .=$this->tpll_link(wl($ID,'do=backlink'),$title, 'class="action backlink"'); return true; default: if(!isset($title)) $title=''; $renderer->doc .= $title; return true; } } return false; } function tpll_link($url,$name,$more=''){ $link='<a href="'.$url.'" '; if ($more) $link.=' '.$more; $link.=">$name</a>"; return $link; } } //Setup VIM: ex: et ts=4 enc=utf-8 :
extended version with some plugins:
<?php /** * Action link plugin. Lets you use action links in your wiki syntax. * Based on the core function - tpl_actionlink(). * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * @author nowotny <nowotnypl@gmail.com> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_INC.'inc/template.php'); //mod class syntax_plugin_actionlink extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'nowotny', 'email' => 'nowotnypl@gmail.com', 'date' => '2006-05-26', 'name' => 'Actionlink plugin', 'desc' => 'Actionlink plugin lets you use action links in your wiki syntax. Basic syntax: {{actionlink>action|title}}', 'url' => 'http://wiki.splitbrain.org/plugin:actionlink', ); } function getType(){ return 'substition'; } function getSort(){ return 306; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{actionlink>.+?\}\}',$mode,'plugin_actionlink'); } function handle($match, $state, $pos, &$handler){ $match = substr($match,13, -2); $matches=explode('|', $match, 2); return array('action'=>hsc($matches[0]),'title'=>hsc($matches[1])); } function render($mode, &$renderer, $data){ if($mode == 'xhtml'){ if(!empty($data['action'])) $action=$data['action']; else $action=''; if(!empty($data['title'])) $title=$data['title']; global $ID; global $INFO; global $REV; global $ACT; global $conf; global $lang; global $auth; switch($action){ case 'edit': #most complicated type - we need to decide on current action if($ACT == 'show' || $ACT == 'search'){ if($INFO['writable']){ if($INFO['exists']){ if(!isset($title)) $title=$lang['btn_edit']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action edit" accesskey="e" rel="nofollow"'); }else{ if(!isset($title)) $title=$lang['btn_create']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action create" accesskey="e" rel="nofollow"'); } }else{ if(!isset($title)) $title=$lang['btn_source']; $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), $title, 'class="action source" accesskey="v" rel="nofollow"'); } }else{ if(!isset($title)) $title=$lang['btn_show']; $renderer->doc .=$this->tpll_link(wl($ID,'do=show'), $title, 'class="action show" accesskey="v" rel="nofollow"'); } return true; case 'history': if(!isset($title)) $title=$lang['btn_revs']; $renderer->doc .=$this->tpll_link(wl($ID,'do=revisions'),$title,'class="action revisions" accesskey="o"'); return true; case 'recent': if(!isset($title)) $title=$lang['btn_recent']; $renderer->doc .=$this->tpll_link(wl($ID,'do=recent'),$title,'class="action recent" accesskey="r"'); return true; case 'index': if(!isset($title)) $title=$lang['btn_index']; $renderer->doc .=$this->tpll_link(wl($ID,'do=index'),$title,'class="action index" accesskey="x"'); return true; case 'top': if(!isset($title)) $title=$lang['btn_top']; $renderer->doc .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$title.'</a>'; return true; case 'back': if ($ID = tpl_getparent($ID)) { if(!isset($title)) $title=$lang['btn_back']; $renderer->doc .=$this->tpll_link(wl($ID,'do=show'),$title,'class="action back" accesskey="b"'); return true; } return false; case 'login': if($conf['useacl']){ if($_SERVER['REMOTE_USER']){ if(!isset($title)) $title=$lang['btn_logout']; $renderer->doc .=$this->tpll_link(wl($ID,'do=logout'),$title,'class="action logout"'); }else{ if(!isset($title)) $title=$lang['btn_login']; $renderer->doc .=$this->tpll_link(wl($ID,'do=login'),$title,'class="action logout"'); } return true; } return false; case 'admin': if($INFO['perm'] == AUTH_ADMIN){ if(!isset($title)) $title=$lang['btn_admin']; $renderer->doc .=$this->tpll_link(wl($ID,'do=admin'),$title,'class="action admin"'); return true; } return false; case 'backlink': if(!isset($title)) $title=$lang['btn_backlink']; $renderer->doc .=$this->tpll_link(wl($ID,'do=backlink'),$title, 'class="action backlink"'); return true; case 'purge': // {{actionlink>purge|Purge}} if(!isset($title)) $title=$lang['btn_purge']; $renderer->doc .=$this->tpll_link(wl($ID,'purge=true'),$title, 'class="action purge"'); return true; case 'subscribe': //mod if(!isset($title)) $title=$lang['btn_subscribe']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"subscribe"), false, "&"),$title,'class="action subscribe"'); return true; case 'addtobook': //mod if(!isset($title)) $title=$lang['btn_addtobook']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"addtobook"), false, "&"),$title,'class="action addtobook"'); return true; case 'cite': //mod if(!isset($title)) $title=$lang['btn_cite']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"cite"), false, "&"),$title,'class="action cite"'); return true; case 'infomail': //mod if(!isset($title)) $title=$lang['btn_infomail']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"infomail"), false, "&"),$title,'class="action infomail"'); return true; case 'export_odt': //mod if(!isset($title)) $title=$lang['btn_export_odt']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"export_odt"), false, "&"),$title,'class="action export_odt"'); return true; case 'export_pdf': //mod if(!isset($title)) $title=$lang['btn_export_pdf']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"export_pdf"), false, "&"),$title,'class="action export_pdf"'); return true; default: if(!isset($title)) $title=''; $renderer->doc .= $title; return true; } } return false; } function tpll_link($url,$name,$more=''){ $link='<a href="'.$url.'" '; if ($more) $link.=' '.$more; $link.=">$name</a>"; return $link; } } //Setup VIM: ex: et ts=4 enc=utf-8 :
Discussion
This is my first DokuWiki plugin ever, so please, be gentle — nowotny 2006-05-26
Wouldn't it be easier to call tpl_actionlink and capture the output?
e.g.ob_start(); tpl_actionlink(...); $renderer->doc .= ob_get_clean();— Christopher Smith 2006-05-26 15:54
Probably… but you wouldn't be able to change the 'title'(caption…? whatever you call it… ). — nowotny 2006-05-26 19:17Fair enough. There are a couple of ways you could do it, but point taken. — Christopher Smith 2006-05-28 14:28
You can (now? or always possible?) set the linktext via the tpl_actionlink-function. Exchange the following code with the original render-function an you benefit to all changes in the tpl_actionlink function
function render($mode, &$renderer, $data) { if($mode == 'xhtml') { if(!empty($data['title'])) $title=$data['title']; if(!empty($data['action'])) { $action=$data['action']; } else { if(!isset($title)) $title=''; $renderer->doc .= $title; return true; } if(isset($title)) { ob_start(); tpl_actionlink($action,'','',$title); $renderer->doc .= ob_get_clean(); } else { ob_start(); tpl_actionlink($action); $renderer->doc .= ob_get_clean(); } return true; } return false; }
— Silbär 2008-05-06 15:34
I'm new to all this, but what would the syntax be when changing the tpl_actionlink function code? — Randy 2008-12-14
The feed.php page returns a missing function error unless inc/template.php is included at the top of the plugin code, otherwise, great little plugin. Thanks!require_once(DOKU_INC.'inc/template.php');— sunny 2006-08-17
Not sure if this plugin is still maintained but is it possible to add a manual link to the search function in this plugin too?
Purge
to add purge, I put following in front of the “default:” fallback:
case 'purge': if(!isset($title)) $title=$lang['btn_purge']; $renderer->doc .=$this->tpll_link(wl($ID,'purge=true'),$title, 'class="action purge"'); return true;
— Hella 2006-10-26
Problem with recent changes
I got a small problem with actionlink>recent (with httaccess rewrite) : it keeps the current page in the URL, resulting in a partial recent changes (it is limited to the current namespace). E.g. on the pagehttp://mydokuwiki.com/namespace/page
,{{actionlink>recent}}
points tohttp://mydokuwiki.com/namespace/page?do=recent
, which show recent changes only for thenamespace
namespace. This also cause the actionlink>index to unwrap the current namespace, but this is less of a problem.
– Fousage
Will this become fixed? Dakkar
This situation happens to me as well. I don't want to change the code, but do you have any solution for this? Something like this would be great:{{actionlink>:recent|Recent Changes}}
in this way, we could use the actions for the namespaces. – Luis Nabais
subscribe-unsubscribe link
Is there any way to implement subscription link with this plugin?. Thanks.
Manuel Munoz
Insert this code into the function “render” :
case 'subscribe': if(!isset($title)) $title=$lang['btn_subscribe']; $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"subscribe"), false, "&"),$title,'class="action subscribe"'); return true;
use NOCACHE
When builing actionlinks for 'admin', 'login' etc. dont forget
~~NOCACHE~~
otherwise (ha!) the page will be cached with authentication infos of the last user editing the page.
Maybe other actions depend on not being cached too…