From 3a2345fe1c246bc0605f06baaa50992adf7c9eb8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 10 Apr 2010 13:38:50 +0000 Subject: [PATCH] Proposed cleanup of recent LanguageConverter-related commits: * Moved the responsibility for calling $wgOut->setPageTitle() from OutputPage::addParserOutputNoText() to the OutputPage/Parser caller. Previously, every call to $wgOut->addWikiText() (or any other message parsing function) was resulting in the title being reset to a converted version of $wgTitle, producing bug 23124. Moving responsibility to the caller seems to work fairly well, since there are apparently only two callers that really want {{DISPLAYTITLE}} etc. to work (EditPage and Article::view). * Reverted data flow obfuscation in OutputPage::setHTMLTitle() from r64851, replaced by the above. The caller decides what overrides what. * Reverted inappropriate, cache-polluting references to $wgUser and $wgRequest in Parser::parse(), introduced in r64819. * Reverted incomprehensible boolean parameter to Language::convert() from r64851, reintroduced Language::convertTitle() instead. Gave it a simpler implementation than before. * Fixed broken {{DISPLAYTITLE}} feature, was being unconditionally overwritten by the ParserOutput::setTitleText() call in Parser::parse(). Give {{DISPLAYTITLE}} precedence over autoconverted title, like we do for -{T|...}-. * Tested extensively (perhaps not exhaustively) --- includes/Article.php | 6 +++++ includes/OutputPage.php | 19 +++------------ includes/parser/Parser.php | 10 ++++---- languages/Language.php | 12 ++++++--- languages/LanguageConverter.php | 43 +++++++++++++++------------------ 5 files changed, 43 insertions(+), 47 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 658ed37556..f5498b5742 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -956,6 +956,12 @@ class Article { } } + # Adjust the title if it was set by displaytitle, -{T|}- or language conversion + $titleText = $this->mParserOutput->getTitleText(); + if ( strval( $titleText ) !== '' ) { + $wgOut->setPageTitle( $titleText ); + } + # Now that we've filled $this->mParserOutput, we know whether # there are any __NOINDEX__ tags on the page $policy = $this->getRobotPolicy( 'view' ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 33753c0f81..0e060ad114 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -9,7 +9,7 @@ class OutputPage { var $mMetatags = array(), $mKeywords = array(), $mLinktags = array(); var $mExtStyles = array(); var $mPagetitle = '', $mBodytext = '', $mDebugtext = ''; - var $mHTMLtitle = '', $mHTMLtitleFromPagetitle = true, $mIsarticle = true, $mPrintable = false; + var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false; var $mSubtitle = '', $mRedirect = '', $mStatusCode; var $mLastModified = '', $mETag = false; var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array(); @@ -447,17 +447,9 @@ class OutputPage { /** * "HTML title" means the contents of . * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file. - * If $name is from page title, it can only override names which are also from page title, - * but if it is not from page title, it can override all other names. */ - public function setHTMLTitle( $name, $frompagetitle = false ) { - if ( $frompagetitle && $this->mHTMLtitleFromPagetitle ) { - $this->mHTMLtitle = $name; - } - elseif ( $this->mHTMLtitleFromPagetitle ) { - $this->mHTMLtitle = $name; - $this->mHTMLtitleFromPagetitle = false; - } + public function setHTMLTitle( $name ) { + $this->mHTMLtitle = $name; } /** @@ -1104,11 +1096,6 @@ class OutputPage { $this->mTemplateIds[$ns] = $dbks; } } - // Page title - $title = $parserOutput->getTitleText(); - if ( $title != '' ) { - $this->setPageTitle( $title ); - } // Hooks registered in the object global $wgParserOutputHooks; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 88bc3e5809..c5b4ef6123 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -303,7 +303,7 @@ class Parser { * to internalParse() which does all the real work. */ - global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion, $wgUser, $wgRequest; + global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion; $fname = __METHOD__.'-' . wfGetCaller(); wfProfileIn( __METHOD__ ); wfProfileIn( $fname ); @@ -377,16 +377,16 @@ class Parser { */ if ( !( $wgDisableLangConversion || $wgDisableTitleConversion - || $wgRequest->getText( 'redirect', 'yes' ) == 'no' - || $wgRequest->getText( 'linkconvert', 'yes' ) == 'no' || isset( $this->mDoubleUnderscores['nocontentconvert'] ) || isset( $this->mDoubleUnderscores['notitleconvert'] ) - || $wgUser->getOption( 'noconvertlink' ) == 1 ) ) { + || $this->mOutput->getDisplayTitle() !== false ) ) + { $convruletitle = $wgContLang->getConvRuleTitle(); if ( $convruletitle ) { $this->mOutput->setTitleText( $convruletitle ); } else { - $this->mOutput->setTitleText( $wgContLang->convert( $title->getPrefixedText(), true ) ); + $titleText = $wgContLang->convertTitle( $title ); + $this->mOutput->setTitleText( $titleText ); } } diff --git a/languages/Language.php b/languages/Language.php index da714a712f..e86e609394 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -36,7 +36,8 @@ class FakeConverter { var $mLang; function FakeConverter( $langobj ) { $this->mLang = $langobj; } function autoConvertToAllVariants( $text ) { return $text; } - function convert( $t, $i ) { return $t; } + function convert( $t ) { return $t; } + function convertTitle( $t ) { return $t->getPrefixedText(); } function getVariants() { return array( $this->mLang->getCode() ); } function getPreferredVariant() { return $this->mLang->getCode(); } function getConvRuleTitle() { return false; } @@ -2606,8 +2607,13 @@ class Language { } # convert text to different variants of a language. - function convert( $text, $isTitle = false ) { - return $this->mConverter->convert( $text, $isTitle ); + function convert( $text ) { + return $this->mConverter->convert( $text ); + } + + # Convert a Title object to a string in the preferred variant + function convertTitle( $title ) { + return $this->mConverter->convertTitle( $title ); } # Check if this is a language with variants diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 9a0eac9a8a..06f794dc2d 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -515,24 +515,6 @@ class LanguageConverter { } } - /** - * Convert namespace. - * @param $title String: the title included namespace - * @return Array of string - * @private - */ - function convertNamespace( $title, $variant ) { - $splittitle = explode( ':', $title, 2 ); - if ( count( $splittitle ) < 2 ) { - return $title; - } - if ( isset( $this->mNamespaceTables[$variant][$splittitle[0]] ) ) { - $splittitle[0] = $this->mNamespaceTables[$variant][$splittitle[0]]; - } - $ret = implode( ':', $splittitle ); - return $ret; - } - /** * Convert text to different variants of a language. The automatic * conversion is done in autoConvert(). Here we parse the text @@ -547,19 +529,34 @@ class LanguageConverter { * @param $text String: text to be converted * @return String: converted text */ - public function convert( $text, $istitle = false ) { + public function convert( $text ) { global $wgDisableLangConversion; if ( $wgDisableLangConversion ) return $text; $variant = $this->getPreferredVariant(); - if( $istitle ) { - $text = $this->convertNamespace( $text, $variant ); - } - return $this->recursiveConvertTopLevel( $text, $variant ); } + /** + * Convert a Title object to a readable string in the preferred variant + */ + public function convertTitle( $title ) { + $variant = $this->getPreferredVariant(); + if ( $title->getNamespace() === NS_MAIN ) { + $text = ''; + } else { + $text = $title->getNsText(); + if ( isset( $this->mNamespaceTables[$variant][$text] ) ) { + $text = $this->mNamespaceTables[$variant][$text]; + } + $text .= ':'; + } + $text .= $title->getText(); + $text = $this->autoConvert( $text, $variant ); + return $text; + } + protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) { $startPos = 0; $out = ''; -- 2.20.1