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