Convert the string to single quoted and manually escape it.
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index 23c7cb0..64cb4be 100644 (file)
@@ -117,7 +117,7 @@ class LanguageConverter {
         * in this case. Right now this is only used by zh.
         *
         * @param $variant String: the language code of the variant
-        * @return String: The code of the fallback language or the
+        * @return String|array: The code of the fallback language or the
         *                               main code if there is no fallback
         */
        public function getVariantFallbacks( $variant ) {
@@ -158,7 +158,7 @@ class LanguageConverter {
                // not memoized (i.e. there return value is not cached) since
                // new information might appear during processing after this
                // is first called.
-               if ( $req = $this->validateVariant( $req ) ) {
+               if ( $this->validateVariant( $req ) ) {
                        return $req;
                }
                return $this->mMainLanguageCode;
@@ -368,11 +368,11 @@ class LanguageConverter {
                        $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) . "\000";
 
                        // Advance to the next position
-                       $startPos = $elementPos + strlen( $element );           
+                       $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;
@@ -385,7 +385,7 @@ class LanguageConverter {
                                        if ( !strpos( $attr, '://' ) ) {
                                                $attr = $this->translate( $attr, $toVariant );
                                        }
-                                       
+
                                        // Remove HTML tags to avoid disrupting the layout
                                        $attr = preg_replace( '/<[^>]+>/', '', $attr );
                                        if ( $attr !== $attrs[$attrName] ) {
@@ -394,7 +394,7 @@ class LanguageConverter {
                                        }
                                }
                                if ( $changed ) {
-                                       $element = $elementMatches[1] . Html::expandAttributes( $attrs ) . 
+                                       $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
                                                $elementMatches[3];
                                }
                        }
@@ -1364,19 +1364,21 @@ class ConverterRule {
                        if ( isset( $this->mVariantFlags[$variant] ) ) {
                                // then convert <text to convert> to current language
                                $this->mRules = $this->mConverter->autoConvert( $this->mRules,
-                                                                                                                               $variant );
+                                       $variant );
                        } else { // if current variant no in flags,
                                   // then we check its fallback variants.
                                $variantFallbacks =
                                        $this->mConverter->getVariantFallbacks( $variant );
-                               foreach ( $variantFallbacks as $variantFallback ) {
-                                       // if current variant's fallback exist in flags
-                                       if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
-                                               // then convert <text to convert> to fallback language
-                                               $this->mRules =
-                                                       $this->mConverter->autoConvert( $this->mRules,
-                                                                                                                       $variantFallback );
-                                               break;
+                               if( is_array( $variantFallbacks ) ) {
+                                       foreach ( $variantFallbacks as $variantFallback ) {
+                                               // if current variant's fallback exist in flags
+                                               if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
+                                                       // then convert <text to convert> to fallback language
+                                                       $this->mRules =
+                                                               $this->mConverter->autoConvert( $this->mRules,
+                                                                       $variantFallback );
+                                                       break;
+                                               }
                                        }
                                }
                        }