r69146 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69145‎ | r69146 | r69147 >
Date:14:46, 7 July 2010
Author:philip
Status:ok (Comments)
Tags:
Comment:
Continue to clean up the LanguageConverter.php.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -69,7 +69,7 @@
7070 'D' => 'D', // convert description (subclass implement)
7171 '-' => '-', // remove convert (not implement)
7272 'H' => 'H', // add rule for convert code
73 - // (but no display in placed code )
 73+ // (but no display in placed code )
7474 'N' => 'N' // current variant name
7575 );
7676 $this->mFlags = array_merge( $defaultflags, $flags );
@@ -102,7 +102,7 @@
103103 *
104104 * @param $variant String: the language code of the variant
105105 * @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
107107 */
108108 public function getVariantFallbacks( $variant ) {
109109 if ( isset( $this->mVariantFallbacks[$variant] ) ) {
@@ -446,20 +446,22 @@
447447 }
448448
449449 /**
450 - * Prepare manual conversion table.
451 - * @private
 450+ * Apply manual conversion rules.
 451+ *
 452+ * @param $convRule Object: Object of ConverterRule
452453 */
453 - function applyManualConv( $convRule ) {
 454+ protected function applyManualConv( $convRule ) {
454455 // Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom
455456 // 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.
458459 $newConvRuleTitle = $convRule->getTitle();
459460 if( $newConvRuleTitle ) {
 461+ // So I add an empty check for getTitle()
460462 $this->mConvRuleTitle = $newConvRuleTitle;
461463 }
462464
463 - // apply manual conversion table to global table
 465+ // merge/remove manual conversion rules to/from global table
464466 $convTable = $convRule->getConvTable();
465467 $action = $convRule->getRulesAction();
466468 foreach ( $convTable as $variant => $pair ) {
@@ -483,31 +485,12 @@
484486 }
485487
486488 /**
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.
491491 *
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
499494 */
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 - */
512495 public function convertTitle( $title ) {
513496 $variant = $this->getPreferredVariant();
514497 $index = $title->getNamespace();
@@ -527,10 +510,51 @@
528511 $text .= ':';
529512 }
530513 $text .= $title->getText();
531 - $text = $this->autoConvert( $text, $variant );
 514+ $text = $this->translate( $text, $variant );
532515 return $text;
533516 }
534517
 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+ */
535559 protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
536560 $startPos = 0;
537561 $out = '';
@@ -560,6 +584,14 @@
561585 return $out;
562586 }
563587
 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+ */
564596 protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
565597 // Quick sanity check (no function calls)
566598 if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
@@ -636,7 +668,7 @@
637669 * @param $link String: the name of the link
638670 * @param $nt Mixed: the title object of the link
639671 * @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
641673 * @return Null, the input parameters may be modified upon return
642674 */
643675 public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
@@ -700,7 +732,7 @@
701733 }
702734 }
703735
704 - /**
 736+ /**
705737 * Returns language specific hash options.
706738 */
707739 public function getExtraHashOptions() {
@@ -757,13 +789,13 @@
758790 wfProfileOut( __METHOD__ );
759791 }
760792
761 - /**
 793+ /**
762794 * Hook for post processig after conversion tables are loaded.
763795 *
764796 */
765797 function postLoadTables() { }
766798
767 - /**
 799+ /**
768800 * Reload the conversion tables.
769801 *
770802 * @private
@@ -960,7 +992,7 @@
961993 // text should be splited by ";" only if a valid variant
962994 // name exist after the markup, for example:
963995 // -{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>;}-
965997 // we should split it as:
966998 // array(
967999 // [0] => 'zh-hans:<span style="font-size:120%;">xxx</span>'
@@ -1121,7 +1153,7 @@
11221154 $bidtable[$v] = $to;
11231155 } elseif ( count( $u ) == 2 ) {
11241156 $from = trim( $u[0] );
1125 - $v = trim( $u[1] );
 1157+ $v = trim( $u[1] );
11261158 if ( array_key_exists( $v, $unidtable )
11271159 && !is_array( $unidtable[$v] )
11281160 && $to

Comments

#Comment by 😂 (talk | contribs)   18:23, 7 July 2010

Please use descriptive commit summaries.

Status & tagging log