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