From d5ed2785fb691494dadc4beda4dd9e102fde50fa Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 25 Oct 2017 02:16:01 +0100 Subject: [PATCH] API: Include setupSkinUserCss in prop=modules for useskin mode Follows-up 90c95fc7f290f, which included result of Skin::getDefaultModules in the prop=modules list. All hardcoded modules in OutputPage and Parser were also subsequently moved into Skin::getDefaultModules. However, a number of modules cannot be moved there because fundamentally Skin::getDefaultModules can only load modules via OutputPage::addModules(). For style modules, addModuleStyles() must be used. Fortunately, there is already a centralised place for that, namely Skin::setupSkinUserCss(). Include that in the ApiParse return as well. That should resolve the last bit of inconsistency between ApiParse and OutputPage when it comes to the module queue. Bug: T140664 Change-Id: I35e2e3bbdccdd1aa2a259b8e624daa80c609ba8c --- includes/api/ApiParse.php | 2 ++ tests/phpunit/includes/api/ApiParseTest.php | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 7cbd35377e..15b94fb952 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -329,6 +329,8 @@ class ApiParse extends ApiBase { $context->setOutput( $outputPage ); if ( $skin ) { + // Based on OutputPage::headElement() + $skin->setupSkinUserCss( $outputPage ); // Based on OutputPage::output() foreach ( $skin->getDefaultModules() as $group ) { $outputPage->addModules( $group ); diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php index 7d33fbc5cd..07bf299093 100644 --- a/tests/phpunit/includes/api/ApiParseTest.php +++ b/tests/phpunit/includes/api/ApiParseTest.php @@ -134,13 +134,17 @@ class ApiParseTest extends ApiTestCase { $factory = new SkinFactory(); $factory->register( 'testing', 'Testing', function () { $skin = $this->getMockBuilder( SkinFallback::class ) - ->setMethods( [ 'getDefaultModules' ] ) + ->setMethods( [ 'getDefaultModules', 'setupSkinUserCss' ] ) ->getMock(); $skin->expects( $this->once() )->method( 'getDefaultModules' ) ->willReturn( [ 'core' => [ 'foo', 'bar' ], 'content' => [ 'baz' ] ] ); + $skin->expects( $this->once() )->method( 'setupSkinUserCss' ) + ->will( $this->returnCallback( function ( OutputPage $out ) { + $out->addModuleStyles( 'foo.styles' ); + } ) ); return $skin; } ); $this->setService( 'SkinFactory', $factory ); @@ -162,7 +166,7 @@ class ApiParseTest extends ApiTestCase { 'resp.parse.modulescripts' ); $this->assertSame( - [], + [ 'foo.styles' ], $res[0]['parse']['modulestyles'], 'resp.parse.modulestyles' ); -- 2.20.1