Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
1 <?php
2 /**
3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * A query action to enumerate the recent changes that were done to the wiki.
25 * Various filters are supported.
26 *
27 * @ingroup API
28 */
29 class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
30
31 public function __construct( ApiQuery $query, $moduleName ) {
32 parent::__construct( $query, $moduleName, 'rc' );
33 }
34
35 private $commentStore;
36
37 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
38 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
39 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
40 $fld_tags = false, $fld_sha1 = false, $token = [];
41
42 private $tokenFunctions;
43
44 /**
45 * Get an array mapping token names to their handler functions.
46 * The prototype for a token function is func($pageid, $title, $rc)
47 * it should return a token or false (permission denied)
48 * @deprecated since 1.24
49 * @return array [ tokenname => function ]
50 */
51 protected function getTokenFunctions() {
52 // Don't call the hooks twice
53 if ( isset( $this->tokenFunctions ) ) {
54 return $this->tokenFunctions;
55 }
56
57 // If we're in a mode that breaks the same-origin policy, no tokens can
58 // be obtained
59 if ( $this->lacksSameOriginSecurity() ) {
60 return [];
61 }
62
63 $this->tokenFunctions = [
64 'patrol' => [ self::class, 'getPatrolToken' ]
65 ];
66 Hooks::run( 'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
67
68 return $this->tokenFunctions;
69 }
70
71 /**
72 * @deprecated since 1.24
73 * @param int $pageid
74 * @param Title $title
75 * @param RecentChange|null $rc
76 * @return bool|string
77 */
78 public static function getPatrolToken( $pageid, $title, $rc = null ) {
79 global $wgUser;
80
81 $validTokenUser = false;
82
83 if ( $rc ) {
84 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
85 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
86 ) {
87 $validTokenUser = true;
88 }
89 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
90 $validTokenUser = true;
91 }
92
93 if ( $validTokenUser ) {
94 // The patrol token is always the same, let's exploit that
95 static $cachedPatrolToken = null;
96
97 if ( is_null( $cachedPatrolToken ) ) {
98 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
99 }
100
101 return $cachedPatrolToken;
102 }
103
104 return false;
105 }
106
107 /**
108 * Sets internal state to include the desired properties in the output.
109 * @param array $prop Associative array of properties, only keys are used here
110 */
111 public function initProperties( $prop ) {
112 $this->fld_comment = isset( $prop['comment'] );
113 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
114 $this->fld_user = isset( $prop['user'] );
115 $this->fld_userid = isset( $prop['userid'] );
116 $this->fld_flags = isset( $prop['flags'] );
117 $this->fld_timestamp = isset( $prop['timestamp'] );
118 $this->fld_title = isset( $prop['title'] );
119 $this->fld_ids = isset( $prop['ids'] );
120 $this->fld_sizes = isset( $prop['sizes'] );
121 $this->fld_redirect = isset( $prop['redirect'] );
122 $this->fld_patrolled = isset( $prop['patrolled'] );
123 $this->fld_loginfo = isset( $prop['loginfo'] );
124 $this->fld_tags = isset( $prop['tags'] );
125 $this->fld_sha1 = isset( $prop['sha1'] );
126 }
127
128 public function execute() {
129 $this->run();
130 }
131
132 public function executeGenerator( $resultPageSet ) {
133 $this->run( $resultPageSet );
134 }
135
136 /**
137 * Generates and outputs the result of this query based upon the provided parameters.
138 *
139 * @param ApiPageSet $resultPageSet
140 */
141 public function run( $resultPageSet = null ) {
142 $user = $this->getUser();
143 /* Get the parameters of the request. */
144 $params = $this->extractRequestParams();
145
146 /* Build our basic query. Namely, something along the lines of:
147 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
148 * AND rc_timestamp < $end AND rc_namespace = $namespace
149 */
150 $this->addTables( 'recentchanges' );
151 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
152
153 if ( !is_null( $params['continue'] ) ) {
154 $cont = explode( '|', $params['continue'] );
155 $this->dieContinueUsageIf( count( $cont ) != 2 );
156 $db = $this->getDB();
157 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
158 $id = intval( $cont[1] );
159 $this->dieContinueUsageIf( $id != $cont[1] );
160 $op = $params['dir'] === 'older' ? '<' : '>';
161 $this->addWhere(
162 "rc_timestamp $op $timestamp OR " .
163 "(rc_timestamp = $timestamp AND " .
164 "rc_id $op= $id)"
165 );
166 }
167
168 $order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
169 $this->addOption( 'ORDER BY', [
170 "rc_timestamp $order",
171 "rc_id $order",
172 ] );
173
174 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
175
176 if ( !is_null( $params['type'] ) ) {
177 try {
178 $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
179 } catch ( Exception $e ) {
180 ApiBase::dieDebug( __METHOD__, $e->getMessage() );
181 }
182 }
183
184 if ( !is_null( $params['show'] ) ) {
185 $show = array_flip( $params['show'] );
186
187 /* Check for conflicting parameters. */
188 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
189 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
190 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
191 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
192 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
193 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
194 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
195 ) {
196 $this->dieWithError( 'apierror-show' );
197 }
198
199 // Check permissions
200 if ( isset( $show['patrolled'] )
201 || isset( $show['!patrolled'] )
202 || isset( $show['unpatrolled'] )
203 ) {
204 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
205 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
206 }
207 }
208
209 /* Add additional conditions to query depending upon parameters. */
210 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
211 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
212 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
213 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
214 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
215 $actorMigration = ActorMigration::newMigration();
216 $actorQuery = $actorMigration->getJoin( 'rc_user' );
217 $this->addTables( $actorQuery['tables'] );
218 $this->addJoinConds( $actorQuery['joins'] );
219 $this->addWhereIf(
220 $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
221 );
222 $this->addWhereIf(
223 $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
224 );
225 }
226 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
227 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
228 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
229
230 if ( isset( $show['unpatrolled'] ) ) {
231 // See ChangesList::isUnpatrolled
232 if ( $user->useRCPatrol() ) {
233 $this->addWhere( 'rc_patrolled = 0' );
234 } elseif ( $user->useNPPatrol() ) {
235 $this->addWhere( 'rc_patrolled = 0' );
236 $this->addWhereFld( 'rc_type', RC_NEW );
237 }
238 }
239
240 // Don't throw log entries out the window here
241 $this->addWhereIf(
242 'page_is_redirect = 0 OR page_is_redirect IS NULL',
243 isset( $show['!redirect'] )
244 );
245 }
246
247 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
248
249 if ( !is_null( $params['user'] ) ) {
250 // Don't query by user ID here, it might be able to use the rc_user_text index.
251 $actorQuery = ActorMigration::newMigration()
252 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
253 $this->addTables( $actorQuery['tables'] );
254 $this->addJoinConds( $actorQuery['joins'] );
255 $this->addWhere( $actorQuery['conds'] );
256 }
257
258 if ( !is_null( $params['excludeuser'] ) ) {
259 // Here there's no chance to use the rc_user_text index, so allow ID to be used.
260 $actorQuery = ActorMigration::newMigration()
261 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
262 $this->addTables( $actorQuery['tables'] );
263 $this->addJoinConds( $actorQuery['joins'] );
264 $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
265 }
266
267 /* Add the fields we're concerned with to our query. */
268 $this->addFields( [
269 'rc_id',
270 'rc_timestamp',
271 'rc_namespace',
272 'rc_title',
273 'rc_cur_id',
274 'rc_type',
275 'rc_deleted'
276 ] );
277
278 $showRedirects = false;
279 /* Determine what properties we need to display. */
280 if ( !is_null( $params['prop'] ) ) {
281 $prop = array_flip( $params['prop'] );
282
283 /* Set up internal members based upon params. */
284 $this->initProperties( $prop );
285
286 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
287 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
288 }
289
290 /* Add fields to our query if they are specified as a needed parameter. */
291 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
292 if ( $this->fld_user || $this->fld_userid ) {
293 $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
294 $this->addTables( $actorQuery['tables'] );
295 $this->addFields( $actorQuery['fields'] );
296 $this->addJoinConds( $actorQuery['joins'] );
297 }
298 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
299 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
300 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
301 $this->addFieldsIf(
302 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
303 $this->fld_loginfo
304 );
305 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
306 || isset( $show['!redirect'] );
307 }
308 $this->addFieldsIf( [ 'rc_this_oldid' ],
309 $resultPageSet && $params['generaterevisions'] );
310
311 if ( $this->fld_tags ) {
312 $this->addTables( 'tag_summary' );
313 $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
314 $this->addFields( 'ts_tags' );
315 }
316
317 if ( $this->fld_sha1 ) {
318 $this->addTables( 'revision' );
319 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
320 [ 'rc_this_oldid=rev_id' ] ] ] );
321 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
322 }
323
324 if ( $params['toponly'] || $showRedirects ) {
325 $this->addTables( 'page' );
326 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
327 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
328 $this->addFields( 'page_is_redirect' );
329
330 if ( $params['toponly'] ) {
331 $this->addWhere( 'rc_this_oldid = page_latest' );
332 }
333 }
334
335 if ( !is_null( $params['tag'] ) ) {
336 $this->addTables( 'change_tag' );
337 $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
338 $this->addWhereFld( 'ct_tag', $params['tag'] );
339 }
340
341 // Paranoia: avoid brute force searches (T19342)
342 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
343 if ( !$user->isAllowed( 'deletedhistory' ) ) {
344 $bitmask = Revision::DELETED_USER;
345 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
346 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
347 } else {
348 $bitmask = 0;
349 }
350 if ( $bitmask ) {
351 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
352 }
353 }
354 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
355 // LogPage::DELETED_ACTION hides the affected page, too.
356 if ( !$user->isAllowed( 'deletedhistory' ) ) {
357 $bitmask = LogPage::DELETED_ACTION;
358 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
359 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
360 } else {
361 $bitmask = 0;
362 }
363 if ( $bitmask ) {
364 $this->addWhere( $this->getDB()->makeList( [
365 'rc_type != ' . RC_LOG,
366 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
367 ], LIST_OR ) );
368 }
369 }
370
371 $this->token = $params['token'];
372
373 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
374 $this->commentStore = CommentStore::getStore();
375 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
376 $this->addTables( $commentQuery['tables'] );
377 $this->addFields( $commentQuery['fields'] );
378 $this->addJoinConds( $commentQuery['joins'] );
379 }
380
381 $this->addOption( 'LIMIT', $params['limit'] + 1 );
382
383 $hookData = [];
384 $count = 0;
385 /* Perform the actual query. */
386 $res = $this->select( __METHOD__, [], $hookData );
387
388 $revids = [];
389 $titles = [];
390
391 $result = $this->getResult();
392
393 /* Iterate through the rows, adding data extracted from them to our query result. */
394 foreach ( $res as $row ) {
395 if ( $count === 0 && $resultPageSet !== null ) {
396 // Set the non-continue since the list of recentchanges is
397 // prone to having entries added at the start frequently.
398 $this->getContinuationManager()->addGeneratorNonContinueParam(
399 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
400 );
401 }
402 if ( ++$count > $params['limit'] ) {
403 // We've reached the one extra which shows that there are
404 // additional pages to be had. Stop here...
405 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
406 break;
407 }
408
409 if ( is_null( $resultPageSet ) ) {
410 /* Extract the data from a single row. */
411 $vals = $this->extractRowInfo( $row );
412
413 /* Add that row's data to our final output. */
414 $fit = $this->processRow( $row, $vals, $hookData ) &&
415 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
416 if ( !$fit ) {
417 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
418 break;
419 }
420 } elseif ( $params['generaterevisions'] ) {
421 $revid = (int)$row->rc_this_oldid;
422 if ( $revid > 0 ) {
423 $revids[] = $revid;
424 }
425 } else {
426 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
427 }
428 }
429
430 if ( is_null( $resultPageSet ) ) {
431 /* Format the result */
432 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
433 } elseif ( $params['generaterevisions'] ) {
434 $resultPageSet->populateFromRevisionIDs( $revids );
435 } else {
436 $resultPageSet->populateFromTitles( $titles );
437 }
438 }
439
440 /**
441 * Extracts from a single sql row the data needed to describe one recent change.
442 *
443 * @param stdClass $row The row from which to extract the data.
444 * @return array An array mapping strings (descriptors) to their respective string values.
445 * @access public
446 */
447 public function extractRowInfo( $row ) {
448 /* Determine the title of the page that has been changed. */
449 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
450 $user = $this->getUser();
451
452 /* Our output data. */
453 $vals = [];
454
455 $type = intval( $row->rc_type );
456 $vals['type'] = RecentChange::parseFromRCType( $type );
457
458 $anyHidden = false;
459
460 /* Create a new entry in the result for the title. */
461 if ( $this->fld_title || $this->fld_ids ) {
462 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
463 $vals['actionhidden'] = true;
464 $anyHidden = true;
465 }
466 if ( $type !== RC_LOG ||
467 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
468 ) {
469 if ( $this->fld_title ) {
470 ApiQueryBase::addTitleInfo( $vals, $title );
471 }
472 if ( $this->fld_ids ) {
473 $vals['pageid'] = intval( $row->rc_cur_id );
474 $vals['revid'] = intval( $row->rc_this_oldid );
475 $vals['old_revid'] = intval( $row->rc_last_oldid );
476 }
477 }
478 }
479
480 if ( $this->fld_ids ) {
481 $vals['rcid'] = intval( $row->rc_id );
482 }
483
484 /* Add user data and 'anon' flag, if user is anonymous. */
485 if ( $this->fld_user || $this->fld_userid ) {
486 if ( $row->rc_deleted & Revision::DELETED_USER ) {
487 $vals['userhidden'] = true;
488 $anyHidden = true;
489 }
490 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
491 if ( $this->fld_user ) {
492 $vals['user'] = $row->rc_user_text;
493 }
494
495 if ( $this->fld_userid ) {
496 $vals['userid'] = (int)$row->rc_user;
497 }
498
499 if ( !$row->rc_user ) {
500 $vals['anon'] = true;
501 }
502 }
503 }
504
505 /* Add flags, such as new, minor, bot. */
506 if ( $this->fld_flags ) {
507 $vals['bot'] = (bool)$row->rc_bot;
508 $vals['new'] = $row->rc_type == RC_NEW;
509 $vals['minor'] = (bool)$row->rc_minor;
510 }
511
512 /* Add sizes of each revision. (Only available on 1.10+) */
513 if ( $this->fld_sizes ) {
514 $vals['oldlen'] = intval( $row->rc_old_len );
515 $vals['newlen'] = intval( $row->rc_new_len );
516 }
517
518 /* Add the timestamp. */
519 if ( $this->fld_timestamp ) {
520 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
521 }
522
523 /* Add edit summary / log summary. */
524 if ( $this->fld_comment || $this->fld_parsedcomment ) {
525 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
526 $vals['commenthidden'] = true;
527 $anyHidden = true;
528 }
529 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
530 $comment = $this->commentStore->getComment( 'rc_comment', $row )->text;
531 if ( $this->fld_comment ) {
532 $vals['comment'] = $comment;
533 }
534
535 if ( $this->fld_parsedcomment ) {
536 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
537 }
538 }
539 }
540
541 if ( $this->fld_redirect ) {
542 $vals['redirect'] = (bool)$row->page_is_redirect;
543 }
544
545 /* Add the patrolled flag */
546 if ( $this->fld_patrolled ) {
547 $vals['patrolled'] = $row->rc_patrolled == 1;
548 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
549 }
550
551 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
552 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
553 $vals['actionhidden'] = true;
554 $anyHidden = true;
555 }
556 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
557 $vals['logid'] = intval( $row->rc_logid );
558 $vals['logtype'] = $row->rc_log_type;
559 $vals['logaction'] = $row->rc_log_action;
560 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
561 }
562 }
563
564 if ( $this->fld_tags ) {
565 if ( $row->ts_tags ) {
566 $tags = explode( ',', $row->ts_tags );
567 ApiResult::setIndexedTagName( $tags, 'tag' );
568 $vals['tags'] = $tags;
569 } else {
570 $vals['tags'] = [];
571 }
572 }
573
574 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
575 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
576 $vals['sha1hidden'] = true;
577 $anyHidden = true;
578 }
579 if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
580 if ( $row->rev_sha1 !== '' ) {
581 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
582 } else {
583 $vals['sha1'] = '';
584 }
585 }
586 }
587
588 if ( !is_null( $this->token ) ) {
589 $tokenFunctions = $this->getTokenFunctions();
590 foreach ( $this->token as $t ) {
591 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
592 $title, RecentChange::newFromRow( $row ) );
593 if ( $val === false ) {
594 $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
595 } else {
596 $vals[$t . 'token'] = $val;
597 }
598 }
599 }
600
601 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
602 $vals['suppressed'] = true;
603 }
604
605 return $vals;
606 }
607
608 public function getCacheMode( $params ) {
609 if ( isset( $params['show'] ) ) {
610 foreach ( $params['show'] as $show ) {
611 if ( $show === 'patrolled' || $show === '!patrolled' ) {
612 return 'private';
613 }
614 }
615 }
616 if ( isset( $params['token'] ) ) {
617 return 'private';
618 }
619 if ( $this->userCanSeeRevDel() ) {
620 return 'private';
621 }
622 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
623 // formatComment() calls wfMessage() among other things
624 return 'anon-public-user-private';
625 }
626
627 return 'public';
628 }
629
630 public function getAllowedParams() {
631 return [
632 'start' => [
633 ApiBase::PARAM_TYPE => 'timestamp'
634 ],
635 'end' => [
636 ApiBase::PARAM_TYPE => 'timestamp'
637 ],
638 'dir' => [
639 ApiBase::PARAM_DFLT => 'older',
640 ApiBase::PARAM_TYPE => [
641 'newer',
642 'older'
643 ],
644 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
645 ],
646 'namespace' => [
647 ApiBase::PARAM_ISMULTI => true,
648 ApiBase::PARAM_TYPE => 'namespace',
649 ApiBase::PARAM_EXTRA_NAMESPACES => [ NS_MEDIA, NS_SPECIAL ],
650 ],
651 'user' => [
652 ApiBase::PARAM_TYPE => 'user'
653 ],
654 'excludeuser' => [
655 ApiBase::PARAM_TYPE => 'user'
656 ],
657 'tag' => null,
658 'prop' => [
659 ApiBase::PARAM_ISMULTI => true,
660 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
661 ApiBase::PARAM_TYPE => [
662 'user',
663 'userid',
664 'comment',
665 'parsedcomment',
666 'flags',
667 'timestamp',
668 'title',
669 'ids',
670 'sizes',
671 'redirect',
672 'patrolled',
673 'loginfo',
674 'tags',
675 'sha1',
676 ],
677 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
678 ],
679 'token' => [
680 ApiBase::PARAM_DEPRECATED => true,
681 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
682 ApiBase::PARAM_ISMULTI => true
683 ],
684 'show' => [
685 ApiBase::PARAM_ISMULTI => true,
686 ApiBase::PARAM_TYPE => [
687 'minor',
688 '!minor',
689 'bot',
690 '!bot',
691 'anon',
692 '!anon',
693 'redirect',
694 '!redirect',
695 'patrolled',
696 '!patrolled',
697 'unpatrolled'
698 ]
699 ],
700 'limit' => [
701 ApiBase::PARAM_DFLT => 10,
702 ApiBase::PARAM_TYPE => 'limit',
703 ApiBase::PARAM_MIN => 1,
704 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
705 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
706 ],
707 'type' => [
708 ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
709 ApiBase::PARAM_ISMULTI => true,
710 ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
711 ],
712 'toponly' => false,
713 'continue' => [
714 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
715 ],
716 'generaterevisions' => false,
717 ];
718 }
719
720 protected function getExamplesMessages() {
721 return [
722 'action=query&list=recentchanges'
723 => 'apihelp-query+recentchanges-example-simple',
724 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
725 => 'apihelp-query+recentchanges-example-generator',
726 ];
727 }
728
729 public function getHelpUrls() {
730 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
731 }
732 }