* @file
*/
+use Wikimedia\WrappedString;
use Wikimedia\WrappedStringList;
/**
/**
* @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 = [] ) {
$this->resourceLoader = $context->getResourceLoader();
$this->options = $options + [
'target' => null,
+ 'safemode' => null,
'nonce' => null,
];
}
/**
* 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 ) {
'general' => [],
],
// Deprecations for style-only modules
- 'styledeprecations' => [],
+ 'styleDeprecations' => [],
];
foreach ( $this->modules as $name ) {
}
$deprecation = $module->getDeprecationInformation();
if ( $deprecation ) {
- $data['styledeprecations'][] = $deprecation;
+ $data['styleDeprecations'][] = $deprecation;
}
}
);
}
- // 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(
// 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,
$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 ) {
* @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,