MediaWiki  1.28.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 $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
40  $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
41  $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
42  $fld_tags = false, $fld_sha1 = false, $token = [];
43 
44  private $tokenFunctions;
45 
53  protected function getTokenFunctions() {
54  // Don't call the hooks twice
55  if ( isset( $this->tokenFunctions ) ) {
56  return $this->tokenFunctions;
57  }
58 
59  // If we're in a mode that breaks the same-origin policy, no tokens can
60  // be obtained
61  if ( $this->lacksSameOriginSecurity() ) {
62  return [];
63  }
64 
65  $this->tokenFunctions = [
66  'patrol' => [ 'ApiQueryRecentChanges', 'getPatrolToken' ]
67  ];
68  Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
69 
70  return $this->tokenFunctions;
71  }
72 
80  public static function getPatrolToken( $pageid, $title, $rc = null ) {
82 
83  $validTokenUser = false;
84 
85  if ( $rc ) {
86  if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
87  ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
88  ) {
89  $validTokenUser = true;
90  }
91  } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
92  $validTokenUser = true;
93  }
94 
95  if ( $validTokenUser ) {
96  // The patrol token is always the same, let's exploit that
97  static $cachedPatrolToken = null;
98 
99  if ( is_null( $cachedPatrolToken ) ) {
100  $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
101  }
102 
103  return $cachedPatrolToken;
104  }
105 
106  return false;
107  }
108 
113  public function initProperties( $prop ) {
114  $this->fld_comment = isset( $prop['comment'] );
115  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
116  $this->fld_user = isset( $prop['user'] );
117  $this->fld_userid = isset( $prop['userid'] );
118  $this->fld_flags = isset( $prop['flags'] );
119  $this->fld_timestamp = isset( $prop['timestamp'] );
120  $this->fld_title = isset( $prop['title'] );
121  $this->fld_ids = isset( $prop['ids'] );
122  $this->fld_sizes = isset( $prop['sizes'] );
123  $this->fld_redirect = isset( $prop['redirect'] );
124  $this->fld_patrolled = isset( $prop['patrolled'] );
125  $this->fld_loginfo = isset( $prop['loginfo'] );
126  $this->fld_tags = isset( $prop['tags'] );
127  $this->fld_sha1 = isset( $prop['sha1'] );
128  }
129 
130  public function execute() {
131  $this->run();
132  }
133 
134  public function executeGenerator( $resultPageSet ) {
135  $this->run( $resultPageSet );
136  }
137 
143  public function run( $resultPageSet = null ) {
144  $user = $this->getUser();
145  /* Get the parameters of the request. */
146  $params = $this->extractRequestParams();
147 
148  /* Build our basic query. Namely, something along the lines of:
149  * SELECT * FROM recentchanges WHERE rc_timestamp > $start
150  * AND rc_timestamp < $end AND rc_namespace = $namespace
151  */
152  $this->addTables( 'recentchanges' );
153  $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
154 
155  if ( !is_null( $params['continue'] ) ) {
156  $cont = explode( '|', $params['continue'] );
157  $this->dieContinueUsageIf( count( $cont ) != 2 );
158  $db = $this->getDB();
159  $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
160  $id = intval( $cont[1] );
161  $this->dieContinueUsageIf( $id != $cont[1] );
162  $op = $params['dir'] === 'older' ? '<' : '>';
163  $this->addWhere(
164  "rc_timestamp $op $timestamp OR " .
165  "(rc_timestamp = $timestamp AND " .
166  "rc_id $op= $id)"
167  );
168  }
169 
170  $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
171  $this->addOption( 'ORDER BY', [
172  "rc_timestamp $order",
173  "rc_id $order",
174  ] );
175 
176  $this->addWhereFld( 'rc_namespace', $params['namespace'] );
177 
178  if ( !is_null( $params['type'] ) ) {
179  try {
180  $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
181  } catch ( Exception $e ) {
182  ApiBase::dieDebug( __METHOD__, $e->getMessage() );
183  }
184  }
185 
186  if ( !is_null( $params['show'] ) ) {
187  $show = array_flip( $params['show'] );
188 
189  /* Check for conflicting parameters. */
190  if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
191  || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
192  || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
193  || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
194  || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
195  || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
196  || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
197  ) {
198  $this->dieUsageMsg( 'show' );
199  }
200 
201  // Check permissions
202  if ( isset( $show['patrolled'] )
203  || isset( $show['!patrolled'] )
204  || isset( $show['unpatrolled'] )
205  ) {
206  if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
207  $this->dieUsage(
208  'You need patrol or patrolmarks permission to request the patrolled flag',
209  'permissiondenied'
210  );
211  }
212  }
213 
214  /* Add additional conditions to query depending upon parameters. */
215  $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
216  $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
217  $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
218  $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
219  $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) );
220  $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
221  $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
222  $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
223  $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
224 
225  if ( isset( $show['unpatrolled'] ) ) {
226  // See ChangesList::isUnpatrolled
227  if ( $user->useRCPatrol() ) {
228  $this->addWhere( 'rc_patrolled = 0' );
229  } elseif ( $user->useNPPatrol() ) {
230  $this->addWhere( 'rc_patrolled = 0' );
231  $this->addWhereFld( 'rc_type', RC_NEW );
232  }
233  }
234 
235  // Don't throw log entries out the window here
236  $this->addWhereIf(
237  'page_is_redirect = 0 OR page_is_redirect IS NULL',
238  isset( $show['!redirect'] )
239  );
240  }
241 
242  if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
243  $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
244  }
245 
246  if ( !is_null( $params['user'] ) ) {
247  $this->addWhereFld( 'rc_user_text', $params['user'] );
248  }
249 
250  if ( !is_null( $params['excludeuser'] ) ) {
251  // We don't use the rc_user_text index here because
252  // * it would require us to sort by rc_user_text before rc_timestamp
253  // * the != condition doesn't throw out too many rows anyway
254  $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
255  }
256 
257  /* Add the fields we're concerned with to our query. */
258  $this->addFields( [
259  'rc_id',
260  'rc_timestamp',
261  'rc_namespace',
262  'rc_title',
263  'rc_cur_id',
264  'rc_type',
265  'rc_deleted'
266  ] );
267 
268  $showRedirects = false;
269  /* Determine what properties we need to display. */
270  if ( !is_null( $params['prop'] ) ) {
271  $prop = array_flip( $params['prop'] );
272 
273  /* Set up internal members based upon params. */
274  $this->initProperties( $prop );
275 
276  if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
277  $this->dieUsage(
278  'You need patrol or patrolmarks permission to request the patrolled flag',
279  'permissiondenied'
280  );
281  }
282 
283  /* Add fields to our query if they are specified as a needed parameter. */
284  $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
285  $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
286  $this->addFieldsIf( 'rc_user', $this->fld_user || $this->fld_userid );
287  $this->addFieldsIf( 'rc_user_text', $this->fld_user );
288  $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
289  $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
290  $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
291  $this->addFieldsIf(
292  [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
293  $this->fld_loginfo
294  );
295  $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
296  || isset( $show['!redirect'] );
297  }
298  $this->addFieldsIf( [ 'rc_this_oldid' ],
299  $resultPageSet && $params['generaterevisions'] );
300 
301  if ( $this->fld_tags ) {
302  $this->addTables( 'tag_summary' );
303  $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
304  $this->addFields( 'ts_tags' );
305  }
306 
307  if ( $this->fld_sha1 ) {
308  $this->addTables( 'revision' );
309  $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
310  [ 'rc_this_oldid=rev_id' ] ] ] );
311  $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
312  }
313 
314  if ( $params['toponly'] || $showRedirects ) {
315  $this->addTables( 'page' );
316  $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
317  [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
318  $this->addFields( 'page_is_redirect' );
319 
320  if ( $params['toponly'] ) {
321  $this->addWhere( 'rc_this_oldid = page_latest' );
322  }
323  }
324 
325  if ( !is_null( $params['tag'] ) ) {
326  $this->addTables( 'change_tag' );
327  $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
328  $this->addWhereFld( 'ct_tag', $params['tag'] );
329  }
330 
331  // Paranoia: avoid brute force searches (bug 17342)
332  if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
333  if ( !$user->isAllowed( 'deletedhistory' ) ) {
334  $bitmask = Revision::DELETED_USER;
335  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
337  } else {
338  $bitmask = 0;
339  }
340  if ( $bitmask ) {
341  $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
342  }
343  }
344  if ( $this->getRequest()->getCheck( 'namespace' ) ) {
345  // LogPage::DELETED_ACTION hides the affected page, too.
346  if ( !$user->isAllowed( 'deletedhistory' ) ) {
347  $bitmask = LogPage::DELETED_ACTION;
348  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
350  } else {
351  $bitmask = 0;
352  }
353  if ( $bitmask ) {
354  $this->addWhere( $this->getDB()->makeList( [
355  'rc_type != ' . RC_LOG,
356  $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
357  ], LIST_OR ) );
358  }
359  }
360 
361  $this->token = $params['token'];
362  $this->addOption( 'LIMIT', $params['limit'] + 1 );
363 
364  $hookData = [];
365  $count = 0;
366  /* Perform the actual query. */
367  $res = $this->select( __METHOD__, [], $hookData );
368 
369  $revids = [];
370  $titles = [];
371 
372  $result = $this->getResult();
373 
374  /* Iterate through the rows, adding data extracted from them to our query result. */
375  foreach ( $res as $row ) {
376  if ( $count === 0 && $resultPageSet !== null ) {
377  // Set the non-continue since the list of recentchanges is
378  // prone to having entries added at the start frequently.
379  $this->getContinuationManager()->addGeneratorNonContinueParam(
380  $this, 'continue', "$row->rc_timestamp|$row->rc_id"
381  );
382  }
383  if ( ++$count > $params['limit'] ) {
384  // We've reached the one extra which shows that there are
385  // additional pages to be had. Stop here...
386  $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
387  break;
388  }
389 
390  if ( is_null( $resultPageSet ) ) {
391  /* Extract the data from a single row. */
392  $vals = $this->extractRowInfo( $row );
393 
394  /* Add that row's data to our final output. */
395  $fit = $this->processRow( $row, $vals, $hookData ) &&
396  $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
397  if ( !$fit ) {
398  $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
399  break;
400  }
401  } elseif ( $params['generaterevisions'] ) {
402  $revid = (int)$row->rc_this_oldid;
403  if ( $revid > 0 ) {
404  $revids[] = $revid;
405  }
406  } else {
407  $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
408  }
409  }
410 
411  if ( is_null( $resultPageSet ) ) {
412  /* Format the result */
413  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
414  } elseif ( $params['generaterevisions'] ) {
415  $resultPageSet->populateFromRevisionIDs( $revids );
416  } else {
417  $resultPageSet->populateFromTitles( $titles );
418  }
419  }
420 
428  public function extractRowInfo( $row ) {
429  /* Determine the title of the page that has been changed. */
430  $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
431  $user = $this->getUser();
432 
433  /* Our output data. */
434  $vals = [];
435 
436  $type = intval( $row->rc_type );
437  $vals['type'] = RecentChange::parseFromRCType( $type );
438 
439  $anyHidden = false;
440 
441  /* Create a new entry in the result for the title. */
442  if ( $this->fld_title || $this->fld_ids ) {
443  if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
444  $vals['actionhidden'] = true;
445  $anyHidden = true;
446  }
447  if ( $type !== RC_LOG ||
449  ) {
450  if ( $this->fld_title ) {
452  }
453  if ( $this->fld_ids ) {
454  $vals['pageid'] = intval( $row->rc_cur_id );
455  $vals['revid'] = intval( $row->rc_this_oldid );
456  $vals['old_revid'] = intval( $row->rc_last_oldid );
457  }
458  }
459  }
460 
461  if ( $this->fld_ids ) {
462  $vals['rcid'] = intval( $row->rc_id );
463  }
464 
465  /* Add user data and 'anon' flag, if user is anonymous. */
466  if ( $this->fld_user || $this->fld_userid ) {
467  if ( $row->rc_deleted & Revision::DELETED_USER ) {
468  $vals['userhidden'] = true;
469  $anyHidden = true;
470  }
471  if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
472  if ( $this->fld_user ) {
473  $vals['user'] = $row->rc_user_text;
474  }
475 
476  if ( $this->fld_userid ) {
477  $vals['userid'] = (int)$row->rc_user;
478  }
479 
480  if ( !$row->rc_user ) {
481  $vals['anon'] = true;
482  }
483  }
484  }
485 
486  /* Add flags, such as new, minor, bot. */
487  if ( $this->fld_flags ) {
488  $vals['bot'] = (bool)$row->rc_bot;
489  $vals['new'] = $row->rc_type == RC_NEW;
490  $vals['minor'] = (bool)$row->rc_minor;
491  }
492 
493  /* Add sizes of each revision. (Only available on 1.10+) */
494  if ( $this->fld_sizes ) {
495  $vals['oldlen'] = intval( $row->rc_old_len );
496  $vals['newlen'] = intval( $row->rc_new_len );
497  }
498 
499  /* Add the timestamp. */
500  if ( $this->fld_timestamp ) {
501  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
502  }
503 
504  /* Add edit summary / log summary. */
505  if ( $this->fld_comment || $this->fld_parsedcomment ) {
506  if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
507  $vals['commenthidden'] = true;
508  $anyHidden = true;
509  }
510  if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
511  if ( $this->fld_comment && isset( $row->rc_comment ) ) {
512  $vals['comment'] = $row->rc_comment;
513  }
514 
515  if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
516  $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title );
517  }
518  }
519  }
520 
521  if ( $this->fld_redirect ) {
522  $vals['redirect'] = (bool)$row->page_is_redirect;
523  }
524 
525  /* Add the patrolled flag */
526  if ( $this->fld_patrolled ) {
527  $vals['patrolled'] = $row->rc_patrolled == 1;
528  $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
529  }
530 
531  if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
532  if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
533  $vals['actionhidden'] = true;
534  $anyHidden = true;
535  }
536  if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
537  $vals['logid'] = intval( $row->rc_logid );
538  $vals['logtype'] = $row->rc_log_type;
539  $vals['logaction'] = $row->rc_log_action;
540  $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
541  }
542  }
543 
544  if ( $this->fld_tags ) {
545  if ( $row->ts_tags ) {
546  $tags = explode( ',', $row->ts_tags );
547  ApiResult::setIndexedTagName( $tags, 'tag' );
548  $vals['tags'] = $tags;
549  } else {
550  $vals['tags'] = [];
551  }
552  }
553 
554  if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
555  if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
556  $vals['sha1hidden'] = true;
557  $anyHidden = true;
558  }
559  if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
560  if ( $row->rev_sha1 !== '' ) {
561  $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
562  } else {
563  $vals['sha1'] = '';
564  }
565  }
566  }
567 
568  if ( !is_null( $this->token ) ) {
570  foreach ( $this->token as $t ) {
571  $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
572  $title, RecentChange::newFromRow( $row ) );
573  if ( $val === false ) {
574  $this->setWarning( "Action '$t' is not allowed for the current user" );
575  } else {
576  $vals[$t . 'token'] = $val;
577  }
578  }
579  }
580 
581  if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
582  $vals['suppressed'] = true;
583  }
584 
585  return $vals;
586  }
587 
588  public function getCacheMode( $params ) {
589  if ( isset( $params['show'] ) ) {
590  foreach ( $params['show'] as $show ) {
591  if ( $show === 'patrolled' || $show === '!patrolled' ) {
592  return 'private';
593  }
594  }
595  }
596  if ( isset( $params['token'] ) ) {
597  return 'private';
598  }
599  if ( $this->userCanSeeRevDel() ) {
600  return 'private';
601  }
602  if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
603  // formatComment() calls wfMessage() among other things
604  return 'anon-public-user-private';
605  }
606 
607  return 'public';
608  }
609 
610  public function getAllowedParams() {
611  return [
612  'start' => [
613  ApiBase::PARAM_TYPE => 'timestamp'
614  ],
615  'end' => [
616  ApiBase::PARAM_TYPE => 'timestamp'
617  ],
618  'dir' => [
619  ApiBase::PARAM_DFLT => 'older',
621  'newer',
622  'older'
623  ],
624  ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
625  ],
626  'namespace' => [
627  ApiBase::PARAM_ISMULTI => true,
628  ApiBase::PARAM_TYPE => 'namespace'
629  ],
630  'user' => [
631  ApiBase::PARAM_TYPE => 'user'
632  ],
633  'excludeuser' => [
634  ApiBase::PARAM_TYPE => 'user'
635  ],
636  'tag' => null,
637  'prop' => [
638  ApiBase::PARAM_ISMULTI => true,
639  ApiBase::PARAM_DFLT => 'title|timestamp|ids',
641  'user',
642  'userid',
643  'comment',
644  'parsedcomment',
645  'flags',
646  'timestamp',
647  'title',
648  'ids',
649  'sizes',
650  'redirect',
651  'patrolled',
652  'loginfo',
653  'tags',
654  'sha1',
655  ],
657  ],
658  'token' => [
660  ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
662  ],
663  'show' => [
664  ApiBase::PARAM_ISMULTI => true,
666  'minor',
667  '!minor',
668  'bot',
669  '!bot',
670  'anon',
671  '!anon',
672  'redirect',
673  '!redirect',
674  'patrolled',
675  '!patrolled',
676  'unpatrolled'
677  ]
678  ],
679  'limit' => [
680  ApiBase::PARAM_DFLT => 10,
681  ApiBase::PARAM_TYPE => 'limit',
682  ApiBase::PARAM_MIN => 1,
685  ],
686  'type' => [
687  ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
688  ApiBase::PARAM_ISMULTI => true,
690  ],
691  'toponly' => false,
692  'continue' => [
693  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
694  ],
695  'generaterevisions' => false,
696  ];
697  }
698 
699  protected function getExamplesMessages() {
700  return [
701  'action=query&list=recentchanges'
702  => 'apihelp-query+recentchanges-example-simple',
703  'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
704  => 'apihelp-query+recentchanges-example-generator',
705  ];
706  }
707 
708  public function getHelpUrls() {
709  return 'https://www.mediawiki.org/wiki/API:Recentchanges';
710  }
711 }
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:88
getDB()
Get the Query database connection (read-only)
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:179
static newFromRow($row)
Handy shortcut for constructing a formatter directly from database row.
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:1555
getResult()
Get the result object.
Definition: ApiBase.php:577
static getChangeTypes()
Get an array of all change types.
addWhereFld($field, $value)
Equivalent to addWhere(array($field => $value))
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2102
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:50
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:177
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:91
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Definition: ApiBase.php:505
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:678
A query action to enumerate the recent changes that were done to the wiki.
static getPatrolToken($pageid, $title, $rc=null)
extractRowInfo($row)
Extracts from a single sql row the data needed to describe one recent change.
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
select($method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addTimestampWhereRange($field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
setContinueEnumParameter($paramName, $paramValue)
Overridden to set the generator param if in generator mode.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
addWhere($value)
Add a set of WHERE clauses to the internal array.
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
Definition: defines.php:28
addJoinConds($join_conds)
Add a set of JOIN conditions to the internal array.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
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:Associative array mapping language codes to prefixed links of the form"language:title".&$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:1934
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getRequest()
Get the WebRequest object.
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:1936
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
if($limit) $timestamp
addWhereIf($value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
$res
Definition: database.txt:21
getContinuationManager()
Get the continuation manager.
Definition: ApiBase.php:617
processRow($row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addOption($name, $value=null)
Add an option such as LIMIT or USE INDEX.
__construct(ApiQuery $query, $moduleName)
$params
initProperties($prop)
Sets internal state to include the desired properties in the output.
run($resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
const DELETED_RESTRICTED
Definition: Revision.php:88
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:457
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE 'limit'.
Definition: ApiBase.php:97
This is the main query class.
Definition: ApiQuery.php:38
setWarning($warning)
Set warning section for this module.
Definition: ApiBase.php:1543
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
dieContinueUsageIf($condition)
Die with the $prefix.
Definition: ApiBase.php:2229
const DELETED_RESTRICTED
Definition: LogPage.php:36
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:1180
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:125
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 local account $user
Definition: hooks.txt:242
const DELETED_TEXT
Definition: Revision.php:85
const LIST_OR
Definition: Defines.php:38
static array static newFromRow($row)
static parseFromRCType($rcType)
Parsing RC_* constants to human-readable test.
addFieldsIf($value, $condition)
Same as addFields(), but add the fields only if a condition is met.
if($IP===false)
Definition: WebStart.php:59
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
const DELETED_USER
Definition: Revision.php:87
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
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's marked as deleted.
addFields($value)
Add a set of fields to select to the internal array.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:53
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition: ApiBase.php:1574
getTokenFunctions()
Get an array mapping token names to their handler functions.
$count
const RC_NEW
Definition: Defines.php:137
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:106
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, if it's marked as deleted.
Definition: Revision.php:1764
const DELETED_COMMENT
Definition: Revision.php:86
const DELETED_ACTION
Definition: LogPage.php:33
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:100
static dieDebug($method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2284
static isUnpatrolled($rc, User $user)
static addTitleInfo(&$arr, $title, $prefix= '')
Add information (title and namespace) about a Title object to a result array.
static parseToRCType($type)
Parsing text to RC_* constants.
getUser()
Get the User object.
addTables($tables, $alias=null)
Add a set of tables to the internal array.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
dieUsageMsg($error)
Output the error message related to a certain array.
Definition: ApiBase.php:2192
const RC_EDIT
Definition: Defines.php:136
const RC_LOG
Definition: Defines.php:138
$wgUser
Definition: Setup.php:806