29 private $watchlistExpiryEnabled;
32 private $watchlistMaxDuration;
37 private function initServices() {
39 if ( isset( $this->watchlistManager ) && isset( $this->userOptionsLookup ) ) {
44 $this->watchlistManager ??= $services->getWatchlistManager();
45 $this->userOptionsLookup ??= $services->getUserOptionsLookup();
59 if ( !$watchOptions ) {
70 ParamValidator::PARAM_DEFAULT =>
'preferences',
71 ParamValidator::PARAM_TYPE => $watchOptions,
75 if ( $this->watchlistExpiryEnabled ) {
76 $result[
'watchlistexpiry'] = [
77 ParamValidator::PARAM_TYPE =>
'expiry',
78 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
79 ExpiryDef::PARAM_USE_MAX =>
true,
99 ?
string $userOption =
null,
100 ?
string $expiry =
null
103 $this->watchlistManager->setWatch( $value, $user, $page, $expiry );
119 ?
string $userOption =
null
121 $this->initServices();
122 $userWatching = $this->watchlistManager->isWatchedIgnoringRights( $user, $page );
124 switch ( $watchlist ) {
133 if ( $userWatching ) {
137 if ( $user->
isBot() ) {
138 return $userWatching;
141 if ( $userOption ===
null ) {
142 return $this->userOptionsLookup->getBoolOption( $user,
'watchdefault' ) ||
143 ( $this->userOptionsLookup->getBoolOption( $user,
'watchcreations' ) && !$page->
exists() );
147 return $this->userOptionsLookup->getBoolOption( $user, $userOption );
151 return $userWatching;
161 $watchlistExpiry = null;
162 if ( $this->watchlistExpiryEnabled && isset(
$params[
'watchlistexpiry'] ) ) {
166 return $watchlistExpiry;
182 $watchedItem = $store->getWatchedItem( $user, $page );
184 if ( $watchedItem ) {
185 $expiry = $watchedItem->getExpiry();
187 if ( $expiry !==
null ) {
197class_alias( ApiWatchlistTrait::class,
'ApiWatchlistTrait' );
array $params
The job parameters.
if(!defined('MW_SETUP_CALLBACK'))
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Interface for objects (potentially) representing an editable wiki page.
exists()
Checks if the page currently exists.