From e96d2d68023bf46d53fbf860c2d4b3ad1a9b7190 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Tue, 3 Jan 2012 01:58:27 +0000 Subject: [PATCH] Add RequestContextCreateSkin hook to allow extensions to override the loading of skins. --- RELEASE-NOTES-1.19 | 2 ++ docs/hooks.txt | 5 ++++ includes/context/RequestContext.php | 36 +++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 47a442ae93..4da9092346 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -241,6 +241,8 @@ production. * (bug 31759) Undefined property notice in querypages API. * (bug 32495) API should allow purge by pageids. * (bug 33147) API examples should explain what they do. +* Extensions can use the RequestContextCreateSkin hook to override what skin is + loaded in some contexts. === Languages updated in 1.19 === diff --git a/docs/hooks.txt b/docs/hooks.txt index ad58d7ec46..4ca46e2088 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1559,6 +1559,11 @@ $out: OutputPage object 'RecentChange_save': called at the end of RecentChange::save() $recentChange: RecentChange object +'RequestContextCreateSkin': Called when RequestContext::getSkin creates a skin instance. +Can be used by an extension override what skin is used in certain contexts. +IContextSource $context: The RequestContext the skin is being created for. +&$skin: A variable reference you may set a Skin instance or string key on to override the skin that will be used for the context. + 'ResourceLoaderGetConfigVars': called at the end of ResourceLoaderStartUpModule::getConfig(). Use this to export static configuration variables to JavaScript. Things that depend on the current diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 15280e6e5a..5aac68b532 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -248,18 +248,34 @@ class RequestContext implements IContextSource { if ( $this->skin === null ) { wfProfileIn( __METHOD__ . '-createskin' ); - global $wgHiddenPrefs; - if( !in_array( 'skin', $wgHiddenPrefs ) ) { - # get the user skin - $userSkin = $this->getUser()->getOption( 'skin' ); - $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin ); - } else { - # if we're not allowing users to override, then use the default - global $wgDefaultSkin; - $userSkin = $wgDefaultSkin; + $skin = null; + wfRunHooks( 'RequestContextCreateSkin', array( $this, &$skin ) ); + + // If the hook worked try to set a skin from it + if ( $skin instanceof Skin ) { + $this->skin = $skin; + } elseif ( is_string($skin) ) { + $this->skin = Skin::newFromKey( $skin ); + } + + // If this is still null (the hook didn't run or didn't work) + // then go through the normal processing to load a skin + if ( $this->skin === null ) { + global $wgHiddenPrefs; + if( !in_array( 'skin', $wgHiddenPrefs ) ) { + # get the user skin + $userSkin = $this->getUser()->getOption( 'skin' ); + $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin ); + } else { + # if we're not allowing users to override, then use the default + global $wgDefaultSkin; + $userSkin = $wgDefaultSkin; + } + + $this->skin = Skin::newFromKey( $userSkin ); } - $this->skin = Skin::newFromKey( $userSkin ); + // After all that set a context on whatever skin got created $this->skin->setContext( $this ); wfProfileOut( __METHOD__ . '-createskin' ); } -- 2.20.1