Merge "(bug 36908) Language::isValidBuiltInCode passed an object"
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 18 May 2012 21:50:35 +0000 (21:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 18 May 2012 21:50:35 +0000 (21:50 +0000)
1  2 
languages/Language.php

diff --combined languages/Language.php
@@@ -245,6 -245,15 +245,15 @@@ class Language 
         * @return bool
         */
        public static function isValidBuiltInCode( $code ) {
+               if( !is_string($code) ) {
+                       $type = gettype( $code );
+                       if( $type === 'object' ) {
+                               $addmsg = " of class " . get_class( $code );
+                       }
+                       throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" );
+               }
                return preg_match( '/^[a-z0-9-]+$/i', $code );
        }
  
         *              Use null for autonyms (native names)
         * @param $include string:
         *              'all' all available languages
 -       *              'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames
 +       *              'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
         *              'mwfile' only if the language is in 'mw' *and* has a message file
 -       * @return array|bool: language code => language name, false if $include is wrong
 +       * @return array: language code => language name
         * @since 1.20
         */
        public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
                        $returnMw[$coreCode] = $names[$coreCode];
                }
  
 -              if( $include === 'mw' ) {
 -                      return $returnMw;
 -              } elseif( $include === 'mwfile' ) {
 +              if( $include === 'mwfile' ) {
                        $namesMwFile = array();
                        # We do this using a foreach over the codes instead of a directory
                        # loop so that messages files in extensions will work correctly.
                        }
                        return $namesMwFile;
                }
 -              return false;
 +              # 'mw' option; default if it's not one of the other two options (all/mwfile)
 +              return $returnMw;
        }
  
        /**