Merge "resourceloader: Allow style-only modules to have deprecation warnings"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderClientHtml.php
index d0a9c42..479a263 100644 (file)
@@ -58,11 +58,15 @@ class ResourceLoaderClientHtml {
         * @param ResourceLoaderContext $context
         * @param array $options [optional] Array of options
         *  - 'target': Custom parameter passed to StartupModule.
+        *  - 'nonce': From OutputPage::getCSPNonce().
         */
        public function __construct( ResourceLoaderContext $context, array $options = [] ) {
                $this->context = $context;
                $this->resourceLoader = $context->getResourceLoader();
-               $this->options = $options;
+               $this->options = $options + [
+                       'target' => null,
+                       'nonce' => null,
+               ];
        }
 
        /**
@@ -139,7 +143,8 @@ class ResourceLoaderClientHtml {
                                'styles' => [],
                                'general' => [],
                        ],
-
+                       // Deprecations for style-only modules
+                       'styledeprecations' => [],
                ];
 
                foreach ( $this->modules as $name ) {
@@ -204,6 +209,10 @@ class ResourceLoaderClientHtml {
                                        $data['styles'][] = $name;
                                }
                        }
+                       $deprecation = $module->getDeprecationInformation();
+                       if ( $deprecation ) {
+                               $data['styledeprecations'][] = $deprecation;
+                       }
                }
 
                foreach ( $this->moduleScripts as $name ) {
@@ -248,10 +257,10 @@ class ResourceLoaderClientHtml {
         * - Inline scripts can't be asynchronous.
         * - For styles, earlier is better.
         *
-        * @param string $nonce From OutputPage::getCSPNonce()
         * @return string|WrappedStringList HTML
         */
-       public function getHeadHtml( $nonce ) {
+       public function getHeadHtml() {
+               $nonce = $this->options['nonce'];
                $data = $this->getData();
                $chunks = [];
 
@@ -307,7 +316,15 @@ class ResourceLoaderClientHtml {
                        );
                }
 
-               // External stylesheets
+               // 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(
                                $data['styles'],
@@ -327,7 +344,7 @@ class ResourceLoaderClientHtml {
 
                // Async scripts. Once the startup is loaded, inline RLQ scripts will run.
                // Pass-through a custom 'target' from OutputPage (T143066).
-               $startupQuery = isset( $this->options['target'] )
+               $startupQuery = $this->options['target'] !== null
                        ? [ 'target' => (string)$this->options['target'] ]
                        : [];
                $chunks[] = $this->getLoad(
@@ -379,12 +396,12 @@ class ResourceLoaderClientHtml {
         * @param ResourceLoaderContext $mainContext
         * @param array $modules One or more module names
         * @param string $only ResourceLoaderModule TYPE_ class constant
-        * @param array $extraQuery Array with extra query parameters for the request
-        * @param string $nonce See OutputPage::getCSPNonce() [Since 1.32]
+        * @param array $extraQuery [optional] Array with extra query parameters for the request
+        * @param string $nonce [optional] Content-Security-Policy nonce (from OutputPage::getCSPNonce)
         * @return string|WrappedStringList HTML
         */
        public static function makeLoad( ResourceLoaderContext $mainContext, array $modules, $only,
-               array $extraQuery, $nonce
+               array $extraQuery = [], $nonce = null
        ) {
                $rl = $mainContext->getResourceLoader();
                $chunks = [];