41 private $commentStore;
44 private $watchedItemQueryService;
47 private $contentLanguage;
50 private $namespaceInfo;
56 private $commentFormatter;
78 parent::__construct( $query, $moduleName,
'wl' );
79 $this->commentStore = $commentStore;
80 $this->watchedItemQueryService = $watchedItemQueryService;
81 $this->contentLanguage = $contentLanguage;
82 $this->namespaceInfo = $namespaceInfo;
83 $this->genderCache = $genderCache;
84 $this->commentFormatter = $commentFormatter;
92 $this->run( $resultPageSet );
102 private $fld_expiry =
false;
108 private function run( $resultPageSet =
null ) {
114 if ( $params[
'prop'] !==
null && $resultPageSet ===
null ) {
115 $prop = array_fill_keys( $params[
'prop'],
true );
117 $this->fld_ids = isset( $prop[
'ids'] );
118 $this->fld_title = isset( $prop[
'title'] );
119 $this->fld_flags = isset( $prop[
'flags'] );
120 $this->fld_user = isset( $prop[
'user'] );
121 $this->fld_userid = isset( $prop[
'userid'] );
122 $this->fld_comment = isset( $prop[
'comment'] );
123 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
124 $this->fld_timestamp = isset( $prop[
'timestamp'] );
125 $this->fld_sizes = isset( $prop[
'sizes'] );
126 $this->fld_patrol = isset( $prop[
'patrol'] );
127 $this->fld_notificationtimestamp = isset( $prop[
'notificationtimestamp'] );
128 $this->fld_loginfo = isset( $prop[
'loginfo'] );
129 $this->fld_tags = isset( $prop[
'tags'] );
130 $this->fld_expiry = isset( $prop[
'expiry'] );
132 if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
133 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'patrol' );
138 'dir' => $params[
'dir'] ===
'older'
143 if ( $resultPageSet ===
null ) {
144 $options[
'includeFields'] = $this->getFieldsToInclude();
146 $options[
'usedInGenerator'] =
true;
149 if ( $params[
'start'] ) {
150 $options[
'start'] = $params[
'start'];
152 if ( $params[
'end'] ) {
153 $options[
'end'] = $params[
'end'];
157 if ( $params[
'continue'] !==
null ) {
162 if ( $wlowner !== $user ) {
163 $options[
'watchlistOwner'] = $wlowner;
164 $options[
'watchlistOwnerToken'] = $params[
'token'];
167 if ( $params[
'namespace'] !==
null ) {
168 $options[
'namespaceIds'] = $params[
'namespace'];
171 if ( $params[
'allrev'] ) {
172 $options[
'allRevisions'] =
true;
175 if ( $params[
'show'] !==
null ) {
176 $show = array_fill_keys( $params[
'show'],
true );
179 if ( $this->showParamsConflicting( $show ) ) {
187 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
188 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
192 $options[
'filters'] = array_keys( $show );
195 if ( $params[
'type'] !==
null ) {
199 $options[
'rcTypes'] = $rcTypes;
201 }
catch ( Exception $e ) {
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 ) {
276 if ( $this->fld_user || $this->fld_userid || $this->fld_loginfo ) {
279 if ( $this->fld_user || $this->fld_loginfo ) {
282 if ( $this->fld_comment || $this->fld_parsedcomment ) {
285 if ( $this->fld_patrol ) {
289 if ( $this->fld_sizes ) {
292 if ( $this->fld_loginfo ) {
295 if ( $this->fld_tags ) {
298 return $includeFields;
301 private function showParamsConflicting( array $show ) {
318 private function extractOutputData(
WatchedItem $watchedItem, array $recentChangeInfo ) {
322 $title = Title::newFromLinkTarget( $target );
324 $title = Title::castFromPageIdentity( $target );
330 $type = (int)$recentChangeInfo[
'rc_type'];
335 if ( $this->fld_title || $this->fld_ids ) {
338 $vals[
'actionhidden'] =
true;
343 $recentChangeInfo[
'rc_deleted'],
348 if ( $this->fld_title ) {
352 if ( $this->fld_ids ) {
353 $vals[
'pageid'] = (int)$recentChangeInfo[
'rc_cur_id'];
354 $vals[
'revid'] = (int)$recentChangeInfo[
'rc_this_oldid'];
355 $vals[
'old_revid'] = (int)$recentChangeInfo[
'rc_last_oldid'];
361 if ( $this->fld_user || $this->fld_userid ) {
362 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_USER ) {
363 $vals[
'userhidden'] =
true;
366 if ( RevisionRecord::userCanBitfield(
367 $recentChangeInfo[
'rc_deleted'],
368 RevisionRecord::DELETED_USER,
371 if ( $this->fld_userid ) {
372 $vals[
'userid'] = (int)$recentChangeInfo[
'rc_user'];
374 $vals[
'user'] = (int)$recentChangeInfo[
'rc_user'];
377 if ( $this->fld_user ) {
378 $vals[
'user'] = $recentChangeInfo[
'rc_user_text'];
381 $vals[
'anon'] = !$recentChangeInfo[
'rc_user'];
386 if ( $this->fld_flags ) {
387 $vals[
'bot'] = (bool)$recentChangeInfo[
'rc_bot'];
388 $vals[
'new'] = $recentChangeInfo[
'rc_type'] ==
RC_NEW;
389 $vals[
'minor'] = (bool)$recentChangeInfo[
'rc_minor'];
393 if ( $this->fld_sizes ) {
394 $vals[
'oldlen'] = (int)$recentChangeInfo[
'rc_old_len'];
395 $vals[
'newlen'] = (int)$recentChangeInfo[
'rc_new_len'];
399 if ( $this->fld_timestamp ) {
400 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $recentChangeInfo[
'rc_timestamp'] );
403 if ( $this->fld_notificationtimestamp ) {
410 if ( $this->fld_comment || $this->fld_parsedcomment ) {
411 if ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_COMMENT ) {
412 $vals[
'commenthidden'] =
true;
415 if ( RevisionRecord::userCanBitfield(
416 $recentChangeInfo[
'rc_deleted'],
417 RevisionRecord::DELETED_COMMENT,
420 $comment = $this->commentStore->getComment(
'rc_comment', $recentChangeInfo )->text;
421 if ( $this->fld_comment ) {
422 $vals[
'comment'] = $comment;
425 if ( $this->fld_parsedcomment ) {
426 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment,
$title );
432 if ( $this->fld_patrol ) {
438 if ( $this->fld_loginfo && $recentChangeInfo[
'rc_type'] ==
RC_LOG ) {
440 $vals[
'actionhidden'] =
true;
444 $recentChangeInfo[
'rc_deleted'],
448 $vals[
'logid'] = (int)$recentChangeInfo[
'rc_logid'];
449 $vals[
'logtype'] = $recentChangeInfo[
'rc_log_type'];
450 $vals[
'logaction'] = $recentChangeInfo[
'rc_log_action'];
453 $vals[
'logparams'] = $logFormatter->formatParametersForApi();
454 $vals[
'logdisplay'] = $logFormatter->getActionText();
458 if ( $this->fld_tags ) {
459 if ( $recentChangeInfo[
'rc_tags'] ) {
460 $tags = explode(
',', $recentChangeInfo[
'rc_tags'] );
462 $vals[
'tags'] = $tags;
468 if ( $this->fld_expiry ) {
470 $expiry = $watchedItem->
getExpiry( TS_ISO_8601 );
471 $vals[
'expiry'] = ( $expiry ?? false );
474 if ( $anyHidden && ( $recentChangeInfo[
'rc_deleted'] & RevisionRecord::DELETED_RESTRICTED ) ) {
475 $vals[
'suppressed'] =
true;
478 $this->
getHookRunner()->onApiQueryWatchlistExtractOutputData(
479 $this, $watchedItem, $recentChangeInfo, $vals );
488 ParamValidator::PARAM_TYPE =>
'timestamp'
491 ParamValidator::PARAM_TYPE =>
'timestamp'
494 ParamValidator::PARAM_ISMULTI =>
true,
495 ParamValidator::PARAM_TYPE =>
'namespace'
498 ParamValidator::PARAM_TYPE =>
'user',
499 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
502 ParamValidator::PARAM_TYPE =>
'user',
503 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
506 ParamValidator::PARAM_DEFAULT =>
'older',
507 ParamValidator::PARAM_TYPE => [
514 ParamValidator::PARAM_DEFAULT => 10,
515 ParamValidator::PARAM_TYPE =>
'limit',
516 IntegerDef::PARAM_MIN => 1,
521 ParamValidator::PARAM_ISMULTI =>
true,
522 ParamValidator::PARAM_DEFAULT =>
'ids|title|flags',
524 ParamValidator::PARAM_TYPE => [
535 'notificationtimestamp',
542 ParamValidator::PARAM_ISMULTI =>
true,
543 ParamValidator::PARAM_TYPE => [
559 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
560 ParamValidator::PARAM_ISMULTI =>
true,
565 ParamValidator::PARAM_TYPE =>
'user',
566 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
569 ParamValidator::PARAM_TYPE =>
'string',
570 ParamValidator::PARAM_SENSITIVE =>
true,
580 'action=query&list=watchlist'
581 =>
'apihelp-query+watchlist-example-simple',
582 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment'
583 =>
'apihelp-query+watchlist-example-props',
584 'action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment|expiry'
585 =>
'apihelp-query+watchlist-example-expiry',
586 'action=query&list=watchlist&wlallrev=&wlprop=ids|title|timestamp|user|comment'
587 =>
'apihelp-query+watchlist-example-allrev',
588 'action=query&generator=watchlist&prop=info'
589 =>
'apihelp-query+watchlist-example-generator',
590 'action=query&generator=watchlist&gwlallrev=&prop=revisions&rvprop=timestamp|user'
591 =>
'apihelp-query+watchlist-example-generator-rev',
592 'action=query&list=watchlist&wlowner=Example&wltoken=123ABC'
593 =>
'apihelp-query+watchlist-example-wlowner',
598 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)
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.
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)
Caches user genders when needed to use correct namespace aliases.
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,...
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
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.