Add RequestContextCreateSkin hook to allow extensions to override the loading of...
authorDaniel Friesen <dantman@users.mediawiki.org>
Tue, 3 Jan 2012 01:58:27 +0000 (01:58 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Tue, 3 Jan 2012 01:58:27 +0000 (01:58 +0000)
RELEASE-NOTES-1.19
docs/hooks.txt
includes/context/RequestContext.php

index 47a442a..4da9092 100644 (file)
@@ -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 ===
 
index ad58d7e..4ca46e2 100644 (file)
@@ -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
index 15280e6..5aac68b 100644 (file)
@@ -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' );
                }