41 private $commentStore;
44 private $watchedItemQueryService;
47 private $contentLanguage;
50 private $namespaceInfo;
56 private $commentFormatter;
78 parent::__construct( $query, $moduleName,
'wl' );
79 $this->commentStore = $commentStore;
80 $this->watchedItemQueryService = $watchedItemQueryService;
81 $this->contentLanguage = $contentLanguage;
82 $this->namespaceInfo = $namespaceInfo;
83 $this->genderCache = $genderCache;
84 $this->commentFormatter = $commentFormatter;
92 $this->run( $resultPageSet );
95 private $fld_ids =
false, $fld_title =
false, $fld_patrol =
false,
96 $fld_flags =
false, $fld_timestamp =
false, $fld_user =
false,
97 $fld_comment =
false, $fld_parsedcomment =
false, $fld_sizes =
false,
98 $fld_notificationtimestamp =
false, $fld_userid =
false,
99 $fld_loginfo =
false, $fld_tags;
102 private $fld_expiry =
false;
108 private function run( $resultPageSet =
null ) {
109 $params = $this->extractRequestParams();
112 $wlowner = $this->getWatchlistUser( $params );
114 if ( $params[
'prop'] !==
null && $resultPageSet ===
null ) {
115 $prop = array_fill_keys( $params[
'prop'],
true );
117 $this->fld_ids = isset( $prop[
'ids'] );
118 $this->fld_title = isset( $prop[
'title'] );
119 $this->fld_flags = isset( $prop[
'flags'] );
120 $this->fld_user = isset( $prop[
'user'] );
121 $this->fld_userid = isset( $prop[
'userid'] );
122 $this->fld_comment = isset( $prop[
'comment'] );
123 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
124 $this->fld_timestamp = isset( $prop[
'timestamp'] );
125 $this->fld_sizes = isset( $prop[
'sizes'] );
126 $this->fld_patrol = isset( $prop[
'patrol'] );
127 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
128 $this->fld_loginfo = isset( $prop[
'loginfo'] );
129 $this->fld_tags = isset( $prop[
'tags'] );
130 $this->fld_expiry = isset( $prop[
'expiry'] );
132 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
133 $this->dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
138 'dir' => $params[
'dir'] ===
'older'
143 if ( $resultPageSet ===
null ) {
144 $options[
'includeFields'] = $this->getFieldsToInclude();
146 $options[
'usedInGenerator'] =
true;
149 if ( $params[
'start'] ) {
150 $options[
'start'] = $params[
'start'];
152 if ( $params[
'end'] ) {
153 $options[
'end'] = $params[
'end'];
157 if ( $params[
'continue'] !==
null ) {
162 if ( $wlowner !== $user ) {
163 $options[
'watchlistOwner'] = $wlowner;
164 $options[
'watchlistOwnerToken'] = $params[
'token'];
167 if ( $params[
'namespace'] !==
null ) {
168 $options[
'namespaceIds'] = $params[
'namespace'];
171 if ( $params[
'allrev'] ) {
172 $options[
'allRevisions'] =
true;
175 if ( $params[
'show'] !==
null ) {
176 $show = array_fill_keys( $params[
'show'],
true );
179 if ( $this->showParamsConflicting( $show ) ) {
184 if ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
185 || isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] )
187 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
188 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
192 $options[
'filters'] = array_keys( $show );
195 if ( $params[
'type'] !==
null ) {
199 $options[
'rcTypes'] = $rcTypes;
201 }
catch ( Exception $e ) {
207 if ( $params[
'user'] !==
null ) {
208 $options[
'onlyByUser'] = $params[
'user'];
210 if ( $params[
'excludeuser'] !==
null ) {
211 $options[
'notByUser'] = $params[
'excludeuser'];
214 $options[
'limit'] = $params[
'limit'];
216 $this->
getHookRunner()->onApiQueryWatchlistPrepareWatchedItemQueryServiceOptions(
217 $this, $params, $options );
220 $items = $this->watchedItemQueryService->getWatchedItemsWithRecentChangeInfo( $wlowner, $options, $startFrom );
223 if ( $items !== [] && $resultPageSet ===
null && $this->fld_title &&
224 $this->contentLanguage->needsGenderDistinction()
227 foreach ( $items as [ $watchedItem, ] ) {
230 if ( $this->namespaceInfo->hasGenderDistinction( $linkTarget->getNamespace() ) ) {
231 $usernames[] = $linkTarget->getText();
234 if ( $usernames !== [] ) {
235 $this->genderCache->doQuery( $usernames, __METHOD__ );
239 foreach ( $items as [ $watchedItem, $recentChangeInfo ] ) {
241 if ( $resultPageSet ===
null ) {
242 $vals = $this->extractOutputData( $watchedItem, $recentChangeInfo );
245 $startFrom = [ $recentChangeInfo[
'rc_timestamp'], $recentChangeInfo[
'rc_id'] ];
248 } elseif ( $params[
'allrev'] ) {
249 $ids[] = (int)$recentChangeInfo[
'rc_this_oldid'];
251 $ids[] = (int)$recentChangeInfo[
'rc_cur_id'];
255 if ( $startFrom !==
null ) {
259 if ( $resultPageSet ===
null ) {
264 } elseif ( $params[
'allrev'] ) {
265 $resultPageSet->populateFromRevisionIDs( $ids );
267 $resultPageSet->populateFromPageIDs( $ids );
271 private function getFieldsToInclude() {
273 if ( $this->fld_flags ) {
276 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
279 if ( $this->fld_user || $this->fld_loginfo ) {
282 if ( $this->fld_comment || $this->fld_parsedcomment ) {
285 if ( $this->fld_patrol ) {
289 if ( $this->fld_sizes ) {
292 if ( $this->fld_loginfo ) {
295 if ( $this->fld_tags ) {
298 return $includeFields;
301 private function showParamsConflicting( array $show ) {
302 return ( isset( $show[WatchedItemQueryService::FILTER_MINOR] )
303 && isset( $show[WatchedItemQueryService::FILTER_NOT_MINOR] ) )
304 || ( isset( $show[WatchedItemQueryService::FILTER_BOT] )
305 && isset( $show[WatchedItemQueryService::FILTER_NOT_BOT] ) )
306 || ( isset( $show[WatchedItemQueryService::FILTER_ANON] )
307 && isset( $show[WatchedItemQueryService::FILTER_NOT_ANON] ) )
308 || ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
309 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
310 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
311 && isset( $show[WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED] ) )
312 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
313 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
314 || ( isset( $show[WatchedItemQueryService::FILTER_UNREAD] )
315 && isset( $show[WatchedItemQueryService::FILTER_NOT_UNREAD] ) );
318 private function extractOutputData(
WatchedItem $watchedItem, array $recentChangeInfo ) {
322 $title = Title::newFromLinkTarget( $target );
324 $title = Title::castFromPageIdentity( $target );
330 $type = (int)$recentChangeInfo[
'rc_type'];
335 if ( $this->fld_title || $this->fld_ids ) {
337 if (
$type ===
RC_LOG && ( $recentChangeInfo[
'rc_deleted'] & LogPage::DELETED_ACTION ) ) {
338 $vals[
'actionhidden'] =
true;
342 LogEventsList::userCanBitfield(
343 $recentChangeInfo[
'rc_deleted'],
344 LogPage::DELETED_ACTION,
348 if ( $this->fld_title ) {
352 if ( $this->fld_ids ) {
353 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
354 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
355 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
361 if ( $this->fld_user || $this->fld_userid ) {
362 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
363 $vals[
'userhidden'] =
true;
366 if ( RevisionRecord::userCanBitfield(
367 $recentChangeInfo[
'rc_deleted'],
368 RevisionRecord::DELETED_USER,
371 if ( $this->fld_userid ) {
372 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
374 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
377 if ( $this->fld_user ) {
378 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
381 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
386 if ( $this->fld_flags ) {
387 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
388 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
389 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
393 if ( $this->fld_sizes ) {
394 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
395 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
399 if ( $this->fld_timestamp ) {
400 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
403 if ( $this->fld_notificationtimestamp ) {
406 :
wfTimestamp( TS_ISO_8601, $watchedItem->getNotificationTimestamp() );
410 if ( $this->fld_comment || $this->fld_parsedcomment ) {
411 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
412 $vals[
'commenthidden'] =
true;
415 if ( RevisionRecord::userCanBitfield(
416 $recentChangeInfo[
'rc_deleted'],
417 RevisionRecord::DELETED_COMMENT,
420 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
421 if ( $this->fld_comment ) {
422 $vals[
'comment'] = $comment;
425 if ( $this->fld_parsedcomment ) {
426 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment,
$title );
432 if ( $this->fld_patrol ) {
438 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
439 if ( $recentChangeInfo[
'rc_deleted'] & LogPage::DELETED_ACTION ) {
440 $vals[
'actionhidden'] =
true;
443 if ( LogEventsList::userCanBitfield(
444 $recentChangeInfo[
'rc_deleted'],
445 LogPage::DELETED_ACTION,
448 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
449 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
450 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
453 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
454 $vals[
'logdisplay'] = $logFormatter->getActionText();
458 if ( $this->fld_tags ) {
459 if ( $recentChangeInfo[
'rc_tags'] ) {
460 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
462 $vals[
'tags'] = $tags;
468 if ( $this->fld_expiry ) {
470 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
471 $vals[
'expiry'] = ( $expiry ?? false );
474 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
475 $vals[
'suppressed'] =
true;
478 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
479 $this, $watchedItem, $recentChangeInfo, $vals );
488 ParamValidator::PARAM_TYPE =>
'timestamp'
491 ParamValidator::PARAM_TYPE =>
'timestamp'
494 ParamValidator::PARAM_ISMULTI =>
true,
495 ParamValidator::PARAM_TYPE =>
'namespace'
498 ParamValidator::PARAM_TYPE =>
'user',
499 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
502 ParamValidator::PARAM_TYPE =>
'user',
503 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
506 ParamValidator::PARAM_DEFAULT =>
'older',
507 ParamValidator::PARAM_TYPE => [
513 'newer' =>
'api-help-paramvalue-direction-newer',
514 'older' =>
'api-help-paramvalue-direction-older',
518 ParamValidator::PARAM_DEFAULT => 10,
519 ParamValidator::PARAM_TYPE =>
'limit',
520 IntegerDef::PARAM_MIN => 1,
525 ParamValidator::PARAM_ISMULTI =>
true,
526 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
528 ParamValidator::PARAM_TYPE => [
539 'notificationtimestamp',
546 ParamValidator::PARAM_ISMULTI =>
true,
547 ParamValidator::PARAM_TYPE => [
548 WatchedItemQueryService::FILTER_MINOR,
549 WatchedItemQueryService::FILTER_NOT_MINOR,
550 WatchedItemQueryService::FILTER_BOT,
551 WatchedItemQueryService::FILTER_NOT_BOT,
552 WatchedItemQueryService::FILTER_ANON,
553 WatchedItemQueryService::FILTER_NOT_ANON,
554 WatchedItemQueryService::FILTER_PATROLLED,
555 WatchedItemQueryService::FILTER_NOT_PATROLLED,
556 WatchedItemQueryService::FILTER_AUTOPATROLLED,
557 WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED,
558 WatchedItemQueryService::FILTER_UNREAD,
559 WatchedItemQueryService::FILTER_NOT_UNREAD,
563 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
564 ParamValidator::PARAM_ISMULTI =>
true,
566 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
569 ParamValidator::PARAM_TYPE =>
'user',
570 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
573 ParamValidator::PARAM_TYPE =>
'string',
574 ParamValidator::PARAM_SENSITIVE =>
true,
584 'action=query&list=watchlist'
585 =>
'apihelp-query+watchlist-example-simple',
586 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
587 =>
'apihelp-query+watchlist-example-props',
588 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
589 =>
'apihelp-query+watchlist-example-expiry',
590 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
591 =>
'apihelp-query+watchlist-example-allrev',
592 'action=query&generator=watchlist&prop=info'
593 =>
'apihelp-query+watchlist-example-generator',
594 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
595 =>
'apihelp-query+watchlist-example-generator-rev',
596 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
597 =>
'apihelp-query+watchlist-example-wlowner',
602 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist';