http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60832

Revision: 60832
Author:   mah
Date:     2010-01-08 08:22:19 +0000 (Fri, 08 Jan 2010)

Log Message:
-----------
follow up r60763
Recover the -{T| }- rule.  Add the ability to test for it to the parserTests 
and add a test for it.  Add a couple of disabled tests that I think demonstrate 
bugs in the LanguageTranslator

Modified Paths:
--------------
    trunk/phase3/includes/parser/Parser.php
    trunk/phase3/languages/Language.php
    trunk/phase3/languages/LanguageConverter.php
    trunk/phase3/maintenance/parserTests.inc
    trunk/phase3/maintenance/parserTests.txt

Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php     2010-01-08 07:52:51 UTC (rev 
60831)
+++ trunk/phase3/includes/parser/Parser.php     2010-01-08 08:22:19 UTC (rev 
60832)
@@ -261,6 +261,12 @@
                if ( !$t || $t instanceof FakeTitle ) {
                        $t = Title::newFromText( 'NO TITLE' );
                }
+               // If we still don't have a Title object, make sure we can
+               // convert whatever we've been passed to a string.
+               if ( !$t instanceOf Title && is_string( "$t" ) ) {
+                       $t = Title::newFromText( "$t" );
+               }
+
                if ( strval( $t->getFragment() ) !== '' ) {
                        # Strip the fragment to avoid various odd effects
                        $this->mTitle = clone $t;
@@ -329,14 +335,6 @@
                # No more strip!
                wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, 
&$this->mStripState ) );
                $text = $this->internalParse( $text );
-               // internalParse took care of the notitleconvert bit, so title 
conversion is here.
-               if ( $this->mDoTitleConvert && 
!$this->mTitle->isConversionTable()) {
-                       $converted = $wgContLang->convert( $title );
-                       if ( !$converted instanceOf Title ) {
-                               $converted = Title::newFromText( $converted );
-                       }
-                       $this->setTitle( $converted );
-               }
 
                $text = $this->mStripState->unstripGeneral( $text );
 
@@ -355,13 +353,23 @@
 
                $this->replaceLinkHolders( $text );
 
-               # the position of the convert() call should not be changed. it
-               # assumes that the links are all replaced and the only thing 
left
-               # is the <nowiki> mark.
+               // The position of the convert() call should not be changed. it
+               // assumes that the links are all replaced and the only thing 
left
+               // is the <nowiki> mark.
                if ( $this->mDoContentConvert && 
!$this->mTitle->isConversionTable()) {
                        $text = $wgContLang->convert( $text );
                }
 
+               // A title may have been set in a conversion rule.
+               // Note that if a user tries to set a title in a conversion
+               // rule but content conversion was not done, then the parser
+               // won't pick it up.  This is probably expected behavior.
+               if ( $wgContLang->getConvRuleTitle() ) {
+                       $this->setTitle( $wgContLang->getConvRuleTitle() );
+               } elseif ( $this->mDoTitleConvert && 
!$this->mTitle->isConversionTable() ) {
+                       $this->setTitle( $wgContLang->convert( $title ) );
+               }
+
                $text = $this->mStripState->unstripNoWiki( $text );
 
                wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );

Modified: trunk/phase3/languages/Language.php
===================================================================
--- trunk/phase3/languages/Language.php 2010-01-08 07:52:51 UTC (rev 60831)
+++ trunk/phase3/languages/Language.php 2010-01-08 08:22:19 UTC (rev 60832)
@@ -34,11 +34,12 @@
  */
 class FakeConverter {
        var $mLang;
+       var $mConvRuleTitle;
        function FakeConverter($langobj) {$this->mLang = $langobj;}
        function autoConvertToAllVariants($text) {return $text;}
        function convert($t, $i) {return $t;}
        function getVariants() { return array( $this->mLang->getCode() ); }
-       function getPreferredVariant() {return $this->mLang->getCode(); }
+       function getPreferredVariant() { return $this->mLang->getCode(); }
        function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {}
        function getExtraHashOptions() {return '';}
        function getParsedTitle() {return '';}
@@ -2664,4 +2665,11 @@
                $text = $this->getMessageFromDB( $msg );
                return str_replace( '$1', $this->formatNum( $size ), $text );
        }
+
+       /**
+        * Get the conversion rule title, if any.
+        */
+       function getConvRuleTitle() {
+               return $this->mConverter->mConvRuleTitle;
+       }
 }

Modified: trunk/phase3/languages/LanguageConverter.php
===================================================================
--- trunk/phase3/languages/LanguageConverter.php        2010-01-08 07:52:51 UTC 
(rev 60831)
+++ trunk/phase3/languages/LanguageConverter.php        2010-01-08 08:22:19 UTC 
(rev 60832)
@@ -31,6 +31,7 @@
        var $mDescCodeSep = ':', $mDescVarSep = ';';
        var $mUcfirst = false;
        var $mHeaderVariant;
+       var $mConvRuleTitle = false;
 
        const CACHE_VERSION_KEY = 'VERSION 6';
 
@@ -459,8 +460,8 @@
         */
        function applyManualConv( $convRule ) {
                // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom
-        // conversion in title
-               $title = $convRule->getTitle();
+               // conversion in title
+               $this->mConvRuleTitle = $convRule->getTitle();
 
                // apply manual conversion table to global table
                $convTable = $convRule->getConvTable();
@@ -544,7 +545,7 @@
         * @return string converted text
         * @public
         */
-       function convert( $text, $isTitle ) {
+       function convert( $text ) {
                global $wgDisableLangConversion;
                if ( $wgDisableLangConversion ) return $text;
 
@@ -558,10 +559,6 @@
 
                // Remove the last delimiter (wasn't real)
            $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] 
) );
-               if ( $isTitle ) {
-                       error_log("title2: $converted\n");
-                       $this->mConvertedTitle = $converted;
-               }
                return $converted;
        }
 
@@ -1110,13 +1107,13 @@
         * Parse rules conversion.
         * @private
         */
-       function getRuleConvertedStr( $variant, $doConvert ) {
+       function getRuleConvertedStr( $variant ) {
                $bidtable = $this->mBidtable;
                $unidtable = $this->mUnidtable;
 
                if ( count( $bidtable ) + count( $unidtable ) == 0 ) {
                        return $this->mRules;
-               } elseif ( $doConvert ) { // the text converted
+               } else {
                        // display current variant in bidirectional array
                        $disp = $this->getTextInBidtable( $variant );
                        // or display current variant in fallbacks
@@ -1142,8 +1139,6 @@
                                }
                        }
                        return $disp;
-               } else { // no convert
-                       return $this->mRules;
                }
        }
 
@@ -1271,15 +1266,13 @@
                        // proces H,- flag or T only: output nothing
                        $this->mRuleDisplay = '';
                } elseif ( in_array( 'S', $flags ) ) {
-                       // true hard-coded now since we shouldn't be called if 
we're not converting
-                       $this->mRuleDisplay = $this->getRuleConvertedStr( 
$variant, true );
+                       $this->mRuleDisplay = $this->getRuleConvertedStr( 
$variant );
                } else {
                        $this->mRuleDisplay = $this->mManualCodeError;
                }
                // process T flag
                if ( in_array( 'T', $flags ) ) {
-                       // true hard-coded now since we shouldn't be called if 
we're not converting
-                       $this->mRuleTitle = $this->getRuleConvertedStr( 
$variant, true );
+                       $this->mRuleTitle = $this->getRuleConvertedStr( 
$variant );
                }
 
                if ( in_array( '-', $flags ) ) {

Modified: trunk/phase3/maintenance/parserTests.inc
===================================================================
--- trunk/phase3/maintenance/parserTests.inc    2010-01-08 07:52:51 UTC (rev 
60831)
+++ trunk/phase3/maintenance/parserTests.inc    2010-01-08 08:22:19 UTC (rev 
60832)
@@ -493,6 +493,10 @@
                        $result = $this->tidy($result);
                }
 
+               if ( isset( $opts['showtitle'] ) ) {
+                       $out = $parser->mTitle . "\n$out";
+        }
+
                $this->teardownGlobals();
 
                if( $result === $out && ( $noxml === true || $this->wellFormed( 
$out ) ) ) {

Modified: trunk/phase3/maintenance/parserTests.txt
===================================================================
--- trunk/phase3/maintenance/parserTests.txt    2010-01-08 07:52:51 UTC (rev 
60831)
+++ trunk/phase3/maintenance/parserTests.txt    2010-01-08 08:22:19 UTC (rev 
60832)
@@ -6929,15 +6929,15 @@
 !! test
 Adding explicit conversion rule for title (T flag)
 !! options
-language=zh variant=zh-tw
+language=zh variant=zh-tw showtitle
 !! input
 Should be stripped-{T|zh:China;zh-tw:Taiwan}-!
 !! result
+Taiwan
 <p>Should be stripped!
 </p>
 !! end
 
-
 !! test
 Raw output of variant escape tags (R flag)
 !! options
@@ -6949,7 +6949,6 @@
 </p>
 !! end
 
-
 !! test
 Do not convert roman numbers to language variants
 !! options
@@ -7515,6 +7514,47 @@
 <a href="/wiki/Main_Page#section" title="Main Page">#section</a>
 !! end
 
+!! test
+Adding explicit conversion rule for title (T flag)
+!! options
+language=zh variant=zh-tw showtitle **** disabled (for now) because I think it 
uncovers a bug and I want a reminder
+!! input
+Should be stripped-{T|zh:China;zh-tw:Taiwan}-!
+!! result
+Taiwan
+<p>Should be stripped!
+</p>
+!! end
+
+!! test
+Adding explicit conversion rule for title (T flag)
+!! options
+language=zh variant=zh showtitle **** disabled (for now) because I think it 
uncovers a bug and I want a reminder
+!! input
+Should be stripped-{T|zh:China;zh-tw:Taiwan}-!
+!! result
+China
+<p>Should be stripped!
+</p>
+!! end
+
+!! test
+Explicit session-wise language variant mapping (A flag and - flag)
+!! options
+language=zh variant=zh **** disabled (for now) because I think it uncovers a 
bug and I want a reminder
+!! input
+Taiwan is not China.
+But -{zh:China;zh-tw:Taiwan}- is China,
+(This-{-|zh:China;zh-tw:Taiwan}- should be stripped!)
+and -{China}- is China.
+!! result
+<p>Taiwan is not China.
+But Taiwan is Taiwan,
+(This should be stripped!)
+and China is China.
+</p>
+!! end
+
 TODO:
 more images
 more tables



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to