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