OutputPage: Move hardcoded default modules to Skin::getDefaultModules
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 20 May 2017 13:07:37 +0000 (15:07 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 21 May 2017 17:06:43 +0000 (19:06 +0200)
These modules should not be hardcoded in OutputPage::output() which
makes them impossible to override and also very hard to retrieve
through the API for action=parse. Move these instead to Skin which
is where all other default module loading happens already.

Moving these modules is in preparation for customising ApiParse
to support "really" returning all would-be loaded modules on a page
when setting 'useskin', which is also needed for Live Preview
and in theory for ajax navigation and other scenarios where there
is a delay between the "initial" page rendering, and a later re-render
which may not have all all the necessary modules.

Bug: T130632
Change-Id: Ic4afccf0cd0d428d7fbc36d4e747415af3ab49f5

includes/OutputPage.php
includes/skins/Skin.php

index e71cf18..ff80f1e 100644 (file)
@@ -2405,26 +2405,10 @@ class OutputPage extends ContextSource {
                        }
 
                        $sk = $this->getSkin();
-                       // add skin specific modules
-                       $modules = $sk->getDefaultModules();
-
-                       // Enforce various default modules for all pages and all skins
-                       $coreModules = [
-                               // Keep this list as small as possible
-                               'site',
-                               'mediawiki.page.startup',
-                               'mediawiki.user',
-                       ];
-
-                       // Support for high-density display images if enabled
-                       if ( $config->get( 'ResponsiveImages' ) ) {
-                               $coreModules[] = 'mediawiki.hidpi';
-                       }
-
-                       $this->addModules( $coreModules );
-                       foreach ( $modules as $group ) {
+                       foreach ( $sk->getDefaultModules() as $group ) {
                                $this->addModules( $group );
                        }
+
                        MWDebug::addModules( $this );
 
                        // Avoid PHP 7.1 warning of passing $this by reference
index 7f00767..2cd28b4 100644 (file)
@@ -158,8 +158,17 @@ abstract class Skin extends ContextSource {
                global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI;
 
                $out = $this->getOutput();
+               $config = $this->getConfig();
                $user = $out->getUser();
                $modules = [
+                       // modules not specific to any specific skin or page
+                       'core' => [
+                               // Enforce various default modules for all pages and all skins
+                               // Keep this list as small as possible
+                               'site',
+                               'mediawiki.page.startup',
+                               'mediawiki.user',
+                       ],
                        // modules that enhance the page content in some way
                        'content' => [
                                'mediawiki.page.ready',
@@ -172,6 +181,11 @@ abstract class Skin extends ContextSource {
                        'user' => [],
                ];
 
+               // Support for high-density display images if enabled
+               if ( $config->get( 'ResponsiveImages' ) ) {
+                       $modules['core'][] = 'mediawiki.hidpi';
+               }
+
                // Preload jquery.tablesorter for mediawiki.page.ready
                if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
                        $modules['content'][] = 'jquery.tablesorter';