cache the title text of an article when there is different ways of presenting the...
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Thu, 7 Apr 2005 23:04:08 +0000 (23:04 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Thu, 7 Apr 2005 23:04:08 +0000 (23:04 +0000)
includes/Article.php
includes/OutputPage.php
includes/Parser.php
languages/Language.php
languages/LanguageZh.php

index 69833d3..508d76e 100644 (file)
@@ -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() &&
index ca22175..61f9ee3 100644 (file)
@@ -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;
index 0775293..0c3d833 100644 (file)
@@ -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 ) {
index 2cfbf71..e26b90c 100644 (file)
@@ -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
index 660c123..b74d6f3 100644 (file)
@@ -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;
+       }
 }
 ?>