SpecialMovepage: Use 'warningbox'/'errorbox' for warnings/errors
[lhc/web/wiklou.git] / includes / Preferences.php
index 248b308..5f37e3f 100644 (file)
@@ -112,20 +112,20 @@ class Preferences {
         * @return array|null
         */
        static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
-               ## Remove preferences that wikis don't want to use
+               # # Remove preferences that wikis don't want to use
                foreach ( $context->getConfig()->get( 'HiddenPrefs' ) as $pref ) {
                        if ( isset( $defaultPreferences[$pref] ) ) {
                                unset( $defaultPreferences[$pref] );
                        }
                }
 
-               ## Make sure that form fields have their parent set. See bug 41337.
+               # # Make sure that form fields have their parent set. See bug 41337.
                $dummyForm = new HTMLForm( array(), $context );
 
                $disable = !$user->isAllowed( 'editmyoptions' );
 
                $defaultOptions = User::getDefaultOptions();
-               ## Prod in defaults from the user
+               # # Prod in defaults from the user
                foreach ( $defaultPreferences as $name => &$info ) {
                        $prefFromUser = self::getOptionFromUser( $name, $info, $user );
                        if ( $disable && !in_array( $name, self::$saveBlacklist ) ) {
@@ -211,7 +211,7 @@ class Preferences {
                // retrieving user name for GENDER and misc.
                $userName = $user->getName();
 
-               ## User info #####################################
+               # # User info #####################################
                // Information panel
                $defaultPreferences['username'] = array(
                        'type' => 'info',
@@ -427,7 +427,7 @@ class Preferences {
                        'section' => 'personal/signature'
                );
 
-               ## Email stuff
+               # # Email stuff
 
                if ( $config->get( 'EnableEmail' ) ) {
                        if ( $canViewPrivateInfo ) {
@@ -508,7 +508,6 @@ class Preferences {
                                                # Apply the same CSS class used on the input to the message:
                                                'cssclass' => $emailauthenticationclass,
                                        );
-                                       $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
                                }
                        }
 
@@ -571,7 +570,7 @@ class Preferences {
         * @return void
         */
        static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Skin #####################################
+               # # Skin #####################################
 
                // Skin selector, if there is at least one valid skin
                $skinOptions = self::generateSkinOptions( $user, $context );
@@ -620,7 +619,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Files #####################################
+               # # Files #####################################
                $defaultPreferences['imagesize'] = array(
                        'type' => 'select',
                        'options' => self::getImageSizes( $context ),
@@ -642,7 +641,7 @@ class Preferences {
         * @return void
         */
        static function datetimePreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Date and time #####################################
+               # # Date and time #####################################
                $dateOptions = self::getDateOptions( $context );
                if ( $dateOptions ) {
                        $defaultPreferences['date'] = array(
@@ -715,7 +714,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function renderingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Diffs ####################################
+               # # Diffs ####################################
                $defaultPreferences['diffonly'] = array(
                        'type' => 'toggle',
                        'section' => 'rendering/diffs',
@@ -727,7 +726,7 @@ class Preferences {
                        'label-message' => 'tog-norollbackdiff',
                );
 
-               ## Page Rendering ##############################
+               # # Page Rendering ##############################
                if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
                        $defaultPreferences['underline'] = array(
                                'type' => 'select',
@@ -777,7 +776,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function editingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Editing #####################################
+               # # Editing #####################################
                $defaultPreferences['editsectiononrightclick'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
@@ -865,7 +864,7 @@ class Preferences {
        static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
                $config = $context->getConfig();
                $rcMaxAge = $config->get( 'RCMaxAge' );
-               ## RecentChanges #####################################
+               # # RecentChanges #####################################
                $defaultPreferences['rcdays'] = array(
                        'type' => 'float',
                        'label-message' => 'recentchangesdays',
@@ -892,6 +891,14 @@ class Preferences {
                        'section' => 'rc/advancedrc',
                );
 
+               if ( $config->get( 'RCWatchCategoryMembership' ) ) {
+                       $defaultPreferences['hidecategorization'] = array(
+                               'type' => 'toggle',
+                               'label-message' => 'tog-hidecategorization',
+                               'section' => 'rc/advancedrc',
+                       );
+               }
+
                if ( $user->useRCPatrol() ) {
                        $defaultPreferences['hidepatrolled'] = array(
                                'type' => 'toggle',
@@ -926,7 +933,7 @@ class Preferences {
                $config = $context->getConfig();
                $watchlistdaysMax = ceil( $config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
 
-               ## Watchlist #####################################
+               # # Watchlist #####################################
                if ( $user->isAllowed( 'editmywatchlist' ) ) {
                        $editWatchlistLinks = array();
                        $editWatchlistModes = array(
@@ -998,6 +1005,19 @@ class Preferences {
                        'section' => 'watchlist/advancedwatchlist',
                        'label-message' => 'tog-watchlisthideliu',
                );
+               $defaultPreferences['watchlistreloadautomatically'] = array(
+                       'type' => 'toggle',
+                       'section' => 'watchlist/advancedwatchlist',
+                       'label-message' => 'tog-watchlistreloadautomatically',
+               );
+
+               if ( $config->get( 'RCWatchCategoryMembership' ) ) {
+                       $defaultPreferences['watchlisthidecategorization'] = array(
+                               'type' => 'toggle',
+                               'section' => 'watchlist/advancedwatchlist',
+                               'label-message' => 'tog-watchlisthidecategorization',
+                       );
+               }
 
                if ( $user->useRCPatrol() ) {
                        $defaultPreferences['watchlisthidepatrolled'] = array(
@@ -1253,7 +1273,7 @@ class Preferences {
         * @param IContextSource $context
         * @param string $formClass
         * @param array $remove Array of items to remove
-        * @return HtmlForm
+        * @return PreferencesForm|HtmlForm
         */
        static function getFormObject(
                $user,
@@ -1433,10 +1453,10 @@ class Preferences {
                        }
 
                        Hooks::run( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
-                       $user->saveSettings();
                }
 
                $wgAuth->updateExternalDB( $user );
+               $user->saveSettings();
 
                return $result;
        }
@@ -1450,7 +1470,7 @@ class Preferences {
                $res = self::tryFormSubmit( $formData, $form );
 
                if ( $res ) {
-                       $urlOptions = array( 'success' => 1 );
+                       $urlOptions = array();
 
                        if ( $res === 'eauth' ) {
                                $urlOptions['eauth'] = 1;
@@ -1460,7 +1480,11 @@ class Preferences {
 
                        $url = $form->getTitle()->getFullURL( $urlOptions );
 
-                       $form->getContext()->getOutput()->redirect( $url );
+                       $context = $form->getContext();
+                       // Set session data for the success message
+                       $context->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
+
+                       $context->getOutput()->redirect( $url );
                }
 
                return Status::newGood();
@@ -1639,4 +1663,12 @@ class PreferencesForm extends HTMLForm {
                Hooks::run( 'PreferencesGetLegend', array( $this, $key, &$legend ) );
                return $legend;
        }
+
+       /**
+        * Get the keys of each top level preference section.
+        * @return array of section keys
+        */
+       function getPreferenceSections() {
+               return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
+       }
 }