14 parent::__construct(
$name, $data, $dataName );
16 $this->tablesUsed = array_merge(
37 $this->pages_to_delete = [];
39 LinkCache::singleton()->clear(); # avoid cached
redirect status,
etc
43 foreach ( $this->pages_to_delete
as $p ) {
48 $p->doDeleteArticle(
"testing done." );
62 protected function newPage( $title, $model =
null ) {
63 if ( is_string(
$title ) ) {
70 $this->pages_to_delete[] = $p;
100 $page = $this->
newPage(
"WikiPageTest_testDoEditContent" );
104 "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
105 .
" nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
112 $this->assertTrue(
$title->getArticleID() > 0,
"Title object should have new page id" );
113 $this->assertTrue(
$page->getId() > 0,
"WikiPage should have new page id" );
114 $this->assertTrue(
$title->exists(),
"Title object should indicate that the page now exists" );
115 $this->assertTrue(
$page->exists(),
"WikiPage object should indicate that the page now exists" );
117 $id =
$page->getId();
119 # ------------------------
121 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
122 $n =
$res->numRows();
125 $this->assertEquals( 1, $n,
'pagelinks should contain one link from the page' );
127 # ------------------------
130 $retrieved =
$page->getContent();
131 $this->assertTrue(
$content->equals( $retrieved ),
'retrieved content doesn\'t equal original' );
133 # ------------------------
135 "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
136 .
"Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
143 # ------------------------
146 $retrieved =
$page->getContent();
147 $this->assertTrue(
$content->equals( $retrieved ),
'retrieved content doesn\'t equal original' );
149 # ------------------------
151 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
152 $n =
$res->numRows();
155 $this->assertEquals( 2, $n,
'pagelinks should contain two links from the page' );
168 $title = Title::newFromText(
"Help:WikiPageTest_testDoEdit" );
172 $text =
"[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
173 .
" nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
175 $page->doEdit( $text,
"[[testing]] 1" );
177 $this->assertTrue(
$title->getArticleID() > 0,
"Title object should have new page id" );
178 $this->assertTrue(
$page->getId() > 0,
"WikiPage should have new page id" );
179 $this->assertTrue(
$title->exists(),
"Title object should indicate that the page now exists" );
180 $this->assertTrue(
$page->exists(),
"WikiPage object should indicate that the page now exists" );
182 $id =
$page->getId();
184 # ------------------------
186 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
187 $n =
$res->numRows();
190 $this->assertEquals( 1, $n,
'pagelinks should contain one link from the page' );
192 # ------------------------
195 $retrieved =
$page->getText();
196 $this->assertEquals( $text, $retrieved,
'retrieved text doesn\'t equal original' );
198 # ------------------------
199 $text =
"At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
200 .
"Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
202 $page->doEdit( $text,
"testing 2" );
204 # ------------------------
207 $retrieved =
$page->getText();
208 $this->assertEquals( $text, $retrieved,
'retrieved text doesn\'t equal original' );
210 # ------------------------
212 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
213 $n =
$res->numRows();
216 $this->assertEquals( 2, $n,
'pagelinks should contain two links from the page' );
224 "WikiPageTest_testDoDeleteArticle",
225 "[[original text]] foo",
228 $id =
$page->getId();
230 $page->doDeleteArticle(
"testing deletion" );
233 $page->getTitle()->getArticleID() > 0,
234 "Title object should now have page id 0"
236 $this->assertFalse(
$page->getId() > 0,
"WikiPage should now have page id 0" );
239 "WikiPage::exists should return false after page was deleted"
243 "WikiPage::getContent should return null after page was deleted"
247 "WikiPage::getText should return false after page was deleted"
250 $t = Title::newFromText(
$page->getTitle()->getPrefixedText() );
253 "Title::exists should return false after page was deleted"
262 # ------------------------
264 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
265 $n =
$res->numRows();
268 $this->assertEquals( 0, $n,
'pagelinks should contain no more links from the page' );
276 "WikiPageTest_testDoDeleteArticle",
277 "[[original text]] foo",
280 $id =
$page->getId();
284 $page->doDeleteUpdates( $id );
292 # ------------------------
294 $res =
$dbr->select(
'pagelinks',
'*', [
'pl_from' => $id ] );
295 $n =
$res->numRows();
298 $this->assertEquals( 0, $n,
'pagelinks should contain no more links from the page' );
305 $page = $this->
newPage(
"WikiPageTest_testGetRevision" );
308 $this->assertNull(
$rev );
315 $this->assertEquals(
$page->getLatest(),
$rev->getId() );
316 $this->assertEquals(
"some text",
$rev->getContent()->getNativeData() );
323 $page = $this->
newPage(
"WikiPageTest_testGetContent" );
332 $this->assertEquals(
"some text",
$content->getNativeData() );
343 $text =
$page->getText();
344 $this->assertFalse( $text );
349 $text =
$page->getText();
350 $this->assertEquals(
"some text", $text );
360 $this->markTestSkipped(
'$wgContentHandlerUseDB is disabled' );
364 "WikiPageTest_testGetContentModel",
380 $this->markTestSkipped(
'$wgContentHandlerUseDB is disabled' );
384 "WikiPageTest_testGetContentHandler",
390 $this->assertEquals(
'JavaScriptContentHandler', get_class(
$page->getContentHandler() ) );
398 $this->assertFalse(
$page->exists() );
402 $this->assertTrue(
$page->exists() );
405 $this->assertTrue(
$page->exists() );
408 $page->doDeleteArticle(
"done testing" );
409 $this->assertFalse(
$page->exists() );
412 $this->assertFalse(
$page->exists() );
417 [
'WikiPageTest_testHasViewableContent',
false,
true ],
418 [
'Special:WikiPageTest_testHasViewableContent',
false ],
419 [
'MediaWiki:WikiPageTest_testHasViewableContent',
false ],
420 [
'Special:Userlogin',
true ],
421 [
'MediaWiki:help',
true ],
431 $this->assertEquals( $viewable,
$page->hasViewableContent() );
435 $this->assertTrue(
$page->hasViewableContent() );
438 $this->assertTrue(
$page->hasViewableContent() );
446 'WikiPageTest_testGetRedirectTarget_2',
448 "#REDIRECT [[hello world]]",
460 'wgCapitalLinks' =>
true,
465 # sanity check, because this test seems to fail for no reason for some people.
466 $c =
$page->getContent();
467 $this->assertEquals(
'WikitextContent', get_class( $c ) );
469 # now, test the actual redirect
470 $t =
$page->getRedirectTarget();
471 $this->assertEquals( $target, is_null(
$t ) ?
null :
$t->getPrefixedText() );
480 $this->assertEquals( !is_null( $target ),
$page->isRedirect() );
487 [
'WikiPageTest_testIsCountable',
493 [
'WikiPageTest_testIsCountable',
501 [
'WikiPageTest_testIsCountable',
507 [
'WikiPageTest_testIsCountable',
515 [
'WikiPageTest_testIsCountable',
521 [
'WikiPageTest_testIsCountable',
529 [
'WikiPageTest_testIsCountable',
535 [
'WikiPageTest_testIsCountable',
541 [
'WikiPageTest_testIsCountable',
549 [
'Talk:WikiPageTest_testIsCountable',
555 [
'Talk:WikiPageTest_testIsCountable',
561 [
'Talk:WikiPageTest_testIsCountable',
569 [
'MediaWiki:WikiPageTest_testIsCountable.js',
575 [
'MediaWiki:WikiPageTest_testIsCountable.js',
581 [
'MediaWiki:WikiPageTest_testIsCountable.js',
605 $this->markTestSkipped(
"Can not use non-default content model $model for "
606 .
$title->getPrefixedDBkey() .
" with \$wgContentHandlerUseDB disabled." );
611 $editInfo =
$page->prepareContentForEdit(
$page->getContent() );
613 $v =
$page->isCountable();
614 $w =
$page->isCountable( $editInfo );
619 "isCountable( null ) returned unexpected value " . var_export( $v,
true )
620 .
" instead of " . var_export( $expected,
true )
621 .
" in mode `$mode` for text \"$text\""
627 "isCountable( \$editInfo ) returned unexpected value " . var_export( $v,
true )
628 .
" instead of " . var_export( $expected,
true )
629 .
" in mode `$mode` for text \"$text\""
645 $page = $this->
createPage(
'WikiPageTest_testGetParserOutput', $text, $model );
647 $opt =
$page->makeParserOptions(
'canonical' );
648 $po =
$page->getParserOutput( $opt );
649 $text = $po->getText();
651 $text = trim( preg_replace(
'/<!--.*?-->/sm',
'', $text ) ); # strip injected comments
652 $text = preg_replace(
'!\s*(</p>)!sm',
'\1', $text ); # don
't let tidy confuse us
654 $this->assertEquals( $expectedHtml, $text );
662 public function testGetParserOutput_nonexisting() {
666 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
668 $opt = new ParserOptions();
669 $po = $page->getParserOutput( $opt );
671 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
677 public function testGetParserOutput_badrev() {
678 $page = $this->createPage( 'WikiPageTest_testGetParserOutput
', "dummy", CONTENT_MODEL_WIKITEXT );
680 $opt = new ParserOptions();
681 $po = $page->getParserOutput( $opt, $page->getLatest() + 1234 );
683 // @todo would be neat to also test deleted revision
685 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
688 public static $sections =
702 public function dataReplaceSection() {
703 // NOTE: assume the Help namespace to contain wikitext
705 [ 'Help:WikiPageTest_testReplaceSection
',
706 CONTENT_MODEL_WIKITEXT,
707 WikiPageTest::$sections,
711 trim( preg_replace( '/^Intro/sm
', 'No more
', WikiPageTest::$sections ) )
713 [ 'Help:WikiPageTest_testReplaceSection
',
714 CONTENT_MODEL_WIKITEXT,
715 WikiPageTest::$sections,
721 [ 'Help:WikiPageTest_testReplaceSection
',
722 CONTENT_MODEL_WIKITEXT,
723 WikiPageTest::$sections,
725 "== TEST ==\nmore fun",
727 trim( preg_replace( '/^== test ==.*== foo ==/sm
',
728 "== TEST ==\nmore fun\n\n== foo ==",
729 WikiPageTest::$sections ) )
731 [ 'Help:WikiPageTest_testReplaceSection
',
732 CONTENT_MODEL_WIKITEXT,
733 WikiPageTest::$sections,
737 trim( WikiPageTest::$sections )
739 [ 'Help:WikiPageTest_testReplaceSection
',
740 CONTENT_MODEL_WIKITEXT,
741 WikiPageTest::$sections,
745 trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
754 public function testReplaceSectionContent( $title, $model, $text, $section,
755 $with, $sectionTitle, $expected
757 $page = $this->createPage( $title, $text, $model );
759 $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
760 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
762 $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
769 public function testReplaceSectionAtRev( $title, $model, $text, $section,
770 $with, $sectionTitle, $expected
772 $page = $this->createPage( $title, $text, $model );
773 $baseRevId = $page->getLatest();
775 $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
776 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
778 $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
781 /* @todo FIXME: fix this!
782 public function testGetUndoText() {
783 $this->markTestSkippedIfNoDiff3();
786 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
787 $rev1 = $page->getRevision();
790 $page->doEditContent(
791 ContentHandler::makeContent( $text, $page->getTitle() ),
794 $rev2 = $page->getRevision();
796 $text .= "\n\nthree";
797 $page->doEditContent(
798 ContentHandler::makeContent( $text, $page->getTitle() ),
799 "adding section three"
801 $rev3 = $page->getRevision();
804 $page->doEditContent(
805 ContentHandler::makeContent( $text, $page->getTitle() ),
806 "adding section four"
808 $rev4 = $page->getRevision();
811 $page->doEditContent(
812 ContentHandler::makeContent( $text, $page->getTitle() ),
813 "adding section five"
815 $rev5 = $page->getRevision();
818 $page->doEditContent(
819 ContentHandler::makeContent( $text, $page->getTitle() ),
822 $rev6 = $page->getRevision();
824 $undo6 = $page->getUndoText( $rev6 );
825 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
826 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
828 $undo3 = $page->getUndoText( $rev4, $rev2 );
829 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
830 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
832 $undo2 = $page->getUndoText( $rev2 );
833 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
834 $this->assertEquals( "one\n\nfive", $undo2 );
842 public function broken_testDoRollback() {
844 $admin->setName( "Admin" );
847 $page = $this->newPage( "WikiPageTest_testDoRollback" );
848 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
849 "section one", EDIT_NEW, false, $admin );
852 $user1->setName( "127.0.1.11" );
854 $page = new WikiPage( $page->getTitle() );
855 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
856 "adding section two", 0, false, $user1 );
859 $user2->setName( "127.0.2.13" );
860 $text .= "\n\nthree";
861 $page = new WikiPage( $page->getTitle() );
862 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
863 "adding section three", 0, false, $user2 );
865 # we are having issues with doRollback spuriously failing. Apparently
866 # the last revision somehow goes missing or not committed under some
867 # circumstances. So, make sure the last revision has the right user name.
868 $dbr = wfGetDB( DB_SLAVE );
869 $this->assertEquals( 3, Revision::countByPageId( $dbr, $page->getId() ) );
871 $page = new WikiPage( $page->getTitle() );
872 $rev3 = $page->getRevision();
873 $this->assertEquals( '127.0.2.13
', $rev3->getUserText() );
875 $rev2 = $rev3->getPrevious();
876 $this->assertEquals( '127.0.1.11
', $rev2->getUserText() );
878 $rev1 = $rev2->getPrevious();
879 $this->assertEquals( 'Admin
', $rev1->getUserText() );
881 # now, try the actual rollback
882 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
883 $token = $admin->getEditToken(
884 [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
887 $errors = $page->doRollback(
897 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
898 . ";\n" . print_r( $details, true ) );
901 $page = new WikiPage( $page->getTitle() );
902 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
903 "rollback did not revert to the correct revision" );
904 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
911 public function testDoRollback() {
913 $admin->setName( "Admin" );
916 $page = $this->newPage( "WikiPageTest_testDoRollback" );
917 $page->doEditContent(
918 ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
924 $rev1 = $page->getRevision();
927 $user1->setName( "127.0.1.11" );
929 $page = new WikiPage( $page->getTitle() );
930 $page->doEditContent(
931 ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
932 "adding section two",
938 # now, try the rollback
939 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
940 $token = $admin->getEditToken(
941 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
944 $errors = $page->doRollback(
954 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
955 . ";\n" . print_r( $details, true ) );
958 $page = new WikiPage( $page->getTitle() );
959 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
960 "rollback did not revert to the correct revision" );
961 $this->assertEquals( "one", $page->getContent()->getNativeData() );
967 public function testDoRollbackFailureSameContent() {
969 $admin->setName( "Admin" );
970 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
973 $page = $this->newPage( "WikiPageTest_testDoRollback" );
974 $page->doEditContent(
975 ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
981 $rev1 = $page->getRevision();
984 $user1->setName( "127.0.1.11" );
985 $user1->addGroup( "sysop" ); # XXX: make the test user a sysop...
987 $page = new WikiPage( $page->getTitle() );
988 $page->doEditContent(
989 ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
990 "adding section two",
996 # now, do a the rollback from the same user was doing the edit before
998 $token = $user1->getEditToken(
999 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
1002 $errors = $page->doRollback(
1004 "testing revert same user",
1011 $this->assertEquals( [], $errors, "Rollback failed same user" );
1013 # now, try the rollback
1014 $resultDetails = [];
1015 $token = $admin->getEditToken(
1016 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
1019 $errors = $page->doRollback(
1029 '127.0.1.11
', 'Admin
' ] ], $errors, "Rollback not failed" );
1031 $page = new WikiPage( $page->getTitle() );
1032 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
1033 "rollback did not revert to the correct revision" );
1034 $this->assertEquals( "one", $page->getContent()->getNativeData() );
1037 public static function provideGetAutosummary() {
1040 'Hello
there, world!
',
1041 '#REDIRECT [[Foo]]
',
1043 '/^Redirected
page .*Foo/
'
1050 '/^Created
page .*Hello/
'
1054 'Hello
there, world!
',
1061 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
1062 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
1063 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
1064 clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
',
1067 '/^Replaced .*Hello/
'
1083 public function testGetAutosummary( $old, $new, $flags, $expected ) {
1084 $this->hideDeprecated( "WikiPage::getAutosummary" );
1086 $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
1088 $summary = $page->getAutosummary( $old, $new, $flags );
1090 $this->assertTrue( (bool)preg_match( $expected, $summary ),
1091 "Autosummary didn't match expected pattern $expected:
$summary" );
1094 public static function provideGetAutoDeleteReason() {
1104 [ "first edit
", null ],
1106 "/first edit.*only contributor/
",
1112 [ "first edit
", null ],
1113 [ "second edit
", null ],
1115 "/second edit.*only contributor/
",
1121 [ "first edit
", "127.0.2.22
" ],
1122 [ "second edit
", "127.0.3.33
" ],
1132 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
"
1133 . " nonumy eirmod tempor invidunt ut labore et dolore magna
"
1134 . "aliquyam erat, sed diam voluptua. At vero eos et accusam
"
1135 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren,
"
1136 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.
'",
1140 '/first edit:.*\.\.\.
"/',
1146 [ "first edit
", "127.0.2.22
" ],
1147 [ "", "127.0.3.33
" ],
1149 "/before blanking.*first edit/
",
1160 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1163 // NOTE: assume Help namespace to contain wikitext
1164 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason
" );
1168 foreach ( $edits as $edit ) {
1171 if ( !empty( $edit[1] ) ) {
1172 $user->setName( $edit[1] );
1177 $content = ContentHandler::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1179 $page->doEditContent( $content, "test edit $c
", $c < 2 ? EDIT_NEW : 0, false, $user );
1184 $reason = $page->getAutoDeleteReason( $hasHistory );
1186 if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) {
1187 $this->assertEquals( $expectedResult, $reason );
1189 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1190 "Autosummary didn
't match expected pattern $expectedResult: $reason" );
1193 $this->assertEquals( $expectedHistory, $hasHistory,
1194 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1196 $page->doDeleteArticle( "done" );
1199 public static function providePreSaveTransform() {
1201 [ 'hello
this is ~~~
',
1202 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1204 [ 'hello \
'\'this\
'\' is <nowiki>~~~</nowiki>
',
1205 'hello \
'\'this\
'\' is <nowiki>~~~</nowiki>
',
1213 public function testWikiPageFactory() {
1214 $title = Title::makeTitle( NS_FILE, 'Someimage.png
' );
1215 $page = WikiPage::factory( $title );
1216 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
1218 $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory
' );
1219 $page = WikiPage::factory( $title );
1222 $title = Title::makeTitle( NS_MAIN, 'SomePage
' );
1223 $page = WikiPage::factory( $title );
1224 $this->assertEquals( 'WikiPage', get_class( $page ) );
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 redirect
has been added to your &Future changes to this page and its associated Talk page will be listed there
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
static destroySingletons()
Destroy the singleton instances.
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
Maintenance script that runs pending jobs.
Represents a title within MediaWiki.
Special handling for category pages.
Special handling for file pages.
ContentHandler Database ^— important, causes temporary tables to be used instead of the real database...
static provideGetRedirectTarget()
testGetText()
WikiPage::getText.
testIsRedirect( $title, $model, $text, $target)
provideGetRedirectTarget WikiPage::isRedirect
__construct( $name=null, array $data=[], $dataName='')
testDoEdit()
WikiPage::doEdit.
static provideIsCountable()
testGetRevision()
WikiPage::getRevision.
testHasViewableContent( $title, $viewable, $create=false)
provideHasViewableContent WikiPage::hasViewableContent
testGetContent()
WikiPage::getContent.
static provideHasViewableContent()
testGetParserOutput( $model, $text, $expectedHtml)
provideGetParserOutput WikiPage::getParserOutput
testIsCountable( $title, $model, $text, $mode, $expected)
provideIsCountable WikiPage::isCountable
testGetRedirectTarget( $title, $model, $text, $target)
provideGetRedirectTarget WikiPage::getRedirectTarget
testDoDeleteUpdates()
WikiPage::doDeleteUpdates.
newPage( $title, $model=null)
testGetContentModel()
WikiPage::getContentModel.
testExists()
WikiPage::exists.
testGetContentHandler()
WikiPage::getContentHandler.
createPage( $page, $text, $model=null)
static provideGetParserOutput()
testDoDeleteArticle()
WikiPage::doDeleteArticle.
testDoEditContent()
WikiPage::doEditContent WikiPage::doModify WikiPage::doCreate WikiPage::doEditUpdates.
Class representing a MediaWiki article and history.
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
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 etc
when a variable name is used in a it is silently declared as a new local masking the global
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
const CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace and then decline to actually register it file or subcat img or subcat $title
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
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
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk page
Allows to change the fields on the form that will be generated $name
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
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