}
}
+ /**
+ * Transfer styles and JavaScript modules from skin.
+ *
+ * @param Skin $sk to load modules for
+ */
+ public function loadSkinModules( $sk ) {
+ foreach ( $sk->getDefaultModules() as $group => $modules ) {
+ if ( $group === 'styles' ) {
+ foreach ( $modules as $key => $moduleMembers ) {
+ $this->addModuleStyles( $moduleMembers );
+ }
+ } else {
+ $this->addModules( $modules );
+ }
+ }
+ }
+
/**
* Finally, all the text has been munged and accumulated into
* the object, let's actually output it:
}
$sk = $this->getSkin();
- foreach ( $sk->getDefaultModules() as $group ) {
- $this->addModules( $group );
- }
+ $this->loadSkinModules( $sk );
MWDebug::addModules( $this );
// Based on OutputPage::headElement()
$skin->setupSkinUserCss( $outputPage );
// Based on OutputPage::output()
- foreach ( $skin->getDefaultModules() as $group ) {
- $outputPage->addModules( $group );
- }
+ $outputPage->loadSkinModules( $skin );
}
Hooks::run( 'ApiParseMakeOutputPage', [ $this, $outputPage ] );
* It is recommended that skins wishing to override call parent::getDefaultModules()
* and substitute out any modules they wish to change by using a key to look them up
*
- * For style modules, use setupSkinUserCss() instead.
+ * Any modules defined with the 'styles' key will be added as render blocking CSS via
+ * Output::addModuleStyles. Similarly, each key should refer to a list of modules
*
* @return array Array of modules with helper keys for easy overriding
*/
$config = $this->getConfig();
$user = $out->getUser();
$modules = [
+ // Styles key sets render blocking styles
+ // Unlike other keys in this definition it is an associative array
+ // where each key is the group name and points to a list of modules
+ 'styles' => [],
// modules not specific to any specific skin or page
'core' => [
// Enforce various default modules for all pages and all skins
--- /dev/null
+<?php
+class SkinTest extends MediaWikiTestCase {
+
+ /**
+ * @covers Skin::getDefaultModules
+ */
+ public function testGetDefaultModules() {
+ $skin = $this->getMockBuilder( Skin::class )
+ ->setMethods( [ 'outputPage', 'setupSkinUserCss' ] )
+ ->getMock();
+
+ $modules = $skin->getDefaultModules();
+ $this->assertTrue( isset( $modules['core'] ), 'core key is set by default' );
+ $this->assertTrue( isset( $modules['styles'] ), 'style key is set by default' );
+ }
+}