resourceloader: Move remaining module registrations to ServiceWiring
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 17 Apr 2019 14:17:15 +0000 (15:17 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 17 Apr 2019 19:01:29 +0000 (19:01 +0000)
Also restore the order of registrations as it was before
last week with 47422fabe2813f. (That is, core modules are registered
before extension modules, in case of conflicts with a warning, the
core one wins).

Bug: T32956
Change-Id: I3a50508178159dfc8e5db1e218a5e6d10e2d4b2a

includes/ServiceWiring.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index d39a0c7..a500c45 100644 (file)
@@ -443,8 +443,17 @@ return [
                        $config,
                        LoggerFactory::getInstance( 'resourceloader' )
                );
+
                $rl->addSource( $config->get( 'ResourceLoaderSources' ) );
+
+               // Core modules, then extension/skin modules
                $rl->register( include "$IP/resources/Resources.php" );
+               $rl->register( $config->get( 'ResourceModules' ) );
+               Hooks::run( 'ResourceLoaderRegisterModules', [ &$rl ] );
+
+               if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
+                       $rl->registerTestModules();
+               }
 
                return $rl;
        },
index 8d60e0f..3371069 100644 (file)
@@ -255,17 +255,6 @@ class ResourceLoader implements LoggerAwareInterface {
                // Special module that always exists
                $this->register( 'startup', [ 'class' => ResourceLoaderStartUpModule::class ] );
 
-               // Register extension modules
-               $this->register( $config->get( 'ResourceModules' ) );
-
-               // Avoid PHP 7.1 warning from passing $this by reference
-               $rl = $this;
-               Hooks::run( 'ResourceLoaderRegisterModules', [ &$rl ] );
-
-               if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
-                       $this->registerTestModules();
-               }
-
                $this->setMessageBlobStore( new MessageBlobStore( $this, $this->logger ) );
        }
 
@@ -394,6 +383,9 @@ class ResourceLoader implements LoggerAwareInterface {
                }
        }
 
+       /**
+        * @internal For use by ServiceWiring only
+        */
        public function registerTestModules() {
                global $IP;
 
index 7239afc..85a47de 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Wikimedia\TestingAccessWrapper;
+use MediaWiki\MediaWikiServices;
 
 class ResourceLoaderTest extends ResourceLoaderTestCase {
 
@@ -14,25 +15,23 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
 
        /**
         * Ensure the ResourceLoaderRegisterModules hook is called.
-        *
-        * @covers ResourceLoader::__construct
+        * @coversNothing
         */
-       public function testConstructRegistrationHook() {
-               $resourceLoaderRegisterModulesHook = false;
+       public function testServiceWiring() {
+               $this->overrideMwServices();
 
+               $ranHook = 0;
                $this->setMwGlobals( 'wgHooks', [
                        'ResourceLoaderRegisterModules' => [
-                               function ( &$resourceLoader ) use ( &$resourceLoaderRegisterModulesHook ) {
-                                       $resourceLoaderRegisterModulesHook = true;
+                               function ( &$resourceLoader ) use ( &$ranHook ) {
+                                       $ranHook++;
                                }
                        ]
                ] );
 
-               $unused = new ResourceLoader();
-               $this->assertTrue(
-                       $resourceLoaderRegisterModulesHook,
-                       'Hook ResourceLoaderRegisterModules called'
-               );
+               MediaWikiServices::getInstance()->getResourceLoader();
+
+               $this->assertSame( 1, $ranHook, 'Hook was called' );
        }
 
        /**