From 4ed96c1dde5ea1afa12355590de7d01ab23151e6 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 16 Aug 2016 15:25:08 -0700 Subject: [PATCH] OutputPage: Apply target and origin filter to exempt modules Follows-up 80e5b160e, which moved filter logic to getRlClient() so that ResourceLoaderClientHtml doesn't have to deal with this. While that worked fine for most modules (including 'site'), it no longer applied the filter for exempt/hardcoded modules (such as 'site.styles' and 'startup'). Bug: T143066 Change-Id: Iec924003873bc47484a0dc2f1a215f87aa4afdfb --- includes/OutputPage.php | 7 +++++-- .../ResourceLoaderClientHtml.php | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index cc377bc6ea..f5a37d460a 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2671,7 +2671,7 @@ class OutputPage extends ContextSource { 'user.options', 'user.tokens', ] ); - $rlClient = new ResourceLoaderClientHtml( $context ); + $rlClient = new ResourceLoaderClientHtml( $context, $this->getTarget() ); $rlClient->setConfig( $this->getJSVars() ); $rlClient->setModules( $this->getModules( /*filter*/ true ) ); $rlClient->setModuleStyles( $this->getModuleStyles( /*filter*/ true ) ); @@ -2790,9 +2790,12 @@ class OutputPage extends ContextSource { * @return string|WrappedStringList HTML */ public function makeResourceLoaderLink( $modules, $only, array $extraQuery = [] ) { + // Apply 'target' and 'origin' filters + $modules = $this->filterModules( (array)$modules, null, $only ); + return ResourceLoaderClientHtml::makeLoad( $this->getRlClientContext(), - (array)$modules, + $modules, $only, $extraQuery ); diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index 3093cdef10..dc70af458e 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -33,6 +33,9 @@ class ResourceLoaderClientHtml { /** @var ResourceLoader */ private $resourceLoader; + /** @var string|null */ + private $target; + /** @var array */ private $config = []; @@ -53,10 +56,12 @@ class ResourceLoaderClientHtml { /** * @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; } /** @@ -316,7 +321,13 @@ class ResourceLoaderClientHtml { } // 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 ); } @@ -358,8 +369,8 @@ class ResourceLoaderClientHtml { 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, -- 2.20.1