MediaWiki  master
Action Class Reference

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

Inheritance diagram for Action:
Collaboration diagram for Action:

Public Member Functions

 __construct (Page $page, IContextSource $context=null)
 Only public since 1.21. More...
 
 addHelpLink ( $to, $overrideBaseUrl=false)
 Adds help link with an icon via page indicators. More...
 
 doesWrites ()
 Indicates whether this action may perform database writes. More...
 
 getArticle ()
 Get a Article object. More...
 
 getContext ()
 Get the IContextSource in use here. More...
 
 getLanguage ()
 Shortcut to get the user Language being used for this instance. More...
 
 getName ()
 Return the name of the action this object responds to. More...
 
 getOutput ()
 Get the OutputPage being used for this instance. More...
 
 getRequest ()
 Get the WebRequest being used for this instance. More...
 
 getRestriction ()
 Get the permission required to perform this action. More...
 
 getSkin ()
 Shortcut to get the Skin being used for this instance. More...
 
 getTitle ()
 Shortcut to get the Title object from the page. More...
 
 getUser ()
 Shortcut to get the User being used for this instance. More...
 
 getWikiPage ()
 Get a WikiPage object. More...
 
 msg ( $key,... $params)
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 requiresUnblock ()
 Whether this action can still be executed by a blocked user. More...
 
 requiresWrite ()
 Whether this action requires the wiki not to be locked. More...
 
 show ()
 The main action entry point. More...
 

Static Public Member Functions

static exists (string $name)
 Check if a given action is recognised, even if it's disabled. More...
 
static factory (?string $action, Page $article, IContextSource $context=null)
 Get an appropriate Action subclass for the given action. More...
 
static getActionName (IContextSource $context)
 Get the action that will be executed, not necessarily the one passed passed through the "action" request parameter. More...
 

Protected Member Functions

 checkCanExecute (User $user)
 Checks if the given user (identified by an object) can perform this action. More...
 
 getDescription ()
 Returns the description that goes below the \<h1\> tag. More...
 
 getHookContainer ()
 
 getHookRunner ()
 
 getPageTitle ()
 Returns the name that goes in the \<h1\> page title. More...
 
 setHeaders ()
 Set output headers for noindexing etc. More...
 
 useTransactionalTimeLimit ()
 Call wfTransactionalTimeLimit() if this request was POSTed. More...
 

Protected Attributes

IContextSource $context
 IContextSource if specified; otherwise we'll use the Context from the Page. More...
 
array $fields
 The fields used to create the HTMLForm. More...
 
WikiPage Article ImagePage CategoryPage Page $page
 Page on which we're performing the action. More...
 

Static Private Member Functions

static convertPageToArticle (Page $page, ?IContextSource $context, string $method)
 
static getClass (string $action, array $overrides)
 Get the Action subclass which should be used to handle this action, false if the action is disabled, or null if it's not recognised. More...
 

Private Attributes

Article $article
 

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.

Definition at line 41 of file Action.php.

Constructor & Destructor Documentation

◆ __construct()

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

Only public since 1.21.

Parameters
Article | WikiPage | Page$pageCalling with anything other then Article is deprecated since 1.35
IContextSource | null$context

Reimplemented in WatchAction.

Definition at line 338 of file Action.php.

References $context, $page, convertPageToArticle(), and wfWarn().

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

References getContext(), getOutput(), Skin\makeUrl(), and wfMessage().

Referenced by InfoAction\onView(), HistoryAction\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
Parameters
User$user
Exceptions
UserBlockedError|ReadOnlyError|PermissionsError

Reimplemented in McrUndoAction, WatchAction, and RevertAction.

Definition at line 405 of file Action.php.

References User\getBlock(), getLanguage(), getName(), getRequest(), getRestriction(), getTitle(), User\isBlockedFrom(), requiresUnblock(), requiresWrite(), and wfReadOnly().

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

◆ convertPageToArticle()

static Action::convertPageToArticle ( Page  $page,
?IContextSource  $context,
string  $method 
)
staticprivate

Definition at line 351 of file Action.php.

References $context, $page, RequestContext\getMain(), Article\newFromWikiPage(), and wfDeprecated().

Referenced by __construct().

◆ doesWrites()

Action::doesWrites ( )

Indicates whether this action may perform database writes.

Returns
bool
Since
1.27

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

Definition at line 536 of file Action.php.

◆ exists()

static Action::exists ( string  $name)
staticfinal

Check if a given action is recognised, even if it's disabled.

Since
1.17
Parameters
string$nameName of an action
Returns
bool

Definition at line 204 of file Action.php.

References getClass().

Referenced by MediaWiki\Permissions\PermissionManager\checkUserBlock(), HistoryAction\fetchRevisions(), HistoryAction\onView(), and InfoAction\pageInfo().

◆ factory()

static Action::factory ( ?string  $action,
Page  $article,
IContextSource  $context = null 
)
staticfinal

Get an appropriate Action subclass for the given action.

Since
1.17
Parameters
string | null$actionNull is hard-deprecated since 1.35
Article | WikiPage | Page$articleCalling with anything other than Article is hard-deprecated since 1.35
IContextSource | null$context
Returns
Action|bool|null False if the action is disabled, null if it is not recognised

Definition at line 113 of file Action.php.

References $article, $context, Article\getActionOverrides(), getClass(), and wfDeprecated().

Referenced by MediaWiki\Permissions\PermissionManager\checkUserBlock(), RebuildFileCache\execute(), getActionName(), SkinTemplate\getFooterLinks(), and MediaWiki\performAction().

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

References $context, $wgActions, IContextSource\canUseWikiPage(), factory(), IContextSource\getRequest(), IContextSource\getWikiPage(), and Article\newFromWikiPage().

Referenced by SkinTemplate\buildContentNavigationUrls(), MediaWiki\getAction(), OutputPage\getHeadLinksArray(), OutputPage\getJSVars(), OutputPage\headElement(), and SkinTemplate\wrapHTML().

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

References $article.

Referenced by CachedAction\getCacheKey(), getContext(), FormAction\getForm(), getWikiPage(), InfoAction\onView(), HistoryAction\onView(), InfoAction\pageInfo(), UnprotectAction\show(), DeleteAction\show(), EditAction\show(), ProtectAction\show(), RenderAction\show(), and ViewAction\show().

◆ getClass()

static Action::getClass ( string  $action,
array  $overrides 
)
staticfinalprivate

Get the Action subclass which should be used to handle this action, false if the action is disabled, or null if it's not recognised.

Parameters
string$action
array$overrides
Returns
bool|null|string|callable|Action

Definition at line 80 of file Action.php.

References $wgActions.

Referenced by exists(), and factory().

◆ getContext()

◆ getDescription()

Action::getDescription ( )
protected

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

Since
1.17
Returns
string HTML

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

Definition at line 486 of file Action.php.

References getName(), and msg().

Referenced by setHeaders().

◆ getHookContainer()

Action::getHookContainer ( )
protected
Since
1.35
Returns
HookContainer

Definition at line 317 of file Action.php.

Referenced by getHookRunner().

◆ getHookRunner()

Action::getHookRunner ( )
protected

◆ getLanguage()

◆ getName()

◆ getOutput()

◆ getPageTitle()

Action::getPageTitle ( )
protected

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

Returns
string

Reimplemented in InfoAction, RevertAction, and HistoryAction.

Definition at line 476 of file Action.php.

References getTitle().

Referenced by setHeaders().

◆ getRequest()

◆ getRestriction()

Action::getRestriction ( )

Get the permission required to perform this action.

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

Since
1.17
Returns
string|null

Reimplemented in RevertAction, MarkpatrolledAction, and RollbackAction.

Definition at line 392 of file Action.php.

Referenced by checkCanExecute().

◆ getSkin()

Action::getSkin ( )
final

Shortcut to get the Skin being used for this instance.

Since
1.17
Returns
Skin

Definition at line 257 of file Action.php.

References getContext().

◆ getTitle()

◆ getUser()

◆ getWikiPage()

◆ msg()

◆ requiresUnblock()

Action::requiresUnblock ( )

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

Since
1.17
Returns
bool

Reimplemented in WatchAction, SpecialPageAction, HistoryAction, InfoAction, RawAction, and PurgeAction.

Definition at line 454 of file Action.php.

Referenced by checkCanExecute().

◆ requiresWrite()

Action::requiresWrite ( )

Whether this action requires the wiki not to be locked.

Since
1.17
Returns
bool

Reimplemented in InfoAction, HistoryAction, and RawAction.

Definition at line 444 of file Action.php.

Referenced by checkCanExecute().

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

Since
1.17

Definition at line 463 of file Action.php.

References getDescription(), getOutput(), and getPageTitle().

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

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

◆ useTransactionalTimeLimit()

Action::useTransactionalTimeLimit ( )
protected

Call wfTransactionalTimeLimit() if this request was POSTed.

Since
1.26

Definition at line 525 of file Action.php.

References getRequest(), and wfTransactionalTimeLimit().

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

Member Data Documentation

◆ $article

Article Action::$article
private
Since
1.35

Definition at line 57 of file Action.php.

Referenced by factory(), getArticle(), and EditAction\show().

◆ $context

IContextSource 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 WatchAction\__construct(), __construct(), convertPageToArticle(), factory(), getActionName(), getContext(), and WatchAction\getExpiryOptions().

◆ $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().

◆ $page


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