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 only=scripts
- if ( $data['scripts'] ) {
- $chunks[] = $this->getLoad(
- $data['scripts'],
- ResourceLoaderModule::TYPE_SCRIPTS,
- $nonce
- );
- }
-
// External stylesheets (only=styles)
if ( $data['styles'] ) {
$chunks[] = $this->getLoad(
// Decide whether to use 'style' or 'script' element
if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
$chunk = Html::linkedStyle( $url );
+ } elseif ( $context->getRaw() || $isRaw ) {
+ $chunk = Html::element( 'script', [
+ // In SpecialJavaScriptTest, QUnit must load synchronous
+ 'async' => !isset( $extraQuery['sync'] ),
+ 'src' => $url
+ ] );
} else {
- if ( $context->getRaw() || $isRaw ) {
- $chunk = Html::element( 'script', [
- // In SpecialJavaScriptTest, QUnit must load synchronous
- 'async' => !isset( $extraQuery['sync'] ),
- 'src' => $url
- ] );
- } else {
- $chunk = ResourceLoader::makeInlineScript(
- Xml::encodeJsCall( 'mw.loader.load', [ $url ] ),
- $nonce
- );
- }
+ $chunk = ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'mw.loader.load', [ $url ] ),
+ $nonce
+ );
}
if ( $group == 'noscript' ) {