27 private $watchlistExpiryEnabled;
30 private $watchlistMaxDuration;
35 private function initServices() {
37 if ( isset( $this->watchlistManager ) && isset( $this->userOptionsLookup ) ) {
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, $page, $expiry );
117 ?
string $userOption =
null
119 $this->initServices();
120 $userWatching = $this->watchlistManager->isWatchedIgnoringRights( $user, $page );
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' ) && !$page->
exists() );
145 return $this->userOptionsLookup->getBoolOption( $user, $userOption );
149 return $userWatching;
159 $watchlistExpiry = null;
160 if ( $this->watchlistExpiryEnabled && isset(
$params[
'watchlistexpiry'] ) ) {
161 $watchlistExpiry = ApiResult::formatExpiry(
$params[
'watchlistexpiry'] );
164 return $watchlistExpiry;
180 $watchedItem = $store->getWatchedItem( $user, $page );
182 if ( $watchedItem ) {
183 $expiry = $watchedItem->getExpiry();
185 if ( $expiry !==
null ) {
186 return ApiResult::formatExpiry( $expiry );
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, PageIdentity $page, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistExpiry(WatchedItemStoreInterface $store, PageIdentity $page, UserIdentity $user)
Get existing expiry from the database.
getWatchlistValue(string $watchlist, PageIdentity $page, User $user, ?string $userOption=null)
Return true if we're to watch the page, false if not.
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...
Interface for objects (potentially) representing an editable wiki page.
exists()
Checks if the page currently exists.