Go to the documentation of this file.
9 protected function setUp() {
24 'localBasePath' => realpath( __DIR__ ),
28 'noTemplateModule' => [],
30 'deprecatedModule' =>
$base + [
33 'deprecatedTomorrow' =>
$base + [
34 'deprecated' =>
'Will be removed tomorrow.'
37 'htmlTemplateModule' =>
$base + [
39 'templates/template.html',
40 'templates/template2.html',
44 'htmlTemplateUnknown' =>
$base + [
46 'templates/notfound.html',
50 'aliasedHtmlTemplateModule' =>
$base + [
52 'foo.html' =>
'templates/template.html',
53 'bar.html' =>
'templates/template2.html',
57 'templateModuleHandlebars' =>
$base + [
59 'templates/template_awesome.handlebars',
63 'aliasFooFromBar' =>
$base + [
65 'foo.foo' =>
'templates/template.bar',
86 $modules[
'templateModuleHandlebars'],
89 'mediawiki.template.handlebars',
96 'mediawiki.template.foo',
109 $rl->setName(
'testing' );
110 $this->assertEquals( $rl->getDependencies(), $expected );
117 'mw.log.warn("This page is using the deprecated ResourceLoader module \"deprecatedModule\".");',
120 'deprecatedTomorrow',
122 '"This page is using the deprecated ResourceLoader module \"deprecatedTomorrow\".\\n' .
123 "Will be removed tomorrow." .
136 $module->setName(
$name );
138 $this->assertEquals( $module->getScript( $ctx ), $expected );
148 'localBasePath' => __DIR__ .
'/../../data/resourceloader',
149 'scripts' => [
'script-nosemi.js',
'script-comment.js' ],
151 $module->setName(
'testing' );
154 "/* eslint-disable */\nmw.foo()\n" .
156 "/* eslint-disable */\nmw.foo()\n// mw.bar();\n" .
158 $module->getScript( $ctx ),
159 'scripts are concatenated with a new-line'
176 'bar.css' => [
'media' =>
'print' ],
177 'screen.less' => [
'media' =>
'screen' ],
178 'screen-query.css' => [
'media' =>
'screen and (min-width: 400px)' ],
181 'default' =>
'quux-fallback.less',
194 $module->setName(
'testing' );
201 'quux-fallback.less',
206 array_map(
'basename', $module->getAllStyleFiles() )
216 return str_replace(
'/*@noflip*/ ',
'',
$css );
232 'styles' => [
'test.css' ],
234 $testModule->setName(
'testing' );
237 'styles' => [
'expected.css' ],
239 $expectedModule->setName(
'testing' );
253 $expectedModule->getStyles( $contextLtr ),
255 "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
258 $expectedModule->getStyles( $contextLtr ),
260 "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
273 $modules[
'templateModuleHandlebars'],
275 'templates/template_awesome.handlebars' =>
"wow\n",
281 'templates/template.html' =>
"<strong>hello</strong>\n",
282 'templates/template2.html' =>
"<div>goodbye</div>\n",
286 $modules[
'aliasedHtmlTemplateModule'],
288 'foo.html' =>
"<strong>hello</strong>\n",
289 'bar.html' =>
"<div>goodbye</div>\n",
305 $rl->setName(
'testing' );
307 if ( $expected ===
false ) {
311 $this->assertEquals( $rl->getTemplates(), $expected );
322 'styles' => [
'bom.css' ],
324 $testModule->setName(
'testing' );
326 substr( file_get_contents(
"$basePath/bom.css" ), 0, 10 ),
327 "\xef\xbb\xbf.efbbbf",
328 'File has leading BOM'
334 [
'all' =>
".efbbbf_bom_char_at_start_of_file {}\n" ],
335 'Leading BOM removed when concatenating files'
344 $basePath = __DIR__ .
'/../../data/less/module';
347 'styles' => [
'styles.less' ],
349 'lessVars' => [
'foo' =>
'2px',
'Foo' =>
'#eeeeee' ]
351 $module->setName(
'test.less' );
352 $styles = $module->getStyles(
$context );
353 $this->assertStringEqualsFile(
$basePath .
'/styles.css', $styles[
'all'] );
365 $version = $module->getVersionHash(
$context );
367 'lessVars' => [
'key' =>
'value' ],
369 $this->assertNotEquals(
371 $module->getVersionHash(
$context ),
372 'Using less variables is significant'
377 $basePath = __DIR__ .
'/../../data/resourceloader';
379 $commentScript = file_get_contents(
"$basePath/script-comment.js" );
380 $nosemiScript = file_get_contents(
"$basePath/script-nosemi.js" );
392 'script-comment.js' => [
394 'content' => $commentScript,
396 'script-nosemi.js' => [
398 'content' => $nosemiScript
401 'main' =>
'script-comment.js'
408 [
'name' =>
'script-nosemi.js',
'main' =>
true ]
410 'deprecated' =>
'Deprecation test',
411 'name' =>
'test-deprecated'
415 'script-comment.js' => [
417 'content' => $commentScript,
419 'script-nosemi.js' => [
421 'content' =>
'mw.log.warn(' .
422 '"This page is using the deprecated ResourceLoader module \"test-deprecated\".\\n' .
428 'main' =>
'script-nosemi.js'
434 [
'name' =>
'init.js',
'file' =>
'script-comment.js',
'main' =>
true ],
435 [
'name' =>
'nosemi.js',
'file' =>
'script-nosemi.js' ],
442 'content' => $commentScript,
446 'content' => $nosemiScript
455 [
'name' =>
'foo.json',
'content' => [
'Hello' =>
'world' ] ],
457 [
'name' =>
'bar.js',
'content' =>
"console.log('Hello');" ],
458 [
'name' =>
'data.json',
'callback' =>
function (
$context ) {
459 return [
'langCode' =>
$context->getLanguage() ];
461 [
'name' =>
'config.json',
'config' => [
463 'wgVersion' =>
'Version',
471 'content' => [
'Hello' =>
'world' ],
475 'content' => (
object)[
'foo' =>
'bar',
'answer' => 42 ],
479 'content' =>
"console.log('Hello');",
483 'content' => [
'langCode' =>
'fy' ]
488 'Sitename' => $config->get(
'Sitename' ),
489 'wgVersion' => $config->get(
'Version' ),
502 [
'file' =>
'script-comment.js' ]
510 [
'name' =>
'foo.json',
'callback' =>
'functionThatDoesNotExist142857' ]
518 'foo.json' => [
'type' =>
'script',
'config' => [
'Sitename' ] ]
526 [
'name' =>
'foo.js',
'config' =>
'Sitename' ]
534 'foo.js' => [
'garbage' =>
'data' ]
542 'filethatdoesnotexist142857.js'
551 [
'name' =>
'foo.json',
'content' => [
'Hello' =>
'world' ],
'main' =>
true ]
568 if ( isset( $moduleDefinition[
'name'] ) ) {
569 $module->setName( $moduleDefinition[
'name'] );
571 if ( $expected ===
false ) {
575 $this->assertEquals( $expected, $module->getScript(
$context ) );
providerGetScriptPackageFiles()
static providerDeprecatedModules()
testLessFileCompilation()
ResourceLoaderFileModule::compileLessFile.
testTemplateDependencies( $module, $expected)
providerTemplateDependencies ResourceLoaderFileModule::__construct ResourceLoaderFileModule::getDepen...
processing should stop and the error should be shown to the user * false
testGetAllSkinStyleFiles()
ResourceLoaderFileModule::getAllStyleFiles ResourceLoaderFileModule::getAllSkinStyleFiles ResourceLoa...
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
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
ResourceLoader module based on local JavaScript/CSS files.
static providerGetTemplates()
testGetScriptPackageFiles( $moduleDefinition, $expected, $contextOptions=[])
providerGetScriptPackageFiles ResourceLoaderFileModule::getScript ResourceLoaderFileModule::getPackag...
Allows to change the fields on the form that will be generated $name
testGetVersionHash()
ResourceLoaderFileModule::getDefinitionSummary ResourceLoaderFileModule::getFileHashes.
testGetScript()
ResourceLoaderFileModule::getScript ResourceLoaderFileModule::getScriptFiles ResourceLoaderFileModule...
static stripNoflip( $css)
Strip @noflip annotations from CSS code.
testMixedCssAnnotations()
What happens when you mix @embed and @noflip? This really is an integration test, but oh well.
static getMain()
Get the RequestContext object associated with the main request.
testDeprecatedModules( $name, $expected)
providerDeprecatedModules ResourceLoaderFileModule::getScript
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
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
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
testGetTemplates( $module, $expected)
providerGetTemplates ResourceLoaderFileModule::getTemplates
static providerTemplateDependencies()
testBomConcatenation()
ResourceLoaderFileModule::stripBom.
static getDefaultInstance()