9use InvalidArgumentException;
22use PHPUnit_Framework_MockObject_MockObject;
71 $this->tablesUsed[] =
'archive';
72 $this->tablesUsed[] =
'page';
73 $this->tablesUsed[] =
'revision';
74 $this->tablesUsed[] =
'comment';
96 if ( $this->testPageTitle ) {
100 $this->testPageTitle = Title::newFromText(
'UTPage-' . __CLASS__ );
107 if ( $this->testPage ) {
112 $this->testPage = WikiPage::factory( $title );
114 if ( !$this->testPage->exists() ) {
118 $user = static::getTestSysop()->getUser();
120 $this->testPage->doEditContent(
122 'UTPageSummary-' . __CLASS__,
136 $domain =
new DatabaseDomain( $server[
'dbname'],
null, $server[
'tablePrefix'] );
138 $lb = $this->getMockBuilder( LoadBalancer::class )
139 ->setMethods( [
'reallyOpenConnection' ] )
140 ->setConstructorArgs( [
141 [
'servers' => [ $server ],
'localDomain' => $domain ]
145 $lb->method(
'reallyOpenConnection' )->willReturnCallback(
146 function (
array $server, $dbNameOverride ) {
158 $db = $this->getMockBuilder( DatabaseSqlite::class )
159 ->setMethods( [
'select',
'doQuery',
'open',
'closeConnection',
'isOpen' ] )
160 ->setConstructorArgs( [
$params ] )
164 $db->method(
'isOpen' )->willReturn(
true );
170 yield [
false,
'test',
'' ];
171 yield [
'test',
'test',
'' ];
173 yield [
false,
'test',
'foo_' ];
174 yield [
'test-foo_',
'test',
'foo_' ];
176 yield [
false,
'dash-test',
'' ];
177 yield [
'dash-test',
'dash-test',
'' ];
179 yield [
false,
'underscore_test',
'foo_' ];
180 yield [
'underscore_test-foo_',
'underscore_test',
'foo_' ];
190 'wgDBname' => $dbName,
191 'wgDBprefix' => $dbPrefix,
198 'dbDirectory' =>
'*dummy*',
200 'password' =>
'test',
209 'connLogger' =>
new \Psr\Log\NullLogger(),
210 'queryLogger' =>
new \Psr\Log\NullLogger(),
211 'errorLogger' =>
function () {
213 'deprecationLogger' =>
function () {
217 'tablePrefix' => $dbPrefix,
223 $blobStore = $this->getMockBuilder( SqlBlobStore::class )
224 ->disableOriginalConstructor()
239 $count = $store->countRevisionsByPageId(
$db, 0 );
243 $this->assertSame( 0, $count );
247 $this->assertEquals( $l1->getDBkey(), $l2->getDBkey() );
248 $this->assertEquals( $l1->getNamespace(), $l2->getNamespace() );
249 $this->assertEquals( $l1->getFragment(), $l2->getFragment() );
250 $this->assertEquals( $l1->getInterwiki(), $l2->getInterwiki() );
255 $r1->getPageAsLinkTarget()->getNamespace(),
256 $r2->getPageAsLinkTarget()->getNamespace()
260 $r1->getPageAsLinkTarget()->getText(),
261 $r2->getPageAsLinkTarget()->getText()
264 if ( $r1->getParentId() ) {
265 $this->assertEquals( $r1->getParentId(), $r2->getParentId() );
268 $this->assertEquals( $r1->getUser()->getName(), $r2->getUser()->getName() );
269 $this->assertEquals( $r1->getUser()->getId(), $r2->getUser()->getId() );
270 $this->assertEquals( $r1->getComment(), $r2->getComment() );
271 $this->assertEquals( $r1->getTimestamp(), $r2->getTimestamp() );
272 $this->assertEquals( $r1->getVisibility(), $r2->getVisibility() );
273 $this->assertEquals( $r1->getSha1(), $r2->getSha1() );
274 $this->assertEquals( $r1->getSize(), $r2->getSize() );
275 $this->assertEquals( $r1->getPageId(), $r2->getPageId() );
277 $this->assertEquals( $r1->getWikiId(), $r2->getWikiId() );
278 $this->assertEquals( $r1->isMinor(), $r2->isMinor() );
279 foreach ( $r1->getSlotRoles() as $role ) {
281 $this->assertTrue( $r1->getContent( $role )->equals( $r2->getContent( $role ) ) );
284 RevisionRecord::DELETED_TEXT,
285 RevisionRecord::DELETED_COMMENT,
286 RevisionRecord::DELETED_USER,
287 RevisionRecord::DELETED_RESTRICTED,
289 $this->assertEquals( $r1->isDeleted( $field ), $r2->isDeleted( $field ) );
294 $this->assertSame( $s1->getRole(), $s2->getRole() );
295 $this->assertSame( $s1->getModel(), $s2->getModel() );
296 $this->assertSame( $s1->getFormat(), $s2->getFormat() );
297 $this->assertSame( $s1->getSha1(), $s2->getSha1() );
298 $this->assertSame( $s1->getSize(), $s2->getSize() );
299 $this->assertTrue( $s1->getContent()->equals( $s2->getContent() ) );
301 $s1->hasRevision() ? $this->assertSame( $s1->getRevision(), $s2->getRevision() ) :
null;
302 $s1->hasAddress() ? $this->assertSame( $s1->hasAddress(), $s2->hasAddress() ) :
null;
306 $this->assertTrue( $r->
hasSlot( SlotRecord::MAIN ) );
307 $this->assertInstanceOf( SlotRecord::class, $r->
getSlot( SlotRecord::MAIN ) );
308 $this->assertInstanceOf( Content::class, $r->
getContent( SlotRecord::MAIN ) );
319 $this->assertInstanceOf( Content::class, $slot->
getContent() );
329 if ( isset( $details[
'user'] ) && $details[
'user'] ===
true ) {
330 $details[
'user'] = $this->
getTestUser()->getUser();
332 if ( isset( $details[
'page'] ) && $details[
'page'] ===
true ) {
335 if ( isset( $details[
'parent'] ) && $details[
'parent'] ===
true ) {
336 $details[
'parent'] = $this->
getTestPage()->getLatest();
341 isset( $details[
'slot'] ) ?
$rev->setSlot( $details[
'slot'] ) :
null;
342 isset( $details[
'parent'] ) ?
$rev->setParentId( $details[
'parent'] ) :
null;
343 isset( $details[
'page'] ) ?
$rev->setPageId( $details[
'page'] ) :
null;
344 isset( $details[
'size'] ) ?
$rev->setSize( $details[
'size'] ) :
null;
345 isset( $details[
'sha1'] ) ?
$rev->setSha1( $details[
'sha1'] ) :
null;
346 isset( $details[
'comment'] ) ?
$rev->setComment( $details[
'comment'] ) :
null;
347 isset( $details[
'timestamp'] ) ?
$rev->setTimestamp( $details[
'timestamp'] ) :
null;
348 isset( $details[
'minor'] ) ?
$rev->setMinorEdit( $details[
'minor'] ) :
null;
349 isset( $details[
'user'] ) ?
$rev->setUser( $details[
'user'] ) :
null;
350 isset( $details[
'visibility'] ) ?
$rev->setVisibility( $details[
'visibility'] ) :
null;
351 isset( $details[
'id'] ) ?
$rev->setId( $details[
'id'] ) :
null;
353 if ( isset( $details[
'content'] ) ) {
354 foreach ( $details[
'content'] as $role =>
$content ) {
363 yield
'Bare minimum revision insertion' => [
365 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
368 'timestamp' =>
'20171117010101',
372 yield
'Detailed revision insertion' => [
374 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
378 'timestamp' =>
'20171117010101',
381 'visibility' => RevisionRecord::DELETED_RESTRICTED,
387 return CommentStoreComment::newUnsavedComment( __METHOD__ .
'.' . rand( 0, 1000 ) );
397 array $revDetails = []
412 $loaded = $store->getRevisionById( $return->getId() );
424 unset( $row->rev_content_model );
425 unset( $row->rev_content_format );
428 unset( $row->rev_comment_text );
429 unset( $row->rev_comment_data );
430 unset( $row->rev_comment_cid );
431 unset( $row->rev_comment_id );
434 $queryInfo = $store->getQueryInfo( [
'user' ] );
436 $row = get_object_vars( $row );
438 $queryInfo[
'tables'],
440 [
'rev_id' =>
$rev->getId() ],
441 [ array_values( $row ) ],
453 $this->assertSame( $a->getAddress(), $b->getAddress() );
462 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
465 'timestamp' =>
'20171117010101',
479 $revDetails[
'slot'] = SlotRecord::newInherited( $firstReturn->getSlot( SlotRecord::MAIN ) );
485 $firstMainSlot = $firstReturn->getSlot( SlotRecord::MAIN );
486 $secondMainSlot = $secondReturn->getSlot( SlotRecord::MAIN );
491 $this->assertNotSame( $firstReturn->getId(), $secondReturn->getId() );
494 $this->assertSame( $firstReturn->getId(), $firstMainSlot->getRevision() );
495 $this->assertSame( $secondReturn->getId(), $secondMainSlot->getRevision() );
502 'timestamp' =>
'20171117010101',
505 new InvalidArgumentException(
'main slot must be provided' )
507 yield
'no main slot' => [
509 'slot' => SlotRecord::newUnsaved(
'aux',
new WikitextContent(
'Turkey' ) ),
511 'timestamp' =>
'20171117010101',
514 new InvalidArgumentException(
'main slot must be provided' )
516 yield
'no timestamp' => [
518 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
524 yield
'no comment' => [
526 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
527 'timestamp' =>
'20171117010101',
534 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN,
new WikitextContent(
'Chicken' ) ),
536 'timestamp' =>
'20171117010101',
547 array $revDetails = [],
554 $this->setExpectedException(
555 get_class( $exception ),
556 $exception->getMessage(),
557 $exception->getCode()
564 Title::newFromText(
'UTPage_notAutoCreated' ),
566 CommentStoreComment::newUnsavedComment( __METHOD__ .
' comment1' ),
570 Title::newFromText(
'UTPage_notAutoCreated' ),
572 CommentStoreComment::newUnsavedComment( __METHOD__ .
' comment2', [
'a' => 1 ] ),
586 $page = WikiPage::factory( $title );
588 if ( !$page->exists() ) {
592 $revDetails[
'page'] = $page->getId();
594 $revDetails[
'comment'] = CommentStoreComment::newUnsavedComment(
'Base' );
595 $revDetails[
'user'] =
$user;
601 $baseRev = $store->insertRevisionOn( $baseRev, $dbw );
602 $page->updateRevisionOn( $dbw,
new Revision( $baseRev ), $page->getLatest() );
604 $record = $store->newNullRevision(
612 $this->assertEquals( $title->getNamespace(), $record->getPageAsLinkTarget()->getNamespace() );
613 $this->assertEquals( $title->getDBkey(), $record->getPageAsLinkTarget()->getDBkey() );
614 $this->assertEquals( $comment, $record->getComment() );
615 $this->assertEquals( $minor, $record->isMinor() );
616 $this->assertEquals( $user->getName(), $record->getUser()->getName() );
617 $this->assertEquals( $baseRev->getId(), $record->getParentId() );
620 $baseRev->getSlotRoles(),
621 $record->getSlotRoles()
624 foreach ( $baseRev->getSlotRoles() as $role ) {
625 $parentSlot = $baseRev->getSlot( $role );
626 $slot = $record->getSlot( $role );
628 $this->assertTrue( $slot->isInherited(),
'isInherited' );
629 $this->assertSame( $parentSlot->getOrigin(), $slot->getOrigin(),
'getOrigin' );
639 $record = $store->newNullRevision(
641 Title::newFromText( __METHOD__ .
'.iDontExist!' ),
642 CommentStoreComment::newUnsavedComment( __METHOD__ .
' comment' ),
646 $this->assertNull( $record );
659 $revisionRecord = $store->getRevisionById(
$rev->getId() );
660 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
662 $this->assertGreaterThan( 0, $result );
664 $store->getRecentChange( $revisionRecord )->getAttribute(
'rc_id' ),
676 $status = $page->doEditContent(
687 $revisionRecord = $store->getRevisionById(
$rev->getId() );
688 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
690 $this->assertSame( 0, $result );
698 $content =
new WikitextContent( __METHOD__ );
704 $revRecord = $store->getRevisionById(
$rev->getId() );
705 $recentChange = $store->getRecentChange( $revRecord );
707 $this->assertEquals(
$rev->getId(), $recentChange->getAttribute(
'rc_this_oldid' ) );
708 $this->assertEquals(
$rev->getRecentChange(), $recentChange );
716 $content =
new WikitextContent( __METHOD__ );
722 $revRecord = $store->getRevisionById(
$rev->getId() );
724 $this->assertSame(
$rev->getId(), $revRecord->getId() );
725 $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals(
$content ) );
726 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
734 $content =
new WikitextContent( __METHOD__ );
740 $revRecord = $store->getRevisionByTitle( $page->getTitle() );
742 $this->assertSame(
$rev->getId(), $revRecord->getId() );
743 $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals(
$content ) );
744 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
752 $content =
new WikitextContent( __METHOD__ );
758 $revRecord = $store->getRevisionByPageId( $page->getId() );
760 $this->assertSame(
$rev->getId(), $revRecord->getId() );
761 $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals(
$content ) );
762 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
780 $revRecord = $store->getRevisionByTimestamp(
785 $this->assertSame(
$rev->getId(), $revRecord->getId() );
786 $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals(
$content ) );
787 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
792 $page = WikiPage::factory(
$rev->getTitle() );
797 'rev_timestamp' => $this->db->timestamp(
$rev->getTimestamp() ),
798 'rev_user_text' => (
string)
$rev->getUserText(),
800 'rev_minor_edit' =>
$rev->isMinor() ?
'1' :
'0',
801 'rev_deleted' => (
string)
$rev->getVisibility(),
803 'rev_parent_id' => (
string)
$rev->getParentId(),
807 if ( in_array(
'page',
$options ) ) {
809 'page_namespace' => (
string)$page->getTitle()->getNamespace(),
810 'page_title' => $page->getTitle()->getDBkey(),
811 'page_id' => (
string)$page->getId(),
812 'page_latest' => (
string)$page->getLatest(),
813 'page_is_redirect' => $page->isRedirect() ?
'1' :
'0',
814 'page_len' => (
string)$page->getContent()->getSize(),
818 if ( in_array(
'user',
$options ) ) {
824 if ( in_array(
'comment',
$options ) ) {
826 'rev_comment_text' =>
$rev->getComment(),
827 'rev_comment_data' =>
null,
828 'rev_comment_cid' =>
null,
832 if (
$rev->getId() ) {
838 return (
object)$fields;
845 $this->assertSame(
$rev->getId(), $record->getId() );
846 $this->assertSame(
$rev->getPage(), $record->getPageId() );
847 $this->assertSame(
$rev->getTimestamp(), $record->getTimestamp() );
848 $this->assertSame(
$rev->getUserText(), $record->getUser()->getName() );
849 $this->assertSame(
$rev->getUser(), $record->getUser()->getId() );
850 $this->assertSame(
$rev->isMinor(), $record->isMinor() );
851 $this->assertSame(
$rev->getVisibility(), $record->getVisibility() );
852 $this->assertSame(
$rev->getSize(), $record->getSize() );
857 $expectedParent =
$rev->getParentId();
858 if ( $expectedParent ===
null ) {
861 $this->assertSame( $expectedParent, $record->getParentId() );
862 $this->assertSame(
$rev->getSha1(), $record->getSha1() );
863 $this->assertSame(
$rev->getComment(), $record->getComment()->text );
864 $this->assertSame(
$rev->getContentFormat(),
865 $record->getContent( SlotRecord::MAIN )->getDefaultFormat() );
866 $this->assertSame(
$rev->getContentModel(), $record->getContent( SlotRecord::MAIN )->getModel() );
869 $revRec =
$rev->getRevisionRecord();
870 $revMain = $revRec->getSlot( SlotRecord::MAIN );
871 $recMain = $record->getSlot( SlotRecord::MAIN );
873 $this->assertSame( $revMain->hasOrigin(), $recMain->hasOrigin(),
'hasOrigin' );
874 $this->assertSame( $revMain->hasAddress(), $recMain->hasAddress(),
'hasAddress' );
875 $this->assertSame( $revMain->hasContentId(), $recMain->hasContentId(),
'hasContentId' );
877 if ( $revMain->hasOrigin() ) {
878 $this->assertSame( $revMain->getOrigin(), $recMain->getOrigin(),
'getOrigin' );
881 if ( $revMain->hasAddress() ) {
882 $this->assertSame( $revMain->getAddress(), $recMain->getAddress(),
'getAddress' );
885 if ( $revMain->hasContentId() ) {
886 $this->assertSame( $revMain->getContentId(), $recMain->getContentId(),
'getContentId' );
896 $text = __METHOD__ .
'a-ä';
898 $rev = $page->doEditContent(
901 )->value[
'revision'];
904 $info = $store->getQueryInfo();
905 $row = $this->db->selectRow(
908 [
'rev_id' =>
$rev->getId() ],
913 $record = $store->newRevisionFromRow(
919 $this->assertSame( $text,
$rev->getContent()->serialize() );
927 $text = __METHOD__ .
'a-ä';
929 $rev = $page->doEditContent(
932 )->value[
'revision'];
935 $record = $store->newRevisionFromRow(
941 $this->assertSame( $text,
$rev->getContent()->serialize() );
948 $this->
setMwGlobals(
'wgLegacyEncoding',
'windows-1252' );
951 $text = __METHOD__ .
'a-ä';
953 $rev = $page->doEditContent(
956 )->value[
'revision'];
959 $record = $store->newRevisionFromRow(
965 $this->assertSame( $text,
$rev->getContent()->serialize() );
973 $text = __METHOD__ .
'b-ä';
975 $rev = $page->doEditContent(
981 )->value[
'revision'];
984 $record = $store->newRevisionFromRow(
990 $this->assertSame( $text,
$rev->getContent()->serialize() );
999 $title = Title::newFromText( __METHOD__ );
1000 $text = __METHOD__ .
'-bä';
1001 $page = WikiPage::factory( $title );
1003 $orig = $page->doEditContent(
new WikitextContent( $text ), __METHOD__ )
1004 ->value[
'revision'];
1005 $page->doDeleteArticle( __METHOD__ );
1008 $arQuery = $store->getArchiveQueryInfo();
1010 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
1011 __METHOD__, [], $arQuery[
'joins']
1013 $this->assertTrue( is_object(
$res ),
'query failed' );
1015 $row =
$res->fetchObject();
1017 $record = $store->newRevisionFromArchiveRow( $row );
1020 $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1027 $this->
setMwGlobals(
'wgLegacyEncoding',
'windows-1252' );
1030 $title = Title::newFromText( __METHOD__ );
1031 $text = __METHOD__ .
'-bä';
1032 $page = WikiPage::factory( $title );
1034 $orig = $page->doEditContent(
new WikitextContent( $text ), __METHOD__ )
1035 ->value[
'revision'];
1036 $page->doDeleteArticle( __METHOD__ );
1039 $arQuery = $store->getArchiveQueryInfo();
1041 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
1042 __METHOD__, [], $arQuery[
'joins']
1044 $this->assertTrue( is_object(
$res ),
'query failed' );
1046 $row =
$res->fetchObject();
1048 $record = $store->newRevisionFromArchiveRow( $row );
1051 $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1062 'ar_page_id' =>
'2',
1063 'ar_namespace' =>
'0',
1064 'ar_title' =>
'Something',
1066 'ar_text_id' =>
'47',
1067 'ar_timestamp' =>
'20180528192356',
1068 'ar_minor_edit' =>
'0',
1069 'ar_deleted' =>
'0',
1071 'ar_parent_id' =>
'0',
1072 'ar_sha1' =>
'deadbeef',
1073 'ar_comment_text' =>
'whatever',
1074 'ar_comment_data' =>
null,
1075 'ar_comment_cid' =>
null,
1077 'ar_user_text' =>
'',
1079 'ar_content_format' =>
null,
1080 'ar_content_model' =>
null,
1083 \Wikimedia\suppressWarnings();
1084 $record = $store->newRevisionFromArchiveRow( $row );
1085 \Wikimedia\suppressWarnings(
true );
1087 $this->assertInstanceOf( RevisionRecord::class, $record );
1088 $this->assertInstanceOf( UserIdentityValue::class, $record->getUser() );
1089 $this->assertSame(
'Unknown user', $record->getUser()->getName() );
1097 $title = Title::newFromText( __METHOD__ );
1102 'page_namespace' =>
'0',
1103 'page_title' => $title->getText(),
1104 'rev_text_id' =>
'47',
1105 'rev_timestamp' =>
'20180528192356',
1106 'rev_minor_edit' =>
'0',
1107 'rev_deleted' =>
'0',
1109 'rev_parent_id' =>
'0',
1110 'rev_sha1' =>
'deadbeef',
1111 'rev_comment_text' =>
'whatever',
1112 'rev_comment_data' =>
null,
1113 'rev_comment_cid' =>
null,
1115 'rev_user_text' =>
'',
1116 'rev_actor' =>
null,
1117 'rev_content_format' =>
null,
1118 'rev_content_model' =>
null,
1121 \Wikimedia\suppressWarnings();
1122 $record = $store->newRevisionFromRow( $row, 0, $title );
1123 \Wikimedia\suppressWarnings(
true );
1125 $this->assertNotNull( $record );
1126 $this->assertNotNull( $record->getUser() );
1127 $this->assertNotEmpty( $record->getUser()->getName() );
1138 $title = Title::newFromText( __METHOD__ );
1140 $page = WikiPage::factory( $title );
1142 $page->doEditContent(
new WikitextContent(
"First" ), __METHOD__ .
'-first' );
1143 $origRev = $page->doEditContent(
new WikitextContent(
"Foo" ), __METHOD__ )
1144 ->value[
'revision'];
1145 $orig = $origRev->getRevisionRecord();
1146 $page->doDeleteArticle( __METHOD__ );
1152 $arQuery = $store->getArchiveQueryInfo();
1154 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
1155 __METHOD__, [], $arQuery[
'joins']
1158 $this->assertNotFalse( $row,
'query failed' );
1160 $record = $store->newRevisionFromArchiveRow(
1164 [
'page_id' => $title->getArticleID() ]
1167 $restored = $store->insertRevisionOn( $record,
$db );
1174 $recMain = $record->getSlot( SlotRecord::MAIN );
1175 $restMain = $restored->getSlot( SlotRecord::MAIN );
1176 $this->assertSame( $recMain->getAddress(), $restMain->getAddress() );
1177 $this->assertSame( $recMain->getContentId(), $restMain->getContentId() );
1178 $this->assertSame( $recMain->getOrigin(), $restMain->getOrigin() );
1179 $this->assertSame(
'Foo', $restMain->getContent()->serialize() );
1182 $loaded = $store->getRevisionById( $restored->getId() );
1183 $this->assertNotNull( $loaded );
1195 $title = Title::newFromText( __METHOD__ );
1196 $page = WikiPage::factory( $title );
1199 ->value[
'revision'];
1210 $title = Title::newFromText( __METHOD__ );
1211 $page = WikiPage::factory( $title );
1214 ->value[
'revision'];
1217 $result = $store->loadRevisionFromPageId(
wfGetDB(
DB_MASTER ), $page->getId() );
1225 $title = Title::newFromText( __METHOD__ );
1226 $page = WikiPage::factory( $title );
1229 ->value[
'revision'];
1240 $title = Title::newFromText( __METHOD__ );
1241 $page = WikiPage::factory( $title );
1243 $revOne = $page->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ )
1244 ->value[
'revision'];
1248 $revTwo = $page->doEditContent(
new WikitextContent( __METHOD__ .
'a' ),
'' )
1249 ->value[
'revision'];
1253 $store->loadRevisionFromTimestamp(
wfGetDB(
DB_MASTER ), $title,
'20150101010101' )
1257 $store->loadRevisionFromTimestamp(
1260 $revOne->getTimestamp()
1265 $store->loadRevisionFromTimestamp(
1268 $revTwo->getTimestamp()
1277 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1279 $revOne = $page->doEditContent(
1281 )->value[
'revision'];
1283 $revTwo = $page->doEditContent(
1285 )->value[
'revision'];
1290 $revOne->getId() => strlen( __METHOD__ ),
1292 $store->listRevisionSizes(
1294 [ $revOne->getId() ]
1299 $revOne->getId() => strlen( __METHOD__ ),
1300 $revTwo->getId() => strlen( __METHOD__ ) + 1,
1302 $store->listRevisionSizes(
1304 [ $revOne->getId(), $revTwo->getId() ]
1313 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1315 $revOne = $page->doEditContent(
1317 )->value[
'revision'];
1319 $revTwo = $page->doEditContent(
1321 )->value[
'revision'];
1325 $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
1329 $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
1337 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1339 $revOne = $page->doEditContent(
1341 )->value[
'revision'];
1343 $revTwo = $page->doEditContent(
1345 )->value[
'revision'];
1350 $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
1353 $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
1364 ->value[
'revision'];
1367 $result = $store->getTimestampFromId(
1372 $this->assertSame(
$rev->getTimestamp(), $result );
1382 ->value[
'revision'];
1385 $result = $store->getTimestampFromId(
1390 $this->assertFalse( $result );
1398 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1421 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1445 $page->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1448 $result = $store->userWasLastToEdit(
1454 $this->assertFalse( $result );
1464 $page->doEditContent(
1473 $result = $store->userWasLastToEdit(
1479 $this->assertTrue( $result );
1488 $rev = $page->doEditContent(
1494 )->value[
'revision'];
1497 $record = $store->getKnownCurrentRevision(
1506 yield
'Basic array, content object' => [
1510 'timestamp' =>
'20171017114835',
1511 'user_text' =>
'111.0.1.2',
1513 'minor_edit' =>
false,
1517 'sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1518 'comment' =>
'Goat Comment!',
1522 yield
'Basic array, serialized text' => [
1526 'timestamp' =>
'20171017114835',
1527 'user_text' =>
'111.0.1.2',
1529 'minor_edit' =>
false,
1533 'sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1534 'comment' =>
'Goat Comment!',
1538 yield
'Basic array, serialized text, utf-8 flags' => [
1542 'timestamp' =>
'20171017114835',
1543 'user_text' =>
'111.0.1.2',
1545 'minor_edit' =>
false,
1549 'sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1550 'comment' =>
'Goat Comment!',
1555 yield
'Basic array, with title' => [
1557 'title' => Title::newFromText(
'SomeText' ),
1558 'timestamp' =>
'20171017114835',
1559 'user_text' =>
'111.0.1.2',
1561 'minor_edit' =>
false,
1565 'sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1566 'comment' =>
'Goat Comment!',
1570 yield
'Basic array, no user field' => [
1574 'timestamp' =>
'20171017114835',
1575 'user_text' =>
'111.0.1.3',
1576 'minor_edit' =>
false,
1580 'sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1581 'comment' =>
'Goat Comment!',
1595 if ( isset( $array[
'page'] ) ) {
1596 $t = Title::newFromID( $array[
'page'] );
1597 if ( !
$t || !
$t->exists() ) {
1598 $t = Title::makeTitle(
NS_MAIN, __METHOD__ );
1600 $array[
'page'] = $info[
'id'];
1604 $result = $store->newMutableRevisionFromArray( $array );
1606 if ( isset( $array[
'id'] ) ) {
1607 $this->assertSame( $array[
'id'], $result->getId() );
1609 if ( isset( $array[
'page'] ) ) {
1610 $this->assertSame( $array[
'page'], $result->getPageId() );
1612 $this->assertSame( $array[
'timestamp'], $result->getTimestamp() );
1613 $this->assertSame( $array[
'user_text'], $result->getUser()->getName() );
1614 if ( isset( $array[
'user'] ) ) {
1615 $this->assertSame( $array[
'user'], $result->getUser()->getId() );
1617 $this->assertSame( (
bool)$array[
'minor_edit'], $result->isMinor() );
1618 $this->assertSame( $array[
'deleted'], $result->getVisibility() );
1619 $this->assertSame( $array[
'len'], $result->getSize() );
1620 $this->assertSame( $array[
'parent_id'], $result->getParentId() );
1621 $this->assertSame( $array[
'sha1'], $result->getSha1() );
1622 $this->assertSame( $array[
'comment'], $result->getComment()->text );
1623 if ( isset( $array[
'content'] ) ) {
1624 foreach ( $array[
'content'] as $role =>
$content ) {
1626 $result->getContent( $role )->equals(
$content )
1629 } elseif ( isset( $array[
'text'] ) ) {
1630 $this->assertSame( $array[
'text'],
1631 $result->getSlot( SlotRecord::MAIN )->getContent()->serialize() );
1632 } elseif ( isset( $array[
'content_format'] ) ) {
1634 $array[
'content_format'],
1635 $result->getSlot( SlotRecord::MAIN )->getContent()->getDefaultFormat()
1637 $this->assertSame( $array[
'content_model'], $result->getSlot( SlotRecord::MAIN )->getModel() );
1649 $blobStore->setLegacyEncoding(
'windows-1252', Language::factory(
'en' ) );
1651 $factory = $this->getMockBuilder( BlobStoreFactory::class )
1652 ->setMethods( [
'newBlobStore',
'newSqlBlobStore' ] )
1653 ->disableOriginalConstructor()
1655 $factory->expects( $this->
any() )
1656 ->method(
'newBlobStore' )
1657 ->willReturn( $blobStore );
1658 $factory->expects( $this->
any() )
1659 ->method(
'newSqlBlobStore' )
1660 ->willReturn( $blobStore );
1662 $this->
setService(
'BlobStoreFactory', $factory );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Simple store for keeping values in an associative array for the current process.
Internationalisation code.
getTitle()
Returns the title of the page associated with this entry.
static getMutableTestUser( $testName, $groups=[])
Get a TestUser object that the caller may modify.
Represents a title within MediaWiki.
Multi-datacenter aware caching interface.
Class representing a MediaWiki article and history.
Class to handle database/prefix specification for IDatabase domains.
Content object for wiki text pages.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
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
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as
patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
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
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
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 but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Base interface for content objects.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))