Merge "Remove "probably you" from password reset email information"
[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 || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
196 || ( isset( $show['autopatrolled'] ) && isset( $show['unpatrolled'] ) )
197 || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
198 ) {
199 $this->dieWithError( 'apierror-show' );
200 }
201
202 // Check permissions
203 if ( isset( $show['patrolled'] )
204 || isset( $show['!patrolled'] )
205 || isset( $show['unpatrolled'] )
206 || isset( $show['autopatrolled'] )
207 || isset( $show['!autopatrolled'] )
208 ) {
209 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
210 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
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 if ( isset( $show['anon'] ) || isset( $show['!anon'] ) ) {
220 $actorMigration = ActorMigration::newMigration();
221 $actorQuery = $actorMigration->getJoin( 'rc_user' );
222 $this->addTables( $actorQuery['tables'] );
223 $this->addJoinConds( $actorQuery['joins'] );
224 $this->addWhereIf(
225 $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ), isset( $show['anon'] )
226 );
227 $this->addWhereIf(
228 $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ), isset( $show['!anon'] )
229 );
230 }
231 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
232 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
233 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
234
235 if ( isset( $show['unpatrolled'] ) ) {
236 // See ChangesList::isUnpatrolled
237 if ( $user->useRCPatrol() ) {
238 $this->addWhere( 'rc_patrolled = 0' );
239 } elseif ( $user->useNPPatrol() ) {
240 $this->addWhere( 'rc_patrolled = 0' );
241 $this->addWhereFld( 'rc_type', RC_NEW );
242 }
243 }
244
245 $this->addWhereIf( 'rc_patrolled != 2', isset( $show['!autopatrolled'] ) );
246 $this->addWhereIf( 'rc_patrolled = 2', isset( $show['autopatrolled'] ) );
247
248 // Don't throw log entries out the window here
249 $this->addWhereIf(
250 'page_is_redirect = 0 OR page_is_redirect IS NULL',
251 isset( $show['!redirect'] )
252 );
253 }
254
255 $this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
256
257 if ( !is_null( $params['user'] ) ) {
258 // Don't query by user ID here, it might be able to use the rc_user_text index.
259 $actorQuery = ActorMigration::newMigration()
260 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['user'], false ), false );
261 $this->addTables( $actorQuery['tables'] );
262 $this->addJoinConds( $actorQuery['joins'] );
263 $this->addWhere( $actorQuery['conds'] );
264 }
265
266 if ( !is_null( $params['excludeuser'] ) ) {
267 // Here there's no chance to use the rc_user_text index, so allow ID to be used.
268 $actorQuery = ActorMigration::newMigration()
269 ->getWhere( $this->getDB(), 'rc_user', User::newFromName( $params['excludeuser'], false ) );
270 $this->addTables( $actorQuery['tables'] );
271 $this->addJoinConds( $actorQuery['joins'] );
272 $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
273 }
274
275 /* Add the fields we're concerned with to our query. */
276 $this->addFields( [
277 'rc_id',
278 'rc_timestamp',
279 'rc_namespace',
280 'rc_title',
281 'rc_cur_id',
282 'rc_type',
283 'rc_deleted'
284 ] );
285
286 $showRedirects = false;
287 /* Determine what properties we need to display. */
288 if ( !is_null( $params['prop'] ) ) {
289 $prop = array_flip( $params['prop'] );
290
291 /* Set up internal members based upon params. */
292 $this->initProperties( $prop );
293
294 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
295 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
296 }
297
298 /* Add fields to our query if they are specified as a needed parameter. */
299 $this->addFieldsIf( [ 'rc_this_oldid', 'rc_last_oldid' ], $this->fld_ids );
300 if ( $this->fld_user || $this->fld_userid ) {
301 $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
302 $this->addTables( $actorQuery['tables'] );
303 $this->addFields( $actorQuery['fields'] );
304 $this->addJoinConds( $actorQuery['joins'] );
305 }
306 $this->addFieldsIf( [ 'rc_minor', 'rc_type', 'rc_bot' ], $this->fld_flags );
307 $this->addFieldsIf( [ 'rc_old_len', 'rc_new_len' ], $this->fld_sizes );
308 $this->addFieldsIf( [ 'rc_patrolled', 'rc_log_type' ], $this->fld_patrolled );
309 $this->addFieldsIf(
310 [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ],
311 $this->fld_loginfo
312 );
313 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
314 || isset( $show['!redirect'] );
315 }
316 $this->addFieldsIf( [ 'rc_this_oldid' ],
317 $resultPageSet && $params['generaterevisions'] );
318
319 if ( $this->fld_tags ) {
320 $this->addTables( 'tag_summary' );
321 $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
322 $this->addFields( 'ts_tags' );
323 }
324
325 if ( $this->fld_sha1 ) {
326 $this->addTables( 'revision' );
327 $this->addJoinConds( [ 'revision' => [ 'LEFT JOIN',
328 [ 'rc_this_oldid=rev_id' ] ] ] );
329 $this->addFields( [ 'rev_sha1', 'rev_deleted' ] );
330 }
331
332 if ( $params['toponly'] || $showRedirects ) {
333 $this->addTables( 'page' );
334 $this->addJoinConds( [ 'page' => [ 'LEFT JOIN',
335 [ 'rc_namespace=page_namespace', 'rc_title=page_title' ] ] ] );
336 $this->addFields( 'page_is_redirect' );
337
338 if ( $params['toponly'] ) {
339 $this->addWhere( 'rc_this_oldid = page_latest' );
340 }
341 }
342
343 if ( !is_null( $params['tag'] ) ) {
344 $this->addTables( 'change_tag' );
345 $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
346 $this->addWhereFld( 'ct_tag', $params['tag'] );
347 }
348
349 // Paranoia: avoid brute force searches (T19342)
350 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
351 if ( !$user->isAllowed( 'deletedhistory' ) ) {
352 $bitmask = Revision::DELETED_USER;
353 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
354 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
355 } else {
356 $bitmask = 0;
357 }
358 if ( $bitmask ) {
359 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
360 }
361 }
362 if ( $this->getRequest()->getCheck( 'namespace' ) ) {
363 // LogPage::DELETED_ACTION hides the affected page, too.
364 if ( !$user->isAllowed( 'deletedhistory' ) ) {
365 $bitmask = LogPage::DELETED_ACTION;
366 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
367 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
368 } else {
369 $bitmask = 0;
370 }
371 if ( $bitmask ) {
372 $this->addWhere( $this->getDB()->makeList( [
373 'rc_type != ' . RC_LOG,
374 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
375 ], LIST_OR ) );
376 }
377 }
378
379 $this->token = $params['token'];
380
381 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
382 $this->commentStore = CommentStore::getStore();
383 $commentQuery = $this->commentStore->getJoin( 'rc_comment' );
384 $this->addTables( $commentQuery['tables'] );
385 $this->addFields( $commentQuery['fields'] );
386 $this->addJoinConds( $commentQuery['joins'] );
387 }
388
389 $this->addOption( 'LIMIT', $params['limit'] + 1 );
390
391 $hookData = [];
392 $count = 0;
393 /* Perform the actual query. */
394 $res = $this->select( __METHOD__, [], $hookData );
395
396 $revids = [];
397 $titles = [];
398
399 $result = $this->getResult();
400
401 /* Iterate through the rows, adding data extracted from them to our query result. */
402 foreach ( $res as $row ) {
403 if ( $count === 0 && $resultPageSet !== null ) {
404 // Set the non-continue since the list of recentchanges is
405 // prone to having entries added at the start frequently.
406 $this->getContinuationManager()->addGeneratorNonContinueParam(
407 $this, 'continue', "$row->rc_timestamp|$row->rc_id"
408 );
409 }
410 if ( ++$count > $params['limit'] ) {
411 // We've reached the one extra which shows that there are
412 // additional pages to be had. Stop here...
413 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
414 break;
415 }
416
417 if ( is_null( $resultPageSet ) ) {
418 /* Extract the data from a single row. */
419 $vals = $this->extractRowInfo( $row );
420
421 /* Add that row's data to our final output. */
422 $fit = $this->processRow( $row, $vals, $hookData ) &&
423 $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
424 if ( !$fit ) {
425 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
426 break;
427 }
428 } elseif ( $params['generaterevisions'] ) {
429 $revid = (int)$row->rc_this_oldid;
430 if ( $revid > 0 ) {
431 $revids[] = $revid;
432 }
433 } else {
434 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
435 }
436 }
437
438 if ( is_null( $resultPageSet ) ) {
439 /* Format the result */
440 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'rc' );
441 } elseif ( $params['generaterevisions'] ) {
442 $resultPageSet->populateFromRevisionIDs( $revids );
443 } else {
444 $resultPageSet->populateFromTitles( $titles );
445 }
446 }
447
448 /**
449 * Extracts from a single sql row the data needed to describe one recent change.
450 *
451 * @param stdClass $row The row from which to extract the data.
452 * @return array An array mapping strings (descriptors) to their respective string values.
453 * @access public
454 */
455 public function extractRowInfo( $row ) {
456 /* Determine the title of the page that has been changed. */
457 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
458 $user = $this->getUser();
459
460 /* Our output data. */
461 $vals = [];
462
463 $type = intval( $row->rc_type );
464 $vals['type'] = RecentChange::parseFromRCType( $type );
465
466 $anyHidden = false;
467
468 /* Create a new entry in the result for the title. */
469 if ( $this->fld_title || $this->fld_ids ) {
470 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
471 $vals['actionhidden'] = true;
472 $anyHidden = true;
473 }
474 if ( $type !== RC_LOG ||
475 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
476 ) {
477 if ( $this->fld_title ) {
478 ApiQueryBase::addTitleInfo( $vals, $title );
479 }
480 if ( $this->fld_ids ) {
481 $vals['pageid'] = intval( $row->rc_cur_id );
482 $vals['revid'] = intval( $row->rc_this_oldid );
483 $vals['old_revid'] = intval( $row->rc_last_oldid );
484 }
485 }
486 }
487
488 if ( $this->fld_ids ) {
489 $vals['rcid'] = intval( $row->rc_id );
490 }
491
492 /* Add user data and 'anon' flag, if user is anonymous. */
493 if ( $this->fld_user || $this->fld_userid ) {
494 if ( $row->rc_deleted & Revision::DELETED_USER ) {
495 $vals['userhidden'] = true;
496 $anyHidden = true;
497 }
498 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
499 if ( $this->fld_user ) {
500 $vals['user'] = $row->rc_user_text;
501 }
502
503 if ( $this->fld_userid ) {
504 $vals['userid'] = (int)$row->rc_user;
505 }
506
507 if ( !$row->rc_user ) {
508 $vals['anon'] = true;
509 }
510 }
511 }
512
513 /* Add flags, such as new, minor, bot. */
514 if ( $this->fld_flags ) {
515 $vals['bot'] = (bool)$row->rc_bot;
516 $vals['new'] = $row->rc_type == RC_NEW;
517 $vals['minor'] = (bool)$row->rc_minor;
518 }
519
520 /* Add sizes of each revision. (Only available on 1.10+) */
521 if ( $this->fld_sizes ) {
522 $vals['oldlen'] = intval( $row->rc_old_len );
523 $vals['newlen'] = intval( $row->rc_new_len );
524 }
525
526 /* Add the timestamp. */
527 if ( $this->fld_timestamp ) {
528 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
529 }
530
531 /* Add edit summary / log summary. */
532 if ( $this->fld_comment || $this->fld_parsedcomment ) {
533 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
534 $vals['commenthidden'] = true;
535 $anyHidden = true;
536 }
537 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
538 $comment = $this->commentStore->getComment( 'rc_comment', $row )->text;
539 if ( $this->fld_comment ) {
540 $vals['comment'] = $comment;
541 }
542
543 if ( $this->fld_parsedcomment ) {
544 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
545 }
546 }
547 }
548
549 if ( $this->fld_redirect ) {
550 $vals['redirect'] = (bool)$row->page_is_redirect;
551 }
552
553 /* Add the patrolled flag */
554 if ( $this->fld_patrolled ) {
555 $vals['patrolled'] = $row->rc_patrolled != 0;
556 $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
557 $vals['autopatrolled'] = $row->rc_patrolled == 2;
558 }
559
560 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
561 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
562 $vals['actionhidden'] = true;
563 $anyHidden = true;
564 }
565 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
566 $vals['logid'] = intval( $row->rc_logid );
567 $vals['logtype'] = $row->rc_log_type;
568 $vals['logaction'] = $row->rc_log_action;
569 $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
570 }
571 }
572
573 if ( $this->fld_tags ) {
574 if ( $row->ts_tags ) {
575 $tags = explode( ',', $row->ts_tags );
576 ApiResult::setIndexedTagName( $tags, 'tag' );
577 $vals['tags'] = $tags;
578 } else {
579 $vals['tags'] = [];
580 }
581 }
582
583 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
584 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
585 $vals['sha1hidden'] = true;
586 $anyHidden = true;
587 }
588 if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
589 if ( $row->rev_sha1 !== '' ) {
590 $vals['sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
591 } else {
592 $vals['sha1'] = '';
593 }
594 }
595 }
596
597 if ( !is_null( $this->token ) ) {
598 $tokenFunctions = $this->getTokenFunctions();
599 foreach ( $this->token as $t ) {
600 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
601 $title, RecentChange::newFromRow( $row ) );
602 if ( $val === false ) {
603 $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
604 } else {
605 $vals[$t . 'token'] = $val;
606 }
607 }
608 }
609
610 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
611 $vals['suppressed'] = true;
612 }
613
614 return $vals;
615 }
616
617 public function getCacheMode( $params ) {
618 if ( isset( $params['show'] ) ) {
619 foreach ( $params['show'] as $show ) {
620 if ( $show === 'patrolled' || $show === '!patrolled' ) {
621 return 'private';
622 }
623 }
624 }
625 if ( isset( $params['token'] ) ) {
626 return 'private';
627 }
628 if ( $this->userCanSeeRevDel() ) {
629 return 'private';
630 }
631 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
632 // formatComment() calls wfMessage() among other things
633 return 'anon-public-user-private';
634 }
635
636 return 'public';
637 }
638
639 public function getAllowedParams() {
640 return [
641 'start' => [
642 ApiBase::PARAM_TYPE => 'timestamp'
643 ],
644 'end' => [
645 ApiBase::PARAM_TYPE => 'timestamp'
646 ],
647 'dir' => [
648 ApiBase::PARAM_DFLT => 'older',
649 ApiBase::PARAM_TYPE => [
650 'newer',
651 'older'
652 ],
653 ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
654 ],
655 'namespace' => [
656 ApiBase::PARAM_ISMULTI => true,
657 ApiBase::PARAM_TYPE => 'namespace',
658 ApiBase::PARAM_EXTRA_NAMESPACES => [ NS_MEDIA, NS_SPECIAL ],
659 ],
660 'user' => [
661 ApiBase::PARAM_TYPE => 'user'
662 ],
663 'excludeuser' => [
664 ApiBase::PARAM_TYPE => 'user'
665 ],
666 'tag' => null,
667 'prop' => [
668 ApiBase::PARAM_ISMULTI => true,
669 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
670 ApiBase::PARAM_TYPE => [
671 'user',
672 'userid',
673 'comment',
674 'parsedcomment',
675 'flags',
676 'timestamp',
677 'title',
678 'ids',
679 'sizes',
680 'redirect',
681 'patrolled',
682 'loginfo',
683 'tags',
684 'sha1',
685 ],
686 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
687 ],
688 'token' => [
689 ApiBase::PARAM_DEPRECATED => true,
690 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
691 ApiBase::PARAM_ISMULTI => true
692 ],
693 'show' => [
694 ApiBase::PARAM_ISMULTI => true,
695 ApiBase::PARAM_TYPE => [
696 'minor',
697 '!minor',
698 'bot',
699 '!bot',
700 'anon',
701 '!anon',
702 'redirect',
703 '!redirect',
704 'patrolled',
705 '!patrolled',
706 'unpatrolled',
707 'autopatrolled',
708 '!autopatrolled',
709 ]
710 ],
711 'limit' => [
712 ApiBase::PARAM_DFLT => 10,
713 ApiBase::PARAM_TYPE => 'limit',
714 ApiBase::PARAM_MIN => 1,
715 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
716 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
717 ],
718 'type' => [
719 ApiBase::PARAM_DFLT => 'edit|new|log|categorize',
720 ApiBase::PARAM_ISMULTI => true,
721 ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
722 ],
723 'toponly' => false,
724 'continue' => [
725 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
726 ],
727 'generaterevisions' => false,
728 ];
729 }
730
731 protected function getExamplesMessages() {
732 return [
733 'action=query&list=recentchanges'
734 => 'apihelp-query+recentchanges-example-simple',
735 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
736 => 'apihelp-query+recentchanges-example-generator',
737 ];
738 }
739
740 public function getHelpUrls() {
741 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
742 }
743 }