use Wikimedia\WrappedStringList;
/**
- * Bootstrap a ResourceLoader client on an HTML page.
+ * Load and configure a ResourceLoader client on an HTML page.
*
* @since 1.28
*/
/** @var array */
private $moduleStyles = [];
- /** @var array */
- private $moduleScripts = [];
-
/** @var array */
private $exemptStates = [];
$this->moduleStyles = $modules;
}
- /**
- * Ensure the scripts of one or more modules are loaded.
- *
- * @deprecated since 1.28
- * @param array $modules Array of module names
- */
- public function setModuleScripts( array $modules ) {
- $this->moduleScripts = $modules;
- }
-
/**
* Set state of special modules that are handled by the caller manually.
*
],
'general' => [],
'styles' => [],
- 'scripts' => [],
// Embedding for private modules
'embed' => [
'styles' => [],
}
}
- foreach ( $this->moduleScripts as $name ) {
- $module = $rl->getModule( $name );
- if ( !$module ) {
- continue;
- }
-
- $group = $module->getGroup();
- $context = $this->getContext( $group, ResourceLoaderModule::TYPE_SCRIPTS );
- if ( $module->isKnownEmpty( $context ) ) {
- // Avoid needless request for empty module
- $data['states'][$name] = 'ready';
- } else {
- // Load from load.php?only=scripts via <script src></script>
- $data['scripts'][] = $name;
-
- // Avoid duplicate request from mw.loader
- $data['states'][$name] = 'loading';
- }
- }
-
return $data;
}
// Inline RLQ: Load general modules
if ( $data['general'] ) {
$chunks[] = ResourceLoader::makeInlineScript(
- Xml::encodeJsCall( 'mw.loader.load', [ $data['general'] ] ),
- $nonce
- );
- }
-
- // Inline RLQ: Load only=scripts
- if ( $data['scripts'] ) {
- $chunks[] = $this->getLoad(
- $data['scripts'],
- ResourceLoaderModule::TYPE_SCRIPTS,
+ 'RLPAGEMODULES='
+ . ResourceLoader::encodeJsonForScript( $data['general'] )
+ . ';'
+ . 'mw.loader.load(RLPAGEMODULES);',
$nonce
);
}