MediaWiki REL1_35
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, User $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

string $watchlistMaxDuration
 Relative maximum expiry.
 
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 135 of file ApiWatchlistTrait.php.

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

◆ getWatchlistExpiry()

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

Get existing expiry from the database.

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

Definition at line 152 of file ApiWatchlistTrait.php.

Referenced by ApiEditPage\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 35 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 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 92 of file ApiWatchlistTrait.php.

References $title, and User\getBoolOption().

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 72 of file ApiWatchlistTrait.php.

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

Variable Documentation

◆ $watchlistMaxDuration

string $watchlistMaxDuration
private

Relative maximum expiry.

Definition at line 23 of file ApiWatchlistTrait.php.