Preferences: Disable the 'skin' preference if there are no skins
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 27 Jul 2014 20:27:29 +0000 (22:27 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 2 Aug 2014 12:07:11 +0000 (12:07 +0000)
Having a radio field with no valid values makes MediaWiki sad and
causes exceptions.

Also make double-sure that the global default value is not invalid.
That causes exceptions too.

Change-Id: I90cc9e6f40303aa5771c265948a0be4a4ce2e42c

includes/Preferences.php

index 084d6ab..eb29e41 100644 (file)
@@ -579,12 +579,16 @@ class Preferences {
                ## Skin #####################################
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $defaultPreferences['skin'] = array(
-                       'type' => 'radio',
-                       'options' => self::generateSkinOptions( $user, $context ),
-                       'label' => '&#160;',
-                       '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' => '&#160;',
+                               'section' => 'rendering/skin',
+                       );
+               }
 
                # Create links to user CSS/JS pages for all skins
                # This code is basically copied from generateSkinOptions().  It'd
@@ -1064,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
@@ -1094,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;
        }