DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:addnewpage_old

This is an old revision of the document!


add new page (old)

description: DISCONTINUED: Use addnewpage instead.
type : syntax
conflicts : addnewpage
similar : new_page_dialog, addnewpage
tags : !discontinued

This plugin, add a select box and an input box for adding new page.
The select box containt all namespace of your wiki.
see in action here

inspired from newpagebutton

syntax

Just write {{NEWPAGE}} :)

Install

With plugin manager, use this zip : http://dokuplugins.idotech.info/addnewpage_old.zip
or manualy :
extract archive and put folder in your wiki folder “lib/plugins/”

Now, you must edit your config file (conf/local.php) and add this line :

$conf['exclude']=array();

use this array to exclude namespace. For example, if you do not want “wiki” namespace appear in the code write :

$conf['exclude']=array('wiki');

Code

(use only if link is broken)
(put this code in “lib/plugins/addnewpage/syntax.php”)

<?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_addnewpage extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'iDo',
            'email'  => 'ido@idotech.info',
            'date'   => '05/04/2006',
            'name'   => 'addnewpage',
            'desc'   => 'add select avec edit for adding new page',
            'url'    => 'http://www.dokuwiki.org/plugin:addnewpage',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * What kind of syntax do we allow (optional)
     */
//    function getAllowedTypes() {
//        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
//    }
 
    /**
     * What about paragraphs? (optional)
     */
    function getPType(){
        return 'block';
    }
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 199;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('{{NEWPAGE}}', $mode, 'plugin_addnewpage');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
		return array();
    }
 
 
function render($mode, &$renderer, $data) {
		$renderer->info['cache'] = false;
    	global $conf, $lang;
 
		if ($mode == 'xhtml') {
$renderer->doc .= utf8_encode('<script type="text/javascript">
   function noaccent(chaine) {
      temp = chaine.replace(/[àâä]/gi,"a")
      temp = temp.replace(/[éèêë]/gi,"e")
      temp = temp.replace(/[îï]/gi,"i")
      temp = temp.replace(/[ôö]/gi,"o")
      temp = temp.replace(/[ùûü]/gi,"u")
	  temp = temp.replace(/[ç]/gi,"c")
      return temp
   }
  </script>');;
		    $renderer->doc .= '<div class="addnewpage_form" id="addnewpage_form" align="left">';
		    $renderer->doc .= '<form name="editform" method="post" action="" accept-charset="'.$lang['encoding'].'">';
		    $renderer->doc .= $this->_makecombo();
		    $renderer->doc .= '<input class="edit" type="text" name="title" id="addnewpage_title" size="20" maxlength="255" tabindex="2" />';    
		    $renderer->doc .= '<input class="button" type="submit" value="'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex="3"  onclick="v=document.location.href.split(\'?\');document.location.href=v[0]+\'?id=\'+document.getElementById(\'np_cat\').value+\':\'+noaccent(document.getElementById(\'addnewpage_title\').value)+\'&do=edit\';return false;" />';
		    $renderer->doc .= '</form>';
		    $renderer->doc .= '</div>';
			return true;
		}
		return false;
	}
	function _makecombo() {
		global $ID;
		$ns=explode(':',$ID);
		array_pop($ns);
		$ns=implode(':',$ns);
 
		$r=$this->_getnslist('');
		$ret='<select id="np_cat" tabindex="1">';
		$ret.='<option '.(($ns=='')?'selected="true"':'').' value="">'.((@$this->getLang('namespaceRoot'))?$this->getLang('namespaceRoot'):'top').'</option>';       // empty value for root namespace
		foreach ($r as $k => $v) {
			$vv=explode(':',$v);
			$vv=str_repeat('&nbsp;&nbsp;',substr_count($v, ':')).$vv[count($vv)-1];
			$ret.='<option '.(($ns==$v)?'selected="true"':'').' value="'.$v.'">'.$vv.'</option>';
 
			//$ret.='<option '.(($k==0)?'selected="true"':'').' value="'.$v.'">'.$vv.'</option>';
			//$ret.='<option value="'.$v.'">'.$vv.'</option>';
		}
		$ret.='</select>';
		return $ret;
	}
	function _getnslist ($tns='') {
		require_once(DOKU_INC.'inc/search.php');
		global $conf;
 
		if ($tns=='')
			$tns = $conf['datadir'];
 
		if (!is_dir($tns))
			$tns  = str_replace(':','/',$tns);
 
		$data = array();
 
		if (!isset($conf['exclude']))
			$conf['exclude']=array();
		if (gettype($conf['exclude'])!="array")
			$conf['exclude']=array();
 
 
		search($data,$tns,'search_index',array('ns' => ''));
 
		foreach($conf['exclude'] as $k => $v)
			$conf['exclude'][$k]=strtolower($v);
 
		$data2 = array();
		foreach($data as $k => $v) {
			if ($v['type']=='d') {
				if (!in_array(strtolower($v['id']),$conf['exclude'])) {
					array_push($data2,$v['id']);
					$r=$this->_getnslist($tns.'/'.$v['id']);
					foreach ($r as $vv) {
						if (!in_array(strtolower($vv),$conf['exclude']))
							array_push($data2,$v['id'].':'.$vv);
					}
				}
			}
		}
		return $data2;
	} 
}
 
?>

Tips

If you want to show the add new page forms out off a page (for example in your template), put this line where you want to see the plugin :

<?php
echo p_render('xhtml',p_get_instructions('{{NEWPAGE}}'),$info);
?>	

If you want to beautify the look of combobox, replace line

$ret='<select id="np_cat" tabindex="1">';

by

$ret='<select id="np_cat" tabindex="1" class="edit">';

Kibi 2006-07-03 22:49

Language

  • French
  • English
  • Russian
  • Italian
  • Other ? add here or mail me : ido@woow-fr.com

Update

2006-11-14 :
Fixed :

  • Bug with new dokuwiki version

Added :

  • Italian language file

2006-07-05 :
Fixed :

  • Zip file is now ok

Added :

  • Russian language file

2006-06-20 :
Fixed :

  • Problem with the empty select box

Added :

  • Multilanguage Support
  • Root Namespace (see Kibi's comment)
  • The selected line is now the same as the current namespace (see Kibi's comment)

Addition

Russian translation

<?php
/**
 * russian language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Alexander Sorkin <kibizoid@gmail.com>
 */
 
/* we don't need these in syntax plugins, do we?
// settings must be present and set appropriately for the language
$lang['encoding']   = 'utf-8';
$lang['direction']  = 'ltr'; */
 
// custom language strings for the plugin
$lang['namespaceRoot']="Корневой уровень";
$lang['okbutton']     = 'Добавить страницу';
//Setup VIM: ex: et ts=2 enc=utf-8 :

Italian translation

<?php
/**
 * italian language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Daniele Savasta <danielesavasta@tiscali.it>
 */
 
/* we don't need these in syntax plugins, do we?
// settings must be present and set appropriately for the language
$lang['encoding']   = 'utf-8';
$lang['direction']  = 'ltr'; */
 
// custom language strings for the plugin
$lang['namespaceRoot']="Root";
$lang['okbutton']     = 'Aggiungi Pagina';
//Setup VIM: ex: et ts=2 enc=utf-8 :

Dutch translation

<?php
/**
 * dutch (nederlands) language file
 *
 * @license    Public domain
 * @author     Anoniem <anoniem>
 */
 
// custom language strings for the plugin
$lang['namespaceRoot']="root";
$lang['okbutton']     = 'Voeg pagina toe';

German translation

<?php
/*
german language file
 */
$lang['namespaceRoot']="Wurzel";
$lang['okbutton']     = 'Seite hinzufügen';
//Setup VIM: ex: et ts=2 enc=utf-8 :
?>

Comments

18 June - the install does not work with the plugin manager, because the folder is not zipped as well. You need to include the folder. It does work when you go in, make the folder, then upload the syntax.php file into the folder. –Rick Cogley

It does not seem to work with IE6 - gives JavaScript error… FireFox 1.5.x is OK.

Ok, the code is updated (that was an charset error)

iDo 2006-04-20 14:54

Found two problems:

  • Got some troubles on windows (empty select box). Commenting line 115 fixed it.
//$tns  = str_replace(':','/',$tns);

This tip don't resolve the problem.

This issue is corrected
  • On IE, parameters are not submitted right. Changing line 90 from
$renderer->doc .= '<input class="button" type="submit" value="ok" tabindex="3"  onclick="v=document.location.href.split(\'?\');document.location.href=v[0]+\'?id=\'+document.getElementById(\'np_cat\').value+\':\'+noaccent(document.getElementById(\'addnewpage_title\').value)+\'&do=edit\';return false;"

to

$renderer->doc .= '<input class="button" type="submit" value="ok" tabindex="3"  onclick="v=document.location.href.split(\'?\');this.form.action=v[0]+\'?id=\'+document.getElementById(\'np_cat\').value+\':\'+noaccent(document.getElementById(\'addnewpage_title\').value)+\'&do=edit\';this.submit();" />';

fixed it. — loïc 2006-04-28 15:00


23 june 06

There is a bug, when you enter ' double times. FIXME ! - Stan Pol

On my config ' are deleted. There is an URL where i can see the bug ?
Perhaps adding
temp = temp.replace(/[\']/g,"")

after

temp = temp.replace(/[ç]/gi,"c")

will correct the problem…


28 aug 06

Could it have been extended with an optional value in the form of e.g.

{{NEWPAGE|namespace:page}}

to be this referred page used as a template (I mean simply just copy that page’s content)?
Then this button could be used as a ‘Create new page from here using template…’.
Another extension could be where more templates could be given and the user can choose from a droplist.
Is it possible? Is it easy to implement?

Ok, fine, I've found an indirect solution using template_chooser :)

2 Oct 06

when I add the following code:

Testing New Page plugin

{{NEWPAGE}}

It does not work. Please help.

Is there some errors ?

Adding page to root namespace

To allow users add pages to root namespace you may change function _makecombo() in following way:

	function _makecombo() {
		$r=$this->_getnslist('');
		$ret='<select id="np_cat" tabindex="1" class="edit">'; // added class="edit" to beautify combobox
		$ret.='<option selected value="">root</option>';       // empty value for root namespace
		foreach ($r as $k => $v) {
			$vv=explode(':',$v);
			$vv=str_repeat('&nbsp;&nbsp;',substr_count($v, ':')).$vv[count($vv)-1];
			$ret.='<option value="'.$v.'">'.$vv.'</option>';  
		}
		$ret.='</select>';
		return $ret;
	}

One of the idea of further improvement is to select current namespace as a default choice in combobox.

If you can improve it - you're welcome! — Kibi 2006-06-18 11:10

Seems to be ok :)

New page plugin is not working

I have ftp'ed the zip file, unzipped it in the plugins drectory. The syntax.php file was created in the addnewpage directory. I have also updated my main config file, however, I still cannot see the new page items on my page. Am I missing something? Please help.

Did you write "{{NEWPAGE}}" on your page ?

Problems with the ns-exclusion

The namespace exclusing does not work with the newest relise of dokuwiki. How can I pass the config['exclude'] to the script?

Try this release :)


I downloaded and installed the latest release on 28-11. Does not work. Dokuwiki version 6-11-2006. I adjusted dokuwiki/lib/plugin/addnewpage/syntax.php.
if (!isset($conf['exclude']))
	$conf['exclude']=array();


to

if (!isset($conf['exclude']))
	$conf['exclude']=array('namespace 1','namespace 2','...','namespace n');


Not nice, but working for now. See also my next item “didn't work” for an additional problem with dokuwiki 6-11-2006.

Didn't work

On clicking the submit button, I got referred to the URL doku.php?start=[pagename] (check this by using method GET in stead of POST in syntax.php). Don't know what went wrong. Looks like the 2 comments above experience the same. To get it working I changed the following lines of dokuwiki/lib/plugin/addnewpage/syntax.php:
Last unmodified line:

$renderer->doc .= '<input class="edit" type="text" name="id" id="addnewpage_title" size="20" maxlength="255" tabindex="2" />';

Added line (right after the line above):

$renderer->doc .= '<input type="hidden" name="do" value="edit">';

Changed the following line:

$renderer->doc .= '<input class="button" type="submit" value="'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex="3"  onclick="v=document.location.href.split(\'?\');document.location.href=v[0]+\'?id=\'+document.getElementById(\'np_cat\').value+\':\'+noaccent(document.getElementById(\'addnewpage_title\').value)+\'&do=edit\';return false;" />';

To this:

		    
$renderer->doc .= '<input class="button" type="submit" value="'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex="3"  onclick="document.getElementById(\'addnewpage_title\').value=document.getElementById(\'np_cat\').value+\':\'+noaccent(document.getElementById(\'addnewpage_title\').value);return false;" />';
plugin/addnewpage_old.1366805333.txt.gz · Last modified: 2013-04-24 14:08 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki