3use Wikimedia\TestingAccessWrapper;
15 'wgExtraNamespaces' => [
17 12313 =>
'Dummy_talk',
21 'wgNamespaceContentModels' => [
24 'wgContentHandlers' => [
30 'testing' => DummyContentHandlerForTesting::class,
31 'testing-callbacks' =>
function ( $modelId ) {
38 MediaWikiServices::getInstance()->resetServiceForTesting(
'LinkCache' );
43 MediaWikiServices::getInstance()->resetServiceForTesting(
'LinkCache' );
49 $this->
insertPage(
'Not_Main_Page',
'This is not a main page' );
50 $this->
insertPage(
'Smithee',
'A smithee is one who smiths. See also [[Alan Smithee]]' );
87 $this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor(
$title ) );
96 MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj(
$title );
98 $this->assertEquals( $expectedContentModel,
$handler->getModelID() );
116 $name = ContentHandler::getLocalizedName( $id );
119 $this->assertNotNull(
$name,
"no name found for content model $id" );
120 $this->assertTrue( preg_match( $expected,
$name ) > 0,
121 "content model name for #$id did not match pattern $expected"
124 $this->assertEquals( $id,
$name,
"localization of unknown model $id should have "
125 .
"fallen back to use the model id directly."
136 [
"MediaWiki:common.js",
'en' ],
137 [
"User:Foo/common.js",
'en' ],
138 [
"MediaWiki:common.css",
'en' ],
139 [
"User:Foo/common.css",
'en' ],
151 if ( is_string(
$title ) ) {
153 MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj(
$title );
161 $this->assertInstanceOf( Language::class,
$lang );
162 $this->assertEquals( $expected->getCode(),
$lang->getCode() );
178 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
182 $text = ContentHandler::getContentText(
$content );
183 $this->assertEquals(
'', $text );
199 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
203 $text = ContentHandler::getContentText(
$content );
204 $this->assertEquals(
$content->getText(), $text );
213 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'fail' );
217 ContentHandler::getContentText(
$content );
224 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'serialize' );
228 $text = ContentHandler::getContentText(
$content );
229 $this->assertEquals(
$content->serialize(), $text );
236 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'ignore' );
240 $text = ContentHandler::getContentText(
$content );
241 $this->assertNull( $text );
248 [
serialize(
'hallo' ),
'Dummy:Test',
null,
null,
"testing",
false ],
266 [
serialize(
'hallo' ),
'Dummy:Test',
null,
"testing",
"testing",
false ],
297 $expectedModelId, $shouldFail
300 MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj(
$title );
305 $this->fail(
"ContentHandler::makeContent should have failed!" );
308 $this->assertEquals( $expectedModelId,
$content->getModel(),
'bad model id' );
309 $this->assertEquals(
$data,
$content->serialize(),
'bad serialized data' );
311 if ( !$shouldFail ) {
312 $this->fail(
"ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
315 $this->assertTrue(
true );
330 $title = Title::newFromText(
'Help:Test' );
334 $autoSummary =
$content->getAutosummary(
null, $newContent, 97 );
335 $this->assertEquals( $autoSummary,
336 wfMessage(
'autosumm-newblank' )->inContentLanguage()->
text() );
338 $autoSummary =
$content->getAutosummary(
null, $newContent, 92 );
339 $this->assertEquals( $autoSummary,
'' );
347 $this->
setMwGlobals(
'wgSoftwareTags', [
'mw-contentmodelchange' =>
true ] );
354 $tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent,
EDIT_UPDATE );
355 $this->assertSame( $tag,
'mw-contentmodelchange' );
363 $this->assertTrue(
$handler->supportsCategories(),
'content model supports categories' );
371 $this->assertFalse(
$handler->supportsDirectEditing(),
'direct editing is not supported' );
375 if ( $text ===
null || $text ===
false ) {
379 $text = strtoupper( $text );
391 [
'testing', DummyContentHandlerForTesting::class ],
392 [
'testing-callbacks', DummyContentHandlerForTesting::class ],
401 $handler = ContentHandler::getForModelID( $modelId );
403 $this->assertInstanceOf( $handlerClass,
$handler );
414 $fields =
$handler->getFieldsForSearchIndex( $searchEngine );
416 $this->assertArrayHasKey(
'category', $fields );
417 $this->assertArrayHasKey(
'external_link', $fields );
418 $this->assertArrayHasKey(
'outgoing_link', $fields );
419 $this->assertArrayHasKey(
'template', $fields );
420 $this->assertArrayHasKey(
'content_model', $fields );
424 $searchEngine = $this->getMockBuilder( SearchEngine::class )
427 $searchEngine->expects( $this->any() )
428 ->method(
'makeSearchFieldMapping' )
429 ->will( $this->returnCallback(
function (
$name,
$type ) {
433 return $searchEngine;
440 $mockEngine = $this->createMock( SearchEngine::class );
452 $fields[
'testDataField'] =
'test content';
457 $this->assertArrayHasKey(
'text',
$data );
458 $this->assertArrayHasKey(
'text_bytes',
$data );
459 $this->assertArrayHasKey(
'language',
$data );
460 $this->assertArrayHasKey(
'testDataField',
$data );
461 $this->assertEquals(
'test content',
$data[
'testDataField'] );
462 $this->assertEquals(
'wikitext',
$data[
'content_model'] );
472 $out = $page->getContentHandler()->getParserOutputForIndexing( $page );
473 $this->assertInstanceOf( ParserOutput::class,
$out );
474 $this->assertContains(
'one who smiths',
$out->getRawText() );
482 $models[] =
'Ferrari';
484 $this->assertContains(
'Ferrari', ContentHandler::getContentModels() );
492 'GetSlotDiffRenderer' => [],
497 $slotDiffRenderer = $contentHandler->getSlotDiffRenderer( RequestContext::getMain() );
498 $this->assertInstanceOf( TextSlotDiffRenderer::class, $slotDiffRenderer );
506 'GetSlotDiffRenderer' => [],
510 $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
511 ->disableOriginalConstructor()
514 $customDifferenceEngine->objectId = 12345;
515 $customContentHandler = $this->getMockBuilder( ContentHandler::class )
516 ->setConstructorArgs( [
'foo', [] ] )
517 ->setMethods( [
'createDifferenceEngine' ] )
518 ->getMockForAbstractClass();
519 $customContentHandler->expects( $this->any() )
520 ->method(
'createDifferenceEngine' )
521 ->willReturn( $customDifferenceEngine );
523 $slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
524 $this->assertInstanceOf( DifferenceEngineSlotDiffRenderer::class, $slotDiffRenderer );
526 $customDifferenceEngine->objectId,
527 TestingAccessWrapper::newFromObject( $slotDiffRenderer )->differenceEngine->objectId
536 'GetSlotDiffRenderer' => [],
540 $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
541 ->disableOriginalConstructor()
543 $customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
544 ->disableOriginalConstructor()
545 ->getMockForAbstractClass();
546 $customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
547 ->setConstructorArgs( [
'bar', [] ] )
548 ->setMethods( [
'createDifferenceEngine',
'getSlotDiffRendererInternal' ] )
549 ->getMockForAbstractClass();
550 $customContentHandler2->expects( $this->any() )
551 ->method(
'createDifferenceEngine' )
552 ->willReturn( $customDifferenceEngine );
553 $customContentHandler2->expects( $this->any() )
554 ->method(
'getSlotDiffRendererInternal' )
555 ->willReturn( $customSlotDiffRenderer );
557 $slotDiffRenderer = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
558 $this->assertSame( $customSlotDiffRenderer, $slotDiffRenderer );
566 'GetSlotDiffRenderer' => [],
570 $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
571 ->disableOriginalConstructor()
573 $customContentHandler = $this->getMockBuilder( ContentHandler::class )
574 ->setConstructorArgs( [
'foo', [] ] )
575 ->setMethods( [
'createDifferenceEngine' ] )
576 ->getMockForAbstractClass();
577 $customContentHandler->expects( $this->any() )
578 ->method(
'createDifferenceEngine' )
579 ->willReturn( $customDifferenceEngine );
582 $customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
583 ->disableOriginalConstructor()
584 ->getMockForAbstractClass();
585 $customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
586 ->setConstructorArgs( [
'bar', [] ] )
587 ->setMethods( [
'createDifferenceEngine',
'getSlotDiffRendererInternal' ] )
588 ->getMockForAbstractClass();
589 $customContentHandler2->expects( $this->any() )
590 ->method(
'createDifferenceEngine' )
591 ->willReturn( $customDifferenceEngine );
592 $customContentHandler2->expects( $this->any() )
593 ->method(
'getSlotDiffRendererInternal' )
594 ->willReturn( $customSlotDiffRenderer );
597 $customSlotDiffRenderer2 = $this->getMockBuilder( SlotDiffRenderer::class )
598 ->disableOriginalConstructor()
599 ->getMockForAbstractClass();
601 function (
$handler, &$slotDiffRenderer )
use ( $customSlotDiffRenderer2 ) {
602 $slotDiffRenderer = $customSlotDiffRenderer2;
605 $slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
606 $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
607 $slotDiffRenderer = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
608 $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
$wgLanguageCode
Site language code.
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
testGetPageLanguage( $title, $expected)
dataGetPageLanguage ContentHandler::getPageLanguage
testGetContentText_Null( $contentHandlerTextFallback)
dataGetContentText_Null ContentHandler::getContentText
testGetContentText_TextContent( $contentHandlerTextFallback)
dataGetContentText_TextContent ContentHandler::getContentText
testGetSlotDiffRenderer_bc()
ContentHandler::getSlotDiffRenderer.
testGetFieldsForSearchIndex()
ContentHandler::getFieldsForSearchIndex.
testGetChangeTag()
Test software tag that is added when content model of the page changes ContentHandler::getChangeTag.
testGetSlotDiffRenderer_nobc()
ContentHandler::getSlotDiffRenderer.
static dataGetLocalizedName()
testGetContentText_NonTextContent_ignore()
ContentHandler::getContentText.
testGetModelForID( $modelId, $handlerClass)
ContentHandler::getForModelID provideGetModelForID.
testSupportsDirectEditing()
ContentHandler::supportsDirectEditing.
testSupportsCategories()
ContentHandler::supportsCategories.
static dataGetContentText_Null()
testGetDefaultModelFor( $title, $expectedModelId)
dataGetDefaultModelFor ContentHandler::getDefaultModelFor
testGetContentModelsHook()
ContentHandler::getContentModels.
testGetContentText_NonTextContent_fail()
ContentHandler::getContentText should have thrown an exception for non-text Content object MWExceptio...
static dummyHookHandler( $foo, &$text, $bar)
testGetAutosummary()
ContentHandler::getAutosummary.
testDataIndexFields()
ContentHandler::getDataForSearchIndex.
static dataGetPageLanguage()
testMakeContent( $data, $title, $modelId, $format, $expectedModelId, $shouldFail)
dataMakeContent ContentHandler::makeContent
static dataGetContentText_TextContent()
testParserOutputForIndexing()
ContentHandler::getParserOutputForIndexing.
testGetForTitle( $title, $expectedContentModel)
dataGetDefaultModelFor ContentHandler::getForTitle
testGetSlotDiffRenderer_default()
ContentHandler::getSlotDiffRenderer.
testGetLocalizedName( $id, $expected)
dataGetLocalizedName ContentHandler::getLocalizedName
static dataGetDefaultModelFor()
testGetContentText_NonTextContent_serialize()
ContentHandler::getContentText.
testGetSlotDiffRenderer_hook()
ContentHandler::getSlotDiffRenderer.
A content handler knows how do deal with a specific type of content on a wiki page.
Dummy implementation of SearchIndexFieldDefinition for testing purposes.
Contain a class for special pages.
Class representing a MediaWiki article and history.
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
getContentHandler()
Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
Content handler for wiki text pages.
Content object for wiki text pages.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const CONTENT_FORMAT_JAVASCRIPT
const CONTENT_MODEL_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
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
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
namespace and then decline to actually register it file or subcat img or subcat $title
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
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
Allows to change the fields on the form that will be generated $name
the value to return A Title object or null for latest all implement SearchIndexField $engine
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
processing should stop and the error should be shown to the user * false
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
if(!isset( $args[0])) $lang