MediaWiki REL1_31
ApiQueryRecentChangesIntegrationTest.php
Go to the documentation of this file.
1<?php
2
5
14
15 public function __construct( $name = null, array $data = [], $dataName = '' ) {
16 parent::__construct( $name, $data, $dataName );
17
18 $this->tablesUsed[] = 'recentchanges';
19 $this->tablesUsed[] = 'page';
20 }
21
22 protected function setUp() {
23 parent::setUp();
24
25 self::$users['ApiQueryRecentChangesIntegrationTestUser'] = $this->getMutableTestUser();
26 wfGetDB( DB_MASTER )->delete( 'recentchanges', '*', __METHOD__ );
27 }
28
29 private function getLoggedInTestUser() {
30 return self::$users['ApiQueryRecentChangesIntegrationTestUser']->getUser();
31 }
32
33 private function doPageEdit( User $user, LinkTarget $target, $summary ) {
34 static $i = 0;
35
36 $title = Title::newFromLinkTarget( $target );
37 $page = WikiPage::factory( $title );
38 $page->doEditContent(
39 ContentHandler::makeContent( __CLASS__ . $i++, $title ),
40 $summary,
41 0,
42 false,
43 $user
44 );
45 }
46
47 private function doMinorPageEdit( User $user, LinkTarget $target, $summary ) {
48 $title = Title::newFromLinkTarget( $target );
49 $page = WikiPage::factory( $title );
50 $page->doEditContent(
51 ContentHandler::makeContent( __CLASS__, $title ),
52 $summary,
54 false,
55 $user
56 );
57 }
58
59 private function doBotPageEdit( User $user, LinkTarget $target, $summary ) {
60 $title = Title::newFromLinkTarget( $target );
61 $page = WikiPage::factory( $title );
62 $page->doEditContent(
63 ContentHandler::makeContent( __CLASS__, $title ),
64 $summary,
66 false,
67 $user
68 );
69 }
70
71 private function doAnonPageEdit( LinkTarget $target, $summary ) {
72 $title = Title::newFromLinkTarget( $target );
73 $page = WikiPage::factory( $title );
74 $page->doEditContent(
75 ContentHandler::makeContent( __CLASS__, $title ),
76 $summary,
77 0,
78 false,
80 );
81 }
82
83 private function deletePage( LinkTarget $target, $reason ) {
84 $title = Title::newFromLinkTarget( $target );
85 $page = WikiPage::factory( $title );
86 $page->doDeleteArticleReal( $reason );
87 }
88
98 private function doPageEdits( User $user, array $editData ) {
99 foreach ( $editData as $singleEditData ) {
100 if ( array_key_exists( 'minorEdit', $singleEditData ) && $singleEditData['minorEdit'] ) {
101 $this->doMinorPageEdit(
102 $user,
103 $singleEditData['target'],
104 $singleEditData['summary']
105 );
106 continue;
107 }
108 if ( array_key_exists( 'botEdit', $singleEditData ) && $singleEditData['botEdit'] ) {
109 $this->doBotPageEdit(
110 $user,
111 $singleEditData['target'],
112 $singleEditData['summary']
113 );
114 continue;
115 }
116 $this->doPageEdit(
117 $user,
118 $singleEditData['target'],
119 $singleEditData['summary']
120 );
121 }
122 }
123
124 private function doListRecentChangesRequest( array $params = [] ) {
125 return $this->doApiRequest(
126 array_merge(
127 [ 'action' => 'query', 'list' => 'recentchanges' ],
128 $params
129 ),
130 null,
131 false,
132 $this->getLoggedInTestUser()
133 );
134 }
135
137 return $this->doApiRequest(
138 array_merge(
139 [ 'action' => 'query', 'generator' => 'recentchanges' ],
140 $params
141 ),
142 null,
143 false,
144 $this->getLoggedInTestUser()
145 );
146 }
147
149 return $response[0]['query']['recentchanges'];
150 }
151
152 private function getTitleFormatter() {
153 return new MediaWikiTitleCodec(
154 Language::factory( 'en' ),
155 MediaWikiServices::getInstance()->getGenderCache()
156 );
157 }
158
159 private function getPrefixedText( LinkTarget $target ) {
160 $formatter = $this->getTitleFormatter();
161 return $formatter->getPrefixedText( $target );
162 }
163
165 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
166 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
167
169
170 $this->assertArrayHasKey( 'query', $result[0] );
171 $this->assertArrayHasKey( 'recentchanges', $result[0]['query'] );
172
173 $items = $this->getItemsFromApiResponse( $result );
174 $this->assertCount( 1, $items );
175 $item = $items[0];
176 $this->assertArraySubset(
177 [
178 'type' => 'new',
179 'ns' => $target->getNamespace(),
180 'title' => $this->getPrefixedText( $target ),
181 ],
182 $item
183 );
184 $this->assertArrayNotHasKey( 'bot', $item );
185 $this->assertArrayNotHasKey( 'new', $item );
186 $this->assertArrayNotHasKey( 'minor', $item );
187 $this->assertArrayHasKey( 'pageid', $item );
188 $this->assertArrayHasKey( 'revid', $item );
189 $this->assertArrayHasKey( 'old_revid', $item );
190 }
191
192 public function testIdsPropParameter() {
193 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
194 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
195
196 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'ids', ] );
197 $items = $this->getItemsFromApiResponse( $result );
198
199 $this->assertCount( 1, $items );
200 $this->assertArrayHasKey( 'pageid', $items[0] );
201 $this->assertArrayHasKey( 'revid', $items[0] );
202 $this->assertArrayHasKey( 'old_revid', $items[0] );
203 $this->assertEquals( 'new', $items[0]['type'] );
204 }
205
206 public function testTitlePropParameter() {
207 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
208 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
209 $this->doPageEdits(
210 $this->getLoggedInTestUser(),
211 [
212 [
213 'target' => $subjectTarget,
214 'summary' => 'Create the page',
215 ],
216 [
217 'target' => $talkTarget,
218 'summary' => 'Create Talk page',
219 ],
220 ]
221 );
222
223 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', ] );
224
225 $this->assertEquals(
226 [
227 [
228 'type' => 'new',
229 'ns' => $talkTarget->getNamespace(),
230 'title' => $this->getPrefixedText( $talkTarget ),
231 ],
232 [
233 'type' => 'new',
234 'ns' => $subjectTarget->getNamespace(),
235 'title' => $this->getPrefixedText( $subjectTarget ),
236 ],
237 ],
238 $this->getItemsFromApiResponse( $result )
239 );
240 }
241
242 public function testFlagsPropParameter() {
243 $normalEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
244 $minorEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPageM' );
245 $botEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPageB' );
246 $this->doPageEdits(
247 $this->getLoggedInTestUser(),
248 [
249 [
250 'target' => $normalEditTarget,
251 'summary' => 'Create the page',
252 ],
253 [
254 'target' => $minorEditTarget,
255 'summary' => 'Create the page',
256 ],
257 [
258 'target' => $minorEditTarget,
259 'summary' => 'Change content',
260 'minorEdit' => true,
261 ],
262 [
263 'target' => $botEditTarget,
264 'summary' => 'Create the page with a bot',
265 'botEdit' => true,
266 ],
267 ]
268 );
269
270 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'flags', ] );
271
272 $this->assertEquals(
273 [
274 [
275 'type' => 'new',
276 'new' => true,
277 'minor' => false,
278 'bot' => true,
279 ],
280 [
281 'type' => 'edit',
282 'new' => false,
283 'minor' => true,
284 'bot' => false,
285 ],
286 [
287 'type' => 'new',
288 'new' => true,
289 'minor' => false,
290 'bot' => false,
291 ],
292 [
293 'type' => 'new',
294 'new' => true,
295 'minor' => false,
296 'bot' => false,
297 ],
298 ],
300 );
301 }
302
303 public function testUserPropParameter() {
304 $userEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
305 $anonEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPageA' );
306 $this->doPageEdit( $this->getLoggedInTestUser(), $userEditTarget, 'Create the page' );
307 $this->doAnonPageEdit( $anonEditTarget, 'Create the page' );
308
309 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'user', ] );
310
311 $this->assertEquals(
312 [
313 [
314 'type' => 'new',
315 'anon' => true,
316 'user' => User::newFromId( 0 )->getName(),
317 ],
318 [
319 'type' => 'new',
320 'user' => $this->getLoggedInTestUser()->getName(),
321 ],
322 ],
324 );
325 }
326
327 public function testUserIdPropParameter() {
328 $user = $this->getLoggedInTestUser();
329 $userEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
330 $anonEditTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPageA' );
331 $this->doPageEdit( $user, $userEditTarget, 'Create the page' );
332 $this->doAnonPageEdit( $anonEditTarget, 'Create the page' );
333
334 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'userid', ] );
335
336 $this->assertEquals(
337 [
338 [
339 'type' => 'new',
340 'anon' => true,
341 'userid' => 0,
342 ],
343 [
344 'type' => 'new',
345 'userid' => $user->getId(),
346 ],
347 ],
348 $this->getItemsFromApiResponse( $result )
349 );
350 }
351
352 public function testCommentPropParameter() {
353 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
354 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' );
355
356 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'comment', ] );
357
358 $this->assertEquals(
359 [
360 [
361 'type' => 'new',
362 'comment' => 'Create the <b>page</b>',
363 ],
364 ],
366 );
367 }
368
370 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
371 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' );
372
373 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'parsedcomment', ] );
374
375 $this->assertEquals(
376 [
377 [
378 'type' => 'new',
379 'parsedcomment' => 'Create the &lt;b&gt;page&lt;/b&gt;',
380 ],
381 ],
383 );
384 }
385
386 public function testTimestampPropParameter() {
387 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
388 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
389
390 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'timestamp', ] );
391 $items = $this->getItemsFromApiResponse( $result );
392
393 $this->assertCount( 1, $items );
394 $this->assertArrayHasKey( 'timestamp', $items[0] );
395 $this->assertInternalType( 'string', $items[0]['timestamp'] );
396 }
397
398 public function testSizesPropParameter() {
399 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
400 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
401
402 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'sizes', ] );
403
404 $this->assertEquals(
405 [
406 [
407 'type' => 'new',
408 'oldlen' => 0,
409 'newlen' => 38,
410 ],
411 ],
413 );
414 }
415
416 private function createPageAndDeleteIt( LinkTarget $target ) {
417 $this->doPageEdit( $this->getLoggedInTestUser(),
418 $target,
419 'Create the page that will be deleted'
420 );
421 $this->deletePage( $target, 'Important Reason' );
422 }
423
424 public function testLoginfoPropParameter() {
425 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
426 $this->createPageAndDeleteIt( $target );
427
428 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'loginfo', ] );
429
430 $items = $this->getItemsFromApiResponse( $result );
431 $this->assertCount( 1, $items );
432 $this->assertArraySubset(
433 [
434 'type' => 'log',
435 'logtype' => 'delete',
436 'logaction' => 'delete',
437 'logparams' => [],
438 ],
439 $items[0]
440 );
441 $this->assertArrayHasKey( 'logid', $items[0] );
442 }
443
444 public function testEmptyPropParameter() {
445 $user = $this->getLoggedInTestUser();
446 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
447 $this->doPageEdit( $user, $target, 'Create the page' );
448
449 $result = $this->doListRecentChangesRequest( [ 'rcprop' => '', ] );
450
451 $this->assertEquals(
452 [
453 [
454 'type' => 'new',
455 ]
456 ],
458 );
459 }
460
461 public function testNamespaceParam() {
462 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
463 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
464 $this->doPageEdits(
465 $this->getLoggedInTestUser(),
466 [
467 [
468 'target' => $subjectTarget,
469 'summary' => 'Create the page',
470 ],
471 [
472 'target' => $talkTarget,
473 'summary' => 'Create the talk page',
474 ],
475 ]
476 );
477
478 $result = $this->doListRecentChangesRequest( [ 'rcnamespace' => '0', ] );
479
480 $items = $this->getItemsFromApiResponse( $result );
481 $this->assertCount( 1, $items );
482 $this->assertArraySubset(
483 [
484 'ns' => 0,
485 'title' => $this->getPrefixedText( $subjectTarget ),
486 ],
487 $items[0]
488 );
489 }
490
491 public function testShowAnonParams() {
492 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
493 $this->doAnonPageEdit( $target, 'Create the page' );
494
495 $resultAnon = $this->doListRecentChangesRequest( [
496 'rcprop' => 'user',
497 'rcshow' => WatchedItemQueryService::FILTER_ANON
498 ] );
499 $resultNotAnon = $this->doListRecentChangesRequest( [
500 'rcprop' => 'user',
501 'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON
502 ] );
503
504 $items = $this->getItemsFromApiResponse( $resultAnon );
505 $this->assertCount( 1, $items );
506 $this->assertArraySubset( [ 'anon' => true ], $items[0] );
507 $this->assertEmpty( $this->getItemsFromApiResponse( $resultNotAnon ) );
508 }
509
511 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
512 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
513 $this->doPageEdits(
514 $this->getLoggedInTestUser(),
515 [
516 [
517 'target' => $subjectTarget,
518 'summary' => 'Create the page',
519 ],
520 [
521 'target' => $subjectTarget,
522 'summary' => 'Change the content',
523 ],
524 [
525 'target' => $talkTarget,
526 'summary' => 'Create Talk page',
527 ],
528 ]
529 );
530
531 $resultNew = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'new' ] );
532 $resultEdit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'edit' ] );
533
534 $this->assertEquals(
535 [
536 [
537 'type' => 'new',
538 'ns' => $talkTarget->getNamespace(),
539 'title' => $this->getPrefixedText( $talkTarget ),
540 ],
541 [
542 'type' => 'new',
543 'ns' => $subjectTarget->getNamespace(),
544 'title' => $this->getPrefixedText( $subjectTarget ),
545 ],
546 ],
547 $this->getItemsFromApiResponse( $resultNew )
548 );
549 $this->assertEquals(
550 [
551 [
552 'type' => 'edit',
553 'ns' => $subjectTarget->getNamespace(),
554 'title' => $this->getPrefixedText( $subjectTarget ),
555 ],
556 ],
557 $this->getItemsFromApiResponse( $resultEdit )
558 );
559 }
560
561 public function testLogTypeParameters() {
562 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
563 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
564 $this->createPageAndDeleteIt( $subjectTarget );
565 $this->doPageEdit( $this->getLoggedInTestUser(), $talkTarget, 'Create Talk page' );
566
567 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'log' ] );
568
569 $this->assertEquals(
570 [
571 [
572 'type' => 'log',
573 'ns' => $subjectTarget->getNamespace(),
574 'title' => $this->getPrefixedText( $subjectTarget ),
575 ],
576 ],
577 $this->getItemsFromApiResponse( $result )
578 );
579 }
580
581 private function getExternalRC( LinkTarget $target ) {
582 $title = Title::newFromLinkTarget( $target );
583
584 $rc = new RecentChange;
585 $rc->mTitle = $title;
586 $rc->mAttribs = [
587 'rc_timestamp' => wfTimestamp( TS_MW ),
588 'rc_namespace' => $title->getNamespace(),
589 'rc_title' => $title->getDBkey(),
590 'rc_type' => RC_EXTERNAL,
591 'rc_source' => 'foo',
592 'rc_minor' => 0,
593 'rc_cur_id' => $title->getArticleID(),
594 'rc_user' => 0,
595 'rc_user_text' => 'm>External User',
596 'rc_comment' => '',
597 'rc_comment_text' => '',
598 'rc_comment_data' => null,
599 'rc_this_oldid' => $title->getLatestRevID(),
600 'rc_last_oldid' => $title->getLatestRevID(),
601 'rc_bot' => 0,
602 'rc_ip' => '',
603 'rc_patrolled' => 0,
604 'rc_new' => 0,
605 'rc_old_len' => $title->getLength(),
606 'rc_new_len' => $title->getLength(),
607 'rc_deleted' => 0,
608 'rc_logid' => 0,
609 'rc_log_type' => null,
610 'rc_log_action' => '',
611 'rc_params' => '',
612 ];
613 $rc->mExtra = [
614 'prefixedDBkey' => $title->getPrefixedDBkey(),
615 'lastTimestamp' => 0,
616 'oldSize' => $title->getLength(),
617 'newSize' => $title->getLength(),
618 'pageStatus' => 'changed'
619 ];
620
621 return $rc;
622 }
623
624 public function testExternalTypeParameters() {
625 $user = $this->getLoggedInTestUser();
626 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
627 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
628 $this->doPageEdit( $user, $subjectTarget, 'Create the page' );
629 $this->doPageEdit( $user, $talkTarget, 'Create Talk page' );
630
631 $rc = $this->getExternalRC( $subjectTarget );
632 $rc->save();
633
634 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'external' ] );
635
636 $this->assertEquals(
637 [
638 [
639 'type' => 'external',
640 'ns' => $subjectTarget->getNamespace(),
641 'title' => $this->getPrefixedText( $subjectTarget ),
642 ],
643 ],
644 $this->getItemsFromApiResponse( $result )
645 );
646 }
647
648 public function testCategorizeTypeParameter() {
649 $user = $this->getLoggedInTestUser();
650 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
651 $categoryTarget = new TitleValue( NS_CATEGORY, 'ApiQueryRecentChangesIntegrationTestCategory' );
652 $this->doPageEdits(
653 $user,
654 [
655 [
656 'target' => $categoryTarget,
657 'summary' => 'Create the category',
658 ],
659 [
660 'target' => $subjectTarget,
661 'summary' => 'Create the page and add it to the category',
662 ],
663 ]
664 );
665 $title = Title::newFromLinkTarget( $subjectTarget );
666 $revision = Revision::newFromTitle( $title );
667
668 $rc = RecentChange::newForCategorization(
669 $revision->getTimestamp(),
670 Title::newFromLinkTarget( $categoryTarget ),
671 $user,
672 $revision->getComment(),
673 $title,
674 0,
675 $revision->getId(),
676 null,
677 false
678 );
679 $rc->save();
680
681 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'categorize' ] );
682
683 $this->assertEquals(
684 [
685 [
686 'type' => 'categorize',
687 'ns' => $categoryTarget->getNamespace(),
688 'title' => $this->getPrefixedText( $categoryTarget ),
689 ],
690 ],
691 $this->getItemsFromApiResponse( $result )
692 );
693 }
694
695 public function testLimitParam() {
696 $target1 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
697 $target2 = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
698 $target3 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage2' );
699 $this->doPageEdits(
700 $this->getLoggedInTestUser(),
701 [
702 [
703 'target' => $target1,
704 'summary' => 'Create the page',
705 ],
706 [
707 'target' => $target2,
708 'summary' => 'Create Talk page',
709 ],
710 [
711 'target' => $target3,
712 'summary' => 'Create the page',
713 ],
714 ]
715 );
716
717 $resultWithoutLimit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] );
718 $resultWithLimit = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] );
719
720 $this->assertEquals(
721 [
722 [
723 'type' => 'new',
724 'ns' => $target3->getNamespace(),
725 'title' => $this->getPrefixedText( $target3 )
726 ],
727 [
728 'type' => 'new',
729 'ns' => $target2->getNamespace(),
730 'title' => $this->getPrefixedText( $target2 )
731 ],
732 [
733 'type' => 'new',
734 'ns' => $target1->getNamespace(),
735 'title' => $this->getPrefixedText( $target1 )
736 ],
737 ],
738 $this->getItemsFromApiResponse( $resultWithoutLimit )
739 );
740 $this->assertEquals(
741 [
742 [
743 'type' => 'new',
744 'ns' => $target3->getNamespace(),
745 'title' => $this->getPrefixedText( $target3 )
746 ],
747 [
748 'type' => 'new',
749 'ns' => $target2->getNamespace(),
750 'title' => $this->getPrefixedText( $target2 )
751 ],
752 ],
753 $this->getItemsFromApiResponse( $resultWithLimit )
754 );
755 $this->assertArrayHasKey( 'continue', $resultWithLimit[0] );
756 $this->assertArrayHasKey( 'rccontinue', $resultWithLimit[0]['continue'] );
757 }
758
759 public function testAllRevParam() {
760 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
761 $this->doPageEdits(
762 $this->getLoggedInTestUser(),
763 [
764 [
765 'target' => $target,
766 'summary' => 'Create the page',
767 ],
768 [
769 'target' => $target,
770 'summary' => 'Change the content',
771 ],
772 ]
773 );
774
775 $resultAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rcallrev' => '', ] );
776 $resultNoAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] );
777
778 $this->assertEquals(
779 [
780 [
781 'type' => 'edit',
782 'ns' => $target->getNamespace(),
783 'title' => $this->getPrefixedText( $target ),
784 ],
785 [
786 'type' => 'new',
787 'ns' => $target->getNamespace(),
788 'title' => $this->getPrefixedText( $target ),
789 ],
790 ],
791 $this->getItemsFromApiResponse( $resultNoAllRev )
792 );
793 $this->assertEquals(
794 [
795 [
796 'type' => 'edit',
797 'ns' => $target->getNamespace(),
798 'title' => $this->getPrefixedText( $target ),
799 ],
800 [
801 'type' => 'new',
802 'ns' => $target->getNamespace(),
803 'title' => $this->getPrefixedText( $target ),
804 ],
805 ],
806 $this->getItemsFromApiResponse( $resultAllRev )
807 );
808 }
809
810 public function testDirParams() {
811 $subjectTarget = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
812 $talkTarget = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
813 $this->doPageEdits(
814 $this->getLoggedInTestUser(),
815 [
816 [
817 'target' => $subjectTarget,
818 'summary' => 'Create the page',
819 ],
820 [
821 'target' => $talkTarget,
822 'summary' => 'Create Talk page',
823 ],
824 ]
825 );
826
827 $resultDirOlder = $this->doListRecentChangesRequest(
828 [ 'rcdir' => 'older', 'rcprop' => 'title' ]
829 );
830 $resultDirNewer = $this->doListRecentChangesRequest(
831 [ 'rcdir' => 'newer', 'rcprop' => 'title' ]
832 );
833
834 $this->assertEquals(
835 [
836 [
837 'type' => 'new',
838 'ns' => $talkTarget->getNamespace(),
839 'title' => $this->getPrefixedText( $talkTarget )
840 ],
841 [
842 'type' => 'new',
843 'ns' => $subjectTarget->getNamespace(),
844 'title' => $this->getPrefixedText( $subjectTarget )
845 ],
846 ],
847 $this->getItemsFromApiResponse( $resultDirOlder )
848 );
849 $this->assertEquals(
850 [
851 [
852 'type' => 'new',
853 'ns' => $subjectTarget->getNamespace(),
854 'title' => $this->getPrefixedText( $subjectTarget )
855 ],
856 [
857 'type' => 'new',
858 'ns' => $talkTarget->getNamespace(),
859 'title' => $this->getPrefixedText( $talkTarget )
860 ],
861 ],
862 $this->getItemsFromApiResponse( $resultDirNewer )
863 );
864 }
865
866 public function testStartEndParams() {
867 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
868 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
869
870 $resultStart = $this->doListRecentChangesRequest( [
871 'rcstart' => '20010115000000',
872 'rcdir' => 'newer',
873 'rcprop' => 'title',
874 ] );
875 $resultEnd = $this->doListRecentChangesRequest( [
876 'rcend' => '20010115000000',
877 'rcdir' => 'newer',
878 'rcprop' => 'title',
879 ] );
880
881 $this->assertEquals(
882 [
883 [
884 'type' => 'new',
885 'ns' => $target->getNamespace(),
886 'title' => $this->getPrefixedText( $target ),
887 ]
888 ],
889 $this->getItemsFromApiResponse( $resultStart )
890 );
891 $this->assertEmpty( $this->getItemsFromApiResponse( $resultEnd ) );
892 }
893
894 public function testContinueParam() {
895 $target1 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
896 $target2 = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage' );
897 $target3 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage2' );
898 $this->doPageEdits(
899 $this->getLoggedInTestUser(),
900 [
901 [
902 'target' => $target1,
903 'summary' => 'Create the page',
904 ],
905 [
906 'target' => $target2,
907 'summary' => 'Create Talk page',
908 ],
909 [
910 'target' => $target3,
911 'summary' => 'Create the page',
912 ],
913 ]
914 );
915
916 $firstResult = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] );
917 $this->assertArrayHasKey( 'continue', $firstResult[0] );
918 $this->assertArrayHasKey( 'rccontinue', $firstResult[0]['continue'] );
919
920 $continuationParam = $firstResult[0]['continue']['rccontinue'];
921
922 $continuedResult = $this->doListRecentChangesRequest(
923 [ 'rccontinue' => $continuationParam, 'rcprop' => 'title' ]
924 );
925
926 $this->assertEquals(
927 [
928 [
929 'type' => 'new',
930 'ns' => $target3->getNamespace(),
931 'title' => $this->getPrefixedText( $target3 ),
932 ],
933 [
934 'type' => 'new',
935 'ns' => $target2->getNamespace(),
936 'title' => $this->getPrefixedText( $target2 ),
937 ],
938 ],
939 $this->getItemsFromApiResponse( $firstResult )
940 );
941 $this->assertEquals(
942 [
943 [
944 'type' => 'new',
945 'ns' => $target1->getNamespace(),
946 'title' => $this->getPrefixedText( $target1 )
947 ]
948 ],
949 $this->getItemsFromApiResponse( $continuedResult )
950 );
951 }
952
954 $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
955 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
956
957 $result = $this->doGeneratorRecentChangesRequest( [ 'prop' => 'info' ] );
958
959 $this->assertArrayHasKey( 'query', $result[0] );
960 $this->assertArrayHasKey( 'pages', $result[0]['query'] );
961
962 // $result[0]['query']['pages'] uses page ids as keys. Page ids don't matter here, so drop them
963 $pages = array_values( $result[0]['query']['pages'] );
964
965 $this->assertCount( 1, $pages );
966 $this->assertArraySubset(
967 [
968 'ns' => $target->getNamespace(),
969 'title' => $this->getPrefixedText( $target ),
970 'new' => true,
971 ],
972 $pages[0]
973 );
974 }
975
976}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
doBotPageEdit(User $user, LinkTarget $target, $summary)
doPageEdits(User $user, array $editData)
Performs a batch of page edits as a specified user.
doPageEdit(User $user, LinkTarget $target, $summary)
__construct( $name=null, array $data=[], $dataName='')
doMinorPageEdit(User $user, LinkTarget $target, $summary)
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
A codec for MediaWiki page titles.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Utility class for creating new RC entries.
Represents a page (or page fragment) title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:614
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
const EDIT_FORCE_BOT
Definition Defines.php:166
const RC_EXTERNAL
Definition Defines.php:155
const EDIT_MINOR
Definition Defines.php:164
const NS_CATEGORY
Definition Defines.php:88
the array() calling protocol came about after MediaWiki 1.4rc1.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) '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 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) '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! 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:1993
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
this hook is for auditing only $response
Definition hooks.txt:783
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
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:37
const DB_MASTER
Definition defines.php:29
$params