From 99357479ea14670d5f0499b3fdf805a1edad70a5 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Mon, 6 Sep 2010 12:11:57 +0000 Subject: [PATCH] Rewrite User::getSkin, broken in r49493 because requesting the skin for a particular title had the side-effect of changing the title associated with the stored Skin object, causing weirdness like the wrong namespace tabs. --- includes/User.php | 57 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/includes/User.php b/includes/User.php index eee0684bab..ef52e70f2f 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2216,33 +2216,46 @@ class User { * @return Skin The current skin * @todo FIXME : need to check the old failback system [AV] */ - function &getSkin( $t = null ) { - if ( !isset( $this->mSkin ) ) { - wfProfileIn( __METHOD__ ); - - global $wgHiddenPrefs; - if( !in_array( 'skin', $wgHiddenPrefs ) ) { - # get the user skin - global $wgRequest; - $userSkin = $this->getOption( 'skin' ); - $userSkin = $wgRequest->getVal( 'useskin', $userSkin ); - } else { - # if we're not allowing users to override, then use the default - global $wgDefaultSkin; - $userSkin = $wgDefaultSkin; + function getSkin( $t = null ) { + if ( $t ) { + $skin = $this->createSkinObject(); + $skin->setTitle( $t ); + return $skin; + } else { + if ( ! $this->mSkin ) { + $this->mSkin = $this->createSkinObject(); } - - $this->mSkin = Skin::newFromKey( $userSkin ); - wfProfileOut( __METHOD__ ); - } - if( $t || !$this->mSkin->getTitle() ) { - if ( !$t ) { + + if ( ! $this->mSkin->getTitle() ) { global $wgOut; $t = $wgOut->getTitle(); + $this->mSkin->setTitle($t); } - $this->mSkin->setTitle( $t ); + + return $this->mSkin; } - return $this->mSkin; + } + + // Creates a Skin object, for getSkin() + private function createSkinObject() { + wfProfileIn( __METHOD__ ); + + global $wgHiddenPrefs; + if( !in_array( 'skin', $wgHiddenPrefs ) ) { + # get the user skin + global $wgRequest; + $userSkin = $this->getOption( 'skin' ); + $userSkin = $wgRequest->getVal( 'useskin', $userSkin ); + } else { + # if we're not allowing users to override, then use the default + global $wgDefaultSkin; + $userSkin = $wgDefaultSkin; + } + + $skin = Skin::newFromKey( $userSkin ); + wfProfileOut( __METHOD__ ); + + return $skin; } /** -- 2.20.1