5 protected function setUp() {
9 'wgResourceLoaderLESSImportPaths' => [
10 dirname( dirname( __DIR__ ) ) .
'/data/less/common',
12 'wgResourceLoaderLESSVars' => [
26 $resourceLoaderRegisterModulesHook =
false;
29 'ResourceLoaderRegisterModules' => [
31 $resourceLoaderRegisterModulesHook =
true;
38 $resourceLoaderRegisterModulesHook,
39 'Hook ResourceLoaderRegisterModules called'
59 $this->setExpectedException(
'MWException',
"name 'test!invalid' is invalid" );
68 $this->setExpectedException(
'MWException',
'ResourceLoader module info type error' );
81 [
'test.foo',
'test.bar' ],
92 $this->assertTrue( $rl->isModuleRegistered(
'test' ) );
93 $this->assertFalse( $rl->isModuleRegistered(
'test.unknown' ) );
101 $this->assertSame( null, $rl->getModule(
'test' ) );
110 $this->assertInstanceOf(
112 $rl->getModule(
'test' )
121 $rl->register(
'test', [] );
122 $this->assertInstanceOf(
124 $rl->getModule(
'test' ),
125 'Array-style module registrations default to FileModule'
134 $basePath = __DIR__ .
'/../../data/less/module';
137 'styles' => [
'styles.less' ],
139 $module->setName(
'test.less' );
140 $styles = $module->getStyles(
$context );
141 $this->assertStringEqualsFile(
$basePath .
'/styles.css', $styles[
'all'] );
147 'Example from makePackedModulesString doc comment',
148 [
'foo.bar',
'foo.baz',
'bar.baz',
'bar.quux' ],
149 'foo.bar,baz|bar.baz,quux',
152 'Example from expandModuleNames doc comment',
153 [
'jquery.foo',
'jquery.bar',
'jquery.ui.baz',
'jquery.ui.quux' ],
154 'jquery.foo,bar|jquery.ui.baz,quux',
157 'Regression fixed in r88706 with dotless names',
158 [
'foo',
'bar',
'baz' ],
162 'Prefixless modules after a prefixed module',
163 [
'single.module',
'foobar',
'foobaz' ],
164 'single.module|foobar,foobaz',
168 [
'foo',
'foo.baz',
'baz.quux',
'foo.bar' ],
169 'foo|foo.baz,bar|baz.quux',
170 [
'foo',
'foo.baz',
'foo.bar',
'baz.quux' ],
197 [
'foowiki',
'https://example.org/w/load.php',
'foowiki' ],
198 [
'foowiki', [
'loadScript' =>
'https://example.org/w/load.php' ],
'foowiki' ],
201 'foowiki' =>
'https://example.org/w/load.php',
202 'bazwiki' =>
'https://example.com/w/load.php',
205 [
'foowiki',
'bazwiki' ]
218 if ( is_array( $expected ) ) {
220 $this->assertArrayHasKey( $source, $rl->getSources() );
223 $this->assertArrayHasKey( $expected, $rl->getSources() );
232 $this->setExpectedException(
'MWException',
'ResourceLoader duplicate source addition error' );
233 $rl->addSource(
'foo',
'https://example.org/w/load.php' );
234 $rl->addSource(
'foo',
'https://example.com/w/load.php' );
242 $this->setExpectedException(
'MWException',
'with no "loadScript" key' );
243 $rl->addSource(
'foo', [
'x' =>
'https://example.org/w/load.php' ] );
249 'title' =>
'Implement scripts, styles and messages',
251 'name' =>
'test.example',
252 'scripts' =>
'mw.example();',
253 'styles' => [
'css' => [
'.mw-example {}' ] ],
254 'messages' => [
'example' =>
'' ],
257 'expected' =>
'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
268 'title' =>
'Implement scripts',
270 'name' =>
'test.example',
271 'scripts' =>
'mw.example();',
274 'expected' =>
'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
279 'title' =>
'Implement styles',
281 'name' =>
'test.example',
283 'styles' => [
'css' => [
'.mw-example {}' ] ],
285 'expected' =>
'mw.loader.implement( "test.example", [], {
292 'title' =>
'Implement scripts and messages',
294 'name' =>
'test.example',
295 'scripts' =>
'mw.example();',
296 'messages' => [
'example' =>
'' ],
298 'expected' =>
'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
305 'title' =>
'Implement scripts and templates',
307 'name' =>
'test.example',
308 'scripts' =>
'mw.example();',
309 'templates' => [
'example.html' =>
'' ],
311 'expected' =>
'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
318 'title' =>
'Implement unwrapped user script',
321 'scripts' =>
'mw.example( 1 );',
324 'expected' =>
'mw.loader.implement( "user", "mw.example( 1 );" );',
337 'styles' => [],
'templates' => [],
'messages' =>
new XmlJsCode(
'{}' )
345 $rl->makeLoaderImplementScript(
347 ( $case[
'wrap'] && is_string( $case[
'scripts'] ) )
361 $this->setExpectedException(
'MWException',
'Invalid scripts error' );
363 $rl->makeLoaderImplementScript(
377 'mw.loader.addSource( "local", "/w/load.php" );',
381 'mw.loader.addSource( {
382 "local": "/w/load.php"
387 'mw.loader.addSource( {
388 "local": "/w/load.php",
389 "example": "https://example.org/w/load.php"
392 'local' =>
'/w/load.php',
393 'example' =>
'https://example.org/w/load.php'
397 'mw.loader.addSource( [] );',
405 'loadScript' =>
'//example.org/w/load.php',
406 'apiScript' =>
'//example.org/w/api.php',
409 'loadScript' =>
'//example.com/w/load.php',
410 'apiScript' =>
'//example.com/w/api.php',
421 $sources = self::fakeSources();
422 $rl->addSource( $sources );
423 foreach ( [
'examplewiki',
'example2wiki' ]
as $name ) {
424 $this->assertEquals( $rl->getLoadScript( $name ), $sources[
$name][
'loadScript'] );
428 $rl->getLoadScript(
'thiswasneverreigstered' );
429 $this->assertTrue(
false,
'ResourceLoader::getLoadScript should have thrown an exception' );
431 $this->assertTrue(
true );
testMakeLoaderImplementScript($case)
provideLoaderImplement ResourceLoader::makeLoaderImplementScript ResourceLoader::trimArray ...
testConstructRegistrationHook()
Ensure the ResourceLoaderRegisterModules hook is called.
testAddSourceInvalid()
ResourceLoader::addSource.
static provideLoaderImplement()
static expandModuleNames($modules)
Expand a string of the form jquery.foo,bar|jquery.ui.baz,quux to an array of module names like [ 'jqu...
error also a ContextSource you ll probably need to make sure the header is varied on such as when responding to a resource loader request or generating HTML output & $resourceLoader
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
static makeLoaderSourcesScript($id, $loadUrl=null)
Returns JS code which calls mw.loader.addSource() with the given parameters.
testGetModuleNames()
ResourceLoader::getModuleNames.
testRegisterValid()
ResourceLoader::register ResourceLoader::getModule.
static newFromClass($className)
Allow access to non-public static methods and properties of the class.
testAddSource($name, $info, $expected)
provideAddSource ResourceLoader::addSource ResourceLoader::getSources
testGetLoadScript()
ResourceLoader::getLoadScript.
testMakeLoaderImplementScriptInvalid()
ResourceLoader::makeLoaderImplementScript.
testIsModuleRegistered()
ResourceLoader::isModuleRegistered.
testGetModuleClass()
ResourceLoader::getModule.
getResourceLoaderContext($lang= 'en', $dir= 'ltr')
static provideAddSource()
testLessFileCompilation()
ResourceLoaderFileModule::compileLessFile.
ResourceLoader module based on local JavaScript/CSS files.
testRegisterInvalidType()
ResourceLoader::register.
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
static makePackedModulesString($modules)
Convert an array of module names to a packed query string.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static clearCache()
Reset static members used for caching.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
testMakePackedModulesString($desc, $modules, $packed)
providePackedModules ResourceLoader::makePackedModulesString
testGetModuleClassDefault()
ResourceLoader::getModule.
addSource($id, $loadUrl=null)
Add a foreign source of modules.
testAddSourceDupe()
ResourceLoader::addSource.
Dynamic JavaScript and CSS resource loading system.
static providePackedModules()
testMakeLoaderSourcesScript()
ResourceLoader::makeLoaderSourcesScript.
testExpandModuleNames($desc, $modules, $packed, $unpacked=null)
providePackedModules ResourceLoaderContext::expandModuleNames
testRegisterInvalidName()
ResourceLoader::register.
testGetModuleUnknown()
ResourceLoader::getModule.
Allows to change the fields on the form that will be generated $name