From 19be1d25ac4ed5533b7fba5fb27983a27a295784 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 25 Jun 2007 15:51:09 +0000 Subject: [PATCH] Fix up DISPLAYTITLE and enable per default: * Clean up the mess in ParserOutput * Reject (ignore) custom titles which don't normalise to the same as the current page -- THIS IS IMPORTANT OTHERWISE LINKING GOES TO POT (and not the good kind of pot) [WARNING: Touches parser version. Old caches will be expired. You might wish to undo this and add some temporarily backwards-compatibility for a few days.] --- RELEASE-NOTES | 3 ++- includes/CoreParserFunctions.php | 23 ++++++++++++++--------- includes/DefaultSettings.php | 2 +- includes/OutputPage.php | 10 ++++------ includes/Parser.php | 2 +- includes/ParserOutput.php | 31 ++++++++++++++++++++++++++----- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 08d50dfe89..6da070f45d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -102,7 +102,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Added option to install to MyISAM * (bug 9250) Remove hardcoded minimum image name length of three characters * (bug 10338) Enforce signature length limit in Unicode characters instead of bytes - +* Fixed DISPLAYTITLE behaviour to reject titles which don't normalise to the + same title as the current page, and enabled per default == Bugfixes since 1.10 == diff --git a/includes/CoreParserFunctions.php b/includes/CoreParserFunctions.php index 72ceb45f60..6cf35f91ab 100644 --- a/includes/CoreParserFunctions.php +++ b/includes/CoreParserFunctions.php @@ -97,15 +97,20 @@ class CoreParserFunctions { return $parser->getFunctionLang()->convertPlural( $text, $arg0, $arg1, $arg2, $arg3, $arg4 ); } - static function displaytitle( $parser, $param = '' ) { - $parserOptions = new ParserOptions; - $local_parser = clone $parser; - $t2 = $local_parser->parse ( $param, $parser->mTitle, $parserOptions, false ); - $parser->mOutput->mHTMLtitle = $t2->GetText(); - - # Add subtitle - $t = $parser->mTitle->getPrefixedText(); - $parser->mOutput->mSubtitle .= wfMsg('displaytitle', $t); + /** + * Override the title of the page when viewed, + * provided we've been given a title which + * will normalise to the canonical title + * + * @param Parser $parser Parent parser + * @param string $text Desired title text + * @return string + */ + static function displaytitle( $parser, $text = '' ) { + $text = trim( $text ); + $title = Title::newFromText( $text ); + if( $title instanceof Title && $title->equals( $parser->mTitle ) ) + $parser->mOutput->setDisplayTitle( $text ); return ''; } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5a81b71ff1..67ca01c4be 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2539,7 +2539,7 @@ $wgAjaxWatch = true; /** * Allow DISPLAYTITLE to change title display */ -$wgAllowDisplayTitle = false ; +$wgAllowDisplayTitle = true; /** * Array of usernames which may not be registered or logged in from diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 75e4ef932d..ed5674f788 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -381,17 +381,15 @@ class OutputPage { if ( $parserOutput->getCacheTime() == -1 ) { $this->enableClientCache( false ); } - if ( $parserOutput->mHTMLtitle != "" ) { - $this->mPagetitle = $parserOutput->mHTMLtitle ; - } - if ( $parserOutput->mSubtitle != '' ) { - $this->mSubtitle .= $parserOutput->mSubtitle ; - } $this->mNoGallery = $parserOutput->getNoGallery(); $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems ); // Versioning... $this->mTemplateIds += (array)$parserOutput->mTemplateIds; + # Display title + if( ( $dt = $parserOutput->getDisplayTitle() ) !== false ) + $this->setPageTitle( $dt ); + wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) ); } diff --git a/includes/Parser.php b/includes/Parser.php index 50f9ac1e70..e4418cd51c 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -12,7 +12,7 @@ * changes in an incompatible way, so the parser cache * can automatically discard old data. */ -define( 'MW_PARSER_VERSION', '1.6.1' ); +define( 'MW_PARSER_VERSION', '1.6.2' ); define( 'RLH_FOR_UPDATE', 1 ); diff --git a/includes/ParserOutput.php b/includes/ParserOutput.php index ba9db7354a..fed4538347 100644 --- a/includes/ParserOutput.php +++ b/includes/ParserOutput.php @@ -17,11 +17,14 @@ class ParserOutput $mTemplateIds, # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken. $mImages, # DB keys of the images used, in the array key only $mExternalLinks, # External link URLs, in the key only - $mHTMLtitle, # Display HTML title - $mSubtitle, # Additional subtitle $mNewSection, # Show a new section link? $mNoGallery, # No gallery on category page? (__NOGALLERY__) $mHeadItems; # Items to put in the section + + /** + * Overridden title for display + */ + private $displayTitle = false; function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(), $containsOldMagic = false, $titletext = '' ) @@ -37,8 +40,6 @@ class ParserOutput $this->mTemplates = array(); $this->mImages = array(); $this->mExternalLinks = array(); - $this->mHTMLtitle = "" ; - $this->mSubtitle = "" ; $this->mNewSection = false; $this->mNoGallery = false; $this->mHeadItems = array(); @@ -65,7 +66,6 @@ class ParserOutput function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); } - function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); } function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; } function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; } @@ -137,6 +137,27 @@ class ParserOutput $this->mHeadItems[] = $section; } } + + /** + * Override the title to be used for display + * -- this is assumed to have been validated + * (check equal normalisation, etc.) + * + * @param string $text Desired title text + */ + public function setDisplayTitle( $text ) { + $this->displayTitle = $text; + } + + /** + * Get the title to be used for display + * + * @return string + */ + public function getDisplayTitle() { + return $this->displayTitle; + } + } ?> -- 2.20.1