24 private $watchlistExpiryEnabled;
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',
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
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 );
152 return $userWatching;
155 return $userWatching;
165 $watchlistExpiry = null;
166 if ( $this->watchlistExpiryEnabled && isset( $params[
'watchlistexpiry'] ) ) {
167 $watchlistExpiry = ApiResult::formatExpiry( $params[
'watchlistexpiry'] );
170 return $watchlistExpiry;
186 $watchedItem = $store->getWatchedItem( $user,
$title );
188 if ( $watchedItem ) {
189 $expiry = $watchedItem->getExpiry();
191 if ( $expiry !==
null ) {
192 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.
string $watchlistMaxDuration
Relative maximum expiry.
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.
WatchlistManager $watchlistManager
UserOptionsLookup $userOptionsLookup
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...