/** @var ResourceLoader */
private $resourceLoader;
+ /** @var string|null */
+ private $target;
+
/** @var array */
private $config = [];
/**
* @param ResourceLoaderContext $context
+ * @param aray $target [optional] Custom 'target' parameter for the startup module
*/
- public function __construct( ResourceLoaderContext $context ) {
+ public function __construct( ResourceLoaderContext $context, $target = null ) {
$this->context = $context;
$this->resourceLoader = $context->getResourceLoader();
+ $this->target = $target;
}
/**
}
// Async scripts. Once the startup is loaded, inline RLQ scripts will run.
- $chunks[] = $this->getLoad( 'startup', ResourceLoaderModule::TYPE_SCRIPTS );
+ // Pass-through a custom target from OutputPage (T143066).
+ $startupQuery = $this->target ? [ 'target' => $this->target ] : [];
+ $chunks[] = $this->getLoad(
+ 'startup',
+ ResourceLoaderModule::TYPE_SCRIPTS,
+ $startupQuery
+ );
return WrappedStringList::join( "\n", $chunks );
}
return self::makeContext( $this->context, $group, $type );
}
- private function getLoad( $modules, $only ) {
- return self::makeLoad( $this->context, (array)$modules, $only );
+ private function getLoad( $modules, $only, array $extraQuery = [] ) {
+ return self::makeLoad( $this->context, (array)$modules, $only, $extraQuery );
}
private static function makeContext( ResourceLoaderContext $mainContext, $group, $type,
foreach ( $sortedModules as $source => $groups ) {
foreach ( $groups as $group => $grpModules ) {
$context = self::makeContext( $mainContext, $group, $only, $extraQuery );
+ $context->setModules( array_keys( $grpModules ) );
if ( $group === 'private' ) {
// Decide whether to use style or script element
// This should NOT be done for the site group (bug 27564) because anons get that too
// and we shouldn't be putting timestamps in CDN-cached HTML
if ( $group === 'user' ) {
- $version = $rl->getCombinedVersion( $context, array_keys( $grpModules ) );
- $context->setVersion( $version );
+ // Must setModules() before makeVersionQuery()
+ $context->setVersion( $rl->makeVersionQuery( $context ) );
}
- $context->setModules( array_keys( $grpModules ) );
$url = $rl->createLoaderURL( $source, $context, $extraQuery );
// Decide whether to use 'style' or 'script' element