Go to the documentation of this file.
5 use Wikimedia\TestingAccessWrapper;
15 $this->assertInstanceOf(
'ResourceLoaderWikiModule', $module );
24 [ [
'foo' =>
'baz' ] ],
26 [ [
'scripts' => [
'MediaWiki:Common.js' ] ] ],
36 $module->setConfig( $config );
39 $getPages =
new ReflectionMethod( $module,
'getPages' );
40 $getPages->setAccessible(
true );
42 $this->assertEquals( $expected,
$out );
52 'styles' => [
'MediaWiki:Common.css' ],
53 'scripts' => [
'MediaWiki:Common.js' ],
59 'MediaWiki:Common.js' => [
'type' =>
'script' ],
60 'MediaWiki:Common.css' => [
'type' =>
'style' ]
63 'MediaWiki:Common.js' => [
'type' =>
'script' ],
66 'MediaWiki:Common.css' => [
'type' =>
'style' ],
70 [
'UseSiteJs' =>
false,
'UseSiteCss' =>
false ]
83 $this->assertEquals( $expected, $module->getGroup() );
91 [ [
'group' =>
'foobar' ],
'foobar' ],
100 $module = $this->getMockBuilder(
'ResourceLoaderWikiModule' )
101 ->setMethods( [
'getTitleInfo',
'getGroup' ] )
103 $module->expects( $this->
any() )
104 ->method(
'getTitleInfo' )
105 ->will( $this->returnValue( $titleInfo ) );
106 $module->expects( $this->
any() )
107 ->method(
'getGroup' )
108 ->will( $this->returnValue( $group ) );
109 $context = $this->getMockBuilder(
'ResourceLoaderContext' )
110 ->disableOriginalConstructor()
112 $this->assertEquals( $expected, $module->isKnownEmpty(
$context ) );
118 [ [],
'test1',
true ],
121 [
'MediaWiki:Common.js' => [
'page_len' => 1234 ] ],
127 [
'MediaWiki:Foo.js' => [
'page_len' => 0 ] ],
133 [
'User:Example/common.js' => [
'page_len' => 25 ] ],
139 [
'User:Example/foo.js' => [
'page_len' => 0 ] ],
151 'MediaWiki:Common.css' => [
'type' =>
'styles' ],
152 'mediawiki: fallback.css' => [
'type' =>
'styles' ],
155 'MediaWiki:Common.css' => [
'page_len' => 1234 ],
156 'MediaWiki:Fallback.css' => [
'page_len' => 0 ],
158 $expected = $titleInfo;
160 $module = $this->getMockBuilder(
'TestResourceLoaderWikiModule' )
161 ->setMethods( [
'getPages' ] )
163 $module->method(
'getPages' )->willReturn( $pages );
165 $module::$returnFetchTitleInfo = $titleInfo;
167 $context = $this->getMockBuilder(
'ResourceLoaderContext' )
168 ->disableOriginalConstructor()
171 $module = TestingAccessWrapper::newFromObject( $module );
172 $this->assertEquals( $expected, $module->getTitleInfo(
$context ),
'Title info' );
182 'MediaWiki:Common.css' => [
'type' =>
'styles' ],
187 'mediawiki: fallback.css' => [
'type' =>
'styles' ],
190 'MediaWiki:Common.css' => [
'page_len' => 1234 ],
191 'MediaWiki:Fallback.css' => [
'page_len' => 0 ],
193 $expected = $titleInfo;
195 $module = $this->getMockBuilder(
'TestResourceLoaderWikiModule' )
196 ->setMethods( [
'getPages' ] )
198 $module->method(
'getPages' )->willReturn( $pages );
200 $module::$returnFetchTitleInfo = $titleInfo;
203 $rl->register(
'testmodule', $module );
218 $module = TestingAccessWrapper::newFromObject( $module );
219 $this->assertEquals( $expected, $module->getTitleInfo(
$context ),
'Title info' );
229 '[x]' => [
'type' =>
'styles' ],
234 $module = $this->getMockBuilder(
'TestResourceLoaderWikiModule' )
235 ->setMethods( [
'getPages' ] ) ->getMock();
236 $module->method(
'getPages' )->willReturn( $pages );
237 $module::$returnFetchTitleInfo = $titleInfo;
239 $rl->register(
'testmodule', $module );
250 $module = TestingAccessWrapper::newFromObject( $module );
251 $this->assertEquals( $titleInfo, $module->getTitleInfo(
$context ),
'Title info' );
272 'Bad title' => [
null,
'[x]' ],
273 'Dead redirect' => [
null, [
274 'text' =>
'Dead redirect',
275 'title' =>
'Dead_redirect',
278 'Bad content model' => [
null, [
279 'text' =>
'MediaWiki:Wikitext',
281 'title' =>
'Wikitext',
283 'No JS content found' => [
null, [
284 'text' =>
'MediaWiki:Script.js',
286 'title' =>
'Script.js',
288 'No CSS content found' => [
null, [
289 'text' =>
'MediaWiki:Styles.css',
291 'title' =>
'Script.css',
302 $module = $this->getMockBuilder(
'ResourceLoaderWikiModule' )
303 ->setMethods( [
'getContentObj' ] ) ->getMock();
304 $module->expects( $this->
any() )
305 ->method(
'getContentObj' )->willReturn(
null );
307 if ( is_array(
$title ) ) {
308 $title += [
'ns' =>
NS_MAIN,
'id' => 1,
'len' => 1,
'redirect' => 0 ];
309 $titleText =
$title[
'text'];
311 MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj(
321 $module = TestingAccessWrapper::newFromObject( $module );
324 $module->getContent( $titleText )
334 $module = $this->getMockBuilder(
'ResourceLoaderWikiModule' )
335 ->setMethods( [
'getPages',
'getContentObj' ] )
337 $module->expects( $this->
any() )
338 ->method(
'getPages' )
339 ->will( $this->returnValue( [
340 'MediaWiki:Redirect.js' => [
'type' =>
'script' ]
342 $module->expects( $this->
any() )
343 ->method(
'getContentObj' )
344 ->will( $this->returnCallback(
function (
Title $title ) {
345 if (
$title->getPrefixedText() ===
'MediaWiki:Redirect.js' ) {
347 return $handler->makeRedirectContent(
350 } elseif (
$title->getPrefixedText() ===
'MediaWiki:Target.js' ) {
358 MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj(
366 "/*\nMediaWiki:Redirect.js\n*/\ntarget;\n",
368 'Redirect resolved by getContent'
377 self::$returnFetchTitleInfo =
null;
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.
testIsKnownEmpty( $titleInfo, $group, $expected)
ResourceLoaderWikiModule::isKnownEmpty provideIsKnownEmpty.
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()
testGetGroup( $params, $expected)
ResourceLoaderWikiModule::getGroup provideGetGroup.
Abstraction for ResourceLoader modules which pull from wiki pages.
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
testGetPreloadedTitleInfo()
ResourceLoaderWikiModule::getTitleInfo ResourceLoaderWikiModule::setTitleInfo ResourceLoaderWikiModul...
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
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
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.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static provideConstructor()
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
testGetPreloadedBadTitle()
ResourceLoaderWikiModule::preloadTitleInfo.
Content for JavaScript pages.
testGetContentForRedirects()
ResourceLoaderWikiModule::getContent.
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.
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.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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
testGetPreloadedTitleInfoEmpty()
ResourceLoaderWikiModule::preloadTitleInfo.
Represents a title within MediaWiki.
testConstructor( $params)
ResourceLoaderWikiModule::__construct provideConstructor.
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
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 invalidateModuleCache(Title $title, Revision $old=null, Revision $new=null, $wikiId)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
static provideIsKnownEmpty()
testGetPages( $params, Config $config, $expected)
provideGetPages ResourceLoaderWikiModule::getPages
the array() calling protocol came about after MediaWiki 1.4rc1.
Represents a page (or page fragment) title within MediaWiki.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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