This is an old revision of the document!
Table of Contents
Pagespace Plugin
By the same author
Compatible with DokuWiki
2007-06-26b
The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Rationale
I love DokuWiki, and use it all the time both at work as a knowledge repository, and at home for my own thoughts and ideas. The one thing I found a little tiresome was typing in long internal links; so I love the idea of relative links. It makes it much easier to create clean clear namespace layouts.
At present you can create the following relative links (if I've understood correctly…!):
- To the root namespace
[[:new link]]
- To the parent namespace (back 2)
[[..:new link]]
- Or to the current namespace (back 1)
[[.:new link]]
What I propose adding is a syntax to create a link to the pagespace, i.e. a namespace based on the current page name
Syntax
Let's assume the current page name (top left in a standard DokuWiki installation) is as follows:
[[plugin:pagespace]]
This means that the current namespace is plugin and the current page is pagespace
Using the following syntax:
[[@new link]] or [[@:new link]]
This link would be created:
[[plugin:pagespace:new_link]]
And that's basically all there is to it!
Code
<?php 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'); /** Creates a relative link to the current 'Pagespace' i.e. a namespace based on current page name (page ID)) To use: If current page name is: [[root:parent:current_page]] then [[@:new page]] or [[@new page]] would result in the following link: [[root:parent:current_page:new_page]] License: GPL */ class syntax_plugin_pagespace extends DokuWiki_Syntax_Plugin { function getInfo() { return array('author' => 'Symon Bent', 'email' => 'symonbent [at] gmail [dot-com]', 'name' => 'pagespace', 'desc' => "New syntax to allow a relative link to a namespace based on current page name, e.g. [[@:new page]]", 'url' => ''); } function getType() { return 'substition'; } function getSort() { return 239; } function connectTo($mode) { $this->Lexer->addSpecialPattern("\[\[\@.+?\]\]",$mode,'plugin_pagespace'); } function handle($match, $state, $pos, &$handler) { //Swaps the @ symbol for the current page ID global $ID; global $conf; $pagespace = $ID; $link = $match; //Ignore the start (root) namespace if ($pagespace == $conf['start']) { $pagespace = ''; } else { $pagespace .= ':'; } // Only replace an initial @ symbol, not elsewhere in link $link = str_replace("[[@", "[[".$pagespace, $link); dbglog($link); // Strip the opening and closing markup $link = substr($link, 2, -2); // Split title from URL $link = preg_split('/\|/u', $link, 2); if ( !isset($link[1]) ) { $link[1] = NULL; } return $link; } function render($mode, &$renderer, $data) { if ($mode == 'xhtml') { $renderer->internallink($data[0], $data[1]); return true; } return false; } }
History
- 2008-01-15: First release, warts and all!
- 2008-02-08: Bug fix - plugin now adds nothing to root namespace, and fixed a little bug in render function
Discussion
This is only my second plugin, the previous one has not been published (it was a adaption of the explain plugin which allowed the glossary to be a normal wiki page. I found it very useful…anybody interested?)
I still have much to learn so any suggestions, improvements, and comments are most welcome. Thanks to all the rest of you for sharing so generously!