MediaWiki master
Action Class Reference

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

Inherits MessageLocalizer.

Inherited by FormAction, and FormlessAction.

Collaboration diagram for 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 this action may perform database writes.
 
 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 ()
 Whether this action requires the wiki not to be locked.
 
 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 51 of file Action.php.

Constructor & Destructor Documentation

◆ __construct()

Action::__construct ( Article  $article,
IContextSource  $context 
)

Only public since 1.21.

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

Reimplemented in DeleteAction, and MediaWiki\Actions\FileDeleteAction.

Definition at line 270 of file Action.php.

Member Function Documentation

◆ addHelpLink()

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 442 of file Action.php.

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

◆ checkCanExecute()

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, McrUndoAction, RevertAction, and WatchAction.

Definition at line 323 of file Action.php.

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

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

◆ doesWrites()

Action::doesWrites ( )

Indicates whether this action may perform database writes.

Returns
bool
Since
1.27
Stability: stable
to override

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

Definition at line 483 of file Action.php.

◆ factory()

static 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 88 of file Action.php.

References $context, and Article\getContext().

◆ getActionName()

static 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 107 of file Action.php.

References MediaWiki\Context\IContextSource\getActionName().

◆ getArticle()

Action::getArticle ( )

Get a Article object.

Since
1.35 Overriding this method is deprecated since 1.35
Returns
Article|ImagePage|CategoryPage

Definition at line 201 of file Action.php.

Referenced by MediaWiki\Actions\FileDeleteAction\__construct(), getContext(), FormAction\getForm(), HistoryAction\onView(), InfoAction\onView(), EditAction\show(), ProtectAction\show(), RenderAction\show(), UnprotectAction\show(), ViewAction\show(), and DeleteAction\tempDelete().

◆ getAuthority()

Action::getAuthority ( )
final

Shortcut to get the Authority executing this instance.

Returns
Authority
Since
1.39

Definition at line 161 of file Action.php.

Referenced by PurgeAction\onSubmit().

◆ getContext()

Action::getContext ( )
final

Get the IContextSource in use here.

Since
1.17
Returns
IContextSource

Definition at line 117 of file Action.php.

References getArticle(), and wfDebug().

Referenced by FormAction\getForm().

◆ getDescription()

Action::getDescription ( )
protected

Returns the description that goes below the <h1> element.

Since
1.17
Stability: stable
to override
Returns
string HTML

Reimplemented in CreditsAction, HistoryAction, InfoAction, MarkpatrolledAction, McrRestoreAction, McrUndoAction, PurgeAction, RevertAction, RollbackAction, and WatchAction.

Definition at line 430 of file Action.php.

◆ getHookContainer()

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

Definition at line 242 of file Action.php.

◆ getHookRunner()

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 255 of file Action.php.

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

◆ getLanguage()

Action::getLanguage ( )
final

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

Returns
Language

Definition at line 180 of file Action.php.

References getContext().

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

◆ getName()

Action::getName ( )
abstract

◆ getOutput()

◆ getPageTitle()

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 DeleteAction, MediaWiki\Actions\FileDeleteAction, HistoryAction, InfoAction, and RevertAction.

Definition at line 419 of file Action.php.

References getTitle().

◆ getRequest()

Action::getRequest ( )
final

Get the WebRequest being used for this instance.

Since
1.17
Returns
WebRequest

Definition at line 131 of file Action.php.

References getContext().

Referenced by MediaWiki\Actions\FileDeleteAction\__construct(), FormAction\getForm(), and PurgeAction\show().

◆ getRestriction()

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 DeleteAction, MarkpatrolledAction, McrUndoAction, RevertAction, RollbackAction, and WatchAction.

Definition at line 295 of file Action.php.

◆ getSkin()

Action::getSkin ( )
final

Shortcut to get the Skin being used for this instance.

Since
1.17
Returns
Skin

Definition at line 171 of file Action.php.

References getContext().

◆ getTitle()

Action::getTitle ( )
final

Shortcut to get the Title object from the page.

Since
1.17
Returns
Title

Definition at line 211 of file Action.php.

Referenced by MediaWiki\Actions\FileDeleteAction\__construct(), FormAction\getForm(), MediaWiki\Actions\FileDeleteAction\getPageTitle(), PurgeAction\onSuccess(), and EditAction\show().

◆ getUser()

Action::getUser ( )
final

Shortcut to get the User being used for this instance.

Since
1.17
Returns
User

Definition at line 151 of file Action.php.

References getContext().

Referenced by EditAction\show(), FormAction\show(), FormlessAction\show(), and PurgeAction\show().

◆ getWikiPage()

◆ msg()

◆ needsReadRights()

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

Definition at line 309 of file Action.php.

◆ requiresUnblock()

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 HistoryAction, InfoAction, RawAction, and WatchAction.

Definition at line 387 of file Action.php.

◆ requiresWrite()

Action::requiresWrite ( )

Whether this action requires the wiki not to be locked.

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 HistoryAction, InfoAction, and RawAction.

Definition at line 372 of file Action.php.

◆ setHeaders()

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 397 of file Action.php.

References wfDeprecated().

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

◆ setHookContainer()

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

Definition at line 232 of file Action.php.

◆ show()

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 DeleteAction, EditAction, FormAction, FormlessAction, McrUndoAction, ProtectAction, PurgeAction, RenderAction, RollbackAction, SubmitAction, UnprotectAction, and ViewAction.

◆ useTransactionalTimeLimit()

Action::useTransactionalTimeLimit ( )
protected

Call wfTransactionalTimeLimit() if this request was POSTed.

Since
1.26

Definition at line 471 of file Action.php.

References getRequest(), and wfTransactionalTimeLimit().

Referenced by RevertAction\onSubmit(), DeleteAction\show(), EditAction\show(), and McrUndoAction\show().

Member Data Documentation

◆ $context

IContextSource null Action::$context
protected

IContextSource if specified; otherwise we'll use the Context from the Page.

Since
1.17

Definition at line 64 of file Action.php.

Referenced by MediaWiki\Actions\FileDeleteAction\__construct(), factory(), and DeleteAction\tempDelete().

◆ $fields

array Action::$fields
protected

The fields used to create the HTMLForm.

Since
1.17

Definition at line 71 of file Action.php.

Referenced by HistoryAction\onView().


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