24 private $watchlistExpiryEnabled;
27 private $watchlistMaxDuration;
30 private $watchlistManager;
33 private $userOptionsLookup;
35 private function initServices() {
36 if ( $this->watchlistManager !==
null && $this->userOptionsLookup !==
null ) {
40 $services = MediaWikiServices::getInstance();
41 if ( $this->watchlistManager ===
null ) {
42 $this->watchlistManager = $services->getWatchlistManager();
44 if ( $this->userOptionsLookup ===
null ) {
45 $this->userOptionsLookup = $services->getUserOptionsLookup();
60 if ( !$watchOptions ) {
71 ParamValidator::PARAM_DEFAULT =>
'preferences',
72 ParamValidator::PARAM_TYPE => $watchOptions,
76 if ( $this->watchlistExpiryEnabled ) {
77 $result[
'watchlistexpiry'] = [
78 ParamValidator::PARAM_TYPE =>
'expiry',
79 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
80 ExpiryDef::PARAM_USE_MAX =>
true,
100 ?
string $userOption =
null,
101 ?
string $expiry =
null
104 $this->watchlistManager->setWatch( $value, $user,
$title, $expiry );
120 ?
string $userOption =
null
122 $this->initServices();
123 $userWatching = $this->watchlistManager->isWatchedIgnoringRights( $user,
$title );
125 switch ( $watchlist ) {
134 if ( $userWatching ) {
138 if ( $user->
isBot() ) {
139 return $userWatching;
142 if ( $userOption ===
null ) {
143 return $this->userOptionsLookup->getBoolOption( $user,
'watchdefault' ) ||
144 $this->userOptionsLookup->getBoolOption( $user,
'watchcreations' ) &&
149 return $this->userOptionsLookup->getBoolOption( $user, $userOption );
153 return $userWatching;
163 $watchlistExpiry = null;
164 if ( $this->watchlistExpiryEnabled && isset( $params[
'watchlistexpiry'] ) ) {
165 $watchlistExpiry = ApiResult::formatExpiry( $params[
'watchlistexpiry'] );
168 return $watchlistExpiry;
184 $watchedItem = $store->getWatchedItem( $user,
$title );
186 if ( $watchedItem ) {
187 $expiry = $watchedItem->getExpiry();
189 if ( $expiry !==
null ) {
190 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.
Represents a title within MediaWiki.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...