Only queue gadget module if relevant on the current target

Bug: T171180
Depends-On: Ibe693bb6a84bdf56fd22d1ea1f0b798094b91c62
Change-Id: Ibce4d642c87651880f3c981dfa0d68def3bddd3a
This commit is contained in:
Derk-Jan Hartman 2018-07-28 22:26:38 +02:00 committed by Jdlrobson
parent c9e4a54ec4
commit 2008def806
2 changed files with 13 additions and 2 deletions

View file

@ -160,7 +160,6 @@ class GadgetHooks {
* @var $gadget Gadget
*/
$user = $out->getUser();
$skin = $out->getSkin();
foreach ( $ids as $id ) {
try {
$gadget = $repo->getGadget( $id );
@ -178,7 +177,8 @@ class GadgetHooks {
}
if ( $gadget->isEnabled( $user )
&& $gadget->isAllowed( $user )
&& $gadget->isSkinSupported( $skin )
&& $gadget->isSkinSupported( $out->getSkin() )
&& ( in_array( $out->getTarget() ?? 'desktop', $gadget->getTargets() ) )
) {
if ( $gadget->hasModule() ) {
if ( $gadget->getType() === 'styles' ) {

View file

@ -101,6 +101,17 @@ class GadgetTest extends MediaWikiUnitTestCase {
$this->assertFalse( $gSkinNotSupported->isSkinSupported( $skin ) );
}
/**
* @covers MediaWikiGadgetsDefinitionRepo::newFromDefinition
* @covers Gadget::getTargets
*/
public function testTargets() {
$g = $this->create( '*foo[ResourceLoader]|foo.js' );
$g2 = $this->create( '*bar[ResourceLoader|targets=desktop,mobile]|bar.js' );
$this->assertEquals( [ 'desktop' ], $g->getTargets() );
$this->assertEquals( [ 'desktop', 'mobile' ], $g2->getTargets() );
}
/**
* @covers MediaWikiGadgetsDefinitionRepo::newFromDefinition
* @covers Gadget::getDependencies