MediaWiki  1.33.0
ContentHandlerTest.php
Go to the documentation of this file.
1 <?php
3 use Wikimedia\TestingAccessWrapper;
4 
10 
11  protected function setUp() {
12  parent::setUp();
13 
14  $this->setMwGlobals( [
15  'wgExtraNamespaces' => [
16  12312 => 'Dummy',
17  12313 => 'Dummy_talk',
18  ],
19  // The below tests assume that namespaces not mentioned here (Help, User, MediaWiki, ..)
20  // default to CONTENT_MODEL_WIKITEXT.
21  'wgNamespaceContentModels' => [
22  12312 => 'testing',
23  ],
24  'wgContentHandlers' => [
31  'testing-callbacks' => function ( $modelId ) {
32  return new DummyContentHandlerForTesting( $modelId );
33  }
34  ],
35  ] );
36 
37  // Reset LinkCache
38  MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
39  }
40 
41  protected function tearDown() {
42  // Reset LinkCache
43  MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
44 
45  parent::tearDown();
46  }
47 
48  public function addDBDataOnce() {
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]]' );
51  }
52 
53  public static function dataGetDefaultModelFor() {
54  return [
55  [ 'Help:Foo', CONTENT_MODEL_WIKITEXT ],
56  [ 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ],
57  [ 'Help:Foo.css', CONTENT_MODEL_WIKITEXT ],
58  [ 'Help:Foo.json', CONTENT_MODEL_WIKITEXT ],
59  [ 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ],
60  [ 'User:Foo', CONTENT_MODEL_WIKITEXT ],
61  [ 'User:Foo.js', CONTENT_MODEL_WIKITEXT ],
62  [ 'User:Foo.css', CONTENT_MODEL_WIKITEXT ],
63  [ 'User:Foo.json', CONTENT_MODEL_WIKITEXT ],
64  [ 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ],
65  [ 'User:Foo/bar.css', CONTENT_MODEL_CSS ],
66  [ 'User:Foo/bar.json', CONTENT_MODEL_JSON ],
67  [ 'User:Foo/bar.json.nope', CONTENT_MODEL_WIKITEXT ],
68  [ 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ],
69  [ 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ],
70  [ 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ],
71  [ 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ],
72  [ 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ],
73  [ 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ],
74  [ 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ],
75  [ 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ],
76  [ 'MediaWiki:Foo.json', CONTENT_MODEL_JSON ],
77  [ 'MediaWiki:Foo.JSON', CONTENT_MODEL_WIKITEXT ],
78  ];
79  }
80 
85  public function testGetDefaultModelFor( $title, $expectedModelId ) {
87  $this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) );
88  }
89 
94  public function testGetForTitle( $title, $expectedContentModel ) {
96  MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
98  $this->assertEquals( $expectedContentModel, $handler->getModelID() );
99  }
100 
101  public static function dataGetLocalizedName() {
102  return [
103  [ null, null ],
104  [ "xyzzy", null ],
105 
106  // XXX: depends on content language
107  [ CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ],
108  ];
109  }
110 
115  public function testGetLocalizedName( $id, $expected ) {
117 
118  if ( $expected ) {
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"
122  );
123  } else {
124  $this->assertEquals( $id, $name, "localization of unknown model $id should have "
125  . "fallen back to use the model id directly."
126  );
127  }
128  }
129 
130  public static function dataGetPageLanguage() {
131  global $wgLanguageCode;
132 
133  return [
134  [ "Main", $wgLanguageCode ],
135  [ "Dummy:Foo", $wgLanguageCode ],
136  [ "MediaWiki:common.js", 'en' ],
137  [ "User:Foo/common.js", 'en' ],
138  [ "MediaWiki:common.css", 'en' ],
139  [ "User:Foo/common.css", 'en' ],
140  [ "User:Foo", $wgLanguageCode ],
141 
142  [ CONTENT_MODEL_JAVASCRIPT, 'javascript' ],
143  ];
144  }
145 
150  public function testGetPageLanguage( $title, $expected ) {
151  if ( is_string( $title ) ) {
153  MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
154  }
155 
156  $expected = wfGetLangObj( $expected );
157 
159  $lang = $handler->getPageLanguage( $title );
160 
161  $this->assertInstanceOf( Language::class, $lang );
162  $this->assertEquals( $expected->getCode(), $lang->getCode() );
163  }
164 
165  public static function dataGetContentText_Null() {
166  return [
167  [ 'fail' ],
168  [ 'serialize' ],
169  [ 'ignore' ],
170  ];
171  }
172 
177  public function testGetContentText_Null( $contentHandlerTextFallback ) {
178  $this->setMwGlobals( 'wgContentHandlerTextFallback', $contentHandlerTextFallback );
179 
180  $content = null;
181 
183  $this->assertEquals( '', $text );
184  }
185 
186  public static function dataGetContentText_TextContent() {
187  return [
188  [ 'fail' ],
189  [ 'serialize' ],
190  [ 'ignore' ],
191  ];
192  }
193 
198  public function testGetContentText_TextContent( $contentHandlerTextFallback ) {
199  $this->setMwGlobals( 'wgContentHandlerTextFallback', $contentHandlerTextFallback );
200 
201  $content = new WikitextContent( "hello world" );
202 
204  $this->assertEquals( $content->getText(), $text );
205  }
206 
213  $this->setMwGlobals( 'wgContentHandlerTextFallback', 'fail' );
214 
215  $content = new DummyContentForTesting( "hello world" );
216 
218  }
219 
224  $this->setMwGlobals( 'wgContentHandlerTextFallback', 'serialize' );
225 
226  $content = new DummyContentForTesting( "hello world" );
227 
229  $this->assertEquals( $content->serialize(), $text );
230  }
231 
236  $this->setMwGlobals( 'wgContentHandlerTextFallback', 'ignore' );
237 
238  $content = new DummyContentForTesting( "hello world" );
239 
241  $this->assertNull( $text );
242  }
243 
244  public static function dataMakeContent() {
245  return [
246  [ 'hallo', 'Help:Test', null, null, CONTENT_MODEL_WIKITEXT, false ],
247  [ 'hallo', 'MediaWiki:Test.js', null, null, CONTENT_MODEL_JAVASCRIPT, false ],
248  [ serialize( 'hallo' ), 'Dummy:Test', null, null, "testing", false ],
249 
250  [
251  'hallo',
252  'Help:Test',
253  null,
256  false
257  ],
258  [
259  'hallo',
260  'MediaWiki:Test.js',
261  null,
264  false
265  ],
266  [ serialize( 'hallo' ), 'Dummy:Test', null, "testing", "testing", false ],
267 
268  [ 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, false ],
269  [
270  'hallo',
271  'MediaWiki:Test.js',
273  null,
275  false
276  ],
277  [
278  serialize( 'hallo' ),
279  'Dummy:Test',
281  null,
283  false
284  ],
285 
286  [ 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT, "testing", null, true ],
287  [ 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS, "testing", null, true ],
288  [ 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT, "testing", null, true ],
289  ];
290  }
291 
296  public function testMakeContent( $data, $title, $modelId, $format,
297  $expectedModelId, $shouldFail
298  ) {
300  MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
301  try {
302  $content = ContentHandler::makeContent( $data, $title, $modelId, $format );
303 
304  if ( $shouldFail ) {
305  $this->fail( "ContentHandler::makeContent should have failed!" );
306  }
307 
308  $this->assertEquals( $expectedModelId, $content->getModel(), 'bad model id' );
309  $this->assertEquals( $data, $content->serialize(), 'bad serialized data' );
310  } catch ( MWException $ex ) {
311  if ( !$shouldFail ) {
312  $this->fail( "ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
313  } else {
314  // dummy, so we don't get the "test did not perform any assertions" message.
315  $this->assertTrue( true );
316  }
317  }
318  }
319 
326  public function testGetAutosummary() {
327  $this->setContentLang( 'en' );
328 
330  $title = Title::newFromText( 'Help:Test' );
331  // Create a new content object with no content
332  $newContent = ContentHandler::makeContent( '', $title, CONTENT_MODEL_WIKITEXT, null );
333  // first check, if we become a blank page created summary with the right bitmask
334  $autoSummary = $content->getAutosummary( null, $newContent, 97 );
335  $this->assertEquals( $autoSummary,
336  wfMessage( 'autosumm-newblank' )->inContentLanguage()->text() );
337  // now check, what we become with another bitmask
338  $autoSummary = $content->getAutosummary( null, $newContent, 92 );
339  $this->assertEquals( $autoSummary, '' );
340  }
341 
346  public function testGetChangeTag() {
347  $this->setMwGlobals( 'wgSoftwareTags', [ 'mw-contentmodelchange' => true ] );
348  $wikitextContentHandler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
349  // Create old content object with javascript content model
350  $oldContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_JAVASCRIPT, null );
351  // Create new content object with wikitext content model
352  $newContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_WIKITEXT, null );
353  // Get the tag for this edit
354  $tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent, EDIT_UPDATE );
355  $this->assertSame( $tag, 'mw-contentmodelchange' );
356  }
357 
361  public function testSupportsCategories() {
363  $this->assertTrue( $handler->supportsCategories(), 'content model supports categories' );
364  }
365 
369  public function testSupportsDirectEditing() {
371  $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' );
372  }
373 
374  public static function dummyHookHandler( $foo, &$text, $bar ) {
375  if ( $text === null || $text === false ) {
376  return false;
377  }
378 
379  $text = strtoupper( $text );
380 
381  return true;
382  }
383 
384  public function provideGetModelForID() {
385  return [
392  [ 'testing-callbacks', DummyContentHandlerForTesting::class ],
393  ];
394  }
395 
400  public function testGetModelForID( $modelId, $handlerClass ) {
402 
403  $this->assertInstanceOf( $handlerClass, $handler );
404  }
405 
409  public function testGetFieldsForSearchIndex() {
410  $searchEngine = $this->newSearchEngine();
411 
413 
414  $fields = $handler->getFieldsForSearchIndex( $searchEngine );
415 
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 );
421  }
422 
423  private function newSearchEngine() {
424  $searchEngine = $this->getMockBuilder( SearchEngine::class )
425  ->getMock();
426 
427  $searchEngine->expects( $this->any() )
428  ->method( 'makeSearchFieldMapping' )
429  ->will( $this->returnCallback( function ( $name, $type ) {
431  } ) );
432 
433  return $searchEngine;
434  }
435 
439  public function testDataIndexFields() {
440  $mockEngine = $this->createMock( SearchEngine::class );
441  $title = Title::newFromText( 'Not_Main_Page', NS_MAIN );
442  $page = new WikiPage( $title );
443 
444  $this->setTemporaryHook( 'SearchDataForIndex',
445  function (
446  &$fields,
448  WikiPage $page,
451  ) {
452  $fields['testDataField'] = 'test content';
453  } );
454 
455  $output = $page->getContent()->getParserOutput( $title );
456  $data = $page->getContentHandler()->getDataForSearchIndex( $page, $output, $mockEngine );
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'] );
463  }
464 
468  public function testParserOutputForIndexing() {
469  $title = Title::newFromText( 'Smithee', NS_MAIN );
470  $page = new WikiPage( $title );
471 
472  $out = $page->getContentHandler()->getParserOutputForIndexing( $page );
473  $this->assertInstanceOf( ParserOutput::class, $out );
474  $this->assertContains( 'one who smiths', $out->getRawText() );
475  }
476 
480  public function testGetContentModelsHook() {
481  $this->setTemporaryHook( 'GetContentModels', function ( &$models ) {
482  $models[] = 'Ferrari';
483  } );
484  $this->assertContains( 'Ferrari', ContentHandler::getContentModels() );
485  }
486 
491  $this->mergeMwGlobalArrayValue( 'wgHooks', [
492  'GetSlotDiffRenderer' => [],
493  ] );
494 
495  // test default renderer
496  $contentHandler = new WikitextContentHandler( CONTENT_MODEL_WIKITEXT );
497  $slotDiffRenderer = $contentHandler->getSlotDiffRenderer( RequestContext::getMain() );
498  $this->assertInstanceOf( TextSlotDiffRenderer::class, $slotDiffRenderer );
499  }
500 
504  public function testGetSlotDiffRenderer_bc() {
505  $this->mergeMwGlobalArrayValue( 'wgHooks', [
506  'GetSlotDiffRenderer' => [],
507  ] );
508 
509  // test B/C renderer
510  $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
511  ->disableOriginalConstructor()
512  ->getMock();
513  // hack to track object identity across cloning
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 );
525  $this->assertSame(
526  $customDifferenceEngine->objectId,
527  TestingAccessWrapper::newFromObject( $slotDiffRenderer )->differenceEngine->objectId
528  );
529  }
530 
534  public function testGetSlotDiffRenderer_nobc() {
535  $this->mergeMwGlobalArrayValue( 'wgHooks', [
536  'GetSlotDiffRenderer' => [],
537  ] );
538 
539  // test that B/C renderer does not get used when getSlotDiffRendererInternal is overridden
540  $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
541  ->disableOriginalConstructor()
542  ->getMock();
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 );
559  }
560 
564  public function testGetSlotDiffRenderer_hook() {
565  $this->mergeMwGlobalArrayValue( 'wgHooks', [
566  'GetSlotDiffRenderer' => [],
567  ] );
568 
569  // test that the hook handler takes precedence
570  $customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
571  ->disableOriginalConstructor()
572  ->getMock();
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();
600  $this->setTemporaryHook( 'GetSlotDiffRenderer',
601  function ( $handler, &$slotDiffRenderer ) use ( $customSlotDiffRenderer2 ) {
602  $slotDiffRenderer = $customSlotDiffRenderer2;
603  } );
604 
605  $slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
606  $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
607  $slotDiffRenderer = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
608  $this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
609  }
610 
611 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:239
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:53
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:252
ContentHandlerTest\setUp
setUp()
Definition: ContentHandlerTest.php:11
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
ContentHandlerTest\testSupportsCategories
testSupportsCategories()
ContentHandler::supportsCategories.
Definition: ContentHandlerTest.php:361
ParserOutput
Definition: ParserOutput.php:25
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ContentHandlerTest\testSupportsDirectEditing
testSupportsDirectEditing()
ContentHandler::supportsDirectEditing.
Definition: ContentHandlerTest.php:369
ContentHandlerTest\addDBDataOnce
addDBDataOnce()
Stub.
Definition: ContentHandlerTest.php:48
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:904
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:237
ContentHandlerTest\testGetPageLanguage
testGetPageLanguage( $title, $expected)
dataGetPageLanguage ContentHandler::getPageLanguage
Definition: ContentHandlerTest.php:150
$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 $out
Definition: hooks.txt:780
ContentHandlerTest\testGetFieldsForSearchIndex
testGetFieldsForSearchIndex()
ContentHandler::getFieldsForSearchIndex.
Definition: ContentHandlerTest.php:409
ContentHandlerTest\tearDown
tearDown()
Definition: ContentHandlerTest.php:41
ContentHandlerTest\testGetSlotDiffRenderer_hook
testGetSlotDiffRenderer_hook()
ContentHandler::getSlotDiffRenderer.
Definition: ContentHandlerTest.php:564
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:45
ContentHandlerTest\testGetChangeTag
testGetChangeTag()
Test software tag that is added when content model of the page changes ContentHandler::getChangeTag.
Definition: ContentHandlerTest.php:346
ContentHandlerTest\testGetAutosummary
testGetAutosummary()
ContentHandler::getAutosummary.
Definition: ContentHandlerTest.php:326
ContentHandlerTest\dataGetDefaultModelFor
static dataGetDefaultModelFor()
Definition: ContentHandlerTest.php:53
ContentHandler\getForTitle
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
Definition: ContentHandler.php:199
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
MediaWikiTestCase\insertPage
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
Insert a new page.
Definition: MediaWikiTestCase.php:1222
serialize
serialize()
Definition: ApiMessageTrait.php:134
php
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
Definition: injection.txt:35
ContentHandlerTest\dataGetPageLanguage
static dataGetPageLanguage()
Definition: ContentHandlerTest.php:130
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
ContentHandlerTest\dataGetContentText_Null
static dataGetContentText_Null()
Definition: ContentHandlerTest.php:165
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:184
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
ContentHandlerTest\testMakeContent
testMakeContent( $data, $title, $modelId, $format, $expectedModelId, $shouldFail)
dataMakeContent ContentHandler::makeContent
Definition: ContentHandlerTest.php:296
ContentHandler\getContentModels
static getContentModels()
Definition: ContentHandler.php:327
$handler
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
Definition: hooks.txt:780
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
ContentHandlerTest\testGetContentText_NonTextContent_ignore
testGetContentText_NonTextContent_ignore()
ContentHandler::getContentText.
Definition: ContentHandlerTest.php:235
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
ContentHandlerTest\testGetDefaultModelFor
testGetDefaultModelFor( $title, $expectedModelId)
dataGetDefaultModelFor ContentHandler::getDefaultModelFor
Definition: ContentHandlerTest.php:85
WikiPage\getContent
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition: WikiPage.php:816
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1241
use
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
Definition: MIT-LICENSE.txt:10
ContentHandlerTest\newSearchEngine
newSearchEngine()
Definition: ContentHandlerTest.php:423
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2901
$output
$output
Definition: SyntaxHighlight.php:334
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
CONTENT_FORMAT_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
Definition: Defines.php:250
ContentHandlerTest\testGetSlotDiffRenderer_nobc
testGetSlotDiffRenderer_nobc()
ContentHandler::getSlotDiffRenderer.
Definition: ContentHandlerTest.php:534
ContentHandlerTest\testGetContentText_NonTextContent_fail
testGetContentText_NonTextContent_fail()
ContentHandler::getContentText should have thrown an exception for non-text Content object MWExceptio...
Definition: ContentHandlerTest.php:212
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:133
ContentHandlerTest\testGetLocalizedName
testGetLocalizedName( $id, $expected)
dataGetLocalizedName ContentHandler::getLocalizedName
Definition: ContentHandlerTest.php:115
null
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
Definition: hooks.txt:780
ContentHandlerTest\testGetModelForID
testGetModelForID( $modelId, $handlerClass)
ContentHandler::getForModelID provideGetModelForID.
Definition: ContentHandlerTest.php:400
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:1066
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
EDIT_UPDATE
const EDIT_UPDATE
Definition: Defines.php:153
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:314
WikitextContentHandler
Content handler for wiki text pages.
Definition: WikitextContentHandler.php:33
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2912
ContentHandlerTest\testGetSlotDiffRenderer_default
testGetSlotDiffRenderer_default()
ContentHandler::getSlotDiffRenderer.
Definition: ContentHandlerTest.php:490
DummyContentForTesting
Definition: DummyContentForTesting.php:3
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
text
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
Definition: All_system_messages.txt:1267
DummySearchIndexFieldDefinition
Dummy implementation of SearchIndexFieldDefinition for testing purposes.
Definition: DummySearchIndexFieldDefinition.php:8
ContentHandlerTest\dataMakeContent
static dataMakeContent()
Definition: ContentHandlerTest.php:244
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:83
ContentHandlerTest\testParserOutputForIndexing
testParserOutputForIndexing()
ContentHandler::getParserOutputForIndexing.
Definition: ContentHandlerTest.php:468
ContentHandlerTest\testGetContentText_Null
testGetContentText_Null( $contentHandlerTextFallback)
dataGetContentText_Null ContentHandler::getContentText
Definition: ContentHandlerTest.php:177
ContentHandlerTest\dataGetLocalizedName
static dataGetLocalizedName()
Definition: ContentHandlerTest.php:101
ContentHandlerTest\testDataIndexFields
testDataIndexFields()
ContentHandler::getDataForSearchIndex.
Definition: ContentHandlerTest.php:439
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 just before the function returns a value If you return true
Definition: hooks.txt:1985
$content
$content
Definition: pageupdater.txt:72
ContentHandlerTest\dataGetContentText_TextContent
static dataGetContentText_TextContent()
Definition: ContentHandlerTest.php:186
ContentHandlerTest\testGetContentText_TextContent
testGetContentText_TextContent( $contentHandlerTextFallback)
dataGetContentText_TextContent ContentHandler::getContentText
Definition: ContentHandlerTest.php:198
class
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
Definition: maintenance.txt:52
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:236
CONTENT_FORMAT_JAVASCRIPT
const CONTENT_FORMAT_JAVASCRIPT
Definition: Defines.php:252
ContentHandlerTest\testGetForTitle
testGetForTitle( $title, $expectedContentModel)
dataGetDefaultModelFor ContentHandler::getForTitle
Definition: ContentHandlerTest.php:94
MediaWikiTestCase\setTemporaryHook
setTemporaryHook( $hookName, $handler)
Create a temporary hook handler which will be reset by tearDown.
Definition: MediaWikiTestCase.php:2325
ContentHandlerTest\provideGetModelForID
provideGetModelForID()
Definition: ContentHandlerTest.php:384
MediaWikiServices
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
Definition: injection.txt:23
CONTENT_MODEL_TEXT
const CONTENT_MODEL_TEXT
Definition: Defines.php:238
wfMessage
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 "&lt
ContentHandlerTest
ContentHandler Database.
Definition: ContentHandlerTest.php:9
WikiPage\getContentHandler
getContentHandler()
Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
Definition: WikiPage.php:286
ContentHandlerTest\testGetContentText_NonTextContent_serialize
testGetContentText_NonTextContent_serialize()
ContentHandler::getContentText.
Definition: ContentHandlerTest.php:223
ContentHandlerTest\testGetSlotDiffRenderer_bc
testGetSlotDiffRenderer_bc()
ContentHandler::getSlotDiffRenderer.
Definition: ContentHandlerTest.php:504
DummyContentHandlerForTesting
Definition: DummyContentHandlerForTesting.php:3
ContentHandlerTest\dummyHookHandler
static dummyHookHandler( $foo, &$text, $bar)
Definition: ContentHandlerTest.php:374
ContentHandlerTest\testGetContentModelsHook
testGetContentModelsHook()
ContentHandler::getContentModels.
Definition: ContentHandlerTest.php:480
$type
$type
Definition: testCompression.php:48