From: Fomafix Date: Thu, 22 Feb 2018 21:09:04 +0000 (+0100) Subject: Avoid sorting the language array twice X-Git-Tag: 1.34.0-rc.0~5343 X-Git-Url: http://git.cyclocoop.org/data/modifier.php?a=commitdiff_plain;h=384dc90874f5ae495ab0538b9d45534e0a5ff14f;p=lhc%2Fweb%2Fwiklou.git Avoid sorting the language array twice Language::fetchLanguageNames returns already a sorted array. An additional ksort is only needed when inserting a new value. Change-Id: If8c7b16fa6e7dfe1545f72ac9c742a2f43eaee57 --- diff --git a/includes/Xml.php b/includes/Xml.php index 7dcd4a4327..10d0d8b913 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -214,10 +214,10 @@ class Xml { // a custom language code might not have a defined name... if ( !array_key_exists( $wgLanguageCode, $languages ) ) { $languages[$wgLanguageCode] = $wgLanguageCode; + // Sort the array again + ksort( $languages ); } - ksort( $languages ); - /** * If a bogus value is set, default to the content language. * Otherwise, no default is selected and the user ends up diff --git a/includes/installer/WebInstallerLanguage.php b/includes/installer/WebInstallerLanguage.php index bce07d3118..846be6ccb6 100644 --- a/includes/installer/WebInstallerLanguage.php +++ b/includes/installer/WebInstallerLanguage.php @@ -108,7 +108,6 @@ class WebInstallerLanguage extends WebInstallerPage { $unwantedLanguageCodes = $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping(); $languages = Language::fetchLanguageNames(); - ksort( $languages ); foreach ( $languages as $code => $lang ) { if ( isset( $unwantedLanguageCodes[$code] ) ) { continue; diff --git a/includes/preferences/DefaultPreferencesFactory.php b/includes/preferences/DefaultPreferencesFactory.php index 2d7d73fac3..d5a706afc4 100644 --- a/includes/preferences/DefaultPreferencesFactory.php +++ b/includes/preferences/DefaultPreferencesFactory.php @@ -413,8 +413,9 @@ class DefaultPreferencesFactory implements PreferencesFactory { $languageCode = $this->config->get( 'LanguageCode' ); if ( !array_key_exists( $languageCode, $languages ) ) { $languages[$languageCode] = $languageCode; + // Sort the array again + ksort( $languages ); } - ksort( $languages ); $options = []; foreach ( $languages as $code => $name ) { diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php index a68f08fd9a..e3485ff724 100644 --- a/includes/specials/SpecialPageLanguage.php +++ b/includes/specials/SpecialPageLanguage.php @@ -82,7 +82,6 @@ class SpecialPageLanguage extends FormSpecialPage { // Building a language selector $userLang = $this->getLanguage()->getCode(); $languages = Language::fetchLanguageNames( $userLang, 'mwfile' ); - ksort( $languages ); $options = []; foreach ( $languages as $code => $name ) { $options["$code - $name"] = $code; diff --git a/languages/Language.php b/languages/Language.php index db302d7004..be0c037ffb 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -797,7 +797,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 +823,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;