DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:revlink

Revision Link Plugin

Compatible with DokuWiki

2009-01-25+

plugin Extend internal link syntax to allow linking to a previous revision a of page.

Last updated on
2009-01-25
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with !discontinued, links, revisions

Not needed anymore

While this plugin may have been necessary with older releases of Dokuwiki, it is actually not needed anymore, unless you want to use the specific @ syntax.

To create a link to a page's specific revision, you can simply use a regular internal link, appending ?rev=XXX to the page name, e.g. Old revision of this page :

[[revlink?rev=1238874513|Old revision of this page]]

This has been tested with Release 2018-04-22 “Greebo”.

Syntax

Just append '@<revision #>' to the page name of an internal link, e.g.

[[page@1234567890|Page (old version)]]

Installation

Just copy the code below into the file lib/plugins/revlink/syntax.php

For more help, refer to Plugins on how to install plugins manually.

Wish list

  • Append to tooltip the revision a link is linking to.
  • Be more permissive with the revision number, perhaps linking to the last revision at or before the given revision number.
  • Allow other formats for referring to a revision, such as date and time

Issues

  • Possibly would not work with other XHTML renderer plugins, as revlink assumes the existence of a particular set of arguments on the renderer's internallink method.

Code

lib/plugins/revlink/syntax.php
<?php
/**
 * Revision Link plugin
 *
 * Syntax: internal links with '@<revision #>' appended to the
 *         page name will make links to that revision of the page.
 *         e.g. [[page@1234567890|Page (old version)]]
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Braden Pellett <dokuwiki@dabrado.net>
 */
 
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');
 
/**
 * revlink plugin
 */
class syntax_plugin_revlink extends DokuWiki_Syntax_Plugin {
 
   /**
    * Get an associative array with plugin info.
    */
    function getInfo(){
        return array(
            'author' => 'Braden Pellett',
            'email'  => 'dokuwiki@dabrado.net',
            'date'   => '2009-01-25',
            'name'   => 'Revision Link',
            'desc'   => 'Extend internal link syntax to allow linking to a previous revision a of page.',
            'url'    => 'http://www.dokuwiki.org/plugin:revlink',
        );
    }
 
   /**
    * We are a substitution type.
    */
    function getType(){
        return 'substition';
    }
 
   /**
    * Hijack internallink.
    */
    function connectTo($mode) {
      $this->Lexer->mapHandler('internallink','plugin_revlink');
    }
 
   /**
    * Sort position only matters if another plugin uses mapHandler to remap
    * 'internallink'.  Two such plugins cannot coexist, as far as I know.
    */
    function getSort(){
        return 999;
    }
 
   /**
    * Do $hander's internallink work, and if we find that it was actually
    * an internal link and one that contained a revision reference, then
    * pull that out and pass it on to our renderer.
    */
    function handle($match, $state, $pos, &$handler){
        $handler->internallink($match, $state, $pos);
        $calls=&$handler->CallWriter->calls;
        if(!$calls){
            $calls=&$handler->calls;
        }
        $call=end($calls);
        $data=false;
        if($call[0] == 'internallink'){
            preg_match('/^(.*?)(?:@(\d+))?(#.*?)?$/', $call[1][0], $matches);
            if($matches[2]){
                array_pop($calls);
                $data=array($matches[1].$matches[3], $matches[2], $call[1][1]);
            }
        }
        return $data;
    }
 
   /**
    * Render internal link as XHTML using normal procedure, and then in the
    * href part of the resulting XHTML we add in the needed ?rev=xxxx.
    */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $xhtml=$renderer->internallink($data[0], $data[2], NULL, true);
            $renderer->doc .= preg_replace('/(href=".*?)((#.*?)?")/', '$1&rev='.$data[1].'$2', $xhtml);
            return true;
        }
        return false;
    }
}

Comments

It seems that revlink is not compatible with siteexport 2016-08-30. Deactivate the siteexport plugin to work with revlink.

plugin/revlink.txt · Last modified: 2020-05-13 11:30 by Michaelsy