From 990cb75cc469784e149f03abd1653e9646a62ea2 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Thu, 14 Feb 2013 21:05:22 +0400 Subject: [PATCH] Add RL targets support to OutputPage The target URI parameter is already used by ResourceLoaderStartUpModule to filter modules, this change introduces the ability to produce mobile-aware load.php links in the core and filter out modules not suitable for current target. Change-Id: Ie03990e11d9a0ac8cd81dd0aae5c5a95f1d23e81 --- includes/OutputPage.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 905b005521..81a00ecd4b 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -253,6 +253,11 @@ class OutputPage extends ContextSource { */ private $mProperties = array(); + /** + * @var string|null: ResourceLoader target for load.php links. If null, will be omitted + */ + private $mTarget = null; + /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -451,7 +456,8 @@ class OutputPage extends ContextSource { $module = $resourceLoader->getModule( $val ); if( $module instanceof ResourceLoaderModule && $module->getOrigin() <= $this->getAllowedModules( $type ) - && ( is_null( $position ) || $module->getPosition() == $position ) ) + && ( is_null( $position ) || $module->getPosition() == $position ) + && ( !$this->mTarget || in_array( $this->mTarget, $module->getTargets() ) ) ) { $filteredModules[] = $val; } @@ -556,6 +562,22 @@ class OutputPage extends ContextSource { $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules ); } + /** + * @return null|string: ResourceLoader target + */ + public function getTarget() { + return $this->mTarget; + } + + /** + * Sets ResourceLoader target for load.php links. If null, will be omitted + * + * @param $target string|null + */ + public function setTarget( $target ) { + $this->mTarget = $target; + } + /** * Get an array of head items * @@ -2600,6 +2622,9 @@ $templates return $links; } } + if ( !is_null( $this->mTarget ) ) { + $extraQuery['target'] = $this->mTarget; + } // Create keyed-by-group list of module objects from modules list $groups = array(); @@ -2612,6 +2637,7 @@ $templates && $only == ResourceLoaderModule::TYPE_SCRIPTS ) || ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_STYLES ) && $only == ResourceLoaderModule::TYPE_STYLES ) + || ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) ) { continue; -- 2.20.1