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