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