26 private $watchlistExpiryEnabled;
29 private $watchlistMaxDuration;
34 private function initServices() {
36 if ( isset( $this->watchlistManager ) && isset( $this->userOptionsLookup ) ) {
40 $services = MediaWikiServices::getInstance();
41 $this->watchlistManager ??= $services->getWatchlistManager();
42 $this->userOptionsLookup ??= $services->getUserOptionsLookup();
56 if ( !$watchOptions ) {
67 ParamValidator::PARAM_DEFAULT =>
'preferences',
68 ParamValidator::PARAM_TYPE => $watchOptions,
72 if ( $this->watchlistExpiryEnabled ) {
73 $result[
'watchlistexpiry'] = [
74 ParamValidator::PARAM_TYPE =>
'expiry',
75 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
76 ExpiryDef::PARAM_USE_MAX =>
true,
96 ?
string $userOption =
null,
97 ?
string $expiry =
null
100 $this->watchlistManager->setWatch( $value, $user, $title, $expiry );
116 ?
string $userOption =
null
118 $this->initServices();
119 $userWatching = $this->watchlistManager->isWatchedIgnoringRights( $user, $title );
121 switch ( $watchlist ) {
130 if ( $userWatching ) {
134 if ( $user->
isBot() ) {
135 return $userWatching;
138 if ( $userOption ===
null ) {
139 return $this->userOptionsLookup->getBoolOption( $user,
'watchdefault' ) ||
140 ( $this->userOptionsLookup->getBoolOption( $user,
'watchcreations' ) && !$title->
exists() );
144 return $this->userOptionsLookup->getBoolOption( $user, $userOption );
148 return $userWatching;
158 $watchlistExpiry = null;
159 if ( $this->watchlistExpiryEnabled && isset(
$params[
'watchlistexpiry'] ) ) {
160 $watchlistExpiry = ApiResult::formatExpiry(
$params[
'watchlistexpiry'] );
163 return $watchlistExpiry;
179 $watchedItem = $store->getWatchedItem( $user, $title );
181 if ( $watchedItem ) {
182 $expiry = $watchedItem->getExpiry();
184 if ( $expiry !==
null ) {
185 return ApiResult::formatExpiry( $expiry );
getWatchlistValue(string $watchlist, Title $title, User $user, ?string $userOption=null)
Return true if we're to watch the page, false if not.
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, Title $title, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistExpiry(WatchedItemStoreInterface $store, Title $title, UserIdentity $user)
Get existing expiry from the database.
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
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...