X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguageConverter.php;h=78b3572ce86a66e871ab30aba70e4c1b5f1434bf;hb=5a41dcaa6e803dd982266d3ae5e07e7fd0253f84;hp=a6b687cfae8a5040a56fa6f000ae2e0b96609d71;hpb=34ebdaff863ff5da203fb450a9366ae2ed83f163;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index a6b687cfae..78b3572ce8 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -502,13 +502,9 @@ class LanguageConverter { } if ( $action == 'add' ) { + // More efficient than array_merge(), about 2.5 times. foreach ( $pair as $from => $to ) { - // to ensure that $from and $to not be left blank - // so $this->translate() could always return a string - if ( $from || $to ) { - // more efficient than array_merge(), about 2.5 times. - $this->mTables[$variant]->setPair( $from, $to ); - } + $this->mTables[$variant]->setPair( $from, $to ); } } elseif ( $action == 'remove' ) { $this->mTables[$variant]->removeArray( $pair ); @@ -543,27 +539,45 @@ class LanguageConverter { * @return string Namespace name for display */ public function convertNamespace( $index, $variant = null ) { + if ( $index === NS_MAIN ) { + return ''; + } + if ( $variant === null ) { $variant = $this->getPreferredVariant(); } - if ( $index === NS_MAIN ) { - return ''; - } else { - // First check if a message gives a converted name in the target variant. - $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant ); - if ( $nsConvMsg->exists() ) { - return $nsConvMsg->plain(); - } - // Then check if a message gives a converted name in content language - // which needs extra translation to the target variant. + + $cache = ObjectCache::newAccelerator( CACHE_NONE ); + $key = wfMemcKey( 'languageconverter', 'namespace-text', $index, $variant ); + $nsVariantText = $cache->get( $key ); + if ( $nsVariantText !== false ) { + return $nsVariantText; + } + + // First check if a message gives a converted name in the target variant. + $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant ); + if ( $nsConvMsg->exists() ) { + $nsVariantText = $nsConvMsg->plain(); + } + + // Then check if a message gives a converted name in content language + // which needs extra translation to the target variant. + if ( $nsVariantText === false ) { $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage(); if ( $nsConvMsg->exists() ) { - return $this->translate( $nsConvMsg->plain(), $variant ); + $nsVariantText = $this->translate( $nsConvMsg->plain(), $variant ); } + } + + if ( $nsVariantText === false ) { // No message exists, retrieve it from the target variant's namespace names. $langObj = $this->mLangObj->factory( $variant ); - return $langObj->getFormattedNsText( $index ); + $nsVariantText = $langObj->getFormattedNsText( $index ); } + + $cache->set( $key, $nsVariantText, 60 ); + + return $nsVariantText; } /** @@ -996,7 +1010,7 @@ class LanguageConverter { if ( $recursive ) { foreach ( $sublinks as $link ) { $s = $this->parseCachedTable( $code, $link, $recursive ); - $ret = array_merge( $ret, $s ); + $ret = $s + $ret; } } @@ -1096,13 +1110,13 @@ class LanguageConverter { // text should be splited by ";" only if a valid variant // name exist after the markup, for example: // -{zh-hans:xxx;zh-hant:\ - // yyy;}- + // yyy;}- // we should split it as: // array( - // [0] => 'zh-hans:xxx' - // [1] => 'zh-hant:yyy' - // [2] => '' - // ) + // [0] => 'zh-hans:xxx' + // [1] => 'zh-hant:yyy' + // [2] => '' + // ) $pat = '/;\s*(?='; foreach ( $this->mVariants as $variant ) { // zh-hans:xxx;zh-hant:yyy