74 parent::__construct( $query, $moduleName,
'wl' );
75 $this->commentStore = $commentStore;
76 $this->watchedItemQueryService = $watchedItemQueryService;
77 $this->contentLanguage = $contentLanguage;
78 $this->namespaceInfo = $namespaceInfo;
79 $this->genderCache = $genderCache;
80 $this->commentFormatter = $commentFormatter;
81 $this->tempUserConfig = $tempUserConfig;
82 $this->logFormatterFactory = $logFormatterFactory;
90 $this->run( $resultPageSet );
93 private bool $fld_ids =
false;
94 private bool $fld_title =
false;
95 private bool $fld_patrol =
false;
96 private bool $fld_flags =
false;
97 private bool $fld_timestamp =
false;
98 private bool $fld_user =
false;
99 private bool $fld_comment =
false;
100 private bool $fld_parsedcomment =
false;
101 private bool $fld_sizes =
false;
102 private bool $fld_notificationtimestamp =
false;
103 private bool $fld_userid =
false;
104 private bool $fld_loginfo =
false;
105 private bool $fld_tags =
false;
106 private bool $fld_expiry =
false;
112 private function run( $resultPageSet =
null ) {
118 if ( $params[
'prop'] !==
null && $resultPageSet ===
null ) {
119 $prop = array_fill_keys( $params[
'prop'],
true );
121 $this->fld_ids = isset( $prop[
'ids'] );
122 $this->fld_title = isset( $prop[
'title'] );
123 $this->fld_flags = isset( $prop[
'flags'] );
124 $this->fld_user = isset( $prop[
'user'] );
125 $this->fld_userid = isset( $prop[
'userid'] );
126 $this->fld_comment = isset( $prop[
'comment'] );
127 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
128 $this->fld_timestamp = isset( $prop[
'timestamp'] );
129 $this->fld_sizes = isset( $prop[
'sizes'] );
130 $this->fld_patrol = isset( $prop[
'patrol'] );
131 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
132 $this->fld_loginfo = isset( $prop[
'loginfo'] );
133 $this->fld_tags = isset( $prop[
'tags'] );
134 $this->fld_expiry = isset( $prop[
'expiry'] );
136 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
137 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
142 'dir' => $params[
'dir'] ===
'older'
143 ? WatchedItemQueryService::DIR_OLDER
144 : WatchedItemQueryService::DIR_NEWER,
147 if ( $resultPageSet ===
null ) {
148 $options[
'includeFields'] = $this->getFieldsToInclude();
150 $options[
'usedInGenerator'] =
true;
153 if ( $params[
'start'] ) {
154 $options[
'start'] =
$params[
'start'];
156 if ( $params[
'end'] ) {
157 $options[
'end'] =
$params[
'end'];
161 if ( $params[
'continue'] !==
null ) {
166 if ( $wlowner !== $user ) {
167 $options[
'watchlistOwner'] = $wlowner;
168 $options[
'watchlistOwnerToken'] =
$params[
'token'];
171 if ( $params[
'namespace'] !==
null ) {
172 $options[
'namespaceIds'] =
$params[
'namespace'];
175 if ( $params[
'allrev'] ) {
176 $options[
'allRevisions'] =
true;
179 if ( $params[
'show'] !==
null ) {
180 $show = array_fill_keys( $params[
'show'],
true );
183 if ( $this->showParamsConflicting( $show ) ) {
188 if ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
189 || isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] )
191 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
192 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
196 $options[
'filters'] = array_keys( $show );
199 if ( $params[
'type'] !==
null ) {
200 $rcTypes = RecentChange::parseToRCType( $params[
'type'] );
202 $options[
'rcTypes'] = $rcTypes;
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, ] ) {
229 $linkTarget = $watchedItem->getTarget();
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 ) {
274 $includeFields[] = WatchedItemQueryService::INCLUDE_FLAGS;
276 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
277 $includeFields[] = WatchedItemQueryService::INCLUDE_USER_ID;
279 if ( $this->fld_user || $this->fld_loginfo ) {
280 $includeFields[] = WatchedItemQueryService::INCLUDE_USER;
282 if ( $this->fld_comment || $this->fld_parsedcomment ) {
283 $includeFields[] = WatchedItemQueryService::INCLUDE_COMMENT;
285 if ( $this->fld_patrol ) {
286 $includeFields[] = WatchedItemQueryService::INCLUDE_PATROL_INFO;
287 $includeFields[] = WatchedItemQueryService::INCLUDE_AUTOPATROL_INFO;
289 if ( $this->fld_sizes ) {
290 $includeFields[] = WatchedItemQueryService::INCLUDE_SIZES;
292 if ( $this->fld_loginfo ) {
293 $includeFields[] = WatchedItemQueryService::INCLUDE_LOG_INFO;
295 if ( $this->fld_tags ) {
296 $includeFields[] = WatchedItemQueryService::INCLUDE_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 ) {
320 $target = $watchedItem->getTarget();
321 if ( $target instanceof LinkTarget ) {
322 $title = Title::newFromLinkTarget( $target );
324 $title = Title::newFromPageIdentity( $target );
330 $type = (int)$recentChangeInfo[
'rc_type'];
331 $vals[
'type'] = RecentChange::parseFromRCType( $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 ) {
351 if ( $this->fld_ids ) {
352 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
353 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
354 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
359 if ( $this->fld_user || $this->fld_userid ) {
360 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
361 $vals[
'userhidden'] =
true;
364 if ( RevisionRecord::userCanBitfield(
365 $recentChangeInfo[
'rc_deleted'],
366 RevisionRecord::DELETED_USER,
369 if ( $this->fld_userid ) {
370 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
372 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
375 if ( $this->fld_user ) {
376 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
377 $vals[
'temp'] = $this->tempUserConfig->isTempName(
378 $recentChangeInfo[
'rc_user_text']
386 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
392 if ( $this->fld_flags ) {
393 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
394 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
395 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
399 if ( $this->fld_sizes ) {
400 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
401 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
405 if ( $this->fld_timestamp ) {
406 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
409 if ( $this->fld_notificationtimestamp ) {
410 $vals[
'notificationtimestamp'] = ( $watchedItem->getNotificationTimestamp() == null )
412 :
wfTimestamp( TS_ISO_8601, $watchedItem->getNotificationTimestamp() );
416 if ( $this->fld_comment || $this->fld_parsedcomment ) {
417 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
418 $vals[
'commenthidden'] =
true;
421 if ( RevisionRecord::userCanBitfield(
422 $recentChangeInfo[
'rc_deleted'],
423 RevisionRecord::DELETED_COMMENT,
426 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
427 if ( $this->fld_comment ) {
428 $vals[
'comment'] = $comment;
431 if ( $this->fld_parsedcomment ) {
432 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment, $title );
438 if ( $this->fld_patrol ) {
439 $vals[
'patrolled'] = $recentChangeInfo[
'rc_patrolled'] != RecentChange::PRC_UNPATROLLED;
440 $vals[
'unpatrolled'] = ChangesList::isUnpatrolled( (
object)$recentChangeInfo, $user );
441 $vals[
'autopatrolled'] = $recentChangeInfo[
'rc_patrolled'] == RecentChange::PRC_AUTOPATROLLED;
444 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
445 if ( $recentChangeInfo[
'rc_deleted'] & LogPage::DELETED_ACTION ) {
446 $vals[
'actionhidden'] =
true;
449 if ( LogEventsList::userCanBitfield(
450 $recentChangeInfo[
'rc_deleted'],
451 LogPage::DELETED_ACTION,
454 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
455 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
456 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
458 $logFormatter = $this->logFormatterFactory->newFromRow( $recentChangeInfo );
459 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
460 $vals[
'logdisplay'] = $logFormatter->getActionText();
464 if ( $this->fld_tags ) {
465 if ( $recentChangeInfo[
'rc_tags'] ) {
466 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
468 $vals[
'tags'] = $tags;
474 if ( $this->fld_expiry ) {
476 $expiry = $watchedItem->getExpiry( TS_ISO_8601 );
477 $vals[
'expiry'] = ( $expiry ?? false );
480 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
481 $vals[
'suppressed'] =
true;
484 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
485 $this, $watchedItem, $recentChangeInfo, $vals );
494 ParamValidator::PARAM_TYPE =>
'timestamp'
497 ParamValidator::PARAM_TYPE =>
'timestamp'
500 ParamValidator::PARAM_ISMULTI =>
true,
501 ParamValidator::PARAM_TYPE =>
'namespace'
504 ParamValidator::PARAM_TYPE =>
'user',
505 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
508 ParamValidator::PARAM_TYPE =>
'user',
509 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
512 ParamValidator::PARAM_DEFAULT =>
'older',
513 ParamValidator::PARAM_TYPE => [
519 'newer' =>
'api-help-paramvalue-direction-newer',
520 'older' =>
'api-help-paramvalue-direction-older',
524 ParamValidator::PARAM_DEFAULT => 10,
525 ParamValidator::PARAM_TYPE =>
'limit',
526 IntegerDef::PARAM_MIN => 1,
531 ParamValidator::PARAM_ISMULTI =>
true,
532 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
534 ParamValidator::PARAM_TYPE => [
545 'notificationtimestamp',
552 ParamValidator::PARAM_ISMULTI =>
true,
553 ParamValidator::PARAM_TYPE => [
554 WatchedItemQueryService::FILTER_MINOR,
555 WatchedItemQueryService::FILTER_NOT_MINOR,
556 WatchedItemQueryService::FILTER_BOT,
557 WatchedItemQueryService::FILTER_NOT_BOT,
558 WatchedItemQueryService::FILTER_ANON,
559 WatchedItemQueryService::FILTER_NOT_ANON,
560 WatchedItemQueryService::FILTER_PATROLLED,
561 WatchedItemQueryService::FILTER_NOT_PATROLLED,
562 WatchedItemQueryService::FILTER_AUTOPATROLLED,
563 WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED,
564 WatchedItemQueryService::FILTER_UNREAD,
565 WatchedItemQueryService::FILTER_NOT_UNREAD,
569 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
570 ParamValidator::PARAM_ISMULTI =>
true,
572 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
575 ParamValidator::PARAM_TYPE =>
'user',
576 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
579 ParamValidator::PARAM_TYPE =>
'string',
580 ParamValidator::PARAM_SENSITIVE =>
true,
590 'action=query&list=watchlist'
591 =>
'apihelp-query+watchlist-example-simple',
592 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
593 =>
'apihelp-query+watchlist-example-props',
594 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
595 =>
'apihelp-query+watchlist-example-expiry',
596 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
597 =>
'apihelp-query+watchlist-example-allrev',
598 'action=query&generator=watchlist&prop=info'
599 =>
'apihelp-query+watchlist-example-generator',
600 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
601 =>
'apihelp-query+watchlist-example-generator-rev',
602 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
603 =>
'apihelp-query+watchlist-example-wlowner',
608 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist';