5use Wikimedia\TestingAccessWrapper;
15 $this->assertInstanceOf( ResourceLoaderWikiModule::class, $module );
24 [ [
'foo' =>
'baz' ] ],
26 [ [
'scripts' => [
'MediaWiki:Common.js' ] ] ],
36 $module->setConfig( $config );
39 $getPages =
new ReflectionMethod( $module,
'getPages' );
40 $getPages->setAccessible(
true );
41 $out = $getPages->invoke( $module, ResourceLoaderContext::newDummyContext() );
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::class )
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::class )
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::class )
161 ->setMethods( [
'getPages' ] )
163 $module->method(
'getPages' )->willReturn( $pages );
165 $module::$returnFetchTitleInfo = $titleInfo;
167 $context = $this->getMockBuilder( ResourceLoaderContext::class )
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::class )
196 ->setMethods( [
'getPages' ] )
198 $module->method(
'getPages' )->willReturn( $pages );
200 $module::$returnFetchTitleInfo = $titleInfo;
203 $rl->register(
'testmodule', $module );
207 Title::newFromText(
'MediaWiki:Common.css' ),
218 $module = TestingAccessWrapper::newFromObject( $module );
219 $this->assertEquals( $expected, $module->getTitleInfo(
$context ),
'Title info' );
229 '[x]' => [
'type' =>
'styles' ],
234 $module = $this->getMockBuilder( TestResourceLoaderWikiModule::class )
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::class )
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(
313 new TitleValue( $title[
'ns'], $title[
'title'] ),
321 $module = TestingAccessWrapper::newFromObject( $module );
324 $module->getContent( $titleText )
334 $module = $this->getMockBuilder( ResourceLoaderWikiModule::class )
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(
360 new TitleValue( NS_MEDIAWIKI,
'Redirect.js' ),
366 "/*\nMediaWiki:Redirect.js\n*/\ntarget;\n",
368 'Redirect resolved by getContent'
377 self::$returnFetchTitleInfo =
null;
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
Object passed around to modules which contains information about the state of a specific loader reque...
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
testGetContent( $expected, $title)
ResourceLoaderWikiModule::getContent provideGetContent.
testGetTitleInfo()
ResourceLoaderWikiModule::getTitleInfo.
static provideGetContent()
testIsKnownEmpty( $titleInfo, $group, $expected)
ResourceLoaderWikiModule::isKnownEmpty provideIsKnownEmpty.
testGetPreloadedTitleInfoEmpty()
ResourceLoaderWikiModule::preloadTitleInfo.
testConstructor( $params)
ResourceLoaderWikiModule::__construct provideConstructor.
static provideConstructor()
static provideIsKnownEmpty()
testGetGroup( $params, $expected)
ResourceLoaderWikiModule::getGroup provideGetGroup.
testGetPages( $params, Config $config, $expected)
provideGetPages ResourceLoaderWikiModule::getPages
testGetPreloadedTitleInfo()
ResourceLoaderWikiModule::getTitleInfo ResourceLoaderWikiModule::setTitleInfo ResourceLoaderWikiModul...
testGetContentForRedirects()
ResourceLoaderWikiModule::getContent.
testGetPreloadedBadTitle()
ResourceLoaderWikiModule::preloadTitleInfo.
Abstraction for ResourceLoader modules which pull from wiki pages.
static preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
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 $returnFetchTitleInfo
static fetchTitleInfo(IDatabase $db, array $pages, $fname=null)
Represents a page (or page fragment) title within MediaWiki.
Represents a title within MediaWiki.
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
namespace and then decline to actually register it file or subcat img or subcat $title
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
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
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
Interface for configuration instances.