MediaWiki REL1_34
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
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
47
55 protected function getTokenFunctions() {
56 // Don't call the hooks twice
57 if ( isset( $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
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 ( $this->includesPatrollingFlags( $show ) ) {
218 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
219 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
220 }
221 }
222
223 /* Add additional conditions to query depending upon parameters. */
224 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
225 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
226 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
227 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
228 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
229 $actorMigration = ActorMigration::newMigration();
230 $actorQuery = $actorMigration->getJoin( 'rc_user' );
231 $this->addTables( $actorQuery['tables'] );
232 $this->addJoinConds( $actorQuery['joins'] );
233 $this->addWhereIf(
234 $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
235 );
236 $this->addWhereIf(
237 $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
238 );
239 }
240 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
241 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
242 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
243
244 if ( isset( $show['unpatrolled'] ) ) {
245 // See ChangesList::isUnpatrolled
246 if ( $user->useRCPatrol() ) {
247 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
248 } elseif ( $user->useNPPatrol() ) {
249 $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
250 $this->addWhereFld( 'rc_type', RC_NEW );
251 }
252 }
253
254 $this->addWhereIf(
255 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
256 isset( $show['!autopatrolled'] )
257 );
258 $this->addWhereIf(
259 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
260 isset( $show['autopatrolled'] )
261 );
262
263 // Don't throw log entries out the window here
264 $this->addWhereIf(
265 'page_is_redirect = 0 OR page_is_redirect IS NULL',
266 isset( $show['!redirect'] )
267 );
268 }
269
270 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
271
272 if ( !is_null( $params['user'] ) ) {
273 // Don't query by user ID here, it might be able to use the rc_user_text index.
274 $actorQuery = ActorMigration::newMigration()
275 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
276 $this->addTables( $actorQuery['tables'] );
277 $this->addJoinConds( $actorQuery['joins'] );
278 $this->addWhere( $actorQuery['conds'] );
279 }
280
281 if ( !is_null( $params['excludeuser'] ) ) {
282 // Here there's no chance to use the rc_user_text index, so allow ID to be used.
283 $actorQuery = ActorMigration::newMigration()
284 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
285 $this->addTables( $actorQuery['tables'] );
286 $this->addJoinConds( $actorQuery['joins'] );
287 $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
288 }
289
290 /* Add the fields we're concerned with to our query. */
291 $this->addFields( [
292 'rc_id',
293 'rc_timestamp',
294 'rc_namespace',
295 'rc_title',
296 'rc_cur_id',
297 'rc_type',
298 'rc_deleted'
299 ] );
300
301 $showRedirects = false;
302 /* Determine what properties we need to display. */
303 if ( !is_null( $params['prop'] ) ) {
304 $prop = array_flip( $params['prop'] );
305
306 /* Set up internal members based upon params. */
307 $this->initProperties( $prop );
308
309 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
310 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
311 }
312
313 /* Add fields to our query if they are specified as a needed parameter. */
314 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
315 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
316 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
317 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
318 $this->addFieldsIf(
319 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
320 $this->fld_loginfo
321 );
322 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
323 || isset( $show['!redirect'] );
324 }
325 $this->addFieldsIf( [ 'rc_this_oldid' ],
326 $resultPageSet && $params['generaterevisions'] );
327
328 if ( $this->fld_tags ) {
329 $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'recentchanges' ) ] );
330 }
331
332 if ( $this->fld_sha1 ) {
333 $this->addTables( 'revision' );
334 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
335 [ 'rc_this_oldid=rev_id' ] ] ] );
336 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
337 }
338
339 if ( $params['toponly'] || $showRedirects ) {
340 $this->addTables( 'page' );
341 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
342 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
343 $this->addFields( 'page_is_redirect' );
344
345 if ( $params['toponly'] ) {
346 $this->addWhere( 'rc_this_oldid = page_latest' );
347 }
348 }
349
350 if ( !is_null( $params['tag'] ) ) {
351 $this->addTables( 'change_tag' );
352 $this->addJoinConds( [ 'change_tag' => [ 'JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
353 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
354 try {
355 $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
356 } catch ( NameTableAccessException $exception ) {
357 // Return nothing.
358 $this->addWhere( '1=0' );
359 }
360 }
361
362 // Paranoia: avoid brute force searches (T19342)
363 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
364 if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
365 $bitmask = RevisionRecord::DELETED_USER;
366 } elseif ( !$this->getPermissionManager()
367 ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
368 ) {
369 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
370 } else {
371 $bitmask = 0;
372 }
373 if ( $bitmask ) {
374 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
375 }
376 }
377 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
378 // LogPage::DELETED_ACTION hides the affected page, too.
379 if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
380 $bitmask = LogPage::DELETED_ACTION;
381 } elseif ( !$this->getPermissionManager()
382 ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
383 ) {
385 } else {
386 $bitmask = 0;
387 }
388 if ( $bitmask ) {
389 $this->addWhere( $this->getDB()->makeList( [
390 'rc_type != ' . RC_LOG,
391 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
392 ], LIST_OR ) );
393 }
394 }
395
396 $this->token = $params['token'];
397
398 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
399 $this->commentStore = CommentStore::getStore();
400 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
401 $this->addTables( $commentQuery['tables'] );
402 $this->addFields( $commentQuery['fields'] );
403 $this->addJoinConds( $commentQuery['joins'] );
404 }
405
406 if ( $this->fld_user || $this->fld_userid || !is_null( $this->token ) ) {
407 // Token needs rc_user for RecentChange::newFromRow/User::newFromAnyId (T228425)
408 $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
409 $this->addTables( $actorQuery['tables'] );
410 $this->addFields( $actorQuery['fields'] );
411 $this->addJoinConds( $actorQuery['joins'] );
412 }
413
414 $this->addOption( 'LIMIT', $params['limit'] + 1 );
415
416 $hookData = [];
417 $count = 0;
418 /* Perform the actual query. */
419 $res = $this->select( __METHOD__, [], $hookData );
420
421 $revids = [];
422 $titles = [];
423
424 $result = $this->getResult();
425
426 /* Iterate through the rows, adding data extracted from them to our query result. */
427 foreach ( $res as $row ) {
428 if ( $count === 0 && $resultPageSet !== null ) {
429 // Set the non-continue since the list of recentchanges is
430 // prone to having entries added at the start frequently.
431 $this->getContinuationManager()->addGeneratorNonContinueParam(
432 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
433 );
434 }
435 if ( ++$count > $params['limit'] ) {
436 // We've reached the one extra which shows that there are
437 // additional pages to be had. Stop here...
438 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
439 break;
440 }
441
442 if ( is_null( $resultPageSet ) ) {
443 /* Extract the data from a single row. */
444 $vals = $this->extractRowInfo( $row );
445
446 /* Add that row's data to our final output. */
447 $fit = $this->processRow( $row, $vals, $hookData ) &&
448 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
449 if ( !$fit ) {
450 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
451 break;
452 }
453 } elseif ( $params['generaterevisions'] ) {
454 $revid = (int)$row->rc_this_oldid;
455 if ( $revid > 0 ) {
456 $revids[] = $revid;
457 }
458 } else {
459 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
460 }
461 }
462
463 if ( is_null( $resultPageSet ) ) {
464 /* Format the result */
465 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
466 } elseif ( $params['generaterevisions'] ) {
467 $resultPageSet->populateFromRevisionIDs( $revids );
468 } else {
469 $resultPageSet->populateFromTitles( $titles );
470 }
471 }
472
479 public function extractRowInfo( $row ) {
480 /* Determine the title of the page that has been changed. */
481 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
482 $user = $this->getUser();
483
484 /* Our output data. */
485 $vals = [];
486
487 $type = (int)$row->rc_type;
488 $vals['type'] = RecentChange::parseFromRCType( $type );
489
490 $anyHidden = false;
491
492 /* Create a new entry in the result for the title. */
493 if ( $this->fld_title || $this->fld_ids ) {
494 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
495 $vals['actionhidden'] = true;
496 $anyHidden = true;
497 }
498 if ( $type !== RC_LOG ||
500 ) {
501 if ( $this->fld_title ) {
503 }
504 if ( $this->fld_ids ) {
505 $vals['pageid'] = (int)$row->rc_cur_id;
506 $vals['revid'] = (int)$row->rc_this_oldid;
507 $vals['old_revid'] = (int)$row->rc_last_oldid;
508 }
509 }
510 }
511
512 if ( $this->fld_ids ) {
513 $vals['rcid'] = (int)$row->rc_id;
514 }
515
516 /* Add user data and 'anon' flag, if user is anonymous. */
517 if ( $this->fld_user || $this->fld_userid ) {
518 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
519 $vals['userhidden'] = true;
520 $anyHidden = true;
521 }
522 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
523 if ( $this->fld_user ) {
524 $vals['user'] = $row->rc_user_text;
525 }
526
527 if ( $this->fld_userid ) {
528 $vals['userid'] = (int)$row->rc_user;
529 }
530
531 if ( !$row->rc_user ) {
532 $vals['anon'] = true;
533 }
534 }
535 }
536
537 /* Add flags, such as new, minor, bot. */
538 if ( $this->fld_flags ) {
539 $vals['bot'] = (bool)$row->rc_bot;
540 $vals['new'] = $row->rc_type == RC_NEW;
541 $vals['minor'] = (bool)$row->rc_minor;
542 }
543
544 /* Add sizes of each revision. (Only available on 1.10+) */
545 if ( $this->fld_sizes ) {
546 $vals['oldlen'] = (int)$row->rc_old_len;
547 $vals['newlen'] = (int)$row->rc_new_len;
548 }
549
550 /* Add the timestamp. */
551 if ( $this->fld_timestamp ) {
552 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
553 }
554
555 /* Add edit summary / log summary. */
556 if ( $this->fld_comment || $this->fld_parsedcomment ) {
557 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
558 $vals['commenthidden'] = true;
559 $anyHidden = true;
560 }
561 if ( RevisionRecord::userCanBitfield(
562 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
563 ) ) {
564 $comment = $this->commentStore->getComment( 'rc_comment', $row )->text;
565 if ( $this->fld_comment ) {
566 $vals['comment'] = $comment;
567 }
568
569 if ( $this->fld_parsedcomment ) {
570 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
571 }
572 }
573 }
574
575 if ( $this->fld_redirect ) {
576 $vals['redirect'] = (bool)$row->page_is_redirect;
577 }
578
579 /* Add the patrolled flag */
580 if ( $this->fld_patrolled ) {
581 $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
582 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
583 $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
584 }
585
586 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
587 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
588 $vals['actionhidden'] = true;
589 $anyHidden = true;
590 }
591 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
592 $vals['logid'] = (int)$row->rc_logid;
593 $vals['logtype'] = $row->rc_log_type;
594 $vals['logaction'] = $row->rc_log_action;
595 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
596 }
597 }
598
599 if ( $this->fld_tags ) {
600 if ( $row->ts_tags ) {
601 $tags = explode( ',', $row->ts_tags );
602 ApiResult::setIndexedTagName( $tags, 'tag' );
603 $vals['tags'] = $tags;
604 } else {
605 $vals['tags'] = [];
606 }
607 }
608
609 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
610 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
611 $vals['sha1hidden'] = true;
612 $anyHidden = true;
613 }
614 if ( RevisionRecord::userCanBitfield(
615 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
616 ) ) {
617 if ( $row->rev_sha1 !== '' ) {
618 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
619 } else {
620 $vals['sha1'] = '';
621 }
622 }
623 }
624
625 if ( !is_null( $this->token ) ) {
627 foreach ( $this->token as $t ) {
628 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
629 $title, RecentChange::newFromRow( $row ) );
630 if ( $val === false ) {
631 $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
632 } else {
633 $vals[$t . 'token'] = $val;
634 }
635 }
636 }
637
638 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
639 $vals['suppressed'] = true;
640 }
641
642 return $vals;
643 }
644
649 private function includesPatrollingFlags( array $flagsArray ) {
650 return isset( $flagsArray['patrolled'] ) ||
651 isset( $flagsArray['!patrolled'] ) ||
652 isset( $flagsArray['unpatrolled'] ) ||
653 isset( $flagsArray['autopatrolled'] ) ||
654 isset( $flagsArray['!autopatrolled'] );
655 }
656
657 public function getCacheMode( $params ) {
658 if ( isset( $params['show'] ) &&
659 $this->includesPatrollingFlags( array_flip( $params['show'] ) )
660 ) {
661 return 'private';
662 }
663 if ( isset( $params['token'] ) ) {
664 return 'private';
665 }
666 if ( $this->userCanSeeRevDel() ) {
667 return 'private';
668 }
669 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
670 // formatComment() calls wfMessage() among other things
671 return 'anon-public-user-private';
672 }
673
674 return 'public';
675 }
676
677 public function getAllowedParams() {
678 return [
679 'start' => [
680 ApiBase::PARAM_TYPE => 'timestamp'
681 ],
682 'end' => [
683 ApiBase::PARAM_TYPE => 'timestamp'
684 ],
685 'dir' => [
686 ApiBase::PARAM_DFLT => 'older',
688 'newer',
689 'older'
690 ],
691 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
692 ],
693 'namespace' => [
695 ApiBase::PARAM_TYPE => 'namespace',
697 ],
698 'user' => [
699 ApiBase::PARAM_TYPE => 'user'
700 ],
701 'excludeuser' => [
702 ApiBase::PARAM_TYPE => 'user'
703 ],
704 'tag' => null,
705 'prop' => [
707 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
709 'user',
710 'userid',
711 'comment',
712 'parsedcomment',
713 'flags',
714 'timestamp',
715 'title',
716 'ids',
717 'sizes',
718 'redirect',
719 'patrolled',
720 'loginfo',
721 'tags',
722 'sha1',
723 ],
725 ],
726 'token' => [
728 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
730 ],
731 'show' => [
734 'minor',
735 '!minor',
736 'bot',
737 '!bot',
738 'anon',
739 '!anon',
740 'redirect',
741 '!redirect',
742 'patrolled',
743 '!patrolled',
744 'unpatrolled',
745 'autopatrolled',
746 '!autopatrolled',
747 ]
748 ],
749 'limit' => [
751 ApiBase::PARAM_TYPE => 'limit',
755 ],
756 'type' => [
757 ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
759 ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
760 ],
761 'toponly' => false,
762 'title' => null,
763 'continue' => [
764 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
765 ],
766 'generaterevisions' => false,
767 ];
768 }
769
770 protected function getExamplesMessages() {
771 return [
772 'action=query&list=recentchanges'
773 => 'apihelp-query+recentchanges-example-simple',
774 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
775 => 'apihelp-query+recentchanges-example-generator',
776 ];
777 }
778
779 public function getHelpUrls() {
780 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
781 }
782}
getUser()
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:103
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:112
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:97
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:2014
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2208
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:2220
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:94
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:55
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
Definition ApiBase.php:710
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:164
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:106
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:259
getResult()
Get the result object.
Definition ApiBase.php:640
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:761
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:931
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
Definition ApiBase.php:193
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:131
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1933
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:261
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:520
getContinuationManager()
Get the continuation manager.
Definition ApiBase.php:680
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:58
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Definition ApiBase.php:568
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
A query action to enumerate the recent changes that were done to the wiki.
includesPatrollingFlags(array $flagsArray)
__construct(ApiQuery $query, $moduleName)
static getPatrolToken( $pageid, $title, $rc=null)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
initProperties( $prop)
Sets internal state to include the desired properties in the output.
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
getTokenFunctions()
Get an array mapping token names to their handler functions.
This is the main query class.
Definition ApiQuery.php:37
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static makeTagSummarySubquery( $tables)
Make the tag summary subquery based on the given tables and return it.
static isUnpatrolled( $rc, User $user)
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:1165
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row,...
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
const DELETED_RESTRICTED
Definition LogPage.php:37
const DELETED_ACTION
Definition LogPage.php:34
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Exception representing a failure to look up a row from a name table.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:518
const RC_NEW
Definition Defines.php:132
const NS_SPECIAL
Definition Defines.php:58
const LIST_OR
Definition Defines.php:51
const RC_LOG
Definition Defines.php:133
const NS_MEDIA
Definition Defines.php:57
const RC_EDIT
Definition Defines.php:131
return true
Definition router.php:94