Merge "Generate Utf8Case.ser directly from UnicodeData.txt"
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index d4c38af..bb5b49f 100644 (file)
@@ -102,8 +102,7 @@ class LanguageConverter {
                        'R' => 'R',       // raw content
                        'D' => 'D',       // convert description (subclass implement)
                        '-' => '-',       // remove convert (not implement)
-                       'H' => 'H',       // add rule for convert code
-                                                 // (but no display in placed code)
+                       'H' => 'H',       // add rule for convert code (but no display in placed code)
                        'N' => 'N'        // current variant name
                );
                $this->mFlags = array_merge( $defaultflags, $flags );
@@ -237,7 +236,8 @@ class LanguageConverter {
                        $ret = $wgRequest->getVal( 'uselang' );
                }
 
-               return $this->mURLVariant = $this->validateVariant( $ret );
+               $this->mURLVariant = $this->validateVariant( $ret );
+               return $this->mURLVariant;
        }
 
        /**
@@ -270,7 +270,8 @@ class LanguageConverter {
                        $ret = $wgUser->getOption( 'language' );
                }
 
-               return $this->mUserVariant = $this->validateVariant( $ret );
+               $this->mUserVariant = $this->validateVariant( $ret );
+               return $this->mUserVariant;
        }
 
        /**
@@ -402,9 +403,9 @@ class LanguageConverter {
                        $startPos = $elementPos + strlen( $element );
 
                        // Translate any alt or title attributes inside the matched element
-                       if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
-                               $elementMatches ) )
-                       {
+                       if ( $element !== ''
+                               && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element, $elementMatches )
+                       {
                                $attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
                                $changed = false;
                                foreach ( array( 'title', 'alt' ) as $attrName ) {
@@ -490,21 +491,6 @@ class LanguageConverter {
                return $ret;
        }
 
-       /**
-        * 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 since 1.17 Use autoConvertToAllVariants() instead
-        */
-       public function convertLinkToAllVariants( $text ) {
-               return $this->autoConvertToAllVariants( $text );
-       }
-
        /**
         * Apply manual conversion rules.
         *
@@ -778,12 +764,12 @@ class LanguageConverter {
                $ns = NS_MAIN;
 
                if ( $disableLinkConversion ||
-                        ( !$ignoreOtherCond &&
-                          ( $isredir == 'no'
-                                || $action == 'edit'
-                                || $action == 'submit'
-                                || $linkconvert == 'no'
-                                || $wgUser->getOption( 'noconvertlink' ) == 1 ) ) ) {
+                       ( !$ignoreOtherCond &&
+                               ( $isredir == 'no'
+                                       || $action == 'edit'
+                                       || $action == 'submit'
+                                       || $linkconvert == 'no'
+                                       || $wgUser->getOption( 'noconvertlink' ) == 1 ) ) ) {
                        return;
                }
 
@@ -876,8 +862,7 @@ class LanguageConverter {
                        $this->mTables = $wgLangConvMemc->get( $this->mCacheKey );
                        wfProfileOut( __METHOD__ . '-cache' );
                }
-               if ( !$this->mTables
-                        || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
+               if ( !$this->mTables || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
                        wfProfileIn( __METHOD__ . '-recache' );
                        // not in cache, or we need a fresh reload.
                        // We will first load the default tables
@@ -1004,8 +989,7 @@ class LanguageConverter {
                                continue;
                        }
                        $mappings = explode( '}-', $block, 2 );
-                       $stripped = str_replace( array( "'", '"', '*', '#' ), '',
-                                                                        $mappings[0] );
+                       $stripped = str_replace( array( "'", '"', '*', '#' ), '', $mappings[0] );
                        $table = StringUtils::explode( ';', $stripped );
                        foreach ( $table as $t ) {
                                $m = explode( '=>', $t, 3 );
@@ -1285,9 +1269,9 @@ class ConverterRule {
                                $from = trim( $u[0] );
                                $v = trim( $u[1] );
                                if ( array_key_exists( $v, $unidtable )
-                                        && !is_array( $unidtable[$v] )
-                                        && $to
-                                        && in_array( $v, $variants ) ) {
+                                       && !is_array( $unidtable[$v] )
+                                       && $to
+                                       && in_array( $v, $variants ) ) {
                                        $unidtable[$v] = array( $from => $to );
                                } elseif ( $to && in_array( $v, $variants ) ) {
                                        $unidtable[$v][$from] = $to;
@@ -1353,8 +1337,7 @@ class ConverterRule {
                                $disp = $disp[0];
                        }
                        // or display frist text under disable manual convert
-                       if ( !$disp
-                                && $this->mConverter->mManualLevel[$variant] == 'disable' ) {
+                       if ( !$disp && $this->mConverter->mManualLevel[$variant] == 'disable' ) {
                                if ( count( $bidtable ) > 0 ) {
                                        $disp = array_values( $bidtable );
                                        $disp = $disp[0];
@@ -1446,8 +1429,8 @@ class ConverterRule {
                        }
                        /* for unidirectional array fill to convert tables */
                        if ( ( $manLevel[$v] == 'bidirectional' || $manLevel[$v] == 'unidirectional' )
-                               && isset( $unidtable[$v] ) )
-                       {
+                               && isset( $unidtable[$v] )
+                       {
                                if ( isset( $this->mConvTable[$v] ) ) {
                                        $this->mConvTable[$v] = array_merge( $this->mConvTable[$v], $unidtable[$v] );
                                } else {
@@ -1477,8 +1460,9 @@ class ConverterRule {
                                // then convert <text to convert> to current language
                                $this->mRules = $this->mConverter->autoConvert( $this->mRules,
                                        $variant );
-                       } else { // if current variant no in flags,
-                                  // then we check its fallback variants.
+                       } else {
+                               // if current variant no in flags,
+                               // then we check its fallback variants.
                                $variantFallbacks =
                                        $this->mConverter->getVariantFallbacks( $variant );
                                if ( is_array( $variantFallbacks ) ) {