Merge "Update formatting"
[lhc/web/wiklou.git] / languages / Language.php
index 2038bac..320688a 100644 (file)
@@ -62,7 +62,6 @@ class FakeConverter {
        function getParsedTitle() { return ''; }
        function markNoConversion( $text, $noParse = false ) { return $text; }
        function convertCategoryKey( $key ) { return $key; }
-       function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); }
        /** @deprecated since 1.22 is no longer used */
        function armourMath( $text ) { return $text; }
        function validateVariant( $variant = null ) { return $variant === $this->mLang->getCode() ? $variant : null; }
@@ -213,8 +212,8 @@ class Language {
        protected static function newFromCode( $code ) {
                // Protect against path traversal below
                if ( !Language::isValidCode( $code )
-                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
-               {
+                       || strcspn( $code, ":/\\\000" ) !== strlen( $code )
+               {
                        throw new MWException( "Invalid language code \"$code\"" );
                }
 
@@ -929,6 +928,7 @@ class Language {
         * @since 1.20
         */
        public static function fetchLanguageName( $code, $inLanguage = null, $include = 'all' ) {
+               $code = strtolower( $code );
                $array = self::fetchLanguageNames( $inLanguage, $include );
                return !array_key_exists( $code, $array ) ? '' : $array[$code];
        }
@@ -1502,8 +1502,7 @@ class Language {
                if (
                        ( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
                        ( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
-               )
-               {
+               ) {
                        $zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
                                        (int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) -
                                        (int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) +
@@ -1753,8 +1752,7 @@ class Language {
                                ( ( $gy > 1912 ) && ( $gy < 1926 ) ) ||
                                ( ( $gy == 1926 ) && ( $gm < 12 ) ) ||
                                ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) )
-                       )
-                       {
+                       ) {
                                # Taishō period
                                $gy_gannen = $gy - 1912 + 1;
                                $gy_offset = $gy_gannen;
@@ -1766,8 +1764,7 @@ class Language {
                                ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) ||
                                ( ( $gy > 1926 ) && ( $gy < 1989 ) ) ||
                                ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) )
-                       )
-                       {
+                       ) {
                                # Shōwa period
                                $gy_gannen = $gy - 1926 + 1;
                                $gy_offset = $gy_gannen;
@@ -3635,17 +3632,10 @@ class Language {
         */
        function convertPlural( $count, $forms ) {
                // Handle explicit n=pluralform cases
-               foreach ( $forms as $index => $form ) {
-                       if ( preg_match( '/^\d+=/i', $form ) ) {
-                               $pos = strpos( $form, '=' );
-                               if ( substr( $form, 0, $pos ) === (string)$count ) {
-                                       return substr( $form, $pos + 1 );
-                               }
-                               unset( $forms[$index] );
-                       }
+               $forms = $this->handleExplicitPluralForms( $count, $forms );
+               if ( is_string( $forms ) ) {
+                       return $forms;
                }
-
-               $forms = array_values( $forms );
                if ( !count( $forms ) ) {
                        return '';
                }
@@ -3655,6 +3645,34 @@ class Language {
                return $forms[$pluralForm];
        }
 
+       /**
+        * Handles explicit plural forms for Language::convertPlural()
+        *
+        * In {{PLURAL:$1|0=nothing|one|many}}, 0=nothing will be returned if $1 equals zero.
+        * If an explicitly defined plural form matches the $count, then
+        * string value returned, otherwise array returned for further consideration
+        * by CLDR rules or overridden convertPlural().
+        *
+        * @since 1.23
+        *
+        * @param int $count non-localized number
+        * @param array $forms different plural forms
+        *
+        * @return array|string
+        */
+       protected function handleExplicitPluralForms( $count, array $forms ) {
+               foreach ( $forms as $index => $form ) {
+                       if ( preg_match( '/\d+=/i', $form ) ) {
+                               $pos = strpos( $form, '=' );
+                               if ( substr( $form, 0, $pos ) === (string) $count ) {
+                                       return substr( $form, $pos + 1 );
+                               }
+                               unset( $forms[$index] );
+                       }
+               }
+               return array_values( $forms );
+       }
+
        /**
         * Checks that convertPlural was given an array and pads it to requested
         * amount of forms by copying the last one.
@@ -3886,21 +3904,6 @@ class Language {
                $this->mConverter->findVariantLink( $link, $nt, $ignoreOtherCond );
        }
 
-       /**
-        * If a language supports multiple variants, converts text
-        * into an array of all possible variants of the text:
-        *  'variant' => text in that variant
-        *
-        * @deprecated since 1.17 Use autoConvertToAllVariants()
-        *
-        * @param $text string
-        *
-        * @return string
-        */
-       public function convertLinkToAllVariants( $text ) {
-               return $this->mConverter->convertLinkToAllVariants( $text );
-       }
-
        /**
         * returns language specific options used by User::getPageRenderHash()
         * for example, the preferred language variant
@@ -4048,8 +4051,8 @@ class Language {
        public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
                // Protect against path traversal
                if ( !Language::isValidCode( $code )
-                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
-               {
+                       || strcspn( $code, ":/\\\000" ) !== strlen( $code )
+               {
                        throw new MWException( "Invalid language code \"$code\"" );
                }