page_redirector plugin by David Lorentsen
Redirect a wiki page to another wiki page
Last updated on 2007-01-24. Provides Syntax, Action.
No compatibility info given!
Similar to 404manager.
This plugin allows you to redirect users between pages and namespaces by adding a particular pattern to a page.
To cut down on the work needed when updating this plugin, I have decided to keep downloads, install, usage, history and so on, on my own site. Since that wiki isn't open to be edited without a user, I figured it would be best to leave discussion, ideas, bugs here. You are also welcome to email me. — David Lorentsen 2007-01-24 20:12
After the plugin is installed, a simple code redirects to another page:
~~REDIRECT>namespace:page~~
I'm not sure if this is the current source, but I'm adding it here as the author's link seems to be returning a 404 not found error. — Christopher Smith 2008/12/11 14:13
<?php /** * Action Plugin: Redirects page requests based on content * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author David Lorentsen <zyberdog@quakenet.org> */ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); /** * All DokuWiki action plugins need to inherit from this class */ class action_plugin_page_redirect extends DokuWiki_Action_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'David Lorentsen', 'email' => 'zyberdog@quakenet.org', 'date' => '2006-11-09', 'name' => 'Page Redirector', 'desc' => 'Redirects page requests based on content', 'url' => 'http://wiki.splitbrain.org/plugin:page_redirector', ); } function register(&$controller) { $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE', $this, 'handle_page_redirect'); } function handle_page_redirect(&$event, $param) { global $ID; if ($event->data == 'show') { if (isset($_GET['redirect']) && $_GET['redirect'] == 'no') { return; } $file = wikiFN($ID,''); $content = io_readfile($file); if (preg_match('/~~REDIRECT>([a-zA-Z0-9_\-:]+)~~/', $content, $matches)) { header("Location: ".wl($matches[1],'',TRUE)); } } } } //Setup VIM: ex: et ts=4 enc=utf-8 :
The wantedpages.php script breaks with this plugin:
ornellas@pound:~/ornellas.apanela.com/dokuwiki/bin$ php wantedpages.php Fatal error: Call to undefined function html_wikilink() in /home/.karamazov/ornellas/ornellas.apanela.com/dokuwiki/lib/plugins/pageredirect/syntax.php on line 50 ornellas@pound:~/ornellas.apanela.com/dokuwiki/bin$
To fix it, edit lib/plugins/pageredirect/syntax.php. After the first require_once add:
require_once(DOKU_INC.'inc/html.php');
This should solve the issue.
I had a problem with this plugin. One of pages was using it to redirect user to other page (A → B), but later I decided to “switch” pages and make the redirection work in the other direction: B → A. I removed redirection line from page A and added text onto this page; then removed text from site B and added a redirection line. All I get was a loop redirection (stopped after 5 redirections). Disabling and enabling or even reinstalling the plugin did not help…
Anyone solved this?
Solution: Open the redirect page you want to edit with the parameter ”?redirect=no” in the URL and you will get the page without getting redirected. — Markus Frosch 2008/08/06 10:17
Maybe an idea to lift this one from devel status so that it can be added to http://wikimatrix.org ? I just can't stand the idea that it is not available in DokuWiki
If you redirect something it keeps redirecting even if you uninstall and reinstall a fresh plugin….does anyone know where the heck this data is stored so I can go in and change it.Did you try ~~NOCACHE~~ on the redirected page?
For me the notice that I was redirected didn't display on the page. It's cause by the session not being started. The solution is to add session_start(); just underneath require_once(DOKU_PLUGIN.'action.php'); and comment out the other line that says session_start(); just above $_SESSION[DOKU_COOKIE]['redirect'] = $ID; — Ryan McCue
There's a slight problem with the plugin: if the page has a period in it's name the plugin won't work. Could you make it accept periods in the title? -Claws
I confirm. — Floriang 2009/05/17 18:44
The code you append to the URL to stop the redirect is ”&redirect=no”. -tjones
Redirecting to pages with Cyrillic names won't work! :( Can anyone help to solve this issue? -lolmaus
I've made patch that will allow anything in redirected page name, it works as the link is converted to wiki path internally
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/dokuwiki-plugin-pageredirect-pagematch.patch
— Elan Ruusamäe 2008/01/25 11:41
It says for build-2: “Optional text to tell the user he has been redirected.” Where is this described? I found no hints anywhere?! Bernd, April 16, 2008, 14:19
Is there a way to make the “Index” page exclude redirects? Thanks, – Matthew Pietz, 2008-07-22 14:17:23
Developer, do you plan on updating the plugin to merge the bug fix for the wantedpages.php script bug? The patch is in this page, only a merge is needed. Please update if you can. — Dace 2008/11/05 13:10
For me I changed the regex from ”~~REDIRECT>[a-zA-Z0-9_\-:]+~~” to ”~~REDIRECT>[a-zA-Z0-9_\-:\.]+~~”, because in my wiki I have pagenames including ”.”. Is there a reason why hasn't been done in the original plugin? Dominik, 13.11.2008
This plugin sends my webserver into an infinite loop when I try to access (or even link to) a page with a redirect on it while useheading is enabled.
I managed to change this plugin so that it accepts the quasi-standard ”#REDIRECT namespace:pagename” (or even ”#REDIRECT namespace/pagename”) syntax for the declaration. This is how:
Step 1: Change line #39 of syntax.php from this:
$this->Lexer->addSpecialPattern('~~REDIRECT>[a-zA-Z0-9_\-:]+~~', $mode, 'plugin_pageredirect');
To this:
$this->Lexer->addSpecialPattern('#REDIRECT .+', $mode, 'plugin_pageredirect');
Step 2: Change line #47 of syntax.php from this:
$page = substr($match,11,-2);
To this:
$page = substr($match,10,-1);
Seems to work just fine for me, although I haven't exactly stress-tested it or anything. You can grab a zipfile (which should work with Plugin Manager) with this revision included at http://nwcs.com/~jvc/pageredirect_modified.zip.
— Jo Valentine-Cooper, 2 August 2009
Thanks for David Lorentsen and Jo Valentine-Cooper. Now it works on multi-byte characters page. 1 January 2010 —raychani