OutputPage: Apply target and origin filter to exempt modules
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 16 Aug 2016 22:25:08 +0000 (15:25 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 16 Aug 2016 22:56:02 +0000 (15:56 -0700)
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
includes/resourceloader/ResourceLoaderClientHtml.php

index cc377bc..f5a37d4 100644 (file)
@@ -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
                );
index 3093cde..dc70af4 100644 (file)
@@ -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,