Proposed cleanup of recent LanguageConverter-related commits:
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 10 Apr 2010 13:38:50 +0000 (13:38 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 10 Apr 2010 13:38:50 +0000 (13:38 +0000)
* 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
includes/OutputPage.php
includes/parser/Parser.php
languages/Language.php
languages/LanguageConverter.php

index 658ed37..f5498b5 100644 (file)
@@ -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' );
index 33753c0..0e060ad 100644 (file)
@@ -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 <title>.
         * 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;
index 88bc3e5..c5b4ef6 100644 (file)
@@ -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 );
                        }
                }
 
index da714a7..e86e609 100644 (file)
@@ -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
index 9a0eac9..06f794d 100644 (file)
@@ -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 = '';