Merge "Move log log_page entries are now that of the moved page"
[lhc/web/wiklou.git] / includes / Preferences.php
index f884ec3..eb29e41 100644 (file)
@@ -98,6 +98,20 @@ class Preferences {
 
                wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
 
+               self::loadPreferenceValues( $user, $context, $defaultPreferences );
+               self::$defaultPreferences = $defaultPreferences;
+               return $defaultPreferences;
+       }
+
+       /**
+        * Loads existing values for a given array of preferences
+        * @throws MWException
+        * @param User $user
+        * @param IContextSource $context
+        * @param array $defaultPreferences Array to load values for
+        * @return array|null
+        */
+       static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
                ## Remove preferences that wikis don't want to use
                global $wgHiddenPrefs;
                foreach ( $wgHiddenPrefs as $pref ) {
@@ -138,8 +152,6 @@ class Preferences {
                        }
                }
 
-               self::$defaultPreferences = $defaultPreferences;
-
                return $defaultPreferences;
        }
 
@@ -195,7 +207,7 @@ class Preferences {
         * @return void
         */
        static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
+               global $wgAuth, $wgContLang, $wgParser, $wgLanguageCode,
                        $wgDisableLangConversion, $wgMaxSigChars,
                        $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
                        $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
@@ -567,12 +579,16 @@ class Preferences {
                ## Skin #####################################
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $defaultPreferences['skin'] = array(
-                       'type' => 'radio',
-                       'options' => self::generateSkinOptions( $user, $context ),
-                       'label' => ' ',
-                       'section' => 'rendering/skin',
-               );
+               // Skin selector, if there is at least one valid skin
+               $skinOptions = self::generateSkinOptions( $user, $context );
+               if ( $skinOptions ) {
+                       $defaultPreferences['skin'] = array(
+                               'type' => 'radio',
+                               'options' => $skinOptions,
+                               'label' => ' ',
+                               'section' => 'rendering/skin',
+                       );
+               }
 
                # Create links to user CSS/JS pages for all skins
                # This code is basically copied from generateSkinOptions().  It'd
@@ -738,7 +754,6 @@ class Preferences {
                        'type' => 'select',
                        'section' => 'rendering/advancedrendering',
                        'options' => $stubThresholdOptions,
-                       'size' => 20,
                        'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
                );
 
@@ -978,10 +993,15 @@ class Preferences {
                        $watchTypes['read'] = 'watchcreations';
                }
 
+               if ( $user->isAllowed( 'rollback' ) ) {
+                       $watchTypes['rollback'] = 'watchrollback';
+               }
+
                foreach ( $watchTypes as $action => $pref ) {
                        if ( $user->isAllowed( $action ) ) {
                                // Messages:
                                // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
+                               // tog-watchrollback
                                $defaultPreferences[$pref] = array(
                                        'type' => 'toggle',
                                        'section' => 'watchlist/advancedwatchlist',
@@ -1011,7 +1031,7 @@ class Preferences {
         */
        static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) {
                foreach ( MWNamespace::getValidNamespaces() as $n ) {
-                       $defaultPreferences[ 'searchNs' . $n ] = array(
+                       $defaultPreferences['searchNs' . $n] = array(
                                'type' => 'api',
                        );
                }
@@ -1048,12 +1068,14 @@ class Preferences {
                }
                asort( $validSkinNames );
 
+               $foundDefault = false;
                foreach ( $validSkinNames as $skinkey => $sn ) {
                        $linkTools = array();
 
                        # Mark the default skin
                        if ( $skinkey == $wgDefaultSkin ) {
                                $linkTools[] = $context->msg( 'default' )->escaped();
+                               $foundDefault = true;
                        }
 
                        # Create preview link
@@ -1078,6 +1100,12 @@ class Preferences {
                        $ret[$display] = $skinkey;
                }
 
+               if ( !$foundDefault ) {
+                       // If the default skin is not available, things are going to break horribly because the
+                       // default value for skin selector will not be a valid value. Let's just not show it then.
+                       return array();
+               }
+
                return $ret;
        }