====== GOTO Plugin ======
---- plugin ----
description: Easily have a page redirect to another page in the wiki.
author : Allen Ormond
email : 2006-07-19
type : syntax
lastupdate : 2006-07-19
compatible : 2006-11-06
depends :
conflicts :
similar :
tags : redirect
----
This [[plugins|plugin]] requires the user to have javascript enabled in order to work to its fullest. However, a redirect link will still be displayed even without javascript.
===== Syntax =====
You can put the GOTO string anywhere in the document, but it probably makes the most sense to put it at the top.
~~GOTO>wiki:syntax~~
The above will force the document to redirect to the [[syntax]] page after the default amount of seconds. You can change the default number of seconds by editing the plugin (by default, this is 10 seconds).
You can change the number of seconds on the fly like so:
~~GOTO>wiki:syntax?15~~
This will redirect the page after a 15 second pause.
By default, users can't set the pause length to be faster than three seconds, but this can be changed by editing the plugin. The reason for the minimum pause length is that if it's too fast, it becomes difficult to hit the 'Edit Page' button before the redirect happens. If you can't edit the page, then it becomes tricky to remove the redirect.
===== Issues =====
*When editing a page with the ''GOTO'' tag, be careful of hitting the 'Preview' button. The preview **will** redirect just the same as the saved page.
*The viewer's web browser must have javascript enabled in order to automatically redirect.
*Currently, the plugin only works correctly for internal links.
===== Installation =====
Download a zip [[http://yeahway.com/stuff/plugingoto.zip|here]], unzip and put the ''goto'' folder in your ''lib/plugins'' directory.
If you want to modify the default pause length and the minimum pause length, edit the following lines in ''syntax.php'':
$seconds = 10; //Default number of seconds to wait before redirect.
$minSeconds = 3; //Minimum number of seconds allowed before redirect.
You can change the redirect message that is displayed by editing the following line in syntax.php:
$message = "You will be redirected to %d in approximately %s seconds.";
''%d'' will be replaced with a link to the destination.\\
''%s'' will be replaced with the number of seconds before redirection.
===== syntax.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');
class syntax_plugin_goto extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Allen Ormond',
'email' => 'aormond atgmaildotcom',
'date' => '2006-07-19',
'name' => 'GOTO',
'desc' => 'Easily redirect to other pages in your wiki.',
'url' => 'http://www.dokuwiki.org/plugin:goto',
);
}
function getType(){
return('substition');
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('(?i)~~GOTO>.+?~~',$mode,'plugin_goto');
}
function getSort() {
return 249;
}
function handle($match, $state, $pos, &$handler){
$seconds = 10; //Default number of seconds to wait before redirect.
$minSeconds = 3; //Minimum number of seconds allowed before redirect.
/* $message is the redirection message that is displayed. %d will be replaced with a link
* to the destination. %s will be replaced with the number of seconds before redirect. */
$message = "You will be redirected to %d in approximately %s seconds.";
global $ID;
$matches = explode("?", substr($match,7,-2));
if (is_numeric($matches[1])){ $seconds = $matches[1]; }
if ($seconds < $minSeconds){ $seconds = $minSeconds; }//Check that seconds is greater than $minSeconds.
resolve_pageid(getNS($ID), $matches[0], $exists);
$message = str_replace("%D","%d",$message);//Make %d case insensitive.
$message = str_replace("%S","%s",$message);//Make %s case insensitive.
return array($matches[0], $seconds, $message);
}
function render($format, &$renderer, $data) {
$message = str_replace("%d",$renderer->internallink($data[0], $data[0],'', true),$data[2]);
$message = str_replace("%s",$data[1],$message);
$renderer->doc .= $message;
$renderer->doc .= '';
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
===== Revision History =====
* 2006-06-30 --- Released.\\
* 2006-07-19 --- Made it easier to customize the displayed redirect message.
===== Discussion =====
Right now this plugin can only redirect to internal wiki pages. I'd like it to be able to redirect to external pages, but I'm a little hazy on how DokuWiki processes URLs. Any help is appreciated. --- //[[aormond@gmail.com|Allen Ormond]] 2006-06-30 22:35//
I don't see the point of a page with a ~~GOTO~~ and then some additional content. I'd suggest that if a page contains only an internal link, make an HTTP-header (HTTP 301 response code) redirection and then show a "Redirected from ..." in the destination page. I'm not that convinced on the subject of automatic external redirection. --- //[[atnbueno@mundoplus.tv|Antonio Bueno]] 2006-07-28 13:25//
>I agree, that does sound nice. However, there are a couple reasons I didn't use an http header redirection. As far as I know, it's impossible to make a simple syntax plugin to do it (or at least it's beyond my abilities). Also, if the page redirects without being seen, it would become difficult for a user to remove the redirect. Of course, I'd love to see a more elegant solution, but this is working for me for now. ^_^ --- //[[aormond@gmail.com|Allen Ormond]] 2006-07-29 01:16//
>>How about a parameter that disables the redirect, e.g. redirect=no?
>>>I set min and default to 0, and use the ?do=edit to stop the redirect. Granted that's not going to work for all users..
Sorry, but this Plugin is a Crap. Why did you not use the all Wiki Standardcode like :
#redirect [[Articlename]]
??
The code you use is to complex and nobody can remember this.
> You're welcome to do better.
> If there actually existed something like an "all Wiki Standardcode", we would all be happy to implement and use it. But there is no such thing!
>> Ever head of [[http://www.wikicreole.org/ |Wiki Creole]]? --Fabian
>>You have to now "#redirect" in the same way like you have to now "~~GOTO~~".
>>Use "\inc\lang\en\edit.txt" to advice the users if necessary.
>>The only thing is, that such a basic function should by part of the basecode.
----
$seconds and $minSeconds could by inserted in to the amin-configuration.
----
==== Why not using HTTP redirects? ====
If you add
ob_start();
ob_implicit_flush(FALSE);
to ''doku.php'' it would be possible to do HTTP redirects by using ''header('Location: ...');'' , which would have some advantages:
- No need to enable JavaScript
- No extra clicks for visitors, if they disabled JavaScript
The issue "editing a page may be tricky" is not right - you can alway enter "pagename?do=edit" manually in the browser - so what's the point?
==== Languages ====
Change
$message = "You will be redirected to %d in approximately %s seconds.";
to
$message = "".$this->getLang('redirect')."";
and
Input this in the Path "lang"
== en ==
== de ==
== fr ==
== es ==