| Author | Jason Grout |
|---|---|
| Version | 2007-02-24 |
| Required DokuWiki version | 2006-11-06 |
| Download | http://math.byu.edu/~grout/newpagetemplate.zip |
| Main page |
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. I've posted a patch below to modify the addnewpage plugin to take advantage of this functionality.
How do I use this? If I have a template that I would like students to use for a particular homework set, say ”:templates:homeworkset1”, then I just put
{{NEWPAGE>|newpagetemplate=:templates:homeworkset1&newpagevars=@LINK@,[[link:to:homework:page]]}}
in the homework submission page. Any page a student creates using the resulting “Add new page” button will automatically be pre-filled in with the template. In addition, the template will substitute the variable @LINK@ with the link I provided ([[link:to:homework:page]]).
Here is the patch for the addnewpage plugin:
--- syntax.php (revision 1141)
+++ syntax.php (revision 1142)
@@ -28,8 +28,8 @@
}
function handle($match, $state, $pos, &$handler){
- $ns = substr($match, 10, -2); // strip markup
- return $ns;
+ $ns = explode('|',substr($match, 10, -2),2); // strip markup
+ return array(trim($ns[0]),trim($ns[1]));
}
@@ -38,7 +38,7 @@
$renderer->info['cache'] = false;
if ($mode == 'xhtml') {
- $cmb=$this->_makecombo($data);
+ $cmb=$this->_makecombo($data[0]);
if ($cmb==$this->getLang('nooption')) {
$renderer->doc .=(!$this->getConf('addpage_hideACL'))?$cmb:'';
return true;
@@ -49,7 +49,15 @@
$renderer->doc .= $cmb;
$renderer->doc .= '<input class="edit" type="text" name="title" id="addnewpage_title" size="20" maxlength="255" tabindex="2" />';
$renderer->doc .= '<input type="hidden" name="do" id="do" value="edit" />';
- $renderer->doc .= '<input class="button" type="submit" value="'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex="3" onclick="setName();" />';
+ if(strlen($data[1])>1) {
+ $t=explode("&",$data[1]);
+ foreach($t as $value) {
+ $parameter=explode("=",$value,2);
+ $renderer->doc .= '<input type="hidden" name="'.htmlentities(trim($parameter[0]),ENT_QUOTES).'" id="'.htmlentities(trim($parameter[0]),ENT_QUOTES).'" value="'.htmlentities(trim($parameter[1]),ENT_QUOTES).'" />';
+ }
+ }
+
+ $renderer->doc .= '<input class="button" type="submit" value="'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex="3" onclick="setName();" />';
$renderer->doc .= '</form>';
$renderer->doc .= '</div>';