Merge "(bug 43467) Add invert selection for ns in Special:Newpages"
[lhc/web/wiklou.git] / languages / Language.php
index 2159052..ffb3268 100644 (file)
@@ -254,7 +254,7 @@ class Language {
         * @since 1.21
         */
        public static function isSupportedLanguage( $code ) {
-               return is_readable( self::getMessagesFileName( $code ) );
+               return $code === strtolower( $code ) && is_readable( self::getMessagesFileName( $code ) );
        }
 
        /**
@@ -361,6 +361,30 @@ class Language {
                return (bool)preg_match( '/^[a-z0-9-]+$/i', $code );
        }
 
+       /**
+        * Returns true if a language code is an IETF tag known to MediaWiki.
+        *
+        * @param $code string
+        *
+        * @since 1.21
+        * @return bool
+        */
+       public static function isKnownLanguageTag( $tag ) {
+               static $coreLanguageNames;
+
+               if ( $coreLanguageNames === null ) {
+                       include( MWInit::compiledPath( 'languages/Names.php' ) );
+               }
+
+               if ( isset( $coreLanguageNames[$tag] )
+                       || self::fetchLanguageName( $tag, $tag ) !== ''
+               ) {
+                       return true;
+               }
+
+               return false;
+       }
+
        /**
         * @param $code
         * @return String Name of the language class
@@ -3043,7 +3067,7 @@ class Language {
                                if ( $start < 0 ) {
                                        $start = 0;
                                }
-                               $groupedNumber = substr( $number , $start, $end -$start ) . $groupedNumber ;
+                               $groupedNumber = substr( $number, $start, $end -$start ) . $groupedNumber ;
                                $end = $start;
                                if ( $numMatches > 1 ) {
                                        // use the last pattern for the rest of the number
@@ -3652,7 +3676,7 @@ class Language {
         * @return bool
         */
        public function hasVariants() {
-               return sizeof( $this->getVariants() ) > 1;
+               return count( $this->getVariants() ) > 1;
        }
 
        /**