From de70e7afe262cdb9e4d3dbc30aab70886698fb3c Mon Sep 17 00:00:00 2001 From: "gesinn.it" Date: Tue, 26 Jan 2021 10:10:24 +0100 Subject: [PATCH] [Filtered] added "list view userparam" (#631) closes #629 * added "list view userparam" to Filtered format * added additional tests for list view specific parameter --- formats/filtered/src/View/ListView.php | 13 ++- i18n/en.json | 1 + i18n/qqq.json | 1 + .../JSONScript/TestCases/filtered-03.json | 104 ++++++++++++++++++ 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/Integration/JSONScript/TestCases/filtered-03.json diff --git a/formats/filtered/src/View/ListView.php b/formats/filtered/src/View/ListView.php index c92d4f938..74ff47f5c 100644 --- a/formats/filtered/src/View/ListView.php +++ b/formats/filtered/src/View/ListView.php @@ -40,6 +40,7 @@ protected function handleParameters() { $this->mIntroTemplate = $params['list view introtemplate']; $this->mOutroTemplate = $params['list view outrotemplate']; $this->mNamedArgs = $params['list view named args']; + $this->mUserParam = $params['list view userparam']; $this->mShowHeaders = $params['headers']; } @@ -124,8 +125,8 @@ protected function printRow( $row, &$rownum, $rowstart, $rowend, &$result, $list if ( $this->mTemplate !== '' ) { // build template code $this->getQueryPrinter()->hasTemplates( true ); - // $wikitext = ( $this->mUserParam ) ? "|userparam=$this->mUserParam" : ''; - $wikitext = ''; + $wikitext = ( $this->mUserParam ) ? "|#userparam=$this->mUserParam" : ''; + //$wikitext = ''; foreach ( $row as $fieldNumber => $field ) { @@ -257,6 +258,14 @@ public static function getParameters() { // 'islist' => false, ]; + $params[] = [ + //'type' => 'string', + 'name' => 'list view userparam', + 'message' => 'srf-paramdesc-filtered-list-userparam', + 'default' => '', + // 'islist' => false, + ]; + return $params; } diff --git a/i18n/en.json b/i18n/en.json index e770088a1..2a6acc691 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -242,6 +242,7 @@ "srf-paramdesc-filtered-filter-position": "The position of the filters in relation to the views. Allowed values: \"top\", \"bottom\". Default: \"top\".", "srf-paramdesc-filtered-list-type": "The type of the list. Allowed values: \"list\", \"ul\", \"ol\". Default: \"list\".", "srf-paramdesc-filtered-list-template": "The template that is to be used to format the list entries.", + "srf-paramdesc-filtered-list-userparam": "The userparam that is passed to the template.", "srf-paramdesc-filtered-list-named-args": "Name the arguments passed to the template.", "srf-paramdesc-filtered-list-introtemplate": "The name of a template to display before the query results, if there are any.", "srf-paramdesc-filtered-list-outrotemplate": "The name of a template to display after the query results, if there are any.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 3374d080e..ccc4e0f49 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -258,6 +258,7 @@ "srf-paramdesc-filtered-filter-position": "{{doc-paramdesc|filter position}}\n{{doc-important|Do not translate the parameter values \"top\" and \"bottom\".}}", "srf-paramdesc-filtered-list-type": "{{doc-paramdesc|list view type}}\n{{doc-important|Do not translate the parameter values \"list\", \"ul\" and \"ol\"}}", "srf-paramdesc-filtered-list-template": "{{doc-paramdesc|list view template}}", + "srf-paramdesc-filtered-list-userparam": "{{doc-paramdesc|list view userparam}}", "srf-paramdesc-filtered-list-named-args": "{{doc-paramdesc|list view named args}}\n\nSee this page for [https://www.semantic-mediawiki.org/wiki/Help:Template_format#Usage_for_named_args detailed information on named argruments].", "srf-paramdesc-filtered-list-introtemplate": "{{doc-paramdesc|list view introtemplate}}\n\nSimilar to {{msg-mw|srf-paramdesc-filtered-list-outrotemplate}}.", "srf-paramdesc-filtered-list-outrotemplate": "{{doc-paramdesc|list view outrotemplate}}\n\nSimilar to {{msg-mw|srf-paramdesc-filtered-list-introtemplate}}.", diff --git a/tests/phpunit/Integration/JSONScript/TestCases/filtered-03.json b/tests/phpunit/Integration/JSONScript/TestCases/filtered-03.json new file mode 100644 index 000000000..5855a93b6 --- /dev/null +++ b/tests/phpunit/Integration/JSONScript/TestCases/filtered-03.json @@ -0,0 +1,104 @@ +{ + "description": "Filtered format: List view tests", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/City name", + "contents": "[[Has type::Text]]" + }, + + { + "namespace": "NS_TEMPLATE", + "page": "City", + "contents": "[[Category:Filtered test]][[Category:City]][[Filtered test/City name::{{{Name|}}}]]" + }, + + { + "namespace": "NS_TEMPLATE", + "page": "RT City", + "contents": "Name: {{{1|}}}" + }, + { + "namespace": "NS_TEMPLATE", + "page": "RT City Intro", + "contents": "INTRO" + }, + { + "namespace": "NS_TEMPLATE", + "page": "RT City Outro", + "contents": "OUTRO" + }, + { + "namespace": "NS_TEMPLATE", + "page": "RT City Userparam", + "contents": "{{{#userparam}}}" + }, + + { + "page": "Filtered test/Berlin", + "contents": "{{City|Name=Berlin}}" + }, + { + "page": "Example/Filtered 03-01", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |format=filtered |views=list |list view template=RT City |link=none}}" + }, + { + "page": "Example/Filtered 03-02", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |format=filtered |views=list |list view userparam=USERPARAM |list view template=RT City Userparam |link=none}}" + }, + { + "page": "Example/Filtered 03-03", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |format=filtered |views=list |list view template=RT City |list view introtemplate=RT City Intro |list view outrotemplate=RT City Outro |link=none}}" + } + ], + "tests": [ + { + "type": "parser", + "about": "Filtered 03-01 (List view: template)", + "subject": "Example/Filtered 03-01", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "Name: Filtered test/Berlin" + ] + } + }, + + { + "type": "parser", + "about": "Filtered 03-02 (List view: template with userparam)", + "subject": "Example/Filtered 03-02", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "USERPARAM" + ] + } + }, + + { + "type": "parser", + "about": "Filtered 03-03 (List view: template with intro/outro template)", + "subject": "Example/Filtered 03-03", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "INTRO", "Name: Filtered test/Berlin", "OUTRO" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}