MediaWiki  master
PageUpdaterTest.php
Go to the documentation of this file.
1 <?php
2 
4 
15 use Title;
16 use User;
18 
24 
25  public function setUp() {
26  parent::setUp();
27 
28  MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
29  'aux',
31  );
32 
33  $this->tablesUsed[] = 'logging';
34  $this->tablesUsed[] = 'recentchanges';
35  }
36 
37  private function getDummyTitle( $method ) {
38  return Title::newFromText( $method, $this->getDefaultWikitextNS() );
39  }
40 
46  private function getRecentChangeFor( $revId ) {
48  $row = $this->db->selectRow(
49  $qi['tables'],
50  $qi['fields'],
51  [ 'rc_this_oldid' => $revId ],
52  __METHOD__,
53  [],
54  $qi['joins']
55  );
56 
57  return $row ? RecentChange::newFromRow( $row ) : null;
58  }
59 
60  // TODO: test setAjaxEditStash();
61 
66  public function testCreatePage() {
67  $user = $this->getTestUser()->getUser();
68 
69  $title = $this->getDummyTitle( __METHOD__ );
70  $page = WikiPage::factory( $title );
71  $updater = $page->newPageUpdater( $user );
72 
73  $oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
74 
75  $this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
76  $this->assertFalse( $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
77  $this->assertSame( 0, $updater->getUndidRevisionId(), 'getUndidRevisionId' );
78 
79  $updater->addTag( 'foo' );
80  $updater->addTags( [ 'bar', 'qux' ] );
81 
82  $tags = $updater->getExplicitTags();
83  sort( $tags );
84  $this->assertSame( [ 'bar', 'foo', 'qux' ], $tags, 'getExplicitTags' );
85 
86  // TODO: MCR: test additional slots
87  $content = new TextContent( 'Lorem Ipsum' );
88  $updater->setContent( SlotRecord::MAIN, $content );
89 
90  $parent = $updater->grabParentRevision();
91 
92  $this->assertNull( $parent, 'getParentRevision' );
93  $this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
94 
95  // TODO: test that hasEditConflict() grabs the parent revision
96  $this->assertFalse( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
97  $this->assertTrue( $updater->hasEditConflict( 1 ), 'hasEditConflict' );
98 
99  // TODO: test failure with EDIT_UPDATE
100  // TODO: test EDIT_MINOR, EDIT_BOT, etc
101  $summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
102  $rev = $updater->saveRevision( $summary );
103 
104  $this->assertNotNull( $rev );
105  $this->assertSame( 0, $rev->getParentId() );
106  $this->assertSame( $summary->text, $rev->getComment( RevisionRecord::RAW )->text );
107  $this->assertSame( $user->getName(), $rev->getUser( RevisionRecord::RAW )->getName() );
108 
109  $this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
110  $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
111  $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
112  $this->assertTrue( $updater->isNew(), 'isNew()' );
113  $this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
114  $this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
115  $this->assertInstanceOf( Revision::class, $updater->getStatus()->value['revision'] );
116 
117  $rev = $updater->getNewRevision();
118  $revContent = $rev->getContent( SlotRecord::MAIN );
119  $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
120 
121  // were the WikiPage and Title objects updated?
122  $this->assertTrue( $page->exists(), 'WikiPage::exists()' );
123  $this->assertTrue( $title->exists(), 'Title::exists()' );
124  $this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
125  $this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
126 
127  // re-load
128  $page2 = WikiPage::factory( $title );
129  $this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
130  $this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
131  $this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
132 
133  // Check RC entry
134  $rc = $this->getRecentChangeFor( $rev->getId() );
135  $this->assertNotNull( $rc, 'RecentChange' );
136 
137  // check site stats - this asserts that derived data updates where run.
138  $stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
139  $this->assertSame( $oldStats->ss_total_pages + 1, (int)$stats->ss_total_pages );
140  $this->assertSame( $oldStats->ss_total_edits + 1, (int)$stats->ss_total_edits );
141 
142  // re-edit with same content - should be a "null-edit"
143  $updater = $page->newPageUpdater( $user );
144  $updater->setContent( SlotRecord::MAIN, $content );
145 
146  $summary = CommentStoreComment::newUnsavedComment( 'to to re-edit' );
147  $rev = $updater->saveRevision( $summary );
148  $status = $updater->getStatus();
149 
150  $this->assertNull( $rev, 'getNewRevision()' );
151  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
152  $this->assertTrue( $updater->isUnchanged(), 'isUnchanged' );
153  $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
154  $this->assertTrue( $status->isOK(), 'getStatus()->isOK()' );
155  $this->assertTrue( $status->hasMessage( 'edit-no-change' ), 'edit-no-change' );
156  }
157 
162  public function testUpdatePage() {
163  $user = $this->getTestUser()->getUser();
164 
165  $title = $this->getDummyTitle( __METHOD__ );
166  $this->insertPage( $title );
167 
168  $page = WikiPage::factory( $title );
169  $parentId = $page->getLatest();
170 
171  $updater = $page->newPageUpdater( $user );
172 
173  $oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
174 
175  $updater->setOriginalRevisionId( 7 );
176  $this->assertSame( 7, $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
177 
178  $this->assertFalse( $updater->hasEditConflict( $parentId ), 'hasEditConflict' );
179  $this->assertTrue( $updater->hasEditConflict( $parentId - 1 ), 'hasEditConflict' );
180  $this->assertTrue( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
181 
182  // TODO: MCR: test additional slots
183  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
184 
185  // TODO: test all flags for saveRevision()!
186  $summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
187  $rev = $updater->saveRevision( $summary );
188 
189  $this->assertNotNull( $rev );
190  $this->assertSame( $parentId, $rev->getParentId() );
191  $this->assertSame( $summary->text, $rev->getComment( RevisionRecord::RAW )->text );
192  $this->assertSame( $user->getName(), $rev->getUser( RevisionRecord::RAW )->getName() );
193 
194  $this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
195  $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
196  $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
197  $this->assertFalse( $updater->isNew(), 'isNew()' );
198  $this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
199  $this->assertInstanceOf( Revision::class, $updater->getStatus()->value['revision'] );
200  $this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
201 
202  // TODO: Test null revision (with different user): new revision!
203 
204  $rev = $updater->getNewRevision();
205  $revContent = $rev->getContent( SlotRecord::MAIN );
206  $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
207 
208  // were the WikiPage and Title objects updated?
209  $this->assertTrue( $page->exists(), 'WikiPage::exists()' );
210  $this->assertTrue( $title->exists(), 'Title::exists()' );
211  $this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
212  $this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
213 
214  // re-load
215  $page2 = WikiPage::factory( $title );
216  $this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
217  $this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
218  $this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
219 
220  // Check RC entry
221  $rc = $this->getRecentChangeFor( $rev->getId() );
222  $this->assertNotNull( $rc, 'RecentChange' );
223 
224  // re-edit
225  $updater = $page->newPageUpdater( $user );
226  $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
227 
228  $summary = CommentStoreComment::newUnsavedComment( 're-edit' );
229  $updater->saveRevision( $summary );
230  $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
231  $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
232 
233  // check site stats - this asserts that derived data updates where run.
234  $stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
235  $this->assertNotNull( $stats, 'site_stats' );
236  $this->assertSame( $oldStats->ss_total_pages + 0, (int)$stats->ss_total_pages );
237  $this->assertSame( $oldStats->ss_total_edits + 2, (int)$stats->ss_total_edits );
238  }
239 
249  private function createRevision( WikiPage $page, $summary, $content = null ) {
250  $user = $this->getTestUser()->getUser();
251  $comment = CommentStoreComment::newUnsavedComment( $summary );
252 
253  if ( !$content instanceof Content ) {
254  $content = new TextContent( $content ?? $summary );
255  }
256 
257  $updater = $page->newPageUpdater( $user );
258  $updater->setContent( SlotRecord::MAIN, $content );
259  $rev = $updater->saveRevision( $comment );
260  return $rev;
261  }
262 
267  public function testCompareAndSwapFailure() {
268  $user = $this->getTestUser()->getUser();
269 
270  $title = $this->getDummyTitle( __METHOD__ );
271 
272  // start editing non-existing page
273  $page = WikiPage::factory( $title );
274  $updater = $page->newPageUpdater( $user );
275  $updater->grabParentRevision();
276 
277  // create page concurrently
278  $concurrentPage = WikiPage::factory( $title );
279  $this->createRevision( $concurrentPage, __METHOD__ . '-one' );
280 
281  // try creating the page - should trigger CAS failure.
282  $summary = CommentStoreComment::newUnsavedComment( 'create?!' );
283  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
284  $updater->saveRevision( $summary );
285  $status = $updater->getStatus();
286 
287  $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
288  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
289  $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
290  $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-conflict' );
291 
292  // start editing existing page
293  $page = WikiPage::factory( $title );
294  $updater = $page->newPageUpdater( $user );
295  $updater->grabParentRevision();
296 
297  // update page concurrently
298  $concurrentPage = WikiPage::factory( $title );
299  $this->createRevision( $concurrentPage, __METHOD__ . '-two' );
300 
301  // try creating the page - should trigger CAS failure.
302  $summary = CommentStoreComment::newUnsavedComment( 'edit?!' );
303  $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
304  $updater->saveRevision( $summary );
305  $status = $updater->getStatus();
306 
307  $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
308  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
309  $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
310  $this->assertTrue( $status->hasMessage( 'edit-conflict' ), 'edit-conflict' );
311  }
312 
316  public function testFailureOnEditFlags() {
317  $user = $this->getTestUser()->getUser();
318 
319  $title = $this->getDummyTitle( __METHOD__ );
320 
321  // start editing non-existing page
322  $page = WikiPage::factory( $title );
323  $updater = $page->newPageUpdater( $user );
324 
325  // update with EDIT_UPDATE flag should fail
326  $summary = CommentStoreComment::newUnsavedComment( 'udpate?!' );
327  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
328  $updater->saveRevision( $summary, EDIT_UPDATE );
329  $status = $updater->getStatus();
330 
331  $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
332  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
333  $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
334  $this->assertTrue( $status->hasMessage( 'edit-gone-missing' ), 'edit-gone-missing' );
335 
336  // create the page
337  $this->createRevision( $page, __METHOD__ );
338 
339  // update with EDIT_NEW flag should fail
340  $summary = CommentStoreComment::newUnsavedComment( 'create?!' );
341  $updater = $page->newPageUpdater( $user );
342  $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
343  $updater->saveRevision( $summary, EDIT_NEW );
344  $status = $updater->getStatus();
345 
346  $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
347  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
348  $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
349  $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-already-exists' );
350  }
351 
355  public function testFailureOnBadContentModel() {
356  $user = $this->getTestUser()->getUser();
357  $title = $this->getDummyTitle( __METHOD__ );
358 
359  // start editing non-existing page
360  $page = WikiPage::factory( $title );
361  $updater = $page->newPageUpdater( $user );
362 
363  // plain text content should fail in aux slot (the main slot doesn't care)
364  $updater->setContent( 'main', new TextContent( 'Main Content' ) );
365  $updater->setContent( 'aux', new TextContent( 'Aux Content' ) );
366 
367  $summary = CommentStoreComment::newUnsavedComment( 'udpate?!' );
368  $updater->saveRevision( $summary, EDIT_UPDATE );
369  $status = $updater->getStatus();
370 
371  $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
372  $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
373  $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
374  $this->assertTrue(
375  $status->hasMessage( 'content-not-allowed-here' ),
376  'content-not-allowed-here'
377  );
378  }
379 
380  public function provideSetRcPatrolStatus( $patrolled ) {
383  }
384 
389  public function testSetRcPatrolStatus( $patrolled ) {
390  $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
391 
392  $user = $this->getTestUser()->getUser();
393 
394  $title = $this->getDummyTitle( __METHOD__ );
395 
396  $page = WikiPage::factory( $title );
397  $updater = $page->newPageUpdater( $user );
398 
399  $summary = CommentStoreComment::newUnsavedComment( 'Lorem ipsum ' . $patrolled );
400  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum ' . $patrolled ) );
401  $updater->setRcPatrolStatus( $patrolled );
402  $rev = $updater->saveRevision( $summary );
403 
404  $rc = $revisionStore->getRecentChange( $rev );
405  $this->assertEquals( $patrolled, $rc->getAttribute( 'rc_patrolled' ) );
406  }
407 
412  public function testInheritSlot() {
413  $user = $this->getTestUser()->getUser();
414  $title = $this->getDummyTitle( __METHOD__ );
415  $page = WikiPage::factory( $title );
416 
417  $updater = $page->newPageUpdater( $user );
418  $summary = CommentStoreComment::newUnsavedComment( 'one' );
419  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
420  $rev1 = $updater->saveRevision( $summary, EDIT_NEW );
421 
422  $updater = $page->newPageUpdater( $user );
423  $summary = CommentStoreComment::newUnsavedComment( 'two' );
424  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Foo Bar' ) );
425  $rev2 = $updater->saveRevision( $summary, EDIT_UPDATE );
426 
427  $updater = $page->newPageUpdater( $user );
428  $summary = CommentStoreComment::newUnsavedComment( 'three' );
429  $updater->inheritSlot( $rev1->getSlot( SlotRecord::MAIN ) );
430  $rev3 = $updater->saveRevision( $summary, EDIT_UPDATE );
431 
432  $this->assertNotSame( $rev1->getId(), $rev3->getId() );
433  $this->assertNotSame( $rev2->getId(), $rev3->getId() );
434 
435  $main1 = $rev1->getSlot( SlotRecord::MAIN );
436  $main3 = $rev3->getSlot( SlotRecord::MAIN );
437 
438  $this->assertNotSame( $main1->getRevision(), $main3->getRevision() );
439  $this->assertSame( $main1->getAddress(), $main3->getAddress() );
440  $this->assertTrue( $main1->getContent()->equals( $main3->getContent() ) );
441  }
442 
443  // TODO: MCR: test adding multiple slots, inheriting parent slots, and removing slots.
444 
446  $this->setContentLang( 'qqx' );
447  $user = $this->getTestUser()->getUser();
448 
449  $title = $this->getDummyTitle( __METHOD__ );
450  $page = WikiPage::factory( $title );
451 
452  $updater = $page->newPageUpdater( $user );
453  $updater->setUseAutomaticEditSummaries( true );
454  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
455 
456  // empty comment triggers auto-summary
458  $updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
459 
460  $rev = $updater->getNewRevision();
461  $comment = $rev->getComment( RevisionRecord::RAW );
462  $this->assertSame( '(autosumm-new: Lorem Ipsum)', $comment->text, 'comment text' );
463 
464  // check that this also works when blanking the page
465  $updater = $page->newPageUpdater( $user );
466  $updater->setUseAutomaticEditSummaries( true );
467  $updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
468 
470  $updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
471 
472  $rev = $updater->getNewRevision();
473  $comment = $rev->getComment( RevisionRecord::RAW );
474  $this->assertSame( '(autosumm-blank)', $comment->text, 'comment text' );
475 
476  // check that we can also disable edit-summaries
477  $title2 = $this->getDummyTitle( __METHOD__ . '/2' );
478  $page2 = WikiPage::factory( $title2 );
479 
480  $updater = $page2->newPageUpdater( $user );
481  $updater->setUseAutomaticEditSummaries( false );
482  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
483 
485  $updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
486 
487  $rev = $updater->getNewRevision();
488  $comment = $rev->getComment( RevisionRecord::RAW );
489  $this->assertSame( '', $comment->text, 'comment text should still be lank' );
490 
491  // check that we don't do auto.summaries without the EDIT_AUTOSUMMARY flag
492  $updater = $page2->newPageUpdater( $user );
493  $updater->setUseAutomaticEditSummaries( true );
494  $updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
495 
497  $updater->saveRevision( $summary, 0 );
498 
499  $rev = $updater->getNewRevision();
500  $comment = $rev->getComment( RevisionRecord::RAW );
501  $this->assertSame( '', $comment->text, 'comment text' );
502  }
503 
504  public function provideSetUsePageCreationLog() {
505  yield [ true, [ [ 'create', 'create' ] ] ];
506  yield [ false, [] ];
507  }
508 
513  public function testSetUsePageCreationLog( $use, $expected ) {
514  $user = $this->getTestUser()->getUser();
515  $title = $this->getDummyTitle( __METHOD__ . ( $use ? '_logged' : '_unlogged' ) );
516  $page = WikiPage::factory( $title );
517 
518  $updater = $page->newPageUpdater( $user );
519  $updater->setUsePageCreationLog( $use );
520  $summary = CommentStoreComment::newUnsavedComment( 'cmt' );
521  $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
522  $updater->saveRevision( $summary, EDIT_NEW );
523 
524  $rev = $updater->getNewRevision();
525  $this->assertSelect(
526  'logging',
527  [ 'log_type', 'log_action' ],
528  [ 'log_page' => $rev->getPageId() ],
529  $expected
530  );
531  }
532 
533  public function provideMagicWords() {
534  yield 'PAGEID' => [
535  'Test {{PAGEID}} Test',
536  function ( RevisionRecord $rev ) {
537  return $rev->getPageId();
538  }
539  ];
540 
541  yield 'REVISIONID' => [
542  'Test {{REVISIONID}} Test',
543  function ( RevisionRecord $rev ) {
544  return $rev->getId();
545  }
546  ];
547 
548  yield 'REVISIONUSER' => [
549  'Test {{REVISIONUSER}} Test',
550  function ( RevisionRecord $rev ) {
551  return $rev->getUser()->getName();
552  }
553  ];
554 
555  yield 'REVISIONTIMESTAMP' => [
556  'Test {{REVISIONTIMESTAMP}} Test',
557  function ( RevisionRecord $rev ) {
558  return $rev->getTimestamp();
559  }
560  ];
561 
562  yield 'subst:REVISIONUSER' => [
563  'Test {{subst:REVISIONUSER}} Test',
564  function ( RevisionRecord $rev ) {
565  return $rev->getUser()->getName();
566  },
567  'subst'
568  ];
569 
570  yield 'subst:PAGENAME' => [
571  'Test {{subst:PAGENAME}} Test',
572  function ( RevisionRecord $rev ) {
573  return 'PageUpdaterTest::testMagicWords';
574  },
575  'subst'
576  ];
577  }
578 
589  public function testMagicWords( $wikitext, $callback, $subst = false ) {
590  $user = User::newFromName( 'A user for ' . __METHOD__ );
591  $user->addToDatabase();
592 
593  $title = $this->getDummyTitle( __METHOD__ . '-' . $this->getName() );
594  $this->insertPage( $title );
595 
596  $page = WikiPage::factory( $title );
597  $updater = $page->newPageUpdater( $user );
598 
599  $updater->setContent( SlotRecord::MAIN, new \WikitextContent( $wikitext ) );
600 
601  $summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
602  $rev = $updater->saveRevision( $summary, EDIT_UPDATE );
603 
604  if ( !$rev ) {
605  $this->fail( $updater->getStatus()->getWikiText() );
606  }
607 
608  $expected = strval( $callback( $rev ) );
609 
610  $output = $page->getParserOutput( ParserOptions::newCanonical( 'canonical' ) );
611  $html = $output->getText();
612  $text = $rev->getContent( SlotRecord::MAIN )->serialize();
613 
614  if ( $subst ) {
615  $this->assertContains( $expected, $text, 'In Wikitext' );
616  }
617 
618  $this->assertContains( $expected, $html, 'In HTML' );
619  }
620 
621 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
testFailureOnEditFlags()
\MediaWiki\Storage\PageUpdater::saveRevision()
\MediaWiki\Storage\PageUpdater Database
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1982
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testSetRcPatrolStatus( $patrolled)
provideSetRcPatrolStatus \MediaWiki\Storage\PageUpdater::setRcPatrolStatus()
static array static newFromRow( $row)
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
const EDIT_UPDATE
Definition: Defines.php:153
static getInstance()
Returns the global default instance of the top level service locator.
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2217
testMagicWords( $wikitext, $callback, $subst=false)
\MediaWiki\Storage\PageUpdater::saveRevision()
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
testSetUsePageCreationLog( $use, $expected)
provideSetUsePageCreationLog
testUpdatePage()
\MediaWiki\Storage\PageUpdater::saveRevision() \WikiPage::newPageUpdater()
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1263
newPageUpdater(User $user, RevisionSlotsUpdate $forUpdate=null)
Returns a PageUpdater for creating new revisions on this page (or creating the page).
Definition: WikiPage.php:1789
testFailureOnBadContentModel()
\MediaWiki\Storage\PageUpdater::saveRevision()
testCreatePage()
\MediaWiki\Storage\PageUpdater::saveRevision() \WikiPage::newPageUpdater()
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
Insert a new page.
testCompareAndSwapFailure()
\MediaWiki\Storage\PageUpdater::grabParentRevision() \MediaWiki\Storage\PageUpdater::saveRevision() ...
const EDIT_AUTOSUMMARY
Definition: Defines.php:158
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
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:1766
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
const PRC_UNPATROLLED
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
testInheritSlot()
\MediaWiki\Storage\PageUpdater::inheritSlot() \MediaWiki\Storage\PageUpdater::setContent() ...
$parent
Definition: pageupdater.txt:71
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
const EDIT_NEW
Definition: Defines.php:152
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object...
Page revision base class.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:587
const PRC_AUTOPATROLLED
$content
Definition: pageupdater.txt:72
createRevision(WikiPage $page, $summary, $content=null)
Creates a revision in the database.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319