MediaWiki master
MediaWiki\Actions\Action Class Reference

Actions are things which can be done to pages (edit, delete, rollback, etc). More...

Inherits MessageLocalizer.

Inherited by MediaWiki\Actions\FormAction, and MediaWiki\Actions\FormlessAction.

Collaboration diagram for MediaWiki\Actions\Action:

Public Member Functions

 __construct (Article $article, IContextSource $context)
 Only public since 1.21.
 
 addHelpLink ( $to, $overrideBaseUrl=false)
 Adds help link with an icon via page indicators.
 
 doesWrites ()
 Indicates whether POST requests handled by this action require write access to the wiki.
 
 getArticle ()
 Get a Article object.
 
 getAuthority ()
 Shortcut to get the Authority executing this instance.
 
 getContext ()
 Get the IContextSource in use here.
 
 getLanguage ()
 Shortcut to get the user Language being used for this instance.
 
 getName ()
 Return the name of the action this object responds to.
 
 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.
 
 requiresUnblock ()
 Whether this action can still be executed by a blocked user.
 
 requiresWrite ()
 Indicates whether this action page write access to the wiki.
 
 setHookContainer (HookContainer $hookContainer)
 
 show ()
 The main action entry point.
 

Static Public Member Functions

static factory (string $action, Article $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

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

IContextSource null $context
 IContextSource if specified; otherwise we'll use the Context from the Page.
 
array $fields
 The fields used to create the HTMLForm.
 

Detailed Description

Actions are things which can be done to pages (edit, delete, rollback, etc).

They are distinct from Special Pages because an action must apply to exactly one page.

To add an action in an extension, create a subclass of Action, and add the key to $wgActions.

Actions generally fall into two groups: the show-a-form-then-do-something-with-the-input format (protect, delete, move, etc), and the just-do-something format (watch, rollback, patrol, etc). The FormAction and FormlessAction classes represent these two groups.

Stability: stable
to extend

Definition at line 66 of file Action.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Actions\Action::__construct ( Article $article,
IContextSource $context )

Only public since 1.21.

Stability: stable
to call
Parameters
Article$article
IContextSource$context

Reimplemented in MediaWiki\Actions\DeleteAction, and MediaWiki\Actions\FileDeleteAction.

Definition at line 287 of file Action.php.

Member Function Documentation

◆ addHelpLink()

MediaWiki\Actions\Action::addHelpLink ( $to,
$overrideBaseUrl = false )

Adds help link with an icon via page indicators.

Link target can be overridden by a local message containing a wikilink: the message key is: lowercase action name + '-helppage'.

Parameters
string$toTarget MediaWiki.org page title or encoded URL.
bool$overrideBaseUrlWhether $url is a full URL, to avoid MW.o.
Since
1.25

Definition at line 465 of file Action.php.

Referenced by MediaWiki\Actions\HistoryAction\onView(), MediaWiki\Actions\InfoAction\onView(), and MediaWiki\Actions\DeleteAction\show().

◆ checkCanExecute()

MediaWiki\Actions\Action::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
Stability: stable
to override
Parameters
User$user
Exceptions
UserBlockedError|ReadOnlyError|PermissionsError

Reimplemented in MediaWiki\Actions\FileDeleteAction, MediaWiki\Actions\McrUndoAction, MediaWiki\Actions\RevertAction, and MediaWiki\Actions\WatchAction.

Definition at line 340 of file Action.php.

References MediaWiki\User\User\getBlock(), and getTitle().

Referenced by MediaWiki\Actions\DeleteAction\show(), MediaWiki\Actions\FormAction\show(), MediaWiki\Actions\FormlessAction\show(), MediaWiki\Actions\PurgeAction\show(), and MediaWiki\Actions\RollbackAction\show().

◆ doesWrites()

MediaWiki\Actions\Action::doesWrites ( )

Indicates whether POST requests handled by this action require write access to the wiki.

Subclasses must override this method to return true if any of the operations that they perform on POST requests are not "safe" per RFC 7231 section 4.2.1. A subclass's operation is "safe" if it is essentially read-only, i.e. the client does not request nor expect any state change that would be observable in the responses to future requests.

Implementations of this method must always return the same value, regardless of the parameters passed to the constructor or system state.

When handling GET/HEAD requests, subclasses should only perform "safe" operations. Note that some subclasses might only perform "safe" operations even for POST requests, particularly in the case where large input parameters are required.

Returns
bool
Since
1.27
Stability: stable
to override

Reimplemented in MediaWiki\Actions\EditAction, MediaWiki\Actions\FormAction, MediaWiki\Actions\MarkpatrolledAction, MediaWiki\Actions\ProtectAction, MediaWiki\Actions\PurgeAction, MediaWiki\Actions\RevertAction, MediaWiki\Actions\RollbackAction, MediaWiki\Actions\UnprotectAction, MediaWiki\Actions\UnwatchAction, and MediaWiki\Actions\WatchAction.

Definition at line 519 of file Action.php.

◆ factory()

static MediaWiki\Actions\Action::factory ( string $action,
Article $article,
?IContextSource $context = null )
staticfinal

Get an appropriate Action subclass for the given action.

Since
1.17
Parameters
string$action
Article$article
IContextSource | null$contextFalls back to article's context
Returns
Action|false|null False if the action is disabled, null if it is not recognised

Definition at line 103 of file Action.php.

References MediaWiki\Actions\Action\$context, MediaWiki\Page\Article\getContext(), and MediaWiki\MediaWikiServices\getInstance().

◆ getActionName()

static MediaWiki\Actions\Action::getActionName ( IContextSource $context)
staticfinal

Get the action that will be executed, not necessarily the one passed passed through the "action" request parameter.

Actions disabled in $wgActions will be replaced by "nosuchaction".

Since
1.19
Parameters
IContextSource$context
Returns
string Action name

Definition at line 122 of file Action.php.

References MediaWiki\Actions\Action\$context, and MediaWiki\Context\IContextSource\getActionName().

◆ getArticle()

◆ getAuthority()

◆ getContext()

◆ getDescription()

MediaWiki\Actions\Action::getDescription ( )
protected

◆ getHookContainer()

MediaWiki\Actions\Action::getHookContainer ( )
protected
Since
1.35
Access: internal
since 1.37
Returns
HookContainer

Definition at line 259 of file Action.php.

◆ getHookRunner()

MediaWiki\Actions\Action::getHookRunner ( )
protected
Since
1.35
Access: internal
This is for use by core only. Hook interfaces may be removed without notice.
Returns
HookRunner

Definition at line 272 of file Action.php.

Referenced by MediaWiki\Actions\HistoryAction\getDescription(), MediaWiki\Actions\FormAction\getForm(), MediaWiki\Actions\HistoryAction\onView(), MediaWiki\Actions\InfoAction\onView(), MediaWiki\Actions\RawAction\onView(), and MediaWiki\Actions\EditAction\show().

◆ getLanguage()

MediaWiki\Actions\Action::getLanguage ( )
final

Shortcut to get the user Language being used for this instance.

Returns
Language

Definition at line 195 of file Action.php.

Referenced by MediaWiki\Actions\CreditsAction\getContributors(), MediaWiki\Actions\HistoryAction\getDescription(), MediaWiki\Actions\RevertAction\getFormFields(), and MediaWiki\Actions\RevertAction\onSuccess().

◆ getName()

◆ getOutput()

◆ getPageTitle()

MediaWiki\Actions\Action::getPageTitle ( )
protected

Returns the name that goes in the <h1> page title.

Since 1.41, returning a string from this method has been deprecated.

Stability: stable
to override
Returns
string|Message

Reimplemented in MediaWiki\Actions\DeleteAction, MediaWiki\Actions\FileDeleteAction, MediaWiki\Actions\HistoryAction, MediaWiki\Actions\InfoAction, and MediaWiki\Actions\RevertAction.

Definition at line 442 of file Action.php.

References getTitle().

◆ getRequest()

◆ getRestriction()

MediaWiki\Actions\Action::getRestriction ( )

Get the permission required to perform this action.

Often, but not always, the same as the action name

Implementations of this methods must always return the same value, regardless of parameters passed to the constructor or system state.

Since
1.17
Stability: stable
to override
Returns
string|null

Reimplemented in MediaWiki\Actions\DeleteAction, MediaWiki\Actions\MarkpatrolledAction, MediaWiki\Actions\McrUndoAction, MediaWiki\Actions\RevertAction, MediaWiki\Actions\RollbackAction, and MediaWiki\Actions\WatchAction.

Definition at line 312 of file Action.php.

◆ getSkin()

MediaWiki\Actions\Action::getSkin ( )
final

Shortcut to get the Skin being used for this instance.

Since
1.17
Returns
Skin

Definition at line 186 of file Action.php.

◆ getTitle()

◆ getUser()

◆ getWikiPage()

◆ msg()

MediaWiki\Actions\Action::msg ( $key,
$params )
final

Get a Message object with context set Parameters are the same as wfMessage()

Parameters
string | string[] | MessageSpecifier$key@phpcs:ignore Generic.Files.LineLength
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params See Message::params()
Returns
Message

Implements MessageLocalizer.

Definition at line 240 of file Action.php.

Referenced by MediaWiki\Actions\RevertAction\checkCanExecute(), MediaWiki\Actions\CreditsAction\getContributors(), MediaWiki\Actions\CreditsAction\getDescription(), MediaWiki\Actions\HistoryAction\getDescription(), MediaWiki\Actions\PurgeAction\getFormFields(), MediaWiki\Actions\RevertAction\getFormFields(), MediaWiki\Actions\RollbackAction\getFormFields(), MediaWiki\Actions\UnwatchAction\getFormFields(), MediaWiki\Actions\WatchAction\getFormFields(), MediaWiki\Actions\DeleteAction\getPageTitle(), MediaWiki\Actions\FileDeleteAction\getPageTitle(), MediaWiki\Actions\HistoryAction\getPageTitle(), MediaWiki\Actions\RevertAction\getPageTitle(), MediaWiki\Actions\RollbackAction\handleRollbackRequest(), MediaWiki\Actions\MarkpatrolledAction\onSubmit(), MediaWiki\Actions\CreditsAction\onView(), MediaWiki\Actions\HistoryAction\onView(), MediaWiki\Actions\InfoAction\onView(), MediaWiki\Actions\CreditsAction\othersLink(), MediaWiki\Actions\PurgeAction\postText(), MediaWiki\Actions\MarkpatrolledAction\preText(), MediaWiki\Actions\DeleteAction\tempDelete(), and MediaWiki\Actions\CreditsAction\userLink().

◆ needsReadRights()

MediaWiki\Actions\Action::needsReadRights ( )

Indicates whether this action requires read rights.

Implementations of this methods must always return the same value, regardless of parameters passed to the constructor or system state.

Since
1.38
Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\Actions\ViewAction.

Definition at line 326 of file Action.php.

◆ requiresUnblock()

MediaWiki\Actions\Action::requiresUnblock ( )

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

Implementations of this methods must always return the same value, regardless of parameters passed to the constructor or system state.

Since
1.17
Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\Actions\HistoryAction, MediaWiki\Actions\InfoAction, MediaWiki\Actions\RawAction, and MediaWiki\Actions\WatchAction.

Definition at line 410 of file Action.php.

◆ requiresWrite()

MediaWiki\Actions\Action::requiresWrite ( )

Indicates whether this action page write access to the wiki.

Subclasses must override this method to return true if the operation they will perform is not "safe" per RFC 7231 section 4.2.1. A subclass's operation is "safe" if it is essentially read-only, i.e. the client does not request nor expect any state change that would be observable in the responses to future requests.

Implementations of this method must always return the same value, regardless of the parameters passed to the constructor or system state.

When handling GET/HEAD requests, subclasses should only perform "safe" operations. Note that subclasses handling POST requests might still implement "safe" operations, particularly in the case where large input parameters are required.

Since
1.17
Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\Actions\HistoryAction, MediaWiki\Actions\InfoAction, and MediaWiki\Actions\RawAction.

Definition at line 395 of file Action.php.

◆ setHeaders()

MediaWiki\Actions\Action::setHeaders ( )
protected

Set output headers for noindexing etc.

This function will not be called through the execute() entry point, so only put UI-related stuff in here.

Stability: stable
to override
Since
1.17

Definition at line 420 of file Action.php.

References wfDeprecated().

Referenced by MediaWiki\Actions\DeleteAction\show(), MediaWiki\Actions\FormAction\show(), MediaWiki\Actions\FormlessAction\show(), MediaWiki\Actions\PurgeAction\show(), and MediaWiki\Actions\RollbackAction\show().

◆ setHookContainer()

MediaWiki\Actions\Action::setHookContainer ( HookContainer $hookContainer)
Since
1.40
Access: internal
For use by ActionFactory
Parameters
HookContainer$hookContainer

Definition at line 249 of file Action.php.

◆ show()

MediaWiki\Actions\Action::show ( )
abstract

The main action entry point.

Do all output for display and send it to the context output. Do not use globals $wgOut, $wgRequest, etc, in implementations; use $this->getOutput(), etc.

Since
1.17
Exceptions
ErrorPageError

Reimplemented in MediaWiki\Actions\DeleteAction, MediaWiki\Actions\EditAction, MediaWiki\Actions\FormAction, MediaWiki\Actions\FormlessAction, MediaWiki\Actions\McrUndoAction, MediaWiki\Actions\ProtectAction, MediaWiki\Actions\PurgeAction, MediaWiki\Actions\RenderAction, MediaWiki\Actions\RollbackAction, MediaWiki\Actions\SubmitAction, MediaWiki\Actions\UnprotectAction, and MediaWiki\Actions\ViewAction.

◆ useTransactionalTimeLimit()

MediaWiki\Actions\Action::useTransactionalTimeLimit ( )
protected

Member Data Documentation

◆ $context

◆ $fields

array MediaWiki\Actions\Action::$fields
protected

The fields used to create the HTMLForm.

Since
1.17

Definition at line 86 of file Action.php.

Referenced by MediaWiki\Actions\HistoryAction\onView().


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