Indice

isns Plugin

Compatibile con DokuWiki

Non sono state date informazioni sulla compatibilità

plugin If called page doesn't exist, convert page name in namespace name and try to open the index

Ultimo aggiornamento il
2006-01-18
Fornisce
Syntax

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

Taggato con namespace, redirect

What's that?

I have created this plugin because when you show a page which is located in sub-namespace (like php:class:mypage) the “youarehere” indication, show the page and all namespace (php » class » mypage). So, if you click on “php” or “class” link you go on “This topic does not exist”…

Some of user will be disappointed by that…

With this plugin, if you call a page which doesn't exist, the “index” page will be include.

(I hope you'll understand me… I'm not really good in English…).

See plugin in action here: http://www.wikistuce.info/doku.php/logiciels/firefox (this link try to call the page “logiciels:firefox”, but this one does not exist.)

How to install it

With plugin manager: isns.zip

Or without: unpack the zip in /lib/plugins of your DokuWiki folder.

After installing, you must edit “newpage.txt” (located in /inc/lang/<your language>) and write {{isns}} at the end of file.

WARNING: write {{isns}} ONLY AT THE END OF FILE!

Code

<?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');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_isns extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'iDo',
            'email'  => 'iDo@woow-fr.com',
            'date'   => '18/01/2006',
            'name'   => 'isns Plugin',
			'desc'   => 'if the page doesnt exist, try tou open the index. syntax : {{isns}}',
            'url'    => 'http://www.dokuwiki.org/plugin:isns',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 1;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern("{{isns}}",$mode,'plugin_isns');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        return true;
    }  
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){ 
			$n=$this->_IsNs();
			if (@$n)
				$renderer->doc = $n;
            return true;
        }
        return false;
    }
 
	function _IsNs() {
		global $conf;
		global $ID;
		$pn=wikiFN($ID);
		if ((!file_exists($pn)) && (is_dir(substr($pn,0,-4)))) {
			ob_start();
			html_index($ID);
			return ob_get_clean();;
		}
		return false;
	}
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

Comments

How can i modify that to bring “topic:start” or “topic:index” instead of the “index”, is this possible? would be even cooler. Of course that should be ACL secure :|

Solution

I patched DokuWiki to do what you need (and me too). What my code does: If there is a page called “index” inside of the assumed namespace, this one is taken as the wanted one (ie, ACL and everything else applies, as this is done later on). Furthermore, if there is no such page, but a namespace exists, show an appropriate index page.

I posted a patch here, but it is not accurate anymore. It had to be extended in some ways. If you are interested, better mail me for details.

You can see it in action here. Try the links to see the “index” redirect, playground/ to see the generated index page, or some invalid page, too (which should still show the “newpage” text).

Sadly enough, this is not a plugin and I don't know how to do it as a plugin. – Johannes Jordan (dokuwiki at lanrules.de)