MediaWiki fundraising/REL1_35
WatchAction Class Reference

Page addition to a user's watchlist. More...

Inheritance diagram for WatchAction:
Collaboration diagram for WatchAction:

Public Member Functions

 __construct (Page $page, IContextSource $context=null)
 Only public since 1.21.
 
 doesWrites ()
 Stable to override.
 
 getName ()
 Return the name of the action this object responds to.
 
 onSubmit ( $data)
 Process the form on POST submission.
 
 onSuccess ()
 Show one of 8 possible success messages.
 
 requiresUnblock ()
 Whether this action can still be executed by a blocked user.
 
- Public Member Functions inherited from FormAction
 show ()
 The basic pattern for actions is to display some sort of HTMLForm UI, maybe with some stuff underneath (history etc); to do some processing on submission of that form (delete, protect, etc) and to do something exciting on 'success', be that display something new or redirect to somewhere.
 
- Public Member Functions inherited from Action
 addHelpLink ( $to, $overrideBaseUrl=false)
 Adds help link with an icon via page indicators.
 
 getArticle ()
 Get a Article object.
 
 getContext ()
 Get the IContextSource in use here.
 
 getLanguage ()
 Shortcut to get the user Language being used for this instance.
 
 getOutput ()
 Get the OutputPage being used for this instance.
 
 getRequest ()
 Get the WebRequest being used for this instance.
 
 getRestriction ()
 Get the permission required to perform this action.
 
 getSkin ()
 Shortcut to get the Skin being used for this instance.
 
 getTitle ()
 Shortcut to get the Title object from the page.
 
 getUser ()
 Shortcut to get the User being used for this instance.
 
 getWikiPage ()
 Get a WikiPage object.
 
 msg ( $key,... $params)
 Get a Message object with context set Parameters are the same as wfMessage()
 
 needsReadRights ()
 Indicates whether this action requires read rights.
 
 requiresWrite ()
 Whether this action requires the wiki not to be locked.
 

Static Public Member Functions

static doUnwatch (Title $title, User $user)
 Unwatch a page.
 
static doWatch (Title $title, User $user, $checkRights=User::CHECK_USER_RIGHTS, ?string $expiry=null)
 Watch a page.
 
static doWatchOrUnwatch ( $watch, Title $title, User $user, string $expiry=null)
 Watch or unwatch a page.
 
static getExpiryOptions (MessageLocalizer $msgLocalizer, $watchedItem)
 Get options and default for a watchlist expiry select list.
 
static getWatchToken (Title $title, User $user, $action='watch')
 Get token to watch (or unwatch) a page for a user.
 
- Static Public Member Functions inherited from Action
static exists (string $name)
 Check if a given action is recognised, even if it's disabled.
 
static factory (?string $action, Page $article, IContextSource $context=null)
 Get an appropriate Action subclass for the given action.
 
static getActionName (IContextSource $context)
 Get the action that will be executed, not necessarily the one passed passed through the "action" request parameter.
 

Protected Member Functions

 alterForm (HTMLForm $form)
 Play with the HTMLForm if you need to more substantially Stable to override.
 
 checkCanExecute (User $user)
 Checks if the given user (identified by an object) can perform this action.
 
 getDescription ()
 Returns the description that goes below the \<h1\> tag.
 
 getFormFields ()
 Get an HTMLForm descriptor array Stable to override.
 
 usesOOUI ()
 Whether the form should use OOUI Stable to override.
 
- Protected Member Functions inherited from FormAction
 getForm ()
 Get the HTMLForm to control behavior Stable to override.
 
 postText ()
 Stable to override.
 
 preText ()
 Add pre- or post-text to the form Stable to override.
 
- Protected Member Functions inherited from Action
 getHookContainer ()
 
 getHookRunner ()
 
 getPageTitle ()
 Returns the name that goes in the \<h1\> page title.
 
 setHeaders ()
 Set output headers for noindexing etc.
 
 useTransactionalTimeLimit ()
 Call wfTransactionalTimeLimit() if this request was POSTed.
 

Protected Attributes

string $expiryFormFieldName = 'expiry'
 
false WatchedItem $watchedItem = false
 
bool $watchlistExpiry
 The value of the $wgWatchlistExpiry configuration variable.
 
- Protected Attributes inherited from Action
IContextSource $context
 IContextSource if specified; otherwise we'll use the Context from the Page.
 
array $fields
 The fields used to create the HTMLForm.
 
WikiPage Article ImagePage CategoryPage Page $page
 Page on which we're performing the action.
 

Static Private Member Functions

static getExpiryOptionsFromMessage (MessageLocalizer $msgLocalizer, ?string $lang=null)
 Parse expiry options message.
 

Detailed Description

Page addition to a user's watchlist.

Definition at line 31 of file WatchAction.php.

Constructor & Destructor Documentation

◆ __construct()

WatchAction::__construct ( Page $page,
IContextSource $context = null )

Only public since 1.21.

Parameters
Page$page
IContextSource | null$context

Reimplemented from Action.

Definition at line 48 of file WatchAction.php.

References Action\$context, Action\$page, Action\getContext(), Action\getTitle(), and Action\getUser().

Member Function Documentation

◆ alterForm()

WatchAction::alterForm ( HTMLForm $form)
protected

Play with the HTMLForm if you need to more substantially Stable to override.

Parameters
HTMLForm$form

Reimplemented from FormAction.

Reimplemented in UnwatchAction.

Definition at line 179 of file WatchAction.php.

References HTMLForm\setSubmitTextMsg(), HTMLForm\setTokenSalt(), and HTMLForm\setWrapperLegendMsg().

◆ checkCanExecute()

WatchAction::checkCanExecute ( User $user)
protected

Checks if the given user (identified by an object) can perform this action.

Can be overridden by sub-classes with more complicated permissions schemes. Failures here must throw subclasses of ErrorPageError

Since
1.17 Stable to override
Parameters
User$user
Exceptions
UserBlockedError|ReadOnlyError|PermissionsError

Reimplemented from Action.

Definition at line 78 of file WatchAction.php.

References User\isAnon().

◆ doesWrites()

WatchAction::doesWrites ( )

Stable to override.

Returns
bool

Reimplemented from FormAction.

Reimplemented in UnwatchAction.

Definition at line 355 of file WatchAction.php.

◆ doUnwatch()

static WatchAction::doUnwatch ( Title $title,
User $user )
static

Unwatch a page.

Since
1.22 Returns Status
Parameters
Title$titlePage to watch/unwatch
User$userUser who is watching/unwatching
Returns
Status

Definition at line 319 of file WatchAction.php.

References $title, getPermissionManager(), and User\removeWatch().

Referenced by UnwatchAction\onSubmit(), and ApiWatch\watchTitle().

◆ doWatch()

static WatchAction::doWatch ( Title $title,
User $user,
$checkRights = User::CHECK_USER_RIGHTS,
?string $expiry = null )
static

Watch a page.

Since
1.22 Returns Status, $checkRights parameter added
Parameters
Title$titlePage to watch/unwatch
User$userUser who is watching/unwatching
bool$checkRightsPassed through to $user->addWatch() Pass User::CHECK_USER_RIGHTS or User::IGNORE_USER_RIGHTS.
string | null$expiryOptional expiry timestamp in any format acceptable to wfTimestamp(), null will not create expiries, or leave them unchanged should they already exist.
Returns
Status

Definition at line 289 of file WatchAction.php.

References $title, and User\addWatch().

Referenced by UploadBase\performUpload(), SpecialBlock\processForm(), and ApiWatch\watchTitle().

◆ doWatchOrUnwatch()

static WatchAction::doWatchOrUnwatch ( $watch,
Title $title,
User $user,
string $expiry = null )
static

Watch or unwatch a page.

Since
1.22
1.35 New $expiry parameter.
Parameters
bool$watchWhether to watch or unwatch the page
Title$titlePage to watch/unwatch
User$userUser who is watching/unwatching
string | null$expiryOptional expiry timestamp in any format acceptable to wfTimestamp(), null will not create expiries, or leave them unchanged should they already exist.
Returns
Status

Definition at line 241 of file WatchAction.php.

References $title, and User\isLoggedIn().

Referenced by Article\delete(), MovePageForm\doSubmit(), FileDeleteForm\execute(), onSubmit(), ProtectionForm\save(), and EditPage\updateWatchlist().

◆ getDescription()

WatchAction::getDescription ( )
protected

Returns the description that goes below the \<h1\> tag.

Since
1.17 Stable to override
Returns
string HTML

Reimplemented from Action.

Definition at line 67 of file WatchAction.php.

◆ getExpiryOptions()

static WatchAction::getExpiryOptions ( MessageLocalizer $msgLocalizer,
$watchedItem )
static

Get options and default for a watchlist expiry select list.

If an expiry time is provided, it will be added to the top of the list as 'x days left'.

Since
1.35
Todo
Move this somewhere better when it's being used in more than just this action.
Parameters
MessageLocalizer$msgLocalizer
WatchedItem | bool$watchedItem
Returns
mixed[] With keys options (string[]) and default (string).

Definition at line 128 of file WatchAction.php.

References $watchedItem, WatchedItem\getExpiry(), WatchedItem\getExpiryInDaysText(), and getExpiryOptionsFromMessage().

Referenced by EditPage\getCheckboxesDefinitionForWatchlist().

◆ getExpiryOptionsFromMessage()

static WatchAction::getExpiryOptionsFromMessage ( MessageLocalizer $msgLocalizer,
?string $lang = null )
staticprivate

Parse expiry options message.

Fallback to english options if translated options are invalid or broken

Parameters
MessageLocalizer$msgLocalizer
string | null$lang
Returns
string[]

Definition at line 154 of file WatchAction.php.

Referenced by getExpiryOptions().

◆ getFormFields()

WatchAction::getFormFields ( )
protected

Get an HTMLForm descriptor array Stable to override.

Returns
array

Reimplemented from FormAction.

Reimplemented in UnwatchAction.

Definition at line 91 of file WatchAction.php.

References Action\getContext(), and Action\msg().

◆ getName()

WatchAction::getName ( )

Return the name of the action this object responds to.

Since
1.17
Returns
string Lowercase name

Reimplemented from Action.

Reimplemented in UnwatchAction.

Definition at line 59 of file WatchAction.php.

◆ getWatchToken()

static WatchAction::getWatchToken ( Title $title,
User $user,
$action = 'watch' )
static

Get token to watch (or unwatch) a page for a user.

Parameters
Title$titleTitle object of page to watch
User$userUser for whom the action is going to be performed
string$actionOptionally override the action to 'unwatch'
Returns
string Token
Since
1.18

Definition at line 347 of file WatchAction.php.

References User\getEditToken().

◆ onSubmit()

WatchAction::onSubmit ( $data)

Process the form on POST submission.

If you don't want to do anything with the form, just return false here.

This method will be passed to the HTMLForm as a submit callback (see HTMLForm::setSubmitCallback) and must return as documented for HTMLForm::trySubmit.

See also
HTMLForm::setSubmitCallback()
HTMLForm::trySubmit()
Parameters
array$data
Returns
bool|string|array|Status Must return as documented for HTMLForm::trySubmit

Reimplemented from FormAction.

Reimplemented in UnwatchAction.

Definition at line 71 of file WatchAction.php.

References doWatchOrUnwatch(), Action\getRequest(), Action\getTitle(), and Action\getUser().

◆ onSuccess()

WatchAction::onSuccess ( )

Show one of 8 possible success messages.

The messages are:

  1. addedwatchtext
  2. addedwatchtext-talk
  3. addedwatchindefinitelytext
  4. addedwatchindefinitelytext-talk
  5. addedwatchexpirytext
  6. addedwatchexpirytext-talk
  7. addedwatchexpiryhours
  8. addedwatchexpiryhours-talk

Reimplemented from FormAction.

Reimplemented in UnwatchAction.

Definition at line 199 of file WatchAction.php.

References getContext(), getTitle(), and wfIsInfinity().

◆ requiresUnblock()

WatchAction::requiresUnblock ( )

Whether this action can still be executed by a blocked user.

Since
1.17 Stable to override
Returns
bool

Reimplemented from Action.

Definition at line 63 of file WatchAction.php.

◆ usesOOUI()

WatchAction::usesOOUI ( )
protected

Whether the form should use OOUI Stable to override.

Returns
bool

Reimplemented from FormAction.

Definition at line 87 of file WatchAction.php.

Member Data Documentation

◆ $expiryFormFieldName

string WatchAction::$expiryFormFieldName = 'expiry'
protected

Definition at line 37 of file WatchAction.php.

◆ $watchedItem

false WatchedItem WatchAction::$watchedItem = false
protected

Definition at line 40 of file WatchAction.php.

Referenced by getExpiryOptions().

◆ $watchlistExpiry

bool WatchAction::$watchlistExpiry
protected

The value of the $wgWatchlistExpiry configuration variable.

Definition at line 34 of file WatchAction.php.


The documentation for this class was generated from the following file: