MediaWiki  master
ApiQueryRecentChanges.php
Go to the documentation of this file.
1 <?php
26 
34 
35  public function __construct( ApiQuery $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'rc' );
37  }
38 
39  private $commentStore;
40 
41  private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
42  $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
43  $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
44  $fld_tags = false, $fld_sha1 = false, $token = [];
45 
46  private $tokenFunctions;
47 
55  protected function getTokenFunctions() {
56  // Don't call the hooks twice
57  if ( isset( $this->tokenFunctions ) ) {
58  return $this->tokenFunctions;
59  }
60 
61  // If we're in a mode that breaks the same-origin policy, no tokens can
62  // be obtained
63  if ( $this->lacksSameOriginSecurity() ) {
64  return [];
65  }
66 
67  $this->tokenFunctions = [
68  'patrol' => [ self::class, 'getPatrolToken' ]
69  ];
70  Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
71 
72  return $this->tokenFunctions;
73  }
74 
82  public static function getPatrolToken( $pageid, $title, $rc = null ) {
83  global $wgUser;
84 
85  $validTokenUser = false;
86 
87  if ( $rc ) {
88  if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
89  ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
90  ) {
91  $validTokenUser = true;
92  }
93  } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
94  $validTokenUser = true;
95  }
96 
97  if ( $validTokenUser ) {
98  // The patrol token is always the same, let's exploit that
99  static $cachedPatrolToken = null;
100 
101  if ( is_null( $cachedPatrolToken ) ) {
102  $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
103  }
104 
105  return $cachedPatrolToken;
106  }
107 
108  return false;
109  }
110 
115  public function initProperties( $prop ) {
116  $this->fld_comment = isset( $prop['comment'] );
117  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
118  $this->fld_user = isset( $prop['user'] );
119  $this->fld_userid = isset( $prop['userid'] );
120  $this->fld_flags = isset( $prop['flags'] );
121  $this->fld_timestamp = isset( $prop['timestamp'] );
122  $this->fld_title = isset( $prop['title'] );
123  $this->fld_ids = isset( $prop['ids'] );
124  $this->fld_sizes = isset( $prop['sizes'] );
125  $this->fld_redirect = isset( $prop['redirect'] );
126  $this->fld_patrolled = isset( $prop['patrolled'] );
127  $this->fld_loginfo = isset( $prop['loginfo'] );
128  $this->fld_tags = isset( $prop['tags'] );
129  $this->fld_sha1 = isset( $prop['sha1'] );
130  }
131 
132  public function execute() {
133  $this->run();
134  }
135 
136  public function executeGenerator( $resultPageSet ) {
137  $this->run( $resultPageSet );
138  }
139 
145  public function run( $resultPageSet = null ) {
146  $user = $this->getUser();
147  /* Get the parameters of the request. */
148  $params = $this->extractRequestParams();
149 
150  /* Build our basic query. Namely, something along the lines of:
151  * SELECT * FROM recentchanges WHERE rc_timestamp > $start
152  * AND rc_timestamp < $end AND rc_namespace = $namespace
153  */
154  $this->addTables( 'recentchanges' );
155  $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
156 
157  if ( !is_null( $params['continue'] ) ) {
158  $cont = explode( '|', $params['continue'] );
159  $this->dieContinueUsageIf( count( $cont ) != 2 );
160  $db = $this->getDB();
161  $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
162  $id = (int)$cont[1];
163  $this->dieContinueUsageIf( $id != $cont[1] );
164  $op = $params['dir'] === 'older' ? '<' : '>';
165  $this->addWhere(
166  "rc_timestamp $op $timestamp OR " .
167  "(rc_timestamp = $timestamp AND " .
168  "rc_id $op= $id)"
169  );
170  }
171 
172  $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
173  $this->addOption( 'ORDER BY', [
174  "rc_timestamp $order",
175  "rc_id $order",
176  ] );
177 
178  $this->addWhereFld( 'rc_namespace', $params['namespace'] );
179 
180  if ( !is_null( $params['type'] ) ) {
181  try {
182  $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
183  } catch ( Exception $e ) {
184  ApiBase::dieDebug( __METHOD__, $e->getMessage() );
185  }
186  }
187 
188  $title = $params['title'];
189  if ( !is_null( $title ) ) {
190  $titleObj = Title::newFromText( $title );
191  if ( is_null( $titleObj ) ) {
192  $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
193  }
194  $this->addWhereFld( 'rc_namespace', $titleObj->getNamespace() );
195  $this->addWhereFld( 'rc_title', $titleObj->getDBkey() );
196  }
197 
198  if ( !is_null( $params['show'] ) ) {
199  $show = array_flip( $params['show'] );
200 
201  /* Check for conflicting parameters. */
202  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
203  || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
204  || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
205  || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
206  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
207  || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
208  || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
209  || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
210  || ( isset( $show['autopatrolled'] ) && isset( $show['unpatrolled'] ) )
211  || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
212  ) {
213  $this->dieWithError( 'apierror-show' );
214  }
215 
216  // Check permissions
217  if ( isset( $show['patrolled'] )
218  || isset( $show['!patrolled'] )
219  || isset( $show['unpatrolled'] )
220  || isset( $show['autopatrolled'] )
221  || isset( $show['!autopatrolled'] )
222  ) {
223  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
224  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
225  }
226  }
227 
228  /* Add additional conditions to query depending upon parameters. */
229  $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
230  $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
231  $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
232  $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
233  if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
234  $actorMigration = ActorMigration::newMigration();
235  $actorQuery = $actorMigration->getJoin( 'rc_user' );
236  $this->addTables( $actorQuery['tables'] );
237  $this->addJoinConds( $actorQuery['joins'] );
238  $this->addWhereIf(
239  $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
240  );
241  $this->addWhereIf(
242  $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
243  );
244  }
245  $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
246  $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
247  $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
248 
249  if ( isset( $show['unpatrolled'] ) ) {
250  // See ChangesList::isUnpatrolled
251  if ( $user->useRCPatrol() ) {
252  $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
253  } elseif ( $user->useNPPatrol() ) {
254  $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
255  $this->addWhereFld( 'rc_type', RC_NEW );
256  }
257  }
258 
259  $this->addWhereIf(
260  'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
261  isset( $show['!autopatrolled'] )
262  );
263  $this->addWhereIf(
264  'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
265  isset( $show['autopatrolled'] )
266  );
267 
268  // Don't throw log entries out the window here
269  $this->addWhereIf(
270  'page_is_redirect = 0 OR page_is_redirect IS NULL',
271  isset( $show['!redirect'] )
272  );
273  }
274 
275  $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
276 
277  if ( !is_null( $params['user'] ) ) {
278  // Don't query by user ID here, it might be able to use the rc_user_text index.
279  $actorQuery = ActorMigration::newMigration()
280  ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
281  $this->addTables( $actorQuery['tables'] );
282  $this->addJoinConds( $actorQuery['joins'] );
283  $this->addWhere( $actorQuery['conds'] );
284  }
285 
286  if ( !is_null( $params['excludeuser'] ) ) {
287  // Here there's no chance to use the rc_user_text index, so allow ID to be used.
288  $actorQuery = ActorMigration::newMigration()
289  ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
290  $this->addTables( $actorQuery['tables'] );
291  $this->addJoinConds( $actorQuery['joins'] );
292  $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
293  }
294 
295  /* Add the fields we're concerned with to our query. */
296  $this->addFields( [
297  'rc_id',
298  'rc_timestamp',
299  'rc_namespace',
300  'rc_title',
301  'rc_cur_id',
302  'rc_type',
303  'rc_deleted'
304  ] );
305 
306  $showRedirects = false;
307  /* Determine what properties we need to display. */
308  if ( !is_null( $params['prop'] ) ) {
309  $prop = array_flip( $params['prop'] );
310 
311  /* Set up internal members based upon params. */
312  $this->initProperties( $prop );
313 
314  if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
315  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
316  }
317 
318  /* Add fields to our query if they are specified as a needed parameter. */
319  $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
320  if ( $this->fld_user || $this->fld_userid ) {
321  $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
322  $this->addTables( $actorQuery['tables'] );
323  $this->addFields( $actorQuery['fields'] );
324  $this->addJoinConds( $actorQuery['joins'] );
325  }
326  $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
327  $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
328  $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
329  $this->addFieldsIf(
330  [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
331  $this->fld_loginfo
332  );
333  $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
334  || isset( $show['!redirect'] );
335  }
336  $this->addFieldsIf( [ 'rc_this_oldid' ],
337  $resultPageSet && $params['generaterevisions'] );
338 
339  if ( $this->fld_tags ) {
340  $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'recentchanges' ) ] );
341  }
342 
343  if ( $this->fld_sha1 ) {
344  $this->addTables( 'revision' );
345  $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
346  [ 'rc_this_oldid=rev_id' ] ] ] );
347  $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
348  }
349 
350  if ( $params['toponly'] || $showRedirects ) {
351  $this->addTables( 'page' );
352  $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
353  [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
354  $this->addFields( 'page_is_redirect' );
355 
356  if ( $params['toponly'] ) {
357  $this->addWhere( 'rc_this_oldid = page_latest' );
358  }
359  }
360 
361  if ( !is_null( $params['tag'] ) ) {
362  $this->addTables( 'change_tag' );
363  $this->addJoinConds( [ 'change_tag' => [ 'JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
364  $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
365  try {
366  $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
367  } catch ( NameTableAccessException $exception ) {
368  // Return nothing.
369  $this->addWhere( '1=0' );
370  }
371  }
372 
373  // Paranoia: avoid brute force searches (T19342)
374  if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
375  if ( !$user->isAllowed( 'deletedhistory' ) ) {
376  $bitmask = RevisionRecord::DELETED_USER;
377  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
378  $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
379  } else {
380  $bitmask = 0;
381  }
382  if ( $bitmask ) {
383  $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
384  }
385  }
386  if ( $this->getRequest()->getCheck( 'namespace' ) ) {
387  // LogPage::DELETED_ACTION hides the affected page, too.
388  if ( !$user->isAllowed( 'deletedhistory' ) ) {
389  $bitmask = LogPage::DELETED_ACTION;
390  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
392  } else {
393  $bitmask = 0;
394  }
395  if ( $bitmask ) {
396  $this->addWhere( $this->getDB()->makeList( [
397  'rc_type != ' . RC_LOG,
398  $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
399  ], LIST_OR ) );
400  }
401  }
402 
403  $this->token = $params['token'];
404 
405  if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
406  $this->commentStore = CommentStore::getStore();
407  $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
408  $this->addTables( $commentQuery['tables'] );
409  $this->addFields( $commentQuery['fields'] );
410  $this->addJoinConds( $commentQuery['joins'] );
411  }
412 
413  $this->addOption( 'LIMIT', $params['limit'] + 1 );
414 
415  $hookData = [];
416  $count = 0;
417  /* Perform the actual query. */
418  $res = $this->select( __METHOD__, [], $hookData );
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 ( is_null( $resultPageSet ) ) {
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 ( is_null( $resultPageSet ) ) {
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 ||
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->rc_user_text;
524  }
525 
526  if ( $this->fld_userid ) {
527  $vals['userid'] = (int)$row->rc_user;
528  }
529 
530  if ( !$row->rc_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 ( !is_null( $this->token ) ) {
626  foreach ( $this->token as $t ) {
627  $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
628  $title, RecentChange::newFromRow( $row ) );
629  if ( $val === false ) {
630  $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
631  } else {
632  $vals[$t . 'token'] = $val;
633  }
634  }
635  }
636 
637  if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
638  $vals['suppressed'] = true;
639  }
640 
641  return $vals;
642  }
643 
644  public function getCacheMode( $params ) {
645  if ( isset( $params['show'] ) ) {
646  foreach ( $params['show'] as $show ) {
647  if ( $show === 'patrolled' || $show === '!patrolled' ) {
648  return 'private';
649  }
650  }
651  }
652  if ( isset( $params['token'] ) ) {
653  return 'private';
654  }
655  if ( $this->userCanSeeRevDel() ) {
656  return 'private';
657  }
658  if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
659  // formatComment() calls wfMessage() among other things
660  return 'anon-public-user-private';
661  }
662 
663  return 'public';
664  }
665 
666  public function getAllowedParams() {
667  return [
668  'start' => [
669  ApiBase::PARAM_TYPE => 'timestamp'
670  ],
671  'end' => [
672  ApiBase::PARAM_TYPE => 'timestamp'
673  ],
674  'dir' => [
675  ApiBase::PARAM_DFLT => 'older',
677  'newer',
678  'older'
679  ],
680  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
681  ],
682  'namespace' => [
683  ApiBase::PARAM_ISMULTI => true,
684  ApiBase::PARAM_TYPE => 'namespace',
686  ],
687  'user' => [
688  ApiBase::PARAM_TYPE => 'user'
689  ],
690  'excludeuser' => [
691  ApiBase::PARAM_TYPE => 'user'
692  ],
693  'tag' => null,
694  'prop' => [
695  ApiBase::PARAM_ISMULTI => true,
696  ApiBase::PARAM_DFLT => 'title|timestamp|ids',
698  'user',
699  'userid',
700  'comment',
701  'parsedcomment',
702  'flags',
703  'timestamp',
704  'title',
705  'ids',
706  'sizes',
707  'redirect',
708  'patrolled',
709  'loginfo',
710  'tags',
711  'sha1',
712  ],
714  ],
715  'token' => [
717  ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
719  ],
720  'show' => [
721  ApiBase::PARAM_ISMULTI => true,
723  'minor',
724  '!minor',
725  'bot',
726  '!bot',
727  'anon',
728  '!anon',
729  'redirect',
730  '!redirect',
731  'patrolled',
732  '!patrolled',
733  'unpatrolled',
734  'autopatrolled',
735  '!autopatrolled',
736  ]
737  ],
738  'limit' => [
739  ApiBase::PARAM_DFLT => 10,
740  ApiBase::PARAM_TYPE => 'limit',
741  ApiBase::PARAM_MIN => 1,
744  ],
745  'type' => [
746  ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
747  ApiBase::PARAM_ISMULTI => true,
749  ],
750  'toponly' => false,
751  'title' => null,
752  'continue' => [
753  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
754  ],
755  'generaterevisions' => false,
756  ];
757  }
758 
759  protected function getExamplesMessages() {
760  return [
761  'action=query&list=recentchanges'
762  => 'apihelp-query+recentchanges-example-simple',
763  'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
764  => 'apihelp-query+recentchanges-example-generator',
765  ];
766  }
767 
768  public function getHelpUrls() {
769  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
770  }
771 }
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:87
getDB()
Get the Query database connection (read-only)
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:254
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1585
getResult()
Get the result object.
Definition: ApiBase.php:632
static getChangeTypes()
Get an array of all change types.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2159
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
static array static newFromRow( $row)
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:252
Exception representing a failure to look up a row from a name table.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:90
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Definition: ApiBase.php:560
const NS_SPECIAL
Definition: Defines.php:53
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1990
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:743
A query action to enumerate the recent changes that were done to the wiki.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
initProperties( $prop)
Sets internal state to include the desired properties in the output.
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:157
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
executeGenerator( $resultPageSet)
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1980
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1982
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static newMigration()
Static constructor.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
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:1126
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
const NS_MEDIA
Definition: Defines.php:52
$res
Definition: database.txt:21
dieContinueUsageIf( $condition)
Die with the &#39;badcontinue&#39; error.
Definition: ApiBase.php:2176
getContinuationManager()
Get the continuation manager.
Definition: ApiBase.php:672
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row, if it&#39;s marked as deleted.
__construct(ApiQuery $query, $moduleName)
$params
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
if(ini_get('mbstring.func_overload'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:51
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:512
addFields( $value)
Add a set of fields to select to the internal array.
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE &#39;limit&#39;.
Definition: ApiBase.php:96
This is the main query class.
Definition: ApiQuery.php:36
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:913
const DELETED_RESTRICTED
Definition: LogPage.php:37
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:124
static getPatrolToken( $pageid, $title, $rc=null)
const LIST_OR
Definition: Defines.php:46
const PRC_UNPATROLLED
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static getStore()
static isUnpatrolled( $rc, User $user)
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
addWhere( $value)
Add a set of WHERE clauses to the internal array.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1909
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
static parseToRCType( $type)
Parsing text to RC_* constants.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2188
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
getTokenFunctions()
Get an array mapping token names to their handler functions.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is &#39;namespace&#39;, include these as additional possible values.
Definition: ApiBase.php:186
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
const RC_NEW
Definition: Defines.php:143
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:105
const DELETED_ACTION
Definition: LogPage.php:34
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:99
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:587
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
Definition: ChangeTags.php:793
const PRC_AUTOPATROLLED
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
const RC_EDIT
Definition: Defines.php:142
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
const RC_LOG
Definition: Defines.php:144
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319