From 87840cb811dac42525b3d20cd26ab510e0a51d0f Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 22 Apr 2013 11:20:42 +0200 Subject: [PATCH] Simplify the logic to decide whether to show "variant" and "noconvertlink" on Special:Preferences - Group common checks; $wgDisableLangConversion and count( $variants ) only be need to be executed once to decide to show or not both fields - Move the check for existence of multiple variant directly after calling getVariants(), so there is no need to run unnecessary code when a language doesn't have variants - Move the declaration of $variantArray to where it will actually be used - fix comment style Change-Id: I2d621424904d0210336845cd82f96bb68a022514 --- includes/Preferences.php | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/includes/Preferences.php b/includes/Preferences.php index 44c87f016c..5518eb38a6 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -310,23 +310,23 @@ class Preferences { 'label-message' => 'yourlanguage', ); - /* see if there are multiple language variants to choose from*/ - $variantArray = array(); + // see if there are multiple language variants to choose from if ( !$wgDisableLangConversion ) { $variants = $wgContLang->getVariants(); - foreach ( $variants as $v ) { - $v = str_replace( '_', '-', strtolower( $v ) ); - $variantArray[$v] = $wgContLang->getVariantname( $v, false ); - } + if ( count( $variants ) > 1 ) { + $variantArray = array(); + foreach ( $variants as $v ) { + $v = str_replace( '_', '-', strtolower( $v ) ); + $variantArray[$v] = $wgContLang->getVariantname( $v, false ); + } - $options = array(); - foreach ( $variantArray as $code => $name ) { - $display = wfBCP47( $code ) . ' - ' . $name; - $options[$display] = $code; - } + $options = array(); + foreach ( $variantArray as $code => $name ) { + $display = wfBCP47( $code ) . ' - ' . $name; + $options[$display] = $code; + } - if ( count( $variantArray ) > 1 ) { $defaultPreferences['variant'] = array( 'label-message' => 'yourvariant', 'type' => 'select', @@ -334,16 +334,16 @@ class Preferences { 'section' => 'personal/i18n', 'help-message' => 'prefs-help-variant', ); - } - } - if ( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) { - $defaultPreferences['noconvertlink'] = - array( - 'type' => 'toggle', - 'section' => 'personal/i18n', - 'label-message' => 'tog-noconvertlink', - ); + if ( !$wgDisableTitleConversion ) { + $defaultPreferences['noconvertlink'] = + array( + 'type' => 'toggle', + 'section' => 'personal/i18n', + 'label-message' => 'tog-noconvertlink', + ); + } + } } // show a preview of the old signature first -- 2.20.1