Go to the documentation of this file.
31 "WikitextContentTest_testGetParserOutput",
34 "<div class=\"mw-parser-output\"><p>hello <i>world</i>\n</p>\n\n\n</div>"
42 [
"WikitextContentTest_testGetSecondaryDataUpdates_1",
51 [
"WikitextContentTest_testGetSecondaryDataUpdates_2",
57 [
'World_test_21344' => 0 ]
78 $page->doEditContent(
$content,
'' );
83 foreach ( $updates
as $update ) {
84 $class = get_class( $update );
85 $updates[$class] = $update;
88 foreach ( $expectedStuff
as $class => $fieldValues ) {
89 $this->assertArrayHasKey( $class, $updates,
"missing an update of type $class" );
91 $update = $updates[$class];
93 foreach ( $fieldValues
as $field =>
$value ) {
94 $v = $update->$field; #
if the field doesn
't exist, just crash and burn
98 "unexpected value for field $field in instance of $class"
103 $page->doDeleteArticle( '' );
106 public static function dataGetSection() {
128 public function testGetSection( $text, $sectionId, $expectedText ) {
129 $content = $this->newContent( $text );
131 $sectionContent = $content->getSection( $sectionId );
132 if ( is_object( $sectionContent ) ) {
133 $sectionText = $sectionContent->getText();
135 $sectionText = $sectionContent;
138 $this->assertEquals( $expectedText, $sectionText );
141 public static function dataReplaceSection() {
147 trim( preg_replace( '/^Intro/sm
', 'No more
', self::$sections ) )
157 "== TEST ==\nmore fun",
160 '/^== test ==.*== foo ==/sm
', "== TEST ==\nmore fun\n\n== foo ==",
174 trim( self::$sections ) . "\n\n\n== New ==\n\nNo more"
183 public function testReplaceSection( $text, $section, $with, $sectionTitle, $expected ) {
184 $content = $this->newContent( $text );
186 $c = $content->replaceSection( $section, $this->newContent( $with ), $sectionTitle );
188 $this->assertEquals( $expected, $c ? $c->getText() : null );
194 public function testAddSectionHeader() {
195 $content = $this->newContent( 'hello world
' );
196 $content = $content->addSectionHeader( 'test
' );
198 $this->assertEquals( "== test ==\n\nhello world", $content->getText() );
201 public static function dataPreSaveTransform() {
203 [ 'hello
this is ~~~
',
204 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
206 [ 'hello \
'\'this\
'\' is <nowiki>~~~</nowiki>
',
207 'hello \
'\'this\
'\' is <nowiki>~~~</nowiki>
',
216 public static function dataPreloadTransform() {
223 'hello \
'\'this\
'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>
',
224 'hello \
'\'this\
'\' is bar
',
229 public static function dataGetRedirectTarget() {
231 [ '#REDIRECT [[
Test]]
',
237 [ '* #REDIRECT [[
Test]]
',
243 public static function dataGetTextForSummary() {
253 [ '[[hello world]].
',
260 public static function dataIsCountable() {
292 [ '#REDIRECT [[bar]]
',
297 [ '#REDIRECT [[bar]]
',
308 public function testMatchMagicWord() {
309 $mw = MediaWikiServices::getInstance()->getMagicWordFactory()->get( "staticredirect" );
311 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
312 $this->assertTrue( $content->matchMagicWord( $mw ), "should have matched magic word" );
314 $content = $this->newContent( "#REDIRECT [[FOO]]" );
316 $content->matchMagicWord( $mw ),
317 "should not have matched magic word"
324 public function testUpdateRedirect() {
325 $target = Title::newFromText( "testUpdateRedirect_target" );
327 // test with non-redirect page
328 $content = $this->newContent( "hello world." );
329 $newContent = $content->updateRedirect( $target );
331 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged" );
333 // test with actual redirect
334 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
335 $newContent = $content->updateRedirect( $target );
337 $this->assertFalse( $content->equals( $newContent ), "content should have changed" );
338 $this->assertTrue( $newContent->isRedirect(), "new content should be a redirect" );
341 $target->getFullText(),
342 $newContent->getRedirectTarget()->getFullText()
349 public function testGetModel() {
350 $content = $this->newContent( "hello world." );
352 $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModel() );
358 public function testGetContentHandler() {
359 $content = $this->newContent( "hello world." );
361 $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() );
368 public function testRedirectParserOption() {
371 // Set up hook and its reporting variables
373 $redirectTarget = null;
374 $this->mergeMwGlobalArrayValue( 'wgHooks
', [
375 'InternalParseBeforeLinks
' => [
376 function ( &$parser, &$text, &$stripState ) use ( &$wikitext, &$redirectTarget ) {
378 $redirectTarget = $parser->getOptions()->getRedirectTarget();
383 // Test with non-redirect page
385 $redirectTarget = false;
386 $content = $this->newContent( 'hello world.
' );
387 $options = ParserOptions::newCanonical( 'canonical
' );
388 $options->setRedirectTarget( $title );
389 $content->getParserOutput( $title, null, $options );
390 $this->assertEquals( 'hello world.
', $wikitext,
391 'Wikitext passed to
hook was
not as expected
'
393 $this->assertEquals( null, $redirectTarget, 'Redirect
seen in hook was
not null' );
394 $this->assertEquals( $title, $options->getRedirectTarget(),
400 $redirectTarget =
false;
402 "#REDIRECT [[TestRedirectParserOption/redir]]\nhello redirect."
409 'Wikitext passed to hook was not as expected'
411 $this->assertNotEquals(
414 'Redirect seen in hook was null' );
416 'TestRedirectParserOption/redir',
417 $redirectTarget->getFullText(),
418 'Redirect seen in hook was not the expected title'
423 'ParserOptions\' redirectTarget was changed'
459 $pstContent =
$content->preSaveTransform(
463 $this->assertTrue( $pstContent->getParserOutput( $titleObj )->getFlag(
'user-signature' ) );
testGetSecondaryDataUpdates( $title, $model, $text, $expectedStuff)
dataGetSecondaryDataUpdates Database WikitextContent::getSecondaryDataUpdates
Set options of the Parser.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
processing should stop and the error should be shown to the user * false
static dataGetSecondaryDataUpdates()
ContentHandler Database ^— needed, because we do need the database to test link updates.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template to be included in the link
const CONTENT_MODEL_WIKITEXT
This document provides an overview of the usage of PageUpdater and that is
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
namespace and then decline to actually register it file or subcat img or subcat $title
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
null for the wiki Added in
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
Content object for wiki text pages.
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a hook
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Content for JavaScript pages.
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
testRedirectParserOption()
ParserOptions::getRedirectTarget ParserOptions::setRedirectTarget.
testHadSignature()
WikitextContent::preSaveTransform WikitextContent::fillParserOutput.
static dataGetDeletionUpdates()
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
Content object implementation for representing flat text.
static dataGetParserOutput()
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 & $options
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
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
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
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be seen