MediaWiki  1.33.0
RevisionStoreDbTestBase.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Exception;
9 use InvalidArgumentException;
25 use PHPUnit_Framework_MockObject_MockObject;
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.
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  $this->assertSame( $revMain->getContentId(), $recMain->getContentId(), 'getContentId' );
901  }
902  }
903 
909  $page = $this->getTestPage();
910  $text = __METHOD__ . 'a-ä';
912  $rev = $page->doEditContent(
913  new WikitextContent( $text ),
914  __METHOD__ . 'a'
915  )->value['revision'];
916 
917  $store = MediaWikiServices::getInstance()->getRevisionStore();
918  $info = $store->getQueryInfo();
919  $row = $this->db->selectRow(
920  $info['tables'],
921  $info['fields'],
922  [ 'rev_id' => $rev->getId() ],
923  __METHOD__,
924  [],
925  $info['joins']
926  );
927  $record = $store->newRevisionFromRow(
928  $row,
929  [],
930  $page->getTitle()
931  );
932  $this->assertRevisionRecordMatchesRevision( $rev, $record );
933  $this->assertSame( $text, $rev->getContent()->serialize() );
934  }
935 
940  $page = $this->getTestPage();
941  $text = __METHOD__ . 'a-ä';
943  $rev = $page->doEditContent(
944  new WikitextContent( $text ),
945  __METHOD__ . 'a'
946  )->value['revision'];
947 
948  $store = MediaWikiServices::getInstance()->getRevisionStore();
949  $record = $store->newRevisionFromRow(
950  $this->revisionToRow( $rev ),
951  [],
952  $page->getTitle()
953  );
954  $this->assertRevisionRecordMatchesRevision( $rev, $record );
955  $this->assertSame( $text, $rev->getContent()->serialize() );
956  }
957 
962  $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
963  $this->overrideMwServices();
964  $page = $this->getTestPage();
965  $text = __METHOD__ . 'a-ä';
967  $rev = $page->doEditContent(
968  new WikitextContent( $text ),
969  __METHOD__ . 'a'
970  )->value['revision'];
971 
972  $store = MediaWikiServices::getInstance()->getRevisionStore();
973  $record = $store->newRevisionFromRow(
974  $this->revisionToRow( $rev ),
975  [],
976  $page->getTitle()
977  );
978  $this->assertRevisionRecordMatchesRevision( $rev, $record );
979  $this->assertSame( $text, $rev->getContent()->serialize() );
980  }
981 
986  $page = $this->getTestPage();
987  $text = __METHOD__ . 'b-ä';
989  $rev = $page->doEditContent(
990  new WikitextContent( $text ),
991  __METHOD__ . 'b',
992  0,
993  false,
994  $this->getTestUser()->getUser()
995  )->value['revision'];
996 
997  $store = MediaWikiServices::getInstance()->getRevisionStore();
998  $record = $store->newRevisionFromRow(
999  $this->revisionToRow( $rev ),
1000  [],
1001  $page->getTitle()
1002  );
1003  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1004  $this->assertSame( $text, $rev->getContent()->serialize() );
1005  }
1006 
1012  $store = MediaWikiServices::getInstance()->getRevisionStore();
1013  $title = Title::newFromText( __METHOD__ );
1014  $text = __METHOD__ . '-bä';
1015  $page = WikiPage::factory( $title );
1017  $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
1018  ->value['revision'];
1019  $page->doDeleteArticle( __METHOD__ );
1020 
1021  $db = wfGetDB( DB_MASTER );
1022  $arQuery = $store->getArchiveQueryInfo();
1023  $res = $db->select(
1024  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1025  __METHOD__, [], $arQuery['joins']
1026  );
1027  $this->assertTrue( is_object( $res ), 'query failed' );
1028 
1029  $row = $res->fetchObject();
1030  $res->free();
1031  $record = $store->newRevisionFromArchiveRow( $row );
1032 
1033  $this->assertRevisionRecordMatchesRevision( $orig, $record );
1034  $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1035  }
1036 
1041  $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
1042  $this->overrideMwServices();
1043  $store = MediaWikiServices::getInstance()->getRevisionStore();
1044  $title = Title::newFromText( __METHOD__ );
1045  $text = __METHOD__ . '-bä';
1046  $page = WikiPage::factory( $title );
1048  $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__ )
1049  ->value['revision'];
1050  $page->doDeleteArticle( __METHOD__ );
1051 
1052  $db = wfGetDB( DB_MASTER );
1053  $arQuery = $store->getArchiveQueryInfo();
1054  $res = $db->select(
1055  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1056  __METHOD__, [], $arQuery['joins']
1057  );
1058  $this->assertTrue( is_object( $res ), 'query failed' );
1059 
1060  $row = $res->fetchObject();
1061  $res->free();
1062  $record = $store->newRevisionFromArchiveRow( $row );
1063 
1064  $this->assertRevisionRecordMatchesRevision( $orig, $record );
1065  $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
1066  }
1067 
1072  $store = MediaWikiServices::getInstance()->getRevisionStore();
1073 
1074  $row = (object)[
1075  'ar_id' => '1',
1076  'ar_page_id' => '2',
1077  'ar_namespace' => '0',
1078  'ar_title' => 'Something',
1079  'ar_rev_id' => '2',
1080  'ar_text_id' => '47',
1081  'ar_timestamp' => '20180528192356',
1082  'ar_minor_edit' => '0',
1083  'ar_deleted' => '0',
1084  'ar_len' => '78',
1085  'ar_parent_id' => '0',
1086  'ar_sha1' => 'deadbeef',
1087  'ar_comment_text' => 'whatever',
1088  'ar_comment_data' => null,
1089  'ar_comment_cid' => null,
1090  'ar_user' => '0',
1091  'ar_user_text' => '', // this is the important bit
1092  'ar_actor' => null,
1093  'ar_content_format' => null,
1094  'ar_content_model' => null,
1095  ];
1096 
1097  \Wikimedia\suppressWarnings();
1098  $record = $store->newRevisionFromArchiveRow( $row );
1099  \Wikimedia\suppressWarnings( true );
1100 
1101  $this->assertInstanceOf( RevisionRecord::class, $record );
1102  $this->assertInstanceOf( UserIdentityValue::class, $record->getUser() );
1103  $this->assertSame( 'Unknown user', $record->getUser()->getName() );
1104  }
1105 
1110  $store = MediaWikiServices::getInstance()->getRevisionStore();
1111  $title = Title::newFromText( __METHOD__ );
1112 
1113  $row = (object)[
1114  'rev_id' => '2',
1115  'rev_page' => '2',
1116  'page_namespace' => '0',
1117  'page_title' => $title->getText(),
1118  'rev_text_id' => '47',
1119  'rev_timestamp' => '20180528192356',
1120  'rev_minor_edit' => '0',
1121  'rev_deleted' => '0',
1122  'rev_len' => '78',
1123  'rev_parent_id' => '0',
1124  'rev_sha1' => 'deadbeef',
1125  'rev_comment_text' => 'whatever',
1126  'rev_comment_data' => null,
1127  'rev_comment_cid' => null,
1128  'rev_user' => '0',
1129  'rev_user_text' => '', // this is the important bit
1130  'rev_actor' => null,
1131  'rev_content_format' => null,
1132  'rev_content_model' => null,
1133  ];
1134 
1135  \Wikimedia\suppressWarnings();
1136  $record = $store->newRevisionFromRow( $row, 0, $title );
1137  \Wikimedia\suppressWarnings( true );
1138 
1139  $this->assertNotNull( $record );
1140  $this->assertNotNull( $record->getUser() );
1141  $this->assertNotEmpty( $record->getUser()->getName() );
1142  }
1143 
1147  public function testInsertRevisionOn_archive() {
1148  // This is a round trip test for deletion and undeletion of a
1149  // revision row via the archive table.
1150 
1151  $store = MediaWikiServices::getInstance()->getRevisionStore();
1152  $title = Title::newFromText( __METHOD__ );
1153 
1154  $page = WikiPage::factory( $title );
1156  $page->doEditContent( new WikitextContent( "First" ), __METHOD__ . '-first' );
1157  $origRev = $page->doEditContent( new WikitextContent( "Foo" ), __METHOD__ )
1158  ->value['revision'];
1159  $orig = $origRev->getRevisionRecord();
1160  $page->doDeleteArticle( __METHOD__ );
1161 
1162  // re-create page, so we can later load revisions for it
1163  $page->doEditContent( new WikitextContent( 'Two' ), __METHOD__ );
1164 
1165  $db = wfGetDB( DB_MASTER );
1166  $arQuery = $store->getArchiveQueryInfo();
1167  $row = $db->selectRow(
1168  $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1169  __METHOD__, [], $arQuery['joins']
1170  );
1171 
1172  $this->assertNotFalse( $row, 'query failed' );
1173 
1174  $record = $store->newRevisionFromArchiveRow(
1175  $row,
1176  0,
1177  $title,
1178  [ 'page_id' => $title->getArticleID() ]
1179  );
1180 
1181  $restored = $store->insertRevisionOn( $record, $db );
1182 
1183  // is the new revision correct?
1184  $this->assertRevisionCompleteness( $restored );
1185  $this->assertRevisionRecordsEqual( $record, $restored );
1186 
1187  // does the new revision use the original slot?
1188  $recMain = $record->getSlot( SlotRecord::MAIN );
1189  $restMain = $restored->getSlot( SlotRecord::MAIN );
1190  $this->assertSame( $recMain->getAddress(), $restMain->getAddress() );
1191  $this->assertSame( $recMain->getContentId(), $restMain->getContentId() );
1192  $this->assertSame( $recMain->getOrigin(), $restMain->getOrigin() );
1193  $this->assertSame( 'Foo', $restMain->getContent()->serialize() );
1194 
1195  // can we load it from the store?
1196  $loaded = $store->getRevisionById( $restored->getId() );
1197  $this->assertNotNull( $loaded );
1198  $this->assertRevisionCompleteness( $loaded );
1199  $this->assertRevisionRecordsEqual( $restored, $loaded );
1200 
1201  // can we find it directly in the database?
1202  $this->assertRevisionExistsInDatabase( $restored );
1203  }
1204 
1208  public function testLoadRevisionFromId() {
1209  $title = Title::newFromText( __METHOD__ );
1210  $page = WikiPage::factory( $title );
1212  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1213  ->value['revision'];
1214 
1215  $store = MediaWikiServices::getInstance()->getRevisionStore();
1216  $result = $store->loadRevisionFromId( wfGetDB( DB_MASTER ), $rev->getId() );
1218  }
1219 
1223  public function testLoadRevisionFromPageId() {
1224  $title = Title::newFromText( __METHOD__ );
1225  $page = WikiPage::factory( $title );
1227  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1228  ->value['revision'];
1229 
1230  $store = MediaWikiServices::getInstance()->getRevisionStore();
1231  $result = $store->loadRevisionFromPageId( wfGetDB( DB_MASTER ), $page->getId() );
1233  }
1234 
1238  public function testLoadRevisionFromTitle() {
1239  $title = Title::newFromText( __METHOD__ );
1240  $page = WikiPage::factory( $title );
1242  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1243  ->value['revision'];
1244 
1245  $store = MediaWikiServices::getInstance()->getRevisionStore();
1246  $result = $store->loadRevisionFromTitle( wfGetDB( DB_MASTER ), $title );
1248  }
1249 
1253  public function testLoadRevisionFromTimestamp() {
1254  $title = Title::newFromText( __METHOD__ );
1255  $page = WikiPage::factory( $title );
1257  $revOne = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1258  ->value['revision'];
1259  // Sleep to ensure different timestamps... )(evil)
1260  sleep( 1 );
1262  $revTwo = $page->doEditContent( new WikitextContent( __METHOD__ . 'a' ), '' )
1263  ->value['revision'];
1264 
1265  $store = MediaWikiServices::getInstance()->getRevisionStore();
1266  $this->assertNull(
1267  $store->loadRevisionFromTimestamp( wfGetDB( DB_MASTER ), $title, '20150101010101' )
1268  );
1269  $this->assertSame(
1270  $revOne->getId(),
1271  $store->loadRevisionFromTimestamp(
1272  wfGetDB( DB_MASTER ),
1273  $title,
1274  $revOne->getTimestamp()
1275  )->getId()
1276  );
1277  $this->assertSame(
1278  $revTwo->getId(),
1279  $store->loadRevisionFromTimestamp(
1280  wfGetDB( DB_MASTER ),
1281  $title,
1282  $revTwo->getTimestamp()
1283  )->getId()
1284  );
1285  }
1286 
1290  public function testGetParentLengths() {
1291  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1293  $revOne = $page->doEditContent(
1294  new WikitextContent( __METHOD__ ), __METHOD__
1295  )->value['revision'];
1297  $revTwo = $page->doEditContent(
1298  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1299  )->value['revision'];
1300 
1301  $store = MediaWikiServices::getInstance()->getRevisionStore();
1302  $this->assertSame(
1303  [
1304  $revOne->getId() => strlen( __METHOD__ ),
1305  ],
1306  $store->listRevisionSizes(
1307  wfGetDB( DB_MASTER ),
1308  [ $revOne->getId() ]
1309  )
1310  );
1311  $this->assertSame(
1312  [
1313  $revOne->getId() => strlen( __METHOD__ ),
1314  $revTwo->getId() => strlen( __METHOD__ ) + 1,
1315  ],
1316  $store->listRevisionSizes(
1317  wfGetDB( DB_MASTER ),
1318  [ $revOne->getId(), $revTwo->getId() ]
1319  )
1320  );
1321  }
1322 
1326  public function testGetPreviousRevision() {
1327  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1329  $revOne = $page->doEditContent(
1330  new WikitextContent( __METHOD__ ), __METHOD__
1331  )->value['revision'];
1333  $revTwo = $page->doEditContent(
1334  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1335  )->value['revision'];
1336 
1337  $store = MediaWikiServices::getInstance()->getRevisionStore();
1338  $this->assertNull(
1339  $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
1340  );
1341  $this->assertSame(
1342  $revOne->getId(),
1343  $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
1344  );
1345  }
1346 
1350  public function testGetNextRevision() {
1351  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1353  $revOne = $page->doEditContent(
1354  new WikitextContent( __METHOD__ ), __METHOD__
1355  )->value['revision'];
1357  $revTwo = $page->doEditContent(
1358  new WikitextContent( __METHOD__ . '2' ), __METHOD__
1359  )->value['revision'];
1360 
1361  $store = MediaWikiServices::getInstance()->getRevisionStore();
1362  $this->assertSame(
1363  $revTwo->getId(),
1364  $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
1365  );
1366  $this->assertNull(
1367  $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
1368  );
1369  }
1370 
1371  public function provideNonHistoryRevision() {
1372  $title = Title::newFromText( __METHOD__ );
1374  yield [ $rev ];
1375 
1376  $user = new UserIdentityValue( 7, 'Frank', 0 );
1377  $comment = CommentStoreComment::newUnsavedComment( 'Test' );
1378  $row = (object)[
1379  'ar_id' => 3,
1380  'ar_rev_id' => 34567,
1381  'ar_page_id' => 5,
1382  'ar_deleted' => 0,
1383  'ar_minor_edit' => 0,
1384  'ar_timestamp' => '20180101020202',
1385  ];
1386  $slots = new RevisionSlots( [] );
1387  $rev = new RevisionArchiveRecord( $title, $user, $comment, $row, $slots );
1388  yield [ $rev ];
1389  }
1390 
1396  $store = MediaWikiServices::getInstance()->getRevisionStore();
1397  $this->assertNull( $store->getPreviousRevision( $rev ) );
1398  }
1399 
1405  $store = MediaWikiServices::getInstance()->getRevisionStore();
1406  $this->assertNull( $store->getNextRevision( $rev ) );
1407  }
1408 
1412  public function testGetTimestampFromId_found() {
1413  $page = $this->getTestPage();
1415  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1416  ->value['revision'];
1417 
1418  $store = MediaWikiServices::getInstance()->getRevisionStore();
1419  $result = $store->getTimestampFromId(
1420  $page->getTitle(),
1421  $rev->getId()
1422  );
1423 
1424  $this->assertSame( $rev->getTimestamp(), $result );
1425  }
1426 
1431  $page = $this->getTestPage();
1433  $rev = $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ )
1434  ->value['revision'];
1435 
1436  $store = MediaWikiServices::getInstance()->getRevisionStore();
1437  $result = $store->getTimestampFromId(
1438  $page->getTitle(),
1439  $rev->getId() + 1
1440  );
1441 
1442  $this->assertFalse( $result );
1443  }
1444 
1448  public function testCountRevisionsByPageId() {
1449  $store = MediaWikiServices::getInstance()->getRevisionStore();
1450  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1451 
1452  $this->assertSame(
1453  0,
1454  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1455  );
1456  $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1457  $this->assertSame(
1458  1,
1459  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1460  );
1461  $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1462  $this->assertSame(
1463  2,
1464  $store->countRevisionsByPageId( wfGetDB( DB_MASTER ), $page->getId() )
1465  );
1466  }
1467 
1471  public function testCountRevisionsByTitle() {
1472  $store = MediaWikiServices::getInstance()->getRevisionStore();
1473  $page = WikiPage::factory( Title::newFromText( __METHOD__ ) );
1474 
1475  $this->assertSame(
1476  0,
1477  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1478  );
1479  $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1480  $this->assertSame(
1481  1,
1482  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1483  );
1484  $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1485  $this->assertSame(
1486  2,
1487  $store->countRevisionsByTitle( wfGetDB( DB_MASTER ), $page->getTitle() )
1488  );
1489  }
1490 
1494  public function testUserWasLastToEdit_false() {
1495  $sysop = $this->getTestSysop()->getUser();
1496  $page = $this->getTestPage();
1497  $page->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
1498 
1499  $store = MediaWikiServices::getInstance()->getRevisionStore();
1500  $result = $store->userWasLastToEdit(
1501  wfGetDB( DB_MASTER ),
1502  $page->getId(),
1503  $sysop->getId(),
1504  '20160101010101'
1505  );
1506  $this->assertFalse( $result );
1507  }
1508 
1512  public function testUserWasLastToEdit_true() {
1513  $startTime = wfTimestampNow();
1514  $sysop = $this->getTestSysop()->getUser();
1515  $page = $this->getTestPage();
1516  $page->doEditContent(
1517  new WikitextContent( __METHOD__ ),
1518  __METHOD__,
1519  0,
1520  false,
1521  $sysop
1522  );
1523 
1524  $store = MediaWikiServices::getInstance()->getRevisionStore();
1525  $result = $store->userWasLastToEdit(
1526  wfGetDB( DB_MASTER ),
1527  $page->getId(),
1528  $sysop->getId(),
1529  $startTime
1530  );
1531  $this->assertTrue( $result );
1532  }
1533 
1537  public function testGetKnownCurrentRevision() {
1538  $page = $this->getTestPage();
1540  $rev = $page->doEditContent(
1541  new WikitextContent( __METHOD__ . 'b' ),
1542  __METHOD__ . 'b',
1543  0,
1544  false,
1545  $this->getTestUser()->getUser()
1546  )->value['revision'];
1547 
1548  $store = MediaWikiServices::getInstance()->getRevisionStore();
1549  $record = $store->getKnownCurrentRevision(
1550  $page->getTitle(),
1551  $rev->getId()
1552  );
1553 
1554  $this->assertRevisionRecordMatchesRevision( $rev, $record );
1555  }
1556 
1558  yield 'Basic array, content object' => [
1559  [
1560  'id' => 2,
1561  'page' => 1,
1562  'timestamp' => '20171017114835',
1563  'user_text' => '111.0.1.2',
1564  'user' => 0,
1565  'minor_edit' => false,
1566  'deleted' => 0,
1567  'len' => 46,
1568  'parent_id' => 1,
1569  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1570  'comment' => 'Goat Comment!',
1571  'content' => new WikitextContent( 'Some Content' ),
1572  ]
1573  ];
1574  yield 'Basic array, serialized text' => [
1575  [
1576  'id' => 2,
1577  'page' => 1,
1578  'timestamp' => '20171017114835',
1579  'user_text' => '111.0.1.2',
1580  'user' => 0,
1581  'minor_edit' => false,
1582  'deleted' => 0,
1583  'len' => 46,
1584  'parent_id' => 1,
1585  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1586  'comment' => 'Goat Comment!',
1587  'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1588  ]
1589  ];
1590  yield 'Basic array, serialized text, utf-8 flags' => [
1591  [
1592  'id' => 2,
1593  'page' => 1,
1594  'timestamp' => '20171017114835',
1595  'user_text' => '111.0.1.2',
1596  'user' => 0,
1597  'minor_edit' => false,
1598  'deleted' => 0,
1599  'len' => 46,
1600  'parent_id' => 1,
1601  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1602  'comment' => 'Goat Comment!',
1603  'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1604  'flags' => 'utf-8',
1605  ]
1606  ];
1607  yield 'Basic array, with title' => [
1608  [
1609  'title' => Title::newFromText( 'SomeText' ),
1610  'timestamp' => '20171017114835',
1611  'user_text' => '111.0.1.2',
1612  'user' => 0,
1613  'minor_edit' => false,
1614  'deleted' => 0,
1615  'len' => 46,
1616  'parent_id' => 1,
1617  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1618  'comment' => 'Goat Comment!',
1619  'content' => new WikitextContent( 'Some Content' ),
1620  ]
1621  ];
1622  yield 'Basic array, no user field' => [
1623  [
1624  'id' => 2,
1625  'page' => 1,
1626  'timestamp' => '20171017114835',
1627  'user_text' => '111.0.1.3',
1628  'minor_edit' => false,
1629  'deleted' => 0,
1630  'len' => 46,
1631  'parent_id' => 1,
1632  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1633  'comment' => 'Goat Comment!',
1634  'content' => new WikitextContent( 'Some Content' ),
1635  ]
1636  ];
1637  }
1638 
1643  public function testNewMutableRevisionFromArray( array $array ) {
1644  $store = MediaWikiServices::getInstance()->getRevisionStore();
1645 
1646  // HACK: if $array['page'] is given, make sure that the page exists
1647  if ( isset( $array['page'] ) ) {
1648  $t = Title::newFromID( $array['page'] );
1649  if ( !$t || !$t->exists() ) {
1650  $t = Title::makeTitle( NS_MAIN, __METHOD__ );
1651  $info = $this->insertPage( $t );
1652  $array['page'] = $info['id'];
1653  }
1654  }
1655 
1656  $result = $store->newMutableRevisionFromArray( $array );
1657 
1658  if ( isset( $array['id'] ) ) {
1659  $this->assertSame( $array['id'], $result->getId() );
1660  }
1661  if ( isset( $array['page'] ) ) {
1662  $this->assertSame( $array['page'], $result->getPageId() );
1663  }
1664  $this->assertSame( $array['timestamp'], $result->getTimestamp() );
1665  $this->assertSame( $array['user_text'], $result->getUser()->getName() );
1666  if ( isset( $array['user'] ) ) {
1667  $this->assertSame( $array['user'], $result->getUser()->getId() );
1668  }
1669  $this->assertSame( (bool)$array['minor_edit'], $result->isMinor() );
1670  $this->assertSame( $array['deleted'], $result->getVisibility() );
1671  $this->assertSame( $array['len'], $result->getSize() );
1672  $this->assertSame( $array['parent_id'], $result->getParentId() );
1673  $this->assertSame( $array['sha1'], $result->getSha1() );
1674  $this->assertSame( $array['comment'], $result->getComment()->text );
1675  if ( isset( $array['content'] ) ) {
1676  foreach ( $array['content'] as $role => $content ) {
1677  $this->assertTrue(
1678  $result->getContent( $role )->equals( $content )
1679  );
1680  }
1681  } elseif ( isset( $array['text'] ) ) {
1682  $this->assertSame( $array['text'],
1683  $result->getSlot( SlotRecord::MAIN )->getContent()->serialize() );
1684  } elseif ( isset( $array['content_format'] ) ) {
1685  $this->assertSame(
1686  $array['content_format'],
1687  $result->getSlot( SlotRecord::MAIN )->getContent()->getDefaultFormat()
1688  );
1689  $this->assertSame( $array['content_model'], $result->getSlot( SlotRecord::MAIN )->getModel() );
1690  }
1691  }
1692 
1698  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1699  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
1700  $blobStore = new SqlBlobStore( $lb, $cache );
1701  $blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
1702 
1703  $factory = $this->getMockBuilder( BlobStoreFactory::class )
1704  ->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
1705  ->disableOriginalConstructor()
1706  ->getMock();
1707  $factory->expects( $this->any() )
1708  ->method( 'newBlobStore' )
1709  ->willReturn( $blobStore );
1710  $factory->expects( $this->any() )
1711  ->method( 'newSqlBlobStore' )
1712  ->willReturn( $blobStore );
1713 
1714  $this->setService( 'BlobStoreFactory', $factory );
1715 
1716  $this->testNewMutableRevisionFromArray( $array );
1717  }
1718 
1726  private function createRevisionStoreCacheRecord( $page, $store ) {
1728  $updater = $page->newPageUpdater( $user );
1729  $updater->setContent( SlotRecord::MAIN, new WikitextContent( __METHOD__ ) );
1730  $summary = CommentStoreComment::newUnsavedComment( __METHOD__ );
1731  $rev = $updater->saveRevision( $summary, EDIT_NEW );
1732  return $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1733  }
1734 
1740 
1741  $this->overrideMwServices();
1742  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1743  $this->setService( 'MainWANObjectCache', $cache );
1744 
1745  $store = MediaWikiServices::getInstance()->getRevisionStore();
1746  $page = $this->getNonexistingTestPage();
1747  $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1748 
1749  // Grab the user name
1750  $userNameBefore = $rev->getUser()->getName();
1751 
1752  // Change the user name in the database, "behind the back" of the cache
1753  $newUserName = "Renamed $userNameBefore";
1754  $this->db->update( 'revision',
1755  [ 'rev_user_text' => $newUserName ],
1756  [ 'rev_id' => $rev->getId() ] );
1757  $this->db->update( 'user',
1758  [ 'user_name' => $newUserName ],
1759  [ 'user_id' => $rev->getUser()->getId() ] );
1761  $this->db->update( 'actor',
1762  [ 'actor_name' => $newUserName ],
1763  [ 'actor_user' => $rev->getUser()->getId() ] );
1764  }
1765 
1766  // Reload the revision and regrab the user name.
1767  $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1768  $userNameAfter = $revAfter->getUser()->getName();
1769 
1770  // The two user names should be different.
1771  // If they are the same, we are seeing a cached value, which is bad.
1772  $this->assertNotSame( $userNameBefore, $userNameAfter );
1773 
1774  // This is implied by the above assertion, but explicitly check it, for completeness
1775  $this->assertSame( $newUserName, $userNameAfter );
1776  }
1777 
1782  $this->overrideMwServices();
1783  $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1784  $this->setService( 'MainWANObjectCache', $cache );
1785 
1786  $store = MediaWikiServices::getInstance()->getRevisionStore();
1787  $page = $this->getNonexistingTestPage();
1788  $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1789 
1790  // Grab the deleted bitmask
1791  $deletedBefore = $rev->getVisibility();
1792 
1793  // Change the deleted bitmask in the database, "behind the back" of the cache
1794  $this->db->update( 'revision',
1795  [ 'rev_deleted' => RevisionRecord::DELETED_TEXT ],
1796  [ 'rev_id' => $rev->getId() ] );
1797 
1798  // Reload the revision and regrab the visibility flag.
1799  $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1800  $deletedAfter = $revAfter->getVisibility();
1801 
1802  // The two deleted flags should be different.
1803  // If they are the same, we are seeing a cached value, which is bad.
1804  $this->assertNotSame( $deletedBefore, $deletedAfter );
1805 
1806  // This is implied by the above assertion, but explicitly check it, for completeness
1807  $this->assertSame( RevisionRecord::DELETED_TEXT, $deletedAfter );
1808  }
1809 
1815 
1816  $page = $this->getTestPage();
1817  $text = __METHOD__;
1819  $rev = $page->doEditContent(
1820  new WikitextContent( $text ),
1821  __METHOD__,
1822  0,
1823  false,
1824  $this->getMutableTestUser()->getUser()
1825  )->value['revision'];
1826 
1827  $store = MediaWikiServices::getInstance()->getRevisionStore();
1828  $record = $store->newRevisionFromRow(
1829  $this->revisionToRow( $rev ),
1830  [],
1831  $page->getTitle()
1832  );
1833 
1834  // Grab the user name
1835  $userNameBefore = $record->getUser()->getName();
1836 
1837  // Change the user name in the database
1838  $newUserName = "Renamed $userNameBefore";
1839  $this->db->update( 'revision',
1840  [ 'rev_user_text' => $newUserName ],
1841  [ 'rev_id' => $record->getId() ] );
1842  $this->db->update( 'user',
1843  [ 'user_name' => $newUserName ],
1844  [ 'user_id' => $record->getUser()->getId() ] );
1846  $this->db->update( 'actor',
1847  [ 'actor_name' => $newUserName ],
1848  [ 'actor_user' => $record->getUser()->getId() ] );
1849  }
1850 
1851  // Reload the record, passing $fromCache as true to force fresh info from the db,
1852  // and regrab the user name
1853  $recordAfter = $store->newRevisionFromRow(
1854  $this->revisionToRow( $rev ),
1855  [],
1856  $page->getTitle(),
1857  true
1858  );
1859  $userNameAfter = $recordAfter->getUser()->getName();
1860 
1861  // The two user names should be different.
1862  // If they are the same, we are seeing a cached value, which is bad.
1863  $this->assertNotSame( $userNameBefore, $userNameAfter );
1864 
1865  // This is implied by the above assertion, but explicitly check it, for completeness
1866  $this->assertSame( $newUserName, $userNameAfter );
1867  }
1868 
1873  $page = $this->getTestPage();
1874  $text = __METHOD__;
1876  $rev = $page->doEditContent(
1877  new WikitextContent( $text ),
1878  __METHOD__
1879  )->value['revision'];
1880 
1881  $store = MediaWikiServices::getInstance()->getRevisionStore();
1882  $record = $store->newRevisionFromRow(
1883  $this->revisionToRow( $rev ),
1884  [],
1885  $page->getTitle()
1886  );
1887 
1888  // Grab the deleted bitmask
1889  $deletedBefore = $record->getVisibility();
1890 
1891  // Change the deleted bitmask in the database
1892  $this->db->update( 'revision',
1893  [ 'rev_deleted' => RevisionRecord::DELETED_TEXT ],
1894  [ 'rev_id' => $record->getId() ] );
1895 
1896  // Reload the record, passing $fromCache as true to force fresh info from the db,
1897  // and regrab the deleted bitmask
1898  $recordAfter = $store->newRevisionFromRow(
1899  $this->revisionToRow( $rev ),
1900  [],
1901  $page->getTitle(),
1902  true
1903  );
1904  $deletedAfter = $recordAfter->getVisibility();
1905 
1906  // The two deleted flags should be different, because we modified the database.
1907  $this->assertNotSame( $deletedBefore, $deletedAfter );
1908 
1909  // This is implied by the above assertion, but explicitly check it, for completeness
1910  $this->assertSame( RevisionRecord::DELETED_TEXT, $deletedAfter );
1911  }
1912 
1913 }
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition: UserIdentityValue.php:32
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1266
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:48
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testInsertRevisionOn_successes
testInsertRevisionOn_successes(array $revDetails=[])
provideInsertRevisionOn_successes \MediaWiki\Revision\RevisionStore::insertRevisionOn \MediaWiki\Revi...
Definition: RevisionStoreDbTestBase.php:400
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromArchiveRow_legacyEncoding
testNewRevisionFromArchiveRow_legacyEncoding()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
Definition: RevisionStoreDbTestBase.php:1040
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
MediaWiki\Linker\LinkTarget\getInterwiki
getInterwiki()
The interwiki component of this LinkTarget.
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:2070
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetParentLengths
testGetParentLengths()
\MediaWiki\Revision\RevisionStore::listRevisionSizes
Definition: RevisionStoreDbTestBase.php:1290
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
Revision\IncompleteRevisionException
Exception throw when trying to access undefined fields on an incomplete RevisionRecord.
Definition: IncompleteRevisionException.php:31
Revision\SlotRecord\getContent
getContent()
Returns the Content of the given slot.
Definition: SlotRecord.php:302
Wikimedia\Rdbms\DatabaseSqlite
Definition: DatabaseSqlite.php:38
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionExistsInDatabase
assertRevisionExistsInDatabase(RevisionRecord $rev)
Definition: RevisionStoreDbTestBase.php:424
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetNextRevision_bad
testGetNextRevision_bad(RevisionRecord $rev)
provideNonHistoryRevision \MediaWiki\Revision\RevisionStore::getNextRevision
Definition: RevisionStoreDbTestBase.php:1404
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromArchiveRow_no_user
testNewRevisionFromArchiveRow_no_user()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
Definition: RevisionStoreDbTestBase.php:1071
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getMcrTablesToReset
getMcrTablesToReset()
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetNextRevision
testGetNextRevision()
\MediaWiki\Revision\RevisionStore::getNextRevision
Definition: RevisionStoreDbTestBase.php:1350
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_revDelete
testNewRevisionFromRow_revDelete()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:1872
Revision\SlotRecord\hasAddress
hasAddress()
Whether this slot has an address.
Definition: SlotRecord.php:435
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetTimestampFromId_notFound
testGetTimestampFromId_notFound()
\MediaWiki\Revision\RevisionStore::getTimestampFromId
Definition: RevisionStoreDbTestBase.php:1430
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetTimestampFromId_found
testGetTimestampFromId_found()
\MediaWiki\Revision\RevisionStore::getTimestampFromId
Definition: RevisionStoreDbTestBase.php:1412
Revision\SlotRecord\newInherited
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
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideInsertRevisionOn_failures
provideInsertRevisionOn_failures()
Definition: RevisionStoreDbTestBase.php:512
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromArchiveRow_getArchiveQueryInfo
testNewRevisionFromArchiveRow_getArchiveQueryInfo()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow \MediaWiki\Revision\RevisionStore::getAr...
Definition: RevisionStoreDbTestBase.php:1011
Revision\SlotRecord\getFormat
getFormat()
Returns the blob serialization format as a MIME type.
Definition: SlotRecord.php:581
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideNewNullRevision
provideNewNullRevision()
Definition: RevisionStoreDbTestBase.php:576
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testInsertRevisionOn_archive
testInsertRevisionOn_archive()
\MediaWiki\Revision\RevisionStore::insertRevisionOn
Definition: RevisionStoreDbTestBase.php:1147
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testCountRevisionsByPageId
testCountRevisionsByPageId()
\MediaWiki\Revision\RevisionStore::countRevisionsByPageId
Definition: RevisionStoreDbTestBase.php:1448
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getLoadBalancerMock
getLoadBalancerMock(array $server)
Definition: RevisionStoreDbTestBase.php:138
Revision\RevisionRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Definition: RevisionRecord.php:414
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\$testPageTitle
Title $testPageTitle
Definition: RevisionStoreDbTestBase.php:48
TestUserRegistry
Definition: TestUserRegistry.php:6
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:76
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects.
Definition: SqlBlobStore.php:49
$result
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. '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:1983
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetKnownCurrentRevision_userNameChange
testGetKnownCurrentRevision_userNameChange()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
Definition: RevisionStoreDbTestBase.php:1738
Revision\RevisionRecord\getTimestamp
getTimestamp()
MCR migration note: this replaces Revision::getTimestamp.
Definition: RevisionRecord.php:436
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testCountRevisionsByTitle
testCountRevisionsByTitle()
\MediaWiki\Revision\RevisionStore::countRevisionsByTitle
Definition: RevisionStoreDbTestBase.php:1471
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:45
$params
$params
Definition: styleTest.css.php:44
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testUserWasLastToEdit_true
testUserWasLastToEdit_true()
\MediaWiki\Revision\RevisionStore::userWasLastToEdit
Definition: RevisionStoreDbTestBase.php:1512
Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:191
MediaWikiTestCase\ensureMockDatabaseConnection
ensureMockDatabaseConnection(IDatabase $db)
Definition: MediaWikiTestCase.php:1559
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getRevisionRecordFromDetailsArray
getRevisionRecordFromDetailsArray( $details=[])
Definition: RevisionStoreDbTestBase.php:331
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getDatabaseMock
getDatabaseMock(array $params)
Definition: RevisionStoreDbTestBase.php:160
$res
$res
Definition: database.txt:21
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewNullRevision
testNewNullRevision(Title $title, $revDetails, $comment, $minor=false)
provideNewNullRevision \MediaWiki\Revision\RevisionStore::newNullRevision \MediaWiki\Revision\Revisio...
Definition: RevisionStoreDbTestBase.php:596
Revision\RevisionRecord\hasSlot
hasSlot( $role)
Returns whether the given slot is defined in this revision.
Definition: RevisionRecord.php:208
Revision\SlotRecord\getRevision
getRevision()
Returns the ID of the revision this slot is associated with.
Definition: SlotRecord.php:396
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertSlotRecordsEqual
assertSlotRecordsEqual(SlotRecord $s1, SlotRecord $s2)
Definition: RevisionStoreDbTestBase.php:297
MediaWikiTestCase\insertPage
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
Insert a new page.
Definition: MediaWikiTestCase.php:1222
serialize
serialize()
Definition: ApiMessageTrait.php:134
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testInsertRevisionOn_blobAddressExists
testInsertRevisionOn_blobAddressExists()
\MediaWiki\Revision\RevisionStore::insertRevisionOn
Definition: RevisionStoreDbTestBase.php:473
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: FakeResultWrapper.php:11
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled
testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled()
\MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
Definition: RevisionStoreDbTestBase.php:686
php
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
MediaWikiTestCase\overrideMwServices
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
Definition: MediaWikiTestCase.php:937
Revision
Definition: Revision.php:40
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
MediaWikiTestCase\getNonexistingTestPage
getNonexistingTestPage( $title=null)
Returns a WikiPage representing a non-existing page.
Definition: MediaWikiTestCase.php:256
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionRecordMatchesRevision
assertRevisionRecordMatchesRevision(Revision $rev, RevisionRecord $record)
Definition: RevisionStoreDbTestBase.php:855
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testUserWasLastToEdit_false
testUserWasLastToEdit_false()
\MediaWiki\Revision\RevisionStore::userWasLastToEdit
Definition: RevisionStoreDbTestBase.php:1494
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionCompleteness
assertRevisionCompleteness(RevisionRecord $r)
Definition: RevisionStoreDbTestBase.php:309
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetKnownCurrentRevision
testGetKnownCurrentRevision()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
Definition: RevisionStoreDbTestBase.php:1537
Revision\RevisionRecord\getSize
getSize()
Returns the nominal size of this revision, in bogo-bytes.
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRcIdIfUnpatrolled_returnsRecentChangesId
testGetRcIdIfUnpatrolled_returnsRecentChangesId()
\MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
Definition: RevisionStoreDbTestBase.php:666
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testLoadRevisionFromTimestamp
testLoadRevisionFromTimestamp()
\MediaWiki\Revision\RevisionStore::loadRevisionFromTimestamp
Definition: RevisionStoreDbTestBase.php:1253
Revision\RevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\revisionToRow
revisionToRow(Revision $rev, $options=[ 'page', 'user', 'comment'])
Definition: RevisionStoreDbTestBase.php:804
Revision\RevisionRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's author's user identity, if it's available to the specified audience.
Definition: RevisionRecord.php:365
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
Revision\SlotRecord\getRole
getRole()
Returns the role of the slot.
Definition: SlotRecord.php:489
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRevisionByTimestamp
testGetRevisionByTimestamp()
\MediaWiki\Revision\RevisionStore::getRevisionByTimestamp
Definition: RevisionStoreDbTestBase.php:782
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertLinkTargetsEqual
assertLinkTargetsEqual(LinkTarget $l1, LinkTarget $l2)
Definition: RevisionStoreDbTestBase.php:250
MediaWiki\Tests\Revision\RevisionStoreDbTestBase
Database RevisionStore.
Definition: RevisionStoreDbTestBase.php:43
Revision\RevisionRecord\isMinor
isMinor()
MCR migration note: this replaces Revision::isMinor.
Definition: RevisionRecord.php:403
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:2000
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Revision\SlotRecord\getModel
getModel()
Returns the content model.
Definition: SlotRecord.php:561
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRevisionById
testGetRevisionById()
\MediaWiki\Revision\RevisionStore::getRevisionById
Definition: RevisionStoreDbTestBase.php:728
MediaWiki\Storage\BlobStoreFactory
Service for instantiating BlobStores.
Definition: BlobStoreFactory.php:35
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\addCoreDBData
addCoreDBData()
Definition: RevisionStoreDbTestBase.php:90
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Revision\SlotRecord\getAddress
getAddress()
Returns the address of this slot's content.
Definition: SlotRecord.php:499
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1941
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewMutableRevisionFromArray_legacyEncoding
testNewMutableRevisionFromArray_legacyEncoding(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
Definition: RevisionStoreDbTestBase.php:1697
Revision\RevisionRecord\getSlotRoles
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Definition: RevisionRecord.php:218
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_anonEdit
testNewRevisionFromRow_anonEdit()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:939
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\setUp
setUp()
Definition: RevisionStoreDbTestBase.php:72
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getTestPageTitle
getTestPageTitle()
Definition: RevisionStoreDbTestBase.php:97
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testDomainCheck
testDomainCheck( $wikiId, $dbName, $dbPrefix)
provideDomainCheck \MediaWiki\Revision\RevisionStore::checkDatabaseWikiId
Definition: RevisionStoreDbTestBase.php:190
string
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
Revision\RevisionRecord\getPageId
getPageId()
Get the page ID.
Definition: RevisionRecord.php:325
Revision\SlotRecord\getSha1
getSha1()
Returns the content size.
Definition: SlotRecord.php:538
Revision\SlotRecord\newUnsaved
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetKnownCurrentRevision_revDelete
testGetKnownCurrentRevision_revDelete()
\MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
Definition: RevisionStoreDbTestBase.php:1781
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRevisionByTitle
testGetRevisionByTitle()
\MediaWiki\Revision\RevisionStore::getRevisionByTitle
Definition: RevisionStoreDbTestBase.php:746
Revision\SlotRecord\hasRevision
hasRevision()
Whether this slot has revision ID associated.
Definition: SlotRecord.php:480
Wikimedia\Rdbms\LoadBalancer
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition: LoadBalancer.php:41
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:273
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideNonHistoryRevision
provideNonHistoryRevision()
Definition: RevisionStoreDbTestBase.php:1371
Revision\getTitle
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:755
Revision\RevisionArchiveRecord
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Definition: RevisionArchiveRecord.php:40
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertSlotCompleteness
assertSlotCompleteness(RevisionRecord $r, SlotRecord $slot)
Definition: RevisionStoreDbTestBase.php:319
Revision\RevisionRecord\getParentId
getParentId()
Get parent revision ID (the original previous page revision).
Definition: RevisionRecord.php:289
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:124
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_userNameChange
testNewRevisionFromRow_userNameChange()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:1813
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_no_user
testNewRevisionFromRow_no_user()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:1109
Revision\SlotRecord\getSize
getSize()
Returns the content size.
Definition: SlotRecord.php:522
Revision\RevisionRecord\DELETED_USER
const DELETED_USER
Definition: RevisionRecord.php:50
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideNewMutableRevisionFromArray
provideNewMutableRevisionFromArray()
Definition: RevisionStoreDbTestBase.php:1557
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:192
Revision\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:41
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:116
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:204
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
SCHEMA_COMPAT_WRITE_NEW
const SCHEMA_COMPAT_WRITE_NEW
Definition: Defines.php:286
Revision\RevisionRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment, if it's available to the specified audience.
Definition: RevisionRecord.php:390
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getRandomCommentStoreComment
getRandomCommentStoreComment()
Definition: RevisionStoreDbTestBase.php:390
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_userEdit
testNewRevisionFromRow_userEdit()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:985
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testLoadRevisionFromPageId
testLoadRevisionFromPageId()
\MediaWiki\Revision\RevisionStore::loadRevisionFromPageId
Definition: RevisionStoreDbTestBase.php:1223
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewNullRevision_nonExistingTitle
testNewNullRevision_nonExistingTitle()
\MediaWiki\Revision\RevisionStore::newNullRevision
Definition: RevisionStoreDbTestBase.php:651
Revision\SlotRecord\MAIN
const MAIN
Definition: SlotRecord.php:41
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionRecordsEqual
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
Definition: RevisionStoreDbTestBase.php:257
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideInsertRevisionOn_successes
provideInsertRevisionOn_successes()
Definition: RevisionStoreDbTestBase.php:366
Content
Base interface for content objects.
Definition: Content.php:34
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:152
Revision\RevisionRecord\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: RevisionRecord.php:425
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertSameSlotContent
assertSameSlotContent(SlotRecord $a, SlotRecord $b)
Definition: RevisionStoreDbTestBase.php:465
Revision\RevisionRecord\getPageAsLinkTarget
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Definition: RevisionRecord.php:345
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testLoadRevisionFromTitle
testLoadRevisionFromTitle()
\MediaWiki\Revision\RevisionStore::loadRevisionFromTitle
Definition: RevisionStoreDbTestBase.php:1238
Title
Represents a title within MediaWiki.
Definition: Title.php:40
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\createRevisionStoreCacheRecord
createRevisionStoreCacheRecord( $page, $store)
Creates a new revision for testing caching behavior.
Definition: RevisionStoreDbTestBase.php:1726
Revision\RevisionRecord\DELETED_COMMENT
const DELETED_COMMENT
Definition: RevisionRecord.php:49
$cache
$cache
Definition: mcc.php:33
$options
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:1985
SCHEMA_COMPAT_NEW
const SCHEMA_COMPAT_NEW
Definition: Defines.php:291
$rev
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:1769
Revision\RevisionRecord\DELETED_TEXT
const DELETED_TEXT
Definition: RevisionRecord.php:48
as
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
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetPreviousRevision_bad
testGetPreviousRevision_bad(RevisionRecord $rev)
provideNonHistoryRevision \MediaWiki\Revision\RevisionStore::getPreviousRevision
Definition: RevisionStoreDbTestBase.php:1395
Revision\RevisionRecord\getContent
getContent( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns the Content of the given slot of this revision.
Definition: RevisionRecord.php:167
$keys
$keys
Definition: testCompression.php:67
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\provideDomainCheck
provideDomainCheck()
Definition: RevisionStoreDbTestBase.php:172
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_anonEdit_legacyEncoding
testNewRevisionFromRow_anonEdit_legacyEncoding()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow
Definition: RevisionStoreDbTestBase.php:961
$updater
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
true
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:1985
$content
$content
Definition: pageupdater.txt:72
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetPreviousRevision
testGetPreviousRevision()
\MediaWiki\Revision\RevisionStore::getPreviousRevision
Definition: RevisionStoreDbTestBase.php:1326
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getTestPage
getTestPage()
Definition: RevisionStoreDbTestBase.php:109
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
class
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
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getMcrMigrationStage
getMcrMigrationStage()
TestUserRegistry\getMutableTestUser
static getMutableTestUser( $testName, $groups=[])
Get a TestUser object that the caller may modify.
Definition: TestUserRegistry.php:34
$t
$t
Definition: testCompression.php:69
EDIT_SUPPRESS_RC
const EDIT_SUPPRESS_RC
Definition: Defines.php:155
object
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
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testInsertRevisionOn_failures
testInsertRevisionOn_failures(array $revDetails=[], Exception $exception)
provideInsertRevisionOn_failures \MediaWiki\Revision\RevisionStore::insertRevisionOn
Definition: RevisionStoreDbTestBase.php:560
Revision\RevisionRecord\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: RevisionRecord.php:51
MediaWikiServices
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
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/prefix specification for IDatabase domains.
Definition: DatabaseDomain.php:28
Wikimedia\Rdbms\TransactionProfiler
Helper class that detects high-contention DB queries via profiling calls.
Definition: TransactionProfiler.php:38
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:457
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewMutableRevisionFromArray
testNewMutableRevisionFromArray(array $array)
provideNewMutableRevisionFromArray \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
Definition: RevisionStoreDbTestBase.php:1643
MediaWikiTestCase\setService
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
Definition: MediaWikiTestCase.php:649
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRevisionByPageId
testGetRevisionByPageId()
\MediaWiki\Revision\RevisionStore::getRevisionByPageId
Definition: RevisionStoreDbTestBase.php:764
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testGetRecentChange
testGetRecentChange()
\MediaWiki\Revision\RevisionStore::getRecentChange
Definition: RevisionStoreDbTestBase.php:710
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testLoadRevisionFromId
testLoadRevisionFromId()
\MediaWiki\Revision\RevisionStore::loadRevisionFromId
Definition: RevisionStoreDbTestBase.php:1208
Revision\RevisionRecord\getWikiId
getWikiId()
Get the ID of the wiki this revision belongs to.
Definition: RevisionRecord.php:334
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
Language
Internationalisation code.
Definition: Language.php:36
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getContentHandlerUseDB
getContentHandlerUseDB()
Definition: RevisionStoreDbTestBase.php:63
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:61
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\$testPage
WikiPage $testPage
Definition: RevisionStoreDbTestBase.php:53
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\testNewRevisionFromRow_getQueryInfo
testNewRevisionFromRow_getQueryInfo()
\MediaWiki\Revision\RevisionStore::newRevisionFromRow \MediaWiki\Revision\RevisionStore::getQueryInfo
Definition: RevisionStoreDbTestBase.php:908
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979