Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | 'D' => 'D', // convert description (subclass implement) |
71 | 71 | '-' => '-', // remove convert (not implement) |
72 | 72 | 'H' => 'H', // add rule for convert code |
73 | | - // (but no display in placed code ) |
| 73 | + // (but no display in placed code ) |
74 | 74 | 'N' => 'N' // current variant name |
75 | 75 | ); |
76 | 76 | $this->mFlags = array_merge( $defaultflags, $flags ); |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | * |
104 | 104 | * @param $variant String: the language code of the variant |
105 | 105 | * @return String: The code of the fallback language or the |
106 | | - * main code if there is no fallback |
| 106 | + * main code if there is no fallback |
107 | 107 | */ |
108 | 108 | public function getVariantFallbacks( $variant ) { |
109 | 109 | if ( isset( $this->mVariantFallbacks[$variant] ) ) { |
— | — | @@ -446,20 +446,22 @@ |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | | - * Prepare manual conversion table. |
451 | | - * @private |
| 450 | + * Apply manual conversion rules. |
| 451 | + * |
| 452 | + * @param $convRule Object: Object of ConverterRule |
452 | 453 | */ |
453 | | - function applyManualConv( $convRule ) { |
| 454 | + protected function applyManualConv( $convRule ) { |
454 | 455 | // Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom |
455 | 456 | // title conversion. |
456 | | - // Bug 24072: mConvRuleTitle won't work if the title conversion |
457 | | - // rule was followed by other manual conversion rule(s). |
| 457 | + // Bug 24072: $mConvRuleTitle was overwritten by other manual |
| 458 | + // rule(s) not for title, this breaks the title conversion. |
458 | 459 | $newConvRuleTitle = $convRule->getTitle(); |
459 | 460 | if( $newConvRuleTitle ) { |
| 461 | + // So I add an empty check for getTitle() |
460 | 462 | $this->mConvRuleTitle = $newConvRuleTitle; |
461 | 463 | } |
462 | 464 | |
463 | | - // apply manual conversion table to global table |
| 465 | + // merge/remove manual conversion rules to/from global table |
464 | 466 | $convTable = $convRule->getConvTable(); |
465 | 467 | $action = $convRule->getRulesAction(); |
466 | 468 | foreach ( $convTable as $variant => $pair ) { |
— | — | @@ -483,31 +485,12 @@ |
484 | 486 | } |
485 | 487 | |
486 | 488 | /** |
487 | | - * Convert text to different variants of a language. The automatic |
488 | | - * conversion is done in autoConvert(). Here we parse the text |
489 | | - * marked with -{}-, which specifies special conversions of the |
490 | | - * text that can not be accomplished in autoConvert(). |
| 489 | + * Auto convert a Title object to a readable string in the |
| 490 | + * preferred variant. |
491 | 491 | * |
492 | | - * Syntax of the markup: |
493 | | - * -{code1:text1;code2:text2;...}- or |
494 | | - * -{flags|code1:text1;code2:text2;...}- or |
495 | | - * -{text}- in which case no conversion should take place for text |
496 | | - * |
497 | | - * @param $text String: text to be converted |
498 | | - * @return String: converted text |
| 492 | + *@param $title Object: a object of Title |
| 493 | + *@return String: converted title text |
499 | 494 | */ |
500 | | - public function convert( $text ) { |
501 | | - global $wgDisableLangConversion; |
502 | | - if ( $wgDisableLangConversion ) return $text; |
503 | | - |
504 | | - $variant = $this->getPreferredVariant(); |
505 | | - |
506 | | - return $this->recursiveConvertTopLevel( $text, $variant ); |
507 | | - } |
508 | | - |
509 | | - /** |
510 | | - * Convert a Title object to a readable string in the preferred variant |
511 | | - */ |
512 | 495 | public function convertTitle( $title ) { |
513 | 496 | $variant = $this->getPreferredVariant(); |
514 | 497 | $index = $title->getNamespace(); |
— | — | @@ -527,10 +510,51 @@ |
528 | 511 | $text .= ':'; |
529 | 512 | } |
530 | 513 | $text .= $title->getText(); |
531 | | - $text = $this->autoConvert( $text, $variant ); |
| 514 | + $text = $this->translate( $text, $variant ); |
532 | 515 | return $text; |
533 | 516 | } |
534 | 517 | |
| 518 | + /** |
| 519 | + * Convert text to different variants of a language. The automatic |
| 520 | + * conversion is done in autoConvert(). Here we parse the text |
| 521 | + * marked with -{}-, which specifies special conversions of the |
| 522 | + * text that can not be accomplished in autoConvert(). |
| 523 | + * |
| 524 | + * Syntax of the markup: |
| 525 | + * -{code1:text1;code2:text2;...}- or |
| 526 | + * -{flags|code1:text1;code2:text2;...}- or |
| 527 | + * -{text}- in which case no conversion should take place for text |
| 528 | + * |
| 529 | + * @param $text String: text to be converted |
| 530 | + * @return String: converted text |
| 531 | + */ |
| 532 | + public function convert( $text ) { |
| 533 | + $variant = $this->getPreferredVariant(); |
| 534 | + return $this->convertTo( $text, $variant ); |
| 535 | + } |
| 536 | + |
| 537 | + /** |
| 538 | + * Same as convert() except a extra parameter to custom variant. |
| 539 | + * |
| 540 | + * @param $text String: text to be converted |
| 541 | + * @param $variant String: the target variant code |
| 542 | + * @return String: converted text |
| 543 | + */ |
| 544 | + public function convertTo( $text, $variant ) { |
| 545 | + global $wgDisableLangConversion; |
| 546 | + if ( $wgDisableLangConversion ) return $text; |
| 547 | + return $this->recursiveConvertTopLevel( $text, $variant ); |
| 548 | + } |
| 549 | + |
| 550 | + /** |
| 551 | + * Recursively convert text on the outside. Allow to use nested |
| 552 | + * markups to custom rules. |
| 553 | + * |
| 554 | + * @param $text String: text to be converted |
| 555 | + * @param $variant String: the target variant code |
| 556 | + * @param $depth Integer: depth of recursion |
| 557 | + * @return String: converted text |
| 558 | + */ |
535 | 559 | protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) { |
536 | 560 | $startPos = 0; |
537 | 561 | $out = ''; |
— | — | @@ -560,6 +584,14 @@ |
561 | 585 | return $out; |
562 | 586 | } |
563 | 587 | |
| 588 | + /** |
| 589 | + * Recursively convert text on the inside. |
| 590 | + * |
| 591 | + * @param $text String: text to be converted |
| 592 | + * @param $variant String: the target variant code |
| 593 | + * @param $depth Integer: depth of recursion |
| 594 | + * @return String: converted text |
| 595 | + */ |
564 | 596 | protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) { |
565 | 597 | // Quick sanity check (no function calls) |
566 | 598 | if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) { |
— | — | @@ -636,7 +668,7 @@ |
637 | 669 | * @param $link String: the name of the link |
638 | 670 | * @param $nt Mixed: the title object of the link |
639 | 671 | * @param $ignoreOtherCond Boolean: to disable other conditions when |
640 | | - * we need to transclude a template or update a category's link |
| 672 | + * we need to transclude a template or update a category's link |
641 | 673 | * @return Null, the input parameters may be modified upon return |
642 | 674 | */ |
643 | 675 | public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) { |
— | — | @@ -700,7 +732,7 @@ |
701 | 733 | } |
702 | 734 | } |
703 | 735 | |
704 | | - /** |
| 736 | + /** |
705 | 737 | * Returns language specific hash options. |
706 | 738 | */ |
707 | 739 | public function getExtraHashOptions() { |
— | — | @@ -757,13 +789,13 @@ |
758 | 790 | wfProfileOut( __METHOD__ ); |
759 | 791 | } |
760 | 792 | |
761 | | - /** |
| 793 | + /** |
762 | 794 | * Hook for post processig after conversion tables are loaded. |
763 | 795 | * |
764 | 796 | */ |
765 | 797 | function postLoadTables() { } |
766 | 798 | |
767 | | - /** |
| 799 | + /** |
768 | 800 | * Reload the conversion tables. |
769 | 801 | * |
770 | 802 | * @private |
— | — | @@ -960,7 +992,7 @@ |
961 | 993 | // text should be splited by ";" only if a valid variant |
962 | 994 | // name exist after the markup, for example: |
963 | 995 | // -{zh-hans:<span style="font-size:120%;">xxx</span>;zh-hant:\ |
964 | | - // <span style="font-size:120%;">yyy</span>;}- |
| 996 | + // <span style="font-size:120%;">yyy</span>;}- |
965 | 997 | // we should split it as: |
966 | 998 | // array( |
967 | 999 | // [0] => 'zh-hans:<span style="font-size:120%;">xxx</span>' |
— | — | @@ -1121,7 +1153,7 @@ |
1122 | 1154 | $bidtable[$v] = $to; |
1123 | 1155 | } elseif ( count( $u ) == 2 ) { |
1124 | 1156 | $from = trim( $u[0] ); |
1125 | | - $v = trim( $u[1] ); |
| 1157 | + $v = trim( $u[1] ); |
1126 | 1158 | if ( array_key_exists( $v, $unidtable ) |
1127 | 1159 | && !is_array( $unidtable[$v] ) |
1128 | 1160 | && $to |