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