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. More...
 
 getWatchlistParams (array $watchOptions=[])
 Get additional allow params specific to watchlisting. More...
 
 getWatchlistValue (string $watchlist, Title $title, User $user, ?string $userOption=null)
 Return true if we're to watch the page, false if not. More...
 
 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. More...
 

Variables

string $watchlistMaxDuration
 Relative maximum expiry. More...
 
trait ApiWatchlistTrait
 An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a page. More...
 

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.

References ApiResult\formatExpiry().

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

◆ 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.

References $watchlistMaxDuration.

Referenced by ApiUndelete\getAllowedParams(), ApiRollback\getAllowedParams(), ApiProtect\getAllowedParams(), ApiDelete\getAllowedParams(), ApiMove\getAllowedParams(), ApiEditPage\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, User\getBoolOption(), User\IGNORE_USER_RIGHTS, and User\isWatched().

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

◆ 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.

References $title, WatchAction\doWatchOrUnwatch(), and getWatchlistValue().

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

Variable Documentation

◆ $watchlistMaxDuration

string $watchlistMaxDuration
private

Relative maximum expiry.

Definition at line 23 of file ApiWatchlistTrait.php.

Referenced by getWatchlistParams().