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)
 Constructor. 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...
 
 msg ()
 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 ($name)
 Check if a given action is recognised, even if it's disabled. More...
 
static factory ($action, Page $page, 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...
 
 getPageTitle ()
 Returns the name that goes in the <h1> page title. More...
 
 setHeaders ()
 Set output headers for noindexing etc. 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 getClass ($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...
 

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. There is also the deprecated UnknownAction hook

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

Constructor & Destructor Documentation

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

Constructor.

Only public since 1.21

Parameters
Page$page
IContextSource$context

Definition at line 261 of file Action.php.

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

Member Function Documentation

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$userThe user to check, or null to use the context user
Exceptions
UserBlockedError|ReadOnlyError|PermissionsError

Definition at line 300 of file Action.php.

References User\getBlock(), getRestriction(), getTitle(), User\isBlocked(), requiresUnblock(), requiresWrite(), and wfReadOnly().

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

static Action::exists (   $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 161 of file Action.php.

References $name, and array().

Referenced by HistoryAction\fetchRevisions(), ActionTest\testActionExists(), ActionTest\testActionExists_doesNotRequireInstantiation(), ActionTest\testDisabledAction_exists(), and ActionTest\testNull_doesNotExist().

static Action::factory (   $action,
Page  $page,
IContextSource  $context = null 
)
staticfinal

Get an appropriate Action subclass for the given action.

Since
1.17
Parameters
string$action
Page$page
IContextSource$context
Returns
Action|bool|null False if the action is disabled, null if it is not recognised

Definition at line 92 of file Action.php.

References $context, and array().

Referenced by getActionName(), MediaWiki\performAction(), SkinTemplate\prepareQuickTemplate(), ActionTest\testActionFactory(), ActionTest\testDisabledAction_factoryReturnsFalse(), and ActionTest\testNull_canNotBeInstantiated().

static Action::getClass (   $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

Definition at line 64 of file Action.php.

References global.

Action::getDescription ( )
protected

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

Since
1.17
Returns
string

Definition at line 370 of file Action.php.

References getName(), and msg().

Referenced by setHeaders().

Action::getLanguage ( )
final
Action::getName ( )
abstract

Return the name of the action this object responds to.

Since
1.17
Returns
string Lowercase name

Referenced by CachedAction\getCacheKey(), getDescription(), and FormAction\getForm().

Action::getPageTitle ( )
protected

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

Returns
string

Definition at line 360 of file Action.php.

References getTitle().

Referenced by setHeaders().

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

Definition at line 287 of file Action.php.

Referenced by checkCanExecute().

Action::getSkin ( )
final

Shortcut to get the Skin being used for this instance.

Since
1.17
Returns
Skin

Definition at line 219 of file Action.php.

References getContext().

Action::requiresUnblock ( )

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

Since
1.17
Returns
bool

Definition at line 338 of file Action.php.

Referenced by checkCanExecute().

Action::requiresWrite ( )

Whether this action requires the wiki not to be locked.

Since
1.17
Returns
bool

Definition at line 328 of file Action.php.

Referenced by checkCanExecute().

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

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

Referenced by FormlessAction\show(), WatchAction\show(), PurgeAction\show(), and FormAction\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

Member Data Documentation

IContextSource Action::$context
protected

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

Since
1.17 $context

Definition at line 49 of file Action.php.

Referenced by __construct(), factory(), getActionName(), and getContext().

array Action::$fields
protected

The fields used to create the HTMLForm.

Since
1.17 $fields

Definition at line 55 of file Action.php.

WikiPage Article ImagePage CategoryPage Page Action::$page
protected

Page on which we're performing the action.

Since
1.17 $page

Definition at line 43 of file Action.php.

Referenced by __construct(), WatchAction\doUnwatch(), WatchAction\doWatch(), HistoryAction\getArticle(), InfoAction\getContributors(), CreditsAction\link(), and EditAction\show().


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