Go to the documentation of this file.
3 use Wikimedia\TestingAccessWrapper;
15 'wgExtraNamespaces' => [
17 12313 =>
'Dummy_talk',
21 'wgNamespaceContentModels' => [
24 'wgContentHandlers' => [
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]]' );
96 MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj(
$title );
98 $this->assertEquals( $expectedContentModel,
$handler->getModelID() );
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->assertEquals( $expected->getCode(),
$lang->getCode() );
177 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
182 $this->assertEquals(
'', $text );
198 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
203 $this->assertEquals(
$content->getNativeData(), $text );
212 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'fail' );
223 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'serialize' );
228 $this->assertEquals(
$content->serialize(), $text );
235 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'ignore' );
240 $this->assertNull( $text );
247 [
serialize(
'hallo' ),
'Dummy:Test',
null,
null,
"testing",
'hallo',
false ],
267 [
serialize(
'hallo' ),
'Dummy:Test',
null,
"testing",
"testing",
'hallo',
false ],
300 $expectedModelId, $expectedNativeData, $shouldFail
303 MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj(
$title );
308 $this->fail(
"ContentHandler::makeContent should have failed!" );
311 $this->assertEquals( $expectedModelId,
$content->getModel(),
'bad model id' );
312 $this->assertEquals( $expectedNativeData,
$content->getNativeData(),
'bads native data' );
314 if ( !$shouldFail ) {
315 $this->fail(
"ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
318 $this->assertTrue(
true );
337 $autoSummary =
$content->getAutosummary(
null, $newContent, 97 );
338 $this->assertEquals( $autoSummary,
339 wfMessage(
'autosumm-newblank' )->inContentLanguage()->
text() );
341 $autoSummary =
$content->getAutosummary(
null, $newContent, 92 );
342 $this->assertEquals( $autoSummary,
'' );
350 $this->
setMwGlobals(
'wgSoftwareTags', [
'mw-contentmodelchange' =>
true ] );
357 $tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent,
EDIT_UPDATE );
358 $this->assertSame( $tag,
'mw-contentmodelchange' );
366 $this->assertTrue(
$handler->supportsCategories(),
'content model supports categories' );
374 $this->assertFalse(
$handler->supportsDirectEditing(),
'direct editing is not supported' );
378 if ( $text ===
null || $text ===
false ) {
382 $text = strtoupper( $text );
406 $this->assertInstanceOf( $handlerClass,
$handler );
417 $fields =
$handler->getFieldsForSearchIndex( $searchEngine );
419 $this->assertArrayHasKey(
'category', $fields );
420 $this->assertArrayHasKey(
'external_link', $fields );
421 $this->assertArrayHasKey(
'outgoing_link', $fields );
422 $this->assertArrayHasKey(
'template', $fields );
423 $this->assertArrayHasKey(
'content_model', $fields );
430 $searchEngine->expects( $this->
any() )
431 ->method(
'makeSearchFieldMapping' )
432 ->will( $this->returnCallback(
function (
$name,
$type ) {
436 return $searchEngine;
455 $fields[
'testDataField'] =
'test content';
460 $this->assertArrayHasKey(
'text', $data );
461 $this->assertArrayHasKey(
'text_bytes', $data );
462 $this->assertArrayHasKey(
'language', $data );
463 $this->assertArrayHasKey(
'testDataField', $data );
464 $this->assertEquals(
'test content', $data[
'testDataField'] );
465 $this->assertEquals(
'wikitext', $data[
'content_model'] );
475 $out = $page->getContentHandler()->getParserOutputForIndexing( $page );
477 $this->assertContains(
'one who smiths',
$out->getRawText() );
485 $models[] =
'Ferrari';
495 'GetSlotDiffRenderer' => [],
509 'GetSlotDiffRenderer' => [],
514 ->disableOriginalConstructor()
517 $customDifferenceEngine->objectId = 12345;
519 ->setConstructorArgs( [
'foo', [] ] )
520 ->setMethods( [
'createDifferenceEngine' ] )
521 ->getMockForAbstractClass();
522 $customContentHandler->expects( $this->
any() )
523 ->method(
'createDifferenceEngine' )
524 ->willReturn( $customDifferenceEngine );
529 $customDifferenceEngine->objectId,
530 TestingAccessWrapper::newFromObject( $slotDiffRenderer )->differenceEngine->objectId
539 'GetSlotDiffRenderer' => [],
544 ->disableOriginalConstructor()
547 ->disableOriginalConstructor()
548 ->getMockForAbstractClass();
550 ->setConstructorArgs( [
'bar', [] ] )
551 ->setMethods( [
'createDifferenceEngine',
'getSlotDiffRendererInternal' ] )
552 ->getMockForAbstractClass();
553 $customContentHandler2->expects( $this->
any() )
554 ->method(
'createDifferenceEngine' )
555 ->willReturn( $customDifferenceEngine );
556 $customContentHandler2->expects( $this->
any() )
557 ->method(
'getSlotDiffRendererInternal' )
558 ->willReturn( $customSlotDiffRenderer );
561 $this->assertSame( $customSlotDiffRenderer, $slotDiffRenderer );
569 'GetSlotDiffRenderer' => [],
574 ->disableOriginalConstructor()
577 ->setConstructorArgs( [
'foo', [] ] )
578 ->setMethods( [
'createDifferenceEngine' ] )
579 ->getMockForAbstractClass();
580 $customContentHandler->expects( $this->
any() )
581 ->method(
'createDifferenceEngine' )
582 ->willReturn( $customDifferenceEngine );
586 ->disableOriginalConstructor()
587 ->getMockForAbstractClass();
589 ->setConstructorArgs( [
'bar', [] ] )
590 ->setMethods( [
'createDifferenceEngine',
'getSlotDiffRendererInternal' ] )
591 ->getMockForAbstractClass();
592 $customContentHandler2->expects( $this->
any() )
593 ->method(
'createDifferenceEngine' )
594 ->willReturn( $customDifferenceEngine );
595 $customContentHandler2->expects( $this->
any() )
596 ->method(
'getSlotDiffRendererInternal' )
597 ->willReturn( $customSlotDiffRenderer );
601 ->disableOriginalConstructor()
602 ->getMockForAbstractClass();
604 function (
$handler, &$slotDiffRenderer )
use ( $customSlotDiffRenderer2 ) {
605 $slotDiffRenderer = $customSlotDiffRenderer2;
609 $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
611 $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
A content handler knows how do deal with a specific type of content on a wiki page.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
testSupportsCategories()
ContentHandler::supportsCategories.
processing should stop and the error should be shown to the user * false
testSupportsDirectEditing()
ContentHandler::supportsDirectEditing.
if(!isset( $args[0])) $lang
testGetPageLanguage( $title, $expected)
dataGetPageLanguage ContentHandler::getPageLanguage
testGetFieldsForSearchIndex()
ContentHandler::getFieldsForSearchIndex.
testGetSlotDiffRenderer_hook()
ContentHandler::getSlotDiffRenderer.
Class representing a MediaWiki article and history.
testGetChangeTag()
Test software tag that is added when content model of the page changes ContentHandler::getChangeTag.
testGetAutosummary()
ContentHandler::getAutosummary.
static dataGetDefaultModelFor()
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
const CONTENT_MODEL_WIKITEXT
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
static dataGetPageLanguage()
static dataGetContentText_Null()
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
namespace and then decline to actually register it file or subcat img or subcat $title
static getContentModels()
testGetContentText_NonTextContent_ignore()
ContentHandler::getContentText.
testGetDefaultModelFor( $title, $expectedModelId)
dataGetDefaultModelFor ContentHandler::getDefaultModelFor
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
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
the value to return A Title object or null for latest all implement SearchIndexField $engine
Content object for wiki text pages.
const CONTENT_FORMAT_WIKITEXT
testGetSlotDiffRenderer_nobc()
ContentHandler::getSlotDiffRenderer.
testGetContentText_NonTextContent_fail()
ContentHandler::getContentText should have thrown an exception for non-text Content object MWExceptio...
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
testGetLocalizedName( $id, $expected)
dataGetLocalizedName ContentHandler::getLocalizedName
testGetModelForID( $modelId, $handlerClass)
ContentHandler::getForModelID provideGetModelForID.
Allows to change the fields on the form that will be generated $name
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Content handler for wiki text pages.
$wgLanguageCode
Site language code.
testGetSlotDiffRenderer_default()
ContentHandler::getSlotDiffRenderer.
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
static getMain()
Get the RequestContext object associated with the main request.
Contain a class for special pages.
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
Dummy implementation of SearchIndexFieldDefinition for testing purposes.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
testParserOutputForIndexing()
ContentHandler::getParserOutputForIndexing.
testGetContentText_Null( $contentHandlerTextFallback)
dataGetContentText_Null ContentHandler::getContentText
static dataGetLocalizedName()
testDataIndexFields()
ContentHandler::getDataForSearchIndex.
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
static dataGetContentText_TextContent()
testGetContentText_TextContent( $contentHandlerTextFallback)
dataGetContentText_TextContent ContentHandler::getContentText
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
const CONTENT_MODEL_JAVASCRIPT
const CONTENT_FORMAT_JAVASCRIPT
testGetForTitle( $title, $expectedContentModel)
dataGetDefaultModelFor ContentHandler::getForTitle
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
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 "<
getContentHandler()
Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
testGetContentText_NonTextContent_serialize()
ContentHandler::getContentText.
testGetSlotDiffRenderer_bc()
ContentHandler::getSlotDiffRenderer.
static dummyHookHandler( $foo, &$text, $bar)
testGetContentModelsHook()
ContentHandler::getContentModels.
testMakeContent( $data, $title, $modelId, $format, $expectedModelId, $expectedNativeData, $shouldFail)
dataMakeContent ContentHandler::makeContent
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