* 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.
This commit is contained in:
Brion Vibber 2005-12-19 23:36:43 +00:00
parent 7c608502a8
commit 10dbba6ea3
4 changed files with 87 additions and 42 deletions

View file

@ -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 ===

View file

@ -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() {

View file

@ -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' );

View file

@ -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;