From: Kunal Mehta Date: Mon, 11 Aug 2014 11:33:54 +0000 (+0100) Subject: SkinFactory: register skins in Setup.php X-Git-Tag: 1.31.0-rc.0~14455^2 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=1154e1848fe336fd9900f7748f041b29e1889f8a;p=lhc%2Fweb%2Fwiklou.git SkinFactory: register skins in Setup.php This un-makes $wgValidSkinNames a legacy thing, and is more backwards-compatible friendly. Change-Id: I5c442f3c9e4ee7a4a3980fd02138ee756ef9fa7a --- diff --git a/includes/Setup.php b/includes/Setup.php index 935fa152c6..b100c7aefa 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -263,8 +263,21 @@ if ( $wgSkipSkin ) { $wgSkipSkins[] = $wgSkipSkin; } -// Register a hidden "fallback" skin -$wgValidSkinNames['fallback'] = 'Fallback'; // SkinFallback +// Register skins +// Use a closure to avoid leaking into global state +call_user_func( function() use ( $wgValidSkinNames ) { + $factory = SkinFactory::getDefaultInstance(); + foreach ( $wgValidSkinNames as $name => $skin ) { + $factory->register( $name, $skin, function() use ( $skin ) { + $class = "Skin$skin"; + return new $class; + } ); + } + // Register a hidden "fallback" skin + $factory->register( 'fallback', 'Fallback', function() { + return new SkinFallback; + } ); +} ); $wgSkipSkins[] = 'fallback'; if ( $wgLocalInterwiki ) { diff --git a/includes/skins/SkinFactory.php b/includes/skins/SkinFactory.php index 51aced9c69..52eaddd532 100644 --- a/includes/skins/SkinFactory.php +++ b/includes/skins/SkinFactory.php @@ -39,6 +39,13 @@ class SkinFactory { */ private $displayNames = array(); + /** + * Map of name => class name without "Skin" prefix + * for legacy skins using the autoloader + * @var array + */ + private $legacySkins = array(); + /** * @var SkinFactory */ @@ -72,10 +79,9 @@ class SkinFactory { * @return array */ private function getLegacySkinNames() { - global $wgValidSkinNames; static $skinsInitialised = false; - if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) { + if ( !$skinsInitialised || !count( $this->legacySkins ) ) { # Get a list of available skins # Build using the regular expression '^(.*).php$' # Array keys are all lower case, array value keep the case used by filename @@ -117,7 +123,7 @@ class SkinFactory { "The mechanism will be removed in MediaWiki 1.25 and the skin will no longer be recognized. " . "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for information how to fix this." ); - $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; + $this->legacySkins[strtolower( $aSkin )] = $aSkin; } } $skinDir->close(); @@ -125,7 +131,7 @@ class SkinFactory { $skinsInitialised = true; wfProfileOut( __METHOD__ . '-init' ); } - return $wgValidSkinNames; + return $this->legacySkins; } diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index e98f0e86c3..038a0e1f9e 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -5,9 +5,9 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { protected function setUp() { parent::setUp(); - $this->setMwGlobals( array( - 'wgValidSkinNames' => array( 'vector' => 'Vector' ), - ) ); + // The return value of the closure shouldn't matter since this test should + // never call it + SkinFactory::getDefaultInstance()->register( 'vector', 'Vector', function(){}); } /**