From: Brion Vibber Date: Mon, 19 Dec 2005 23:36:43 +0000 (+0000) Subject: * Upgrade old skin preferences properly at Special:Preferences X-Git-Tag: 1.6.0~928 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=10dbba6ea32c8e5652e9d796795ddcfc7e84e6ca;p=lhc%2Fweb%2Fwiklou.git * Upgrade old skin preferences properly at Special:Preferences (used to spontaneously switch to Classic skin for old numeric pref records) This one keeps biting me when I log in on wikis I haven't been to in a year or two, then change prefs. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fe82f1cd25..9418f656fa 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -335,6 +335,8 @@ fully support the editing toolbar, but was found to be too confusing. * Use $wgOut->parse() in wfGetSiteNotice() instead of creating a new parser instance. This allows use of extension hooks if required. * Removed experimental Amethyst skin from default set +* Upgrade old skin preferences properly at Special:Preferences + (used to spontaneously switch to Classic skin for old numeric pref records) === Caveats === diff --git a/includes/Skin.php b/includes/Skin.php index a9aeccd010..884e97877c 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -73,13 +73,93 @@ class Skin extends Linker { /** Constructor, call parent constructor */ function Skin() { parent::Linker(); } + /** + * Fetch the set of available skins. + * @return array of strings + * @static + */ function getSkinNames() { global $wgValidSkinNames; return $wgValidSkinNames; } + + /** + * Normalize a skin preference value to a form that can be loaded. + * If a skin can't be found, it will fall back to the configured + * default (or the old 'Classic' skin if that's broken). + * @param string $key + * @return string + * @static + */ + function normalizeKey( $key ) { + global $wgDefaultSkin; + $skinNames = Skin::getSkinNames(); + + if( $key == '' ) { + // Don't return the default immediately; + // in a misconfiguration we need to fall back. + $key = $wgDefaultSkin; + } + + if( isset( $skinNames[$key] ) ) { + return $key; + } + + // Older versions of the software used a numeric setting + // in the user preferences. + $fallback = array( + 0 => $wgDefaultSkin, + 1 => 'nostalgia', + 2 => 'cologneblue' ); + + if( isset( $fallback[$key] ) ){ + $key = $fallback[$key]; + } + + if( isset( $skinNames[$key] ) ) { + return $key; + } else { + // The old built-in skin + return 'standard'; + } + } + + /** + * Factory method for loading a skin of a given type + * @param string $key 'monobook', 'standard', etc + * @return Skin + * @static + */ + function &newFromKey( $key ) { + $key = Skin::normalizeKey( $key ); + + $skinNames = Skin::getSkinNames(); + $skinName = $skinNames[$key]; + + global $IP; + + # Grab the skin class and initialise it. Each skin checks for PHPTal + # and will not load if it's not enabled. + require_once( $IP.'/skins/'.$skinName.'.php' ); + + # Check if we got if not failback to default skin + $className = 'Skin'.$skinName; + if( !class_exists( $className ) ) { + # DO NOT die if the class isn't found. This breaks maintenance + # scripts and can cause a user account to be unrecoverable + # except by SQL manipulation if a previously valid skin name + # is no longer valid. + $className = 'SkinStandard'; + require_once( $IP.'/skins/Standard.php' ); + } + $skin =& new $className; + return $skin; + } /** @return string path to the skin stylesheet */ - function getStylesheet() { return 'common/wikistandard.css?1'; } + function getStylesheet() { + return 'common/wikistandard.css?1'; + } /** @return string skin name */ function getSkinName() { diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index 40366dc43c..71f34ca1ae 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -331,7 +331,7 @@ class PreferencesForm { $this->mNick = $wgUser->getOption( 'nickname' ); $this->mQuickbar = $wgUser->getOption( 'quickbar' ); - $this->mSkin = $wgUser->getOption( 'skin' ); + $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) ); $this->mMath = $wgUser->getOption( 'math' ); $this->mDate = $wgUser->getOption( 'date' ); $this->mRows = $wgUser->getOption( 'rows' ); diff --git a/includes/User.php b/includes/User.php index 1c59a64ce1..60e06fb8a1 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1137,46 +1137,9 @@ class User { # get the user skin $userSkin = $this->getOption( 'skin' ); - $userSkin = $wgRequest->getText('useskin', $userSkin); - if ( $userSkin == '' ) { $userSkin = 'standard'; } - - if ( !isset( $skinNames[$userSkin] ) ) { - # in case the user skin could not be found find a replacement - $fallback = array( - 0 => 'Standard', - 1 => 'Nostalgia', - 2 => 'CologneBlue'); - # if phptal is enabled we should have monobook skin that - # superseed the good old SkinStandard. - if ( isset( $skinNames['monobook'] ) ) { - $fallback[0] = 'MonoBook'; - } - - if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){ - $sn = $fallback[$userSkin]; - } else { - $sn = 'Standard'; - } - } else { - # The user skin is available - $sn = $skinNames[$userSkin]; - } - - # Grab the skin class and initialise it. Each skin checks for PHPTal - # and will not load if it's not enabled. - require_once( $IP.'/skins/'.$sn.'.php' ); - - # Check if we got if not failback to default skin - $className = 'Skin'.$sn; - if( !class_exists( $className ) ) { - # DO NOT die if the class isn't found. This breaks maintenance - # scripts and can cause a user account to be unrecoverable - # except by SQL manipulation if a previously valid skin name - # is no longer valid. - $className = 'SkinStandard'; - require_once( $IP.'/skins/Standard.php' ); - } - $this->mSkin =& new $className; + $userSkin = $wgRequest->getVal('useskin', $userSkin); + + $this->mSkin =& Skin::newFromKey( $userSkin ); wfProfileOut( $fname ); } return $this->mSkin;