25 private $watchlistExpiryEnabled;
28 private $watchlistMaxDuration;
31 private $watchlistManager;
34 private $userOptionsLookup;
36 private function initServices() {
37 if ( $this->watchlistManager !==
null && $this->userOptionsLookup !==
null ) {
41 $services = MediaWikiServices::getInstance();
42 $this->watchlistManager ??= $services->getWatchlistManager();
43 $this->userOptionsLookup ??= $services->getUserOptionsLookup();
57 if ( !$watchOptions ) {
68 ParamValidator::PARAM_DEFAULT =>
'preferences',
69 ParamValidator::PARAM_TYPE => $watchOptions,
73 if ( $this->watchlistExpiryEnabled ) {
74 $result[
'watchlistexpiry'] = [
75 ParamValidator::PARAM_TYPE =>
'expiry',
76 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
77 ExpiryDef::PARAM_USE_MAX =>
true,
97 ?
string $userOption =
null,
98 ?
string $expiry =
null
101 $this->watchlistManager->setWatch( $value, $user,
$title, $expiry );
117 ?
string $userOption =
null
119 $this->initServices();
120 $userWatching = $this->watchlistManager->isWatchedIgnoringRights( $user,
$title );
122 switch ( $watchlist ) {
131 if ( $userWatching ) {
135 if ( $user->
isBot() ) {
136 return $userWatching;
139 if ( $userOption ===
null ) {
140 return $this->userOptionsLookup->getBoolOption( $user,
'watchdefault' ) ||
141 $this->userOptionsLookup->getBoolOption( $user,
'watchcreations' ) &&
146 return $this->userOptionsLookup->getBoolOption( $user, $userOption );
150 return $userWatching;
160 $watchlistExpiry = null;
161 if ( $this->watchlistExpiryEnabled && isset( $params[
'watchlistexpiry'] ) ) {
162 $watchlistExpiry = ApiResult::formatExpiry( $params[
'watchlistexpiry'] );
165 return $watchlistExpiry;
181 $watchedItem = $store->getWatchedItem( $user,
$title );
183 if ( $watchedItem ) {
184 $expiry = $watchedItem->getExpiry();
186 if ( $expiry !==
null ) {
187 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.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...