Merge "Use ResourceLoader::makeComment to embed page title in wiki modules"
[lhc/web/wiklou.git] / includes / api / ApiQueryWatchlist.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 25, 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 * This query action allows clients to retrieve a list of recently modified pages
29 * that are part of the logged-in user's watchlist.
30 *
31 * @ingroup API
32 */
33 class ApiQueryWatchlist extends ApiQueryGeneratorBase {
34
35 public function __construct( $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'wl' );
37 }
38
39 public function execute() {
40 $this->run();
41 }
42
43 public function executeGenerator( $resultPageSet ) {
44 $this->run( $resultPageSet );
45 }
46
47 private $fld_ids = false, $fld_title = false, $fld_patrol = false,
48 $fld_flags = false, $fld_timestamp = false, $fld_user = false,
49 $fld_comment = false, $fld_parsedcomment = false, $fld_sizes = false,
50 $fld_notificationtimestamp = false, $fld_userid = false,
51 $fld_loginfo = false;
52
53 /**
54 * @param $resultPageSet ApiPageSet
55 * @return void
56 */
57 private function run( $resultPageSet = null ) {
58 $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
59
60 $params = $this->extractRequestParams();
61
62 $user = $this->getUser();
63 $wlowner = $this->getWatchlistUser( $params );
64
65 if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) {
66 $prop = array_flip( $params['prop'] );
67
68 $this->fld_ids = isset( $prop['ids'] );
69 $this->fld_title = isset( $prop['title'] );
70 $this->fld_flags = isset( $prop['flags'] );
71 $this->fld_user = isset( $prop['user'] );
72 $this->fld_userid = isset( $prop['userid'] );
73 $this->fld_comment = isset( $prop['comment'] );
74 $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
75 $this->fld_timestamp = isset( $prop['timestamp'] );
76 $this->fld_sizes = isset( $prop['sizes'] );
77 $this->fld_patrol = isset( $prop['patrol'] );
78 $this->fld_notificationtimestamp = isset( $prop['notificationtimestamp'] );
79 $this->fld_loginfo = isset( $prop['loginfo'] );
80
81 if ( $this->fld_patrol ) {
82 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
83 $this->dieUsage( 'patrol property is not available', 'patrol' );
84 }
85 }
86 }
87
88 $this->addFields( array(
89 'rc_id',
90 'rc_namespace',
91 'rc_title',
92 'rc_timestamp',
93 'rc_type',
94 'rc_deleted',
95 ) );
96
97 if ( is_null( $resultPageSet ) ) {
98 $this->addFields( array(
99 'rc_cur_id',
100 'rc_this_oldid',
101 'rc_last_oldid',
102 ) );
103
104 $this->addFieldsIf( array( 'rc_type', 'rc_minor', 'rc_bot' ), $this->fld_flags );
105 $this->addFieldsIf( 'rc_user', $this->fld_user || $this->fld_userid );
106 $this->addFieldsIf( 'rc_user_text', $this->fld_user );
107 $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
108 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrol );
109 $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes );
110 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp );
111 $this->addFieldsIf(
112 array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ),
113 $this->fld_loginfo
114 );
115 } elseif ( $params['allrev'] ) {
116 $this->addFields( 'rc_this_oldid' );
117 } else {
118 $this->addFields( 'rc_cur_id' );
119 }
120
121 $this->addTables( array(
122 'recentchanges',
123 'watchlist',
124 ) );
125
126 $userId = $wlowner->getId();
127 $this->addJoinConds( array( 'watchlist' => array( 'INNER JOIN',
128 array(
129 'wl_user' => $userId,
130 'wl_namespace=rc_namespace',
131 'wl_title=rc_title'
132 )
133 ) ) );
134
135 $db = $this->getDB();
136
137 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'],
138 $params['start'], $params['end'] );
139 // Include in ORDER BY for uniqueness
140 $this->addWhereRange( 'rc_id', $params['dir'], null, null );
141
142 if ( !is_null( $params['continue'] ) ) {
143 $cont = explode( '|', $params['continue'] );
144 $this->dieContinueUsageIf( count( $cont ) != 2 );
145 $op = ( $params['dir'] === 'newer' ? '>' : '<' );
146 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
147 $continueId = (int)$cont[1];
148 $this->dieContinueUsageIf( $continueId != $cont[1] );
149 $this->addWhere( "rc_timestamp $op $continueTimestamp OR " .
150 "(rc_timestamp = $continueTimestamp AND " .
151 "rc_id $op= $continueId)"
152 );
153 }
154
155 $this->addWhereFld( 'wl_namespace', $params['namespace'] );
156
157 if ( !$params['allrev'] ) {
158 $this->addTables( 'page' );
159 $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', 'rc_cur_id=page_id' ) ) );
160 $this->addWhere( 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG );
161 }
162
163 if ( !is_null( $params['show'] ) ) {
164 $show = array_flip( $params['show'] );
165
166 /* Check for conflicting parameters. */
167 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
168 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
169 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
170 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
171 ) {
172 $this->dieUsageMsg( 'show' );
173 }
174
175 // Check permissions.
176 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
177 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
178 $this->dieUsage(
179 'You need the patrol right to request the patrolled flag',
180 'permissiondenied'
181 );
182 }
183 }
184
185 /* Add additional conditions to query depending upon parameters. */
186 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
187 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
188 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
189 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
190 $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) );
191 $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
192 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
193 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
194 }
195
196 if ( !is_null( $params['type'] ) ) {
197 $this->addWhereFld( 'rc_type', $this->parseRCType( $params['type'] ) );
198 }
199
200 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
201 $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
202 }
203 if ( !is_null( $params['user'] ) ) {
204 $this->addWhereFld( 'rc_user_text', $params['user'] );
205 }
206 if ( !is_null( $params['excludeuser'] ) ) {
207 $this->addWhere( 'rc_user_text != ' . $db->addQuotes( $params['excludeuser'] ) );
208 }
209
210 // This is an index optimization for mysql, as done in the Special:Watchlist page
211 $this->addWhereIf(
212 "rc_timestamp > ''",
213 !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql'
214 );
215
216 // Paranoia: avoid brute force searches (bug 17342)
217 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
218 if ( !$user->isAllowed( 'deletedhistory' ) ) {
219 $bitmask = Revision::DELETED_USER;
220 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
221 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
222 } else {
223 $bitmask = 0;
224 }
225 if ( $bitmask ) {
226 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" );
227 }
228 }
229
230 // LogPage::DELETED_ACTION hides the affected page, too. So hide those
231 // entirely from the watchlist, or someone could guess the title.
232 if ( !$user->isAllowed( 'deletedhistory' ) ) {
233 $bitmask = LogPage::DELETED_ACTION;
234 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
235 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
236 } else {
237 $bitmask = 0;
238 }
239 if ( $bitmask ) {
240 $this->addWhere( $this->getDB()->makeList( array(
241 'rc_type != ' . RC_LOG,
242 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
243 ), LIST_OR ) );
244 }
245
246 $this->addOption( 'LIMIT', $params['limit'] + 1 );
247
248 $ids = array();
249 $count = 0;
250 $res = $this->select( __METHOD__ );
251
252 foreach ( $res as $row ) {
253 if ( ++$count > $params['limit'] ) {
254 // We've reached the one extra which shows that there are
255 // additional pages to be had. Stop here...
256 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
257 break;
258 }
259
260 if ( is_null( $resultPageSet ) ) {
261 $vals = $this->extractRowInfo( $row );
262 $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
263 if ( !$fit ) {
264 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
265 break;
266 }
267 } else {
268 if ( $params['allrev'] ) {
269 $ids[] = intval( $row->rc_this_oldid );
270 } else {
271 $ids[] = intval( $row->rc_cur_id );
272 }
273 }
274 }
275
276 if ( is_null( $resultPageSet ) ) {
277 $this->getResult()->setIndexedTagName_internal(
278 array( 'query', $this->getModuleName() ),
279 'item'
280 );
281 } elseif ( $params['allrev'] ) {
282 $resultPageSet->populateFromRevisionIDs( $ids );
283 } else {
284 $resultPageSet->populateFromPageIDs( $ids );
285 }
286 }
287
288 private function extractRowInfo( $row ) {
289 /* Determine the title of the page that has been changed. */
290 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
291 $user = $this->getUser();
292
293 /* Our output data. */
294 $vals = array();
295
296 $type = intval( $row->rc_type );
297
298 /* Determine what kind of change this was. */
299 switch ( $type ) {
300 case RC_EDIT:
301 $vals['type'] = 'edit';
302 break;
303 case RC_NEW:
304 $vals['type'] = 'new';
305 break;
306 case RC_MOVE:
307 $vals['type'] = 'move';
308 break;
309 case RC_LOG:
310 $vals['type'] = 'log';
311 break;
312 case RC_EXTERNAL:
313 $vals['type'] = 'external';
314 break;
315 case RC_MOVE_OVER_REDIRECT:
316 $vals['type'] = 'move over redirect';
317 break;
318 default:
319 $vals['type'] = $type;
320 }
321
322 $anyHidden = false;
323
324 /* Create a new entry in the result for the title. */
325 if ( $this->fld_title || $this->fld_ids ) {
326 // These should already have been filtered out of the query, but just in case.
327 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
328 $vals['actionhidden'] = '';
329 $anyHidden = true;
330 }
331 if ( $type !== RC_LOG ||
332 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
333 ) {
334 if ( $this->fld_title ) {
335 ApiQueryBase::addTitleInfo( $vals, $title );
336 }
337 if ( $this->fld_ids ) {
338 $vals['pageid'] = intval( $row->rc_cur_id );
339 $vals['revid'] = intval( $row->rc_this_oldid );
340 $vals['old_revid'] = intval( $row->rc_last_oldid );
341 }
342 }
343 }
344
345 /* Add user data and 'anon' flag, if user is anonymous. */
346 if ( $this->fld_user || $this->fld_userid ) {
347 if ( $row->rc_deleted & Revision::DELETED_USER ) {
348 $vals['userhidden'] = '';
349 $anyHidden = true;
350 }
351 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
352 if ( $this->fld_userid ) {
353 $vals['userid'] = $row->rc_user;
354 // for backwards compatibility
355 $vals['user'] = $row->rc_user;
356 }
357
358 if ( $this->fld_user ) {
359 $vals['user'] = $row->rc_user_text;
360 }
361
362 if ( !$row->rc_user ) {
363 $vals['anon'] = '';
364 }
365 }
366 }
367
368 /* Add flags, such as new, minor, bot. */
369 if ( $this->fld_flags ) {
370 if ( $row->rc_bot ) {
371 $vals['bot'] = '';
372 }
373 if ( $row->rc_type == RC_NEW ) {
374 $vals['new'] = '';
375 }
376 if ( $row->rc_minor ) {
377 $vals['minor'] = '';
378 }
379 }
380
381 /* Add sizes of each revision. (Only available on 1.10+) */
382 if ( $this->fld_sizes ) {
383 $vals['oldlen'] = intval( $row->rc_old_len );
384 $vals['newlen'] = intval( $row->rc_new_len );
385 }
386
387 /* Add the timestamp. */
388 if ( $this->fld_timestamp ) {
389 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
390 }
391
392 if ( $this->fld_notificationtimestamp ) {
393 $vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null )
394 ? ''
395 : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
396 }
397
398 /* Add edit summary / log summary. */
399 if ( $this->fld_comment || $this->fld_parsedcomment ) {
400 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
401 $vals['commenthidden'] = '';
402 $anyHidden = true;
403 }
404 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
405 if ( $this->fld_comment && isset( $row->rc_comment ) ) {
406 $vals['comment'] = $row->rc_comment;
407 }
408
409 if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
410 $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title );
411 }
412 }
413 }
414
415 /* Add the patrolled flag */
416 if ( $this->fld_patrol && $row->rc_patrolled == 1 ) {
417 $vals['patrolled'] = '';
418 }
419
420 if ( $this->fld_patrol && ChangesList::isUnpatrolled( $row, $user ) ) {
421 $vals['unpatrolled'] = '';
422 }
423
424 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
425 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
426 $vals['actionhidden'] = '';
427 $anyHidden = true;
428 }
429 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
430 $vals['logid'] = intval( $row->rc_logid );
431 $vals['logtype'] = $row->rc_log_type;
432 $vals['logaction'] = $row->rc_log_action;
433 $logEntry = DatabaseLogEntry::newFromRow( (array)$row );
434 ApiQueryLogEvents::addLogParams(
435 $this->getResult(),
436 $vals,
437 $logEntry->getParameters(),
438 $logEntry->getType(),
439 $logEntry->getSubtype(),
440 $logEntry->getTimestamp()
441 );
442 }
443 }
444
445 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
446 $vals['suppressed'] = '';
447 }
448
449 return $vals;
450 }
451
452 /** Copied from ApiQueryRecentChanges.
453 *
454 * @param string $type
455 * @return string
456 */
457 private function parseRCType( $type ) {
458 if ( is_array( $type ) ) {
459 $retval = array();
460 foreach ( $type as $t ) {
461 $retval[] = $this->parseRCType( $t );
462 }
463
464 return $retval;
465 }
466
467 switch ( $type ) {
468 case 'edit':
469 return RC_EDIT;
470 case 'new':
471 return RC_NEW;
472 case 'log':
473 return RC_LOG;
474 case 'external':
475 return RC_EXTERNAL;
476 default:
477 ApiBase::dieDebug( __METHOD__, "Unknown type '$type'" );
478 }
479 }
480
481 public function getAllowedParams() {
482 return array(
483 'allrev' => false,
484 'start' => array(
485 ApiBase::PARAM_TYPE => 'timestamp'
486 ),
487 'end' => array(
488 ApiBase::PARAM_TYPE => 'timestamp'
489 ),
490 'namespace' => array(
491 ApiBase::PARAM_ISMULTI => true,
492 ApiBase::PARAM_TYPE => 'namespace'
493 ),
494 'user' => array(
495 ApiBase::PARAM_TYPE => 'user',
496 ),
497 'excludeuser' => array(
498 ApiBase::PARAM_TYPE => 'user',
499 ),
500 'dir' => array(
501 ApiBase::PARAM_DFLT => 'older',
502 ApiBase::PARAM_TYPE => array(
503 'newer',
504 'older'
505 )
506 ),
507 'limit' => array(
508 ApiBase::PARAM_DFLT => 10,
509 ApiBase::PARAM_TYPE => 'limit',
510 ApiBase::PARAM_MIN => 1,
511 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
512 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
513 ),
514 'prop' => array(
515 ApiBase::PARAM_ISMULTI => true,
516 ApiBase::PARAM_DFLT => 'ids|title|flags',
517 ApiBase::PARAM_TYPE => array(
518 'ids',
519 'title',
520 'flags',
521 'user',
522 'userid',
523 'comment',
524 'parsedcomment',
525 'timestamp',
526 'patrol',
527 'sizes',
528 'notificationtimestamp',
529 'loginfo',
530 )
531 ),
532 'show' => array(
533 ApiBase::PARAM_ISMULTI => true,
534 ApiBase::PARAM_TYPE => array(
535 'minor',
536 '!minor',
537 'bot',
538 '!bot',
539 'anon',
540 '!anon',
541 'patrolled',
542 '!patrolled',
543 )
544 ),
545 'type' => array(
546 ApiBase::PARAM_ISMULTI => true,
547 ApiBase::PARAM_TYPE => array(
548 'edit',
549 'external',
550 'new',
551 'log',
552 )
553 ),
554 'owner' => array(
555 ApiBase::PARAM_TYPE => 'user'
556 ),
557 'token' => array(
558 ApiBase::PARAM_TYPE => 'string'
559 ),
560 'continue' => null,
561 );
562 }
563
564 public function getParamDescription() {
565 $p = $this->getModulePrefix();
566
567 return array(
568 'allrev' => 'Include multiple revisions of the same page within given timeframe',
569 'start' => 'The timestamp to start enumerating from',
570 'end' => 'The timestamp to end enumerating',
571 'namespace' => 'Filter changes to only the given namespace(s)',
572 'user' => 'Only list changes by this user',
573 'excludeuser' => 'Don\'t list changes by this user',
574 'dir' => $this->getDirectionDescription( $p ),
575 'limit' => 'How many total results to return per request',
576 'prop' => array(
577 'Which additional items to get (non-generator mode only).',
578 ' ids - Adds revision ids and page ids',
579 ' title - Adds title of the page',
580 ' flags - Adds flags for the edit',
581 ' user - Adds the user who made the edit',
582 ' userid - Adds user id of whom made the edit',
583 ' comment - Adds comment of the edit',
584 ' parsedcomment - Adds parsed comment of the edit',
585 ' timestamp - Adds timestamp of the edit',
586 ' patrol - Tags edits that are patrolled',
587 ' sizes - Adds the old and new lengths of the page',
588 ' notificationtimestamp - Adds timestamp of when the user was last notified about the edit',
589 ' loginfo - Adds log information where appropriate',
590 ),
591 'show' => array(
592 'Show only items that meet this criteria.',
593 "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
594 ),
595 'type' => array(
596 'Which types of changes to show',
597 ' edit - Regular page edits',
598 ' external - External changes',
599 ' new - Page creations',
600 ' log - Log entries',
601 ),
602 'owner' => 'The name of the user whose watchlist you\'d like to access',
603 'token' => 'Give a security token (settable in preferences) to ' .
604 'allow access to another user\'s watchlist',
605 'continue' => 'When more results are available, use this to continue',
606 );
607 }
608
609 public function getResultProperties() {
610 global $wgLogTypes;
611
612 return array(
613 '' => array(
614 'type' => array(
615 ApiBase::PROP_TYPE => array(
616 'edit',
617 'new',
618 'move',
619 'log',
620 'move over redirect'
621 )
622 )
623 ),
624 'ids' => array(
625 'pageid' => 'integer',
626 'revid' => 'integer',
627 'old_revid' => 'integer'
628 ),
629 'title' => array(
630 'ns' => 'namespace',
631 'title' => 'string'
632 ),
633 'user' => array(
634 'user' => 'string',
635 'anon' => 'boolean'
636 ),
637 'userid' => array(
638 'userid' => 'integer',
639 'anon' => 'boolean'
640 ),
641 'flags' => array(
642 'new' => 'boolean',
643 'minor' => 'boolean',
644 'bot' => 'boolean'
645 ),
646 'patrol' => array(
647 'patrolled' => 'boolean'
648 ),
649 'timestamp' => array(
650 'timestamp' => 'timestamp'
651 ),
652 'sizes' => array(
653 'oldlen' => 'integer',
654 'newlen' => 'integer'
655 ),
656 'notificationtimestamp' => array(
657 'notificationtimestamp' => array(
658 ApiBase::PROP_TYPE => 'timestamp',
659 ApiBase::PROP_NULLABLE => true
660 )
661 ),
662 'comment' => array(
663 'comment' => array(
664 ApiBase::PROP_TYPE => 'string',
665 ApiBase::PROP_NULLABLE => true
666 )
667 ),
668 'parsedcomment' => array(
669 'parsedcomment' => array(
670 ApiBase::PROP_TYPE => 'string',
671 ApiBase::PROP_NULLABLE => true
672 )
673 ),
674 'loginfo' => array(
675 'logid' => array(
676 ApiBase::PROP_TYPE => 'integer',
677 ApiBase::PROP_NULLABLE => true
678 ),
679 'logtype' => array(
680 ApiBase::PROP_TYPE => $wgLogTypes,
681 ApiBase::PROP_NULLABLE => true
682 ),
683 'logaction' => array(
684 ApiBase::PROP_TYPE => 'string',
685 ApiBase::PROP_NULLABLE => true
686 )
687 )
688 );
689 }
690
691 public function getDescription() {
692 return "Get all recent changes to pages in the logged in user's watchlist.";
693 }
694
695 public function getPossibleErrors() {
696 return array_merge( parent::getPossibleErrors(), array(
697 array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ),
698 array(
699 'code' => 'bad_wltoken',
700 'info' => 'Incorrect watchlist token provided -- ' .
701 'please set a correct token in Special:Preferences'
702 ),
703 array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
704 array( 'code' => 'patrol', 'info' => 'patrol property is not available' ),
705 array( 'show' ),
706 array(
707 'code' => 'permissiondenied',
708 'info' => 'You need the patrol right to request the patrolled flag'
709 ),
710 array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ),
711 ) );
712 }
713
714 public function getExamples() {
715 return array(
716 'api.php?action=query&list=watchlist',
717 'api.php?action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment',
718 'api.php?action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment',
719 'api.php?action=query&generator=watchlist&prop=info',
720 'api.php?action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user',
721 'api.php?action=query&list=watchlist&wlowner=Bob_Smith&wltoken=123ABC'
722 );
723 }
724
725 public function getHelpUrls() {
726 return 'https://www.mediawiki.org/wiki/API:Watchlist';
727 }
728 }