From ffd7b6829ec2a9e692fec0ebd7b1bdee626280f8 Mon Sep 17 00:00:00 2001 From: Zheng Zhu Date: Thu, 7 Apr 2005 23:04:08 +0000 Subject: [PATCH] cache the title text of an article when there is different ways of presenting the title in different language variants --- includes/Article.php | 7 ++++++- includes/OutputPage.php | 4 ++++ includes/Parser.php | 9 +++++++-- languages/Language.php | 8 ++++++++ languages/LanguageZh.php | 15 ++++++++++----- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 69833d3e88..508d76eb34 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -750,7 +750,12 @@ class Article { $wgOut->addWikiText( $text ); } } - $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + /* title may have been set from the cache */ + $t = $wgOut->getPageTitle(); + if( empty( $t ) ) { + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + } + # If we have been passed an &rcid= parameter, we want to give the user a # chance to mark this new article as patrolled. if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->isLoggedIn() && diff --git a/includes/OutputPage.php b/includes/OutputPage.php index ca2217505f..61f9ee3834 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -288,6 +288,10 @@ class OutputPage { $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); $this->addHTML( $parserOutput->getText() ); + $t = $parserOutput->getTitleText(); + if( !empty( $t ) ) { + $this->setPageTitle( $t ); + } return true; } else { return false; diff --git a/includes/Parser.php b/includes/Parser.php index 0775293a38..0c3d83398b 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -214,7 +214,7 @@ class Parser $this->replaceLinkHolders( $text ); $text = $wgContLang->convert($text); - + $this->mOutput->setTitleText($wgContLang->getParsedTitle()); $text = $this->unstripNoWiki( $text, $this->mStripState ); if ($wgUseTidy) { $text = Parser::tidy($text); @@ -2917,9 +2917,10 @@ class ParserOutput var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic; var $mCacheTime; # Used in ParserCache var $mVersion; # Compatibility check + var $mTitleText; # title text of the chosen language variant function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(), - $containsOldMagic = false ) + $containsOldMagic = false, $titletext = '' ) { $this->mText = $text; $this->mLanguageLinks = $languageLinks; @@ -2927,18 +2928,22 @@ class ParserOutput $this->mContainsOldMagic = $containsOldMagic; $this->mCacheTime = ''; $this->mVersion = MW_PARSER_VERSION; + $this->mTitleText = $titletext; } function getText() { return $this->mText; } function getLanguageLinks() { return $this->mLanguageLinks; } function getCategoryLinks() { return array_keys( $this->mCategoryLinks ); } function getCacheTime() { return $this->mCacheTime; } + function getTitleText() { return $this->mTitleText; } function containsOldMagic() { return $this->mContainsOldMagic; } function setText( $text ) { return wfSetVar( $this->mText, $text ); } function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); } function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks, $cl ); } 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 addCategoryLink( $c ) { $this->mCategoryLinks[$c] = 1; } function merge( $other ) { diff --git a/languages/Language.php b/languages/Language.php index 2cfbf71c78..e26b90c37f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2505,6 +2505,14 @@ class Language { return $this; } + /* for languages that support multiple variants, the title of an + article may be displayed differently in different variants. this + function returns the apporiate title defined in the body of the article. + */ + function getParsedTitle() { + return ''; + } + } # This should fail gracefully if there's not a localization available diff --git a/languages/LanguageZh.php b/languages/LanguageZh.php index 660c1236ac..b74d6f3964 100644 --- a/languages/LanguageZh.php +++ b/languages/LanguageZh.php @@ -44,7 +44,7 @@ class LanguageZh extends LanguageZh_cn { var $mTablesLoaded = false; var $mCacheKey; var $mDoTitleConvert = true, $mDoContentConvert = true; - var $mTitleDisplay=false; + var $mTitleDisplay=''; function LanguageZh() { global $wgDBname; $this->mCacheKey = $wgDBname . ":zhtables"; @@ -323,10 +323,11 @@ class LanguageZh extends LanguageZh_cn { return $text; if( $isTitle ) { - if( !$this->mDoTitleConvert ) + if( !$this->mDoTitleConvert ) { + $this->mTitleDisplay = $text; return $text; - - if( $this->mTitleDisplay != false ) + } + if( !empty($this->mTitleDisplay)) return $this->mTitleDisplay; global $wgRequest; @@ -336,7 +337,8 @@ class LanguageZh extends LanguageZh_cn { return $text; } else { - return $this->autoConvert($text); + $this->mTitleDisplay = $this->autoConvert($text); + return $this->mTitleDisplay; } } @@ -488,5 +490,8 @@ class LanguageZh extends LanguageZh_cn { return '!' . $variant ; } + function getParsedTitle() { + return $this->mTitleDisplay; + } } ?> -- 2.20.1