diff --git a/_test/SearchConfigTest.php b/_test/SearchConfigTest.php index d071d0a8..7861fde0 100644 --- a/_test/SearchConfigTest.php +++ b/_test/SearchConfigTest.php @@ -33,6 +33,53 @@ 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('baz', $searchConfig->applyFilterVars('$PAGE$')); + + saveWikiText($ID, '', 'cleanup'); + 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'; + + $this->loadSchemaJSON('schema1'); + + $config = [ + 'schemas' => [ + ['schema1', 'alias1'] + ], + 'cols' => ['first'] + ]; + + $searchConfig = new SearchConfig($config, false); + + $this->assertSame(0, $searchConfig->getOffset()); + $this->assertSame([], $searchConfig->getSorts()); + $this->assertEquals([], $this->getInaccessibleProperty($searchConfig, 'filter')); + + $INPUT->remove(meta\SearchConfigParameters::$PARAM_SORT); + $INPUT->remove(meta\SearchConfigParameters::$PARAM_OFFSET); + unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]); + } + public function test_filtervars_nsorid() { global $INFO; diff --git a/helper.php b/helper.php index 3a1580e0..38fe2c7b 100644 --- a/helper.php +++ b/helper.php @@ -32,7 +32,6 @@ class helper_plugin_struct extends 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 7daaf26f..d458a21e 100644 --- a/meta/SearchConfig.php +++ b/meta/SearchConfig.php @@ -116,7 +116,7 @@ protected function applyFilterVars($filter) global $INPUT; global $INFO; if (!isset($INFO['id'])) { - $INFO['id'] = ''; + $INFO = pageinfo(); } $ns = getNS($INFO['id']); diff --git a/syntax/output.php b/syntax/output.php index 2354e3cf..9f789bd3 100644 --- a/syntax/output.php +++ b/syntax/output.php @@ -16,7 +16,7 @@ class syntax_plugin_struct_output extends SyntaxPlugin { - protected $hasBeenRendered = false; + protected $hasBeenRendered = array('metadata' => false, 'xhtml' => false); protected const XHTML_OPEN = '
'; protected const XHTML_CLOSE = '
'; @@ -100,13 +100,24 @@ 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; + } elseif ($format == 'xhtml') { + $this->hasBeenRendered['xhtml'] = true; + } try { $assignments = Assignments::getInstance(); } catch (StructException $e) { diff --git a/syntax/table.php b/syntax/table.php index c6de0b84..3d21819a 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -109,9 +109,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); } @@ -144,9 +149,9 @@ public function render($format, Doku_Renderer $renderer, $config) * @param array $config * @return SearchConfig */ - protected function getSearchConfig($config) + protected function getSearchConfig($config, $dynamic = true) { - return new SearchConfig($config); + return new SearchConfig($config, $dynamic); }