MediaWiki REL1_31
RevisionStoreDbTest.php
Go to the documentation of this file.
1<?php
2
4
6use Exception;
8use InvalidArgumentException;
9use Language;
20use Revision;
22use Title;
29use WikiPage;
31
36
37 public function setUp() {
38 parent::setUp();
39 $this->tablesUsed[] = 'archive';
40 $this->tablesUsed[] = 'page';
41 $this->tablesUsed[] = 'revision';
42 $this->tablesUsed[] = 'comment';
43 }
44
48 private function getLoadBalancerMock( array $server ) {
49 $lb = $this->getMockBuilder( LoadBalancer::class )
50 ->setMethods( [ 'reallyOpenConnection' ] )
51 ->setConstructorArgs( [ [ 'servers' => [ $server ] ] ] )
52 ->getMock();
53
54 $lb->method( 'reallyOpenConnection' )->willReturnCallback(
55 function ( array $server, $dbNameOverride ) {
56 return $this->getDatabaseMock( $server );
57 }
58 );
59
60 return $lb;
61 }
62
66 private function getDatabaseMock( array $params ) {
67 $db = $this->getMockBuilder( DatabaseSqlite::class )
68 ->setMethods( [ 'select', 'doQuery', 'open', 'closeConnection', 'isOpen' ] )
69 ->setConstructorArgs( [ $params ] )
70 ->getMock();
71
72 $db->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
73 $db->method( 'isOpen' )->willReturn( true );
74
75 return $db;
76 }
77
78 public function provideDomainCheck() {
79 yield [ false, 'test', '' ];
80 yield [ 'test', 'test', '' ];
81
82 yield [ false, 'test', 'foo_' ];
83 yield [ 'test-foo_', 'test', 'foo_' ];
84
85 yield [ false, 'dash-test', '' ];
86 yield [ 'dash-test', 'dash-test', '' ];
87
88 yield [ false, 'underscore_test', 'foo_' ];
89 yield [ 'underscore_test-foo_', 'underscore_test', 'foo_' ];
90 }
91
96 public function testDomainCheck( $wikiId, $dbName, $dbPrefix ) {
97 $this->setMwGlobals(
98 [
99 'wgDBname' => $dbName,
100 'wgDBprefix' => $dbPrefix,
101 ]
102 );
103
104 $loadBalancer = $this->getLoadBalancerMock(
105 [
106 'host' => '*dummy*',
107 'dbDirectory' => '*dummy*',
108 'user' => 'test',
109 'password' => 'test',
110 'flags' => 0,
111 'variables' => [],
112 'schema' => '',
113 'cliMode' => true,
114 'agent' => '',
115 'load' => 100,
116 'profiler' => null,
117 'trxProfiler' => new TransactionProfiler(),
118 'connLogger' => new \Psr\Log\NullLogger(),
119 'queryLogger' => new \Psr\Log\NullLogger(),
120 'errorLogger' => function () {
121 },
122 'deprecationLogger' => function () {
123 },
124 'type' => 'test',
125 'dbname' => $dbName,
126 'tablePrefix' => $dbPrefix,
127 ]
128 );
129 $db = $loadBalancer->getConnection( DB_REPLICA );
130
131 $blobStore = $this->getMockBuilder( SqlBlobStore::class )
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $store = new RevisionStore(
136 $loadBalancer,
137 $blobStore,
138 new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
139 MediaWikiServices::getInstance()->getCommentStore(),
140 MediaWikiServices::getInstance()->getActorMigration(),
141 $wikiId
142 );
143
144 $count = $store->countRevisionsByPageId( $db, 0 );
145
146 // Dummy check to make PhpUnit happy. We are really only interested in
147 // countRevisionsByPageId not failing due to the DB domain check.
148 $this->assertSame( 0, $count );
149 }
150
151 private function assertLinkTargetsEqual( LinkTarget $l1, LinkTarget $l2 ) {
152 $this->assertEquals( $l1->getDBkey(), $l2->getDBkey() );
153 $this->assertEquals( $l1->getNamespace(), $l2->getNamespace() );
154 $this->assertEquals( $l1->getFragment(), $l2->getFragment() );
155 $this->assertEquals( $l1->getInterwiki(), $l2->getInterwiki() );
156 }
157
159 $this->assertEquals( $r1->getUser()->getName(), $r2->getUser()->getName() );
160 $this->assertEquals( $r1->getUser()->getId(), $r2->getUser()->getId() );
161 $this->assertEquals( $r1->getComment(), $r2->getComment() );
162 $this->assertEquals( $r1->getPageAsLinkTarget(), $r2->getPageAsLinkTarget() );
163 $this->assertEquals( $r1->getTimestamp(), $r2->getTimestamp() );
164 $this->assertEquals( $r1->getVisibility(), $r2->getVisibility() );
165 $this->assertEquals( $r1->getSha1(), $r2->getSha1() );
166 $this->assertEquals( $r1->getParentId(), $r2->getParentId() );
167 $this->assertEquals( $r1->getSize(), $r2->getSize() );
168 $this->assertEquals( $r1->getPageId(), $r2->getPageId() );
169 $this->assertEquals( $r1->getSlotRoles(), $r2->getSlotRoles() );
170 $this->assertEquals( $r1->getWikiId(), $r2->getWikiId() );
171 $this->assertEquals( $r1->isMinor(), $r2->isMinor() );
172 foreach ( $r1->getSlotRoles() as $role ) {
173 $this->assertSlotRecordsEqual( $r1->getSlot( $role ), $r2->getSlot( $role ) );
174 $this->assertTrue( $r1->getContent( $role )->equals( $r2->getContent( $role ) ) );
175 }
176 foreach ( [
177 RevisionRecord::DELETED_TEXT,
178 RevisionRecord::DELETED_COMMENT,
179 RevisionRecord::DELETED_USER,
180 RevisionRecord::DELETED_RESTRICTED,
181 ] as $field ) {
182 $this->assertEquals( $r1->isDeleted( $field ), $r2->isDeleted( $field ) );
183 }
184 }
185
186 private function assertSlotRecordsEqual( SlotRecord $s1, SlotRecord $s2 ) {
187 $this->assertSame( $s1->getRole(), $s2->getRole() );
188 $this->assertSame( $s1->getModel(), $s2->getModel() );
189 $this->assertSame( $s1->getFormat(), $s2->getFormat() );
190 $this->assertSame( $s1->getSha1(), $s2->getSha1() );
191 $this->assertSame( $s1->getSize(), $s2->getSize() );
192 $this->assertTrue( $s1->getContent()->equals( $s2->getContent() ) );
193
194 $s1->hasRevision() ? $this->assertSame( $s1->getRevision(), $s2->getRevision() ) : null;
195 $s1->hasAddress() ? $this->assertSame( $s1->hasAddress(), $s2->hasAddress() ) : null;
196 }
197
199 foreach ( $r->getSlotRoles() as $role ) {
200 $this->assertSlotCompleteness( $r, $r->getSlot( $role ) );
201 }
202 }
203
204 private function assertSlotCompleteness( RevisionRecord $r, SlotRecord $slot ) {
205 $this->assertTrue( $slot->hasAddress() );
206 $this->assertSame( $r->getId(), $slot->getRevision() );
207 }
208
214 private function getRevisionRecordFromDetailsArray( $title, $details = [] ) {
215 // Convert some values that can't be provided by dataProviders
216 $page = WikiPage::factory( $title );
217 if ( isset( $details['user'] ) && $details['user'] === true ) {
218 $details['user'] = $this->getTestUser()->getUser();
219 }
220 if ( isset( $details['page'] ) && $details['page'] === true ) {
221 $details['page'] = $page->getId();
222 }
223 if ( isset( $details['parent'] ) && $details['parent'] === true ) {
224 $details['parent'] = $page->getLatest();
225 }
226
227 // Create the RevisionRecord with any available data
228 $rev = new MutableRevisionRecord( $title );
229 isset( $details['slot'] ) ? $rev->setSlot( $details['slot'] ) : null;
230 isset( $details['parent'] ) ? $rev->setParentId( $details['parent'] ) : null;
231 isset( $details['page'] ) ? $rev->setPageId( $details['page'] ) : null;
232 isset( $details['size'] ) ? $rev->setSize( $details['size'] ) : null;
233 isset( $details['sha1'] ) ? $rev->setSha1( $details['sha1'] ) : null;
234 isset( $details['comment'] ) ? $rev->setComment( $details['comment'] ) : null;
235 isset( $details['timestamp'] ) ? $rev->setTimestamp( $details['timestamp'] ) : null;
236 isset( $details['minor'] ) ? $rev->setMinorEdit( $details['minor'] ) : null;
237 isset( $details['user'] ) ? $rev->setUser( $details['user'] ) : null;
238 isset( $details['visibility'] ) ? $rev->setVisibility( $details['visibility'] ) : null;
239 isset( $details['id'] ) ? $rev->setId( $details['id'] ) : null;
240
241 return $rev;
242 }
243
244 private function getRandomCommentStoreComment() {
245 return CommentStoreComment::newUnsavedComment( __METHOD__ . '.' . rand( 0, 1000 ) );
246 }
247
249 yield 'Bare minimum revision insertion' => [
250 Title::newFromText( 'UTPage' ),
251 [
252 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
253 'parent' => true,
254 'comment' => $this->getRandomCommentStoreComment(),
255 'timestamp' => '20171117010101',
256 'user' => true,
257 ],
258 ];
259 yield 'Detailed revision insertion' => [
260 Title::newFromText( 'UTPage' ),
261 [
262 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
263 'parent' => true,
264 'page' => true,
265 'comment' => $this->getRandomCommentStoreComment(),
266 'timestamp' => '20171117010101',
267 'user' => true,
268 'minor' => true,
269 'visibility' => RevisionRecord::DELETED_RESTRICTED,
270 ],
271 ];
272 }
273
278 public function testInsertRevisionOn_successes( Title $title, array $revDetails = [] ) {
279 $rev = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
280
281 $store = MediaWikiServices::getInstance()->getRevisionStore();
282 $return = $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER ) );
283
284 $this->assertLinkTargetsEqual( $title, $return->getPageAsLinkTarget() );
285 $this->assertRevisionRecordsEqual( $rev, $return );
286 $this->assertRevisionCompleteness( $return );
287 }
288
293 $title = Title::newFromText( 'UTPage' );
294 $revDetails = [
295 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
296 'parent' => true,
297 'comment' => $this->getRandomCommentStoreComment(),
298 'timestamp' => '20171117010101',
299 'user' => true,
300 ];
301
302 $store = MediaWikiServices::getInstance()->getRevisionStore();
303
304 // Insert the first revision
305 $revOne = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
306 $firstReturn = $store->insertRevisionOn( $revOne, wfGetDB( DB_MASTER ) );
307 $this->assertLinkTargetsEqual( $title, $firstReturn->getPageAsLinkTarget() );
308 $this->assertRevisionRecordsEqual( $revOne, $firstReturn );
309
310 // Insert a second revision inheriting the same blob address
311 $revDetails['slot'] = SlotRecord::newInherited( $firstReturn->getSlot( 'main' ) );
312 $revTwo = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
313 $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_MASTER ) );
314 $this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
315 $this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
316
317 // Assert that the same blob address has been used.
318 $this->assertEquals(
319 $firstReturn->getSlot( 'main' )->getAddress(),
320 $secondReturn->getSlot( 'main' )->getAddress()
321 );
322 // And that different revisions have been created.
323 $this->assertNotSame(
324 $firstReturn->getId(),
325 $secondReturn->getId()
326 );
327 }
328
330 yield 'no slot' => [
331 Title::newFromText( 'UTPage' ),
332 [
333 'comment' => $this->getRandomCommentStoreComment(),
334 'timestamp' => '20171117010101',
335 'user' => true,
336 ],
337 new InvalidArgumentException( 'At least one slot needs to be defined!' )
338 ];
339 yield 'slot that is not main slot' => [
340 Title::newFromText( 'UTPage' ),
341 [
342 'slot' => SlotRecord::newUnsaved( 'lalala', new WikitextContent( 'Chicken' ) ),
343 'comment' => $this->getRandomCommentStoreComment(),
344 'timestamp' => '20171117010101',
345 'user' => true,
346 ],
347 new InvalidArgumentException( 'Only the main slot is supported for now!' )
348 ];
349 yield 'no timestamp' => [
350 Title::newFromText( 'UTPage' ),
351 [
352 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
353 'comment' => $this->getRandomCommentStoreComment(),
354 'user' => true,
355 ],
356 new IncompleteRevisionException( 'timestamp field must not be NULL!' )
357 ];
358 yield 'no comment' => [
359 Title::newFromText( 'UTPage' ),
360 [
361 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
362 'timestamp' => '20171117010101',
363 'user' => true,
364 ],
365 new IncompleteRevisionException( 'comment must not be NULL!' )
366 ];
367 yield 'no user' => [
368 Title::newFromText( 'UTPage' ),
369 [
370 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
371 'comment' => $this->getRandomCommentStoreComment(),
372 'timestamp' => '20171117010101',
373 ],
374 new IncompleteRevisionException( 'user must not be NULL!' )
375 ];
376 }
377
383 Title $title,
384 array $revDetails = [],
385 Exception $exception ) {
386 $rev = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
387
388 $store = MediaWikiServices::getInstance()->getRevisionStore();
389
390 $this->setExpectedException(
391 get_class( $exception ),
392 $exception->getMessage(),
393 $exception->getCode()
394 );
395 $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER ) );
396 }
397
398 public function provideNewNullRevision() {
399 yield [
400 Title::newFromText( 'UTPage' ),
401 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment1' ),
402 true,
403 ];
404 yield [
405 Title::newFromText( 'UTPage' ),
406 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment2', [ 'a' => 1 ] ),
407 false,
408 ];
409 }
410
415 public function testNewNullRevision( Title $title, $comment, $minor ) {
416 $store = MediaWikiServices::getInstance()->getRevisionStore();
417 $user = TestUserRegistry::getMutableTestUser( __METHOD__ )->getUser();
418
419 $parent = $store->getRevisionByTitle( $title );
420 $record = $store->newNullRevision(
422 $title,
423 $comment,
424 $minor,
425 $user
426 );
427
428 $this->assertEquals( $title->getNamespace(), $record->getPageAsLinkTarget()->getNamespace() );
429 $this->assertEquals( $title->getDBkey(), $record->getPageAsLinkTarget()->getDBkey() );
430 $this->assertEquals( $comment, $record->getComment() );
431 $this->assertEquals( $minor, $record->isMinor() );
432 $this->assertEquals( $user->getName(), $record->getUser()->getName() );
433 $this->assertEquals( $parent->getId(), $record->getParentId() );
434
435 $parentSlot = $parent->getSlot( 'main' );
436 $slot = $record->getSlot( 'main' );
437
438 $this->assertTrue( $slot->isInherited(), 'isInherited' );
439 $this->assertSame( $parentSlot->getOrigin(), $slot->getOrigin(), 'getOrigin' );
440 $this->assertSame( $parentSlot->getAddress(), $slot->getAddress(), 'getAddress' );
441 }
442
447 $store = MediaWikiServices::getInstance()->getRevisionStore();
448 $record = $store->newNullRevision(
450 Title::newFromText( __METHOD__ . '.iDontExist!' ),
451 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment' ),
452 false,
453 TestUserRegistry::getMutableTestUser( __METHOD__ )->getUser()
454 );
455 $this->assertNull( $record );
456 }
457
462 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
463 $status = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
465 $rev = $status->value['revision'];
466
467 $store = MediaWikiServices::getInstance()->getRevisionStore();
468 $revisionRecord = $store->getRevisionById( $rev->getId() );
469 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
470
471 $this->assertGreaterThan( 0, $result );
472 $this->assertSame(
473 $page->getRevision()->getRecentChange()->getAttribute( 'rc_id' ),
474 $result
475 );
476 }
477
482 // This assumes that sysops are auto patrolled
483 $sysop = $this->getTestSysop()->getUser();
484 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
485 $status = $page->doEditContent(
486 new WikitextContent( __METHOD__ ),
487 __METHOD__,
488 0,
489 false,
490 $sysop
491 );
493 $rev = $status->value['revision'];
494
495 $store = MediaWikiServices::getInstance()->getRevisionStore();
496 $revisionRecord = $store->getRevisionById( $rev->getId() );
497 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
498
499 $this->assertSame( 0, $result );
500 }
501
505 public function testGetRecentChange() {
506 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
507 $content = new WikitextContent( __METHOD__ );
508 $status = $page->doEditContent( $content, __METHOD__ );
510 $rev = $status->value['revision'];
511
512 $store = MediaWikiServices::getInstance()->getRevisionStore();
513 $revRecord = $store->getRevisionById( $rev->getId() );
514 $recentChange = $store->getRecentChange( $revRecord );
515
516 $this->assertEquals( $rev->getId(), $recentChange->getAttribute( 'rc_this_oldid' ) );
517 $this->assertEquals( $rev->getRecentChange(), $recentChange );
518 }
519
523 public function testGetRevisionById() {
524 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
525 $content = new WikitextContent( __METHOD__ );
526 $status = $page->doEditContent( $content, __METHOD__ );
528 $rev = $status->value['revision'];
529
530 $store = MediaWikiServices::getInstance()->getRevisionStore();
531 $revRecord = $store->getRevisionById( $rev->getId() );
532
533 $this->assertSame( $rev->getId(), $revRecord->getId() );
534 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
535 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
536 }
537
541 public function testGetRevisionByTitle() {
542 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
543 $content = new WikitextContent( __METHOD__ );
544 $status = $page->doEditContent( $content, __METHOD__ );
546 $rev = $status->value['revision'];
547
548 $store = MediaWikiServices::getInstance()->getRevisionStore();
549 $revRecord = $store->getRevisionByTitle( $page->getTitle() );
550
551 $this->assertSame( $rev->getId(), $revRecord->getId() );
552 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
553 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
554 }
555
559 public function testGetRevisionByPageId() {
560 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
561 $content = new WikitextContent( __METHOD__ );
562 $status = $page->doEditContent( $content, __METHOD__ );
564 $rev = $status->value['revision'];
565
566 $store = MediaWikiServices::getInstance()->getRevisionStore();
567 $revRecord = $store->getRevisionByPageId( $page->getId() );
568
569 $this->assertSame( $rev->getId(), $revRecord->getId() );
570 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
571 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
572 }
573
577 public function testGetRevisionByTimestamp() {
578 // Make sure there is 1 second between the last revision and the rev we create...
579 // Otherwise we might not get the correct revision and the test may fail...
580 // :(
581 sleep( 1 );
582 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
583 $content = new WikitextContent( __METHOD__ );
584 $status = $page->doEditContent( $content, __METHOD__ );
586 $rev = $status->value['revision'];
587
588 $store = MediaWikiServices::getInstance()->getRevisionStore();
589 $revRecord = $store->getRevisionByTimestamp(
590 $page->getTitle(),
591 $rev->getTimestamp()
592 );
593
594 $this->assertSame( $rev->getId(), $revRecord->getId() );
595 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
596 $this->assertSame( __METHOD__, $revRecord->getComment()->text );
597 }
598
599 private function revisionToRow( Revision $rev ) {
600 $page = WikiPage::factory( $rev->getTitle() );
601
602 return (object)[
603 'rev_id' => (string)$rev->getId(),
604 'rev_page' => (string)$rev->getPage(),
605 'rev_text_id' => (string)$rev->getTextId(),
606 'rev_timestamp' => (string)$rev->getTimestamp(),
607 'rev_user_text' => (string)$rev->getUserText(),
608 'rev_user' => (string)$rev->getUser(),
609 'rev_minor_edit' => $rev->isMinor() ? '1' : '0',
610 'rev_deleted' => (string)$rev->getVisibility(),
611 'rev_len' => (string)$rev->getSize(),
612 'rev_parent_id' => (string)$rev->getParentId(),
613 'rev_sha1' => (string)$rev->getSha1(),
614 'rev_comment_text' => $rev->getComment(),
615 'rev_comment_data' => null,
616 'rev_comment_cid' => null,
617 'rev_content_format' => $rev->getContentFormat(),
618 'rev_content_model' => $rev->getContentModel(),
619 'page_namespace' => (string)$page->getTitle()->getNamespace(),
620 'page_title' => $page->getTitle()->getDBkey(),
621 'page_id' => (string)$page->getId(),
622 'page_latest' => (string)$page->getLatest(),
623 'page_is_redirect' => $page->isRedirect() ? '1' : '0',
624 'page_len' => (string)$page->getContent()->getSize(),
625 'user_name' => (string)$rev->getUserText(),
626 ];
627 }
628
631 RevisionRecord $record
632 ) {
633 $this->assertSame( $rev->getId(), $record->getId() );
634 $this->assertSame( $rev->getPage(), $record->getPageId() );
635 $this->assertSame( $rev->getTimestamp(), $record->getTimestamp() );
636 $this->assertSame( $rev->getUserText(), $record->getUser()->getName() );
637 $this->assertSame( $rev->getUser(), $record->getUser()->getId() );
638 $this->assertSame( $rev->isMinor(), $record->isMinor() );
639 $this->assertSame( $rev->getVisibility(), $record->getVisibility() );
640 $this->assertSame( $rev->getSize(), $record->getSize() );
645 $expectedParent = $rev->getParentId();
646 if ( $expectedParent === null ) {
647 $expectedParent = 0;
648 }
649 $this->assertSame( $expectedParent, $record->getParentId() );
650 $this->assertSame( $rev->getSha1(), $record->getSha1() );
651 $this->assertSame( $rev->getComment(), $record->getComment()->text );
652 $this->assertSame( $rev->getContentFormat(), $record->getContent( 'main' )->getDefaultFormat() );
653 $this->assertSame( $rev->getContentModel(), $record->getContent( 'main' )->getModel() );
654 $this->assertLinkTargetsEqual( $rev->getTitle(), $record->getPageAsLinkTarget() );
655 }
656
662 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
663 $this->overrideMwServices();
664
665 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
666 $text = __METHOD__ . 'a-ä';
668 $rev = $page->doEditContent(
669 new WikitextContent( $text ),
670 __METHOD__ . 'a'
671 )->value['revision'];
672
673 $store = MediaWikiServices::getInstance()->getRevisionStore();
674 $record = $store->newRevisionFromRow(
675 $this->revisionToRow( $rev ),
676 [],
677 $page->getTitle()
678 );
679 $this->assertRevisionRecordMatchesRevision( $rev, $record );
680 $this->assertSame( $text, $rev->getContent()->serialize() );
681 }
682
688 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
689 $this->overrideMwServices();
690 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
691 $text = __METHOD__ . 'a-ä';
693 $rev = $page->doEditContent(
694 new WikitextContent( $text ),
695 __METHOD__. 'a'
696 )->value['revision'];
697
698 $store = MediaWikiServices::getInstance()->getRevisionStore();
699 $record = $store->newRevisionFromRow(
700 $this->revisionToRow( $rev ),
701 [],
702 $page->getTitle()
703 );
704 $this->assertRevisionRecordMatchesRevision( $rev, $record );
705 $this->assertSame( $text, $rev->getContent()->serialize() );
706 }
707
713 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
714 $this->overrideMwServices();
715
716 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
717 $text = __METHOD__ . 'b-ä';
719 $rev = $page->doEditContent(
720 new WikitextContent( $text ),
721 __METHOD__ . 'b',
722 0,
723 false,
724 $this->getTestUser()->getUser()
725 )->value['revision'];
726
727 $store = MediaWikiServices::getInstance()->getRevisionStore();
728 $record = $store->newRevisionFromRow(
729 $this->revisionToRow( $rev ),
730 [],
731 $page->getTitle()
732 );
733 $this->assertRevisionRecordMatchesRevision( $rev, $record );
734 $this->assertSame( $text, $rev->getContent()->serialize() );
735 }
736
741 $store = MediaWikiServices::getInstance()->getRevisionStore();
742 $title = Title::newFromText( __METHOD__ );
743 $text = __METHOD__ . '-bä';
744 $page = WikiPage::factory( $title );
746 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
747 ->value['revision'];
748 $page->doDeleteArticle( __METHOD__ );
749
750 $db = wfGetDB( DB_MASTER );
751 $arQuery = $store->getArchiveQueryInfo();
752 $res = $db->select(
753 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
754 __METHOD__, [], $arQuery['joins']
755 );
756 $this->assertTrue( is_object( $res ), 'query failed' );
757
758 $row = $res->fetchObject();
759 $res->free();
760 $record = $store->newRevisionFromArchiveRow( $row );
761
762 $this->assertRevisionRecordMatchesRevision( $orig, $record );
763 $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
764 }
765
770 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
771 $this->overrideMwServices();
772 $store = MediaWikiServices::getInstance()->getRevisionStore();
773 $title = Title::newFromText( __METHOD__ );
774 $text = __METHOD__ . '-bä';
775 $page = WikiPage::factory( $title );
777 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
778 ->value['revision'];
779 $page->doDeleteArticle( __METHOD__ );
780
781 $db = wfGetDB( DB_MASTER );
782 $arQuery = $store->getArchiveQueryInfo();
783 $res = $db->select(
784 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
785 __METHOD__, [], $arQuery['joins']
786 );
787 $this->assertTrue( is_object( $res ), 'query failed' );
788
789 $row = $res->fetchObject();
790 $res->free();
791 $record = $store->newRevisionFromArchiveRow( $row );
792
793 $this->assertRevisionRecordMatchesRevision( $orig, $record );
794 $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
795 }
796
800 public function testLoadRevisionFromId() {
801 $title = Title::newFromText( __METHOD__ );
802 $page = WikiPage::factory( $title );
804 $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
805 ->value['revision'];
806
807 $store = MediaWikiServices::getInstance()->getRevisionStore();
808 $result = $store->loadRevisionFromId( wfGetDB( DB_MASTER ), $rev->getId() );
809 $this->assertRevisionRecordMatchesRevision( $rev, $result );
810 }
811
815 public function testLoadRevisionFromPageId() {
816 $title = Title::newFromText( __METHOD__ );
817 $page = WikiPage::factory( $title );
819 $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
820 ->value['revision'];
821
822 $store = MediaWikiServices::getInstance()->getRevisionStore();
823 $result = $store->loadRevisionFromPageId( wfGetDB( DB_MASTER ), $page->getId() );
824 $this->assertRevisionRecordMatchesRevision( $rev, $result );
825 }
826
830 public function testLoadRevisionFromTitle() {
831 $title = Title::newFromText( __METHOD__ );
832 $page = WikiPage::factory( $title );
834 $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
835 ->value['revision'];
836
837 $store = MediaWikiServices::getInstance()->getRevisionStore();
838 $result = $store->loadRevisionFromTitle( wfGetDB( DB_MASTER ), $title );
839 $this->assertRevisionRecordMatchesRevision( $rev, $result );
840 }
841
846 $title = Title::newFromText( __METHOD__ );
847 $page = WikiPage::factory( $title );
849 $revOne = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
850 ->value['revision'];
851 // Sleep to ensure different timestamps... )(evil)
852 sleep( 1 );
854 $revTwo = $page->doEditContent( new WikitextContent( __METHOD__ . 'a' ), '' )
855 ->value['revision'];
856
857 $store = MediaWikiServices::getInstance()->getRevisionStore();
858 $this->assertNull(
859 $store->loadRevisionFromTimestamp( wfGetDB( DB_MASTER ), $title, '20150101010101' )
860 );
861 $this->assertSame(
862 $revOne->getId(),
863 $store->loadRevisionFromTimestamp(
865 $title,
866 $revOne->getTimestamp()
867 )->getId()
868 );
869 $this->assertSame(
870 $revTwo->getId(),
871 $store->loadRevisionFromTimestamp(
873 $title,
874 $revTwo->getTimestamp()
875 )->getId()
876 );
877 }
878
882 public function testGetParentLengths() {
883 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
885 $revOne = $page->doEditContent(
886 new WikitextContent( __METHOD__ ), __METHOD__
887 )->value['revision'];
889 $revTwo = $page->doEditContent(
890 new WikitextContent( __METHOD__ . '2' ), __METHOD__
891 )->value['revision'];
892
893 $store = MediaWikiServices::getInstance()->getRevisionStore();
894 $this->assertSame(
895 [
896 $revOne->getId() => strlen( __METHOD__ ),
897 ],
898 $store->listRevisionSizes(
900 [ $revOne->getId() ]
901 )
902 );
903 $this->assertSame(
904 [
905 $revOne->getId() => strlen( __METHOD__ ),
906 $revTwo->getId() => strlen( __METHOD__ ) + 1,
907 ],
908 $store->listRevisionSizes(
910 [ $revOne->getId(), $revTwo->getId() ]
911 )
912 );
913 }
914
918 public function testGetPreviousRevision() {
919 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
921 $revOne = $page->doEditContent(
922 new WikitextContent( __METHOD__ ), __METHOD__
923 )->value['revision'];
925 $revTwo = $page->doEditContent(
926 new WikitextContent( __METHOD__ . '2' ), __METHOD__
927 )->value['revision'];
928
929 $store = MediaWikiServices::getInstance()->getRevisionStore();
930 $this->assertNull(
931 $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
932 );
933 $this->assertSame(
934 $revOne->getId(),
935 $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
936 );
937 }
938
942 public function testGetNextRevision() {
943 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
945 $revOne = $page->doEditContent(
946 new WikitextContent( __METHOD__ ), __METHOD__
947 )->value['revision'];
949 $revTwo = $page->doEditContent(
950 new WikitextContent( __METHOD__ . '2' ), __METHOD__
951 )->value['revision'];
952
953 $store = MediaWikiServices::getInstance()->getRevisionStore();
954 $this->assertSame(
955 $revTwo->getId(),
956 $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
957 );
958 $this->assertNull(
959 $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
960 );
961 }
962
967 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
969 $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
970 ->value['revision'];
971
972 $store = MediaWikiServices::getInstance()->getRevisionStore();
973 $result = $store->getTimestampFromId(
974 $page->getTitle(),
975 $rev->getId()
976 );
977
978 $this->assertSame( $rev->getTimestamp(), $result );
979 }
980
985 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
987 $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
988 ->value['revision'];
989
990 $store = MediaWikiServices::getInstance()->getRevisionStore();
991 $result = $store->getTimestampFromId(
992 $page->getTitle(),
993 $rev->getId() + 1
994 );
995
996 $this->assertFalse( $result );
997 }
998
1002 public function testCountRevisionsByPageId() {
1003 $store = MediaWikiServices::getInstance()->getRevisionStore();
1004 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1005
1006 $this->assertSame(
1007 0,
1008 $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1009 );
1010 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1011 $this->assertSame(
1012 1,
1013 $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1014 );
1015 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1016 $this->assertSame(
1017 2,
1018 $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1019 );
1020 }
1021
1025 public function testCountRevisionsByTitle() {
1026 $store = MediaWikiServices::getInstance()->getRevisionStore();
1027 $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1028
1029 $this->assertSame(
1030 0,
1031 $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1032 );
1033 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1034 $this->assertSame(
1035 1,
1036 $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1037 );
1038 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1039 $this->assertSame(
1040 2,
1041 $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1042 );
1043 }
1044
1049 $sysop = $this->getTestSysop()->getUser();
1050 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
1051 $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
1052
1053 $store = MediaWikiServices::getInstance()->getRevisionStore();
1054 $result = $store->userWasLastToEdit(
1055 wfGetDB( DB_MASTER ),
1056 $page->getId(),
1057 $sysop->getId(),
1058 '20160101010101'
1059 );
1060 $this->assertFalse( $result );
1061 }
1062
1066 public function testUserWasLastToEdit_true() {
1067 $startTime = wfTimestampNow();
1068 $sysop = $this->getTestSysop()->getUser();
1069 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
1070 $page->doEditContent(
1071 new WikitextContent( __METHOD__ ),
1072 __METHOD__,
1073 0,
1074 false,
1075 $sysop
1076 );
1077
1078 $store = MediaWikiServices::getInstance()->getRevisionStore();
1079 $result = $store->userWasLastToEdit(
1080 wfGetDB( DB_MASTER ),
1081 $page->getId(),
1082 $sysop->getId(),
1083 $startTime
1084 );
1085 $this->assertTrue( $result );
1086 }
1087
1092 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
1094 $rev = $page->doEditContent(
1095 new WikitextContent( __METHOD__ . 'b' ),
1096 __METHOD__ . 'b',
1097 0,
1098 false,
1099 $this->getTestUser()->getUser()
1100 )->value['revision'];
1101
1102 $store = MediaWikiServices::getInstance()->getRevisionStore();
1103 $record = $store->getKnownCurrentRevision(
1104 $page->getTitle(),
1105 $rev->getId()
1106 );
1107
1108 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1109 }
1110
1112 yield 'Basic array, with page & id' => [
1113 [
1114 'id' => 2,
1115 'page' => 1,
1116 'text_id' => 2,
1117 'timestamp' => '20171017114835',
1118 'user_text' => '111.0.1.2',
1119 'user' => 0,
1120 'minor_edit' => false,
1121 'deleted' => 0,
1122 'len' => 46,
1123 'parent_id' => 1,
1124 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1125 'comment' => 'Goat Comment!',
1126 'content_format' => 'text/x-wiki',
1127 'content_model' => 'wikitext',
1128 ]
1129 ];
1130 yield 'Basic array, content object' => [
1131 [
1132 'id' => 2,
1133 'page' => 1,
1134 'timestamp' => '20171017114835',
1135 'user_text' => '111.0.1.2',
1136 'user' => 0,
1137 'minor_edit' => false,
1138 'deleted' => 0,
1139 'len' => 46,
1140 'parent_id' => 1,
1141 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1142 'comment' => 'Goat Comment!',
1143 'content' => new WikitextContent( 'Some Content' ),
1144 ]
1145 ];
1146 yield 'Basic array, serialized text' => [
1147 [
1148 'id' => 2,
1149 'page' => 1,
1150 'timestamp' => '20171017114835',
1151 'user_text' => '111.0.1.2',
1152 'user' => 0,
1153 'minor_edit' => false,
1154 'deleted' => 0,
1155 'len' => 46,
1156 'parent_id' => 1,
1157 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1158 'comment' => 'Goat Comment!',
1159 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1160 ]
1161 ];
1162 yield 'Basic array, serialized text, utf-8 flags' => [
1163 [
1164 'id' => 2,
1165 'page' => 1,
1166 'timestamp' => '20171017114835',
1167 'user_text' => '111.0.1.2',
1168 'user' => 0,
1169 'minor_edit' => false,
1170 'deleted' => 0,
1171 'len' => 46,
1172 'parent_id' => 1,
1173 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1174 'comment' => 'Goat Comment!',
1175 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1176 'flags' => 'utf-8',
1177 ]
1178 ];
1179 yield 'Basic array, with title' => [
1180 [
1181 'title' => Title::newFromText( 'SomeText' ),
1182 'text_id' => 2,
1183 'timestamp' => '20171017114835',
1184 'user_text' => '111.0.1.2',
1185 'user' => 0,
1186 'minor_edit' => false,
1187 'deleted' => 0,
1188 'len' => 46,
1189 'parent_id' => 1,
1190 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1191 'comment' => 'Goat Comment!',
1192 'content_format' => 'text/x-wiki',
1193 'content_model' => 'wikitext',
1194 ]
1195 ];
1196 yield 'Basic array, no user field' => [
1197 [
1198 'id' => 2,
1199 'page' => 1,
1200 'text_id' => 2,
1201 'timestamp' => '20171017114835',
1202 'user_text' => '111.0.1.3',
1203 'minor_edit' => false,
1204 'deleted' => 0,
1205 'len' => 46,
1206 'parent_id' => 1,
1207 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1208 'comment' => 'Goat Comment!',
1209 'content_format' => 'text/x-wiki',
1210 'content_model' => 'wikitext',
1211 ]
1212 ];
1213 }
1214
1219 public function testNewMutableRevisionFromArray( array $array ) {
1220 $store = MediaWikiServices::getInstance()->getRevisionStore();
1221
1222 $result = $store->newMutableRevisionFromArray( $array );
1223
1224 if ( isset( $array['id'] ) ) {
1225 $this->assertSame( $array['id'], $result->getId() );
1226 }
1227 if ( isset( $array['page'] ) ) {
1228 $this->assertSame( $array['page'], $result->getPageId() );
1229 }
1230 $this->assertSame( $array['timestamp'], $result->getTimestamp() );
1231 $this->assertSame( $array['user_text'], $result->getUser()->getName() );
1232 if ( isset( $array['user'] ) ) {
1233 $this->assertSame( $array['user'], $result->getUser()->getId() );
1234 }
1235 $this->assertSame( (bool)$array['minor_edit'], $result->isMinor() );
1236 $this->assertSame( $array['deleted'], $result->getVisibility() );
1237 $this->assertSame( $array['len'], $result->getSize() );
1238 $this->assertSame( $array['parent_id'], $result->getParentId() );
1239 $this->assertSame( $array['sha1'], $result->getSha1() );
1240 $this->assertSame( $array['comment'], $result->getComment()->text );
1241 if ( isset( $array['content'] ) ) {
1242 $this->assertTrue(
1243 $result->getSlot( 'main' )->getContent()->equals( $array['content'] )
1244 );
1245 } elseif ( isset( $array['text'] ) ) {
1246 $this->assertSame( $array['text'], $result->getSlot( 'main' )->getContent()->serialize() );
1247 } else {
1248 $this->assertSame(
1249 $array['content_format'],
1250 $result->getSlot( 'main' )->getContent()->getDefaultFormat()
1251 );
1252 $this->assertSame( $array['content_model'], $result->getSlot( 'main' )->getModel() );
1253 }
1254 }
1255
1260 public function testNewMutableRevisionFromArray_legacyEncoding( array $array ) {
1261 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1262 $blobStore = new SqlBlobStore( wfGetLB(), $cache );
1263 $blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
1264
1265 $factory = $this->getMockBuilder( BlobStoreFactory::class )
1266 ->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
1267 ->disableOriginalConstructor()
1268 ->getMock();
1269 $factory->expects( $this->any() )
1270 ->method( 'newBlobStore' )
1271 ->willReturn( $blobStore );
1272 $factory->expects( $this->any() )
1273 ->method( 'newSqlBlobStore' )
1274 ->willReturn( $blobStore );
1275
1276 $this->setService( 'BlobStoreFactory', $factory );
1277
1278 $this->testNewMutableRevisionFromArray( $array );
1279 }
1280
1281}
serialize()
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetLB( $wiki=false)
Get a load balancer object.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
CommentStoreComment represents a comment stored by CommentStore.
Simple store for keeping values in an associative array for the current process.
Internationalisation code.
Definition Language.php:35
Database $db
Primary database.
static getTestSysop()
Convenience method for getting an immutable admin test user.
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
Service for instantiating BlobStores.
Exception throw when trying to access undefined fields on an incomplete RevisionRecord.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Page revision base class.
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Service for looking up page revisions.
Value object representing a content slot associated with a page revision.
getRevision()
Returns the ID of the revision this slot is associated with.
hasAddress()
Whether this slot has an address.
Service for storing and loading Content objects.
testGetNextRevision()
\MediaWiki\Storage\RevisionStore::getNextRevision
testLoadRevisionFromId()
\MediaWiki\Storage\RevisionStore::loadRevisionFromId
assertSlotCompleteness(RevisionRecord $r, SlotRecord $slot)
testInsertRevisionOn_blobAddressExists()
\MediaWiki\Storage\RevisionStore::insertRevisionOn
testUserWasLastToEdit_true()
\MediaWiki\Storage\RevisionStore::userWasLastToEdit
testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled()
\MediaWiki\Storage\RevisionStore::getRcIdIfUnpatrolled
testNewMutableRevisionFromArray_legacyEncoding(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
testUserWasLastToEdit_false()
\MediaWiki\Storage\RevisionStore::userWasLastToEdit
testGetRevisionByTimestamp()
\MediaWiki\Storage\RevisionStore::getRevisionByTimestamp
testNewNullRevision_nonExistingTitle()
\MediaWiki\Storage\RevisionStore::newNullRevision
testGetParentLengths()
\MediaWiki\Storage\RevisionStore::listRevisionSizes
testNewRevisionFromRow_anonEdit_legacyEncoding()
\MediaWiki\Storage\RevisionStore::newRevisionFromRow \MediaWiki\Storage\RevisionStore::newRevisionFro...
testCountRevisionsByPageId()
\MediaWiki\Storage\RevisionStore::countRevisionsByPageId
testInsertRevisionOn_failures(Title $title, array $revDetails=[], Exception $exception)
provideInsertRevisionOn_failures \MediaWiki\Storage\RevisionStore::insertRevisionOn
testCountRevisionsByTitle()
\MediaWiki\Storage\RevisionStore::countRevisionsByTitle
testGetTimestampFromId_found()
\MediaWiki\Storage\RevisionStore::getTimestampFromId
testGetRevisionById()
\MediaWiki\Storage\RevisionStore::getRevisionById
testNewRevisionFromArchiveRow()
\MediaWiki\Storage\RevisionStore::newRevisionFromArchiveRow
testNewRevisionFromRow_userEdit()
\MediaWiki\Storage\RevisionStore::newRevisionFromRow \MediaWiki\Storage\RevisionStore::newRevisionFro...
assertSlotRecordsEqual(SlotRecord $s1, SlotRecord $s2)
testGetTimestampFromId_notFound()
\MediaWiki\Storage\RevisionStore::getTimestampFromId
testInsertRevisionOn_successes(Title $title, array $revDetails=[])
provideInsertRevisionOn_successes \MediaWiki\Storage\RevisionStore::insertRevisionOn
testLoadRevisionFromTitle()
\MediaWiki\Storage\RevisionStore::loadRevisionFromTitle
testGetPreviousRevision()
\MediaWiki\Storage\RevisionStore::getPreviousRevision
testGetRevisionByPageId()
\MediaWiki\Storage\RevisionStore::getRevisionByPageId
testLoadRevisionFromPageId()
\MediaWiki\Storage\RevisionStore::loadRevisionFromPageId
testNewRevisionFromArchiveRow_legacyEncoding()
\MediaWiki\Storage\RevisionStore::newRevisionFromArchiveRow
testGetKnownCurrentRevision()
\MediaWiki\Storage\RevisionStore::getKnownCurrentRevision
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
testLoadRevisionFromTimestamp()
\MediaWiki\Storage\RevisionStore::loadRevisionFromTimestamp
testNewMutableRevisionFromArray(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
testGetRevisionByTitle()
\MediaWiki\Storage\RevisionStore::getRevisionByTitle
testDomainCheck( $wikiId, $dbName, $dbPrefix)
provideDomainCheck \MediaWiki\Storage\RevisionStore::checkDatabaseWikiId
testNewNullRevision(Title $title, $comment, $minor)
provideNewNullRevision \MediaWiki\Storage\RevisionStore::newNullRevision
testGetRcIdIfUnpatrolled_returnsRecentChangesId()
\MediaWiki\Storage\RevisionStore::getRcIdIfUnpatrolled
testGetRecentChange()
\MediaWiki\Storage\RevisionStore::getRecentChange
assertRevisionRecordMatchesRevision(Revision $rev, RevisionRecord $record)
assertLinkTargetsEqual(LinkTarget $l1, LinkTarget $l2)
testNewRevisionFromRow_anonEdit()
\MediaWiki\Storage\RevisionStore::newRevisionFromRow \MediaWiki\Storage\RevisionStore::newRevisionFro...
getTitle()
Returns the title of the page associated with this entry.
Definition Revision.php:734
static getMutableTestUser( $testName, $groups=[])
Get a TestUser object that the caller may modify.
Represents a title within MediaWiki.
Definition Title.php:39
Multi-datacenter aware caching interface.
Class representing a MediaWiki article and history.
Definition WikiPage.php:37
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:115
Relational database abstraction object.
Definition Database.php:48
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Database connection, tracking, load balancing, and transaction manager for a cluster.
Helper class that detects high-contention DB queries via profiling calls.
Content object for wiki text pages.
$res
Definition database.txt:21
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. '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
Definition hooks.txt:1051
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
Definition hooks.txt:181
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
Definition hooks.txt:1777
const MIGRATION_WRITE_BOTH
Definition Defines.php:303
$cache
Definition mcc.php:33
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:29
$params