73 parent::__construct( $query, $moduleName,
'wl' );
74 $this->commentStore = $commentStore;
75 $this->watchedItemQueryService = $watchedItemQueryService;
76 $this->contentLanguage = $contentLanguage;
77 $this->namespaceInfo = $namespaceInfo;
78 $this->genderCache = $genderCache;
79 $this->commentFormatter = $commentFormatter;
80 $this->tempUserConfig = $tempUserConfig;
88 $this->
run( $resultPageSet );
91 private $fld_ids =
false, $fld_title =
false, $fld_patrol =
false,
92 $fld_flags =
false, $fld_timestamp =
false, $fld_user =
false,
93 $fld_comment =
false, $fld_parsedcomment =
false, $fld_sizes =
false,
94 $fld_notificationtimestamp =
false, $fld_userid =
false,
95 $fld_loginfo =
false, $fld_tags;
98 private $fld_expiry =
false;
104 private function run( $resultPageSet =
null ) {
105 $params = $this->extractRequestParams();
108 $wlowner = $this->getWatchlistUser(
$params );
110 if (
$params[
'prop'] !==
null && $resultPageSet ===
null ) {
111 $prop = array_fill_keys(
$params[
'prop'],
true );
113 $this->fld_ids = isset( $prop[
'ids'] );
114 $this->fld_title = isset( $prop[
'title'] );
115 $this->fld_flags = isset( $prop[
'flags'] );
116 $this->fld_user = isset( $prop[
'user'] );
117 $this->fld_userid = isset( $prop[
'userid'] );
118 $this->fld_comment = isset( $prop[
'comment'] );
119 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
120 $this->fld_timestamp = isset( $prop[
'timestamp'] );
121 $this->fld_sizes = isset( $prop[
'sizes'] );
122 $this->fld_patrol = isset( $prop[
'patrol'] );
123 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
124 $this->fld_loginfo = isset( $prop[
'loginfo'] );
125 $this->fld_tags = isset( $prop[
'tags'] );
126 $this->fld_expiry = isset( $prop[
'expiry'] );
128 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
129 $this->dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
134 'dir' =>
$params[
'dir'] ===
'older'
139 if ( $resultPageSet ===
null ) {
140 $options[
'includeFields'] = $this->getFieldsToInclude();
142 $options[
'usedInGenerator'] =
true;
146 $options[
'start'] =
$params[
'start'];
149 $options[
'end'] =
$params[
'end'];
153 if (
$params[
'continue'] !==
null ) {
158 if ( $wlowner !== $user ) {
159 $options[
'watchlistOwner'] = $wlowner;
160 $options[
'watchlistOwnerToken'] =
$params[
'token'];
163 if (
$params[
'namespace'] !==
null ) {
164 $options[
'namespaceIds'] =
$params[
'namespace'];
168 $options[
'allRevisions'] =
true;
171 if (
$params[
'show'] !==
null ) {
172 $show = array_fill_keys(
$params[
'show'],
true );
175 if ( $this->showParamsConflicting( $show ) ) {
180 if ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
181 || isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] )
183 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
184 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
188 $options[
'filters'] = array_keys( $show );
191 if (
$params[
'type'] !==
null ) {
194 $options[
'rcTypes'] = $rcTypes;
199 if (
$params[
'user'] !==
null ) {
200 $options[
'onlyByUser'] =
$params[
'user'];
202 if (
$params[
'excludeuser'] !==
null ) {
203 $options[
'notByUser'] =
$params[
'excludeuser'];
206 $options[
'limit'] =
$params[
'limit'];
208 $this->
getHookRunner()->onApiQueryWatchlistPrepareWatchedItemQueryServiceOptions(
212 $items = $this->watchedItemQueryService->getWatchedItemsWithRecentChangeInfo( $wlowner, $options, $startFrom );
215 if ( $items !== [] && $resultPageSet ===
null && $this->fld_title &&
216 $this->contentLanguage->needsGenderDistinction()
219 foreach ( $items as [ $watchedItem, ] ) {
222 if ( $this->namespaceInfo->hasGenderDistinction( $linkTarget->getNamespace() ) ) {
223 $usernames[] = $linkTarget->getText();
226 if ( $usernames !== [] ) {
227 $this->genderCache->doQuery( $usernames, __METHOD__ );
231 foreach ( $items as [ $watchedItem, $recentChangeInfo ] ) {
233 if ( $resultPageSet ===
null ) {
234 $vals = $this->extractOutputData( $watchedItem, $recentChangeInfo );
237 $startFrom = [ $recentChangeInfo[
'rc_timestamp'], $recentChangeInfo[
'rc_id'] ];
240 } elseif (
$params[
'allrev'] ) {
241 $ids[] = (int)$recentChangeInfo[
'rc_this_oldid'];
243 $ids[] = (int)$recentChangeInfo[
'rc_cur_id'];
247 if ( $startFrom !==
null ) {
251 if ( $resultPageSet ===
null ) {
256 } elseif (
$params[
'allrev'] ) {
257 $resultPageSet->populateFromRevisionIDs( $ids );
259 $resultPageSet->populateFromPageIDs( $ids );
263 private function getFieldsToInclude() {
265 if ( $this->fld_flags ) {
268 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
271 if ( $this->fld_user || $this->fld_loginfo ) {
274 if ( $this->fld_comment || $this->fld_parsedcomment ) {
277 if ( $this->fld_patrol ) {
281 if ( $this->fld_sizes ) {
284 if ( $this->fld_loginfo ) {
287 if ( $this->fld_tags ) {
290 return $includeFields;
293 private function showParamsConflicting( array $show ) {
294 return ( isset( $show[WatchedItemQueryService::FILTER_MINOR] )
295 && isset( $show[WatchedItemQueryService::FILTER_NOT_MINOR] ) )
296 || ( isset( $show[WatchedItemQueryService::FILTER_BOT] )
297 && isset( $show[WatchedItemQueryService::FILTER_NOT_BOT] ) )
298 || ( isset( $show[WatchedItemQueryService::FILTER_ANON] )
299 && isset( $show[WatchedItemQueryService::FILTER_NOT_ANON] ) )
300 || ( isset( $show[WatchedItemQueryService::FILTER_PATROLLED] )
301 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
302 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
303 && isset( $show[WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED] ) )
304 || ( isset( $show[WatchedItemQueryService::FILTER_AUTOPATROLLED] )
305 && isset( $show[WatchedItemQueryService::FILTER_NOT_PATROLLED] ) )
306 || ( isset( $show[WatchedItemQueryService::FILTER_UNREAD] )
307 && isset( $show[WatchedItemQueryService::FILTER_NOT_UNREAD] ) );
310 private function extractOutputData(
WatchedItem $watchedItem, array $recentChangeInfo ) {
314 $title = Title::newFromLinkTarget( $target );
316 $title = Title::newFromPageIdentity( $target );
322 $type = (int)$recentChangeInfo[
'rc_type'];
327 if ( $this->fld_title || $this->fld_ids ) {
329 if ( $type ===
RC_LOG && ( $recentChangeInfo[
'rc_deleted'] & LogPage::DELETED_ACTION ) ) {
330 $vals[
'actionhidden'] =
true;
334 LogEventsList::userCanBitfield(
335 $recentChangeInfo[
'rc_deleted'],
336 LogPage::DELETED_ACTION,
340 if ( $this->fld_title ) {
343 if ( $this->fld_ids ) {
344 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
345 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
346 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
351 if ( $this->fld_user || $this->fld_userid ) {
352 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
353 $vals[
'userhidden'] =
true;
356 if ( RevisionRecord::userCanBitfield(
357 $recentChangeInfo[
'rc_deleted'],
358 RevisionRecord::DELETED_USER,
361 if ( $this->fld_userid ) {
362 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
364 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
367 if ( $this->fld_user ) {
368 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
369 $vals[
'temp'] = $this->tempUserConfig->isTempName(
370 $recentChangeInfo[
'rc_user_text']
378 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
384 if ( $this->fld_flags ) {
385 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
386 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
387 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
391 if ( $this->fld_sizes ) {
392 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
393 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
397 if ( $this->fld_timestamp ) {
398 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
401 if ( $this->fld_notificationtimestamp ) {
404 :
wfTimestamp( TS_ISO_8601, $watchedItem->getNotificationTimestamp() );
408 if ( $this->fld_comment || $this->fld_parsedcomment ) {
409 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
410 $vals[
'commenthidden'] =
true;
413 if ( RevisionRecord::userCanBitfield(
414 $recentChangeInfo[
'rc_deleted'],
415 RevisionRecord::DELETED_COMMENT,
418 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
419 if ( $this->fld_comment ) {
420 $vals[
'comment'] = $comment;
423 if ( $this->fld_parsedcomment ) {
424 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment, $title );
430 if ( $this->fld_patrol ) {
436 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
437 if ( $recentChangeInfo[
'rc_deleted'] & LogPage::DELETED_ACTION ) {
438 $vals[
'actionhidden'] =
true;
441 if ( LogEventsList::userCanBitfield(
442 $recentChangeInfo[
'rc_deleted'],
443 LogPage::DELETED_ACTION,
446 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
447 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
448 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
451 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
452 $vals[
'logdisplay'] = $logFormatter->getActionText();
456 if ( $this->fld_tags ) {
457 if ( $recentChangeInfo[
'rc_tags'] ) {
458 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
460 $vals[
'tags'] = $tags;
466 if ( $this->fld_expiry ) {
468 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
469 $vals[
'expiry'] = ( $expiry ?? false );
472 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
473 $vals[
'suppressed'] =
true;
476 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
477 $this, $watchedItem, $recentChangeInfo, $vals );
486 ParamValidator::PARAM_TYPE =>
'timestamp'
489 ParamValidator::PARAM_TYPE =>
'timestamp'
492 ParamValidator::PARAM_ISMULTI =>
true,
493 ParamValidator::PARAM_TYPE =>
'namespace'
496 ParamValidator::PARAM_TYPE =>
'user',
497 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
500 ParamValidator::PARAM_TYPE =>
'user',
501 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
504 ParamValidator::PARAM_DEFAULT =>
'older',
505 ParamValidator::PARAM_TYPE => [
511 'newer' =>
'api-help-paramvalue-direction-newer',
512 'older' =>
'api-help-paramvalue-direction-older',
516 ParamValidator::PARAM_DEFAULT => 10,
517 ParamValidator::PARAM_TYPE =>
'limit',
518 IntegerDef::PARAM_MIN => 1,
523 ParamValidator::PARAM_ISMULTI =>
true,
524 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
526 ParamValidator::PARAM_TYPE => [
537 'notificationtimestamp',
544 ParamValidator::PARAM_ISMULTI =>
true,
545 ParamValidator::PARAM_TYPE => [
546 WatchedItemQueryService::FILTER_MINOR,
547 WatchedItemQueryService::FILTER_NOT_MINOR,
548 WatchedItemQueryService::FILTER_BOT,
549 WatchedItemQueryService::FILTER_NOT_BOT,
550 WatchedItemQueryService::FILTER_ANON,
551 WatchedItemQueryService::FILTER_NOT_ANON,
552 WatchedItemQueryService::FILTER_PATROLLED,
553 WatchedItemQueryService::FILTER_NOT_PATROLLED,
554 WatchedItemQueryService::FILTER_AUTOPATROLLED,
555 WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED,
556 WatchedItemQueryService::FILTER_UNREAD,
557 WatchedItemQueryService::FILTER_NOT_UNREAD,
561 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
562 ParamValidator::PARAM_ISMULTI =>
true,
564 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
567 ParamValidator::PARAM_TYPE =>
'user',
568 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
571 ParamValidator::PARAM_TYPE =>
'string',
572 ParamValidator::PARAM_SENSITIVE =>
true,
582 'action=query&list=watchlist'
583 =>
'apihelp-query+watchlist-example-simple',
584 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
585 =>
'apihelp-query+watchlist-example-props',
586 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
587 =>
'apihelp-query+watchlist-example-expiry',
588 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
589 =>
'apihelp-query+watchlist-example-allrev',
590 'action=query&generator=watchlist&prop=info'
591 =>
'apihelp-query+watchlist-example-generator',
592 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
593 =>
'apihelp-query+watchlist-example-generator-rev',
594 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
595 =>
'apihelp-query+watchlist-example-wlowner',
600 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist';