Simplify the logic to decide whether to show "variant" and "noconvertlink" on Special...
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 22 Apr 2013 09:20:42 +0000 (11:20 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 24 Apr 2013 13:38:31 +0000 (13:38 +0000)
- 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

index 44c87f0..5518eb3 100644 (file)
@@ -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