Go to the documentation of this file.
5 use Wikimedia\TestingAccessWrapper;
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' ],
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 ) );
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;
161 ->setMethods( [
'getPages' ] )
163 $module->method(
'getPages' )->willReturn( $pages );
165 $module::$returnFetchTitleInfo = $titleInfo;
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;
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' ],
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',
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 )
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' ) {
346 $handler = new JavaScriptContentHandler();
347 return $handler->makeRedirectContent(
348 Title::makeTitle( NS_MEDIAWIKI,
'Target.js' )
350 } elseif (
$title->getPrefixedText() ===
'MediaWiki:Target.js' ) {
351 return new JavaScriptContent(
'target;' );
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.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
the array() calling protocol came about after MediaWiki 1.4rc1.
A Config instance which stores all settings as a member variable.
static provideGetContent()
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
testGetGroup( $params, $expected)
ResourceLoaderWikiModule::getGroup provideGetGroup.
Abstraction for ResourceLoader modules which pull from wiki pages.
testGetPreloadedTitleInfo()
ResourceLoaderWikiModule::getTitleInfo ResourceLoaderWikiModule::setTitleInfo ResourceLoaderWikiModul...
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
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 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.
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()
namespace and then decline to actually register it file or subcat img or subcat $title
testGetPreloadedBadTitle()
ResourceLoaderWikiModule::preloadTitleInfo.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
testGetContentForRedirects()
ResourceLoaderWikiModule::getContent.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
testGetPreloadedTitleInfoEmpty()
ResourceLoaderWikiModule::preloadTitleInfo.
Represents a title within MediaWiki.
testConstructor( $params)
ResourceLoaderWikiModule::__construct provideConstructor.
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
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 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...
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
static provideIsKnownEmpty()
testGetPages( $params, Config $config, $expected)
provideGetPages ResourceLoaderWikiModule::getPages
Represents a page (or page fragment) title within MediaWiki.