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

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 158 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,
PageIdentity $page,
UserIdentity $user )
protected

Get existing expiry from the database.

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

Definition at line 175 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 56 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,
PageIdentity $page,
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'
PageIdentity$pageThe 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 $page doesn't exist.
Returns
bool

Definition at line 113 of file ApiWatchlistTrait.php.

References MediaWiki\Page\PageIdentity\exists(), and MediaWiki\User\User\isBot().

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

◆ setWatch()

setWatch ( string $watch,
PageIdentity $page,
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'
PageIdentity$pageThe page 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 93 of file ApiWatchlistTrait.php.

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