====== Actionlink plugin ======
---- plugin ----
description: This plugin lets you use actionlinks in your wiki syntax. It's based on the DokuWiki's core function tpl_actionlink().
author : nowotny
email : nowotnypl@gmail.com
type : syntax
lastupdate : 2006-05-26
compatible :
depends :
conflicts :
similar :
tags : links
----
===== 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
* 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
\\
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:plugin|plugin manager]].\\
\\
Sources: [[http://mbot.ovh.org/plugin-actionlink-2005-05-26.tar.gz|plugin-actionlink-2005-05-26.tar.gz(2kb)]] | [[http://mbot.ovh.org/plugin-actionlink-2005-05-26.zip|plugin-actionlink-2005-05-26.zip(2kb)]]
To install manually: create a folder ''actionlink'' in ''lib/plugins'' and put the code below in ''syntax.php''.
* @author Matthias Grimm
* @author nowotny
*/
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 .= ''.$title.'';
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='$name";
return $link;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
====== Discussion ======
This is my first DokuWiki plugin ever, so please, be gentle ;-) --- //[[nowotnypl@gmail.com|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();
--- //[[chris@jalakai.co.uk|Christopher Smith]] 2006-05-26 15:54//
>>Probably... but you wouldn't be able to change the 'title'(caption...? whatever you call it... :-) ). --- //[[nowotnypl@gmail.com|nowotny]] 2006-05-26 19:17//
>>> Fair enough. There are a couple of ways you could do it, but point taken. :-) --- //[[chris@jalakai.co.uk|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;
}
--- //[[Timo.Falk@gmx.de|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? --- //[[techsyn@cablene.com|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@poeticpublishing.com|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;
--- //[[http://www.unixwitch.de|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 page ''%%http://mydokuwiki.com/namespace/page%%'', ''%%{{actionlink>recent}}%%'' points to ''%%http://mydokuwiki.com/namespace/page?do=recent%%'', which show recent changes only for the ''%%namespace%%'' 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
===== subscribe-unsubscribe link =====
Is there any way to implement subscription link with this plugin?. Thanks.
[[anestesiadorhvs@yahoo.es|Manuel Munoz]]
===== 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...