68 parent::__construct( $query, $moduleName,
'wl' );
69 $this->commentStore = $commentStore;
70 $this->watchedItemQueryService = $watchedItemQueryService;
71 $this->contentLanguage = $contentLanguage;
72 $this->namespaceInfo = $namespaceInfo;
73 $this->genderCache = $genderCache;
81 $this->
run( $resultPageSet );
97 private function run( $resultPageSet =
null ) {
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'
130 ? WatchedItemQueryService::DIR_OLDER
131 : WatchedItemQueryService::DIR_NEWER,
134 if ( $resultPageSet ===
null ) {
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 );
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 ) {
192 $rcTypes = RecentChange::parseToRCType( $params[
'type'] );
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 ) ) {
224 $linkTarget = $watchedItem->getTarget();
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 ) {
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 );
268 if ( $this->fld_flags ) {
269 $includeFields[] = WatchedItemQueryService::INCLUDE_FLAGS;
271 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
272 $includeFields[] = WatchedItemQueryService::INCLUDE_USER_ID;
274 if ( $this->fld_user || $this->fld_loginfo ) {
275 $includeFields[] = WatchedItemQueryService::INCLUDE_USER;
277 if ( $this->fld_comment || $this->fld_parsedcomment ) {
278 $includeFields[] = WatchedItemQueryService::INCLUDE_COMMENT;
280 if ( $this->fld_patrol ) {
281 $includeFields[] = WatchedItemQueryService::INCLUDE_PATROL_INFO;
282 $includeFields[] = WatchedItemQueryService::INCLUDE_AUTOPATROL_INFO;
284 if ( $this->fld_sizes ) {
285 $includeFields[] = WatchedItemQueryService::INCLUDE_SIZES;
287 if ( $this->fld_loginfo ) {
288 $includeFields[] = WatchedItemQueryService::INCLUDE_LOG_INFO;
290 if ( $this->fld_tags ) {
291 $includeFields[] = WatchedItemQueryService::INCLUDE_TAGS;
293 return $includeFields;
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] ) );
317 $title = Title::newFromLinkTarget( $target );
319 $title = Title::castFromPageIdentity( $target );
325 $type = (int)$recentChangeInfo[
'rc_type'];
326 $vals[
'type'] = RecentChange::parseFromRCType(
$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 ) {
346 if ( $this->fld_ids ) {
347 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
348 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
349 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
355 if ( $this->fld_user || $this->fld_userid ) {
356 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
357 $vals[
'userhidden'] =
true;
360 if ( RevisionRecord::userCanBitfield(
361 $recentChangeInfo[
'rc_deleted'],
362 RevisionRecord::DELETED_USER,
365 if ( $this->fld_userid ) {
366 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
368 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
371 if ( $this->fld_user ) {
372 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
375 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
380 if ( $this->fld_flags ) {
381 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
382 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
383 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
387 if ( $this->fld_sizes ) {
388 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
389 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
393 if ( $this->fld_timestamp ) {
394 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
397 if ( $this->fld_notificationtimestamp ) {
404 if ( $this->fld_comment || $this->fld_parsedcomment ) {
405 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
406 $vals[
'commenthidden'] =
true;
409 if ( RevisionRecord::userCanBitfield(
410 $recentChangeInfo[
'rc_deleted'],
411 RevisionRecord::DELETED_COMMENT,
414 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
415 if ( $this->fld_comment ) {
416 $vals[
'comment'] = $comment;
419 if ( $this->fld_parsedcomment ) {
426 if ( $this->fld_patrol ) {
427 $vals[
'patrolled'] = $recentChangeInfo[
'rc_patrolled'] != RecentChange::PRC_UNPATROLLED;
428 $vals[
'unpatrolled'] = ChangesList::isUnpatrolled( (
object)$recentChangeInfo, $user );
429 $vals[
'autopatrolled'] = $recentChangeInfo[
'rc_patrolled'] == RecentChange::PRC_AUTOPATROLLED;
432 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
434 $vals[
'actionhidden'] =
true;
437 if ( LogEventsList::userCanBitfield(
438 $recentChangeInfo[
'rc_deleted'],
442 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
443 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
444 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
447 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
448 $vals[
'logdisplay'] = $logFormatter->getActionText();
452 if ( $this->fld_tags ) {
453 if ( $recentChangeInfo[
'rc_tags'] ) {
454 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
455 ApiResult::setIndexedTagName( $tags,
'tag' );
456 $vals[
'tags'] = $tags;
462 if ( $this->fld_expiry ) {
464 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
465 $vals[
'expiry'] = ( $expiry ?? false );
468 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
469 $vals[
'suppressed'] =
true;
472 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
473 $this, $watchedItem, $recentChangeInfo, $vals );
493 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
497 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
529 'notificationtimestamp',
538 WatchedItemQueryService::FILTER_MINOR,
539 WatchedItemQueryService::FILTER_NOT_MINOR,
540 WatchedItemQueryService::FILTER_BOT,
541 WatchedItemQueryService::FILTER_NOT_BOT,
542 WatchedItemQueryService::FILTER_ANON,
543 WatchedItemQueryService::FILTER_NOT_ANON,
544 WatchedItemQueryService::FILTER_PATROLLED,
545 WatchedItemQueryService::FILTER_NOT_PATROLLED,
546 WatchedItemQueryService::FILTER_AUTOPATROLLED,
547 WatchedItemQueryService::FILTER_NOT_AUTOPATROLLED,
548 WatchedItemQueryService::FILTER_UNREAD,
549 WatchedItemQueryService::FILTER_NOT_UNREAD,
560 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
574 'action=query&list=watchlist'
575 =>
'apihelp-query+watchlist-example-simple',
576 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
577 =>
'apihelp-query+watchlist-example-props',
578 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
579 =>
'apihelp-query+watchlist-example-expiry',
580 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
581 =>
'apihelp-query+watchlist-example-allrev',
582 'action=query&generator=watchlist&prop=info'
583 =>
'apihelp-query+watchlist-example-generator',
584 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
585 =>
'apihelp-query+watchlist-example-generator-rev',
586 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
587 =>
'apihelp-query+watchlist-example-wlowner',
592 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getWatchlistUser( $params)
Gets the user for whom to get the watchlist.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
This query action allows clients to retrieve a list of recently modified pages that are part of the l...
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, WatchedItemQueryService $watchedItemQueryService, Language $contentLanguage, NamespaceInfo $namespaceInfo, GenderCache $genderCache)
Language $contentLanguage
run( $resultPageSet=null)
$fld_notificationtimestamp
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
extractOutputData(WatchedItem $watchedItem, array $recentChangeInfo)
showParamsConflicting(array $show)
CommentStore $commentStore
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
NamespaceInfo $namespaceInfo
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
WatchedItemQueryService $watchedItemQueryService
This is the main query class.
Caches user genders when needed to use correct namespace aliases.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Representation of a pair of user and title for watchlist entries.
getExpiry(?int $style=TS_MW)
When the watched item will expire.
getNotificationTimestamp()
Get the notification timestamp of this entry.