Go to the documentation of this file.
5 use Wikimedia\TestingAccessWrapper;
21 foreach ( $mockInfo
as $key => $val ) {
33 [ [
'foo' =>
'baz' ] ],
35 [ [
'scripts' => [
'MediaWiki:Common.js' ] ] ],
45 $module->setConfig( $config );
48 $getPages =
new ReflectionMethod( $module,
'getPages' );
49 $getPages->setAccessible(
true );
51 $this->assertEquals( $expected,
$out );
61 'styles' => [
'MediaWiki:Common.css' ],
62 'scripts' => [
'MediaWiki:Common.js' ],
68 'MediaWiki:Common.js' => [
'type' =>
'script' ],
69 'MediaWiki:Common.css' => [
'type' =>
'style' ]
72 'MediaWiki:Common.js' => [
'type' =>
'script' ],
75 'MediaWiki:Common.css' => [
'type' =>
'style' ],
79 [
'UseSiteJs' =>
false,
'UseSiteCss' =>
false ]
92 $this->assertEquals( $expected, $module->getGroup() );
100 [ [
'group' =>
'foobar' ],
'foobar' ],
110 ->setMethods( [
'getTitleInfo',
'getGroup',
'getDependencies' ] )
112 $module->expects( $this->
any() )
113 ->method(
'getTitleInfo' )
115 $module->expects( $this->
any() )
116 ->method(
'getGroup' )
117 ->will( $this->returnValue( $group ) );
118 $module->expects( $this->
any() )
119 ->method(
'getDependencies' )
120 ->will( $this->returnValue( $dependencies ) );
122 ->disableOriginalConstructor()
124 $this->assertEquals( $expected, $module->isKnownEmpty(
$context ) );
130 [ [],
'test1', [],
true ],
133 [
'MediaWiki:Common.js' => [
'page_len' => 1234 ] ],
147 [
'MediaWiki:Common.js' => [
'page_len' => 0 ] ],
154 [
'MediaWiki:Foo.js' => [
'page_len' => 0 ] ],
161 [
'User:Example/common.js' => [
'page_len' => 25 ] ],
168 [
'User:Example/foo.js' => [
'page_len' => 0 ] ],
181 'MediaWiki:Common.css' => [
'type' =>
'styles' ],
182 'mediawiki: fallback.css' => [
'type' =>
'styles' ],
185 'MediaWiki:Common.css' => [
'page_len' => 1234 ],
186 'MediaWiki:Fallback.css' => [
'page_len' => 0 ],
188 $expected = $titleInfo;
191 ->setMethods( [
'getPages' ] )
193 $module->method(
'getPages' )->willReturn( $pages );
195 $module::$returnFetchTitleInfo = $titleInfo;
198 ->disableOriginalConstructor()
201 $module = TestingAccessWrapper::newFromObject( $module );
202 $this->assertEquals( $expected, $module->getTitleInfo(
$context ),
'Title info' );
212 'MediaWiki:Common.css' => [
'type' =>
'styles' ],
217 'mediawiki: fallback.css' => [
'type' =>
'styles' ],
220 'MediaWiki:Common.css' => [
'page_len' => 1234 ],
221 'MediaWiki:Fallback.css' => [
'page_len' => 0 ],
223 $expected = $titleInfo;
226 ->setMethods( [
'getPages' ] )
228 $module->method(
'getPages' )->willReturn( $pages );
230 $module::$returnFetchTitleInfo = $titleInfo;
233 $rl->register(
'testmodule', $module );
248 $module = TestingAccessWrapper::newFromObject( $module );
249 $this->assertEquals( $expected, $module->getTitleInfo(
$context ),
'Title info' );
259 '[x]' => [
'type' =>
'styles' ],
265 ->setMethods( [
'getPages' ] )->getMock();
266 $module->method(
'getPages' )->willReturn( $pages );
267 $module::$returnFetchTitleInfo = $titleInfo;
269 $rl->register(
'testmodule', $module );
280 $module = TestingAccessWrapper::newFromObject( $module );
281 $this->assertEquals( $titleInfo, $module->getTitleInfo(
$context ),
'Title info' );
302 'Bad title' => [
null,
'[x]' ],
303 'Dead redirect' => [
null, [
304 'text' =>
'Dead redirect',
305 'title' =>
'Dead_redirect',
308 'Bad content model' => [
null, [
309 'text' =>
'MediaWiki:Wikitext',
311 'title' =>
'Wikitext',
313 'No JS content found' => [
null, [
314 'text' =>
'MediaWiki:Script.js',
316 'title' =>
'Script.js',
318 'No CSS content found' => [
null, [
319 'text' =>
'MediaWiki:Styles.css',
321 'title' =>
'Script.css',
333 ->setMethods( [
'getContentObj' ] )->getMock();
334 $module->expects( $this->
any() )
335 ->method(
'getContentObj' )->willReturn(
null );
337 if ( is_array(
$title ) ) {
338 $title += [
'ns' =>
NS_MAIN,
'id' => 1,
'len' => 1,
'redirect' => 0 ];
339 $titleText =
$title[
'text'];
341 MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj(
351 $module = TestingAccessWrapper::newFromObject( $module );
354 $module->getContent( $titleText,
$context )
365 'MediaWiki:Common.css' => [
'type' =>
'style' ],
369 ->setMethods( [
'getPages' ] )
371 $module->method(
'getPages' )->willReturn( $pages );
374 $rl->register(
'testmodule', $module );
379 if (
$t->getPrefixedText() ===
'MediaWiki:Common.css' ) {
385 $this->assertTrue( $module->shouldEmbedModule(
$context ) );
386 $this->assertEquals( [
388 "/*\nMediaWiki:Common.css\n*/\n.override{}"
390 ], $module->getStyles(
$context ) );
393 if (
$t->getPrefixedText() ===
'MediaWiki:Skin.css' ) {
398 $this->assertFalse( $module->shouldEmbedModule(
$context ) );
411 ->setMethods( [
'getPages' ] )
413 $module->expects( $this->
any() )
414 ->method(
'getPages' )
415 ->will( $this->returnValue( [
416 'MediaWiki:Redirect.js' => [
'type' =>
'script' ]
419 if (
$title->getPrefixedText() ===
'MediaWiki:Redirect.js' ) {
421 return $handler->makeRedirectContent(
424 } elseif (
$title->getPrefixedText() ===
'MediaWiki:Target.js' ) {
432 MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj(
440 "/*\nMediaWiki:Redirect.js\n*/\ntarget;\n",
442 'Redirect resolved by getContent'
456 self::$returnFetchTitleInfo =
null;
prepareTitleInfo(array $mockInfo)
Object passed around to modules which contains information about the state of a specific loader reque...
WebRequest clone which takes values from a provided array.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
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
A Config instance which stores all settings as a member variable.
static provideGetContent()
testContentOverrides()
ResourceLoaderWikiModule::getContent ResourceLoaderWikiModule::getContentObj ResourceLoaderWikiModule...
static clearCaches()
Text form (spaces not underscores) of the main part.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
testGetGroup( $params, $expected)
ResourceLoaderWikiModule::getGroup provideGetGroup.
Abstraction for ResourceLoader modules which pull from wiki pages.
testGetPreloadedTitleInfo()
ResourceLoaderWikiModule::getTitleInfo ResourceLoaderWikiModule::setTitleInfo ResourceLoaderWikiModul...
Content object for CSS pages.
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
Interface for configuration instances.
testGetTitleInfo()
ResourceLoaderWikiModule::getTitleInfo.
namespace and then decline to actually register it file or subcat img or subcat $title
static fetchTitleInfo(IDatabase $db, array $pages, $fname=null)
static $returnFetchTitleInfo
static preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
testGetContent( $expected, $title)
ResourceLoaderWikiModule::getContent provideGetContent.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
static provideConstructor()
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
testGetPreloadedBadTitle()
ResourceLoaderWikiModule::preloadTitleInfo.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Content for JavaScript pages.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
testGetContentForRedirects()
ResourceLoaderWikiModule::getContent ResourceLoaderWikiModule::getContentObj.
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Allows changing specific properties of a context object, without changing the main one.
static invalidateModuleCache(Title $title, Revision $old=null, Revision $new=null, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
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 & $ret
Content handler for JavaScript pages.
testGetPreloadedTitleInfoEmpty()
ResourceLoaderWikiModule::preloadTitleInfo.
Represents a title within MediaWiki.
testConstructor( $params)
ResourceLoaderWikiModule::__construct provideConstructor.
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
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
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
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 MediaWikiServices
static provideIsKnownEmpty()
testGetPages( $params, Config $config, $expected)
provideGetPages ResourceLoaderWikiModule::getPages
testIsKnownEmpty( $titleInfo, $group, $dependencies, $expected)
ResourceLoaderWikiModule::isKnownEmpty provideIsKnownEmpty.
Represents a page (or page fragment) title within MediaWiki.