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