38 private $commentStore;
41 private $watchedItemQueryService;
44 private $contentLanguage;
47 private $namespaceInfo;
70 parent::__construct( $query, $moduleName,
'wl' );
71 $this->commentStore = $commentStore;
72 $this->watchedItemQueryService = $watchedItemQueryService;
73 $this->contentLanguage = $contentLanguage;
74 $this->namespaceInfo = $namespaceInfo;
75 $this->genderCache = $genderCache;
83 $this->run( $resultPageSet );
86 private $fld_ids =
false, $fld_title =
false, $fld_patrol =
false,
87 $fld_flags =
false, $fld_timestamp =
false, $fld_user =
false,
88 $fld_comment =
false, $fld_parsedcomment =
false, $fld_sizes =
false,
89 $fld_notificationtimestamp =
false, $fld_userid =
false,
90 $fld_loginfo =
false, $fld_tags;
93 private $fld_expiry =
false;
99 private function run( $resultPageSet =
null ) {
100 $params = $this->extractRequestParams();
103 $wlowner = $this->getWatchlistUser( $params );
105 if ( $params[
'prop'] !==
null && $resultPageSet ===
null ) {
106 $prop = array_fill_keys( $params[
'prop'],
true );
108 $this->fld_ids = isset( $prop[
'ids'] );
109 $this->fld_title = isset( $prop[
'title'] );
110 $this->fld_flags = isset( $prop[
'flags'] );
111 $this->fld_user = isset( $prop[
'user'] );
112 $this->fld_userid = isset( $prop[
'userid'] );
113 $this->fld_comment = isset( $prop[
'comment'] );
114 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
115 $this->fld_timestamp = isset( $prop[
'timestamp'] );
116 $this->fld_sizes = isset( $prop[
'sizes'] );
117 $this->fld_patrol = isset( $prop[
'patrol'] );
118 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
119 $this->fld_loginfo = isset( $prop[
'loginfo'] );
120 $this->fld_tags = isset( $prop[
'tags'] );
121 $this->fld_expiry = isset( $prop[
'expiry'] );
123 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
124 $this->dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
129 'dir' => $params[
'dir'] ===
'older'
134 if ( $resultPageSet ===
null ) {
135 $options[
'includeFields'] = $this->getFieldsToInclude();
137 $options[
'usedInGenerator'] =
true;
140 if ( $params[
'start'] ) {
141 $options[
'start'] = $params[
'start'];
143 if ( $params[
'end'] ) {
144 $options[
'end'] = $params[
'end'];
148 if ( $params[
'continue'] !==
null ) {
149 $cont = explode(
'|', $params[
'continue'] );
151 $continueTimestamp = $cont[0];
152 $continueId = (int)$cont[1];
154 $startFrom = [ $continueTimestamp, $continueId ];
157 if ( $wlowner !== $user ) {
158 $options[
'watchlistOwner'] = $wlowner;
159 $options[
'watchlistOwnerToken'] = $params[
'token'];
162 if ( $params[
'namespace'] !==
null ) {
163 $options[
'namespaceIds'] = $params[
'namespace'];
166 if ( $params[
'allrev'] ) {
167 $options[
'allRevisions'] =
true;
170 if ( $params[
'show'] !==
null ) {
171 $show = array_fill_keys( $params[
'show'],
true );
174 if ( $this->showParamsConflicting( $show ) ) {
179 if ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
180 || isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] )
182 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
183 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
187 $options[
'filters'] = array_keys( $show );
190 if ( $params[
'type'] !==
null ) {
194 $options[
'rcTypes'] = $rcTypes;
196 }
catch ( Exception $e ) {
202 if ( $params[
'user'] !==
null ) {
203 $options[
'onlyByUser'] = $params[
'user'];
205 if ( $params[
'excludeuser'] !==
null ) {
206 $options[
'notByUser'] = $params[
'excludeuser'];
209 $options[
'limit'] = $params[
'limit'];
211 $this->
getHookRunner()->onApiQueryWatchlistPrepareWatchedItemQueryServiceOptions(
212 $this, $params, $options );
215 $items = $this->watchedItemQueryService->getWatchedItemsWithRecentChangeInfo( $wlowner, $options, $startFrom );
218 if ( $items !== [] && $resultPageSet ===
null && $this->fld_title &&
219 $this->contentLanguage->needsGenderDistinction()
222 foreach ( $items as list( $watchedItem, $recentChangeInfo ) ) {
225 if ( $this->namespaceInfo->hasGenderDistinction( $linkTarget->getNamespace() ) ) {
226 $usernames[] = $linkTarget->getText();
229 if ( $usernames !== [] ) {
230 $this->genderCache->doQuery( $usernames, __METHOD__ );
234 foreach ( $items as list( $watchedItem, $recentChangeInfo ) ) {
236 if ( $resultPageSet ===
null ) {
237 $vals = $this->extractOutputData( $watchedItem, $recentChangeInfo );
240 $startFrom = [ $recentChangeInfo[
'rc_timestamp'], $recentChangeInfo[
'rc_id'] ];
243 } elseif ( $params[
'allrev'] ) {
244 $ids[] = (int)$recentChangeInfo[
'rc_this_oldid'];
246 $ids[] = (int)$recentChangeInfo[
'rc_cur_id'];
250 if ( $startFrom !==
null ) {
254 if ( $resultPageSet ===
null ) {
259 } elseif ( $params[
'allrev'] ) {
260 $resultPageSet->populateFromRevisionIDs( $ids );
262 $resultPageSet->populateFromPageIDs( $ids );
266 private function getFieldsToInclude() {
268 if ( $this->fld_flags ) {
271 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
274 if ( $this->fld_user || $this->fld_loginfo ) {
277 if ( $this->fld_comment || $this->fld_parsedcomment ) {
280 if ( $this->fld_patrol ) {
284 if ( $this->fld_sizes ) {
287 if ( $this->fld_loginfo ) {
290 if ( $this->fld_tags ) {
293 return $includeFields;
296 private function showParamsConflicting( array $show ) {
297 return ( isset( $show[WatchedItemQueryService::FILTER_MINOR] )
298 && isset( $show[WatchedItemQueryService::FILTER_NOT_MINOR] ) )
299 || ( isset( $show[WatchedItemQueryService::FILTER_BOT] )
300 && isset( $show[WatchedItemQueryService::FILTER_NOT_BOT] ) )
301 || ( isset( $show[WatchedItemQueryService::FILTER_ANON] )
302 && isset( $show[WatchedItemQueryService::FILTER_NOT_ANON] ) )
303 || ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
304 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
305 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
306 && isset( $show[WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED] ) )
307 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
308 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
309 || ( isset( $show[WatchedItemQueryService::FILTER_UNREAD] )
310 && isset( $show[WatchedItemQueryService::FILTER_NOT_UNREAD] ) );
313 private function extractOutputData(
WatchedItem $watchedItem, array $recentChangeInfo ) {
325 $type = (int)$recentChangeInfo[
'rc_type'];
330 if ( $this->fld_title || $this->fld_ids ) {
333 $vals[
'actionhidden'] =
true;
337 LogEventsList::userCanBitfield(
338 $recentChangeInfo[
'rc_deleted'],
343 if ( $this->fld_title ) {
347 if ( $this->fld_ids ) {
348 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
349 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
350 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
356 if ( $this->fld_user || $this->fld_userid ) {
357 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
358 $vals[
'userhidden'] =
true;
361 if ( RevisionRecord::userCanBitfield(
362 $recentChangeInfo[
'rc_deleted'],
363 RevisionRecord::DELETED_USER,
366 if ( $this->fld_userid ) {
367 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
369 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
372 if ( $this->fld_user ) {
373 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
376 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
381 if ( $this->fld_flags ) {
382 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
383 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
384 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
388 if ( $this->fld_sizes ) {
389 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
390 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
394 if ( $this->fld_timestamp ) {
395 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
398 if ( $this->fld_notificationtimestamp ) {
401 :
wfTimestamp( TS_ISO_8601, $watchedItem->getNotificationTimestamp() );
405 if ( $this->fld_comment || $this->fld_parsedcomment ) {
406 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
407 $vals[
'commenthidden'] =
true;
410 if ( RevisionRecord::userCanBitfield(
411 $recentChangeInfo[
'rc_deleted'],
412 RevisionRecord::DELETED_COMMENT,
415 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
416 if ( $this->fld_comment ) {
417 $vals[
'comment'] = $comment;
420 if ( $this->fld_parsedcomment ) {
427 if ( $this->fld_patrol ) {
433 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
435 $vals[
'actionhidden'] =
true;
438 if ( LogEventsList::userCanBitfield(
439 $recentChangeInfo[
'rc_deleted'],
443 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
444 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
445 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
448 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
449 $vals[
'logdisplay'] = $logFormatter->getActionText();
453 if ( $this->fld_tags ) {
454 if ( $recentChangeInfo[
'rc_tags'] ) {
455 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
457 $vals[
'tags'] = $tags;
463 if ( $this->fld_expiry ) {
465 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
466 $vals[
'expiry'] = ( $expiry ?? false );
469 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
470 $vals[
'suppressed'] =
true;
473 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
474 $this, $watchedItem, $recentChangeInfo, $vals );
483 ParamValidator::PARAM_TYPE =>
'timestamp'
486 ParamValidator::PARAM_TYPE =>
'timestamp'
489 ParamValidator::PARAM_ISMULTI =>
true,
490 ParamValidator::PARAM_TYPE =>
'namespace'
493 ParamValidator::PARAM_TYPE =>
'user',
494 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
497 ParamValidator::PARAM_TYPE =>
'user',
498 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
501 ParamValidator::PARAM_DEFAULT =>
'older',
502 ParamValidator::PARAM_TYPE => [
508 'newer' =>
'api-help-paramvalue-direction-newer',
509 'older' =>
'api-help-paramvalue-direction-older',
513 ParamValidator::PARAM_DEFAULT => 10,
514 ParamValidator::PARAM_TYPE =>
'limit',
515 IntegerDef::PARAM_MIN => 1,
520 ParamValidator::PARAM_ISMULTI =>
true,
521 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
523 ParamValidator::PARAM_TYPE => [
534 'notificationtimestamp',
541 ParamValidator::PARAM_ISMULTI =>
true,
542 ParamValidator::PARAM_TYPE => [
543 WatchedItemQueryService::FILTER_MINOR,
544 WatchedItemQueryService::FILTER_NOT_MINOR,
545 WatchedItemQueryService::FILTER_BOT,
546 WatchedItemQueryService::FILTER_NOT_BOT,
547 WatchedItemQueryService::FILTER_ANON,
548 WatchedItemQueryService::FILTER_NOT_ANON,
549 WatchedItemQueryService::FILTER_PATROLLED,
550 WatchedItemQueryService::FILTER_NOT_PATROLLED,
551 WatchedItemQueryService::FILTER_AUTOPATROLLED,
552 WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED,
553 WatchedItemQueryService::FILTER_UNREAD,
554 WatchedItemQueryService::FILTER_NOT_UNREAD,
558 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
559 ParamValidator::PARAM_ISMULTI =>
true,
561 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
564 ParamValidator::PARAM_TYPE =>
'user',
565 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
568 ParamValidator::PARAM_TYPE =>
'string',
569 ParamValidator::PARAM_SENSITIVE =>
true,
579 'action=query&list=watchlist'
580 =>
'apihelp-query+watchlist-example-simple',
581 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
582 =>
'apihelp-query+watchlist-example-props',
583 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
584 =>
'apihelp-query+watchlist-example-expiry',
585 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
586 =>
'apihelp-query+watchlist-example-allrev',
587 'action=query&generator=watchlist&prop=info'
588 =>
'apihelp-query+watchlist-example-generator',
589 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
590 =>
'apihelp-query+watchlist-example-generator-rev',
591 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
592 =>
'apihelp-query+watchlist-example-wlowner',
597 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist';