15 'wgExtraNamespaces' => [
17 12313 =>
'Dummy_talk',
21 'wgNamespaceContentModels' => [
24 'wgContentHandlers' => [
30 'testing' => DummyContentHandlerForTesting::class,
31 'testing-callbacks' =>
function ( $modelId ) {
38 MWNamespace::clearCaches();
41 MediaWikiServices::getInstance()->resetServiceForTesting(
'LinkCache' );
48 MWNamespace::clearCaches();
51 MediaWikiServices::getInstance()->resetServiceForTesting(
'LinkCache' );
57 $this->
insertPage(
'Not_Main_Page',
'This is not a main page' );
58 $this->
insertPage(
'Smithee',
'A smithee is one who smiths. See also [[Alan Smithee]]' );
94 $title = Title::newFromText( $title );
95 $this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) );
103 $title = Title::newFromText( $title );
104 LinkCache::singleton()->addBadLinkObj( $title );
105 $handler = ContentHandler::getForTitle( $title );
106 $this->assertEquals( $expectedContentModel,
$handler->getModelID() );
124 $name = ContentHandler::getLocalizedName( $id );
127 $this->assertNotNull( $name,
"no name found for content model $id" );
128 $this->assertTrue( preg_match( $expected, $name ) > 0,
129 "content model name for #$id did not match pattern $expected"
132 $this->assertEquals( $id, $name,
"localization of unknown model $id should have "
133 .
"fallen back to use the model id directly."
144 [
"MediaWiki:common.js",
'en' ],
145 [
"User:Foo/common.js",
'en' ],
146 [
"MediaWiki:common.css",
'en' ],
147 [
"User:Foo/common.css",
'en' ],
159 if ( is_string( $title ) ) {
160 $title = Title::newFromText( $title );
161 LinkCache::singleton()->addBadLinkObj( $title );
166 $handler = ContentHandler::getForTitle( $title );
169 $this->assertEquals( $expected->getCode(),
$lang->getCode() );
185 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
189 $text = ContentHandler::getContentText( $content );
190 $this->assertEquals(
'', $text );
206 $this->
setMwGlobals(
'wgContentHandlerTextFallback', $contentHandlerTextFallback );
210 $text = ContentHandler::getContentText( $content );
211 $this->assertEquals( $content->getNativeData(), $text );
220 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'fail' );
224 ContentHandler::getContentText( $content );
231 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'serialize' );
235 $text = ContentHandler::getContentText( $content );
236 $this->assertEquals( $content->serialize(), $text );
243 $this->
setMwGlobals(
'wgContentHandlerTextFallback',
'ignore' );
247 $text = ContentHandler::getContentText( $content );
248 $this->assertNull( $text );
255 [
serialize(
'hallo' ),
'Dummy:Test',
null,
null,
"testing",
'hallo',
false ],
275 [
serialize(
'hallo' ),
'Dummy:Test',
null,
"testing",
"testing",
'hallo',
false ],
308 $expectedModelId, $expectedNativeData, $shouldFail
310 $title = Title::newFromText( $title );
311 LinkCache::singleton()->addBadLinkObj( $title );
313 $content = ContentHandler::makeContent( $data, $title, $modelId, $format );
316 $this->fail(
"ContentHandler::makeContent should have failed!" );
319 $this->assertEquals( $expectedModelId, $content->getModel(),
'bad model id' );
320 $this->assertEquals( $expectedNativeData, $content->getNativeData(),
'bads native data' );
322 if ( !$shouldFail ) {
323 $this->fail(
"ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
326 $this->assertTrue(
true );
338 $this->
setMwGlobals(
'wgContLang', Language::factory(
'en' ) );
341 $title = Title::newFromText(
'Help:Test' );
345 $autoSummary = $content->getAutosummary(
null, $newContent, 97 );
346 $this->assertEquals( $autoSummary,
347 wfMessage(
'autosumm-newblank' )->inContentLanguage()->
text() );
349 $autoSummary = $content->getAutosummary(
null, $newContent, 92 );
350 $this->assertEquals( $autoSummary,
'' );
358 $this->
setMwGlobals(
'wgSoftwareTags', [
'mw-contentmodelchange' =>
true ] );
365 $tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent,
EDIT_UPDATE );
366 $this->assertSame( $tag,
'mw-contentmodelchange' );
374 $this->assertTrue(
$handler->supportsCategories(),
'content model supports categories' );
382 $this->assertFalse(
$handler->supportsDirectEditing(),
'direct editing is not supported' );
386 if ( $text ===
null || $text ===
false ) {
390 $text = strtoupper( $text );
402 [
'testing', DummyContentHandlerForTesting::class ],
403 [
'testing-callbacks', DummyContentHandlerForTesting::class ],
412 $handler = ContentHandler::getForModelID( $modelId );
414 $this->assertInstanceOf( $handlerClass,
$handler );
425 $fields =
$handler->getFieldsForSearchIndex( $searchEngine );
427 $this->assertArrayHasKey(
'category', $fields );
428 $this->assertArrayHasKey(
'external_link', $fields );
429 $this->assertArrayHasKey(
'outgoing_link', $fields );
430 $this->assertArrayHasKey(
'template', $fields );
431 $this->assertArrayHasKey(
'content_model', $fields );
435 $searchEngine = $this->getMockBuilder( SearchEngine::class )
438 $searchEngine->expects( $this->
any() )
439 ->method(
'makeSearchFieldMapping' )
440 ->will( $this->returnCallback(
function ( $name,
$type ) {
444 return $searchEngine;
451 $mockEngine = $this->createMock( SearchEngine::class );
452 $title = Title::newFromText(
'Not_Main_Page',
NS_MAIN );
463 $fields[
'testDataField'] =
'test content';
468 $this->assertArrayHasKey(
'text', $data );
469 $this->assertArrayHasKey(
'text_bytes', $data );
470 $this->assertArrayHasKey(
'language', $data );
471 $this->assertArrayHasKey(
'testDataField', $data );
472 $this->assertEquals(
'test content', $data[
'testDataField'] );
473 $this->assertEquals(
'wikitext', $data[
'content_model'] );
480 $title = Title::newFromText(
'Smithee',
NS_MAIN );
483 $out = $page->getContentHandler()->getParserOutputForIndexing( $page );
484 $this->assertInstanceOf( ParserOutput::class,
$out );
485 $this->assertContains(
'one who smiths',
$out->getRawText() );
493 $models[] =
'Ferrari';
495 $this->assertContains(
'Ferrari', ContentHandler::getContentModels() );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
$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
testGetFieldsForSearchIndex()
ContentHandler::getFieldsForSearchIndex.
testGetChangeTag()
Test software tag that is added when content model of the page changes ContentHandler::getChangeTag.
static dataGetLocalizedName()
testGetContentText_NonTextContent_ignore()
ContentHandler::getContentText.
testGetModelForID( $modelId, $handlerClass)
ContentHandler::getForModelID provideGetModelForID.
testMakeContent( $data, $title, $modelId, $format, $expectedModelId, $expectedNativeData, $shouldFail)
dataMakeContent ContentHandler::makeContent
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()
static dataGetContentText_TextContent()
testParserOutputForIndexing()
ContentHandler::getParserOutputForIndexing.
testGetForTitle( $title, $expectedContentModel)
dataGetDefaultModelFor ContentHandler::getForTitle
testGetLocalizedName( $id, $expected)
dataGetLocalizedName ContentHandler::getLocalizedName
static dataGetDefaultModelFor()
testGetContentText_NonTextContent_serialize()
ContentHandler::getContentText.
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 object for wiki text pages.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
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 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
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
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
the value to return A Title object or null for latest all implement SearchIndexField $engine
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
processing should stop and the error should be shown to the user * false
const CONTENT_FORMAT_JAVASCRIPT
const CONTENT_MODEL_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
if(!isset( $args[0])) $lang