MediaWiki master
ApiWatchlistTrait.php File Reference

Go to the source code of this file.

Functions

 getExpiryFromParams (array $params)
 Get formatted expiry from the given parameters, or null if no expiry was provided.
 
 getWatchlistExpiry (WatchedItemStoreInterface $store, Title $title, UserIdentity $user)
 Get existing expiry from the database.
 
 getWatchlistParams (array $watchOptions=[])
 Get additional allow params specific to watchlisting.
 
 getWatchlistValue (string $watchlist, Title $title, User $user, ?string $userOption=null)
 Return true if we're to watch the page, false if not.
 
 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.
 

Variables

trait ApiWatchlistTrait
 An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a page.
 

Function Documentation

◆ getExpiryFromParams()

getExpiryFromParams ( array $params)
protected

Get formatted expiry from the given parameters, or null if no expiry was provided.

Parameters
array$paramsRequest parameters passed to the API.
Returns
string|null

Definition at line 157 of file ApiWatchlistTrait.php.

References $params.

Referenced by ApiBlock\execute(), ApiDelete\execute(), ApiEditPage\execute(), ApiMove\execute(), ApiProtect\execute(), ApiRollback\execute(), ApiUnblock\execute(), ApiUndelete\execute(), ApiUserrights\execute(), and ApiUpload\performUpload().

◆ getWatchlistExpiry()

getWatchlistExpiry ( WatchedItemStoreInterface $store,
Title $title,
UserIdentity $user )
protected

Get existing expiry from the database.

Parameters
WatchedItemStoreInterface$store
Title$title
UserIdentity$userThe user to get the expiry for.
Returns
string|null

Definition at line 174 of file ApiWatchlistTrait.php.

Referenced by ApiBlock\execute(), ApiEditPage\execute(), ApiUnblock\execute(), ApiUserrights\execute(), and ChangesList\getArticleLink().

◆ getWatchlistParams()

getWatchlistParams ( array $watchOptions = [])
protected

Get additional allow params specific to watchlisting.

This should be merged in with the result of self::getAllowedParams().

This purposefully does not include the deprecated 'watch' and 'unwatch' parameters that some APIs still accept.

Parameters
string[]$watchOptions
Returns
array

Definition at line 55 of file ApiWatchlistTrait.php.

Referenced by ApiDelete\getAllowedParams(), ApiEditPage\getAllowedParams(), ApiMove\getAllowedParams(), ApiProtect\getAllowedParams(), ApiRollback\getAllowedParams(), ApiUndelete\getAllowedParams(), and ApiUpload\getAllowedParams().

◆ getWatchlistValue()

getWatchlistValue ( string $watchlist,
Title $title,
User $user,
?string $userOption = null )
protected

Return true if we're to watch the page, false if not.

Parameters
string$watchlistValid values: 'watch', 'unwatch', 'preferences', 'nochange'
Title$titleThe page under consideration
User$userThe user get the value for.
string | null$userOptionThe user option to consider when $watchlist=preferences. If not set will use watchdefault always and watchcreations if $title doesn't exist.
Returns
bool

Definition at line 112 of file ApiWatchlistTrait.php.

References MediaWiki\Title\Title\exists(), and MediaWiki\User\User\isBot().

Referenced by ApiEditPage\execute(), and ApiUpload\performUpload().

◆ setWatch()

setWatch ( string $watch,
Title $title,
User $user,
?string $userOption = null,
?string $expiry = null )
protected

Set a watch (or unwatch) based the based on a watchlist parameter.

Parameters
string$watchValid values: 'watch', 'unwatch', 'preferences', 'nochange'
Title$titleThe article's title to change
User$userThe user to set watch/unwatch for
string | null$userOptionThe user option to consider when $watch=preferences
string | null$expiryOptional expiry timestamp in any format acceptable to wfTimestamp(), null will not create expiries, or leave them unchanged should they already exist.

Definition at line 92 of file ApiWatchlistTrait.php.

Referenced by ApiBlock\execute(), ApiDelete\execute(), ApiMove\execute(), ApiProtect\execute(), ApiRollback\execute(), ApiUnblock\execute(), ApiUndelete\execute(), and ApiUserrights\execute().