Warn when duplicate arguments are found
authorJackmcbarn <jackmcbarn@gmail.com>
Fri, 24 Oct 2014 16:09:36 +0000 (12:09 -0400)
committerJackmcbarn <jackmcbarn@gmail.com>
Thu, 28 May 2015 17:36:50 +0000 (13:36 -0400)
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

includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php
languages/i18n/en.json
languages/i18n/qqq.json

index 0351f2a..caef648 100644 (file)
@@ -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 );
index af91ad4..d32fb57 100644 (file)
@@ -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'];
index 26c4b1b..9ade1fc 100644 (file)
        "content-model-json": "JSON",
        "content-json-empty-object": "Empty object",
        "content-json-empty-array": "Empty array",
+       "duplicate-args-warning": "<strong>Warning:</strong> [[:$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 <code><nowiki>{{foo|bar=1|bar=2}}</nowiki></code> or <code><nowiki>{{foo|bar|1=baz}}</nowiki></code>.",
        "expensive-parserfunction-warning": "<strong>Warning:</strong> 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}}.",
index 282ced5..872d104 100644 (file)
        "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 <code><nowiki>{{foo|bar=1|bar=2}}</nowiki></code> or <code><nowiki>{{foo|bar|1=baz}}</nowiki></code>, 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 <code><nowiki>{{foo|bar=1|bar=2}}</nowiki></code> or <code><nowiki>{{foo|bar|1=baz}}</nowiki></code>.",
        "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. <code><nowiki>{{#ifexist:}}</nowiki></code>) 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}}",