MediaWiki REL1_39
ApiQueryRecentChanges.php
Go to the documentation of this file.
1<?php
33
41
43 private $commentStore;
44
46 private $commentFormatter;
47
49 private $changeTagDefStore;
50
52 private $slotRoleStore;
53
55 private $slotRoleRegistry;
56
57 private $formattedComments = [];
58
68 public function __construct(
69 ApiQuery $query,
70 $moduleName,
71 CommentStore $commentStore,
72 RowCommentFormatter $commentFormatter,
73 NameTableStore $changeTagDefStore,
74 NameTableStore $slotRoleStore,
75 SlotRoleRegistry $slotRoleRegistry
76 ) {
77 parent::__construct( $query, $moduleName, 'rc' );
78 $this->commentStore = $commentStore;
79 $this->commentFormatter = $commentFormatter;
80 $this->changeTagDefStore = $changeTagDefStore;
81 $this->slotRoleStore = $slotRoleStore;
82 $this->slotRoleRegistry = $slotRoleRegistry;
83 }
84
85 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
86 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
87 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
88 $fld_tags = false, $fld_sha1 = false;
89
94 public function initProperties( $prop ) {
95 $this->fld_comment = isset( $prop['comment'] );
96 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
97 $this->fld_user = isset( $prop['user'] );
98 $this->fld_userid = isset( $prop['userid'] );
99 $this->fld_flags = isset( $prop['flags'] );
100 $this->fld_timestamp = isset( $prop['timestamp'] );
101 $this->fld_title = isset( $prop['title'] );
102 $this->fld_ids = isset( $prop['ids'] );
103 $this->fld_sizes = isset( $prop['sizes'] );
104 $this->fld_redirect = isset( $prop['redirect'] );
105 $this->fld_patrolled = isset( $prop['patrolled'] );
106 $this->fld_loginfo = isset( $prop['loginfo'] );
107 $this->fld_tags = isset( $prop['tags'] );
108 $this->fld_sha1 = isset( $prop['sha1'] );
109 }
110
111 public function execute() {
112 $this->run();
113 }
114
115 public function executeGenerator( $resultPageSet ) {
116 $this->run( $resultPageSet );
117 }
118
124 public function run( $resultPageSet = null ) {
125 $user = $this->getUser();
126 /* Get the parameters of the request. */
127 $params = $this->extractRequestParams();
128
129 /* Build our basic query. Namely, something along the lines of:
130 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
131 * AND rc_timestamp < $end AND rc_namespace = $namespace
132 */
133 $this->addTables( 'recentchanges' );
134 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
135
136 if ( $params['continue'] !== null ) {
137 $cont = explode( '|', $params['continue'] );
138 $this->dieContinueUsageIf( count( $cont ) != 2 );
139 $db = $this->getDB();
140 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
141 $id = (int)$cont[1];
142 $this->dieContinueUsageIf( $id != $cont[1] );
143 $op = $params['dir'] === 'older' ? '<' : '>';
144 $this->addWhere(
145 "rc_timestamp $op $timestamp OR " .
146 "(rc_timestamp = $timestamp AND " .
147 "rc_id $op= $id)"
148 );
149 }
150
151 $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
152 $this->addOption( 'ORDER BY', [
153 "rc_timestamp $order",
154 "rc_id $order",
155 ] );
156
157 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
158
159 if ( $params['type'] !== null ) {
160 try {
161 $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
162 } catch ( Exception $e ) {
163 ApiBase::dieDebug( __METHOD__, $e->getMessage() );
164 }
165 }
166
167 $title = $params['title'];
168 if ( $title !== null ) {
169 $titleObj = Title::newFromText( $title );
170 if ( $titleObj === null || $titleObj->isExternal() ) {
171 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
172 }
173 $this->addWhereFld( 'rc_namespace', $titleObj->getNamespace() );
174 $this->addWhereFld( 'rc_title', $titleObj->getDBkey() );
175 }
176
177 if ( $params['show'] !== null ) {
178 $show = array_fill_keys( $params['show'], true );
179
180 /* Check for conflicting parameters. */
181 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
182 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
183 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
184 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
185 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
186 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
187 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
188 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
189 || ( isset( $show['autopatrolled'] ) && isset( $show['unpatrolled'] ) )
190 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
191 ) {
192 $this->dieWithError( 'apierror-show' );
193 }
194
195 // Check permissions
196 if ( $this->includesPatrollingFlags( $show ) && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
197 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
198 }
199
200 /* Add additional conditions to query depending upon parameters. */
201 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
202 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
203 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
204 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
205 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
206 $this->addTables( 'actor', 'actor' );
207 $this->addJoinConds( [ 'actor' => [ 'JOIN', 'actor_id=rc_actor' ] ] );
208 $this->addWhereIf(
209 'actor_user IS NULL', isset( $show['anon'] )
210 );
211 $this->addWhereIf(
212 'actor_user IS NOT NULL', isset( $show['!anon'] )
213 );
214 }
215 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
216 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
217 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
218
219 if ( isset( $show['unpatrolled'] ) ) {
220 // See ChangesList::isUnpatrolled
221 if ( $user->useRCPatrol() ) {
222 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
223 } elseif ( $user->useNPPatrol() ) {
224 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
225 $this->addWhereFld( 'rc_type', RC_NEW );
226 }
227 }
228
229 $this->addWhereIf(
230 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
231 isset( $show['!autopatrolled'] )
232 );
233 $this->addWhereIf(
234 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
235 isset( $show['autopatrolled'] )
236 );
237
238 // Don't throw log entries out the window here
239 $this->addWhereIf(
240 'page_is_redirect = 0 OR page_is_redirect IS NULL',
241 isset( $show['!redirect'] )
242 );
243 }
244
245 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
246
247 if ( $params['prop'] !== null ) {
248 $prop = array_fill_keys( $params['prop'], true );
249
250 /* Set up internal members based upon params. */
251 $this->initProperties( $prop );
252 }
253
254 if ( $this->fld_user
255 || $this->fld_userid
256 || $params['user'] !== null
257 || $params['excludeuser'] !== null
258 ) {
259 $this->addTables( 'actor', 'actor' );
260 $this->addFields( [ 'actor_name', 'actor_user', 'rc_actor' ] );
261 $this->addJoinConds( [ 'actor' => [ 'JOIN', 'actor_id=rc_actor' ] ] );
262 }
263
264 if ( $params['user'] !== null ) {
265 $this->addWhereFld( 'actor_name', $params['user'] );
266 }
267
268 if ( $params['excludeuser'] !== null ) {
269 $this->addWhere( 'actor_name<>' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
270 }
271
272 /* Add the fields we're concerned with to our query. */
273 $this->addFields( [
274 'rc_id',
275 'rc_timestamp',
276 'rc_namespace',
277 'rc_title',
278 'rc_cur_id',
279 'rc_type',
280 'rc_deleted'
281 ] );
282
283 $showRedirects = false;
284 /* Determine what properties we need to display. */
285 if ( $params['prop'] !== null ) {
286 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
287 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
288 }
289
290 /* Add fields to our query if they are specified as a needed parameter. */
291 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
292 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
293 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
294 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
295 $this->addFieldsIf(
296 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
297 $this->fld_loginfo
298 );
299 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
300 || isset( $show['!redirect'] );
301 }
302 $this->addFieldsIf( [ 'rc_this_oldid' ],
303 $resultPageSet && $params['generaterevisions'] );
304
305 if ( $this->fld_tags ) {
306 $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'recentchanges' ) ] );
307 }
308
309 if ( $this->fld_sha1 ) {
310 $this->addTables( 'revision' );
311 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
312 [ 'rc_this_oldid=rev_id' ] ] ] );
313 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
314 }
315
316 if ( $params['toponly'] || $showRedirects ) {
317 $this->addTables( 'page' );
318 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
319 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
320 $this->addFields( 'page_is_redirect' );
321
322 if ( $params['toponly'] ) {
323 $this->addWhere( 'rc_this_oldid = page_latest' );
324 }
325 }
326
327 if ( $params['tag'] !== null ) {
328 $this->addTables( 'change_tag' );
329 $this->addJoinConds( [ 'change_tag' => [ 'JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
330 try {
331 $this->addWhereFld( 'ct_tag_id', $this->changeTagDefStore->getId( $params['tag'] ) );
332 } catch ( NameTableAccessException $exception ) {
333 // Return nothing.
334 $this->addWhere( '1=0' );
335 }
336 }
337
338 // Paranoia: avoid brute force searches (T19342)
339 if ( $params['user'] !== null || $params['excludeuser'] !== null ) {
340 if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
341 $bitmask = RevisionRecord::DELETED_USER;
342 } elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
343 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
344 } else {
345 $bitmask = 0;
346 }
347 if ( $bitmask ) {
348 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
349 }
350 }
351 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
352 // LogPage::DELETED_ACTION hides the affected page, too.
353 if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
354 $bitmask = LogPage::DELETED_ACTION;
355 } elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
357 } else {
358 $bitmask = 0;
359 }
360 if ( $bitmask ) {
361 $this->addWhere( $this->getDB()->makeList( [
362 'rc_type != ' . RC_LOG,
363 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
364 ], LIST_OR ) );
365 }
366 }
367
368 if ( $this->fld_comment || $this->fld_parsedcomment ) {
369 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
370 $this->addTables( $commentQuery['tables'] );
371 $this->addFields( $commentQuery['fields'] );
372 $this->addJoinConds( $commentQuery['joins'] );
373 }
374
375 if ( $params['slot'] !== null ) {
376 try {
377 $slotId = $this->slotRoleStore->getId( $params['slot'] );
378 } catch ( Exception $e ) {
379 $slotId = null;
380 }
381
382 $this->addTables( [
383 'slot' => 'slots', 'parent_slot' => 'slots'
384 ] );
385 $this->addJoinConds( [
386 'slot' => [ 'LEFT JOIN', [
387 'rc_this_oldid = slot.slot_revision_id',
388 'slot.slot_role_id' => $slotId,
389 ] ],
390 'parent_slot' => [ 'LEFT JOIN', [
391 'rc_last_oldid = parent_slot.slot_revision_id',
392 'parent_slot.slot_role_id' => $slotId,
393 ] ]
394 ] );
395 // Detecting whether the slot has been touched as follows:
396 // 1. if slot_origin=slot_revision_id then the slot has been newly created or edited
397 // with this revision
398 // 2. otherwise if the content of a slot is different to the content of its parent slot,
399 // then the content of the slot has been changed in this revision
400 // (probably by a revert)
401 $this->addWhere(
402 'slot.slot_origin = slot.slot_revision_id OR ' .
403 'slot.slot_content_id != parent_slot.slot_content_id OR ' .
404 '(slot.slot_content_id IS NULL AND parent_slot.slot_content_id IS NOT NULL) OR ' .
405 '(slot.slot_content_id IS NOT NULL AND parent_slot.slot_content_id IS NULL)'
406 );
407 // Only include changes that touch page content (i.e. RC_NEW, RC_EDIT)
408 $changeTypes = RecentChange::parseToRCType(
409 array_intersect( $params['type'], [ 'new', 'edit' ] )
410 );
411 if ( count( $changeTypes ) ) {
412 $this->addWhereFld( 'rc_type', $changeTypes );
413 } else {
414 // Calling $this->addWhere() with an empty array does nothing, so explicitly
415 // add an unsatisfiable condition
416 $this->addWhere( 'rc_type IS NULL' );
417 }
418 }
419
420 $this->addOption( 'LIMIT', $params['limit'] + 1 );
421 $this->addOption(
422 'MAX_EXECUTION_TIME',
423 $this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
424 );
425
426 $hookData = [];
427 $count = 0;
428 /* Perform the actual query. */
429 $res = $this->select( __METHOD__, [], $hookData );
430
431 // Do batch queries
432 if ( $this->fld_title && $resultPageSet === null ) {
433 $this->executeGenderCacheFromResultWrapper( $res, __METHOD__, 'rc' );
434 }
435 if ( $this->fld_parsedcomment ) {
436 $this->formattedComments = $this->commentFormatter->formatItems(
437 $this->commentFormatter->rows( $res )
438 ->indexField( 'rc_id' )
439 ->commentKey( 'rc_comment' )
440 ->namespaceField( 'rc_namespace' )
441 ->titleField( 'rc_title' )
442 );
443 }
444
445 $revids = [];
446 $titles = [];
447
448 $result = $this->getResult();
449
450 /* Iterate through the rows, adding data extracted from them to our query result. */
451 foreach ( $res as $row ) {
452 if ( $count === 0 && $resultPageSet !== null ) {
453 // Set the non-continue since the list of recentchanges is
454 // prone to having entries added at the start frequently.
455 $this->getContinuationManager()->addGeneratorNonContinueParam(
456 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
457 );
458 }
459 if ( ++$count > $params['limit'] ) {
460 // We've reached the one extra which shows that there are
461 // additional pages to be had. Stop here...
462 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
463 break;
464 }
465
466 if ( $resultPageSet === null ) {
467 /* Extract the data from a single row. */
468 $vals = $this->extractRowInfo( $row );
469
470 /* Add that row's data to our final output. */
471 $fit = $this->processRow( $row, $vals, $hookData ) &&
472 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
473 if ( !$fit ) {
474 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
475 break;
476 }
477 } elseif ( $params['generaterevisions'] ) {
478 $revid = (int)$row->rc_this_oldid;
479 if ( $revid > 0 ) {
480 $revids[] = $revid;
481 }
482 } else {
483 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
484 }
485 }
486
487 if ( $resultPageSet === null ) {
488 /* Format the result */
489 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
490 } elseif ( $params['generaterevisions'] ) {
491 $resultPageSet->populateFromRevisionIDs( $revids );
492 } else {
493 $resultPageSet->populateFromTitles( $titles );
494 }
495 }
496
503 public function extractRowInfo( $row ) {
504 /* Determine the title of the page that has been changed. */
505 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
506 $user = $this->getUser();
507
508 /* Our output data. */
509 $vals = [];
510
511 $type = (int)$row->rc_type;
512 $vals['type'] = RecentChange::parseFromRCType( $type );
513
514 $anyHidden = false;
515
516 /* Create a new entry in the result for the title. */
517 if ( $this->fld_title || $this->fld_ids ) {
518 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
519 $vals['actionhidden'] = true;
520 $anyHidden = true;
521 }
522 if ( $type !== RC_LOG ||
523 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
524 ) {
525 if ( $this->fld_title ) {
527 }
528 if ( $this->fld_ids ) {
529 $vals['pageid'] = (int)$row->rc_cur_id;
530 $vals['revid'] = (int)$row->rc_this_oldid;
531 $vals['old_revid'] = (int)$row->rc_last_oldid;
532 }
533 }
534 }
535
536 if ( $this->fld_ids ) {
537 $vals['rcid'] = (int)$row->rc_id;
538 }
539
540 /* Add user data and 'anon' flag, if user is anonymous. */
541 if ( $this->fld_user || $this->fld_userid ) {
542 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
543 $vals['userhidden'] = true;
544 $anyHidden = true;
545 }
546 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
547 if ( $this->fld_user ) {
548 $vals['user'] = $row->actor_name;
549 }
550
551 if ( $this->fld_userid ) {
552 $vals['userid'] = (int)$row->actor_user;
553 }
554
555 if ( !$row->actor_user ) {
556 $vals['anon'] = true;
557 }
558 }
559 }
560
561 /* Add flags, such as new, minor, bot. */
562 if ( $this->fld_flags ) {
563 $vals['bot'] = (bool)$row->rc_bot;
564 $vals['new'] = $row->rc_type == RC_NEW;
565 $vals['minor'] = (bool)$row->rc_minor;
566 }
567
568 /* Add sizes of each revision. (Only available on 1.10+) */
569 if ( $this->fld_sizes ) {
570 $vals['oldlen'] = (int)$row->rc_old_len;
571 $vals['newlen'] = (int)$row->rc_new_len;
572 }
573
574 /* Add the timestamp. */
575 if ( $this->fld_timestamp ) {
576 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
577 }
578
579 /* Add edit summary / log summary. */
580 if ( $this->fld_comment || $this->fld_parsedcomment ) {
581 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
582 $vals['commenthidden'] = true;
583 $anyHidden = true;
584 }
585 if ( RevisionRecord::userCanBitfield(
586 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
587 ) ) {
588 if ( $this->fld_comment ) {
589 $vals['comment'] = $this->commentStore->getComment( 'rc_comment', $row )->text;
590 }
591
592 if ( $this->fld_parsedcomment ) {
593 $vals['parsedcomment'] = $this->formattedComments[$row->rc_id];
594 }
595 }
596 }
597
598 if ( $this->fld_redirect ) {
599 $vals['redirect'] = (bool)$row->page_is_redirect;
600 }
601
602 /* Add the patrolled flag */
603 if ( $this->fld_patrolled ) {
604 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
605 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
606 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
607 }
608
609 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
610 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
611 $vals['actionhidden'] = true;
612 $anyHidden = true;
613 }
614 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
615 $vals['logid'] = (int)$row->rc_logid;
616 $vals['logtype'] = $row->rc_log_type;
617 $vals['logaction'] = $row->rc_log_action;
618 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
619 }
620 }
621
622 if ( $this->fld_tags ) {
623 if ( $row->ts_tags ) {
624 $tags = explode( ',', $row->ts_tags );
625 ApiResult::setIndexedTagName( $tags, 'tag' );
626 $vals['tags'] = $tags;
627 } else {
628 $vals['tags'] = [];
629 }
630 }
631
632 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
633 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
634 $vals['sha1hidden'] = true;
635 $anyHidden = true;
636 }
637 if ( RevisionRecord::userCanBitfield(
638 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
639 ) ) {
640 if ( $row->rev_sha1 !== '' ) {
641 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
642 } else {
643 $vals['sha1'] = '';
644 }
645 }
646 }
647
648 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
649 $vals['suppressed'] = true;
650 }
651
652 return $vals;
653 }
654
659 private function includesPatrollingFlags( array $flagsArray ) {
660 return isset( $flagsArray['patrolled'] ) ||
661 isset( $flagsArray['!patrolled'] ) ||
662 isset( $flagsArray['unpatrolled'] ) ||
663 isset( $flagsArray['autopatrolled'] ) ||
664 isset( $flagsArray['!autopatrolled'] );
665 }
666
667 public function getCacheMode( $params ) {
668 if ( isset( $params['show'] ) &&
669 $this->includesPatrollingFlags( array_fill_keys( $params['show'], true ) )
670 ) {
671 return 'private';
672 }
673 if ( $this->userCanSeeRevDel() ) {
674 return 'private';
675 }
676 if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
677 // formatComment() calls wfMessage() among other things
678 return 'anon-public-user-private';
679 }
680
681 return 'public';
682 }
683
684 public function getAllowedParams() {
685 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
686 sort( $slotRoles, SORT_STRING );
687
688 return [
689 'start' => [
690 ParamValidator::PARAM_TYPE => 'timestamp'
691 ],
692 'end' => [
693 ParamValidator::PARAM_TYPE => 'timestamp'
694 ],
695 'dir' => [
696 ParamValidator::PARAM_DEFAULT => 'older',
697 ParamValidator::PARAM_TYPE => [
698 'newer',
699 'older'
700 ],
701 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
703 'newer' => 'api-help-paramvalue-direction-newer',
704 'older' => 'api-help-paramvalue-direction-older',
705 ],
706 ],
707 'namespace' => [
708 ParamValidator::PARAM_ISMULTI => true,
709 ParamValidator::PARAM_TYPE => 'namespace',
710 NamespaceDef::PARAM_EXTRA_NAMESPACES => [ NS_MEDIA, NS_SPECIAL ],
711 ],
712 'user' => [
713 ParamValidator::PARAM_TYPE => 'user',
714 UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'id', 'interwiki' ],
715 ],
716 'excludeuser' => [
717 ParamValidator::PARAM_TYPE => 'user',
718 UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'id', 'interwiki' ],
719 ],
720 'tag' => null,
721 'prop' => [
722 ParamValidator::PARAM_ISMULTI => true,
723 ParamValidator::PARAM_DEFAULT => 'title|timestamp|ids',
724 ParamValidator::PARAM_TYPE => [
725 'user',
726 'userid',
727 'comment',
728 'parsedcomment',
729 'flags',
730 'timestamp',
731 'title',
732 'ids',
733 'sizes',
734 'redirect',
735 'patrolled',
736 'loginfo',
737 'tags',
738 'sha1',
739 ],
741 ],
742 'show' => [
743 ParamValidator::PARAM_ISMULTI => true,
744 ParamValidator::PARAM_TYPE => [
745 'minor',
746 '!minor',
747 'bot',
748 '!bot',
749 'anon',
750 '!anon',
751 'redirect',
752 '!redirect',
753 'patrolled',
754 '!patrolled',
755 'unpatrolled',
756 'autopatrolled',
757 '!autopatrolled',
758 ]
759 ],
760 'limit' => [
761 ParamValidator::PARAM_DEFAULT => 10,
762 ParamValidator::PARAM_TYPE => 'limit',
763 IntegerDef::PARAM_MIN => 1,
764 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
765 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
766 ],
767 'type' => [
768 ParamValidator::PARAM_DEFAULT => 'edit|new|log|categorize',
769 ParamValidator::PARAM_ISMULTI => true,
770 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
771 ],
772 'toponly' => false,
773 'title' => null,
774 'continue' => [
775 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
776 ],
777 'generaterevisions' => false,
778 'slot' => [
779 ParamValidator::PARAM_TYPE => $slotRoles
780 ],
781 ];
782 }
783
784 protected function getExamplesMessages() {
785 return [
786 'action=query&list=recentchanges'
787 => 'apihelp-query+recentchanges-example-simple',
788 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
789 => 'apihelp-query+recentchanges-example-generator',
790 ];
791 }
792
793 public function getHelpUrls() {
794 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
795 }
796}
getUser()
getAuthority()
const RC_NEW
Definition Defines.php:117
const NS_SPECIAL
Definition Defines.php:53
const LIST_OR
Definition Defines.php:46
const RC_LOG
Definition Defines.php:118
const NS_MEDIA
Definition Defines.php:52
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1454
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:1643
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1656
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:196
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:221
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:938
getResult()
Get the result object.
Definition ApiBase.php:629
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:765
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:163
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:223
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:498
getContinuationManager()
Definition ApiBase.php:663
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
A query action to enumerate the recent changes that were done to the wiki.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
initProperties( $prop)
Sets internal state to include the desired properties in the output.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, NameTableStore $changeTagDefStore, NameTableStore $slotRoleStore, SlotRoleRegistry $slotRoleRegistry)
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
This is the main query class.
Definition ApiQuery.php:41
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
Handle database storage of comments such as edit summaries and log reasons.
const DELETED_RESTRICTED
Definition LogPage.php:43
const DELETED_ACTION
Definition LogPage.php:40
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
A class containing constants representing the names of configuration variables.
Type definition for namespace types.
Type definition for user types.
Definition UserDef.php:27
Page revision base class.
A registry service for SlotRoleHandlers, used to define which slot roles are available on which page.
Exception representing a failure to look up a row from a name table.
Service for formatting and validating API parameters.
Type definition for integer types.