Table of Contents

newpagetemplate Plugin

Compatible with DokuWiki

  • 2012-01-25 "Angua" unknown
  • 2011-05-25 "Rincewind" yes
  • 2010-11-07 "Anteater" yes

plugin Loads predefined page content from a given template

Last updated on
2011-09-04
Provides
Syntax

Tagged with button, editing, template

Description

This plugin loads into the new page creation box a template specified in the $_REQUEST “newpagetemplate” parameter. Effectively, this means that you can pass a template page, similar to the namespace template pages, either in the URL or in a POST form to the creation page. Also, you can pass any number of substitution variables in the “newpagevars” variable.

See the addnewpage plugin discussion to see how to modify the addnewpage plugin to take advantage of this feature.

Version History

This plugin was originally written by Jason Grout. It was later modified by: Sergio (1 Apr 2007), an unidentified author, and Niko Paltzer (15 Jan 2010). The original version was not compatible with current Dokuwiki distributions (post-2010-03-10). The current version of newpagetemplate supports all current distributions of Dokuwiki and is backwardly compatible with distributions going back to 2006.

The original version of newpagetemplate has security concerns which have been addressed in the current distribution. In the earlier version, ACL is not checked before the template page is accessed, which means that anyone with access to the wiki can access the template page. A user with enough rights in one part of the wiki might access any page in whole wiki. Moreover, user input inserted with the userreplace option was not sanitized, making it possible to inject code with malicious intentions.

If you wish to use the original version it is available from github

Example

If a new page is created with the URL:

doku.php?id=:mynewpage&do=edit&rev=&newpagetemplate=:pagetemplates:homepagetemplate&newpagevars=@HI@,Howdy!

then the :pagetemplates:homepagetemplate page is pasted into the edit box. If the “standardreplace” configuration option is true, then the substitutions noted below are performed. If the “userreplace” configuration option is true, then you can also replace ”@HI@” with “Howdy!”, as this substitution was passed in newpagevars. The format for newpagevars is: newpagevars=key,value;key2,value2;key3,value3;

Did you can offer an dokuwiki-syntax example?
Not quite sure what the question is. If you create a template with this markup in :pagetemplates:
  This page is: @ID@
  
  @HI@ @NAME@
  

And if you paste the above URL into your browser's location bar, you will get a page in your browser that looks something like this:

 This page is: mynewpage
 
 Howdy! Joe
 

@ID@ is one of the 'standardreplace' macros and @HI@ is a 'userreplace' marcro.

Is it possible to use standard wiki-link syntax for this? For eg. like:

 [[:mynewpage&newpagetemplate=:pagetemplates:homepagetemplate&newpagevars=@HI@,Howdy!|New page with template]]  

Yes, you can do this. But you will have to substitute some url-encoded characters. In particular, the comma must be represented as %2c. So this would give you:

           
  &newpagevars=@HI@%2CHowdy

You may find with use that there are others.

It doesn't work. I have started a forum-thread to discuss it there.

Please refer to this forum item, where the difficulty is shown to be an error in the user's syntax.

Substitutions

As with the _template.txt namespace templates, the following variables are replaced in your template.

@ID@ full ID of the page
@NS@ namespace of the page
@PAGE@ page name (ID without namespace and underscores replaced by spaces)
@!PAGE@ same as above but with the first character uppercased
@!!PAGE@ same as above but with the first character of all words uppercased
@!PAGE!@ same as above but with all characters uppercased
@FILE@ page name (ID without namespace, underscores kept as is)
@!FILE@ same as above but with the first character uppercased
@!FILE!@ same as above but with all characters uppercased
@USER@ ID of user who is creating the page
@NAME@ name of user who is creating the page
@MAIL@ mail address of user who is creating the page
@DATE@ date and time when edit session started

Bugs

Discussion

Could anybody provide me a simple description or example for the usage of the plugin in combination with 'addnewpage'?
Thanks, Matt
See the openas plugin

When accessing a non-existing page you're provided with a text:
This topic does not exist yet
You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by using the Create this page button


It would be nice to add text where the user can choose from different templates, your plugin would then provide the URL to match the name of the page and the user has choice from different templates. Or am I missing something here ?
I have a same question. Can anybody explain me how to use a new page template when adding a page. I am new to PHP and don't know anything. Your help is highly appreciated.
Thanks, George

This plugin helped me quickly setup template pages for my students to work on, today. Thanks! The only inconvenience was that I had to create a unique link for each student to follow. For example:

  * [[:courses:isci422:projects:Ima Student:start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template|]]
  * [[:courses:isci422:projects:Anutha Student:start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template|]]
  * ...

It would have been even better if I could have created a single link with a substitution in the linked namespace, like:

[[:courses:isci422:projects:@NAME@:start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template|]]

I don't know if it's feasible but it sure would be cool :-)Rik BlokRik Blok
rikblok

2011/11/08 05:42

The problem here would be where to get the substitutions from. Somewhere there would have to be a list of names for @NAME@ and some way to identify which name to use for the substitution.