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