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