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;
74 $this->commentFormatter = $commentFormatter;
82 $this->run( $resultPageSet );
92 private $fld_expiry =
false;
98 private function run( $resultPageSet =
null ) {
104 if ( $params[
'prop'] !==
null && $resultPageSet ===
null ) {
105 $prop = array_fill_keys( $params[
'prop'],
true );
107 $this->fld_ids = isset( $prop[
'ids'] );
108 $this->fld_title = isset( $prop[
'title'] );
109 $this->fld_flags = isset( $prop[
'flags'] );
110 $this->fld_user = isset( $prop[
'user'] );
111 $this->fld_userid = isset( $prop[
'userid'] );
112 $this->fld_comment = isset( $prop[
'comment'] );
113 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
114 $this->fld_timestamp = isset( $prop[
'timestamp'] );
115 $this->fld_sizes = isset( $prop[
'sizes'] );
116 $this->fld_patrol = isset( $prop[
'patrol'] );
117 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
118 $this->fld_loginfo = isset( $prop[
'loginfo'] );
119 $this->fld_tags = isset( $prop[
'tags'] );
120 $this->fld_expiry = isset( $prop[
'expiry'] );
122 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
123 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
128 'dir' => $params[
'dir'] ===
'older'
133 if ( $resultPageSet ===
null ) {
134 $options[
'includeFields'] = $this->getFieldsToInclude();
136 $options[
'usedInGenerator'] =
true;
139 if ( $params[
'start'] ) {
140 $options[
'start'] = $params[
'start'];
142 if ( $params[
'end'] ) {
143 $options[
'end'] = $params[
'end'];
147 if ( $params[
'continue'] !==
null ) {
152 if ( $wlowner !== $user ) {
153 $options[
'watchlistOwner'] = $wlowner;
154 $options[
'watchlistOwnerToken'] = $params[
'token'];
157 if ( $params[
'namespace'] !==
null ) {
158 $options[
'namespaceIds'] = $params[
'namespace'];
161 if ( $params[
'allrev'] ) {
162 $options[
'allRevisions'] =
true;
165 if ( $params[
'show'] !==
null ) {
166 $show = array_fill_keys( $params[
'show'],
true );
169 if ( $this->showParamsConflicting( $show ) ) {
177 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
178 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
182 $options[
'filters'] = array_keys( $show );
185 if ( $params[
'type'] !==
null ) {
189 $options[
'rcTypes'] = $rcTypes;
191 }
catch ( Exception $e ) {
197 if ( $params[
'user'] !==
null ) {
198 $options[
'onlyByUser'] = $params[
'user'];
200 if ( $params[
'excludeuser'] !==
null ) {
201 $options[
'notByUser'] = $params[
'excludeuser'];
204 $options[
'limit'] = $params[
'limit'];
206 $this->
getHookRunner()->onApiQueryWatchlistPrepareWatchedItemQueryServiceOptions(
207 $this, $params, $options );
210 $items = $this->watchedItemQueryService->getWatchedItemsWithRecentChangeInfo( $wlowner, $options, $startFrom );
213 if ( $items !== [] && $resultPageSet ===
null && $this->fld_title &&
214 $this->contentLanguage->needsGenderDistinction()
217 foreach ( $items as [ $watchedItem, ] ) {
219 $linkTarget = $watchedItem->getTarget();
220 if ( $this->namespaceInfo->hasGenderDistinction( $linkTarget->getNamespace() ) ) {
221 $usernames[] = $linkTarget->getText();
224 if ( $usernames !== [] ) {
225 $this->genderCache->doQuery( $usernames, __METHOD__ );
229 foreach ( $items as [ $watchedItem, $recentChangeInfo ] ) {
231 if ( $resultPageSet ===
null ) {
232 $vals = $this->extractOutputData( $watchedItem, $recentChangeInfo );
235 $startFrom = [ $recentChangeInfo[
'rc_timestamp'], $recentChangeInfo[
'rc_id'] ];
238 } elseif ( $params[
'allrev'] ) {
239 $ids[] = (int)$recentChangeInfo[
'rc_this_oldid'];
241 $ids[] = (int)$recentChangeInfo[
'rc_cur_id'];
245 if ( $startFrom !==
null ) {
249 if ( $resultPageSet ===
null ) {
254 } elseif ( $params[
'allrev'] ) {
255 $resultPageSet->populateFromRevisionIDs( $ids );
257 $resultPageSet->populateFromPageIDs( $ids );
261 private function getFieldsToInclude() {
263 if ( $this->fld_flags ) {
266 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
269 if ( $this->fld_user || $this->fld_loginfo ) {
272 if ( $this->fld_comment || $this->fld_parsedcomment ) {
275 if ( $this->fld_patrol ) {
279 if ( $this->fld_sizes ) {
282 if ( $this->fld_loginfo ) {
285 if ( $this->fld_tags ) {
288 return $includeFields;
291 private function showParamsConflicting( array $show ) {
308 private function extractOutputData(
WatchedItem $watchedItem, array $recentChangeInfo ) {
312 $title = Title::newFromLinkTarget( $target );
314 $title = Title::newFromPageIdentity( $target );
320 $type = (int)$recentChangeInfo[
'rc_type'];
325 if ( $this->fld_title || $this->fld_ids ) {
328 $vals[
'actionhidden'] =
true;
333 $recentChangeInfo[
'rc_deleted'],
338 if ( $this->fld_title ) {
341 if ( $this->fld_ids ) {
342 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
343 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
344 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
350 if ( $this->fld_user || $this->fld_userid ) {
351 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
352 $vals[
'userhidden'] =
true;
355 if ( RevisionRecord::userCanBitfield(
356 $recentChangeInfo[
'rc_deleted'],
357 RevisionRecord::DELETED_USER,
360 if ( $this->fld_userid ) {
361 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
363 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
366 if ( $this->fld_user ) {
367 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
370 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
375 if ( $this->fld_flags ) {
376 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
377 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
378 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
382 if ( $this->fld_sizes ) {
383 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
384 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
388 if ( $this->fld_timestamp ) {
389 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
392 if ( $this->fld_notificationtimestamp ) {
399 if ( $this->fld_comment || $this->fld_parsedcomment ) {
400 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
401 $vals[
'commenthidden'] =
true;
404 if ( RevisionRecord::userCanBitfield(
405 $recentChangeInfo[
'rc_deleted'],
406 RevisionRecord::DELETED_COMMENT,
409 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
410 if ( $this->fld_comment ) {
411 $vals[
'comment'] = $comment;
414 if ( $this->fld_parsedcomment ) {
415 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment, $title );
421 if ( $this->fld_patrol ) {
427 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
429 $vals[
'actionhidden'] =
true;
433 $recentChangeInfo[
'rc_deleted'],
437 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
438 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
439 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
442 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
443 $vals[
'logdisplay'] = $logFormatter->getActionText();
447 if ( $this->fld_tags ) {
448 if ( $recentChangeInfo[
'rc_tags'] ) {
449 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
451 $vals[
'tags'] = $tags;
457 if ( $this->fld_expiry ) {
459 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
460 $vals[
'expiry'] = ( $expiry ?? false );
463 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
464 $vals[
'suppressed'] =
true;
467 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
468 $this, $watchedItem, $recentChangeInfo, $vals );
477 ParamValidator::PARAM_TYPE =>
'timestamp'
480 ParamValidator::PARAM_TYPE =>
'timestamp'
483 ParamValidator::PARAM_ISMULTI =>
true,
484 ParamValidator::PARAM_TYPE =>
'namespace'
487 ParamValidator::PARAM_TYPE =>
'user',
488 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
491 ParamValidator::PARAM_TYPE =>
'user',
492 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
495 ParamValidator::PARAM_DEFAULT =>
'older',
496 ParamValidator::PARAM_TYPE => [
502 'newer' =>
'api-help-paramvalue-direction-newer',
503 'older' =>
'api-help-paramvalue-direction-older',
507 ParamValidator::PARAM_DEFAULT => 10,
508 ParamValidator::PARAM_TYPE =>
'limit',
509 IntegerDef::PARAM_MIN => 1,
514 ParamValidator::PARAM_ISMULTI =>
true,
515 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
517 ParamValidator::PARAM_TYPE => [
528 'notificationtimestamp',
535 ParamValidator::PARAM_ISMULTI =>
true,
536 ParamValidator::PARAM_TYPE => [
552 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
553 ParamValidator::PARAM_ISMULTI =>
true,
558 ParamValidator::PARAM_TYPE =>
'user',
559 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
562 ParamValidator::PARAM_TYPE =>
'string',
563 ParamValidator::PARAM_SENSITIVE =>
true,
573 'action=query&list=watchlist'
574 =>
'apihelp-query+watchlist-example-simple',
575 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
576 =>
'apihelp-query+watchlist-example-props',
577 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
578 =>
'apihelp-query+watchlist-example-expiry',
579 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
580 =>
'apihelp-query+watchlist-example-allrev',
581 'action=query&generator=watchlist&prop=info'
582 =>
'apihelp-query+watchlist-example-generator',
583 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
584 =>
'apihelp-query+watchlist-example-generator-rev',
585 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
586 =>
'apihelp-query+watchlist-example-wlowner',
591 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.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Dies if more than one parameter from a certain set of parameters are 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.
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...
$fld_notificationtimestamp
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, WatchedItemQueryService $watchedItemQueryService, Language $contentLanguage, NamespaceInfo $namespaceInfo, GenderCache $genderCache, CommentFormatter $commentFormatter)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
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.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static isUnpatrolled( $rc, User $user)
Look up "gender" user preference.
Base class for language-specific code.
static userCanBitfield( $bitfield, $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this log row,...
static parseToRCType( $type)
Parsing text to RC_* constants.
static getChangeTypes()
Get an array of all change types.
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
const INCLUDE_AUTOPATROL_INFO
const FILTER_NOT_AUTOPATROLLED
const INCLUDE_PATROL_INFO
const FILTER_AUTOPATROLLED
const FILTER_NOT_PATROLLED
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.