* changed variable list as per comment on r79954 left only wgDBtype
[lhc/web/wiklou.git] / includes / Preferences.php
index 502af4e..8cf1f44 100644 (file)
@@ -29,14 +29,17 @@ class Preferences {
        static $defaultPreferences = null;
        static $saveFilters = array(
                        'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
+                       'cols' => array( 'Preferences', 'filterIntval' ),
+                       'rows' => array( 'Preferences', 'filterIntval' ),
+                       'rclimit' => array( 'Preferences', 'filterIntval' ),
+                       'wllimit' => array( 'Preferences', 'filterIntval' ),
+                       'searchlimit' => array( 'Preferences', 'filterIntval' ),
        );
 
        static function getPreferences( $user ) {
                if ( self::$defaultPreferences )
                        return self::$defaultPreferences;
 
-               global $wgRCMaxAge;
-
                $defaultPreferences = array();
 
                self::profilePreferences( $user, $defaultPreferences );
@@ -62,10 +65,9 @@ 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
+                       $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
                        $defaultOptions = User::getDefaultOptions();
                        $globalDefault = isset( $defaultOptions[$name] )
                                ? $defaultOptions[$name]
@@ -101,7 +103,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;
                                }
@@ -217,18 +219,24 @@ class Preferences {
                                'section' => 'personal/info',
                        );
                }
-
-               $defaultPreferences['rememberpassword'] = array(
-                       'type' => 'toggle',
-                       'label-message' => 'tog-rememberpassword',
-                       'section' => 'personal/info',
-               );
+               global $wgCookieExpiration;
+               if ( $wgCookieExpiration > 0 ) {
+                       $defaultPreferences['rememberpassword'] = array(
+                               'type' => 'toggle',
+                               'label' => wfMsgExt(
+                                       'tog-rememberpassword',
+                                       array( 'parsemag' ),
+                                       $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )
+                                       ),
+                               'section' => 'personal/info',
+                       );
+               }
 
                // 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 );
 
@@ -436,7 +444,7 @@ class Preferences {
                $defaultPreferences['skin'] = array(
                        'type' => 'radio',
                        'options' => self::generateSkinOptions( $user ),
-                       'label' => ' ',
+                       'label' => ' ',
                        'section' => 'rendering/skin',
                );
 
@@ -468,8 +476,6 @@ class Preferences {
 
                $selectedSkin = $user->getOption( 'skin' );
                if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
-                       global $wgLang;
-
                        $settings = array_flip( $wgLang->getQuickbarSettings() );
 
                        $defaultPreferences['quickbar'] = array(
@@ -488,7 +494,7 @@ class Preferences {
                        $defaultPreferences['math'] = array(
                                'type' => 'radio',
                                'options' => array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ),
-                               'label' => ' ',
+                               'label' => ' ',
                                'section' => 'rendering/math',
                        );
                }
@@ -519,7 +525,7 @@ class Preferences {
                        $defaultPreferences['date'] = array(
                                'type' => 'radio',
                                'options' => $dateOptions,
-                               'label' => ' ',
+                               'label' => ' ',
                                'section' => 'datetime/dateformat',
                        );
                }
@@ -528,7 +534,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',
@@ -582,8 +588,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;
                }
@@ -744,7 +750,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(
@@ -757,7 +763,7 @@ class Preferences {
                        'type' => 'int',
                        'label-message' => 'recentchangescount',
                        'help-message' => 'prefs-help-recentchangescount',
-                       'section' => 'rc/display',
+                       'section' => 'rc/displayrc',
                );
                $defaultPreferences['usenewrc'] = array(
                        'type' => 'toggle',
@@ -801,7 +807,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',
                );
@@ -811,7 +817,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',
@@ -893,19 +899,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,
                );
 
@@ -914,7 +920,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'
                        );
                }
 
@@ -981,8 +996,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;
@@ -1055,7 +1070,6 @@ class Preferences {
                                $wgDefaultUserOptions['date'] = 'default';
                        }
 
-                       $idCnt = 0;
                        $epoch = wfTimestampNow();
                        foreach ( $dateopts as $key ) {
                                if ( $key == 'default' ) {
@@ -1103,7 +1117,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 {
@@ -1113,7 +1128,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.
@@ -1135,10 +1150,11 @@ 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->setId( 'mw-prefs-form' );
                $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
                # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
                $htmlForm->setSubmitTooltip( 'preferences-save' );
@@ -1204,6 +1220,10 @@ class Preferences {
                }
                return $opt;
        }
+       
+       static function filterIntval( $value, $alldata ){
+               return intval( $value );
+       }
 
        static function filterTimezoneInput( $tz, $alldata ) {
                $data = explode( '|', $tz, 3 );
@@ -1213,7 +1233,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] );
@@ -1263,8 +1282,8 @@ class Preferences {
                                        # Mail a temporary password to the dirty address.
                                        # User can come back through the confirmation URL to re-enable email.
                                        $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
-                                       if ( WikiError::isError( $result ) ) {
-                                               return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
+                                       if ( !$result->isGood() ) {
+                                               return htmlspecialchars( $result->getWikiText( 'mailerror' ) );
                                        } elseif ( $entryPoint == 'ui' ) {
                                                $result = 'eauth';
                                        }
@@ -1319,7 +1338,7 @@ class Preferences {
                        $wgOut->redirect( $url );
                }
 
-               return true;
+               return Status::newGood();
        }
 
        public static function loadOldSearchNs( $user ) {