Merge "Throw exception on invalid RecentChange types"
[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( $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'rc' );
37 }
38
39 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
40 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
41 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
42 $fld_tags = false, $fld_sha1 = false, $token = array();
43
44 private $tokenFunctions;
45
46 /**
47 * Get an array mapping token names to their handler functions.
48 * The prototype for a token function is func($pageid, $title, $rc)
49 * it should return a token or false (permission denied)
50 * @return array array(tokenname => function)
51 */
52 protected function getTokenFunctions() {
53 // Don't call the hooks twice
54 if ( isset( $this->tokenFunctions ) ) {
55 return $this->tokenFunctions;
56 }
57
58 // If we're in JSON callback mode, no tokens can be obtained
59 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
60 return array();
61 }
62
63 $this->tokenFunctions = array(
64 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' )
65 );
66 wfRunHooks( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) );
67
68 return $this->tokenFunctions;
69 }
70
71 /**
72 * @param $pageid
73 * @param $title
74 * @param $rc RecentChange (optional)
75 * @return bool|string
76 */
77 public static function getPatrolToken( $pageid, $title, $rc = null ) {
78 global $wgUser;
79
80 $validTokenUser = false;
81
82 if ( $rc ) {
83 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
84 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW )
85 ) {
86 $validTokenUser = true;
87 }
88 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
89 $validTokenUser = true;
90 }
91
92 if ( $validTokenUser ) {
93 // The patrol token is always the same, let's exploit that
94 static $cachedPatrolToken = null;
95
96 if ( is_null( $cachedPatrolToken ) ) {
97 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
98 }
99
100 return $cachedPatrolToken;
101 }
102
103 return false;
104 }
105
106 /**
107 * Sets internal state to include the desired properties in the output.
108 * @param array $prop associative array of properties, only keys are used here
109 */
110 public function initProperties( $prop ) {
111 $this->fld_comment = isset( $prop['comment'] );
112 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
113 $this->fld_user = isset( $prop['user'] );
114 $this->fld_userid = isset( $prop['userid'] );
115 $this->fld_flags = isset( $prop['flags'] );
116 $this->fld_timestamp = isset( $prop['timestamp'] );
117 $this->fld_title = isset( $prop['title'] );
118 $this->fld_ids = isset( $prop['ids'] );
119 $this->fld_sizes = isset( $prop['sizes'] );
120 $this->fld_redirect = isset( $prop['redirect'] );
121 $this->fld_patrolled = isset( $prop['patrolled'] );
122 $this->fld_loginfo = isset( $prop['loginfo'] );
123 $this->fld_tags = isset( $prop['tags'] );
124 $this->fld_sha1 = isset( $prop['sha1'] );
125 }
126
127 public function execute() {
128 $this->run();
129 }
130
131 public function executeGenerator( $resultPageSet ) {
132 $this->run( $resultPageSet );
133 }
134
135 /**
136 * Generates and outputs the result of this query based upon the provided parameters.
137 *
138 * @param $resultPageSet ApiPageSet
139 */
140 public function run( $resultPageSet = null ) {
141 $user = $this->getUser();
142 /* Get the parameters of the request. */
143 $params = $this->extractRequestParams();
144
145 /* Build our basic query. Namely, something along the lines of:
146 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
147 * AND rc_timestamp < $end AND rc_namespace = $namespace
148 * AND rc_deleted = 0
149 */
150 $this->addTables( 'recentchanges' );
151 $index = array( 'recentchanges' => 'rc_timestamp' ); // May change
152 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
153
154 if ( !is_null( $params['continue'] ) ) {
155 $cont = explode( '|', $params['continue'] );
156 if ( count( $cont ) != 2 ) {
157 $this->dieUsage( 'Invalid continue param. You should pass the ' .
158 'original value returned by the previous query', '_badcontinue' );
159 }
160
161 $timestamp = $this->getDB()->addQuotes( wfTimestamp( TS_MW, $cont[0] ) );
162 $id = intval( $cont[1] );
163 $op = $params['dir'] === 'older' ? '<' : '>';
164
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', array(
174 "rc_timestamp $order",
175 "rc_id $order",
176 ) );
177
178 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
179 $this->addWhereFld( 'rc_deleted', 0 );
180
181 if ( !is_null( $params['type'] ) ) {
182 $this->addWhereFld( 'rc_type', $this->parseRCType( $params['type'] ) );
183 }
184
185 if ( !is_null( $params['show'] ) ) {
186 $show = array_flip( $params['show'] );
187
188 /* Check for conflicting parameters. */
189 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
190 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
191 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
192 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
193 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
194 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
195 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
196 ) {
197 $this->dieUsageMsg( 'show' );
198 }
199
200 // Check permissions
201 if ( isset( $show['patrolled'] )
202 || isset( $show['!patrolled'] )
203 || isset( $show['unpatrolled'] )
204 ) {
205 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
206 $this->dieUsage(
207 'You need the patrol right to request the patrolled flag',
208 'permissiondenied'
209 );
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 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
242 $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
243 }
244
245 if ( !is_null( $params['user'] ) ) {
246 $this->addWhereFld( 'rc_user_text', $params['user'] );
247 $index['recentchanges'] = 'rc_user_text';
248 }
249
250 if ( !is_null( $params['excludeuser'] ) ) {
251 // We don't use the rc_user_text index here because
252 // * it would require us to sort by rc_user_text before rc_timestamp
253 // * the != condition doesn't throw out too many rows anyway
254 $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
255 }
256
257 /* Add the fields we're concerned with to our query. */
258 $this->addFields( array(
259 'rc_timestamp',
260 'rc_namespace',
261 'rc_title',
262 'rc_cur_id',
263 'rc_type',
264 'rc_deleted'
265 ) );
266
267 $showRedirects = false;
268 /* Determine what properties we need to display. */
269 if ( !is_null( $params['prop'] ) ) {
270 $prop = array_flip( $params['prop'] );
271
272 /* Set up internal members based upon params. */
273 $this->initProperties( $prop );
274
275 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
276 $this->dieUsage(
277 'You need the patrol right to request the patrolled flag',
278 'permissiondenied'
279 );
280 }
281
282 $this->addFields( 'rc_id' );
283 /* Add fields to our query if they are specified as a needed parameter. */
284 $this->addFieldsIf( array( 'rc_this_oldid', 'rc_last_oldid' ), $this->fld_ids );
285 $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
286 $this->addFieldsIf( 'rc_user', $this->fld_user );
287 $this->addFieldsIf( 'rc_user_text', $this->fld_user || $this->fld_userid );
288 $this->addFieldsIf( array( 'rc_minor', 'rc_type', 'rc_bot' ), $this->fld_flags );
289 $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes );
290 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
291 $this->addFieldsIf(
292 array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ),
293 $this->fld_loginfo
294 );
295 $showRedirects = $this->fld_redirect || isset( $show['redirect'] )
296 || isset( $show['!redirect'] );
297 }
298
299 if ( $this->fld_tags ) {
300 $this->addTables( 'tag_summary' );
301 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rc_id=ts_rc_id' ) ) ) );
302 $this->addFields( 'ts_tags' );
303 }
304
305 if ( $this->fld_sha1 ) {
306 $this->addTables( 'revision' );
307 $this->addJoinConds( array( 'revision' => array( 'LEFT JOIN',
308 array( 'rc_this_oldid=rev_id' ) ) ) );
309 $this->addFields( array( 'rev_sha1', 'rev_deleted' ) );
310 }
311
312 if ( $params['toponly'] || $showRedirects ) {
313 $this->addTables( 'page' );
314 $this->addJoinConds( array( 'page' => array( 'LEFT JOIN',
315 array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) );
316 $this->addFields( 'page_is_redirect' );
317
318 if ( $params['toponly'] ) {
319 $this->addWhere( 'rc_this_oldid = page_latest' );
320 }
321 }
322
323 if ( !is_null( $params['tag'] ) ) {
324 $this->addTables( 'change_tag' );
325 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) );
326 $this->addWhereFld( 'ct_tag', $params['tag'] );
327 }
328
329 $this->token = $params['token'];
330 $this->addOption( 'LIMIT', $params['limit'] + 1 );
331 $this->addOption( 'USE INDEX', $index );
332
333 $count = 0;
334 /* Perform the actual query. */
335 $res = $this->select( __METHOD__ );
336
337 $titles = array();
338
339 $result = $this->getResult();
340
341 /* Iterate through the rows, adding data extracted from them to our query result. */
342 foreach ( $res as $row ) {
343 if ( ++$count > $params['limit'] ) {
344 // We've reached the one extra which shows that there are
345 // additional pages to be had. Stop here...
346 $this->setContinueEnumParameter(
347 'continue',
348 wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id
349 );
350 break;
351 }
352
353 if ( is_null( $resultPageSet ) ) {
354 /* Extract the data from a single row. */
355 $vals = $this->extractRowInfo( $row );
356
357 /* Add that row's data to our final output. */
358 if ( !$vals ) {
359 continue;
360 }
361 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
362 if ( !$fit ) {
363 $this->setContinueEnumParameter(
364 'continue',
365 wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id
366 );
367 break;
368 }
369 } else {
370 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
371 }
372 }
373
374 if ( is_null( $resultPageSet ) ) {
375 /* Format the result */
376 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
377 } else {
378 $resultPageSet->populateFromTitles( $titles );
379 }
380 }
381
382 /**
383 * Extracts from a single sql row the data needed to describe one recent change.
384 *
385 * @param mixed $row The row from which to extract the data.
386 * @return array An array mapping strings (descriptors) to their respective string values.
387 * @access public
388 */
389 public function extractRowInfo( $row ) {
390 /* Determine the title of the page that has been changed. */
391 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
392
393 /* Our output data. */
394 $vals = array();
395
396 $type = intval( $row->rc_type );
397
398 /* Determine what kind of change this was. */
399 switch ( $type ) {
400 case RC_EDIT:
401 $vals['type'] = 'edit';
402 break;
403 case RC_NEW:
404 $vals['type'] = 'new';
405 break;
406 case RC_MOVE:
407 $vals['type'] = 'move';
408 break;
409 case RC_LOG:
410 $vals['type'] = 'log';
411 break;
412 case RC_EXTERNAL:
413 $vals['type'] = 'external';
414 break;
415 case RC_MOVE_OVER_REDIRECT:
416 $vals['type'] = 'move over redirect';
417 break;
418 default:
419 $vals['type'] = $type;
420 }
421
422 /* Create a new entry in the result for the title. */
423 if ( $this->fld_title ) {
424 ApiQueryBase::addTitleInfo( $vals, $title );
425 }
426
427 /* Add ids, such as rcid, pageid, revid, and oldid to the change's info. */
428 if ( $this->fld_ids ) {
429 $vals['rcid'] = intval( $row->rc_id );
430 $vals['pageid'] = intval( $row->rc_cur_id );
431 $vals['revid'] = intval( $row->rc_this_oldid );
432 $vals['old_revid'] = intval( $row->rc_last_oldid );
433 }
434
435 /* Add user data and 'anon' flag, if use is anonymous. */
436 if ( $this->fld_user || $this->fld_userid ) {
437
438 if ( $this->fld_user ) {
439 $vals['user'] = $row->rc_user_text;
440 }
441
442 if ( $this->fld_userid ) {
443 $vals['userid'] = $row->rc_user;
444 }
445
446 if ( !$row->rc_user ) {
447 $vals['anon'] = '';
448 }
449 }
450
451 /* Add flags, such as new, minor, bot. */
452 if ( $this->fld_flags ) {
453 if ( $row->rc_bot ) {
454 $vals['bot'] = '';
455 }
456 if ( $row->rc_type == RC_NEW ) {
457 $vals['new'] = '';
458 }
459 if ( $row->rc_minor ) {
460 $vals['minor'] = '';
461 }
462 }
463
464 /* Add sizes of each revision. (Only available on 1.10+) */
465 if ( $this->fld_sizes ) {
466 $vals['oldlen'] = intval( $row->rc_old_len );
467 $vals['newlen'] = intval( $row->rc_new_len );
468 }
469
470 /* Add the timestamp. */
471 if ( $this->fld_timestamp ) {
472 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
473 }
474
475 /* Add edit summary / log summary. */
476 if ( $this->fld_comment && isset( $row->rc_comment ) ) {
477 $vals['comment'] = $row->rc_comment;
478 }
479
480 if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
481 $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title );
482 }
483
484 if ( $this->fld_redirect ) {
485 if ( $row->page_is_redirect ) {
486 $vals['redirect'] = '';
487 }
488 }
489
490 /* Add the patrolled flag */
491 if ( $this->fld_patrolled && $row->rc_patrolled == 1 ) {
492 $vals['patrolled'] = '';
493 }
494
495 if ( $this->fld_patrolled && ChangesList::isUnpatrolled( $row, $this->getUser() ) ) {
496 $vals['unpatrolled'] = '';
497 }
498
499 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
500 $vals['logid'] = intval( $row->rc_logid );
501 $vals['logtype'] = $row->rc_log_type;
502 $vals['logaction'] = $row->rc_log_action;
503 $logEntry = DatabaseLogEntry::newFromRow( (array)$row );
504 ApiQueryLogEvents::addLogParams(
505 $this->getResult(),
506 $vals,
507 $logEntry->getParameters(),
508 $logEntry->getType(),
509 $logEntry->getSubtype(),
510 $logEntry->getTimestamp()
511 );
512 }
513
514 if ( $this->fld_tags ) {
515 if ( $row->ts_tags ) {
516 $tags = explode( ',', $row->ts_tags );
517 $this->getResult()->setIndexedTagName( $tags, 'tag' );
518 $vals['tags'] = $tags;
519 } else {
520 $vals['tags'] = array();
521 }
522 }
523
524 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
525 // The RevDel check should currently never pass due to the
526 // rc_deleted = 0 condition in the WHERE clause, but in case that
527 // ever changes we check it here too.
528 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
529 $vals['sha1hidden'] = '';
530 } elseif ( $row->rev_sha1 !== '' ) {
531 $vals['sha1'] = wfBaseConvert( $row->rev_sha1, 36, 16, 40 );
532 } else {
533 $vals['sha1'] = '';
534 }
535 }
536
537 if ( !is_null( $this->token ) ) {
538 $tokenFunctions = $this->getTokenFunctions();
539 foreach ( $this->token as $t ) {
540 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
541 $title, RecentChange::newFromRow( $row ) );
542 if ( $val === false ) {
543 $this->setWarning( "Action '$t' is not allowed for the current user" );
544 } else {
545 $vals[$t . 'token'] = $val;
546 }
547 }
548 }
549
550 return $vals;
551 }
552
553 private function parseRCType( $type ) {
554 if ( is_array( $type ) ) {
555 $retval = array();
556 foreach ( $type as $t ) {
557 $retval[] = $this->parseRCType( $t );
558 }
559
560 return $retval;
561 }
562
563 switch ( $type ) {
564 case 'edit':
565 return RC_EDIT;
566 case 'new':
567 return RC_NEW;
568 case 'log':
569 return RC_LOG;
570 case 'external':
571 return RC_EXTERNAL;
572 default:
573 ApiBase::dieDebug( __METHOD__, "Unknown type '$type'" );
574 }
575 }
576
577 public function getCacheMode( $params ) {
578 if ( isset( $params['show'] ) ) {
579 foreach ( $params['show'] as $show ) {
580 if ( $show === 'patrolled' || $show === '!patrolled' ) {
581 return 'private';
582 }
583 }
584 }
585 if ( isset( $params['token'] ) ) {
586 return 'private';
587 }
588 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
589 // formatComment() calls wfMessage() among other things
590 return 'anon-public-user-private';
591 }
592
593 return 'public';
594 }
595
596 public function getAllowedParams() {
597 return array(
598 'start' => array(
599 ApiBase::PARAM_TYPE => 'timestamp'
600 ),
601 'end' => array(
602 ApiBase::PARAM_TYPE => 'timestamp'
603 ),
604 'dir' => array(
605 ApiBase::PARAM_DFLT => 'older',
606 ApiBase::PARAM_TYPE => array(
607 'newer',
608 'older'
609 )
610 ),
611 'namespace' => array(
612 ApiBase::PARAM_ISMULTI => true,
613 ApiBase::PARAM_TYPE => 'namespace'
614 ),
615 'user' => array(
616 ApiBase::PARAM_TYPE => 'user'
617 ),
618 'excludeuser' => array(
619 ApiBase::PARAM_TYPE => 'user'
620 ),
621 'tag' => null,
622 'prop' => array(
623 ApiBase::PARAM_ISMULTI => true,
624 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
625 ApiBase::PARAM_TYPE => array(
626 'user',
627 'userid',
628 'comment',
629 'parsedcomment',
630 'flags',
631 'timestamp',
632 'title',
633 'ids',
634 'sizes',
635 'redirect',
636 'patrolled',
637 'loginfo',
638 'tags',
639 'sha1',
640 )
641 ),
642 'token' => array(
643 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
644 ApiBase::PARAM_ISMULTI => true
645 ),
646 'show' => array(
647 ApiBase::PARAM_ISMULTI => true,
648 ApiBase::PARAM_TYPE => array(
649 'minor',
650 '!minor',
651 'bot',
652 '!bot',
653 'anon',
654 '!anon',
655 'redirect',
656 '!redirect',
657 'patrolled',
658 '!patrolled',
659 'unpatrolled'
660 )
661 ),
662 'limit' => array(
663 ApiBase::PARAM_DFLT => 10,
664 ApiBase::PARAM_TYPE => 'limit',
665 ApiBase::PARAM_MIN => 1,
666 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
667 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
668 ),
669 'type' => array(
670 ApiBase::PARAM_ISMULTI => true,
671 ApiBase::PARAM_TYPE => array(
672 'edit',
673 'external',
674 'new',
675 'log'
676 )
677 ),
678 'toponly' => false,
679 'continue' => null,
680 );
681 }
682
683 public function getParamDescription() {
684 $p = $this->getModulePrefix();
685
686 return array(
687 'start' => 'The timestamp to start enumerating from',
688 'end' => 'The timestamp to end enumerating',
689 'dir' => $this->getDirectionDescription( $p ),
690 'namespace' => 'Filter log entries to only this namespace(s)',
691 'user' => 'Only list changes by this user',
692 'excludeuser' => 'Don\'t list changes by this user',
693 'prop' => array(
694 'Include additional pieces of information',
695 ' user - Adds the user responsible for the edit and tags if they are an IP',
696 ' userid - Adds the user id responsible for the edit',
697 ' comment - Adds the comment for the edit',
698 ' parsedcomment - Adds the parsed comment for the edit',
699 ' flags - Adds flags for the edit',
700 ' timestamp - Adds timestamp of the edit',
701 ' title - Adds the page title of the edit',
702 ' ids - Adds the page ID, recent changes ID and the new and old revision ID',
703 ' sizes - Adds the new and old page length in bytes',
704 ' redirect - Tags edit if page is a redirect',
705 ' patrolled - Tags patrollable edits as being patrolled or unpatrolled',
706 ' loginfo - Adds log information (logid, logtype, etc) to log entries',
707 ' tags - Lists tags for the entry',
708 ' sha1 - Adds the content checksum for entries associated with a revision',
709 ),
710 'token' => 'Which tokens to obtain for each change',
711 'show' => array(
712 'Show only items that meet this criteria.',
713 "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
714 ),
715 'type' => 'Which types of changes to show',
716 'limit' => 'How many total changes to return',
717 'tag' => 'Only list changes tagged with this tag',
718 'toponly' => 'Only list changes which are the latest revision',
719 'continue' => 'When more results are available, use this to continue',
720 );
721 }
722
723 public function getResultProperties() {
724 global $wgLogTypes;
725 $props = array(
726 '' => array(
727 'type' => array(
728 ApiBase::PROP_TYPE => array(
729 'edit',
730 'new',
731 'move',
732 'log',
733 'move over redirect'
734 )
735 )
736 ),
737 'title' => array(
738 'ns' => 'namespace',
739 'title' => 'string',
740 'new_ns' => array(
741 ApiBase::PROP_TYPE => 'namespace',
742 ApiBase::PROP_NULLABLE => true
743 ),
744 'new_title' => array(
745 ApiBase::PROP_TYPE => 'string',
746 ApiBase::PROP_NULLABLE => true
747 )
748 ),
749 'ids' => array(
750 'rcid' => 'integer',
751 'pageid' => 'integer',
752 'revid' => 'integer',
753 'old_revid' => 'integer'
754 ),
755 'user' => array(
756 'user' => 'string',
757 'anon' => 'boolean'
758 ),
759 'userid' => array(
760 'userid' => 'integer',
761 'anon' => 'boolean'
762 ),
763 'flags' => array(
764 'bot' => 'boolean',
765 'new' => 'boolean',
766 'minor' => 'boolean'
767 ),
768 'sizes' => array(
769 'oldlen' => 'integer',
770 'newlen' => 'integer'
771 ),
772 'timestamp' => array(
773 'timestamp' => 'timestamp'
774 ),
775 'comment' => array(
776 'comment' => array(
777 ApiBase::PROP_TYPE => 'string',
778 ApiBase::PROP_NULLABLE => true
779 )
780 ),
781 'parsedcomment' => array(
782 'parsedcomment' => array(
783 ApiBase::PROP_TYPE => 'string',
784 ApiBase::PROP_NULLABLE => true
785 )
786 ),
787 'redirect' => array(
788 'redirect' => 'boolean'
789 ),
790 'patrolled' => array(
791 'patrolled' => 'boolean',
792 'unpatrolled' => 'boolean'
793 ),
794 'loginfo' => array(
795 'logid' => array(
796 ApiBase::PROP_TYPE => 'integer',
797 ApiBase::PROP_NULLABLE => true
798 ),
799 'logtype' => array(
800 ApiBase::PROP_TYPE => $wgLogTypes,
801 ApiBase::PROP_NULLABLE => true
802 ),
803 'logaction' => array(
804 ApiBase::PROP_TYPE => 'string',
805 ApiBase::PROP_NULLABLE => true
806 )
807 ),
808 'sha1' => array(
809 'sha1' => array(
810 ApiBase::PROP_TYPE => 'string',
811 ApiBase::PROP_NULLABLE => true
812 ),
813 'sha1hidden' => array(
814 ApiBase::PROP_TYPE => 'boolean',
815 ApiBase::PROP_NULLABLE => true
816 ),
817 ),
818 );
819
820 self::addTokenProperties( $props, $this->getTokenFunctions() );
821
822 return $props;
823 }
824
825 public function getDescription() {
826 return 'Enumerate recent changes';
827 }
828
829 public function getPossibleErrors() {
830 return array_merge( parent::getPossibleErrors(), array(
831 array( 'show' ),
832 array(
833 'code' => 'permissiondenied',
834 'info' => 'You need the patrol right to request the patrolled flag'
835 ),
836 array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ),
837 ) );
838 }
839
840 public function getExamples() {
841 return array(
842 'api.php?action=query&list=recentchanges'
843 );
844 }
845
846 public function getHelpUrls() {
847 return 'https://www.mediawiki.org/wiki/API:Recentchanges';
848 }
849 }