API: Include setupSkinUserCss in prop=modules for useskin mode
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 25 Oct 2017 01:16:01 +0000 (02:16 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 25 Oct 2017 01:16:01 +0000 (02:16 +0100)
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
tests/phpunit/includes/api/ApiParseTest.php

index 7cbd353..15b94fb 100644 (file)
@@ -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 );
index 7d33fbc..07bf299 100644 (file)
@@ -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'
                );