Merge "Segregate right to edit sitewide CSS/JS"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderClientHtml.php
index 479a263..8d08366 100644 (file)
@@ -18,6 +18,7 @@
  * @file
  */
 
+use Wikimedia\WrappedString;
 use Wikimedia\WrappedStringList;
 
 /**
@@ -57,7 +58,8 @@ class ResourceLoaderClientHtml {
        /**
         * @param ResourceLoaderContext $context
         * @param array $options [optional] Array of options
-        *  - 'target': Custom parameter passed to StartupModule.
+        *  - 'target': Parameter for modules=startup request, see ResourceLoaderStartUpModule.
+        *  - 'safemode': Parameter for modules=startup request, see ResourceLoaderStartUpModule.
         *  - 'nonce': From OutputPage::getCSPNonce().
         */
        public function __construct( ResourceLoaderContext $context, array $options = [] ) {
@@ -65,6 +67,7 @@ class ResourceLoaderClientHtml {
                $this->resourceLoader = $context->getResourceLoader();
                $this->options = $options + [
                        'target' => null,
+                       'safemode' => null,
                        'nonce' => null,
                ];
        }
@@ -92,7 +95,6 @@ class ResourceLoaderClientHtml {
        /**
         * Ensure the styles of one or more modules are loaded.
         *
-        * @deprecated since 1.28
         * @param array $modules Array of module names
         */
        public function setModuleStyles( array $modules ) {
@@ -144,7 +146,7 @@ class ResourceLoaderClientHtml {
                                'general' => [],
                        ],
                        // Deprecations for style-only modules
-                       'styledeprecations' => [],
+                       'styleDeprecations' => [],
                ];
 
                foreach ( $this->modules as $name ) {
@@ -211,7 +213,7 @@ class ResourceLoaderClientHtml {
                        }
                        $deprecation = $module->getDeprecationInformation();
                        if ( $deprecation ) {
-                               $data['styledeprecations'][] = $deprecation;
+                               $data['styleDeprecations'][] = $deprecation;
                        }
                }
 
@@ -316,14 +318,6 @@ class ResourceLoaderClientHtml {
                        );
                }
 
-               // Deprecations for only=styles modules
-               if ( $data['styledeprecations'] ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               implode( '', $data['styledeprecations'] ),
-                               $nonce
-                       );
-               }
-
                // External stylesheets (only=styles)
                if ( $data['styles'] ) {
                        $chunks[] = $this->getLoad(
@@ -344,9 +338,12 @@ class ResourceLoaderClientHtml {
 
                // Async scripts. Once the startup is loaded, inline RLQ scripts will run.
                // Pass-through a custom 'target' from OutputPage (T143066).
-               $startupQuery = $this->options['target'] !== null
-                       ? [ 'target' => (string)$this->options['target'] ]
-                       : [];
+               $startupQuery = [];
+               foreach ( [ 'target', 'safemode' ] as $param ) {
+                       if ( $this->options[$param] !== null ) {
+                               $startupQuery[$param] = (string)$this->options[$param];
+                       }
+               }
                $chunks[] = $this->getLoad(
                        'startup',
                        ResourceLoaderModule::TYPE_SCRIPTS,
@@ -354,14 +351,25 @@ class ResourceLoaderClientHtml {
                        $startupQuery
                );
 
-               return WrappedStringList::join( "\n", $chunks );
+               return WrappedString::join( "\n", $chunks );
        }
 
        /**
         * @return string|WrappedStringList HTML
         */
        public function getBodyHtml() {
-               return '';
+               $data = $this->getData();
+               $chunks = [];
+
+               // Deprecations for only=styles modules
+               if ( $data['styleDeprecations'] ) {
+                       $chunks[] = ResourceLoader::makeInlineScript(
+                               implode( '', $data['styleDeprecations'] ),
+                               $this->options['nonce']
+                       );
+               }
+
+               return WrappedString::join( "\n", $chunks );
        }
 
        private function getContext( $group, $type ) {
@@ -397,7 +405,8 @@ class ResourceLoaderClientHtml {
         * @param array $modules One or more module names
         * @param string $only ResourceLoaderModule TYPE_ class constant
         * @param array $extraQuery [optional] Array with extra query parameters for the request
-        * @param string $nonce [optional] Content-Security-Policy nonce (from OutputPage::getCSPNonce)
+        * @param string|null $nonce [optional] Content-Security-Policy nonce
+        *  (from OutputPage::getCSPNonce)
         * @return string|WrappedStringList HTML
         */
        public static function makeLoad( ResourceLoaderContext $mainContext, array $modules, $only,