From: Jackmcbarn Date: Fri, 24 Oct 2014 16:09:36 +0000 (-0400) Subject: Warn when duplicate arguments are found X-Git-Tag: 1.31.0-rc.0~11269 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=9a805b816d9aa19611a49d638fab86b7389c8618;p=lhc%2Fweb%2Fwiklou.git Warn when duplicate arguments are found Currently, duplicate arguments result in a categorization but not a warning, and it's often difficult to find where in the template hierarchy the problem lies. This causes a warning to be provided containing the calling page's name, the called template's name, and the parameter's name. Bug: T85352 Change-Id: I26b9a7ed5a2f246d00a49a5f6effe40b4443a9d0 --- diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 0351f2a8f1..caef648942 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -1029,6 +1029,10 @@ class PPFrame_DOM implements PPFrame { $index = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent; $index = $index - $indexOffset; if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) { + $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning', + wfEscapeWikiText( $this->title ), + wfEscapeWikiText( $title ), + wfEscapeWikiText( $index ) )->text() ); $this->parser->addTrackingCategory( 'duplicate-args-category' ); } $numberedArgs[$index] = $value->item( 0 ); @@ -1037,6 +1041,10 @@ class PPFrame_DOM implements PPFrame { // Named parameter $name = trim( $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS ) ); if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) { + $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning', + wfEscapeWikiText( $this->title ), + wfEscapeWikiText( $title ), + wfEscapeWikiText( $name ) )->text() ); $this->parser->addTrackingCategory( 'duplicate-args-category' ); } $namedArgs[$name] = $value->item( 0 ); diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index af91ad47fb..d32fb574ef 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -972,6 +972,10 @@ class PPFrame_Hash implements PPFrame { // Numbered parameter $index = $bits['index'] - $indexOffset; if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) { + $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning', + wfEscapeWikiText( $this->title ), + wfEscapeWikiText( $title ), + wfEscapeWikiText( $index ) )->text() ); $this->parser->addTrackingCategory( 'duplicate-args-category' ); } $numberedArgs[$index] = $bits['value']; @@ -980,6 +984,10 @@ class PPFrame_Hash implements PPFrame { // Named parameter $name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) ); if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) { + $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning', + wfEscapeWikiText( $this->title ), + wfEscapeWikiText( $title ), + wfEscapeWikiText( $name ) )->text() ); $this->parser->addTrackingCategory( 'duplicate-args-category' ); } $namedArgs[$name] = $bits['value']; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 26c4b1bb22..9ade1fc6c7 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -716,6 +716,7 @@ "content-model-json": "JSON", "content-json-empty-object": "Empty object", "content-json-empty-array": "Empty array", + "duplicate-args-warning": "Warning: [[:$1]] is calling [[:$2]] with more than one value for the \"$3\" parameter. Only the last value provided will be used.", "duplicate-args-category": "Pages using duplicate arguments in template calls", "duplicate-args-category-desc": "The page contains template calls that use duplicates of arguments, such as {{foo|bar=1|bar=2}} or {{foo|bar|1=baz}}.", "expensive-parserfunction-warning": "Warning: This page contains too many expensive parser function calls.\n\nIt should have less than $2 {{PLURAL:$2|call|calls}}, there {{PLURAL:$1|is now $1 call|are now $1 calls}}.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 282ced5d8b..872d104988 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -886,6 +886,7 @@ "content-model-json": "Name for the JSON content model, used when decribing what type of content a page contains.\n\nThis message is substituted in:\n*{{msg-mw|Bad-target-model}}\n*{{msg-mw|Content-not-allowed-here}}", "content-json-empty-object": "Used to represent an object with no properties on a JSON content model page.", "content-json-empty-array": "Used to represent an array with no values on a JSON content model page.", + "duplicate-args-warning": "If a page calls a template and specifies the same argument more than once, such as {{foo|bar=1|bar=2}} or {{foo|bar|1=baz}}, this warning is displayed when previewing.\n\nParameters:\n* $1 - The calling page\n* $2 - The called template\n $3 - The name of the duplicated argument", "duplicate-args-category": "This message is used as a category name for a [[mw:Special:MyLanguage/Help:Tracking categories|tracking category]] where pages are placed automatically if they contain template calls that use duplicates of arguments, such as {{foo|bar=1|bar=2}} or {{foo|bar|1=baz}}.", "duplicate-args-category-desc": "Duplicate arguments category description. Shown on [[Special:TrackingCategories]].\n\nSee also:\n* {{msg-mw|Duplicate-args-category}}", "expensive-parserfunction-warning": "On some (expensive) [[MetaWikipedia:Help:ParserFunctions|parser functions]] (e.g. {{#ifexist:}}) there is a limit of how many times it may be used. This is an error message shown when the limit is exceeded.\n\nParameters:\n* $1 - the current number of parser function calls\n* $2 - the allowed number of parser function calls\nSee also [[:mw:Manual:$wgExpensiveParserFunctionLimit|$wgExpensiveParserFunctionLimit in the MediaWiki manual]].\n\nSee also:\n* {{msg-mw|Expensive-parserfunction-category}}",