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