From: Jackmcbarn Date: Thu, 29 May 2014 16:55:40 +0000 (-0400) Subject: Add a tracking category for duplicate arguments X-Git-Tag: 1.31.0-rc.0~13594 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=05b7a51966709d42beb5f786378bb8af4ca7a72f;p=lhc%2Fweb%2Fwiklou.git Add a tracking category for duplicate arguments If a page accidentally duplicates an argument, such as {{foo|bar=1|bar=2}} or {{foo|bar|1=baz}}, add it to a tracking category. Bug: 69964 Change-Id: I3b6eeff8b51859bc7af0ea985f6f7528c2e9d220 --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index de29f0d2ae..57859ece53 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3797,6 +3797,7 @@ $wgNamespacesWithSubpages = array( $wgTrackingCategories = array( 'index-category', 'noindex-category', + 'duplicate-args-category', 'expensive-parserfunction-category', 'post-expand-template-argument-category', 'post-expand-template-inclusion-category', diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 2edb79a2af..2cce574934 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -1043,11 +1043,17 @@ class PPFrame_DOM implements PPFrame { // Numbered parameter $index = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent; $index = $index - $indexOffset; + if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) { + $this->parser->addTrackingCategory( 'duplicate-args-category' ); + } $numberedArgs[$index] = $value->item( 0 ); unset( $namedArgs[$index] ); } else { // Named parameter $name = trim( $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS ) ); + if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) { + $this->parser->addTrackingCategory( 'duplicate-args-category' ); + } $namedArgs[$name] = $value->item( 0 ); unset( $numberedArgs[$name] ); } diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 637639675b..b4b14dc4d7 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -985,11 +985,17 @@ class PPFrame_Hash implements PPFrame { if ( $bits['index'] !== '' ) { // Numbered parameter $index = $bits['index'] - $indexOffset; + if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) { + $this->parser->addTrackingCategory( 'duplicate-args-category' ); + } $numberedArgs[$index] = $bits['value']; unset( $namedArgs[$index] ); } else { // Named parameter $name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) ); + if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) { + $this->parser->addTrackingCategory( 'duplicate-args-category' ); + } $namedArgs[$name] = $bits['value']; unset( $numberedArgs[$name] ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 99554e7320..9aa05f3c3c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -694,6 +694,8 @@ "content-model-text": "plain text", "content-model-javascript": "JavaScript", "content-model-css": "CSS", + "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}}.", "expensive-parserfunction-category": "Pages with too many expensive parser function calls", "post-expand-template-inclusion-warning": "Warning: Template include size is too large.\nSome templates will not be included.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 99aecb0c52..55945e92ca 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -857,6 +857,8 @@ "content-model-text": "Name for the plain text 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}}\n{{Identical|Plain text}}", "content-model-javascript": "Name for the JavaScript 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-model-css": "Name for the CSS 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}}", + "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}}", "expensive-parserfunction-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 too many calls to expensive parser functions.\n\nSee also:\n* {{msg-mw|Expensive-parserfunction-category-desc}}\n* {{msg-mw|Expensive-parserfunction-warning}}", "post-expand-template-inclusion-warning": "When templates are expanded, there is a size limit for the number of bytes yielded. Usually that occurs from excessively nested templates, recursive templates, or ones having x-zillion of #if #case or similar contructs in them. When the wikicode parser detects this, it outputs a red warning message to the page.\n\n\nSee also:\n* {{msg-mw|Post-expand-template-inclusion-category}}",