MediaWiki  master
RevisionStoreDbTestBase.php
Go to the documentation of this file.
1 <?php
2 
4 
28 use Title;
38 
44 
48  private $testPageTitle;
49 
53  private $testPage;
54 
58  abstract protected function getMcrMigrationStage();
59 
63  protected function getContentHandlerUseDB() {
64  return true;
65  }
66 
70  abstract protected function getMcrTablesToReset();
71 
72  public function setUp() {
73  parent::setUp();
74  $this->tablesUsed[] = 'archive';
75  $this->tablesUsed[] = 'page';
76  $this->tablesUsed[] = 'revision';
77  $this->tablesUsed[] = 'comment';
78 
79  $this->tablesUsed += $this->getMcrTablesToReset();
80 
81  $this->setMwGlobals( [
82  'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(),
83  'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
84  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
85  ] );
86 
87  $this->overrideMwServices();
88  }
89 
90  protected function addCoreDBData() {
91  // Blank out. This would fail with a modified schema, and we don't need it.
92  }
93 
97  protected function getTestPageTitle() {
98  if ( $this->testPageTitle ) {
99  return $this->testPageTitle;
100  }
101 
102  $this->testPageTitle = Title::newFromText( 'UTPage-' . __CLASS__ );
103  return $this->testPageTitle;
104  }
105 
109  protected function getTestPage() {
110  if ( $this->testPage ) {
111  return $this->testPage;
112  }
113 
114  $title = $this->getTestPageTitle();
115  $this->testPage = WikiPage::factory( $title );
116 
117  if ( !$this->testPage->exists() ) {
118  // Make sure we don't write to the live db.
119  $this->ensureMockDatabaseConnection( wfGetDB( DB_MASTER ) );
120 
121  $user = static::getTestSysop()->getUser();
122 
123  $this->testPage->doEditContent(
124  new WikitextContent( 'UTContent-' . __CLASS__ ),
125  'UTPageSummary-' . __CLASS__,
127  false,
128  $user
129  );
130  }
131 
132  return $this->testPage;
133  }
134 
138  private function getLoadBalancerMock( array $server ) {
139  $domain = new DatabaseDomain( $server['dbname'], null, $server['tablePrefix'] );
140 
141  $lb = $this->getMockBuilder( LoadBalancer::class )
142  ->setMethods( [ 'reallyOpenConnection' ] )
143  ->setConstructorArgs( [
144  [ 'servers' => [ $server ], 'localDomain' => $domain ]
145  ] )
146  ->getMock();
147 
148  $lb->method( 'reallyOpenConnection' )->willReturnCallback(
149  function ( array $server, $dbNameOverride ) {
150  return $this->getDatabaseMock( $server );
151  }
152  );
153 
154  return $lb;
155  }
156 
160  private function getDatabaseMock( array $params ) {
161  $db = $this->getMockBuilder( DatabaseSqlite::class )
162  ->setMethods( [ 'select', 'doQuery', 'open', 'closeConnection', 'isOpen' ] )
163  ->setConstructorArgs( [ $params ] )
164  ->getMock();
165 
166  $db->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
167  $db->method( 'isOpen' )->willReturn( true );
168 
169  return $db;
170  }
171 
172  public function provideDomainCheck() {
173  yield [ false, 'test', '' ];
174  yield [ 'test', 'test', '' ];
175 
176  yield [ false, 'test', 'foo_' ];
177  yield [ 'test-foo_', 'test', 'foo_' ];
178 
179  yield [ false, 'dash-test', '' ];
180  yield [ 'dash-test', 'dash-test', '' ];
181 
182  yield [ false, 'underscore_test', 'foo_' ];
183  yield [ 'underscore_test-foo_', 'underscore_test', 'foo_' ];
184  }
185 
190  public function testDomainCheck( $wikiId, $dbName, $dbPrefix ) {
191  $this->setMwGlobals(
192  [
193  'wgDBname' => $dbName,
194  'wgDBprefix' => $dbPrefix,
195  ]
196  );
197 
198  $loadBalancer = $this->getLoadBalancerMock(
199  [
200  'host' => '*dummy*',
201  'dbDirectory' => '*dummy*',
202  'user' => 'test',
203  'password' => 'test',
204  'flags' => 0,
205  'variables' => [],
206  'schema' => '',
207  'cliMode' => true,
208  'agent' => '',
209  'load' => 100,
210  'profiler' => null,
211  'trxProfiler' => new TransactionProfiler(),
212  'connLogger' => new \Psr\Log\NullLogger(),
213  'queryLogger' => new \Psr\Log\NullLogger(),
214  'errorLogger' => function () {
215  },
216  'deprecationLogger' => function () {
217  },
218  'type' => 'test',
219  'dbname' => $dbName,
220  'tablePrefix' => $dbPrefix,
221  ]
222  );
223  $db = $loadBalancer->getConnection( DB_REPLICA );
224 
226  $blobStore = $this->getMockBuilder( SqlBlobStore::class )
227  ->disableOriginalConstructor()
228  ->getMock();
229 
230  $store = new RevisionStore(
231  $loadBalancer,
232  $blobStore,
233  new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
234  MediaWikiServices::getInstance()->getCommentStore(),
235  MediaWikiServices::getInstance()->getContentModelStore(),
236  MediaWikiServices::getInstance()->getSlotRoleStore(),
237  MediaWikiServices::getInstance()->getSlotRoleRegistry(),
238  $this->getMcrMigrationStage(),
239  MediaWikiServices::getInstance()->getActorMigration(),
240  $wikiId
241  );
242 
243  $count = $store->countRevisionsByPageId( $db, 0 );
244 
245  // Dummy check to make PhpUnit happy. We are really only interested in
246  // countRevisionsByPageId not failing due to the DB domain check.
247  $this->assertSame( 0, $count );
248  }
249 
250  protected function assertLinkTargetsEqual( LinkTarget $l1, LinkTarget $l2 ) {
251  $this->assertEquals( $l1->getDBkey(), $l2->getDBkey() );
252  $this->assertEquals( $l1->getNamespace(), $l2->getNamespace() );
253  $this->assertEquals( $l1->getFragment(), $l2->getFragment() );
254  $this->assertEquals( $l1->getInterwiki(), $l2->getInterwiki() );
255  }
256 
258  $this->assertEquals(
259  $r1->getPageAsLinkTarget()->getNamespace(),
260  $r2->getPageAsLinkTarget()->getNamespace()
261  );
262 
263  $this->assertEquals(
264  $r1->getPageAsLinkTarget()->getText(),
265  $r2->getPageAsLinkTarget()->getText()
266  );
267 
268  if ( $r1->getParentId() ) {
269  $this->assertEquals( $r1->getParentId(), $r2->getParentId() );
270  }
271 
272  $this->assertEquals( $r1->getUser()->getName(), $r2->getUser()->getName() );
273  $this->assertEquals( $r1->getUser()->getId(), $r2->getUser()->getId() );
274  $this->assertEquals( $r1->getComment(), $r2->getComment() );
275  $this->assertEquals( $r1->getTimestamp(), $r2->getTimestamp() );
276  $this->assertEquals( $r1->getVisibility(), $r2->getVisibility() );
277  $this->assertEquals( $r1->getSha1(), $r2->getSha1() );
278  $this->assertEquals( $r1->getSize(), $r2->getSize() );
279  $this->assertEquals( $r1->getPageId(), $r2->getPageId() );
280  $this->assertArrayEquals( $r1->getSlotRoles(), $r2->getSlotRoles() );
281  $this->assertEquals( $r1->getWikiId(), $r2->getWikiId() );
282  $this->assertEquals( $r1->isMinor(), $r2->isMinor() );
283  foreach ( $r1->getSlotRoles() as $role ) {
284  $this->assertSlotRecordsEqual( $r1->getSlot( $role ), $r2->getSlot( $role ) );
285  $this->assertTrue( $r1->getContent( $role )->equals( $r2->getContent( $role ) ) );
286  }
287  foreach ( [
292  ] as $field ) {
293  $this->assertEquals( $r1->isDeleted( $field ), $r2->isDeleted( $field ) );
294  }
295  }
296 
297  protected function assertSlotRecordsEqual( SlotRecord $s1, SlotRecord $s2 ) {
298  $this->assertSame( $s1->getRole(), $s2->getRole() );
299  $this->assertSame( $s1->getModel(), $s2->getModel() );
300  $this->assertSame( $s1->getFormat(), $s2->getFormat() );
301  $this->assertSame( $s1->getSha1(), $s2->getSha1() );
302  $this->assertSame( $s1->getSize(), $s2->getSize() );
303  $this->assertTrue( $s1->getContent()->equals( $s2->getContent() ) );
304 
305  $s1->hasRevision() ? $this->assertSame( $s1->getRevision(), $s2->getRevision() ) : null;
306  $s1->hasAddress() ? $this->assertSame( $s1->hasAddress(), $s2->hasAddress() ) : null;
307  }
308 
309  protected function assertRevisionCompleteness( RevisionRecord $r ) {
310  $this->assertTrue( $r->hasSlot( SlotRecord::MAIN ) );
311  $this->assertInstanceOf( SlotRecord::class, $r->getSlot( SlotRecord::MAIN ) );
312  $this->assertInstanceOf( Content::class, $r->getContent( SlotRecord::MAIN ) );
313 
314  foreach ( $r->getSlotRoles() as $role ) {
315  $this->assertSlotCompleteness( $r, $r->getSlot( $role ) );
316  }
317  }
318 
319  protected function assertSlotCompleteness( RevisionRecord $r, SlotRecord $slot ) {
320  $this->assertTrue( $slot->hasAddress() );
321  $this->assertSame( $r->getId(), $slot->getRevision() );
322 
323  $this->assertInstanceOf( Content::class, $slot->getContent() );
324  }
325 
331  private function getRevisionRecordFromDetailsArray( $details = [] ) {
332  // Convert some values that can't be provided by dataProviders
333  if ( isset( $details['user'] ) && $details['user'] === true ) {
334  $details['user'] = $this->getTestUser()->getUser();
335  }
336  if ( isset( $details['page'] ) && $details['page'] === true ) {
337  $details['page'] = $this->getTestPage()->getId();
338  }
339  if ( isset( $details['parent'] ) && $details['parent'] === true ) {
340  $details['parent'] = $this->getTestPage()->getLatest();
341  }
342 
343  // Create the RevisionRecord with any available data
344  $rev = new MutableRevisionRecord( $this->getTestPageTitle() );
345  isset( $details['slot'] ) ? $rev->setSlot( $details['slot'] ) : null;
346  isset( $details['parent'] ) ? $rev->setParentId( $details['parent'] ) : null;
347  isset( $details['page'] ) ? $rev->setPageId( $details['page'] ) : null;
348  isset( $details['size'] ) ? $rev->setSize( $details['size'] ) : null;
349  isset( $details['sha1'] ) ? $rev->setSha1( $details['sha1'] ) : null;
350  isset( $details['comment'] ) ? $rev->setComment( $details['comment'] ) : null;
351  isset( $details['timestamp'] ) ? $rev->setTimestamp( $details['timestamp'] ) : null;
352  isset( $details['minor'] ) ? $rev->setMinorEdit( $details['minor'] ) : null;
353  isset( $details['user'] ) ? $rev->setUser( $details['user'] ) : null;
354  isset( $details['visibility'] ) ? $rev->setVisibility( $details['visibility'] ) : null;
355  isset( $details['id'] ) ? $rev->setId( $details['id'] ) : null;
356 
357  if ( isset( $details['content'] ) ) {
358  foreach ( $details['content'] as $role => $content ) {
359  $rev->setContent( $role, $content );
360  }
361  }
362 
363  return $rev;
364  }
365 
367  yield 'Bare minimum revision insertion' => [
368  [
369  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
370  'page' => true,
371  'comment' => $this->getRandomCommentStoreComment(),
372  'timestamp' => '20171117010101',
373  'user' => true,
374  ],
375  ];
376  yield 'Detailed revision insertion' => [
377  [
378  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
379  'parent' => true,
380  'page' => true,
381  'comment' => $this->getRandomCommentStoreComment(),
382  'timestamp' => '20171117010101',
383  'user' => true,
384  'minor' => true,
385  'visibility' => RevisionRecord::DELETED_RESTRICTED,
386  ],
387  ];
388  }
389 
390  protected function getRandomCommentStoreComment() {
391  return CommentStoreComment::newUnsavedComment( __METHOD__ . '.' . rand( 0, 1000 ) );
392  }
393 
401  array $revDetails = []
402  ) {
403  $title = $this->getTestPageTitle();
404  $rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
405 
406  $this->overrideMwServices();
407  $store = MediaWikiServices::getInstance()->getRevisionStore();
408  $return = $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER ) );
409 
410  // is the new revision correct?
411  $this->assertRevisionCompleteness( $return );
412  $this->assertLinkTargetsEqual( $title, $return->getPageAsLinkTarget() );
413  $this->assertRevisionRecordsEqual( $rev, $return );
414 
415  // can we load it from the store?
416  $loaded = $store->getRevisionById( $return->getId() );
417  $this->assertRevisionCompleteness( $loaded );
418  $this->assertRevisionRecordsEqual( $return, $loaded );
419 
420  // can we find it directly in the database?
421  $this->assertRevisionExistsInDatabase( $return );
422  }
423 
425  $row = $this->revisionToRow( new Revision( $rev ), [] );
426 
427  // unset nulled fields
428  unset( $row->rev_content_model );
429  unset( $row->rev_content_format );
430 
431  // unset fake fields
432  unset( $row->rev_comment_text );
433  unset( $row->rev_comment_data );
434  unset( $row->rev_comment_cid );
435  unset( $row->rev_comment_id );
436 
437  $store = MediaWikiServices::getInstance()->getRevisionStore();
438  $queryInfo = $store->getQueryInfo( [ 'user' ] );
439 
440  $row = get_object_vars( $row );
441 
442  // Use aliased fields from $queryInfo, e.g. rev_user
443  $keys = array_keys( $row );
444  $keys = array_combine( $keys, $keys );
445  $fields = array_intersect_key( $queryInfo['fields'], $keys ) + $keys;
446 
447  // assertSelect() fails unless the orders match.
448  ksort( $fields );
449  ksort( $row );
450 
451  $this->assertSelect(
452  $queryInfo['tables'],
453  $fields,
454  [ 'rev_id' => $rev->getId() ],
455  [ array_values( $row ) ],
456  [],
457  $queryInfo['joins']
458  );
459  }
460 
465  protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
466  // Assert that the same blob address has been used.
467  $this->assertSame( $a->getAddress(), $b->getAddress() );
468  }
469 
474  $title = $this->getTestPageTitle();
475  $revDetails = [
476  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
477  'parent' => true,
478  'comment' => $this->getRandomCommentStoreComment(),
479  'timestamp' => '20171117010101',
480  'user' => true,
481  ];
482 
483  $this->overrideMwServices();
484  $store = MediaWikiServices::getInstance()->getRevisionStore();
485 
486  // Insert the first revision
487  $revOne = $this->getRevisionRecordFromDetailsArray( $revDetails );
488  $firstReturn = $store->insertRevisionOn( $revOne, wfGetDB( DB_MASTER ) );
489  $this->assertLinkTargetsEqual( $title, $firstReturn->getPageAsLinkTarget() );
490  $this->assertRevisionRecordsEqual( $revOne, $firstReturn );
491 
492  // Insert a second revision inheriting the same blob address
493  $revDetails['slot'] = SlotRecord::newInherited( $firstReturn->getSlot( SlotRecord::MAIN ) );
494  $revTwo = $this->getRevisionRecordFromDetailsArray( $revDetails );
495  $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_MASTER ) );
496  $this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
497  $this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
498 
499  $firstMainSlot = $firstReturn->getSlot( SlotRecord::MAIN );
500  $secondMainSlot = $secondReturn->getSlot( SlotRecord::MAIN );
501 
502  $this->assertSameSlotContent( $firstMainSlot, $secondMainSlot );
503 
504  // And that different revisions have been created.
505  $this->assertNotSame( $firstReturn->getId(), $secondReturn->getId() );
506 
507  // Make sure the slot rows reference the correct revision
508  $this->assertSame( $firstReturn->getId(), $firstMainSlot->getRevision() );
509  $this->assertSame( $secondReturn->getId(), $secondMainSlot->getRevision() );
510  }
511 
513  yield 'no slot' => [
514  [
515  'comment' => $this->getRandomCommentStoreComment(),
516  'timestamp' => '20171117010101',
517  'user' => true,
518  ],
519  new InvalidArgumentException( 'main slot must be provided' )
520  ];
521  yield 'no main slot' => [
522  [
523  'slot' => SlotRecord::newUnsaved( 'aux', new WikitextContent( 'Turkey' ) ),
524  'comment' => $this->getRandomCommentStoreComment(),
525  'timestamp' => '20171117010101',
526  'user' => true,
527  ],
528  new InvalidArgumentException( 'main slot must be provided' )
529  ];
530  yield 'no timestamp' => [
531  [
532  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
533  'comment' => $this->getRandomCommentStoreComment(),
534  'user' => true,
535  ],
536  new IncompleteRevisionException( 'timestamp field must not be NULL!' )
537  ];
538  yield 'no comment' => [
539  [
540  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
541  'timestamp' => '20171117010101',
542  'user' => true,
543  ],
544  new IncompleteRevisionException( 'comment must not be NULL!' )
545  ];
546  yield 'no user' => [
547  [
548  'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
549  'comment' => $this->getRandomCommentStoreComment(),
550  'timestamp' => '20171117010101',
551  ],
552  new IncompleteRevisionException( 'user must not be NULL!' )
553  ];
554  }
555 
561  array $revDetails = [],
562  Exception $exception
563  ) {
564  $rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
565 
566  $store = MediaWikiServices::getInstance()->getRevisionStore();
567 
568  $this->setExpectedException(
569  get_class( $exception ),
570  $exception->getMessage(),
571  $exception->getCode()
572  );
573  $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER ) );
574  }
575 
576  public function provideNewNullRevision() {
577  yield [
578  Title::newFromText( 'UTPage_notAutoCreated' ),
579  [ 'content' => [ 'main' => new WikitextContent( 'Flubber1' ) ] ],
580  CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment1' ),
581  true,
582  ];
583  yield [
584  Title::newFromText( 'UTPage_notAutoCreated' ),
585  [ 'content' => [ 'main' => new WikitextContent( 'Flubber2' ) ] ],
586  CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment2', [ 'a' => 1 ] ),
587  false,
588  ];
589  }
590 
596  public function testNewNullRevision( Title $title, $revDetails, $comment, $minor = false ) {
597  $this->overrideMwServices();
598 
599  $user = TestUserRegistry::getMutableTestUser( __METHOD__ )->getUser();
600  $page = WikiPage::factory( $title );
601 
602  if ( !$page->exists() ) {
603  $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__, EDIT_NEW );
604  }
605 
606  $revDetails['page'] = $page->getId();
607  $revDetails['timestamp'] = wfTimestampNow();
608  $revDetails['comment'] = CommentStoreComment::newUnsavedComment( 'Base' );
609  $revDetails['user'] = $user;
610 
611  $baseRev = $this->getRevisionRecordFromDetailsArray( $revDetails );
612  $store = MediaWikiServices::getInstance()->getRevisionStore();
613 
614  $dbw = wfGetDB( DB_MASTER );
615  $baseRev = $store->insertRevisionOn( $baseRev, $dbw );
616  $page->updateRevisionOn( $dbw, new Revision( $baseRev ), $page->getLatest() );
617 
618  $record = $store->newNullRevision(
619  wfGetDB( DB_MASTER ),
620  $title,
621  $comment,
622  $minor,
623  $user
624  );
625 
626  $this->assertEquals( $title->getNamespace(), $record->getPageAsLinkTarget()->getNamespace() );
627  $this->assertEquals( $title->getDBkey(), $record->getPageAsLinkTarget()->getDBkey() );
628  $this->assertEquals( $comment, $record->getComment() );
629  $this->assertEquals( $minor, $record->isMinor() );
630  $this->assertEquals( $user->getName(), $record->getUser()->getName() );
631  $this->assertEquals( $baseRev->getId(), $record->getParentId() );
632 
633  $this->assertArrayEquals(
634  $baseRev->getSlotRoles(),
635  $record->getSlotRoles()
636  );
637 
638  foreach ( $baseRev->getSlotRoles() as $role ) {
639  $parentSlot = $baseRev->getSlot( $role );
640  $slot = $record->getSlot( $role );
641 
642  $this->assertTrue( $slot->isInherited(), 'isInherited' );
643  $this->assertSame( $parentSlot->getOrigin(), $slot->getOrigin(), 'getOrigin' );
644  $this->assertSameSlotContent( $parentSlot, $slot );
645  }
646  }
647 
652  $store = MediaWikiServices::getInstance()->getRevisionStore();
653  $record = $store->newNullRevision(
654  wfGetDB( DB_MASTER ),
655  Title::newFromText( __METHOD__ . '.iDontExist!' ),
656  CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment' ),
657  false,
658  TestUserRegistry::getMutableTestUser( __METHOD__ )->getUser()
659  );
660  $this->assertNull( $record );
661  }
662 
667  $page = $this->getTestPage();
668  $status = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
670  $rev = $status->value['revision'];
671 
672  $store = MediaWikiServices::getInstance()->getRevisionStore();
673  $revisionRecord = $store->getRevisionById( $rev->getId() );
674  $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
675 
676  $this->assertGreaterThan( 0, $result );
677  $this->assertSame(
678  $store->getRecentChange( $revisionRecord )->getAttribute( 'rc_id' ),
679  $result
680  );
681  }
682 
687  // This assumes that sysops are auto patrolled
688  $sysop = $this->getTestSysop()->getUser();
689  $page = $this->getTestPage();
690  $status = $page->doEditContent(
691  new WikitextContent( __METHOD__ ),
692  __METHOD__,
693  0,
694  false,
695  $sysop
696  );
698  $rev = $status->value['revision'];
699 
700  $store = MediaWikiServices::getInstance()->getRevisionStore();
701  $revisionRecord = $store->getRevisionById( $rev->getId() );
702  $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
703 
704  $this->assertSame( 0, $result );
705  }
706 
710  public function testGetRecentChange() {
711  $page = $this->getTestPage();
712  $content = new WikitextContent( __METHOD__ );
713  $status = $page->doEditContent( $content, __METHOD__ );
715  $rev = $status->value['revision'];
716 
717  $store = MediaWikiServices::getInstance()->getRevisionStore();
718  $revRecord = $store->getRevisionById( $rev->getId() );
719  $recentChange = $store->getRecentChange( $revRecord );
720 
721  $this->assertEquals( $rev->getId(), $recentChange->getAttribute( 'rc_this_oldid' ) );
722  $this->assertEquals( $rev->getRecentChange(), $recentChange );
723  }
724 
728  public function testGetRevisionById() {
729  $page = $this->getTestPage();
730  $content = new WikitextContent( __METHOD__ );
731  $status = $page->doEditContent( $content, __METHOD__ );
733  $rev = $status->value['revision'];
734 
735  $store = MediaWikiServices::getInstance()->getRevisionStore();
736  $revRecord = $store->getRevisionById( $rev->getId() );
737 
738  $this->assertSame( $rev->getId(), $revRecord->getId() );
739  $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
740  $this->assertSame( __METHOD__, $revRecord->getComment()->text );
741  }
742 
746  public function testGetRevisionByTitle() {
747  $page = $this->getTestPage();
748  $content = new WikitextContent( __METHOD__ );
749  $status = $page->doEditContent( $content, __METHOD__ );
751  $rev = $status->value['revision'];
752 
753  $store = MediaWikiServices::getInstance()->getRevisionStore();
754  $revRecord = $store->getRevisionByTitle( $page->getTitle() );
755 
756  $this->assertSame( $rev->getId(), $revRecord->getId() );
757  $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
758  $this->assertSame( __METHOD__, $revRecord->getComment()->text );
759  }
760 
764  public function testGetRevisionByPageId() {
765  $page = $this->getTestPage();
766  $content = new WikitextContent( __METHOD__ );
767  $status = $page->doEditContent( $content, __METHOD__ );
769  $rev = $status->value['revision'];
770 
771  $store = MediaWikiServices::getInstance()->getRevisionStore();
772  $revRecord = $store->getRevisionByPageId( $page->getId() );
773 
774  $this->assertSame( $rev->getId(), $revRecord->getId() );
775  $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
776  $this->assertSame( __METHOD__, $revRecord->getComment()->text );
777  }
778 
782  public function testGetRevisionByTimestamp() {
783  // Make sure there is 1 second between the last revision and the rev we create...
784  // Otherwise we might not get the correct revision and the test may fail...
785  // :(
786  $page = $this->getTestPage();
787  sleep( 1 );
788  $content = new WikitextContent( __METHOD__ );
789  $status = $page->doEditContent( $content, __METHOD__ );
791  $rev = $status->value['revision'];
792 
793  $store = MediaWikiServices::getInstance()->getRevisionStore();
794  $revRecord = $store->getRevisionByTimestamp(
795  $page->getTitle(),
796  $rev->getTimestamp()
797  );
798 
799  $this->assertSame( $rev->getId(), $revRecord->getId() );
800  $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
801  $this->assertSame( __METHOD__, $revRecord->getComment()->text );
802  }
803 
804  protected function revisionToRow( Revision $rev, $options = [ 'page', 'user', 'comment' ] ) {
805  // XXX: the WikiPage object loads another RevisionRecord from the database. Not great.
806  $page = WikiPage::factory( $rev->getTitle() );
807 
808  $fields = [
809  'rev_id' => (string)$rev->getId(),
810  'rev_page' => (string)$rev->getPage(),
811  'rev_timestamp' => $this->db->timestamp( $rev->getTimestamp() ),
812  'rev_user_text' => (string)$rev->getUserText(),
813  'rev_user' => (string)$rev->getUser() ?: null,
814  'rev_minor_edit' => $rev->isMinor() ? '1' : '0',
815  'rev_deleted' => (string)$rev->getVisibility(),
816  'rev_len' => (string)$rev->getSize(),
817  'rev_parent_id' => (string)$rev->getParentId(),
818  'rev_sha1' => (string)$rev->getSha1(),
819  ];
820 
821  if ( in_array( 'page', $options ) ) {
822  $fields += [
823  'page_namespace' => (string)$page->getTitle()->getNamespace(),
824  'page_title' => $page->getTitle()->getDBkey(),
825  'page_id' => (string)$page->getId(),
826  'page_latest' => (string)$page->getLatest(),
827  'page_is_redirect' => $page->isRedirect() ? '1' : '0',
828  'page_len' => (string)$page->getContent()->getSize(),
829  ];
830  }
831 
832  if ( in_array( 'user', $options ) ) {
833  $fields += [
834  'user_name' => (string)$rev->getUserText(),
835  ];
836  }
837 
838  if ( in_array( 'comment', $options ) ) {
839  $fields += [
840  'rev_comment_text' => $rev->getComment(),
841  'rev_comment_data' => null,
842  'rev_comment_cid' => null,
843  ];
844  }
845 
846  if ( $rev->getId() ) {
847  $fields += [
848  'rev_id' => (string)$rev->getId(),
849  ];
850  }
851 
852  return (object)$fields;
853  }
854 
856  Revision $rev,
857  RevisionRecord $record
858  ) {
859  $this->assertSame( $rev->getId(), $record->getId() );
860  $this->assertSame( $rev->getPage(), $record->getPageId() );
861  $this->assertSame( $rev->getTimestamp(), $record->getTimestamp() );
862  $this->assertSame( $rev->getUserText(), $record->getUser()->getName() );
863  $this->assertSame( $rev->getUser(), $record->getUser()->getId() );
864  $this->assertSame( $rev->isMinor(), $record->isMinor() );
865  $this->assertSame( $rev->getVisibility(), $record->getVisibility() );
866  $this->assertSame( $rev->getSize(), $record->getSize() );
871  $expectedParent = $rev->getParentId();
872  if ( $expectedParent === null ) {
873  $expectedParent = 0;
874  }
875  $this->assertSame( $expectedParent, $record->getParentId() );
876  $this->assertSame( $rev->getSha1(), $record->getSha1() );
877  $this->assertSame( $rev->getComment(), $record->getComment()->text );
878  $this->assertSame( $rev->getContentFormat(),
879  $record->getContent( SlotRecord::MAIN )->getDefaultFormat() );
880  $this->assertSame( $rev->getContentModel(), $record->getContent( SlotRecord::MAIN )->getModel() );
881  $this->assertLinkTargetsEqual( $rev->getTitle(), $record->getPageAsLinkTarget() );
882 
883  $revRec = $rev->getRevisionRecord();
884  $revMain = $revRec->getSlot( SlotRecord::MAIN );
885  $recMain = $record->getSlot( SlotRecord::MAIN );
886 
887  $this->assertSame( $revMain->hasOrigin(), $recMain->hasOrigin(), 'hasOrigin' );
888  $this->assertSame( $revMain->hasAddress(), $recMain->hasAddress(), 'hasAddress' );
889  $this->assertSame( $revMain->hasContentId(), $recMain->hasContentId(), 'hasContentId' );
890 
891  if ( $revMain->hasOrigin() ) {
892  $this->assertSame( $revMain->getOrigin(), $recMain->getOrigin(), 'getOrigin' );
893  }
894 
895  if ( $revMain->hasAddress() ) {
896  $this->assertSame( $revMain->getAddress(), $recMain->getAddress(), 'getAddress' );
897  }
898 
899  if ( $revMain->hasContentId() ) {
900  // XXX: the content ID value is ill-defined when SCHEMA_COMPAT_WRITE_BOTH and
901  // SCHEMA_COMPAT_READ_OLD is set, since revision insertion will report the
902  // content ID used with the new schema, while loading the revision from the
903  // old schema will report an emulated ID.
904  if ( $this->getMcrMigrationStage() & SCHEMA_COMPAT_READ_NEW ) {
905  $this->assertSame( $revMain->getContentId(), $recMain->getContentId(), 'getContentId' );
906  }
907  }
908  }
909 
915  $page = $this->getTestPage();
916  $text = __METHOD__ . 'o-ö';
918  $rev = $page->doEditContent(
919  new WikitextContent( $text ),
920  __METHOD__ . 'a'
921  )->value['revision'];
922 
923  $store = MediaWikiServices::getInstance()->getRevisionStore();
924  $info = $store->getQueryInfo();
925  $row = $this->db->selectRow(
926  $info['tables'],
927  $info['fields'],
928  [ 'rev_id' => $rev->getId() ],
929  __METHOD__,
930  [],
931  $info['joins']
932  );
933 
934  $info = $store->getSlotsQueryInfo( [ 'content' ] );
935  $slotRows = $this->db->select(
936  $info['tables'],
937  $info['fields'],
938  $this->getSlotRevisionConditions( $rev->getId() ),
939  __METHOD__,
940  [],
941  $info['joins']
942  );
943 
944  $record = $store->newRevisionFromRowAndSlots(
945  $row,
946  iterator_to_array( $slotRows ),
947  [],
948  $page->getTitle()
949  );
950  $this->assertRevisionRecordMatchesRevision( $rev, $record );
951  $this->assertSame( $text, $rev->getContent()->serialize() );
952  }
953 
960  abstract protected function getSlotRevisionConditions( $revId );
961 
968  $page = $this->getTestPage();
969  $text = __METHOD__ . 'a-ä';
971  $rev = $page->doEditContent(
972  new WikitextContent( $text ),
973  __METHOD__ . 'a'
974  )->value['revision'];
975 
976  $store = MediaWikiServices::getInstance()->getRevisionStore();
977  $info = $store->getQueryInfo();
978  $row = $this->db->selectRow(
979  $info['tables'],
980  $info['fields'],
981  [ 'rev_id' => $rev->getId() ],
982  __METHOD__,
983  [],
984  $info['joins']
985  );
986  $record = $store->newRevisionFromRow(
987  $row,
988  [],
989  $page->getTitle()
990  );
991  $this->assertRevisionRecordMatchesRevision( $rev, $record );
992  $this->assertSame( $text, $rev->getContent()->serialize() );
993  }
994 
1000  $page = $this->getTestPage();
1001  $text = __METHOD__ . 'a-ä';
1003  $rev = $page->doEditContent(
1004  new WikitextContent( $text ),
1005  __METHOD__ . 'a'
1006  )->value['revision'];
1007 
1008  $store = MediaWikiServices::getInstance()->getRevisionStore();
1009  $record = $store->newRevisionFromRow(
1010  $this->revisionToRow( $rev ),
1011  [],
1012  $page->getTitle()
1013  );
1014  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1015  $this->assertSame( $text, $rev->getContent()->serialize() );
1016  }
1017 
1023  $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
1024  $this->overrideMwServices();
1025  $page = $this->getTestPage();
1026  $text = __METHOD__ . 'a-ä';
1028  $rev = $page->doEditContent(
1029  new WikitextContent( $text ),
1030  __METHOD__ . 'a'
1031  )->value['revision'];
1032 
1033  $store = MediaWikiServices::getInstance()->getRevisionStore();
1034  $record = $store->newRevisionFromRow(
1035  $this->revisionToRow( $rev ),
1036  [],
1037  $page->getTitle()
1038  );
1039  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1040  $this->assertSame( $text, $rev->getContent()->serialize() );
1041  }
1042 
1048  $page = $this->getTestPage();
1049  $text = __METHOD__ . 'b-ä';
1051  $rev = $page->doEditContent(
1052  new WikitextContent( $text ),
1053  __METHOD__ . 'b',
1054  0,
1055  false,
1056  $this->getTestUser()->getUser()
1057  )->value['revision'];
1058 
1059  $store = MediaWikiServices::getInstance()->getRevisionStore();
1060  $record = $store->newRevisionFromRow(
1061  $this->revisionToRow( $rev ),
1062  [],
1063  $page->getTitle()
1064  );
1065  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1066  $this->assertSame( $text, $rev->getContent()->serialize() );
1067  }
1068 
1074  $store = MediaWikiServices::getInstance()->getRevisionStore();
1075  $title = Title::newFromText( __METHOD__ );
1076  $text = __METHOD__ . '-bä';
1077  $page = WikiPage::factory( $title );
1079  $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
1080  ->value['revision'];
1081  $page->doDeleteArticle( __METHOD__ );
1082 
1083  $db = wfGetDB( DB_MASTER );
1084  $arQuery = $store->getArchiveQueryInfo();
1085  $res = $db->select(
1086  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1087  __METHOD__, [], $arQuery['joins']
1088  );
1089  $this->assertTrue( is_object( $res ), 'query failed' );
1090 
1091  $row = $res->fetchObject();
1092  $res->free();
1093  $record = $store->newRevisionFromArchiveRow( $row );
1094 
1095  $this->assertRevisionRecordMatchesRevision( $orig, $record );
1096  $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1097  }
1098 
1103  $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
1104  $this->overrideMwServices();
1105  $store = MediaWikiServices::getInstance()->getRevisionStore();
1106  $title = Title::newFromText( __METHOD__ );
1107  $text = __METHOD__ . '-bä';
1108  $page = WikiPage::factory( $title );
1110  $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
1111  ->value['revision'];
1112  $page->doDeleteArticle( __METHOD__ );
1113 
1114  $db = wfGetDB( DB_MASTER );
1115  $arQuery = $store->getArchiveQueryInfo();
1116  $res = $db->select(
1117  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1118  __METHOD__, [], $arQuery['joins']
1119  );
1120  $this->assertTrue( is_object( $res ), 'query failed' );
1121 
1122  $row = $res->fetchObject();
1123  $res->free();
1124  $record = $store->newRevisionFromArchiveRow( $row );
1125 
1126  $this->assertRevisionRecordMatchesRevision( $orig, $record );
1127  $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1128  }
1129 
1134  $store = MediaWikiServices::getInstance()->getRevisionStore();
1135 
1136  $row = (object)[
1137  'ar_id' => '1',
1138  'ar_page_id' => '2',
1139  'ar_namespace' => '0',
1140  'ar_title' => 'Something',
1141  'ar_rev_id' => '2',
1142  'ar_text_id' => '47',
1143  'ar_timestamp' => '20180528192356',
1144  'ar_minor_edit' => '0',
1145  'ar_deleted' => '0',
1146  'ar_len' => '78',
1147  'ar_parent_id' => '0',
1148  'ar_sha1' => 'deadbeef',
1149  'ar_comment_text' => 'whatever',
1150  'ar_comment_data' => null,
1151  'ar_comment_cid' => null,
1152  'ar_user' => '0',
1153  'ar_user_text' => '', // this is the important bit
1154  'ar_actor' => null,
1155  'ar_content_format' => null,
1156  'ar_content_model' => null,
1157  ];
1158 
1159  \Wikimedia\suppressWarnings();
1160  $record = $store->newRevisionFromArchiveRow( $row );
1161  \Wikimedia\suppressWarnings( true );
1162 
1163  $this->assertInstanceOf( RevisionRecord::class, $record );
1164  $this->assertInstanceOf( UserIdentityValue::class, $record->getUser() );
1165  $this->assertSame( 'Unknown user', $record->getUser()->getName() );
1166  }
1167 
1173  $store = MediaWikiServices::getInstance()->getRevisionStore();
1174  $title = Title::newFromText( __METHOD__ );
1175 
1176  $row = (object)[
1177  'rev_id' => '2',
1178  'rev_page' => '2',
1179  'page_namespace' => '0',
1180  'page_title' => $title->getText(),
1181  'rev_text_id' => '47',
1182  'rev_timestamp' => '20180528192356',
1183  'rev_minor_edit' => '0',
1184  'rev_deleted' => '0',
1185  'rev_len' => '78',
1186  'rev_parent_id' => '0',
1187  'rev_sha1' => 'deadbeef',
1188  'rev_comment_text' => 'whatever',
1189  'rev_comment_data' => null,
1190  'rev_comment_cid' => null,
1191  'rev_user' => '0',
1192  'rev_user_text' => '', // this is the important bit
1193  'rev_actor' => null,
1194  'rev_content_format' => null,
1195  'rev_content_model' => null,
1196  ];
1197 
1198  \Wikimedia\suppressWarnings();
1199  $record = $store->newRevisionFromRow( $row, 0, $title );
1200  \Wikimedia\suppressWarnings( true );
1201 
1202  $this->assertNotNull( $record );
1203  $this->assertNotNull( $record->getUser() );
1204  $this->assertNotEmpty( $record->getUser()->getName() );
1205  }
1206 
1210  public function testInsertRevisionOn_archive() {
1211  // This is a round trip test for deletion and undeletion of a
1212  // revision row via the archive table.
1213 
1214  $store = MediaWikiServices::getInstance()->getRevisionStore();
1215  $title = Title::newFromText( __METHOD__ );
1216 
1217  $page = WikiPage::factory( $title );
1219  $page->doEditContent( new WikitextContent( "First" ), __METHOD__ . '-first' );
1220  $origRev = $page->doEditContent( new WikitextContent( "Foo" ), __METHOD__ )
1221  ->value['revision'];
1222  $orig = $origRev->getRevisionRecord();
1223  $page->doDeleteArticle( __METHOD__ );
1224 
1225  // re-create page, so we can later load revisions for it
1226  $page->doEditContent( new WikitextContent( 'Two' ), __METHOD__ );
1227 
1228  $db = wfGetDB( DB_MASTER );
1229  $arQuery = $store->getArchiveQueryInfo();
1230  $row = $db->selectRow(
1231  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1232  __METHOD__, [], $arQuery['joins']
1233  );
1234 
1235  $this->assertNotFalse( $row, 'query failed' );
1236 
1237  $record = $store->newRevisionFromArchiveRow(
1238  $row,
1239  0,
1240  $title,
1241  [ 'page_id' => $title->getArticleID() ]
1242  );
1243 
1244  $restored = $store->insertRevisionOn( $record, $db );
1245 
1246  // is the new revision correct?
1247  $this->assertRevisionCompleteness( $restored );
1248  $this->assertRevisionRecordsEqual( $record, $restored );
1249 
1250  // does the new revision use the original slot?
1251  $recMain = $record->getSlot( SlotRecord::MAIN );
1252  $restMain = $restored->getSlot( SlotRecord::MAIN );
1253  $this->assertSame( $recMain->getAddress(), $restMain->getAddress() );
1254  $this->assertSame( $recMain->getContentId(), $restMain->getContentId() );
1255  $this->assertSame( $recMain->getOrigin(), $restMain->getOrigin() );
1256  $this->assertSame( 'Foo', $restMain->getContent()->serialize() );
1257 
1258  // can we load it from the store?
1259  $loaded = $store->getRevisionById( $restored->getId() );
1260  $this->assertNotNull( $loaded );
1261  $this->assertRevisionCompleteness( $loaded );
1262  $this->assertRevisionRecordsEqual( $restored, $loaded );
1263 
1264  // can we find it directly in the database?
1265  $this->assertRevisionExistsInDatabase( $restored );
1266  }
1267 
1271  public function testLoadRevisionFromId() {
1272  $title = Title::newFromText( __METHOD__ );
1273  $page = WikiPage::factory( $title );
1275  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1276  ->value['revision'];
1277 
1278  $store = MediaWikiServices::getInstance()->getRevisionStore();
1279  $result = $store->loadRevisionFromId( wfGetDB( DB_MASTER ), $rev->getId() );
1281  }
1282 
1286  public function testLoadRevisionFromPageId() {
1287  $title = Title::newFromText( __METHOD__ );
1288  $page = WikiPage::factory( $title );
1290  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1291  ->value['revision'];
1292 
1293  $store = MediaWikiServices::getInstance()->getRevisionStore();
1294  $result = $store->loadRevisionFromPageId( wfGetDB( DB_MASTER ), $page->getId() );
1296  }
1297 
1301  public function testLoadRevisionFromTitle() {
1302  $title = Title::newFromText( __METHOD__ );
1303  $page = WikiPage::factory( $title );
1305  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1306  ->value['revision'];
1307 
1308  $store = MediaWikiServices::getInstance()->getRevisionStore();
1309  $result = $store->loadRevisionFromTitle( wfGetDB( DB_MASTER ), $title );
1311  }
1312 
1316  public function testLoadRevisionFromTimestamp() {
1317  $title = Title::newFromText( __METHOD__ );
1318  $page = WikiPage::factory( $title );
1320  $revOne = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1321  ->value['revision'];
1322  // Sleep to ensure different timestamps... )(evil)
1323  sleep( 1 );
1325  $revTwo = $page->doEditContent( new WikitextContent( __METHOD__ . 'a' ), '' )
1326  ->value['revision'];
1327 
1328  $store = MediaWikiServices::getInstance()->getRevisionStore();
1329  $this->assertNull(
1330  $store->loadRevisionFromTimestamp( wfGetDB( DB_MASTER ), $title, '20150101010101' )
1331  );
1332  $this->assertSame(
1333  $revOne->getId(),
1334  $store->loadRevisionFromTimestamp(
1335  wfGetDB( DB_MASTER ),
1336  $title,
1337  $revOne->getTimestamp()
1338  )->getId()
1339  );
1340  $this->assertSame(
1341  $revTwo->getId(),
1342  $store->loadRevisionFromTimestamp(
1343  wfGetDB( DB_MASTER ),
1344  $title,
1345  $revTwo->getTimestamp()
1346  )->getId()
1347  );
1348  }
1349 
1353  public function testGetParentLengths() {
1354  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1356  $revOne = $page->doEditContent(
1357  new WikitextContent( __METHOD__ ), __METHOD__
1358  )->value['revision'];
1360  $revTwo = $page->doEditContent(
1361  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1362  )->value['revision'];
1363 
1364  $store = MediaWikiServices::getInstance()->getRevisionStore();
1365  $this->assertSame(
1366  [
1367  $revOne->getId() => strlen( __METHOD__ ),
1368  ],
1369  $store->listRevisionSizes(
1370  wfGetDB( DB_MASTER ),
1371  [ $revOne->getId() ]
1372  )
1373  );
1374  $this->assertSame(
1375  [
1376  $revOne->getId() => strlen( __METHOD__ ),
1377  $revTwo->getId() => strlen( __METHOD__ ) + 1,
1378  ],
1379  $store->listRevisionSizes(
1380  wfGetDB( DB_MASTER ),
1381  [ $revOne->getId(), $revTwo->getId() ]
1382  )
1383  );
1384  }
1385 
1389  public function testGetPreviousRevision() {
1390  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1392  $revOne = $page->doEditContent(
1393  new WikitextContent( __METHOD__ ), __METHOD__
1394  )->value['revision'];
1396  $revTwo = $page->doEditContent(
1397  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1398  )->value['revision'];
1399 
1400  $store = MediaWikiServices::getInstance()->getRevisionStore();
1401  $this->assertNull(
1402  $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
1403  );
1404  $this->assertSame(
1405  $revOne->getId(),
1406  $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
1407  );
1408  }
1409 
1413  public function testGetNextRevision() {
1414  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1416  $revOne = $page->doEditContent(
1417  new WikitextContent( __METHOD__ ), __METHOD__
1418  )->value['revision'];
1420  $revTwo = $page->doEditContent(
1421  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1422  )->value['revision'];
1423 
1424  $store = MediaWikiServices::getInstance()->getRevisionStore();
1425  $this->assertSame(
1426  $revTwo->getId(),
1427  $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
1428  );
1429  $this->assertNull(
1430  $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
1431  );
1432  }
1433 
1434  public function provideNonHistoryRevision() {
1435  $title = Title::newFromText( __METHOD__ );
1437  yield [ $rev ];
1438 
1439  $user = new UserIdentityValue( 7, 'Frank', 0 );
1440  $comment = CommentStoreComment::newUnsavedComment( 'Test' );
1441  $row = (object)[
1442  'ar_id' => 3,
1443  'ar_rev_id' => 34567,
1444  'ar_page_id' => 5,
1445  'ar_deleted' => 0,
1446  'ar_minor_edit' => 0,
1447  'ar_timestamp' => '20180101020202',
1448  ];
1449  $slots = new RevisionSlots( [] );
1450  $rev = new RevisionArchiveRecord( $title, $user, $comment, $row, $slots );
1451  yield [ $rev ];
1452  }
1453 
1459  $store = MediaWikiServices::getInstance()->getRevisionStore();
1460  $this->assertNull( $store->getPreviousRevision( $rev ) );
1461  }
1462 
1468  $store = MediaWikiServices::getInstance()->getRevisionStore();
1469  $this->assertNull( $store->getNextRevision( $rev ) );
1470  }
1471 
1475  public function testGetTimestampFromId_found() {
1476  $page = $this->getTestPage();
1478  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1479  ->value['revision'];
1480 
1481  $store = MediaWikiServices::getInstance()->getRevisionStore();
1482  $result = $store->getTimestampFromId( $rev->getId() );
1483 
1484  $this->assertSame( $rev->getTimestamp(), $result );
1485  }
1486 
1491  $page = $this->getTestPage();
1493  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1494  ->value['revision'];
1495 
1496  $store = MediaWikiServices::getInstance()->getRevisionStore();
1497  $result = $store->getTimestampFromId( $rev->getId() + 1 );
1498 
1499  $this->assertFalse( $result );
1500  }
1501 
1505  public function testCountRevisionsByPageId() {
1506  $store = MediaWikiServices::getInstance()->getRevisionStore();
1507  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1508 
1509  $this->assertSame(
1510  0,
1511  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1512  );
1513  $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1514  $this->assertSame(
1515  1,
1516  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1517  );
1518  $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1519  $this->assertSame(
1520  2,
1521  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1522  );
1523  }
1524 
1528  public function testCountRevisionsByTitle() {
1529  $store = MediaWikiServices::getInstance()->getRevisionStore();
1530  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1531 
1532  $this->assertSame(
1533  0,
1534  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1535  );
1536  $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1537  $this->assertSame(
1538  1,
1539  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1540  );
1541  $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1542  $this->assertSame(
1543  2,
1544  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1545  );
1546  }
1547 
1551  public function testUserWasLastToEdit_false() {
1552  $sysop = $this->getTestSysop()->getUser();
1553  $page = $this->getTestPage();
1554  $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
1555 
1556  $store = MediaWikiServices::getInstance()->getRevisionStore();
1557  $result = $store->userWasLastToEdit(
1558  wfGetDB( DB_MASTER ),
1559  $page->getId(),
1560  $sysop->getId(),
1561  '20160101010101'
1562  );
1563  $this->assertFalse( $result );
1564  }
1565 
1569  public function testUserWasLastToEdit_true() {
1570  $startTime = wfTimestampNow();
1571  $sysop = $this->getTestSysop()->getUser();
1572  $page = $this->getTestPage();
1573  $page->doEditContent(
1574  new WikitextContent( __METHOD__ ),
1575  __METHOD__,
1576  0,
1577  false,
1578  $sysop
1579  );
1580 
1581  $store = MediaWikiServices::getInstance()->getRevisionStore();
1582  $result = $store->userWasLastToEdit(
1583  wfGetDB( DB_MASTER ),
1584  $page->getId(),
1585  $sysop->getId(),
1586  $startTime
1587  );
1588  $this->assertTrue( $result );
1589  }
1590 
1594  public function testGetKnownCurrentRevision() {
1595  $page = $this->getTestPage();
1597  $rev = $page->doEditContent(
1598  new WikitextContent( __METHOD__ . 'b' ),
1599  __METHOD__ . 'b',
1600  0,
1601  false,
1602  $this->getTestUser()->getUser()
1603  )->value['revision'];
1604 
1605  $store = MediaWikiServices::getInstance()->getRevisionStore();
1606  $record = $store->getKnownCurrentRevision(
1607  $page->getTitle(),
1608  $rev->getId()
1609  );
1610 
1611  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1612  }
1613 
1615  yield 'Basic array, content object' => [
1616  [
1617  'id' => 2,
1618  'page' => 1,
1619  'timestamp' => '20171017114835',
1620  'user_text' => '111.0.1.2',
1621  'user' => 0,
1622  'minor_edit' => false,
1623  'deleted' => 0,
1624  'len' => 46,
1625  'parent_id' => 1,
1626  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1627  'comment' => 'Goat Comment!',
1628  'content' => new WikitextContent( 'Some Content' ),
1629  ]
1630  ];
1631  yield 'Basic array, serialized text' => [
1632  [
1633  'id' => 2,
1634  'page' => 1,
1635  'timestamp' => '20171017114835',
1636  'user_text' => '111.0.1.2',
1637  'user' => 0,
1638  'minor_edit' => false,
1639  'deleted' => 0,
1640  'len' => 46,
1641  'parent_id' => 1,
1642  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1643  'comment' => 'Goat Comment!',
1644  'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1645  ]
1646  ];
1647  yield 'Basic array, serialized text, utf-8 flags' => [
1648  [
1649  'id' => 2,
1650  'page' => 1,
1651  'timestamp' => '20171017114835',
1652  'user_text' => '111.0.1.2',
1653  'user' => 0,
1654  'minor_edit' => false,
1655  'deleted' => 0,
1656  'len' => 46,
1657  'parent_id' => 1,
1658  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1659  'comment' => 'Goat Comment!',
1660  'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1661  'flags' => 'utf-8',
1662  ]
1663  ];
1664  yield 'Basic array, with title' => [
1665  [
1666  'title' => Title::newFromText( 'SomeText' ),
1667  'timestamp' => '20171017114835',
1668  'user_text' => '111.0.1.2',
1669  'user' => 0,
1670  'minor_edit' => false,
1671  'deleted' => 0,
1672  'len' => 46,
1673  'parent_id' => 1,
1674  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1675  'comment' => 'Goat Comment!',
1676  'content' => new WikitextContent( 'Some Content' ),
1677  ]
1678  ];
1679  yield 'Basic array, no user field' => [
1680  [
1681  'id' => 2,
1682  'page' => 1,
1683  'timestamp' => '20171017114835',
1684  'user_text' => '111.0.1.3',
1685  'minor_edit' => false,
1686  'deleted' => 0,
1687  'len' => 46,
1688  'parent_id' => 1,
1689  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1690  'comment' => 'Goat Comment!',
1691  'content' => new WikitextContent( 'Some Content' ),
1692  ]
1693  ];
1694  }
1695 
1700  public function testNewMutableRevisionFromArray( array $array ) {
1701  $store = MediaWikiServices::getInstance()->getRevisionStore();
1702 
1703  // HACK: if $array['page'] is given, make sure that the page exists
1704  if ( isset( $array['page'] ) ) {
1705  $t = Title::newFromID( $array['page'] );
1706  if ( !$t || !$t->exists() ) {
1707  $t = Title::makeTitle( NS_MAIN, __METHOD__ );
1708  $info = $this->insertPage( $t );
1709  $array['page'] = $info['id'];
1710  }
1711  }
1712 
1713  $result = $store->newMutableRevisionFromArray( $array );
1714 
1715  if ( isset( $array['id'] ) ) {
1716  $this->assertSame( $array['id'], $result->getId() );
1717  }
1718  if ( isset( $array['page'] ) ) {
1719  $this->assertSame( $array['page'], $result->getPageId() );
1720  }
1721  $this->assertSame( $array['timestamp'], $result->getTimestamp() );
1722  $this->assertSame( $array['user_text'], $result->getUser()->getName() );
1723  if ( isset( $array['user'] ) ) {
1724  $this->assertSame( $array['user'], $result->getUser()->getId() );
1725  }
1726  $this->assertSame( (bool)$array['minor_edit'], $result->isMinor() );
1727  $this->assertSame( $array['deleted'], $result->getVisibility() );
1728  $this->assertSame( $array['len'], $result->getSize() );
1729  $this->assertSame( $array['parent_id'], $result->getParentId() );
1730  $this->assertSame( $array['sha1'], $result->getSha1() );
1731  $this->assertSame( $array['comment'], $result->getComment()->text );
1732  if ( isset( $array['content'] ) ) {
1733  foreach ( $array['content'] as $role => $content ) {
1734  $this->assertTrue(
1735  $result->getContent( $role )->equals( $content )
1736  );
1737  }
1738  } elseif ( isset( $array['text'] ) ) {
1739  $this->assertSame( $array['text'],
1740  $result->getSlot( SlotRecord::MAIN )->getContent()->serialize() );
1741  } elseif ( isset( $array['content_format'] ) ) {
1742  $this->assertSame(
1743  $array['content_format'],
1744  $result->getSlot( SlotRecord::MAIN )->getContent()->getDefaultFormat()
1745  );
1746  $this->assertSame( $array['content_model'], $result->getSlot( SlotRecord::MAIN )->getModel() );
1747  }
1748  }
1749 
1754  public function testNewMutableRevisionFromArray_legacyEncoding( array $array ) {
1755  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1757  $lb = $services->getDBLoadBalancer();
1758  $access = $services->getExternalStoreAccess();
1759  $blobStore = new SqlBlobStore( $lb, $access, $cache );
1760  $blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
1761 
1762  $factory = $this->getMockBuilder( BlobStoreFactory::class )
1763  ->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
1764  ->disableOriginalConstructor()
1765  ->getMock();
1766  $factory->expects( $this->any() )
1767  ->method( 'newBlobStore' )
1768  ->willReturn( $blobStore );
1769  $factory->expects( $this->any() )
1770  ->method( 'newSqlBlobStore' )
1771  ->willReturn( $blobStore );
1772 
1773  $this->setService( 'BlobStoreFactory', $factory );
1774 
1775  $this->testNewMutableRevisionFromArray( $array );
1776  }
1777 
1785  private function createRevisionStoreCacheRecord( $page, $store ) {
1786  $user = MediaWikiTestCase::getMutableTestUser()->getUser();
1787  $updater = $page->newPageUpdater( $user );
1788  $updater->setContent( SlotRecord::MAIN, new WikitextContent( __METHOD__ ) );
1789  $summary = CommentStoreComment::newUnsavedComment( __METHOD__ );
1790  $rev = $updater->saveRevision( $summary, EDIT_NEW );
1791  return $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1792  }
1793 
1799 
1800  $this->overrideMwServices();
1801  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1802  $this->setService( 'MainWANObjectCache', $cache );
1803 
1804  $store = MediaWikiServices::getInstance()->getRevisionStore();
1805  $page = $this->getNonexistingTestPage();
1806  $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1807 
1808  // Grab the user name
1809  $userNameBefore = $rev->getUser()->getName();
1810 
1811  // Change the user name in the database, "behind the back" of the cache
1812  $newUserName = "Renamed $userNameBefore";
1813  $this->db->update( 'revision',
1814  [ 'rev_user_text' => $newUserName ],
1815  [ 'rev_id' => $rev->getId() ] );
1816  $this->db->update( 'user',
1817  [ 'user_name' => $newUserName ],
1818  [ 'user_id' => $rev->getUser()->getId() ] );
1819  if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
1820  $this->db->update( 'actor',
1821  [ 'actor_name' => $newUserName ],
1822  [ 'actor_user' => $rev->getUser()->getId() ] );
1823  }
1824 
1825  // Reload the revision and regrab the user name.
1826  $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1827  $userNameAfter = $revAfter->getUser()->getName();
1828 
1829  // The two user names should be different.
1830  // If they are the same, we are seeing a cached value, which is bad.
1831  $this->assertNotSame( $userNameBefore, $userNameAfter );
1832 
1833  // This is implied by the above assertion, but explicitly check it, for completeness
1834  $this->assertSame( $newUserName, $userNameAfter );
1835  }
1836 
1841  $this->overrideMwServices();
1842  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1843  $this->setService( 'MainWANObjectCache', $cache );
1844 
1845  $store = MediaWikiServices::getInstance()->getRevisionStore();
1846  $page = $this->getNonexistingTestPage();
1847  $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1848 
1849  // Grab the deleted bitmask
1850  $deletedBefore = $rev->getVisibility();
1851 
1852  // Change the deleted bitmask in the database, "behind the back" of the cache
1853  $this->db->update( 'revision',
1854  [ 'rev_deleted' => RevisionRecord::DELETED_TEXT ],
1855  [ 'rev_id' => $rev->getId() ] );
1856 
1857  // Reload the revision and regrab the visibility flag.
1858  $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1859  $deletedAfter = $revAfter->getVisibility();
1860 
1861  // The two deleted flags should be different.
1862  // If they are the same, we are seeing a cached value, which is bad.
1863  $this->assertNotSame( $deletedBefore, $deletedAfter );
1864 
1865  // This is implied by the above assertion, but explicitly check it, for completeness
1866  $this->assertSame( RevisionRecord::DELETED_TEXT, $deletedAfter );
1867  }
1868 
1874 
1875  $page = $this->getTestPage();
1876  $text = __METHOD__;
1878  $rev = $page->doEditContent(
1879  new WikitextContent( $text ),
1880  __METHOD__,
1881  0,
1882  false,
1883  $this->getMutableTestUser()->getUser()
1884  )->value['revision'];
1885 
1886  $store = MediaWikiServices::getInstance()->getRevisionStore();
1887  $record = $store->newRevisionFromRow(
1888  $this->revisionToRow( $rev ),
1889  [],
1890  $page->getTitle()
1891  );
1892 
1893  // Grab the user name
1894  $userNameBefore = $record->getUser()->getName();
1895 
1896  // Change the user name in the database
1897  $newUserName = "Renamed $userNameBefore";
1898  $this->db->update( 'revision',
1899  [ 'rev_user_text' => $newUserName ],
1900  [ 'rev_id' => $record->getId() ] );
1901  $this->db->update( 'user',
1902  [ 'user_name' => $newUserName ],
1903  [ 'user_id' => $record->getUser()->getId() ] );
1904  if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
1905  $this->db->update( 'actor',
1906  [ 'actor_name' => $newUserName ],
1907  [ 'actor_user' => $record->getUser()->getId() ] );
1908  }
1909 
1910  // Reload the record, passing $fromCache as true to force fresh info from the db,
1911  // and regrab the user name
1912  $recordAfter = $store->newRevisionFromRow(
1913  $this->revisionToRow( $rev ),
1914  [],
1915  $page->getTitle(),
1916  true
1917  );
1918  $userNameAfter = $recordAfter->getUser()->getName();
1919 
1920  // The two user names should be different.
1921  // If they are the same, we are seeing a cached value, which is bad.
1922  $this->assertNotSame( $userNameBefore, $userNameAfter );
1923 
1924  // This is implied by the above assertion, but explicitly check it, for completeness
1925  $this->assertSame( $newUserName, $userNameAfter );
1926  }
1927 
1932  $page = $this->getTestPage();
1933  $text = __METHOD__;
1935  $rev = $page->doEditContent(
1936  new WikitextContent( $text ),
1937  __METHOD__
1938  )->value['revision'];
1939 
1940  $store = MediaWikiServices::getInstance()->getRevisionStore();
1941  $record = $store->newRevisionFromRow(
1942  $this->revisionToRow( $rev ),
1943  [],
1944  $page->getTitle()
1945  );
1946 
1947  // Grab the deleted bitmask
1948  $deletedBefore = $record->getVisibility();
1949 
1950  // Change the deleted bitmask in the database
1951  $this->db->update( 'revision',
1952  [ 'rev_deleted' => RevisionRecord::DELETED_TEXT ],
1953  [ 'rev_id' => $record->getId() ] );
1954 
1955  // Reload the record, passing $fromCache as true to force fresh info from the db,
1956  // and regrab the deleted bitmask
1957  $recordAfter = $store->newRevisionFromRow(
1958  $this->revisionToRow( $rev ),
1959  [],
1960  $page->getTitle(),
1961  true
1962  );
1963  $deletedAfter = $recordAfter->getVisibility();
1964 
1965  // The two deleted flags should be different, because we modified the database.
1966  $this->assertNotSame( $deletedBefore, $deletedAfter );
1967 
1968  // This is implied by the above assertion, but explicitly check it, for completeness
1969  $this->assertSame( RevisionRecord::DELETED_TEXT, $deletedAfter );
1970  }
1971 
1972 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
testUserWasLastToEdit_false()
\MediaWiki\Revision\RevisionStore::userWasLastToEdit
Helper class that detects high-contention DB queries via profiling calls.
Service for storing and loading Content objects.
getUserText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision&#39;s username if it&#39;s available to the specified audience.
Definition: Revision.php:823
testLoadRevisionFromTitle()
\MediaWiki\Revision\RevisionStore::loadRevisionFromTitle
testGetRcIdIfUnpatrolled_returnsRecentChangesId()
\MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
isMinor()
MCR migration note: this replaces Revision::isMinor.
testNewNullRevision_nonExistingTitle()
\MediaWiki\Revision\RevisionStore::newNullRevision
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:473
const NS_MAIN
Definition: Defines.php:60
getRevisionRecord()
Definition: Revision.php:629
getPage()
Get the page ID.
Definition: Revision.php:782
serialize()
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getTimestamp()
Definition: Revision.php:994
testCountRevisionsByPageId()
\MediaWiki\Revision\RevisionStore::countRevisionsByPageId
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
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
Definition: globals.txt:25
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
testNewRevisionFromRowAndSlot_getQueryInfo()
\MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots \MediaWiki\Revision\RevisionStore::getQ...
testGetRevisionByTimestamp()
\MediaWiki\Revision\RevisionStore::getRevisionByTimestamp
testGetKnownCurrentRevision_userNameChange()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
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:175
testGetKnownCurrentRevision_revDelete()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:267
testGetParentLengths()
\MediaWiki\Revision\RevisionStore::listRevisionSizes
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
testInsertRevisionOn_successes(array $revDetails=[])
provideInsertRevisionOn_successes \MediaWiki\Revision\RevisionStore::insertRevisionOn \MediaWiki\Revi...
Exception throw when trying to access undefined fields on an incomplete RevisionRecord.
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
hasSlot( $role)
Returns whether the given slot is defined in this revision.
testGetNextRevision()
\MediaWiki\Revision\RevisionStore::getNextRevision
testNewNullRevision(Title $title, $revDetails, $comment, $minor=false)
provideNewNullRevision \MediaWiki\Revision\RevisionStore::newNullRevision \MediaWiki\Revision\Revisio...
getSlotRevisionConditions( $revId)
Conditions to use together with getSlotsQueryInfo() when selecting slot rows for a given revision...
static getInstance()
Returns the global default instance of the top level service locator.
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
testNewMutableRevisionFromArray(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray ...
const DB_MASTER
Definition: defines.php:26
testGetPreviousRevision()
\MediaWiki\Revision\RevisionStore::getPreviousRevision
testInsertRevisionOn_archive()
\MediaWiki\Revision\RevisionStore::insertRevisionOn
getNamespace()
Get the namespace index.
createRevisionStoreCacheRecord( $page, $store)
Creates a new revision for testing caching behavior.
getContent()
Returns the Content of the given slot.
Definition: SlotRecord.php:302
testDomainCheck( $wikiId, $dbName, $dbPrefix)
provideDomainCheck \MediaWiki\Revision\RevisionStore::checkDatabaseDomain
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\*-\*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1970
testGetNextRevision_bad(RevisionRecord $rev)
provideNonHistoryRevision \MediaWiki\Revision\RevisionStore::getNextRevision
getModel()
Returns the content model.
Definition: SlotRecord.php:566
getFragment()
Get the link fragment (i.e.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
testNewMutableRevisionFromArray_legacyEncoding(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray ...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1972
testNewRevisionFromRow_getQueryInfo()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::newRevisionF...
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 '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:1244
static newInherited(SlotRecord $slot)
Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a p...
Definition: SlotRecord.php:103
testCountRevisionsByTitle()
\MediaWiki\Revision\RevisionStore::countRevisionsByTitle
getFormat()
Returns the blob serialization format as a MIME type.
Definition: SlotRecord.php:586
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:755
assertSlotCompleteness(RevisionRecord $r, SlotRecord $slot)
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
getParentId()
Get parent revision ID (the original previous page revision)
Definition: Revision.php:717
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision&#39;s user id if it&#39;s available to the specified audience.
Definition: Revision.php:799
getVisibility()
Get the deletion bitfield of the revision.
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2205
testNewRevisionFromRow_userEdit()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::newRevisionF...
getDBkey()
Get the main part with underscores.
Definition: Title.php:1021
getId()
Get revision ID.
Definition: Revision.php:638
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
testLoadRevisionFromTimestamp()
\MediaWiki\Revision\RevisionStore::loadRevisionFromTimestamp
Service for looking up page revisions.
testNewRevisionFromRow_anonEdit()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::newRevisionF...
const SCHEMA_COMPAT_WRITE_NEW
Definition: Defines.php:266
testGetTimestampFromId_notFound()
\MediaWiki\Revision\RevisionStore::getTimestampFromId
$res
Definition: database.txt:21
getContent( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns the Content of the given slot of this revision.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getDBkey()
Get the main part with underscores.
$cache
Definition: mcc.php:33
$params
testInsertRevisionOn_failures(array $revDetails=[], Exception $exception)
provideInsertRevisionOn_failures \MediaWiki\Revision\RevisionStore::insertRevisionOn ...
const EDIT_SUPPRESS_RC
Definition: Defines.php:135
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
Definition: hooks.txt:1972
static getMutableTestUser( $testName, $groups=[])
Get a TestUser object that the caller may modify.
getRevision()
Returns the ID of the revision this slot is associated with.
Definition: SlotRecord.php:396
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: Revision.php:845
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
Value object representing a user&#39;s identity.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:216
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1045
testNewRevisionFromRow_userNameChange()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
testGetKnownCurrentRevision()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
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:1748
A RevisionRecord representing a revision of a deleted page persisted in the archive table...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
getContentModel()
Returns the content model for the main slot of this revision.
Definition: Revision.php:955
testNewRevisionFromRow_revDelete()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
testGetPreviousRevision_bad(RevisionRecord $rev)
provideNonHistoryRevision \MediaWiki\Revision\RevisionStore::getPreviousRevision
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled()
\MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
testNewRevisionFromArchiveRow_legacyEncoding()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
testNewRevisionFromArchiveRow_getArchiveQueryInfo()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow \MediaWiki\Revision\RevisionStore::getAr...
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:897
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
getId()
Get revision ID.
revisionToRow(Revision $rev, $options=[ 'page', 'user', 'comment'])
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getRole()
Returns the role of the slot.
Definition: SlotRecord.php:489
Class to handle database/prefix specification for IDatabase domains.
getSha1()
Returns the content size.
Definition: SlotRecord.php:538
testLoadRevisionFromPageId()
\MediaWiki\Revision\RevisionStore::loadRevisionFromPageId
testGetRevisionById()
\MediaWiki\Revision\RevisionStore::getRevisionById
testNewRevisionFromArchiveRow_no_user()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
hasRevision()
Whether this slot has revision ID associated.
Definition: SlotRecord.php:480
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
testInsertRevisionOn_blobAddressExists()
\MediaWiki\Revision\RevisionStore::insertRevisionOn
const EDIT_NEW
Definition: Defines.php:132
Overloads the relevant methods of the real ResultsWrapper so it doesn&#39;t go anywhere near an actual da...
getSha1()
Returns the base36 sha1 of this revision.
getSize()
Returns the content size.
Definition: SlotRecord.php:522
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
getTimestamp()
MCR migration note: this replaces Revision::getTimestamp.
getAddress()
Returns the address of this slot&#39;s content.
Definition: SlotRecord.php:499
testUserWasLastToEdit_true()
\MediaWiki\Revision\RevisionStore::userWasLastToEdit
const SCHEMA_COMPAT_NEW
Definition: Defines.php:271
getInterwiki()
The interwiki component of this LinkTarget.
testGetRevisionByTitle()
\MediaWiki\Revision\RevisionStore::getRevisionByTitle
getWikiId()
Get the ID of the wiki this revision belongs to.
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
getSize()
Returns the nominal size of this revision, in bogo-bytes.
Page revision base class.
hasAddress()
Whether this slot has an address.
Definition: SlotRecord.php:435
const DB_REPLICA
Definition: defines.php:25
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision&#39;s author&#39;s user identity, if it&#39;s available to the specified audience.
testNewRevisionFromRow_no_user()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::newRevisionF...
testNewRevisionFromRow_anonEdit_legacyEncoding()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::newRevisionF...
testLoadRevisionFromId()
\MediaWiki\Revision\RevisionStore::loadRevisionFromId
Value object representing the set of slots belonging to a revision.
getContentFormat()
Returns the content format for the main slot of this revision.
Definition: Revision.php:970
assertRevisionRecordMatchesRevision(Revision $rev, RevisionRecord $record)
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment, if it&#39;s available to the specified audience.
$content
Definition: pageupdater.txt:72
getSize()
Returns the length of the text in this revision, or null if unknown.
Definition: Revision.php:726
testGetTimestampFromId_found()
\MediaWiki\Revision\RevisionStore::getTimestampFromId
getParentId()
Get parent revision ID (the original previous page revision).
testGetRecentChange()
\MediaWiki\Revision\RevisionStore::getRecentChange
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
Definition: Revision.php:739
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
getPageId()
Get the page ID.
testGetRevisionByPageId()
\MediaWiki\Revision\RevisionStore::getRevisionByPageId
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:322