Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / languages / Language.php
index db302d7..9d2bdb2 100644 (file)
@@ -188,9 +188,7 @@ class Language {
                }
 
                // get the language object to process
-               $langObj = isset( self::$mLangObjCache[$code] )
-                       ? self::$mLangObjCache[$code]
-                       : self::newFromCode( $code );
+               $langObj = self::$mLangObjCache[$code] ?? self::newFromCode( $code );
 
                // merge the language object in to get it up front in the cache
                self::$mLangObjCache = array_merge( [ $code => $langObj ], self::$mLangObjCache );
@@ -542,7 +540,7 @@ class Language {
         */
        public function getNsText( $index ) {
                $ns = $this->getNamespaces();
-               return isset( $ns[$index] ) ? $ns[$index] : false;
+               return $ns[$index] ?? false;
        }
 
        /**
@@ -577,7 +575,7 @@ class Language {
                $ns = $wgExtraGenderNamespaces +
                        (array)self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' );
 
-               return isset( $ns[$index][$gender] ) ? $ns[$index][$gender] : $this->getNsText( $index );
+               return $ns[$index][$gender] ?? $this->getNsText( $index );
        }
 
        /**
@@ -613,7 +611,7 @@ class Language {
        function getLocalNsIndex( $text ) {
                $lctext = $this->lc( $text );
                $ids = $this->getNamespaceIds();
-               return isset( $ids[$lctext] ) ? $ids[$lctext] : false;
+               return $ids[$lctext] ?? false;
        }
 
        /**
@@ -700,7 +698,7 @@ class Language {
                        return $ns;
                }
                $ids = $this->getNamespaceIds();
-               return isset( $ids[$lctext] ) ? $ids[$lctext] : false;
+               return $ids[$lctext] ?? false;
        }
 
        /**
@@ -797,7 +795,7 @@ class Language {
         *              'all' all available languages
         *              '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 Language code => language name
+        * @return array Language code => language name (sorted by key)
         * @since 1.20
         */
        public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
@@ -823,7 +821,7 @@ class Language {
         *              'all' all available languages
         *              '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 Language code => language name
+        * @return array Language code => language name (sorted by key)
         */
        private static function fetchLanguageNamesUncached( $inLanguage = null, $include = 'mw' ) {
                global $wgExtraLanguageNames, $wgUsePigLatinVariant;
@@ -2990,8 +2988,8 @@ class Language {
                global $wgAllUnicodeFixes;
                $s = UtfNormal\Validator::cleanUp( $s );
                if ( $wgAllUnicodeFixes ) {
-                       $s = $this->transformUsingPairFile( 'normalize-ar.ser', $s );
-                       $s = $this->transformUsingPairFile( 'normalize-ml.ser', $s );
+                       $s = $this->transformUsingPairFile( 'normalize-ar.php', $s );
+                       $s = $this->transformUsingPairFile( 'normalize-ml.php', $s );
                }
 
                return $s;
@@ -3011,12 +3009,10 @@ class Language {
         * @throws MWException
         * @return string
         */
-       function transformUsingPairFile( $file, $string ) {
+       protected function transformUsingPairFile( $file, $string ) {
                if ( !isset( $this->transformData[$file] ) ) {
-                       $data = wfGetPrecompiledData( $file );
-                       if ( $data === false ) {
-                               throw new MWException( __METHOD__ . ": The transformation file $file is missing" );
-                       }
+                       global $IP;
+                       $data = require "$IP/languages/data/{$file}";
                        $this->transformData[$file] = new ReplacementArray( $data );
                }
                return $this->transformData[$file]->replace( $string );
@@ -3962,7 +3958,7 @@ class Language {
                if ( $gender === 'female' ) {
                        return $forms[1];
                }
-               return isset( $forms[2] ) ? $forms[2] : $forms[0];
+               return $forms[2] ?? $forms[0];
        }
 
        /**