From a80f32ab9d9d73bfe96990420c84443c781479e5 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:39:35 +0900 Subject: [PATCH 01/11] Metadata render fix --- helper.php | 1 - meta/SearchConfig.php | 5 +++-- syntax/output.php | 22 +++++++++++++++++----- syntax/table.php | 15 ++++++++++----- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/helper.php b/helper.php index 3cb91c68..48a7168a 100644 --- a/helper.php +++ b/helper.php @@ -31,7 +31,6 @@ class helper_plugin_struct extends DokuWiki_Plugin * All descendants are also blacklisted. */ public const BLACKLIST_RENDERER = [ - 'Doku_Renderer_metadata', '\renderer_plugin_qc' ]; diff --git a/meta/SearchConfig.php b/meta/SearchConfig.php index 938d843d..4a53e331 100644 --- a/meta/SearchConfig.php +++ b/meta/SearchConfig.php @@ -113,8 +113,9 @@ protected function applyFilterVars($filter) { global $INPUT; global $INFO; - if (!isset($INFO['id'])) { - $INFO['id'] = null; + + if (is_null($INFO)) { + $INFO = pageinfo(); } // apply inexpensive filters first diff --git a/syntax/output.php b/syntax/output.php index 58a10dee..26d7c9de 100644 --- a/syntax/output.php +++ b/syntax/output.php @@ -13,7 +13,7 @@ class syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin { - protected $hasBeenRendered = false; + protected $hasBeenRendered = array('metadata'=>false, 'xhtml'=>false); protected const XHTML_OPEN = '
'; protected const XHTML_CLOSE = '
'; @@ -97,13 +97,25 @@ public function render($format, Doku_Renderer $renderer, $data) return true; } } - if (!isset($INFO['id']) || ($ID != $INFO['id'])) return true; - if (!$INFO['exists']) return true; - if ($this->hasBeenRendered) return true; + if (!isset($INFO) || $format == "metadata") { + $pagename = pageinfo()['id']; + } else { + $pagename = $INFO['id']; + } + + if ($ID != $pagename) return true; + if (!page_exists($pagename)) return true; + if ($this->hasBeenRendered['metadata'] && $format == 'metadata') return true; + if ($this->hasBeenRendered['xhtml'] && $format == 'xhtml') return true; if (!preg_match(self::WHITELIST_ACTIONS, act_clean($ACT))) return true; // do not render the output twice on the same page, e.g. when another page has been included - $this->hasBeenRendered = true; + if ($format == 'metadata') { + $this->hasBeenRendered['metadata'] = true; + } + else if ($format == 'xhtml') { + $this->hasBeenRendered['xhtml'] = true; + } try { $assignments = Assignments::getInstance(); } catch (StructException $e) { diff --git a/syntax/table.php b/syntax/table.php index 36306be0..ef4768ea 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -108,9 +108,14 @@ public function render($format, Doku_Renderer $renderer, $config) } try { - $search = $this->getSearchConfig($config); - if ($format === 'struct_csv') { - // no pagination in export + if ($format === "metadata") { + $search = $this->getSearchConfig($config, false); + } else { + $search = $this->getSearchConfig($config); + } + + if ($format === 'struct_csv' || $format === "metadata") { + // no pagination in export or metadata render $search->setLimit(0); $search->setOffset(0); } @@ -139,9 +144,9 @@ public function render($format, Doku_Renderer $renderer, $config) * @param array $config * @return SearchConfig */ - protected function getSearchConfig($config) + protected function getSearchConfig($config, $dymamic = true) { - return new SearchConfig($config); + return new SearchConfig($config, $dymamic); } From 8f2c653de92b81e4c9fe53ef84c7effaeb267814 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 11:59:52 +0900 Subject: [PATCH 02/11] Change filter to be more specific --- meta/SearchConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/SearchConfig.php b/meta/SearchConfig.php index 34e7e2a4..d458a21e 100644 --- a/meta/SearchConfig.php +++ b/meta/SearchConfig.php @@ -115,7 +115,7 @@ protected function applyFilterVars($filter) { global $INPUT; global $INFO; - if (is_null($INFO)) { + if (!isset($INFO['id'])) { $INFO = pageinfo(); } $ns = getNS($INFO['id']); From 5285d14ee29612ffa028fbb97b5ba93756e25547 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 12:21:54 +0900 Subject: [PATCH 03/11] Code refactor --- syntax/output.php | 5 ++--- syntax/table.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/syntax/output.php b/syntax/output.php index 56239b01..9f789bd3 100644 --- a/syntax/output.php +++ b/syntax/output.php @@ -16,7 +16,7 @@ class syntax_plugin_struct_output extends SyntaxPlugin { - protected $hasBeenRendered = array('metadata'=>false, 'xhtml'=>false); + protected $hasBeenRendered = array('metadata' => false, 'xhtml' => false); protected const XHTML_OPEN = '
'; protected const XHTML_CLOSE = '
'; @@ -115,8 +115,7 @@ public function render($format, Doku_Renderer $renderer, $data) // do not render the output twice on the same page, e.g. when another page has been included if ($format == 'metadata') { $this->hasBeenRendered['metadata'] = true; - } - else if ($format == 'xhtml') { + } elseif ($format == 'xhtml') { $this->hasBeenRendered['xhtml'] = true; } try { diff --git a/syntax/table.php b/syntax/table.php index 147b23b9..d892da8d 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -114,7 +114,7 @@ public function render($format, Doku_Renderer $renderer, $config) } else { $search = $this->getSearchConfig($config); } - + if ($format === 'struct_csv' || $format === "metadata") { // no pagination in export or metadata render $search->setLimit(0); From dc3360c1581b94f9ca63c64e5ec4253beeedb2ea Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 12:34:43 +0900 Subject: [PATCH 04/11] Add test for $INFO['id'] missing --- _test/SearchConfigTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index d071d0a8..a6c0453b 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -33,6 +33,24 @@ public function test_filtervars_simple() $this->assertEquals(date('Y-m-d'), $searchConfig->applyFilterVars('$DATE(now)$')); } + public function test_filtervars_missing_pageid() + { + global $INFO, $ID; + + $ID = 'foo:bar:baz'; + saveWikiText($ID, 'initial page', 'created for filter var test'); + $INFO = []; + + $searchConfig = new SearchConfig([]); + + $this->assertEquals($ID, $searchConfig->applyFilterVars('$ID$')); + $this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NS$')); + $this->assertEquals('init', $searchConfig->applyFilterVars('$PAGE$')); + + saveWikiText($ID, '', 'cleanup'); + clearstatcache(); + } + public function test_filtervars_nsorid() { global $INFO; From 3a15352be11d1b39eafe55a4871a5d9fb1468eae Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 12:36:16 +0900 Subject: [PATCH 05/11] Test typo fix --- _test/SearchConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index a6c0453b..8b5589fb 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -45,7 +45,7 @@ public function test_filtervars_missing_pageid() $this->assertEquals($ID, $searchConfig->applyFilterVars('$ID$')); $this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NS$')); - $this->assertEquals('init', $searchConfig->applyFilterVars('$PAGE$')); + $this->assertEquals('baz', $searchConfig->applyFilterVars('$PAGE$')); saveWikiText($ID, '', 'cleanup'); clearstatcache(); From 7ac8fd5757380a4cef3cd936e2bb025cd8c92d16 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 20:04:45 +0900 Subject: [PATCH 06/11] Typo fix --- syntax/table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/table.php b/syntax/table.php index d892da8d..3d21819a 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -149,9 +149,9 @@ public function render($format, Doku_Renderer $renderer, $config) * @param array $config * @return SearchConfig */ - protected function getSearchConfig($config, $dymamic = true) + protected function getSearchConfig($config, $dynamic = true) { - return new SearchConfig($config, $dymamic); + return new SearchConfig($config, $dynamic); } From 95eeecf0a5a1079deaaf80c0010db8b8f6c6d604 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:30:23 +0900 Subject: [PATCH 07/11] Add ignore dynamic filter test --- _test/SearchConfigTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index 8b5589fb..f4de7747 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -51,6 +51,36 @@ public function test_filtervars_missing_pageid() clearstatcache(); } + public function test_filtervars_ignore_dynamic_filters() + { + global $INPUT; + + $INPUT->set(meta\SearchConfigParameters::$PARAM_SORT, '^alias2.athird'); + $INPUT->set(meta\SearchConfigParameters::$PARAM_OFFSET, 25); + $_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['alias1.first*~'] = 'test'; + $_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['afirst='] = 'test2'; + + $config = [ + 'schemas' => [ + ['schema1', 'alias1'] + ], + 'cols' => ['first'], + 'limit' => 10 + ]; + + $searchConfig = new SearchConfig($config, false); + + $this->assertSame(0, $searchConfig->getLimit()); + $this->assertSame(0, $searchConfig->getOffset()); + $this->assertSame([], $searchConfig->getSorts()); + $this->assertEquals([], $searchConfig->getDynamicParameters()->getURLParameters()); + + unset($INPUT[meta\SearchConfigParameters::$PARAM_SORT]); + unset($INPUT[meta\SearchConfigParameters::$PARAM_OFFSET]); + unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); + unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); + } + public function test_filtervars_nsorid() { global $INFO; From ef7a244d1f26b06177bc56b13653727d0ccc5a46 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:34:06 +0900 Subject: [PATCH 08/11] Fix missing test element --- _test/SearchConfigTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index f4de7747..0fd959db 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -60,6 +60,8 @@ public function test_filtervars_ignore_dynamic_filters() $_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['alias1.first*~'] = 'test'; $_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['afirst='] = 'test2'; + $this->loadSchemaJSON('schema1'); + $config = [ 'schemas' => [ ['schema1', 'alias1'] From f433253521b90fd3867a3220802392cc55732144 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:40:26 +0900 Subject: [PATCH 09/11] Fix test --- _test/SearchConfigTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index 0fd959db..059a54a1 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -66,13 +66,11 @@ public function test_filtervars_ignore_dynamic_filters() 'schemas' => [ ['schema1', 'alias1'] ], - 'cols' => ['first'], - 'limit' => 10 + 'cols' => ['first'] ]; $searchConfig = new SearchConfig($config, false); - $this->assertSame(0, $searchConfig->getLimit()); $this->assertSame(0, $searchConfig->getOffset()); $this->assertSame([], $searchConfig->getSorts()); $this->assertEquals([], $searchConfig->getDynamicParameters()->getURLParameters()); @@ -80,7 +78,6 @@ public function test_filtervars_ignore_dynamic_filters() unset($INPUT[meta\SearchConfigParameters::$PARAM_SORT]); unset($INPUT[meta\SearchConfigParameters::$PARAM_OFFSET]); unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); - unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); } public function test_filtervars_nsorid() From 1642af8a15226aecfb7c3b9c328b858be828181b Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:51:24 +0900 Subject: [PATCH 10/11] Fix test --- _test/SearchConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index 059a54a1..cb82d3c3 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -73,7 +73,7 @@ public function test_filtervars_ignore_dynamic_filters() $this->assertSame(0, $searchConfig->getOffset()); $this->assertSame([], $searchConfig->getSorts()); - $this->assertEquals([], $searchConfig->getDynamicParameters()->getURLParameters()); + $this->assertEquals([], $this->getInaccessibleProperty($searchConfig, 'filter')); unset($INPUT[meta\SearchConfigParameters::$PARAM_SORT]); unset($INPUT[meta\SearchConfigParameters::$PARAM_OFFSET]); From c71421615f2e1e9e8be37fb7174cb22ad37d1090 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:03:38 +0900 Subject: [PATCH 11/11] Test fix --- _test/SearchConfigTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index cb82d3c3..7861fde0 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -75,8 +75,8 @@ public function test_filtervars_ignore_dynamic_filters() $this->assertSame([], $searchConfig->getSorts()); $this->assertEquals([], $this->getInaccessibleProperty($searchConfig, 'filter')); - unset($INPUT[meta\SearchConfigParameters::$PARAM_SORT]); - unset($INPUT[meta\SearchConfigParameters::$PARAM_OFFSET]); + $INPUT->remove(meta\SearchConfigParameters::$PARAM_SORT); + $INPUT->remove(meta\SearchConfigParameters::$PARAM_OFFSET); unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); }