Skip to content

Commit 649d5fc

Browse files
committed
Merge branch 'master' into pr72
# Conflicts: # plugin.info.txt # syntax.php
2 parents 0aa2c11 + 2677d01 commit 649d5fc

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

plugin.info.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
base addnewpage
33
author Damien Regad, Benjamin Santalucia, Sam Wilson and other contributors
44
5-
date 2017-05-29
5+
date 2023-05-10
66
name Add New Page plugin
77
desc Adds a "new page form" to any wiki page.
88
url https://www.dokuwiki.org/plugin:addnewpage

syntax.php

+26-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
* @noinspection PhpMissingParamTypeInspection, PhpMissingReturnTypeInspection
1111
*/
1212

13+
use dokuwiki\Extension\SyntaxPlugin;
1314
use dokuwiki\File\PageResolver;
1415

1516
// must be run within Dokuwiki
1617
if(!defined('DOKU_INC')) die();
1718

18-
class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin {
19+
class syntax_plugin_addnewpage extends SyntaxPlugin {
1920

2021
/** @var array the parsed options */
2122
protected $options;
@@ -102,7 +103,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) {
102103
/**
103104
* Create the new-page form.
104105
*
105-
* @param $format string output format being rendered
106+
* @param $format string output format being rendered
106107
* @param $renderer Doku_Renderer the current renderer object
107108
* @param $data array data created by handler()
108109
* @return boolean rendered correctly?
@@ -126,17 +127,15 @@ public function render($format, Doku_Renderer $renderer, $data) {
126127
}
127128
if($disablecache) $renderer->info['cache'] = false;
128129

129-
$newpagetemplateinput = $this->_htmlTemplateInput($data['newpagetemplates']);
130-
131130
$input = 'text';
132131
if($this->options['autopage']) $input = 'hidden';
133132

134133
$form = '<div class="addnewpage"><p>'
135134
. '<form name="addnewpage" method="get" action="' . DOKU_BASE . DOKU_SCRIPT . '" accept-charset="' . $lang['encoding'] . '">'
136135
. $namespaceinput
137136
. '<input class="edit" type="'.$input.'" name="title" size="20" maxlength="255" tabindex="2" />'
138-
. $newpagetemplateinput
139-
. '<input type="hidden" name="newpagevars" value="' . $data['newpagevars'] . '"/>'
137+
. $this->_htmlTemplateInput($data['newpagetemplates'])
138+
. $this->_htmlTemplateVars($data['newpagevars'])
140139
. '<input type="hidden" name="do" value="edit" />'
141140
. '<input type="hidden" name="id" />'
142141
. '<input class="button" type="submit" value="' . $this->getLang('okbutton') . '" tabindex="4" />'
@@ -355,11 +354,13 @@ protected function _getNamespaceList($topns = '') {
355354
* @param array $newpagetemplates array of namespace templates
356355
* @return string html of select or hidden input
357356
*/
358-
public function _htmlTemplateInput($newpagetemplates) {
357+
protected function _htmlTemplateInput($newpagetemplates) {
359358
$cnt = count($newpagetemplates);
360359
if($cnt < 1 || $cnt == 1 && $newpagetemplates[0] == '') {
361-
$input = '';
362-
360+
// Workaround for newpagetemplate plugin not checking for request var existence
361+
// https://github.com/turnermm/newpagetemplate/pull/10
362+
// When fixed, replace next line by `$input = '';`
363+
$input = '<input type="hidden" name="newpagetemplate" />';
363364
} else {
364365
if($cnt == 1) {
365366
list($template,) = $this->_parseNSTemplatePage($newpagetemplates[0]);
@@ -382,6 +383,22 @@ public function _htmlTemplateInput($newpagetemplates) {
382383
return $input;
383384
}
384385

386+
/**
387+
* Generate html for namespace template variables.
388+
*
389+
* @param string $newpagevars
390+
*
391+
* @return string html of hidden input
392+
*/
393+
protected function _htmlTemplateVars($newpagevars) {
394+
return $newpagevars
395+
? '<input type="hidden" name="newpagevars" value="' . $newpagevars . '"/>'
396+
// Workaround for newpagetemplate plugin not checking for request var existence
397+
// https://github.com/turnermm/newpagetemplate/pull/10
398+
// When fixed, replace next line by `: '';`
399+
: '<input type="hidden" name="newpagevars" />';
400+
}
401+
385402
/**
386403
* Parses and resolves the namespace template page
387404
*

0 commit comments

Comments
 (0)