From af66fecb2d887e917bcb57e2377a71c3cdab987c Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Tue, 8 Jul 2014 23:34:50 -0400 Subject: [PATCH] Warn when DISPLAYTITLE is used more than once Implement the same duplicate-warning logic for DISPLAYTITLE that DEFAULTSORT currently uses, to catch cases where a newer call overrides an older one. Bug: 50449 Change-Id: Ibce776d019aab07fb88fbb89afc5340300735405 --- includes/parser/CoreParserFunctions.php | 30 ++++++++++++++++++++----- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + languages/messages/MessagesEn.php | 2 ++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 79c8ade65e..faff0e7a9d 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -365,9 +365,15 @@ class CoreParserFunctions { * @param string $text Desired title text * @return string */ - static function displaytitle( $parser, $text = '' ) { + static function displaytitle( $parser, $text = '', $uarg = '' ) { global $wgRestrictDisplayTitle; + static $magicWords = null; + if ( is_null( $magicWords ) ) { + $magicWords = new MagicWordArray( array( 'displaytitle_noerror', 'displaytitle_noreplace' ) ); + } + $arg = $magicWords->matchStartToEnd( $uarg ); + // parse a limited subset of wiki markup (just the single quote items) $text = $parser->doQuotes( $text ); @@ -413,13 +419,25 @@ class CoreParserFunctions { ) ); $title = Title::newFromText( Sanitizer::stripAllTags( $text ) ); - if ( !$wgRestrictDisplayTitle ) { - $parser->mOutput->setDisplayTitle( $text ); - } elseif ( $title instanceof Title + if ( !$wgRestrictDisplayTitle || + ( $title instanceof Title && !$title->hasFragment() - && $title->equals( $parser->mTitle ) + && $title->equals( $parser->mTitle ) ) ) { - $parser->mOutput->setDisplayTitle( $text ); + $old = $parser->mOutput->getProperty( 'displaytitle' ); + if ( $old === false || $arg !== 'displaytitle_noreplace' ) { + $parser->mOutput->setDisplayTitle( $text ); + } + if ( $old !== false && $old !== $text && !$arg ) { + $converter = $parser->getConverterLanguage()->getConverter(); + return '' . + wfMessage( 'duplicate-displaytitle', + // Message should be parsed, but these params should only be escaped. + $converter->markNoConversion( wfEscapeWikiText( $old ) ), + $converter->markNoConversion( wfEscapeWikiText( $text ) ) + )->inContentLanguage()->text() . + ''; + } } return ''; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index d0e7ad3ebf..b9dc69eab3 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3214,6 +3214,7 @@ "timezone-utc": "UTC", "unknown_extension_tag": "Unknown extension tag \"$1\"", "duplicate-defaultsort": "Warning: Default sort key \"$2\" overrides earlier default sort key \"$1\".", + "duplicate-displaytitle": "Warning: Display title \"$2\" overrides earlier display title \"$1\".", "version": "Version", "version-summary": "", "version-extensions": "Installed extensions", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 78dd1fd570..aa2151fdd1 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3376,6 +3376,7 @@ "timezone-utc": "{{optional}}", "unknown_extension_tag": "This is an error shown when you use an unknown extension tag name.\n\nThis feature allows tags like
 to be called with a parser like {{#tag:pre}}.\n\nParameters:\n* $1 - the unknown extension tag name",
 	"duplicate-defaultsort": "See definition of [[w:Sorting|sort key]] on Wikipedia. Parameters:\n* $1 - old default sort key\n* $2 - new default sort key",
+	"duplicate-displaytitle": "Warning shown when a page has its display title set multiple times. Parameters:\n* $1 - old display title\n* $2 - new display title",
 	"version": "{{doc-special|Version}}\n{{Identical|Version}}",
 	"version-summary": "{{doc-specialpagesummary|version}}",
 	"version-extensions": "Header on [[Special:Version]].",
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php
index 6900aebc2a..8167b1948f 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -365,6 +365,8 @@ $magicWords = array(
 	'url_query'               => array( 0,    'QUERY' ),
 	'defaultsort_noerror'     => array( 0,    'noerror' ),
 	'defaultsort_noreplace'   => array( 0,    'noreplace' ),
+	'displaytitle_noerror'    => array( 0,    'noerror' ),
+	'displaytitle_noreplace'  => array( 0,    'noreplace' ),
 	'pagesincategory_all'     => array( 0,    'all' ),
 	'pagesincategory_pages'   => array( 0,    'pages' ),
 	'pagesincategory_subcats' => array( 0,    'subcats' ),
-- 
2.20.1