Index: trunk/phase3/maintenance/parserTests.inc |
— | — | @@ -493,6 +493,10 @@ |
494 | 494 | $result = $this->tidy($result); |
495 | 495 | } |
496 | 496 | |
| 497 | + if ( isset( $opts['showtitle'] ) ) { |
| 498 | + $out = $parser->mTitle . "\n$out"; |
| 499 | + } |
| 500 | + |
497 | 501 | $this->teardownGlobals(); |
498 | 502 | |
499 | 503 | if( $result === $out && ( $noxml === true || $this->wellFormed( $out ) ) ) { |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -6929,15 +6929,15 @@ |
6930 | 6930 | !! test |
6931 | 6931 | Adding explicit conversion rule for title (T flag) |
6932 | 6932 | !! options |
6933 | | -language=zh variant=zh-tw |
| 6933 | +language=zh variant=zh-tw showtitle |
6934 | 6934 | !! input |
6935 | 6935 | Should be stripped-{T|zh:China;zh-tw:Taiwan}-! |
6936 | 6936 | !! result |
| 6937 | +Taiwan |
6937 | 6938 | <p>Should be stripped! |
6938 | 6939 | </p> |
6939 | 6940 | !! end |
6940 | 6941 | |
6941 | | - |
6942 | 6942 | !! test |
6943 | 6943 | Raw output of variant escape tags (R flag) |
6944 | 6944 | !! options |
— | — | @@ -6949,7 +6949,6 @@ |
6950 | 6950 | </p> |
6951 | 6951 | !! end |
6952 | 6952 | |
6953 | | - |
6954 | 6953 | !! test |
6955 | 6954 | Do not convert roman numbers to language variants |
6956 | 6955 | !! options |
— | — | @@ -7515,6 +7514,47 @@ |
7516 | 7515 | <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a> |
7517 | 7516 | !! end |
7518 | 7517 | |
| 7518 | +!! test |
| 7519 | +Adding explicit conversion rule for title (T flag) |
| 7520 | +!! options |
| 7521 | +language=zh variant=zh-tw showtitle **** disabled (for now) because I think it uncovers a bug and I want a reminder |
| 7522 | +!! input |
| 7523 | +Should be stripped-{T|zh:China;zh-tw:Taiwan}-! |
| 7524 | +!! result |
| 7525 | +Taiwan |
| 7526 | +<p>Should be stripped! |
| 7527 | +</p> |
| 7528 | +!! end |
| 7529 | + |
| 7530 | +!! test |
| 7531 | +Adding explicit conversion rule for title (T flag) |
| 7532 | +!! options |
| 7533 | +language=zh variant=zh showtitle **** disabled (for now) because I think it uncovers a bug and I want a reminder |
| 7534 | +!! input |
| 7535 | +Should be stripped-{T|zh:China;zh-tw:Taiwan}-! |
| 7536 | +!! result |
| 7537 | +China |
| 7538 | +<p>Should be stripped! |
| 7539 | +</p> |
| 7540 | +!! end |
| 7541 | + |
| 7542 | +!! test |
| 7543 | +Explicit session-wise language variant mapping (A flag and - flag) |
| 7544 | +!! options |
| 7545 | +language=zh variant=zh **** disabled (for now) because I think it uncovers a bug and I want a reminder |
| 7546 | +!! input |
| 7547 | +Taiwan is not China. |
| 7548 | +But -{zh:China;zh-tw:Taiwan}- is China, |
| 7549 | +(This-{-|zh:China;zh-tw:Taiwan}- should be stripped!) |
| 7550 | +and -{China}- is China. |
| 7551 | +!! result |
| 7552 | +<p>Taiwan is not China. |
| 7553 | +But Taiwan is Taiwan, |
| 7554 | +(This should be stripped!) |
| 7555 | +and China is China. |
| 7556 | +</p> |
| 7557 | +!! end |
| 7558 | + |
7519 | 7559 | TODO: |
7520 | 7560 | more images |
7521 | 7561 | more tables |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -261,6 +261,12 @@ |
262 | 262 | if ( !$t || $t instanceof FakeTitle ) { |
263 | 263 | $t = Title::newFromText( 'NO TITLE' ); |
264 | 264 | } |
| 265 | + // If we still don't have a Title object, make sure we can |
| 266 | + // convert whatever we've been passed to a string. |
| 267 | + if ( !$t instanceOf Title && is_string( "$t" ) ) { |
| 268 | + $t = Title::newFromText( "$t" ); |
| 269 | + } |
| 270 | + |
265 | 271 | if ( strval( $t->getFragment() ) !== '' ) { |
266 | 272 | # Strip the fragment to avoid various odd effects |
267 | 273 | $this->mTitle = clone $t; |
— | — | @@ -329,14 +335,6 @@ |
330 | 336 | # No more strip! |
331 | 337 | wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); |
332 | 338 | $text = $this->internalParse( $text ); |
333 | | - // internalParse took care of the notitleconvert bit, so title conversion is here. |
334 | | - if ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable()) { |
335 | | - $converted = $wgContLang->convert( $title ); |
336 | | - if ( !$converted instanceOf Title ) { |
337 | | - $converted = Title::newFromText( $converted ); |
338 | | - } |
339 | | - $this->setTitle( $converted ); |
340 | | - } |
341 | 339 | |
342 | 340 | $text = $this->mStripState->unstripGeneral( $text ); |
343 | 341 | |
— | — | @@ -355,13 +353,23 @@ |
356 | 354 | |
357 | 355 | $this->replaceLinkHolders( $text ); |
358 | 356 | |
359 | | - # the position of the convert() call should not be changed. it |
360 | | - # assumes that the links are all replaced and the only thing left |
361 | | - # is the <nowiki> mark. |
| 357 | + // The position of the convert() call should not be changed. it |
| 358 | + // assumes that the links are all replaced and the only thing left |
| 359 | + // is the <nowiki> mark. |
362 | 360 | if ( $this->mDoContentConvert && !$this->mTitle->isConversionTable()) { |
363 | 361 | $text = $wgContLang->convert( $text ); |
364 | 362 | } |
365 | 363 | |
| 364 | + // A title may have been set in a conversion rule. |
| 365 | + // Note that if a user tries to set a title in a conversion |
| 366 | + // rule but content conversion was not done, then the parser |
| 367 | + // won't pick it up. This is probably expected behavior. |
| 368 | + if ( $wgContLang->getConvRuleTitle() ) { |
| 369 | + $this->setTitle( $wgContLang->getConvRuleTitle() ); |
| 370 | + } elseif ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable() ) { |
| 371 | + $this->setTitle( $wgContLang->convert( $title ) ); |
| 372 | + } |
| 373 | + |
366 | 374 | $text = $this->mStripState->unstripNoWiki( $text ); |
367 | 375 | |
368 | 376 | wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) ); |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | var $mDescCodeSep = ':', $mDescVarSep = ';'; |
33 | 33 | var $mUcfirst = false; |
34 | 34 | var $mHeaderVariant; |
| 35 | + var $mConvRuleTitle = false; |
35 | 36 | |
36 | 37 | const CACHE_VERSION_KEY = 'VERSION 6'; |
37 | 38 | |
— | — | @@ -459,8 +460,8 @@ |
460 | 461 | */ |
461 | 462 | function applyManualConv( $convRule ) { |
462 | 463 | // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom |
463 | | - // conversion in title |
464 | | - $title = $convRule->getTitle(); |
| 464 | + // conversion in title |
| 465 | + $this->mConvRuleTitle = $convRule->getTitle(); |
465 | 466 | |
466 | 467 | // apply manual conversion table to global table |
467 | 468 | $convTable = $convRule->getConvTable(); |
— | — | @@ -544,7 +545,7 @@ |
545 | 546 | * @return string converted text |
546 | 547 | * @public |
547 | 548 | */ |
548 | | - function convert( $text, $isTitle ) { |
| 549 | + function convert( $text ) { |
549 | 550 | global $wgDisableLangConversion; |
550 | 551 | if ( $wgDisableLangConversion ) return $text; |
551 | 552 | |
— | — | @@ -558,10 +559,6 @@ |
559 | 560 | |
560 | 561 | // Remove the last delimiter (wasn't real) |
561 | 562 | $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) ); |
562 | | - if ( $isTitle ) { |
563 | | - error_log("title2: $converted\n"); |
564 | | - $this->mConvertedTitle = $converted; |
565 | | - } |
566 | 563 | return $converted; |
567 | 564 | } |
568 | 565 | |
— | — | @@ -1110,13 +1107,13 @@ |
1111 | 1108 | * Parse rules conversion. |
1112 | 1109 | * @private |
1113 | 1110 | */ |
1114 | | - function getRuleConvertedStr( $variant, $doConvert ) { |
| 1111 | + function getRuleConvertedStr( $variant ) { |
1115 | 1112 | $bidtable = $this->mBidtable; |
1116 | 1113 | $unidtable = $this->mUnidtable; |
1117 | 1114 | |
1118 | 1115 | if ( count( $bidtable ) + count( $unidtable ) == 0 ) { |
1119 | 1116 | return $this->mRules; |
1120 | | - } elseif ( $doConvert ) { // the text converted |
| 1117 | + } else { |
1121 | 1118 | // display current variant in bidirectional array |
1122 | 1119 | $disp = $this->getTextInBidtable( $variant ); |
1123 | 1120 | // or display current variant in fallbacks |
— | — | @@ -1142,8 +1139,6 @@ |
1143 | 1140 | } |
1144 | 1141 | } |
1145 | 1142 | return $disp; |
1146 | | - } else { // no convert |
1147 | | - return $this->mRules; |
1148 | 1143 | } |
1149 | 1144 | } |
1150 | 1145 | |
— | — | @@ -1271,15 +1266,13 @@ |
1272 | 1267 | // proces H,- flag or T only: output nothing |
1273 | 1268 | $this->mRuleDisplay = ''; |
1274 | 1269 | } elseif ( in_array( 'S', $flags ) ) { |
1275 | | - // true hard-coded now since we shouldn't be called if we're not converting |
1276 | | - $this->mRuleDisplay = $this->getRuleConvertedStr( $variant, true ); |
| 1270 | + $this->mRuleDisplay = $this->getRuleConvertedStr( $variant ); |
1277 | 1271 | } else { |
1278 | 1272 | $this->mRuleDisplay = $this->mManualCodeError; |
1279 | 1273 | } |
1280 | 1274 | // process T flag |
1281 | 1275 | if ( in_array( 'T', $flags ) ) { |
1282 | | - // true hard-coded now since we shouldn't be called if we're not converting |
1283 | | - $this->mRuleTitle = $this->getRuleConvertedStr( $variant, true ); |
| 1276 | + $this->mRuleTitle = $this->getRuleConvertedStr( $variant ); |
1284 | 1277 | } |
1285 | 1278 | |
1286 | 1279 | if ( in_array( '-', $flags ) ) { |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -34,11 +34,12 @@ |
35 | 35 | */ |
36 | 36 | class FakeConverter { |
37 | 37 | var $mLang; |
| 38 | + var $mConvRuleTitle; |
38 | 39 | function FakeConverter($langobj) {$this->mLang = $langobj;} |
39 | 40 | function autoConvertToAllVariants($text) {return $text;} |
40 | 41 | function convert($t, $i) {return $t;} |
41 | 42 | function getVariants() { return array( $this->mLang->getCode() ); } |
42 | | - function getPreferredVariant() {return $this->mLang->getCode(); } |
| 43 | + function getPreferredVariant() { return $this->mLang->getCode(); } |
43 | 44 | function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {} |
44 | 45 | function getExtraHashOptions() {return '';} |
45 | 46 | function getParsedTitle() {return '';} |
— | — | @@ -2664,4 +2665,11 @@ |
2665 | 2666 | $text = $this->getMessageFromDB( $msg ); |
2666 | 2667 | return str_replace( '$1', $this->formatNum( $size ), $text ); |
2667 | 2668 | } |
| 2669 | + |
| 2670 | + /** |
| 2671 | + * Get the conversion rule title, if any. |
| 2672 | + */ |
| 2673 | + function getConvRuleTitle() { |
| 2674 | + return $this->mConverter->mConvRuleTitle; |
| 2675 | + } |
2668 | 2676 | } |