2010-11-11 18:19:57 +00:00
|
|
|
<?php
|
2017-04-19 21:38:48 +00:00
|
|
|
|
2022-02-06 18:54:47 +00:00
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
/**
|
|
|
|
* @group Gadgets
|
|
|
|
*/
|
2019-07-22 08:34:21 +00:00
|
|
|
class GadgetTest extends MediaWikiUnitTestCase {
|
2022-08-16 15:24:01 +00:00
|
|
|
use GadgetTestTrait;
|
2022-08-27 10:54:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::toArray
|
|
|
|
*/
|
|
|
|
public function testToArray() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '*bar[ResourceLoader|rights=test]|bar.js|foo.css | foo.json' );
|
2022-08-27 10:54:28 +00:00
|
|
|
$gNewFromSerialized = new Gadget( $g->toArray() );
|
|
|
|
$this->assertArrayEquals( $g->toArray(), $gNewFromSerialized->toArray() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::serializeDefinition
|
|
|
|
*/
|
|
|
|
public function testGadgetFromDefinitionContent() {
|
|
|
|
$gArray = Gadget::serializeDefinition( 'bar', [
|
|
|
|
'settings' => [
|
|
|
|
'rights' => [],
|
|
|
|
'default' => true,
|
|
|
|
'package' => true,
|
|
|
|
'hidden' => false,
|
|
|
|
'actions' => [],
|
|
|
|
'targets' => [ 'desktop' ],
|
|
|
|
'skins' => [],
|
2020-09-04 03:42:31 +00:00
|
|
|
'namespaces' => [],
|
2023-05-22 08:41:15 +00:00
|
|
|
'contentModels' => [],
|
2022-08-27 10:54:28 +00:00
|
|
|
'category' => 'misc',
|
|
|
|
'supportsUrlLoad' => false,
|
|
|
|
'requiresES6' => false,
|
|
|
|
],
|
|
|
|
'module' => [
|
2023-12-11 17:16:30 +00:00
|
|
|
'pages' => [ 'foo.js', 'bar.css' ],
|
2022-08-27 10:54:28 +00:00
|
|
|
'datas' => [],
|
|
|
|
'dependencies' => [ 'moment' ],
|
|
|
|
'peers' => [],
|
|
|
|
'messages' => [ 'blanknamespace' ],
|
|
|
|
'type' => 'general',
|
|
|
|
]
|
|
|
|
] );
|
|
|
|
|
|
|
|
$g = new Gadget( $gArray );
|
|
|
|
|
|
|
|
$this->assertTrue( $g->isOnByDefault() );
|
|
|
|
$this->assertTrue( $g->isPackaged() );
|
|
|
|
$this->assertFalse( $g->isHidden() );
|
|
|
|
$this->assertFalse( $g->supportsUrlLoad() );
|
|
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
|
|
|
$this->assertCount( 1, $g->getScripts() );
|
|
|
|
$this->assertCount( 1, $g->getStyles() );
|
|
|
|
$this->assertCount( 0, $g->getJSONs() );
|
|
|
|
$this->assertCount( 1, $g->getDependencies() );
|
|
|
|
$this->assertCount( 1, $g->getMessages() );
|
2023-09-20 21:39:45 +00:00
|
|
|
|
|
|
|
// Ensure parity and internal consistency
|
|
|
|
// between Gadget::serializeDefinition and Gadget::toArray
|
|
|
|
$arr = $g->toArray();
|
|
|
|
unset( $arr['definition'] );
|
|
|
|
$this->assertSame( $arr, $gArray );
|
2022-08-27 10:54:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:08:41 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
2018-01-05 00:08:41 +00:00
|
|
|
*/
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testInvalidLines() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$this->assertFalse( $this->makeGadget( '' ) );
|
|
|
|
$this->assertFalse( $this->makeGadget( '<foo|bar>' ) );
|
2010-11-11 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:08:41 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget
|
2018-01-05 00:08:41 +00:00
|
|
|
*/
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testSimpleCases() {
|
2023-12-11 17:16:30 +00:00
|
|
|
$g = $this->makeGadget( '* foo bar| foo.css|foo.js|foo.json|foo.bar' );
|
2010-11-11 18:19:57 +00:00
|
|
|
$this->assertEquals( 'foo_bar', $g->getName() );
|
2015-08-03 06:37:32 +00:00
|
|
|
$this->assertEquals( 'ext.gadget.foo_bar', Gadget::getModuleName( $g->getName() ) );
|
2016-12-28 10:25:47 +00:00
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
|
2023-12-11 17:16:30 +00:00
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.json' ], $g->getJSONs() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.js', 'MediaWiki:Gadget-foo.css', 'MediaWiki:Gadget-foo.json' ],
|
|
|
|
$g->getScriptsAndStyles() );
|
2016-12-28 10:25:47 +00:00
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.js' ], $g->getLegacyScripts() );
|
2010-11-11 18:19:57 +00:00
|
|
|
$this->assertFalse( $g->supportsResourceLoader() );
|
|
|
|
$this->assertTrue( $g->hasModule() );
|
|
|
|
}
|
|
|
|
|
2018-01-05 00:08:41 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::supportsResourceLoader
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::getLegacyScripts
|
2018-01-05 00:08:41 +00:00
|
|
|
*/
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testRLtag() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '*foo [ResourceLoader]|foo.js|foo.css' );
|
2010-11-11 18:19:57 +00:00
|
|
|
$this->assertEquals( 'foo', $g->getName() );
|
|
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
2021-01-29 11:15:45 +00:00
|
|
|
$this->assertCount( 0, $g->getLegacyScripts() );
|
2010-11-11 18:19:57 +00:00
|
|
|
}
|
2010-11-13 18:45:21 +00:00
|
|
|
|
2021-10-17 13:05:15 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget
|
2021-10-17 13:05:15 +00:00
|
|
|
*/
|
|
|
|
public function testPackaged() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '* foo bar[ResourceLoader|package]| foo.css|foo.js|foo.bar|foo.json' );
|
2021-10-17 13:05:15 +00:00
|
|
|
$this->assertEquals( 'foo_bar', $g->getName() );
|
|
|
|
$this->assertEquals( 'ext.gadget.foo_bar', Gadget::getModuleName( $g->getName() ) );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.json' ], $g->getJSONs() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-foo.js', 'MediaWiki:Gadget-foo.css', 'MediaWiki:Gadget-foo.json' ],
|
|
|
|
$g->getScriptsAndStyles() );
|
|
|
|
$this->assertEquals( [], $g->getLegacyScripts() );
|
|
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
|
|
|
$this->assertTrue( $g->hasModule() );
|
|
|
|
}
|
|
|
|
|
2022-01-11 09:03:44 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget
|
2022-01-11 09:03:44 +00:00
|
|
|
*/
|
|
|
|
public function testSupportsUrlLoad() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$directLoadAllowedByDefault = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$directLoadAllowed1 = $this->makeGadget( '*bar[ResourceLoader|supportsUrlLoad]|bar.js' );
|
|
|
|
$directLoadAllowed2 = $this->makeGadget( '*bar[ResourceLoader|supportsUrlLoad=true]|bar.js' );
|
|
|
|
$directLoadNotAllowed = $this->makeGadget( '*baz[ResourceLoader|supportsUrlLoad=false]|baz.js' );
|
2022-01-11 09:03:44 +00:00
|
|
|
|
|
|
|
$this->assertFalse( $directLoadAllowedByDefault->supportsUrlLoad() );
|
|
|
|
$this->assertTrue( $directLoadAllowed1->supportsUrlLoad() );
|
|
|
|
$this->assertTrue( $directLoadAllowed2->supportsUrlLoad() );
|
|
|
|
$this->assertFalse( $directLoadNotAllowed->supportsUrlLoad() );
|
|
|
|
}
|
|
|
|
|
2016-07-20 06:27:26 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isAllowed
|
2016-07-20 06:27:26 +00:00
|
|
|
*/
|
2019-07-22 08:34:21 +00:00
|
|
|
public function testIsAllowed() {
|
|
|
|
$user = $this->getMockBuilder( User::class )
|
2021-05-04 07:24:31 +00:00
|
|
|
->onlyMethods( [ 'isAllowedAll' ] )
|
2019-07-22 08:34:21 +00:00
|
|
|
->getMock();
|
|
|
|
$user->method( 'isAllowedAll' )
|
|
|
|
->willReturnCallback(
|
2021-05-04 07:24:31 +00:00
|
|
|
static function ( ...$rights ) {
|
2019-07-22 08:34:21 +00:00
|
|
|
return array_diff( $rights, [ 'test' ] ) === [];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var User $user */
|
2022-08-16 15:24:01 +00:00
|
|
|
$gUnset = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$gAllowed = $this->makeGadget( '*bar[ResourceLoader|rights=test]|bar.js' );
|
|
|
|
$gNotAllowed = $this->makeGadget( '*baz[ResourceLoader|rights=nope]|baz.js' );
|
2019-07-22 08:34:21 +00:00
|
|
|
$this->assertTrue( $gUnset->isAllowed( $user ) );
|
|
|
|
$this->assertTrue( $gAllowed->isAllowed( $user ) );
|
|
|
|
$this->assertFalse( $gNotAllowed->isAllowed( $user ) );
|
2016-07-20 06:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isSkinSupported
|
2016-07-20 06:27:26 +00:00
|
|
|
*/
|
|
|
|
public function testSkinsTag() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$gUnset = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$gSkinSupported = $this->makeGadget( '*bar[ResourceLoader|skins=fallback]|bar.js' );
|
|
|
|
$gSkinNotSupported = $this->makeGadget( '*baz[ResourceLoader|skins=bar]|baz.js' );
|
2016-07-20 06:27:26 +00:00
|
|
|
$skin = new SkinFallback();
|
|
|
|
$this->assertTrue( $gUnset->isSkinSupported( $skin ) );
|
|
|
|
$this->assertTrue( $gSkinSupported->isSkinSupported( $skin ) );
|
|
|
|
$this->assertFalse( $gSkinNotSupported->isSkinSupported( $skin ) );
|
|
|
|
}
|
|
|
|
|
2021-12-14 13:10:22 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isActionSupported
|
2021-12-14 13:10:22 +00:00
|
|
|
*/
|
|
|
|
public function testActionsTag() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$gUnset = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$gActionSupported = $this->makeGadget( '*bar[ResourceLoader|actions=edit]|bar.js' );
|
|
|
|
$gActionNotSupported = $this->makeGadget( '*baz[ResourceLoader|actions=history]|baz.js' );
|
2021-12-14 13:10:22 +00:00
|
|
|
$this->assertTrue( $gUnset->isActionSupported( 'edit' ) );
|
|
|
|
$this->assertTrue( $gActionSupported->isActionSupported( 'edit' ) );
|
|
|
|
$this->assertFalse( $gActionNotSupported->isActionSupported( 'edit' ) );
|
|
|
|
|
|
|
|
// special case
|
|
|
|
$this->assertTrue( $gActionSupported->isActionSupported( 'submit' ) );
|
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
$gMultiActions = $this->makeGadget( '*bar[ResourceLoader|actions=unknown,history]|bar.js' );
|
2021-12-14 13:10:22 +00:00
|
|
|
$this->assertTrue( $gMultiActions->isActionSupported( 'history' ) );
|
|
|
|
$this->assertFalse( $gMultiActions->isActionSupported( 'view' ) );
|
|
|
|
}
|
|
|
|
|
2020-09-04 03:42:31 +00:00
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isNamespaceSupported
|
|
|
|
*/
|
|
|
|
public function testNamespacesTag() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$gUnsetNamespace = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$gNamespace0 = $this->makeGadget( '*bar[ResourceLoader|namespaces=0]|bar.js' );
|
|
|
|
$gNamespace1 = $this->makeGadget( '*bar[ResourceLoader|namespaces=1]|bar.js' );
|
|
|
|
$gMultiNamespace = $this->makeGadget( '*bar[ResourceLoader|namespaces=1,2,3,4]|bar.js' );
|
2020-09-04 03:42:31 +00:00
|
|
|
|
|
|
|
$this->assertTrue( $gUnsetNamespace->isNamespaceSupported( 5 ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $gNamespace0->isNamespaceSupported( 0 ) );
|
|
|
|
$this->assertFalse( $gNamespace0->isNamespaceSupported( 2 ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $gNamespace1->isNamespaceSupported( 1 ) );
|
|
|
|
$this->assertFalse( $gNamespace1->isNamespaceSupported( 2 ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $gMultiNamespace->isNamespaceSupported( 1 ) );
|
|
|
|
$this->assertTrue( $gMultiNamespace->isNamespaceSupported( 2 ) );
|
|
|
|
$this->assertFalse( $gMultiNamespace->isNamespaceSupported( 5 ) );
|
|
|
|
}
|
|
|
|
|
2023-05-22 08:41:15 +00:00
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isContentModelSupported
|
|
|
|
*/
|
|
|
|
public function testContentModelsTags() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$gUnsetModel = $this->makeGadget( '*foo[ResourceLoader]|foo.js' );
|
|
|
|
$gModelWikitext = $this->makeGadget( '*bar[ResourceLoader|contentModels=wikitext]|bar.js' );
|
|
|
|
$gModelCode = $this->makeGadget( '*bar[ResourceLoader|contentModels=javascript,css]|bar.js' );
|
2023-05-22 08:41:15 +00:00
|
|
|
|
|
|
|
$this->assertTrue( $gUnsetModel->isContentModelSupported( 'wikitext' ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $gModelWikitext->isContentModelSupported( 'wikitext' ) );
|
|
|
|
$this->assertFalse( $gModelWikitext->isContentModelSupported( 'javascript' ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $gModelCode->isContentModelSupported( 'javascript' ) );
|
|
|
|
$this->assertTrue( $gModelCode->isContentModelSupported( 'css' ) );
|
|
|
|
$this->assertFalse( $gModelCode->isContentModelSupported( 'wikitext' ) );
|
|
|
|
}
|
|
|
|
|
2018-07-28 20:26:38 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
2018-07-28 20:26:38 +00:00
|
|
|
*/
|
2023-06-29 00:57:04 +00:00
|
|
|
public function testGadgetTargets() {
|
|
|
|
$gadget = new Gadget( [
|
|
|
|
'targets' => [ 'desktop' ]
|
|
|
|
] );
|
|
|
|
|
|
|
|
$this->assertFalse( $gadget->isTargetSupported( true ),
|
|
|
|
'Desktop-targeted code is not shipped in mobile mode.' );
|
|
|
|
$this->assertTrue( $gadget->isTargetSupported( false ),
|
|
|
|
'Desktop-targeted code is shipped in desktop mode.' );
|
2018-07-28 20:26:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:08:41 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::getDependencies
|
2018-01-05 00:08:41 +00:00
|
|
|
*/
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testDependencies() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
|
2016-12-28 10:25:47 +00:00
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-bar.js' ], $g->getScripts() );
|
2010-11-13 18:45:21 +00:00
|
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
2016-12-28 10:25:47 +00:00
|
|
|
$this->assertEquals( [ 'jquery.ui' ], $g->getDependencies() );
|
2010-11-13 18:45:21 +00:00
|
|
|
}
|
2011-04-03 19:01:52 +00:00
|
|
|
|
2022-01-30 13:15:25 +00:00
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::requiresES6
|
|
|
|
*/
|
|
|
|
public function testES6() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$es6gadget = $this->makeGadget( '* foo[ResourceLoader|requiresES6]|bar.js' );
|
|
|
|
$es5gadget = $this->makeGadget( '* foo[ResourceLoader]|bar.js' );
|
2022-01-30 13:15:25 +00:00
|
|
|
$this->assertTrue( $es6gadget->requiresES6() );
|
|
|
|
$this->assertFalse( $es5gadget->requiresES6() );
|
|
|
|
}
|
|
|
|
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
public static function provideGetType() {
|
2016-12-28 10:25:47 +00:00
|
|
|
return [
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Default (mixed)',
|
|
|
|
'* foo[ResourceLoader]|bar.css|bar.js',
|
2017-05-12 17:37:49 +00:00
|
|
|
'general',
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Default (styles only)',
|
|
|
|
'* foo[ResourceLoader]|bar.css',
|
|
|
|
'styles',
|
|
|
|
ResourceLoaderModule::LOAD_STYLES,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Default (scripts only)',
|
|
|
|
'* foo[ResourceLoader]|bar.js',
|
|
|
|
'general',
|
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
2016-11-17 01:53:10 +00:00
|
|
|
'Default (styles only with dependencies)',
|
|
|
|
'* foo[ResourceLoader|dependencies=jquery.ui]|bar.css',
|
2017-05-12 17:37:49 +00:00
|
|
|
'general',
|
2016-11-17 01:53:10 +00:00
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Styles type (mixed)',
|
|
|
|
'* foo[ResourceLoader|type=styles]|bar.css|bar.js',
|
|
|
|
'styles',
|
|
|
|
ResourceLoaderModule::LOAD_STYLES,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Styles type (styles only)',
|
|
|
|
'* foo[ResourceLoader|type=styles]|bar.css',
|
|
|
|
'styles',
|
|
|
|
ResourceLoaderModule::LOAD_STYLES,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'Styles type (scripts only)',
|
|
|
|
'* foo[ResourceLoader|type=styles]|bar.js',
|
|
|
|
'styles',
|
|
|
|
ResourceLoaderModule::LOAD_STYLES,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'General type (mixed)',
|
|
|
|
'* foo[ResourceLoader|type=general]|bar.css|bar.js',
|
|
|
|
'general',
|
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'General type (styles only)',
|
|
|
|
'* foo[ResourceLoader|type=general]|bar.css',
|
|
|
|
'general',
|
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
[
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
'General type (scripts only)',
|
|
|
|
'* foo[ResourceLoader|type=general]|bar.js',
|
|
|
|
'general',
|
|
|
|
ResourceLoaderModule::LOAD_GENERAL,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
];
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetType
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::getType
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule::getType
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
*/
|
|
|
|
public function testType( $message, $definition, $gType, $mType ) {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( $definition );
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
$this->assertEquals( $gType, $g->getType(), "Gadget: $message" );
|
2022-08-16 15:24:01 +00:00
|
|
|
$this->assertEquals( $mType, $this->makeGadgetModule( $g )->getType(), "Module: $message" );
|
Implement support for specifying type=styles
T87871 formally introduced the concept of a styles module,
which sets mw.loader.state to "ready" when loaded through addModuleStyles().
Previously, addModuleStyles couldn't safely do that because a module may
contain scripts also, in which case mw.loader must still load the (rest)
of the module (causes styles to load twice).
In MediaWiki core or extensions this is easily avoided by calling not
calling both addModules() and addModuleStyles().
For Gadgets we call both as a workaround to allow users to provide styles
(without a FOUC), but also to provide scripts+styles. Since we don't declare
which one is intended (and some gadgets do both), we loaded them both ways.
This will no longer be allowed in the future (see T92459).
The new 'type=styles' Gadget attribute promises to ResourceLoader that a
gadget only contains styles.
Impact:
* [Bug fix] When mw.loader requires a styles module that already loaded,
it will not load again.
* [Feature] It is possible for a general scripts+styles gadget to depend on
a styles gadget. Previously this caused the styles to load twice.
* Specifying type=styles will load the module through addModuleStyles() only.
Use this for modules that contain styles that relate to elements already
on the page (e.g. when customising the skin, layout, or article content).
* Specifying type=general will load the module through addModules() only.
Use this if your module contains both scripts and styles and the styles
only relate to elements created by the script. This means the styles do not
need to be loaded separately through addModuleStyles() and will not apply
to noscript mode.
Effective difference:
* Gadgets with only styles: We assume type=styles.
This fixes the main bug (styles loading twice) and requires no migration!
* Gadgets with only scripts: We assume type=general.
This requires no migration! (And: No more empty stylesheet request)
* Gadgets with scripts (with or without styles): We assume type=general, but
unless type=general was explicitly set we'll still load it both ways so
that the styles apply directly on page load.
If this is not needed, set type=general.
If this is needed, it should become two separate modules. We do not support
a single module having two purposes (1: apply styles to the page,
2: provide scripts+styles). The styles module should be separate.
It can be made hidden, and listed as dependency of the other module.
The latter case is detected on page load and results in a console warning
with a link to T42284.
Bug: T42284
Bug: T92459
Change-Id: Ia3c9ddee243f710022144fc2884434350695699a
2016-09-01 23:31:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:08:41 +00:00
|
|
|
/**
|
2022-02-06 18:54:47 +00:00
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo::newFromDefinition
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::isHidden
|
2018-01-05 00:08:41 +00:00
|
|
|
*/
|
2016-11-17 01:58:37 +00:00
|
|
|
public function testIsHidden() {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '* foo[hidden]|bar.js' );
|
2016-11-17 01:58:37 +00:00
|
|
|
$this->assertTrue( $g->isHidden() );
|
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '* foo[ResourceLoader|hidden]|bar.js' );
|
2016-11-17 01:58:37 +00:00
|
|
|
$this->assertTrue( $g->isHidden() );
|
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( '* foo[ResourceLoader]|bar.js' );
|
2016-11-17 01:58:37 +00:00
|
|
|
$this->assertFalse( $g->isHidden() );
|
|
|
|
}
|
2021-12-28 21:29:05 +00:00
|
|
|
|
|
|
|
public static function provideWarnings() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'* foo[ResourceLoader|package]|foo.css',
|
|
|
|
[ 'gadgets-validate-noentrypoint' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'* foo[ResourceLoader]|foo.js,foo.json',
|
|
|
|
[ 'gadgets-validate-json' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'* foo[ResourceLoader|type=styles]|foo.js|foo.css',
|
|
|
|
[ 'gadgets-validate-scriptsnotallowed' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'* foo[ResourceLoader|type=styles|peers=bar]|foo.js|foo.json|foo.css',
|
|
|
|
[ 'gadgets-validate-scriptsnotallowed', 'gadgets-validate-stylepeers', 'gadgets-validate-json' ]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideWarnings
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget::getValidationWarnings
|
|
|
|
*/
|
|
|
|
public function testGadgetWarnings( $definition, $expectedMsgKeys ) {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->makeGadget( $definition );
|
2021-12-28 21:29:05 +00:00
|
|
|
$msgKeys = $g->getValidationWarnings();
|
|
|
|
$this->assertArrayEquals( $expectedMsgKeys, $msgKeys );
|
|
|
|
}
|
2011-05-21 11:23:06 +00:00
|
|
|
}
|