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