Rewrite User::getSkin, broken in r49493 because requesting the skin for a particular...
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 6 Sep 2010 12:11:57 +0000 (12:11 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 6 Sep 2010 12:11:57 +0000 (12:11 +0000)
includes/User.php

index eee0684..ef52e70 100644 (file)
@@ -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;
        }
 
        /**