DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:mredirect

MRedirect Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" unknown
  • 2016-06-26 "Elenor Of Tsort" unknown
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

plugin Redirection plugin - any page containing nothing but a standard link will auto-redirect instantaneously

Last updated on
2013-09-10
Provides
Action
Repository
Source

Similar to goto, redirect

Tagged with redirect

Description

Redirection from one page to another. The redirecting page must contain nothing but a standard DokuWiki link to the target page (this may include namespace and/or a section anchor), OR a standard URL.

At wiki-internal redirection a small message pops up showing where you came from (using the standard msg() function). Click the page name in this message to go straight to the redirecting article in edit mode.

Updates:

  • 2012-02-10: Added support for outside standard URLs. (Hat tip: JP Viljoen)
  • 2013-05-24: Better support for complex namespace calls.
  • 2013-09-10: GitHub repository added.

Installation

Download the plugin files using the link above. Create a plugin directory named mredirect and put the unzipped files in it.

Discussion

Use Heading Extension

I find the plugin extremely useful and elegant, so thanks a lot for that. As I also like the useheading option of the wiki, I made the plugin compatible with it, or at least support it more.

This is the file from above with two changes:

  • The regular expression now also allows for a single headline, with an optional newline, before the link, so the page gets a nice name in the rest of the wiki.
  • The redirection notice will now use this title, if present, to show from where the user was redirected.

Maybe this will be useful for someone else :-) I apologize if adding this section here broke some guideline of these plugin pages.

action.php
<?php
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
class action_plugin_mredirect extends DokuWiki_Action_Plugin {
 
    function register(Doku_Event_Handler $controller){
        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_start', array());
    }
 
    function handle_start(&$event, $param){
        global $ID;
        global $ACT;
        global $INFO;
 
      if ($ACT != 'show') return;
      if (!($INFO['exists'])) return;      # don't try to read an article that doesn't exist

      $text = rawWiki($ID);
      if(preg_match('/^([=]+[^=]+[=]+[\n]?)?\[\[([^]#]*)\#?([^]]*)\]\]$/',$text,$p)) {
        msg(sprintf('From: <a href="'.wl($ID,'do=edit').'">'.tpl_pagetitle($ID, true).'</a>'));
        $check = false;    # dummy variable for sectionID
        $url = ($p[3] == '') ? wl($p[2]) : wl($p[2]) . '#' . sectionID($p[3], $check);
        idx_addPage($ID);  # seemingly required for fulltext search indexing of the page, without which we won't show up on the$
        send_redirect($url);
      }
    }
}
?>

Installation instructions?

Can't this be made into a standard plugin rather than a snippet of code? I only have limited understanding of php and how Dokuwiki works - I'm assuming you put this as an action.php file in the Plugins folder? Proper instructions for n00bs would be helpful.

Also to be honest this seems like the kinda functionality that should really be integrated into Dokuwiki!


Seems to be just the plugin I am looking for! :-)

But I don't have a clue how to use the snippet! It would be great if you could create a downloadable plugin or give or short hint to implement the snippet. It would be very helpful for me!

Thx, thomas [dot] 81 [at] outlook [dot] com]]


Very useful plugin, thanks! I couldn't find a way to do it myself, and I was beginning to pull my hair…

For those who don't know how to use it, it's very simple: Install the plugin in your plugin directory, as explained, and any page that has no other content than a link, will be automatically redirected to the URL the link points to. It can be very useful, for instance, when you want to get “rid of” start pages you don't use: you can redirect them to your homepage, or whatever…

plugin/mredirect.txt · Last modified: 2016-01-13 14:41 by Aleksandr