Remove a couple of unused variables, add spaces, wrap some long lines
[lhc/web/wiklou.git] / includes / Preferences.php
index d889184..2f377e1 100644 (file)
@@ -35,8 +35,6 @@ class Preferences {
                if ( self::$defaultPreferences )
                        return self::$defaultPreferences;
 
-               global $wgRCMaxAge;
-
                $defaultPreferences = array();
 
                self::profilePreferences( $user, $defaultPreferences );
@@ -62,7 +60,6 @@ class Preferences {
                }
 
                ## Prod in defaults from the user
-               global $wgDefaultUserOptions;
                foreach ( $defaultPreferences as $name => &$info ) {
                        $prefFromUser = self::getOptionFromUser( $name, $info, $user );
                        $field = HTMLForm::loadInputFromParameters( $info ); // For validation
@@ -101,7 +98,7 @@ class Preferences {
                        $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
                        $val = array();
 
-                       foreach ( $options as $label => $value ) {
+                       foreach ( $options as $value ) {
                                if ( $user->getOption( "$prefix$value" ) ) {
                                        $val[] = $value;
                                }
@@ -231,10 +228,10 @@ class Preferences {
                }
 
                // Language
-               global $wgContLanguageCode;
-               $languages = array_reverse( Language::getLanguageNames( false ) );
-               if ( !array_key_exists( $wgContLanguageCode, $languages ) ) {
-                       $languages[$wgContLanguageCode] = $wgContLanguageCode;
+               global $wgLanguageCode;
+               $languages = Language::getLanguageNames( false );
+               if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
+                       $languages[$wgLanguageCode] = $wgLanguageCode;
                }
                ksort( $languages );
 
@@ -474,8 +471,6 @@ class Preferences {
 
                $selectedSkin = $user->getOption( 'skin' );
                if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
-                       global $wgLang;
-
                        $settings = array_flip( $wgLang->getQuickbarSettings() );
 
                        $defaultPreferences['quickbar'] = array(
@@ -534,7 +529,7 @@ class Preferences {
                $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
                        $wgLang->time( $now = wfTimestampNow(), true ) );
                $nowserver = $wgLang->time( $now, false ) .
-                       Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
+                       Html::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 . substr( $now, 10, 2 ) );
 
                $defaultPreferences['nowserver'] = array(
                        'type' => 'info',
@@ -588,8 +583,8 @@ class Preferences {
                        );
                }
 
-               $stubThresholdValues = array( 0, 50, 100, 500, 1000, 2000, 5000, 10000 );
-               $stubThresholdOptions = array();
+               $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
+               $stubThresholdOptions = array( wfMsg( 'stub-threshold-disabled' ) => 0 );
                foreach ( $stubThresholdValues as $value ) {
                        $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
                }
@@ -750,7 +745,7 @@ class Preferences {
                $defaultPreferences['rcdays'] = array(
                        'type' => 'float',
                        'label-message' => 'recentchangesdays',
-                       'section' => 'rc/display',
+                       'section' => 'rc/displayrc',
                        'min' => 1,
                        'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
                        'help' => wfMsgExt(
@@ -763,7 +758,7 @@ class Preferences {
                        'type' => 'int',
                        'label-message' => 'recentchangescount',
                        'help-message' => 'prefs-help-recentchangescount',
-                       'section' => 'rc/display',
+                       'section' => 'rc/displayrc',
                );
                $defaultPreferences['usenewrc'] = array(
                        'type' => 'toggle',
@@ -807,7 +802,7 @@ class Preferences {
                        'type' => 'float',
                        'min' => 0,
                        'max' => 7,
-                       'section' => 'watchlist/display',
+                       'section' => 'watchlist/displaywatchlist',
                        'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
                        'label-message' => 'prefs-watchlist-days',
                );
@@ -817,7 +812,7 @@ class Preferences {
                        'max' => 1000,
                        'label-message' => 'prefs-watchlist-edits',
                        'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
-                       'section' => 'watchlist/display',
+                       'section' => 'watchlist/displaywatchlist',
                );
                $defaultPreferences['extendwatchlist'] = array(
                        'type' => 'toggle',
@@ -899,19 +894,19 @@ class Preferences {
                $defaultPreferences['searchlimit'] = array(
                        'type' => 'int',
                        'label-message' => 'resultsperpage',
-                       'section' => 'searchoptions/display',
+                       'section' => 'searchoptions/displaysearchoptions',
                        'min' => 0,
                );
                $defaultPreferences['contextlines'] = array(
                        'type' => 'int',
                        'label-message' => 'contextlines',
-                       'section' => 'searchoptions/display',
+                       'section' => 'searchoptions/displaysearchoptions',
                        'min' => 0,
                );
                $defaultPreferences['contextchars'] = array(
                        'type' => 'int',
                        'label-message' => 'contextchars',
-                       'section' => 'searchoptions/display',
+                       'section' => 'searchoptions/displaysearchoptions',
                        'min' => 0,
                );
 
@@ -920,7 +915,16 @@ class Preferences {
                        $defaultPreferences['disablesuggest'] = array(
                                'type' => 'toggle',
                                'label-message' => 'mwsuggest-disable',
-                               'section' => 'searchoptions/display',
+                               'section' => 'searchoptions/displaysearchoptions',
+                       );
+               }
+               
+               global $wgVectorUseSimpleSearch;
+               if ( $wgVectorUseSimpleSearch ) {
+                       $defaultPreferences['vector-simplesearch'] = array(
+                               'type' => 'toggle',
+                               'label-message' => 'vector-simplesearch-preference',
+                               'section' => 'searchoptions/displaysearchoptions'
                        );
                }
 
@@ -987,8 +991,8 @@ class Preferences {
        }
 
        /**
-        * @param object $user The user object
-        * @return array Text/links to display as key; $skinkey as value
+        * @param $user The User object
+        * @return Array: text/links to display as key; $skinkey as value
         */
        static function generateSkinOptions( $user ) {
                global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
@@ -1061,7 +1065,6 @@ class Preferences {
                                $wgDefaultUserOptions['date'] = 'default';
                        }
 
-                       $idCnt = 0;
                        $epoch = wfTimestampNow();
                        foreach ( $dateopts as $key ) {
                                if ( $key == 'default' ) {
@@ -1109,7 +1112,8 @@ class Preferences {
                                        $wgLang->formatNum( $wgMaxSigChars )
                                )
                        );
-               } elseif ( !empty( $alldata['fancysig'] ) &&
+               } elseif ( isset( $alldata['fancysig'] ) &&
+                               $alldata['fancysig'] &&
                                false === $wgParser->validateSig( $signature ) ) {
                        return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
                } else {
@@ -1119,7 +1123,7 @@ class Preferences {
 
        static function cleanSignature( $signature, $alldata ) {
                global $wgParser;
-               if ( $alldata['fancysig'] ) {
+               if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
                        $signature = $wgParser->cleanSig( $signature );
                } else {
                        // When no fancy sig used, make sure ~{3,5} get removed.
@@ -1141,9 +1145,9 @@ class Preferences {
                return true;
        }
 
-       static function getFormObject( $user ) {
+       static function getFormObject( $user, $formClass = 'PreferencesForm' ) {
                $formDescriptor = Preferences::getPreferences( $user );
-               $htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
+               $htmlForm = new $formClass( $formDescriptor, 'prefs' );
 
                $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
                # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
@@ -1219,7 +1223,6 @@ class Preferences {
                                return $tz;
                        default:
                                $data = explode( ':', $tz, 2 );
-                               $minDiff = 0;
                                if ( count( $data ) == 2 ) {
                                        $data[0] = intval( $data[0] );
                                        $data[1] = intval( $data[1] );