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