r72481 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72480‎ | r72481 | r72482 >
Date:12:11, 6 September 2010
Author:werdna
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -2216,35 +2216,48 @@
22172217 * @return Skin The current skin
22182218 * @todo FIXME : need to check the old failback system [AV]
22192219 */
2220 - function &getSkin( $t = null ) {
2221 - if ( !isset( $this->mSkin ) ) {
2222 - wfProfileIn( __METHOD__ );
2223 -
2224 - global $wgHiddenPrefs;
2225 - if( !in_array( 'skin', $wgHiddenPrefs ) ) {
2226 - # get the user skin
2227 - global $wgRequest;
2228 - $userSkin = $this->getOption( 'skin' );
2229 - $userSkin = $wgRequest->getVal( 'useskin', $userSkin );
2230 - } else {
2231 - # if we're not allowing users to override, then use the default
2232 - global $wgDefaultSkin;
2233 - $userSkin = $wgDefaultSkin;
 2220+ function getSkin( $t = null ) {
 2221+ if ( $t ) {
 2222+ $skin = $this->createSkinObject();
 2223+ $skin->setTitle( $t );
 2224+ return $skin;
 2225+ } else {
 2226+ if ( ! $this->mSkin ) {
 2227+ $this->mSkin = $this->createSkinObject();
22342228 }
2235 -
2236 - $this->mSkin = Skin::newFromKey( $userSkin );
2237 - wfProfileOut( __METHOD__ );
2238 - }
2239 - if( $t || !$this->mSkin->getTitle() ) {
2240 - if ( !$t ) {
 2229+
 2230+ if ( ! $this->mSkin->getTitle() ) {
22412231 global $wgOut;
22422232 $t = $wgOut->getTitle();
 2233+ $this->mSkin->setTitle($t);
22432234 }
2244 - $this->mSkin->setTitle( $t );
 2235+
 2236+ return $this->mSkin;
22452237 }
2246 - return $this->mSkin;
22472238 }
 2239+
 2240+ // Creates a Skin object, for getSkin()
 2241+ private function createSkinObject() {
 2242+ wfProfileIn( __METHOD__ );
22482243
 2244+ global $wgHiddenPrefs;
 2245+ if( !in_array( 'skin', $wgHiddenPrefs ) ) {
 2246+ # get the user skin
 2247+ global $wgRequest;
 2248+ $userSkin = $this->getOption( 'skin' );
 2249+ $userSkin = $wgRequest->getVal( 'useskin', $userSkin );
 2250+ } else {
 2251+ # if we're not allowing users to override, then use the default
 2252+ global $wgDefaultSkin;
 2253+ $userSkin = $wgDefaultSkin;
 2254+ }
 2255+
 2256+ $skin = Skin::newFromKey( $userSkin );
 2257+ wfProfileOut( __METHOD__ );
 2258+
 2259+ return $skin;
 2260+ }
 2261+
22492262 /**
22502263 * Check the watched status of an article.
22512264 * @param $title \type{Title} Title of the article to look at

Follow-up revisions

RevisionCommit summaryAuthorDate
r75873Cleanup r49493, r72481: Adding skin to $wgHiddenPrefs disabled the useskin pa...demon20:18, 2 November 2010
r81675Cleanup to r70900, r72481: don't construct new skin objects just because the ...demon01:08, 8 February 2011
r81684MFT r81675: avoid creating unneeded skin objects due to changes in r70900, r7...brion02:48, 8 February 2011
r81685MFT from r81675 via REL1_17 r81684: cleanup for r70900, r72481brion02:50, 8 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r49493initPage() is far too late to be setting a title, so we'll do it right after ...demon04:43, 15 April 2009

Comments

#Comment by MarkAHershberger (talk | contribs)   23:04, 5 January 2011

Is "the side-effect of changing the title associated with the stored Skin object" why $this->mSkin is not set if a title was passed in? If so, a comment in the code would help.

If that isn't why $this->mSkin isn't set when a a title is passed in, then a comment would still be helpful here. I dug all the way back from r70900 to figure out what that code meant in the current context.

#Comment by 😂 (talk | contribs)   18:37, 7 February 2011

If we already have $mSkin, we should check if it's getTitle() equals the $title we're passed. That way when something like r70900 call's getSkin() a lot with the same Title, we don't keep constructing new skin objects.

#Comment by 😂 (talk | contribs)   01:11, 8 February 2011

I cleaned up this and r70900 in r81675. Creates a bunch of useless skin objects when passed a Title that matches $wgOut->getTitle() (which is *really* likely when called from a skin like in r70900)

#Comment by 😂 (talk | contribs)   02:49, 8 February 2011

r70900 is of course completely unrelated :p

Status & tagging log