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