Merge "EditPage: Declare 'mediawiki.toolbar' needed for inline script"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 7 Aug 2018 22:10:59 +0000 (22:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 7 Aug 2018 22:10:59 +0000 (22:10 +0000)
includes/EditPage.php
includes/resourceloader/ResourceLoader.php

index 127946c..5f9ce0b 100644 (file)
@@ -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 = '<div id="toolbar"></div>';
 
                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;
index aa632c3..a0acf1f 100644 (file)
@@ -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.
         *