10
10
* @noinspection PhpMissingParamTypeInspection, PhpMissingReturnTypeInspection
11
11
*/
12
12
13
+ use dokuwiki \Extension \SyntaxPlugin ;
13
14
use dokuwiki \File \PageResolver ;
14
15
15
16
// must be run within Dokuwiki
16
17
if (!defined ('DOKU_INC ' )) die ();
17
18
18
- class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin {
19
+ class syntax_plugin_addnewpage extends SyntaxPlugin {
19
20
20
21
/** @var array the parsed options */
21
22
protected $ options ;
@@ -102,7 +103,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) {
102
103
/**
103
104
* Create the new-page form.
104
105
*
105
- * @param $format string output format being rendered
106
+ * @param $format string output format being rendered
106
107
* @param $renderer Doku_Renderer the current renderer object
107
108
* @param $data array data created by handler()
108
109
* @return boolean rendered correctly?
@@ -126,17 +127,15 @@ public function render($format, Doku_Renderer $renderer, $data) {
126
127
}
127
128
if ($ disablecache ) $ renderer ->info ['cache ' ] = false ;
128
129
129
- $ newpagetemplateinput = $ this ->_htmlTemplateInput ($ data ['newpagetemplates ' ]);
130
-
131
130
$ input = 'text ' ;
132
131
if ($ this ->options ['autopage ' ]) $ input = 'hidden ' ;
133
132
134
133
$ form = '<div class="addnewpage"><p> '
135
134
. '<form name="addnewpage" method="get" action=" ' . DOKU_BASE . DOKU_SCRIPT . '" accept-charset=" ' . $ lang ['encoding ' ] . '"> '
136
135
. $ namespaceinput
137
136
. '<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 ' ])
140
139
. '<input type="hidden" name="do" value="edit" /> '
141
140
. '<input type="hidden" name="id" /> '
142
141
. '<input class="button" type="submit" value=" ' . $ this ->getLang ('okbutton ' ) . '" tabindex="4" /> '
@@ -355,11 +354,13 @@ protected function _getNamespaceList($topns = '') {
355
354
* @param array $newpagetemplates array of namespace templates
356
355
* @return string html of select or hidden input
357
356
*/
358
- public function _htmlTemplateInput ($ newpagetemplates ) {
357
+ protected function _htmlTemplateInput ($ newpagetemplates ) {
359
358
$ cnt = count ($ newpagetemplates );
360
359
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" /> ' ;
363
364
} else {
364
365
if ($ cnt == 1 ) {
365
366
list ($ template ,) = $ this ->_parseNSTemplatePage ($ newpagetemplates [0 ]);
@@ -382,6 +383,22 @@ public function _htmlTemplateInput($newpagetemplates) {
382
383
return $ input ;
383
384
}
384
385
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
+
385
402
/**
386
403
* Parses and resolves the namespace template page
387
404
*
0 commit comments