This is an old revision of the document!
Table of Contents
autostart plugin
Compatible with DokuWiki
>= 2006-11-06
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.
Similar to 404manager, autosearch
Download | dokuwiki-plugin-autostart.tgz |
---|
Description
If a non-existent page is requested, but a namespace with that name exists, and it has a start page, you will be redirected to it. I think the autosearch plugin does this, but I haven't been able to obtain it.
Source Code
Create a directory autostart
in /wiki/lib/plugins
and save the code in a action.php
file there.
<?php /** * Autostart Plugin: Redirects to the namespace's start page if available * * @author Jesús A. Álvarez <zydeco@namedfork.net> */ 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_autostart extends DokuWiki_Action_Plugin { function getInfo() { return array ( 'author' => 'Jesús A. Álvarez', 'email' => 'zydeco@namedfork.net', 'date' => '2008-04-28', 'name' => 'Autostart Plugin', 'desc' => "Redirect from the namespace's name to its start page", 'url' => 'http://www.dokuwiki.org/plugin:autostart', ); } function page_exists($id) { if (function_exists('page_exists')) return page_exists($id); else return @file_exists(wikiFN($id)); } function register(&$controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'preprocess', array ()); } function preprocess(& $event, $param) { global $conf; global $ID; if (!$this->page_exists($ID) && $event->data == 'show') { if($this->page_exists($ID.':'.$conf['start'])) // start page inside namespace $id = $ID.':'.$conf['start']; elseif($this->page_exists($ID.':'.noNS(cleanID($ID)))) // page named like the NS inside the NS $id = $ID.':'.noNS(cleanID($ID)); if ($id) header('Location: ' . wl($id,'',true)); } } }
Discussion
Nice work! Thanks! - Jason Xun Xu jasonxu [dot] dev [at] gmail [dot] com
Very handy plugin, great work! By the way: redirecting into a namespace (e.g. foobar → foobar:start) only works if the user/group has at least read permissions for the underlying/root namespace. In certain setups, e.g. one namespace per customer, this can be very tedious to securely implement. By removing a condition for the HTTP redirect this works out and permissions are checked on the target page anyway.
--- lib/plugins/autostart/action.php.orig 2009-11-24 20:41:31.000000000 +0100 +++ lib/plugins/autostart/action.php 2009-11-24 20:42:58.000000000 +0100 @@ -36,7 +36,7 @@ function preprocess(& $event, $param) { global $conf; global $ID; - if (!$this->page_exists($ID) && $event->data == 'show') + if (!$this->page_exists($ID)) { if($this->page_exists($ID.':'.$conf['start'])) // start page inside namespace
Andreas de Pretis ad [at] 25th [dash] floor [dot] com