From fb997e13891685c49d98f27d7b445c303a22f73a Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 7 Aug 2018 19:45:10 +0100 Subject: [PATCH] EditPage: Declare 'mediawiki.toolbar' needed for inline script Switch from passing a plain function to RLQ that calls depends on using() from 'mediawiki.base' and 'jquery', to using the new array format introduced in Ica7bb9c3bdb (T192623). This ensures the code will keep after we change the fact that RLQ is blocked by base modules. Bug: T192623 Change-Id: Id50e6dcc28c13b021d8395a2da0d83b46f88e18c --- includes/EditPage.php | 9 +++++---- includes/resourceloader/ResourceLoader.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 127946c20e..5f9ce0b60f 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -4138,7 +4138,7 @@ ERROR; ] ]; - $script = 'mw.loader.using("mediawiki.toolbar", function () {'; + $script = ''; foreach ( $toolarray as $tool ) { if ( !$tool ) { continue; @@ -4165,15 +4165,16 @@ ERROR; ); } - $script .= '});'; - $toolbar = '
'; if ( Hooks::run( 'EditPageBeforeEditToolbar', [ &$toolbar ] ) ) { // Only add the old toolbar cruft to the page payload if the toolbar has not // been over-written by a hook caller $nonce = $wgOut->getCSPNonce(); - $wgOut->addScript( ResourceLoader::makeInlineScript( $script, $nonce ) ); + $wgOut->addScript( Html::inlineScript( + ResourceLoader::makeInlineCodeWithModule( 'mediawiki.toolbar', $script ), + $nonce + ) ); }; return $toolbar; diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index aa632c3c20..a0acf1f30b 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -1490,10 +1490,27 @@ MESSAGE; * @return string JavaScript code */ public static function makeLoaderConditionalScript( $script ) { + // Adds a function to lazy-created RLQ return '(window.RLQ=window.RLQ||[]).push(function(){' . trim( $script ) . '});'; } + /** + * Wraps JavaScript code to run after a required module. + * + * @since 1.32 + * @param string|string[] $modules Module name(s) + * @param string $script JavaScript code + * @return string JavaScript code + */ + public static function makeInlineCodeWithModule( $modules, $script ) { + // Adds an array to lazy-created RLQ + return '(window.RLQ=window.RLQ||[]).push([' + . json_encode( $modules ) . ',' + . 'function(){' . trim( $script ) . '}' + . ']);'; + } + /** * Returns an HTML script tag that runs given JS code after startup and base modules. * -- 2.20.1