mw.language: Document ability to set multiple values at once.
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index 0aaa931..18d1dbc 100644 (file)
@@ -72,7 +72,7 @@ class LanguageConverter {
                $this->mMainLanguageCode = $maincode;
                $this->mVariants = array_diff( $variants, $wgDisabledVariants );
                $this->mVariantFallbacks = $variantfallbacks;
-               $this->mVariantNames = Language::getLanguageNames();
+               $this->mVariantNames = Language::fetchLanguageNames();
                $this->mCacheKey = wfMemcKey( 'conversiontables', $maincode );
                $defaultflags = array(
                        // 'S' show converted text
@@ -576,7 +576,7 @@ class LanguageConverter {
         */
        public function convertTo( $text, $variant ) {
                global $wgDisableLangConversion;
-               if ( $wgDisableLangConversion || $this->guessVariant( $text, $variant ) ) {
+               if ( $wgDisableLangConversion ) {
                        return $text;
                }
                return $this->recursiveConvertTopLevel( $text, $variant );
@@ -595,18 +595,22 @@ class LanguageConverter {
                $startPos = 0;
                $out = '';
                $length = strlen( $text );
+               $shouldConvert = !$this->guessVariant( $text, $variant );
+
                while ( $startPos < $length ) {
                        $pos = strpos( $text, '-{', $startPos );
 
                        if ( $pos === false ) {
                                // No more markup, append final segment
-                               $out .= $this->autoConvert( substr( $text, $startPos ), $variant );
+                               $fragment = substr( $text, $startPos );
+                               $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
                                return $out;
                        }
 
                        // Markup found
                        // Append initial segment
-                       $out .= $this->autoConvert( substr( $text, $startPos, $pos - $startPos ), $variant );
+                       $fragment = substr( $text, $startPos, $pos - $startPos );
+                       $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
 
                        // Advance position
                        $startPos = $pos;
@@ -626,6 +630,7 @@ class LanguageConverter {
         * @param $startPos int
         * @param $depth Integer: depth of recursion
         *
+        * @throws MWException
         * @return String: converted text
         */
        protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
@@ -796,6 +801,7 @@ class LanguageConverter {
         * This method must be implemented in derived class.
         *
         * @private
+        * @throws MWException
         */
        function loadDefaultTables() {
                $name = get_class( $this );
@@ -808,16 +814,18 @@ class LanguageConverter {
         * @param $fromCache Boolean: load from memcached? Defaults to true.
         */
        function loadTables( $fromCache = true ) {
+               global $wgLangConvMemc;
+
                if ( $this->mTablesLoaded ) {
                        return;
                }
-               global $wgMemc;
+
                wfProfileIn( __METHOD__ );
                $this->mTablesLoaded = true;
                $this->mTables = false;
                if ( $fromCache ) {
                        wfProfileIn( __METHOD__ . '-cache' );
-                       $this->mTables = $wgMemc->get( $this->mCacheKey );
+                       $this->mTables = $wgLangConvMemc->get( $this->mCacheKey );
                        wfProfileOut( __METHOD__ . '-cache' );
                }
                if ( !$this->mTables
@@ -835,7 +843,7 @@ class LanguageConverter {
                        $this->postLoadTables();
                        $this->mTables[self::CACHE_VERSION_KEY] = true;
 
-                       $wgMemc->set( $this->mCacheKey, $this->mTables, 43200 );
+                       $wgLangConvMemc->set( $this->mCacheKey, $this->mTables, 43200 );
                        wfProfileOut( __METHOD__ . '-recache' );
                }
                wfProfileOut( __METHOD__ );