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