API: Add prop=sha1 to list=recentchanges
[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 return $this->tokenFunctions;
68 }
69
70 /**
71 * @param $pageid
72 * @param $title
73 * @param $rc RecentChange (optional)
74 * @return bool|String
75 */
76 public static function getPatrolToken( $pageid, $title, $rc = null ) {
77 global $wgUser;
78
79 $validTokenUser = false;
80
81 if ( $rc ) {
82 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
83 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) )
84 {
85 $validTokenUser = true;
86 }
87 } else {
88 if ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
89 $validTokenUser = true;
90 }
91 }
92
93 if ( $validTokenUser ) {
94 // The patrol token is always the same, let's exploit that
95 static $cachedPatrolToken = null;
96 if ( is_null( $cachedPatrolToken ) ) {
97 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
98 }
99 return $cachedPatrolToken;
100 } else {
101 return false;
102 }
103
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 ) {
195 $this->dieUsageMsg( 'show' );
196 }
197
198 // Check permissions
199 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
200 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
201 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
202 }
203 }
204
205 /* Add additional conditions to query depending upon parameters. */
206 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
207 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
208 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
209 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
210 $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) );
211 $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
212 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
213 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
214 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
215
216 // Don't throw log entries out the window here
217 $this->addWhereIf( 'page_is_redirect = 0 OR page_is_redirect IS NULL', isset( $show['!redirect'] ) );
218 }
219
220 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
221 $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
222 }
223
224 if ( !is_null( $params['user'] ) ) {
225 $this->addWhereFld( 'rc_user_text', $params['user'] );
226 $index['recentchanges'] = 'rc_user_text';
227 }
228
229 if ( !is_null( $params['excludeuser'] ) ) {
230 // We don't use the rc_user_text index here because
231 // * it would require us to sort by rc_user_text before rc_timestamp
232 // * the != condition doesn't throw out too many rows anyway
233 $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
234 }
235
236 /* Add the fields we're concerned with to our query. */
237 $this->addFields( array(
238 'rc_timestamp',
239 'rc_namespace',
240 'rc_title',
241 'rc_cur_id',
242 'rc_type',
243 'rc_deleted'
244 ) );
245
246 $showRedirects = false;
247 /* Determine what properties we need to display. */
248 if ( !is_null( $params['prop'] ) ) {
249 $prop = array_flip( $params['prop'] );
250
251 /* Set up internal members based upon params. */
252 $this->initProperties( $prop );
253
254 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
255 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
256 }
257
258 $this->addFields( 'rc_id' );
259 /* Add fields to our query if they are specified as a needed parameter. */
260 $this->addFieldsIf( array( 'rc_this_oldid', 'rc_last_oldid' ), $this->fld_ids );
261 $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
262 $this->addFieldsIf( 'rc_user', $this->fld_user );
263 $this->addFieldsIf( 'rc_user_text', $this->fld_user || $this->fld_userid );
264 $this->addFieldsIf( array( 'rc_minor', 'rc_type', 'rc_bot' ), $this->fld_flags );
265 $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes );
266 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
267 $this->addFieldsIf( array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ), $this->fld_loginfo );
268 $showRedirects = $this->fld_redirect || isset( $show['redirect'] ) || isset( $show['!redirect'] );
269 }
270
271 if ( $this->fld_tags ) {
272 $this->addTables( 'tag_summary' );
273 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rc_id=ts_rc_id' ) ) ) );
274 $this->addFields( 'ts_tags' );
275 }
276
277 if ( $this->fld_sha1 ) {
278 $this->addTables( 'revision' );
279 $this->addJoinConds( array( 'revision' => array( 'LEFT JOIN', array( 'rc_this_oldid=rev_id' ) ) ) );
280 $this->addFields( array( 'rev_sha1', 'rev_deleted' ) );
281 }
282
283 if ( $params['toponly'] || $showRedirects ) {
284 $this->addTables( 'page' );
285 $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) );
286 $this->addFields( 'page_is_redirect' );
287
288 if ( $params['toponly'] ) {
289 $this->addWhere( 'rc_this_oldid = page_latest' );
290 }
291 }
292
293 if ( !is_null( $params['tag'] ) ) {
294 $this->addTables( 'change_tag' );
295 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) );
296 $this->addWhereFld( 'ct_tag', $params['tag'] );
297 global $wgOldChangeTagsIndex;
298 $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
299 }
300
301 $this->token = $params['token'];
302 $this->addOption( 'LIMIT', $params['limit'] + 1 );
303 $this->addOption( 'USE INDEX', $index );
304
305 $count = 0;
306 /* Perform the actual query. */
307 $res = $this->select( __METHOD__ );
308
309 $titles = array();
310
311 $result = $this->getResult();
312
313 /* Iterate through the rows, adding data extracted from them to our query result. */
314 foreach ( $res as $row ) {
315 if ( ++ $count > $params['limit'] ) {
316 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
317 $this->setContinueEnumParameter( 'continue', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id );
318 break;
319 }
320
321 if ( is_null( $resultPageSet ) ) {
322 /* Extract the data from a single row. */
323 $vals = $this->extractRowInfo( $row );
324
325 /* Add that row's data to our final output. */
326 if ( !$vals ) {
327 continue;
328 }
329 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
330 if ( !$fit ) {
331 $this->setContinueEnumParameter( 'continue', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id );
332 break;
333 }
334 } else {
335 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
336 }
337 }
338
339 if ( is_null( $resultPageSet ) ) {
340 /* Format the result */
341 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
342 } else {
343 $resultPageSet->populateFromTitles( $titles );
344 }
345 }
346
347 /**
348 * Extracts from a single sql row the data needed to describe one recent change.
349 *
350 * @param mixed $row The row from which to extract the data.
351 * @return array An array mapping strings (descriptors) to their respective string values.
352 * @access public
353 */
354 public function extractRowInfo( $row ) {
355 /* Determine the title of the page that has been changed. */
356 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
357
358 /* Our output data. */
359 $vals = array();
360
361 $type = intval( $row->rc_type );
362
363 /* Determine what kind of change this was. */
364 switch ( $type ) {
365 case RC_EDIT:
366 $vals['type'] = 'edit';
367 break;
368 case RC_NEW:
369 $vals['type'] = 'new';
370 break;
371 case RC_MOVE:
372 $vals['type'] = 'move';
373 break;
374 case RC_LOG:
375 $vals['type'] = 'log';
376 break;
377 case RC_EXTERNAL:
378 $vals['type'] = 'external';
379 break;
380 case RC_MOVE_OVER_REDIRECT:
381 $vals['type'] = 'move over redirect';
382 break;
383 default:
384 $vals['type'] = $type;
385 }
386
387 /* Create a new entry in the result for the title. */
388 if ( $this->fld_title ) {
389 ApiQueryBase::addTitleInfo( $vals, $title );
390 }
391
392 /* Add ids, such as rcid, pageid, revid, and oldid to the change's info. */
393 if ( $this->fld_ids ) {
394 $vals['rcid'] = intval( $row->rc_id );
395 $vals['pageid'] = intval( $row->rc_cur_id );
396 $vals['revid'] = intval( $row->rc_this_oldid );
397 $vals['old_revid'] = intval( $row->rc_last_oldid );
398 }
399
400 /* Add user data and 'anon' flag, if use is anonymous. */
401 if ( $this->fld_user || $this->fld_userid ) {
402
403 if ( $this->fld_user ) {
404 $vals['user'] = $row->rc_user_text;
405 }
406
407 if ( $this->fld_userid ) {
408 $vals['userid'] = $row->rc_user;
409 }
410
411 if ( !$row->rc_user ) {
412 $vals['anon'] = '';
413 }
414 }
415
416 /* Add flags, such as new, minor, bot. */
417 if ( $this->fld_flags ) {
418 if ( $row->rc_bot ) {
419 $vals['bot'] = '';
420 }
421 if ( $row->rc_type == RC_NEW ) {
422 $vals['new'] = '';
423 }
424 if ( $row->rc_minor ) {
425 $vals['minor'] = '';
426 }
427 }
428
429 /* Add sizes of each revision. (Only available on 1.10+) */
430 if ( $this->fld_sizes ) {
431 $vals['oldlen'] = intval( $row->rc_old_len );
432 $vals['newlen'] = intval( $row->rc_new_len );
433 }
434
435 /* Add the timestamp. */
436 if ( $this->fld_timestamp ) {
437 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
438 }
439
440 /* Add edit summary / log summary. */
441 if ( $this->fld_comment && isset( $row->rc_comment ) ) {
442 $vals['comment'] = $row->rc_comment;
443 }
444
445 if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
446 $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title );
447 }
448
449 if ( $this->fld_redirect ) {
450 if ( $row->page_is_redirect ) {
451 $vals['redirect'] = '';
452 }
453 }
454
455 /* Add the patrolled flag */
456 if ( $this->fld_patrolled && $row->rc_patrolled == 1 ) {
457 $vals['patrolled'] = '';
458 }
459
460 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
461 $vals['logid'] = intval( $row->rc_logid );
462 $vals['logtype'] = $row->rc_log_type;
463 $vals['logaction'] = $row->rc_log_action;
464 $logEntry = DatabaseLogEntry::newFromRow( (array)$row );
465 ApiQueryLogEvents::addLogParams(
466 $this->getResult(),
467 $vals,
468 $logEntry->getParameters(),
469 $logEntry->getType(),
470 $logEntry->getSubtype(),
471 $logEntry->getTimestamp()
472 );
473 }
474
475 if ( $this->fld_tags ) {
476 if ( $row->ts_tags ) {
477 $tags = explode( ',', $row->ts_tags );
478 $this->getResult()->setIndexedTagName( $tags, 'tag' );
479 $vals['tags'] = $tags;
480 } else {
481 $vals['tags'] = array();
482 }
483 }
484
485 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
486 // The RevDel check should currently never pass due to the
487 // rc_deleted = 0 condition in the WHERE clause, but in case that
488 // ever changes we check it here too.
489 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
490 $vals['sha1hidden'] = '';
491 } elseif ( $row->rev_sha1 !== '' ) {
492 $vals['sha1'] = wfBaseConvert( $row->rev_sha1, 36, 16, 40 );
493 } else {
494 $vals['sha1'] = '';
495 }
496 }
497
498 if ( !is_null( $this->token ) ) {
499 $tokenFunctions = $this->getTokenFunctions();
500 foreach ( $this->token as $t ) {
501 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
502 $title, RecentChange::newFromRow( $row ) );
503 if ( $val === false ) {
504 $this->setWarning( "Action '$t' is not allowed for the current user" );
505 } else {
506 $vals[$t . 'token'] = $val;
507 }
508 }
509 }
510
511 return $vals;
512 }
513
514 private function parseRCType( $type ) {
515 if ( is_array( $type ) ) {
516 $retval = array();
517 foreach ( $type as $t ) {
518 $retval[] = $this->parseRCType( $t );
519 }
520 return $retval;
521 }
522 switch ( $type ) {
523 case 'edit':
524 return RC_EDIT;
525 case 'new':
526 return RC_NEW;
527 case 'log':
528 return RC_LOG;
529 case 'external':
530 return RC_EXTERNAL;
531 }
532 }
533
534 public function getCacheMode( $params ) {
535 if ( isset( $params['show'] ) ) {
536 foreach ( $params['show'] as $show ) {
537 if ( $show === 'patrolled' || $show === '!patrolled' ) {
538 return 'private';
539 }
540 }
541 }
542 if ( isset( $params['token'] ) ) {
543 return 'private';
544 }
545 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
546 // formatComment() calls wfMessage() among other things
547 return 'anon-public-user-private';
548 }
549 return 'public';
550 }
551
552 public function getAllowedParams() {
553 return array(
554 'start' => array(
555 ApiBase::PARAM_TYPE => 'timestamp'
556 ),
557 'end' => array(
558 ApiBase::PARAM_TYPE => 'timestamp'
559 ),
560 'dir' => array(
561 ApiBase::PARAM_DFLT => 'older',
562 ApiBase::PARAM_TYPE => array(
563 'newer',
564 'older'
565 )
566 ),
567 'namespace' => array(
568 ApiBase::PARAM_ISMULTI => true,
569 ApiBase::PARAM_TYPE => 'namespace'
570 ),
571 'user' => array(
572 ApiBase::PARAM_TYPE => 'user'
573 ),
574 'excludeuser' => array(
575 ApiBase::PARAM_TYPE => 'user'
576 ),
577 'tag' => null,
578 'prop' => array(
579 ApiBase::PARAM_ISMULTI => true,
580 ApiBase::PARAM_DFLT => 'title|timestamp|ids',
581 ApiBase::PARAM_TYPE => array(
582 'user',
583 'userid',
584 'comment',
585 'parsedcomment',
586 'flags',
587 'timestamp',
588 'title',
589 'ids',
590 'sizes',
591 'redirect',
592 'patrolled',
593 'loginfo',
594 'tags',
595 'sha1',
596 )
597 ),
598 'token' => array(
599 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
600 ApiBase::PARAM_ISMULTI => true
601 ),
602 'show' => array(
603 ApiBase::PARAM_ISMULTI => true,
604 ApiBase::PARAM_TYPE => array(
605 'minor',
606 '!minor',
607 'bot',
608 '!bot',
609 'anon',
610 '!anon',
611 'redirect',
612 '!redirect',
613 'patrolled',
614 '!patrolled'
615 )
616 ),
617 'limit' => array(
618 ApiBase::PARAM_DFLT => 10,
619 ApiBase::PARAM_TYPE => 'limit',
620 ApiBase::PARAM_MIN => 1,
621 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
622 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
623 ),
624 'type' => array(
625 ApiBase::PARAM_ISMULTI => true,
626 ApiBase::PARAM_TYPE => array(
627 'edit',
628 'external',
629 'new',
630 'log'
631 )
632 ),
633 'toponly' => false,
634 'continue' => null,
635 );
636 }
637
638 public function getParamDescription() {
639 $p = $this->getModulePrefix();
640 return array(
641 'start' => 'The timestamp to start enumerating from',
642 'end' => 'The timestamp to end enumerating',
643 'dir' => $this->getDirectionDescription( $p ),
644 'namespace' => 'Filter log entries to only this namespace(s)',
645 'user' => 'Only list changes by this user',
646 'excludeuser' => 'Don\'t list changes by this user',
647 'prop' => array(
648 'Include additional pieces of information',
649 ' user - Adds the user responsible for the edit and tags if they are an IP',
650 ' userid - Adds the user id responsible for the edit',
651 ' comment - Adds the comment for the edit',
652 ' parsedcomment - Adds the parsed comment for the edit',
653 ' flags - Adds flags for the edit',
654 ' timestamp - Adds timestamp of the edit',
655 ' title - Adds the page title of the edit',
656 ' ids - Adds the page ID, recent changes ID and the new and old revision ID',
657 ' sizes - Adds the new and old page length in bytes',
658 ' redirect - Tags edit if page is a redirect',
659 ' patrolled - Tags edits that have been patrolled',
660 ' loginfo - Adds log information (logid, logtype, etc) to log entries',
661 ' tags - Lists tags for the entry',
662 ' sha1 - Adds the content checksum for entries associated with a revision',
663 ),
664 'token' => 'Which tokens to obtain for each change',
665 'show' => array(
666 'Show only items that meet this criteria.',
667 "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
668 ),
669 'type' => 'Which types of changes to show',
670 'limit' => 'How many total changes to return',
671 'tag' => 'Only list changes tagged with this tag',
672 'toponly' => 'Only list changes which are the latest revision',
673 'continue' => 'When more results are available, use this to continue',
674 );
675 }
676
677 public function getResultProperties() {
678 global $wgLogTypes;
679 $props = array(
680 '' => array(
681 'type' => array(
682 ApiBase::PROP_TYPE => array(
683 'edit',
684 'new',
685 'move',
686 'log',
687 'move over redirect'
688 )
689 )
690 ),
691 'title' => array(
692 'ns' => 'namespace',
693 'title' => 'string',
694 'new_ns' => array(
695 ApiBase::PROP_TYPE => 'namespace',
696 ApiBase::PROP_NULLABLE => true
697 ),
698 'new_title' => array(
699 ApiBase::PROP_TYPE => 'string',
700 ApiBase::PROP_NULLABLE => true
701 )
702 ),
703 'ids' => array(
704 'rcid' => 'integer',
705 'pageid' => 'integer',
706 'revid' => 'integer',
707 'old_revid' => 'integer'
708 ),
709 'user' => array(
710 'user' => 'string',
711 'anon' => 'boolean'
712 ),
713 'userid' => array(
714 'userid' => 'integer',
715 'anon' => 'boolean'
716 ),
717 'flags' => array(
718 'bot' => 'boolean',
719 'new' => 'boolean',
720 'minor' => 'boolean'
721 ),
722 'sizes' => array(
723 'oldlen' => 'integer',
724 'newlen' => 'integer'
725 ),
726 'timestamp' => array(
727 'timestamp' => 'timestamp'
728 ),
729 'comment' => array(
730 'comment' => array(
731 ApiBase::PROP_TYPE => 'string',
732 ApiBase::PROP_NULLABLE => true
733 )
734 ),
735 'parsedcomment' => array(
736 'parsedcomment' => array(
737 ApiBase::PROP_TYPE => 'string',
738 ApiBase::PROP_NULLABLE => true
739 )
740 ),
741 'redirect' => array(
742 'redirect' => 'boolean'
743 ),
744 'patrolled' => array(
745 'patrolled' => 'boolean'
746 ),
747 'loginfo' => array(
748 'logid' => array(
749 ApiBase::PROP_TYPE => 'integer',
750 ApiBase::PROP_NULLABLE => true
751 ),
752 'logtype' => array(
753 ApiBase::PROP_TYPE => $wgLogTypes,
754 ApiBase::PROP_NULLABLE => true
755 ),
756 'logaction' => array(
757 ApiBase::PROP_TYPE => 'string',
758 ApiBase::PROP_NULLABLE => true
759 )
760 ),
761 'sha1' => array(
762 'sha1' => array(
763 ApiBase::PROP_TYPE => 'string',
764 ApiBase::PROP_NULLABLE => true
765 ),
766 'sha1hidden' => array(
767 ApiBase::PROP_TYPE => 'boolean',
768 ApiBase::PROP_NULLABLE => true
769 ),
770 ),
771 );
772
773 self::addTokenProperties( $props, $this->getTokenFunctions() );
774
775 return $props;
776 }
777
778 public function getDescription() {
779 return 'Enumerate recent changes';
780 }
781
782 public function getPossibleErrors() {
783 return array_merge( parent::getPossibleErrors(), array(
784 array( 'show' ),
785 array( 'code' => 'permissiondenied', 'info' => 'You need the patrol right to request the patrolled flag' ),
786 array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ),
787 ) );
788 }
789
790 public function getExamples() {
791 return array(
792 'api.php?action=query&list=recentchanges'
793 );
794 }
795
796 public function getHelpUrls() {
797 return 'https://www.mediawiki.org/wiki/API:Recentchanges';
798 }
799 }