From c470c9e16a1e13b403a191d49b168355b5ac0a89 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sun, 13 Jul 2014 03:23:55 +0200 Subject: [PATCH] Skin: Make normalizeKey() accept non-canonical case variants of keys For example, passing 'MonoBook' and 'monobook' will now both yield 'monobook'; previously, the former yielded the default skin ('vector'). This magically fixes casing issues in the &useskin= URL parameter, as well as in configuration variables like $wgDefaultSkin. (This is per agreement on wikitech-l discussion a few weeks ago, "What should be the recommended / supported way to do skins?"). Change-Id: I0df77b6d42726605b56d52b34e204113e8089e80 --- includes/Skin.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index bc30eff4f1..35e1ef86b2 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -155,10 +155,15 @@ abstract class Skin extends ContextSource { $skinNames = Skin::getSkinNames(); + // Make keys lowercase for case-insensitive matching. + $skinNames = array_change_key_case( $skinNames, CASE_LOWER ); + $key = strtolower( $key ); + $default = strtolower( $wgDefaultSkin ); + if ( $key == '' || $key == 'default' ) { // Don't return the default immediately; // in a misconfiguration we need to fall back. - $key = $wgDefaultSkin; + $key = $default; } if ( isset( $skinNames[$key] ) ) { @@ -168,7 +173,7 @@ abstract class Skin extends ContextSource { // Older versions of the software used a numeric setting // in the user preferences. $fallback = array( - 0 => $wgDefaultSkin, + 0 => $default, 2 => 'cologneblue' ); @@ -178,8 +183,8 @@ abstract class Skin extends ContextSource { if ( isset( $skinNames[$key] ) ) { return $key; - } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) { - return $wgDefaultSkin; + } elseif ( isset( $skinNames[$default] ) ) { + return $default; } else { return 'vector'; } -- 2.20.1