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