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