MediaWiki  1.30.0
ApiQueryRecentChanges.php
Go to the documentation of this file.
1 <?php
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' => [ 'ApiQueryRecentChanges', 'getPatrolToken' ]
69  ];
70  Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
71 
72  return $this->tokenFunctions;
73  }
74 
82  public static function getPatrolToken( $pageid, $title, $rc = null ) {
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 = intval( $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  if ( !is_null( $params['show'] ) ) {
189  $show = array_flip( $params['show'] );
190 
191  /* Check for conflicting parameters. */
192  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
193  || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
194  || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
195  || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
196  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
197  || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
198  || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
199  ) {
200  $this->dieWithError( 'apierror-show' );
201  }
202 
203  // Check permissions
204  if ( isset( $show['patrolled'] )
205  || isset( $show['!patrolled'] )
206  || isset( $show['unpatrolled'] )
207  ) {
208  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
209  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
210  }
211  }
212 
213  /* Add additional conditions to query depending upon parameters. */
214  $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
215  $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
216  $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
217  $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
218  $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) );
219  $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
220  $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
221  $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
222  $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
223 
224  if ( isset( $show['unpatrolled'] ) ) {
225  // See ChangesList::isUnpatrolled
226  if ( $user->useRCPatrol() ) {
227  $this->addWhere( 'rc_patrolled = 0' );
228  } elseif ( $user->useNPPatrol() ) {
229  $this->addWhere( 'rc_patrolled = 0' );
230  $this->addWhereFld( 'rc_type', RC_NEW );
231  }
232  }
233 
234  // Don't throw log entries out the window here
235  $this->addWhereIf(
236  'page_is_redirect = 0 OR page_is_redirect IS NULL',
237  isset( $show['!redirect'] )
238  );
239  }
240 
241  $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
242 
243  if ( !is_null( $params['user'] ) ) {
244  $this->addWhereFld( 'rc_user_text', $params['user'] );
245  }
246 
247  if ( !is_null( $params['excludeuser'] ) ) {
248  // We don't use the rc_user_text index here because
249  // * it would require us to sort by rc_user_text before rc_timestamp
250  // * the != condition doesn't throw out too many rows anyway
251  $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
252  }
253 
254  /* Add the fields we're concerned with to our query. */
255  $this->addFields( [
256  'rc_id',
257  'rc_timestamp',
258  'rc_namespace',
259  'rc_title',
260  'rc_cur_id',
261  'rc_type',
262  'rc_deleted'
263  ] );
264 
265  $showRedirects = false;
266  /* Determine what properties we need to display. */
267  if ( !is_null( $params['prop'] ) ) {
268  $prop = array_flip( $params['prop'] );
269 
270  /* Set up internal members based upon params. */
271  $this->initProperties( $prop );
272 
273  if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
274  $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
275  }
276 
277  /* Add fields to our query if they are specified as a needed parameter. */
278  $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
279  $this->addFieldsIf( 'rc_user', $this->fld_user || $this->fld_userid );
280  $this->addFieldsIf( 'rc_user_text', $this->fld_user );
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->addTables( 'tag_summary' );
296  $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
297  $this->addFields( 'ts_tags' );
298  }
299 
300  if ( $this->fld_sha1 ) {
301  $this->addTables( 'revision' );
302  $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
303  [ 'rc_this_oldid=rev_id' ] ] ] );
304  $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
305  }
306 
307  if ( $params['toponly'] || $showRedirects ) {
308  $this->addTables( 'page' );
309  $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
310  [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
311  $this->addFields( 'page_is_redirect' );
312 
313  if ( $params['toponly'] ) {
314  $this->addWhere( 'rc_this_oldid = page_latest' );
315  }
316  }
317 
318  if ( !is_null( $params['tag'] ) ) {
319  $this->addTables( 'change_tag' );
320  $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
321  $this->addWhereFld( 'ct_tag', $params['tag'] );
322  }
323 
324  // Paranoia: avoid brute force searches (T19342)
325  if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
326  if ( !$user->isAllowed( 'deletedhistory' ) ) {
327  $bitmask = Revision::DELETED_USER;
328  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
330  } else {
331  $bitmask = 0;
332  }
333  if ( $bitmask ) {
334  $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
335  }
336  }
337  if ( $this->getRequest()->getCheck( 'namespace' ) ) {
338  // LogPage::DELETED_ACTION hides the affected page, too.
339  if ( !$user->isAllowed( 'deletedhistory' ) ) {
340  $bitmask = LogPage::DELETED_ACTION;
341  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
343  } else {
344  $bitmask = 0;
345  }
346  if ( $bitmask ) {
347  $this->addWhere( $this->getDB()->makeList( [
348  'rc_type != ' . RC_LOG,
349  $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
350  ], LIST_OR ) );
351  }
352  }
353 
354  $this->token = $params['token'];
355 
356  if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
357  $this->commentStore = new CommentStore( 'rc_comment' );
358  $commentQuery = $this->commentStore->getJoin();
359  $this->addTables( $commentQuery['tables'] );
360  $this->addFields( $commentQuery['fields'] );
361  $this->addJoinConds( $commentQuery['joins'] );
362  }
363 
364  $this->addOption( 'LIMIT', $params['limit'] + 1 );
365 
366  $hookData = [];
367  $count = 0;
368  /* Perform the actual query. */
369  $res = $this->select( __METHOD__, [], $hookData );
370 
371  $revids = [];
372  $titles = [];
373 
374  $result = $this->getResult();
375 
376  /* Iterate through the rows, adding data extracted from them to our query result. */
377  foreach ( $res as $row ) {
378  if ( $count === 0 && $resultPageSet !== null ) {
379  // Set the non-continue since the list of recentchanges is
380  // prone to having entries added at the start frequently.
381  $this->getContinuationManager()->addGeneratorNonContinueParam(
382  $this, 'continue', "$row->rc_timestamp|$row->rc_id"
383  );
384  }
385  if ( ++$count > $params['limit'] ) {
386  // We've reached the one extra which shows that there are
387  // additional pages to be had. Stop here...
388  $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
389  break;
390  }
391 
392  if ( is_null( $resultPageSet ) ) {
393  /* Extract the data from a single row. */
394  $vals = $this->extractRowInfo( $row );
395 
396  /* Add that row's data to our final output. */
397  $fit = $this->processRow( $row, $vals, $hookData ) &&
398  $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
399  if ( !$fit ) {
400  $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
401  break;
402  }
403  } elseif ( $params['generaterevisions'] ) {
404  $revid = (int)$row->rc_this_oldid;
405  if ( $revid > 0 ) {
406  $revids[] = $revid;
407  }
408  } else {
409  $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
410  }
411  }
412 
413  if ( is_null( $resultPageSet ) ) {
414  /* Format the result */
415  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
416  } elseif ( $params['generaterevisions'] ) {
417  $resultPageSet->populateFromRevisionIDs( $revids );
418  } else {
419  $resultPageSet->populateFromTitles( $titles );
420  }
421  }
422 
430  public function extractRowInfo( $row ) {
431  /* Determine the title of the page that has been changed. */
432  $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
433  $user = $this->getUser();
434 
435  /* Our output data. */
436  $vals = [];
437 
438  $type = intval( $row->rc_type );
439  $vals['type'] = RecentChange::parseFromRCType( $type );
440 
441  $anyHidden = false;
442 
443  /* Create a new entry in the result for the title. */
444  if ( $this->fld_title || $this->fld_ids ) {
445  if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
446  $vals['actionhidden'] = true;
447  $anyHidden = true;
448  }
449  if ( $type !== RC_LOG ||
451  ) {
452  if ( $this->fld_title ) {
454  }
455  if ( $this->fld_ids ) {
456  $vals['pageid'] = intval( $row->rc_cur_id );
457  $vals['revid'] = intval( $row->rc_this_oldid );
458  $vals['old_revid'] = intval( $row->rc_last_oldid );
459  }
460  }
461  }
462 
463  if ( $this->fld_ids ) {
464  $vals['rcid'] = intval( $row->rc_id );
465  }
466 
467  /* Add user data and 'anon' flag, if user is anonymous. */
468  if ( $this->fld_user || $this->fld_userid ) {
469  if ( $row->rc_deleted & Revision::DELETED_USER ) {
470  $vals['userhidden'] = true;
471  $anyHidden = true;
472  }
473  if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
474  if ( $this->fld_user ) {
475  $vals['user'] = $row->rc_user_text;
476  }
477 
478  if ( $this->fld_userid ) {
479  $vals['userid'] = (int)$row->rc_user;
480  }
481 
482  if ( !$row->rc_user ) {
483  $vals['anon'] = true;
484  }
485  }
486  }
487 
488  /* Add flags, such as new, minor, bot. */
489  if ( $this->fld_flags ) {
490  $vals['bot'] = (bool)$row->rc_bot;
491  $vals['new'] = $row->rc_type == RC_NEW;
492  $vals['minor'] = (bool)$row->rc_minor;
493  }
494 
495  /* Add sizes of each revision. (Only available on 1.10+) */
496  if ( $this->fld_sizes ) {
497  $vals['oldlen'] = intval( $row->rc_old_len );
498  $vals['newlen'] = intval( $row->rc_new_len );
499  }
500 
501  /* Add the timestamp. */
502  if ( $this->fld_timestamp ) {
503  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
504  }
505 
506  /* Add edit summary / log summary. */
507  if ( $this->fld_comment || $this->fld_parsedcomment ) {
508  if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
509  $vals['commenthidden'] = true;
510  $anyHidden = true;
511  }
512  if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
513  $comment = $this->commentStore->getComment( $row )->text;
514  if ( $this->fld_comment ) {
515  $vals['comment'] = $comment;
516  }
517 
518  if ( $this->fld_parsedcomment ) {
519  $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
520  }
521  }
522  }
523 
524  if ( $this->fld_redirect ) {
525  $vals['redirect'] = (bool)$row->page_is_redirect;
526  }
527 
528  /* Add the patrolled flag */
529  if ( $this->fld_patrolled ) {
530  $vals['patrolled'] = $row->rc_patrolled == 1;
531  $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
532  }
533 
534  if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
535  if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
536  $vals['actionhidden'] = true;
537  $anyHidden = true;
538  }
539  if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
540  $vals['logid'] = intval( $row->rc_logid );
541  $vals['logtype'] = $row->rc_log_type;
542  $vals['logaction'] = $row->rc_log_action;
543  $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
544  }
545  }
546 
547  if ( $this->fld_tags ) {
548  if ( $row->ts_tags ) {
549  $tags = explode( ',', $row->ts_tags );
550  ApiResult::setIndexedTagName( $tags, 'tag' );
551  $vals['tags'] = $tags;
552  } else {
553  $vals['tags'] = [];
554  }
555  }
556 
557  if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
558  if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
559  $vals['sha1hidden'] = true;
560  $anyHidden = true;
561  }
562  if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
563  if ( $row->rev_sha1 !== '' ) {
564  $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
565  } else {
566  $vals['sha1'] = '';
567  }
568  }
569  }
570 
571  if ( !is_null( $this->token ) ) {
573  foreach ( $this->token as $t ) {
574  $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
575  $title, RecentChange::newFromRow( $row ) );
576  if ( $val === false ) {
577  $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
578  } else {
579  $vals[$t . 'token'] = $val;
580  }
581  }
582  }
583 
584  if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
585  $vals['suppressed'] = true;
586  }
587 
588  return $vals;
589  }
590 
591  public function getCacheMode( $params ) {
592  if ( isset( $params['show'] ) ) {
593  foreach ( $params['show'] as $show ) {
594  if ( $show === 'patrolled' || $show === '!patrolled' ) {
595  return 'private';
596  }
597  }
598  }
599  if ( isset( $params['token'] ) ) {
600  return 'private';
601  }
602  if ( $this->userCanSeeRevDel() ) {
603  return 'private';
604  }
605  if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
606  // formatComment() calls wfMessage() among other things
607  return 'anon-public-user-private';
608  }
609 
610  return 'public';
611  }
612 
613  public function getAllowedParams() {
614  return [
615  'start' => [
616  ApiBase::PARAM_TYPE => 'timestamp'
617  ],
618  'end' => [
619  ApiBase::PARAM_TYPE => 'timestamp'
620  ],
621  'dir' => [
622  ApiBase::PARAM_DFLT => 'older',
624  'newer',
625  'older'
626  ],
627  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
628  ],
629  'namespace' => [
630  ApiBase::PARAM_ISMULTI => true,
631  ApiBase::PARAM_TYPE => 'namespace',
633  ],
634  'user' => [
635  ApiBase::PARAM_TYPE => 'user'
636  ],
637  'excludeuser' => [
638  ApiBase::PARAM_TYPE => 'user'
639  ],
640  'tag' => null,
641  'prop' => [
642  ApiBase::PARAM_ISMULTI => true,
643  ApiBase::PARAM_DFLT => 'title|timestamp|ids',
645  'user',
646  'userid',
647  'comment',
648  'parsedcomment',
649  'flags',
650  'timestamp',
651  'title',
652  'ids',
653  'sizes',
654  'redirect',
655  'patrolled',
656  'loginfo',
657  'tags',
658  'sha1',
659  ],
661  ],
662  'token' => [
664  ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
666  ],
667  'show' => [
668  ApiBase::PARAM_ISMULTI => true,
670  'minor',
671  '!minor',
672  'bot',
673  '!bot',
674  'anon',
675  '!anon',
676  'redirect',
677  '!redirect',
678  'patrolled',
679  '!patrolled',
680  'unpatrolled'
681  ]
682  ],
683  'limit' => [
684  ApiBase::PARAM_DFLT => 10,
685  ApiBase::PARAM_TYPE => 'limit',
686  ApiBase::PARAM_MIN => 1,
689  ],
690  'type' => [
691  ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
692  ApiBase::PARAM_ISMULTI => true,
694  ],
695  'toponly' => false,
696  'continue' => [
697  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
698  ],
699  'generaterevisions' => false,
700  ];
701  }
702 
703  protected function getExamplesMessages() {
704  return [
705  'action=query&list=recentchanges'
706  => 'apihelp-query+recentchanges-example-simple',
707  'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
708  => 'apihelp-query+recentchanges-example-generator',
709  ];
710  }
711 
712  public function getHelpUrls() {
713  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
714  }
715 }
ApiQueryRecentChanges\getPatrolToken
static getPatrolToken( $pageid, $title, $rc=null)
Definition: ApiQueryRecentChanges.php:82
ApiQueryRecentChanges\run
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
Definition: ApiQueryRecentChanges.php:145
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:92
ApiQueryRecentChanges\$fld_comment
$fld_comment
Definition: ApiQueryRecentChanges.php:41
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:93
if
if($IP===false)
Definition: cleanupArchiveUserText.php:4
$wgUser
$wgUser
Definition: Setup.php:809
ApiQueryBase\processRow
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
Definition: ApiQueryBase.php:406
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:196
ApiQueryRecentChanges\$fld_ids
$fld_ids
Definition: ApiQueryRecentChanges.php:42
ApiQuery
This is the main query class.
Definition: ApiQuery.php:40
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1779
ApiQueryRecentChanges
A query action to enumerate the recent changes that were done to the wiki.
Definition: ApiQueryRecentChanges.php:33
ApiQueryRecentChanges\extractRowInfo
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
Definition: ApiQueryRecentChanges.php:430
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:91
Revision\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1798
ApiQueryRecentChanges\$commentStore
$commentStore
Definition: ApiQueryRecentChanges.php:39
captcha-old.count
count
Definition: captcha-old.py:249
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1855
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:319
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:128
$result
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 '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. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) '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 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) '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! 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:1963
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
ApiQueryRecentChanges\getTokenFunctions
getTokenFunctions()
Get an array mapping token names to their handler functions.
Definition: ApiQueryRecentChanges.php:55
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:91
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:632
RC_LOG
const RC_LOG
Definition: Defines.php:145
ApiQueryRecentChanges\$fld_sizes
$fld_sizes
Definition: ApiQueryRecentChanges.php:43
ApiQueryRecentChanges\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryRecentChanges.php:132
RecentChange\getChangeTypes
static getChangeTypes()
Get an array of all change types.
Definition: RecentChange.php:166
CommentStore
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Definition: CommentStore.php:30
$params
$params
Definition: styleTest.css.php:40
ApiQueryRecentChanges\$fld_userid
$fld_userid
Definition: ApiQueryRecentChanges.php:41
RC_EDIT
const RC_EDIT
Definition: Defines.php:143
$res
$res
Definition: database.txt:21
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:331
RecentChange\parseToRCType
static parseToRCType( $type)
Parsing text to RC_* constants.
Definition: RecentChange.php:133
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
ApiBase\lacksSameOriginSecurity
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Definition: ApiBase.php:560
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:210
php
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
ApiQueryRecentChanges\$fld_redirect
$fld_redirect
Definition: ApiQueryRecentChanges.php:43
ApiQueryGeneratorBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
Definition: ApiQueryGeneratorBase.php:88
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:109
$query
null for the 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:1581
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:54
ApiQueryRecentChanges\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryRecentChanges.php:613
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:103
ApiQueryRecentChanges\$fld_flags
$fld_flags
Definition: ApiQueryRecentChanges.php:42
LIST_OR
const LIST_OR
Definition: Defines.php:47
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
$titles
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
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:76
ApiQueryRecentChanges\executeGenerator
executeGenerator( $resultPageSet)
Execute this module as a generator.
Definition: ApiQueryRecentChanges.php:136
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:225
ApiQueryRecentChanges\$fld_title
$fld_title
Definition: ApiQueryRecentChanges.php:42
ApiQueryRecentChanges\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryRecentChanges.php:41
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:109
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:94
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:119
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:162
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:356
ApiQueryRecentChanges\$fld_user
$fld_user
Definition: ApiQueryRecentChanges.php:41
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:529
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ApiBase\PARAM_EXTRA_NAMESPACES
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
Definition: ApiBase.php:189
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
ApiQueryRecentChanges\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryRecentChanges.php:35
ApiBase\getContinuationManager
getContinuationManager()
Get the continuation manager.
Definition: ApiBase.php:672
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:740
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:53
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2026
ApiQueryRecentChanges\initProperties
initProperties( $prop)
Sets internal state to include the desired properties in the output.
Definition: ApiQueryRecentChanges.php:115
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:185
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:264
RC_NEW
const RC_NEW
Definition: Defines.php:144
ApiBase\requireMaxOneParameter
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:814
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:1099
ApiQueryGeneratorBase
Definition: ApiQueryGeneratorBase.php:30
ApiQueryRecentChanges\$fld_tags
$fld_tags
Definition: ApiQueryRecentChanges.php:44
ApiQueryRecentChanges\$fld_patrolled
$fld_patrolled
Definition: ApiQueryRecentChanges.php:43
ApiQueryRecentChanges\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryRecentChanges.php:712
ApiQueryRecentChanges\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryRecentChanges.php:703
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:227
ApiQueryRecentChanges\$fld_loginfo
$fld_loginfo
Definition: ApiQueryRecentChanges.php:43
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:542
RecentChange\parseFromRCType
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
Definition: RecentChange.php:155
ApiQueryRecentChanges\$fld_timestamp
$fld_timestamp
Definition: ApiQueryRecentChanges.php:42
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:52
as
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
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:512
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:55
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:100
true
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:1965
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:35
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:231
ChangesList\isUnpatrolled
static isUnpatrolled( $rc, User $user)
Definition: ChangesList.php:709
$t
$t
Definition: testCompression.php:67
ApiQueryRecentChanges\$token
$token
Definition: ApiQueryRecentChanges.php:44
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:160
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
ApiQueryBase\userCanSeeRevDel
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Definition: ApiQueryBase.php:606
ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2038
ApiQueryRecentChanges\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryRecentChanges.php:591
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:90
ApiQueryBase\addWhereIf
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
Definition: ApiQueryBase.php:249
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:486
$type
$type
Definition: testCompression.php:48
ApiQueryRecentChanges\$fld_sha1
$fld_sha1
Definition: ApiQueryRecentChanges.php:44
ApiQueryRecentChanges\$tokenFunctions
$tokenFunctions
Definition: ApiQueryRecentChanges.php:46