http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69134
Revision: 69134 Author: philip Date: 2010-07-07 08:59:03 +0000 (Wed, 07 Jul 2010) Log Message: ----------- * Deprecated convertLinkToAllVariants() since the "{" and "}" are not allowed in titles, the text will get all converted always like autoConvertToAllVariants(). * Removed some redundant code. Modified Paths: -------------- trunk/phase3/languages/LanguageConverter.php Modified: trunk/phase3/languages/LanguageConverter.php =================================================================== --- trunk/phase3/languages/LanguageConverter.php 2010-07-07 08:35:25 UTC (rev 69133) +++ trunk/phase3/languages/LanguageConverter.php 2010-07-07 08:59:03 UTC (rev 69134) @@ -318,14 +318,10 @@ * @return String: the converted text */ public function autoConvert( $text, $toVariant = false ) { - $fname = 'LanguageConverter::autoConvert'; + wfProfileIn( __METHOD__ ); - wfProfileIn( $fname ); + $this->loadTables(); - if ( !$this->mTablesLoaded ) { - $this->loadTables(); - } - if ( !$toVariant ) { $toVariant = $this->getPreferredVariant(); if ( !$toVariant ) { @@ -390,7 +386,7 @@ $ret .= array_shift( $notrtext ); $ret .= $t; } - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $ret; } @@ -408,9 +404,7 @@ // If $text is empty or only includes spaces, do nothing // Otherwise translate it if ( trim( $text ) ) { - if ( !$this->mTablesLoaded ) { - $this->loadTables(); - } + $this->loadTables(); $text = $this->mTables[$variant]->replace( $text ); } wfProfileOut( __METHOD__ ); @@ -424,57 +418,31 @@ * @return Array: variant => converted text */ public function autoConvertToAllVariants( $text ) { - $fname = 'LanguageConverter::autoConvertToAllVariants'; - wfProfileIn( $fname ); - if ( !$this->mTablesLoaded ) { - $this->loadTables(); - } + wfProfileIn( __METHOD__ ); + $this->loadTables(); $ret = array(); foreach ( $this->mVariants as $variant ) { $ret[$variant] = $this->translate( $text, $variant ); } - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $ret; } /** - * Convert link text to all supported variants. + * Convert link text to all valid variants. + * In the first, this function only convert text outside the + * "-{" "}-" markups. Since the "{" and "}" are not allowed in + * titles, the text will get all converted always. + * So I removed this feature and deprecated the function. * * @param $text String: the text to be converted * @return Array: variant => converted text + * @deprecated Use autoConvertToAllVariants() instead */ public function convertLinkToAllVariants( $text ) { - if ( !$this->mTablesLoaded ) { - $this->loadTables(); - } - - $ret = array(); - $tarray = StringUtils::explode( '-{', $text ); - $first = true; - - foreach ( $tarray as $txt ) { - if ( $first ) { - $first = false; - foreach ( $this->mVariants as $variant ) { - $ret[$variant] = $this->translate( $txt, $variant ); - } - continue; - } - - $marked = explode( '}-', $txt, 2 ); - - foreach ( $this->mVariants as $variant ) { - $ret[$variant] .= '-{' . $marked[0] . '}-'; - if ( array_key_exists( 1, $marked ) ) { - $ret[$variant] .= $this->translate( $marked[1], $variant ); - } - } - - } - - return $ret; + return $this->autoConvertToAllVariants( $text ); } /** @@ -756,10 +724,10 @@ * @private */ function loadTables( $fromcache = true ) { - global $wgMemc; if ( $this->mTablesLoaded ) { return; } + global $wgMemc; wfProfileIn( __METHOD__ ); $this->mTablesLoaded = true; $this->mTables = false; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs