From fec857f50bb91e0f90aca33e06d86afc7702a60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Tue, 11 Apr 2017 14:03:40 +0200 Subject: [PATCH 01/14] fix: Always use id of main page --- syntax.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syntax.php b/syntax.php index 4629040..ad05a98 100644 --- a/syntax.php +++ b/syntax.php @@ -121,12 +121,13 @@ public function render($mode, Doku_Renderer $renderer, $data) { * @author Michael Braun */ protected function _parseNS($ns) { - global $ID; + global $INFO; + $id = $INFO['id']; if(strpos($ns, '@PAGE@') !== false) { - return cleanID(str_replace('@PAGE@', $ID, $ns)); + return cleanID(str_replace('@PAGE@', $id, $ns)); } - if($ns == "@NS@") return getNS($ID); - $ns = preg_replace("/^\.(:|$)/", dirname(str_replace(':', '/', $ID)) . "$1", $ns); + if($ns == "@NS@") return getNS($id); + $ns = preg_replace("/^\.(:|$)/", dirname(str_replace(':', '/', $id)) . "$1", $ns); $ns = str_replace("/", ":", $ns); $ns = cleanID($ns); return $ns; From b8304a8e35ed04496b9ac384900f002cc55e0a6a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 29 May 2017 12:06:45 +0200 Subject: [PATCH 02/14] more flexibility * @INPUT@ placeholder can be used to reference the given input (useful to create a new namespace) makes #70 obsolete * new ? syntax to overwrite config options from the syntax (defaults still come from the config setting) * support for strftime placeholders in the namespace config. Allows to create a daily page for example * New option autopage which hides the input field. Together with the new date placeholder this allows to create a daily page on a single button click --- conf/default.php | 2 + conf/metadata.php | 1 + lang/en/settings.php | 1 + script.js | 45 +++++++------ syntax.php | 150 +++++++++++++++++++++++++++++++++---------- 5 files changed, 145 insertions(+), 54 deletions(-) diff --git a/conf/default.php b/conf/default.php index 5a25000..4d30e5a 100644 --- a/conf/default.php +++ b/conf/default.php @@ -3,3 +3,5 @@ $conf['addpage_showroot'] = 1; $conf['addpage_hide'] = 1; $conf['addpage_hideACL'] = 0; +$conf['addpage_autopage'] = 0; + diff --git a/conf/metadata.php b/conf/metadata.php index 7590fbe..63a75fc 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -3,3 +3,4 @@ $meta['addpage_showroot'] = array('onoff'); $meta['addpage_hide'] = array('onoff'); $meta['addpage_hideACL'] = array('onoff'); +$meta['addpage_autopage'] = array('onoff'); diff --git a/lang/en/settings.php b/lang/en/settings.php index aa6b961..6cba688 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -8,3 +8,4 @@ $lang['addpage_showroot'] = "Show root namespace"; $lang['addpage_hide'] = "When you use {{NEWPAGE>[ns]}} syntax: Hide namespace selection (unchecked: show only subnamespaces)"; $lang['addpage_hideACL'] = "Hide {{NEWPAGE}} if user does not have rights to add pages (show message if unchecked)"; +$lang['addpage_autopage'] = "Don't show the input box, the preconfigured namespace is treated as a full page ID. (makes sense with date placeholders)"; diff --git a/script.js b/script.js index 153d4fa..a566062 100755 --- a/script.js +++ b/script.js @@ -1,30 +1,33 @@ -jQuery(document).ready(function() { +jQuery(document).ready(function () { + var $form = jQuery(".addnewpage form"); + if (!$form.length) return; - // Start with disabled submit button - jQuery(".addnewpage :submit").prop("disabled", true); - // Then enable it when a title is entered - jQuery(".addnewpage input[name='title']").keyup(function(){ - var $submit = jQuery(this).parent("form").find(":submit"); - if (jQuery(this).val().length > 0) { - $submit.removeAttr("disabled"); - } else { - // For when the user deletes the text - $submit.attr("disabled", "disabled"); - } - }).keyup(); + var $ns = $form.find("[name='np_cat']"); + var $title = $form.find("input[name='title']"); + var $id = $form.find("input[name='id']"); + var $submit = $form.find(':submit'); - // Change the form's page-ID field on submit - jQuery(".addnewpage form").submit(function(e) { + // disable submit unless something is in input or input is disabled + if ($title.attr('type') === 'text') { + $submit.attr('disabled', 'disabled'); + $title.keyup(function () { + if ($title.val().length > 0) { + $submit.removeAttr('disabled'); + } else { + $submit.attr('disabled', 'disabled'); + } + }); + } + // Change the form's page-ID field on submit + $form.submit(function () { // Build the new page ID and save in hidden form field - var ns = jQuery(this).find("[name='np_cat']"); - var title = jQuery(this).find("input[name='title']"); - var id = ns.val()+":"+title.val(); - jQuery(this).find("input[name='id']").val(id); + var id = $ns.val().replace('@INPUT@', $title.val()); + $id.val(id); // Clean up the form vars, just to make the resultant URL a bit nicer - ns.prop("disabled", true); - title.prop("disabled", true); + $ns.prop("disabled", true); + $title.prop("disabled", true); return true; }); diff --git a/syntax.php b/syntax.php index ad05a98..ccb6270 100644 --- a/syntax.php +++ b/syntax.php @@ -12,6 +12,9 @@ */ class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin { + /** @var array the parsed options */ + protected $options; + /** * Syntax Type */ @@ -50,25 +53,44 @@ public function connectTo($mode) { * {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}} * {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}} * - * @param string $match The text matched by the patterns - * @param int $state The lexer state for the match - * @param int $pos The character position of the matched text + * @param string $match The text matched by the patterns + * @param int $state The lexer state for the match + * @param int $pos The character position of the matched text * @param Doku_Handler $handler The Doku_Handler object * @return array Return an array with all data you want to use in render * @codingStandardsIgnoreStart */ public function handle($match, $state, $pos, Doku_Handler $handler) { /* @codingStandardsIgnoreEnd */ - $options = substr($match, 9, -2); // strip markup - $options = explode('#', $options, 2); - - $namespace = trim(ltrim($options[0], '>')); - $templates = explode(',', $options[1]); - $templates = array_map('trim', $templates); - return array( - 'namespace' => $namespace, - 'newpagetemplates' => $templates + $match = substr($match, 9, -2); // strip markup + + $data = array( + 'namespace' => '', + 'newpagetemplates' => array(), + 'options' => array( + 'exclude' => $this->getConf('addpage_exclude'), + 'showroot' => $this->getConf('addpage_showroot'), + 'hide' => $this->getConf('addpage_hide'), + 'hideacl' => $this->getConf('addpage_hideACL'), + 'autopage' => $this->getConf('addpage_autopage'), + ) ); + + if(preg_match('/>(.*?)(#|\?|$)/', $match, $m)) { + $data['namespace'] = trim($m[1]); + } + + if(preg_match('/#(.*?)(\?|$)/', $match, $m)) { + $data['newpagetemplates'] = array_map('trim', explode(',', $m[1])); + } + + if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { + $this->_parseOptions($m[1], $data['options']); + // make options available in class + $this->options = $data['options']; + } + + return $data; } /** @@ -82,11 +104,14 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { public function render($mode, Doku_Renderer $renderer, $data) { global $lang; + // make options available in class + $this->options = $data['options']; + if($mode == 'xhtml') { $disablecache = null; $namespaceinput = $this->_htmlNamespaceInput($data['namespace'], $disablecache); if($namespaceinput === false) { - if($this->getConf('addpage_hideACL')) { + if($this->options['hideacl']) { $renderer->doc .= ''; } else { $renderer->doc .= $this->getLang('nooption'); @@ -97,10 +122,13 @@ public function render($mode, Doku_Renderer $renderer, $data) { $newpagetemplateinput = $this->_htmlTemplateInput($data['newpagetemplates']); + $input = 'text'; + if($this->options['autopage']) $input = 'hidden'; + $form = '
' . DOKU_LF . DOKU_TAB . '
' . DOKU_LF . DOKU_TAB . DOKU_TAB . $namespaceinput . DOKU_LF - . DOKU_TAB . DOKU_TAB . '' . DOKU_LF + . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . $newpagetemplateinput . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB . '' . DOKU_LF @@ -114,22 +142,78 @@ public function render($mode, Doku_Renderer $renderer, $data) { return false; } + /** + * Overwrites the $options with the ones parsed from $optstr + * + * @param string $optstr + * @param array $options + * @author Andreas Gohr + */ + protected function _parseOptions($optstr, &$options) { + $opts = preg_split('/[,&]/', $optstr); + + foreach($opts as $opt) { + $opt = strtolower(trim($opt)); + $val = true; + // booleans can be negated with a no prefix + if(substr($opt, 0, 2) == 'no') { + $opt = substr($opt, 2); + $val = false; + } + + // not a known option? might be a key=value pair + if(!isset($options[$opt])) { + list($opt, $val) = array_map('trim', explode('=', $opt, 2)); + } + + // still unknown? skip it + if(!isset($options[$opt])) continue; + + // overwrite the current value + $options[$opt] = $val; + } + } + /** * Parse namespace request * + * This creates the final ID to be created (still having an @INPUT@ variable + * which is filled in via JavaScript) + * * @author Samuele Tognini * @author Michael Braun + * @author Andreas Gohr + * @param string $ns The namespace as given in the syntax + * @return string */ protected function _parseNS($ns) { global $INFO; - $id = $INFO['id']; - if(strpos($ns, '@PAGE@') !== false) { - return cleanID(str_replace('@PAGE@', $id, $ns)); - } - if($ns == "@NS@") return getNS($id); - $ns = preg_replace("/^\.(:|$)/", dirname(str_replace(':', '/', $id)) . "$1", $ns); - $ns = str_replace("/", ":", $ns); + + $selfid = $INFO['id']; + $selfns = getNS($INFO['id']); + // replace the input variable with something unique that survives cleanID + $keep = sha1(time()); + + // by default append the input to the namespace (except on autopage) + if(strpos($ns, '@INPUT@') === false && !$this->options['autopage']) $ns .= ":@INPUT@"; + + // date replacements + $ns = dformat(null, $ns); + + // placeholders + $replacements = array( + '/\//' => ':', // forward slashes to colons + '/@PAGE@/' => $selfid, + '/@NS@/' => $selfns, + '/^\.(:|\/|$)/' => "$selfns:", + '/@INPUT@/' => $keep, + ); + $ns = preg_replace(array_keys($replacements), array_values($replacements), $ns); + + // clean up, then reinsert the input variable $ns = cleanID($ns); + $ns = str_replace($keep, '@INPUT@', $ns); + return $ns; } @@ -147,7 +231,7 @@ protected function _htmlNamespaceInput($dest_ns, &$disablecache) { // If a NS has been provided: // Whether to hide the NS selection (otherwise, show only subnamespaces). - $hide = $this->getConf('addpage_hide'); + $hide = $this->options['hide']; $parsed_dest_ns = $this->_parseNS($dest_ns); // Whether the user can create pages in the provided NS (or root, if no @@ -172,7 +256,7 @@ protected function _htmlNamespaceInput($dest_ns, &$disablecache) { $someopt = false; // Show root namespace if requested and allowed - if($this->getConf('addpage_showroot') && $can_create) { + if($this->options['showroot'] && $can_create) { if(empty($dest_ns)) { // If no namespace has been provided, add an option for the root NS. $ret .= ''; @@ -188,7 +272,7 @@ protected function _htmlNamespaceInput($dest_ns, &$disablecache) { // The top of this stack will always be the last printed ancestor namespace $ancestor_stack = array(); - if (!empty($dest_ns)) { + if(!empty($dest_ns)) { array_push($ancestor_stack, $dest_ns); } @@ -202,14 +286,14 @@ protected function _htmlNamespaceInput($dest_ns, &$disablecache) { } $nsparts = explode(':', $ns); - $first_unprinted_depth = empty($ancestor_stack)? 1 : (2 + substr_count($ancestor_stack[count($ancestor_stack) - 1], ':')); - for ($i = $first_unprinted_depth, $end = count($nsparts); $i <= $end; $i++) { + $first_unprinted_depth = empty($ancestor_stack) ? 1 : (2 + substr_count($ancestor_stack[count($ancestor_stack) - 1], ':')); + for($i = $first_unprinted_depth, $end = count($nsparts); $i <= $end; $i++) { $namespace = implode(':', array_slice($nsparts, 0, $i)); array_push($ancestor_stack, $namespace); $selectOptionText = str_repeat('  ', substr_count($namespace, ':')) . $nsparts[$i - 1]; $ret .= ''; } @@ -238,7 +322,7 @@ protected function _getNamespaceList($topns = '') { $topns = utf8_encodeFN(str_replace(':', '/', $topns)); - $excludes = $this->getConf('addpage_exclude'); + $excludes = $this->options['exclude']; if($excludes == "") { $excludes = array(); } else { @@ -250,7 +334,7 @@ protected function _getNamespaceList($topns = '') { $namespaces = array(); foreach($searchdata as $ns) { foreach($excludes as $exclude) { - if( ! empty($exclude) && strpos($ns['id'], $exclude) === 0) { + if(!empty($exclude) && strpos($ns['id'], $exclude) === 0) { continue 2; } } @@ -273,7 +357,7 @@ public function _htmlTemplateInput($newpagetemplates) { } else { if($cnt == 1) { - list($template, ) = $this->_parseNSTemplatePage($newpagetemplates[0]); + list($template,) = $this->_parseNSTemplatePage($newpagetemplates[0]); $input = ''; } else { $first = true; @@ -283,8 +367,8 @@ public function _htmlTemplateInput($newpagetemplates) { $first = false; list($template, $name) = $this->_parseNSTemplatePage($template); - $p .= ' value="'.formText($template).'"'; - $input .= ""; + $p .= ' value="' . formText($template) . '"'; + $input .= ""; } $input .= ''; } @@ -307,7 +391,7 @@ protected function _parseNSTemplatePage($nstemplate) { $exist = null; resolve_pageid(getNS($ID), $template, $exist); //get absolute id - if (is_null($name)) $name = $template; + if(is_null($name)) $name = $template; return array($template, $name); } From 19faa288b4352fd6d317b1eb8538b5d135aa1ba3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 29 May 2017 14:40:18 +0200 Subject: [PATCH 03/14] updated version --- plugin.info.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.info.txt b/plugin.info.txt index ef82c86..d539d4c 100755 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,8 +1,8 @@ # General Plugin Info base addnewpage author Benjamin Santalucia, Sam Wilson, Michael Braun, Gerrit Uitslag, Albert Chern -email -date 2015-11-02 +email +date 2017-05-29 name Add New Page desc Adds a "new page form" to any wiki page. url http://www.dokuwiki.org/plugin:addnewpage From 8640cd557ebcb2fa32c001e25096a8243e59707a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 May 2017 09:13:35 +0200 Subject: [PATCH 04/14] fix script to work on multiple forms again --- script.js | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/script.js b/script.js index a566062..0fc0574 100755 --- a/script.js +++ b/script.js @@ -1,35 +1,35 @@ -jQuery(document).ready(function () { - var $form = jQuery(".addnewpage form"); - if (!$form.length) return; +jQuery(function () { + jQuery(".addnewpage form").each(function () { + var $form = jQuery(this); + var $ns = $form.find("[name='np_cat']"); + var $title = $form.find("input[name='title']"); + var $id = $form.find("input[name='id']"); + var $submit = $form.find(':submit'); - var $ns = $form.find("[name='np_cat']"); - var $title = $form.find("input[name='title']"); - var $id = $form.find("input[name='id']"); - var $submit = $form.find(':submit'); + // disable submit unless something is in input or input is disabled + if ($title.attr('type') === 'text') { + $submit.attr('disabled', 'disabled'); + $title.keyup(function () { + if ($title.val().length > 0) { + $submit.removeAttr('disabled'); + } else { + $submit.attr('disabled', 'disabled'); + } + }); + } - // disable submit unless something is in input or input is disabled - if ($title.attr('type') === 'text') { - $submit.attr('disabled', 'disabled'); - $title.keyup(function () { - if ($title.val().length > 0) { - $submit.removeAttr('disabled'); - } else { - $submit.attr('disabled', 'disabled'); - } - }); - } + // Change the form's page-ID field on submit + $form.submit(function () { + // Build the new page ID and save in hidden form field + var id = $ns.val().replace('@INPUT@', $title.val()); + $id.val(id); - // Change the form's page-ID field on submit - $form.submit(function () { - // Build the new page ID and save in hidden form field - var id = $ns.val().replace('@INPUT@', $title.val()); - $id.val(id); + // Clean up the form vars, just to make the resultant URL a bit nicer + $ns.prop("disabled", true); + $title.prop("disabled", true); - // Clean up the form vars, just to make the resultant URL a bit nicer - $ns.prop("disabled", true); - $title.prop("disabled", true); + return true; + }); - return true; }); - }); From cf018a6a3de354be07ce928ecfa3c97d9daa41a1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 May 2017 09:15:17 +0200 Subject: [PATCH 05/14] removed unneeded options assignment Options are not used after the handler step, so no need to assign them to the class member. --- syntax.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/syntax.php b/syntax.php index ccb6270..8fdb070 100644 --- a/syntax.php +++ b/syntax.php @@ -86,8 +86,6 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { $this->_parseOptions($m[1], $data['options']); - // make options available in class - $this->options = $data['options']; } return $data; From 88aaa9dc2f6c12e2584562c48ada3124d1732e87 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 May 2017 09:17:19 +0200 Subject: [PATCH 06/14] use input event instead of keyup This should also catch copy'n'paste actions. https://caniuse.com/#feat=input-event --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.js b/script.js index 0fc0574..952663a 100755 --- a/script.js +++ b/script.js @@ -9,7 +9,7 @@ jQuery(function () { // disable submit unless something is in input or input is disabled if ($title.attr('type') === 'text') { $submit.attr('disabled', 'disabled'); - $title.keyup(function () { + $title.on('input', function () { if ($title.val().length > 0) { $submit.removeAttr('disabled'); } else { From 0d90564c63508563e4f3c8776e96661181a11b99 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 7 May 2023 18:29:17 +0200 Subject: [PATCH 07/14] Add param "newpagevars" for plugin newpagetemplate Fixes #66 UNTESTED adaptation of commit 9785b7d18e7da5a6454820073a551feb3c2a8617 to the new preg_match()-based parser. --- syntax.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index 8fdb070..c4aa794 100644 --- a/syntax.php +++ b/syntax.php @@ -52,6 +52,7 @@ public function connectTo($mode) { * {{NEWPAGE#newtpl1,newtpl2}} * {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}} * {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}} + * {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1#@HI@,Howdy}} * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match @@ -67,6 +68,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $data = array( 'namespace' => '', 'newpagetemplates' => array(), + 'newpagevars' => array(), 'options' => array( 'exclude' => $this->getConf('addpage_exclude'), 'showroot' => $this->getConf('addpage_showroot'), @@ -80,8 +82,9 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $data['namespace'] = trim($m[1]); } - if(preg_match('/#(.*?)(\?|$)/', $match, $m)) { + if(preg_match('/#(.*?)(#.*?)?(\?|$)/', $match, $m)) { $data['newpagetemplates'] = array_map('trim', explode(',', $m[1])); + $data['newpagevars'] = array_map('trim', explode(',', $m[2])); } if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { @@ -128,6 +131,7 @@ public function render($mode, Doku_Renderer $renderer, $data) { . DOKU_TAB . DOKU_TAB . $namespaceinput . DOKU_LF . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . $newpagetemplateinput + . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB . '' . DOKU_LF From 96b582114916e363f7a9f2cd6167a6265bf08017 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sat, 27 May 2023 16:59:40 +0200 Subject: [PATCH 08/14] Fix incorrect merge resolution In commit 22d9c079c34f0ef65334aeb535c0d954067f9d2a --- syntax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index fc277dc..095ef11 100644 --- a/syntax.php +++ b/syntax.php @@ -134,7 +134,7 @@ public function render($format, Doku_Renderer $renderer, $data) { $form = '

' . '' . $namespaceinput - . '' + . '' . $newpagetemplateinput . '' . '' From 0aa2c115ba36261ec917e2ea7c9ec605ae91aed4 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sat, 27 May 2023 17:01:37 +0200 Subject: [PATCH 09/14] Fix static analysis warnings --- syntax.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/syntax.php b/syntax.php index 095ef11..2988fe1 100644 --- a/syntax.php +++ b/syntax.php @@ -6,13 +6,13 @@ * @author iDO * @author Sam Wilson * - * @noinspection PhpUnused, - * PhpMissingParamTypeInspection, PhpMissingReturnTypeInspection + * @noinspection PhpUnused + * @noinspection PhpMissingParamTypeInspection, PhpMissingReturnTypeInspection */ -// must be run within Dokuwiki use dokuwiki\File\PageResolver; +// must be run within Dokuwiki if(!defined('DOKU_INC')) die(); class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin { @@ -220,9 +220,7 @@ protected function _parseNS($ns) { // clean up, then reinsert the input variable $ns = cleanID($ns); - $ns = str_replace($keep, '@INPUT@', $ns); - - return $ns; + return str_replace($keep, '@INPUT@', $ns); } /** From 31967e049694389408c9c98a49524275a2789360 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 24 Sep 2023 18:41:39 +0200 Subject: [PATCH 10/14] Fix Array to string conversion warning Regression introduced by incorrect implementation of newpagevars in commit 0d90564c63508563e4f3c8776e96661181a11b99 when porting #66 - It should be a string, not an array. --- syntax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax.php b/syntax.php index 2988fe1..8051678 100644 --- a/syntax.php +++ b/syntax.php @@ -73,7 +73,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $data = array( 'namespace' => '', 'newpagetemplates' => array(), - 'newpagevars' => array(), + 'newpagevars' => '', 'options' => array( 'exclude' => $this->getConf('addpage_exclude'), 'showroot' => $this->getConf('addpage_showroot'), @@ -89,7 +89,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { if(preg_match('/#(.*?)(#.*?)?(\?|$)/', $match, $m)) { $data['newpagetemplates'] = array_map('trim', explode(',', $m[1])); - $data['newpagevars'] = array_map('trim', explode(',', $m[2])); + $data['newpagevars'] = trim($m[2]); } if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { From d49ba5bbd1c846091adb73c73843dcb0c828e8fa Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 24 Sep 2023 18:47:04 +0200 Subject: [PATCH 11/14] Skip leading # in newpagevars parameter The regex for newpagetemplate parameters parsing that was implemented in commit 0d90564c63508563e4f3c8776e96661181a11b99 included the leading `#` in the newpagevars parameter, preventing the newpagetemplate plugin from processing the first parameter as `#@PARAM@` would not match the expected `@PARAM@`. Adapting the regex accordingly. --- syntax.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/syntax.php b/syntax.php index 8051678..f2a6107 100644 --- a/syntax.php +++ b/syntax.php @@ -87,9 +87,12 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $data['namespace'] = trim($m[1]); } - if(preg_match('/#(.*?)(#.*?)?(\?|$)/', $match, $m)) { + # Extract the newpagetemplate plugin parameters + # - after the initial #: the template name + # - after optional 2nd #: custom variable names + if(preg_match('/#(.*?)(?:#(.*?))?(?:\?|$)/', $match, $m)) { $data['newpagetemplates'] = array_map('trim', explode(',', $m[1])); - $data['newpagevars'] = trim($m[2]); + $data['newpagevars'] = trim($m[2] ?? ''); } if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { From 641f0487ea9954b1ef223b55832d3664c320d4e3 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 24 Sep 2023 18:57:22 +0200 Subject: [PATCH 12/14] French translation for autopage config --- lang/fr/settings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/fr/settings.php b/lang/fr/settings.php index 640d899..0c4d359 100644 --- a/lang/fr/settings.php +++ b/lang/fr/settings.php @@ -8,3 +8,4 @@ $lang['addpage_showroot'] = "Afficher le namespace racine"; $lang['addpage_hide'] = "Quand vous utlisez la syntaxe {{NEWPAGE>[ns]}} : Cache la selection de namespace (décoché: affiche uniquement les sous-namespaces)"; $lang['addpage_hideACL'] = "Si non cochée, affiche un message lorsque l'utlisateur n'a pas les droits d'ajout de page. Sinon, cache simplement {{NEWPAGE}}"; +$lang['addpage_autopage'] = "Ne pas afficher le champ de saisie; le namespace préconfiguré est traité comme un identifiant de page complet (utile avec des attributs de date)"; From d2f65217798b544337d1cb03b53dd4153f522c55 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 24 Sep 2023 19:04:40 +0200 Subject: [PATCH 13/14] PHPDoc --- syntax.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/syntax.php b/syntax.php index f2a6107..4b33db1 100644 --- a/syntax.php +++ b/syntax.php @@ -49,20 +49,26 @@ public function connectTo($mode) { } /** - * Handler to prepare matched data for the rendering process + * Handler to prepare matched data for the rendering process. * * Handled syntax options: - * {{NEWPAGE}} - * {{NEWPAGE>your:namespace}} - * {{NEWPAGE#newtpl1,newtpl2}} - * {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}} - * {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}} - * {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1#@HI@,Howdy}} + * - {{NEWPAGE}} + * - {{NEWPAGE>your:namespace}} + * - {{NEWPAGE>your:namespace:@INPUT@:start}} + * - {{NEWPAGE>your:namespace:[date formats]}} {@see strftime()} + * - {{NEWPAGE?config_overrides}} + * - {{NEWPAGE#newtpl1,newtpl2}} + * - {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}} + * - {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}} + * - {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1#@HI@,Howdy}} + * + * Refer to {@see https://www.dokuwiki.org/plugin:addnewpage} for details. * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text * @param Doku_Handler $handler The Doku_Handler object + * * @return array Return an array with all data you want to use in render * @codingStandardsIgnoreStart */ From 666684905ec6d090cfb4c9a05d8903ea66600655 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 10 Nov 2024 12:21:50 +0100 Subject: [PATCH 14/14] Fix PHP notice --- syntax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index 956df7d..e9d0537 100644 --- a/syntax.php +++ b/syntax.php @@ -183,7 +183,7 @@ protected function _parseOptions($optstr, &$options) { // not a known option? might be a key=value pair if(!isset($options[$opt])) { - list($opt, $val) = array_map('trim', explode('=', $opt, 2)); + list($opt, $val) = array_map('trim', sexplode('=', $opt, 2)); } // still unknown? skip it