summaryrefslogtreecommitdiff
path: root/includes/Action.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
commit63601400e476c6cf43d985f3e7b9864681695ed4 (patch)
treef7846203a952e38aaf66989d0a4702779f549962 /includes/Action.php
parent8ff01378c9e0207f9169b81966a51def645b6a51 (diff)
Update to MediaWiki 1.20.2
this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/Action.php')
-rw-r--r--includes/Action.php64
1 files changed, 41 insertions, 23 deletions
diff --git a/includes/Action.php b/includes/Action.php
index 37c48488..51922251 100644
--- a/includes/Action.php
+++ b/includes/Action.php
@@ -1,15 +1,6 @@
<?php
/**
- * @defgroup Actions Action done on pages
- */
-
-/**
- * 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
- *
+ * Base classes for actions done on pages.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,23 +18,39 @@
*
* @file
*/
+
+/**
+ * @defgroup Actions Action done on pages
+ */
+
+/**
+ * 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 respresent these two groups.
+ */
abstract class Action {
/**
* Page on which we're performing the action
- * @var Page
+ * @var Page $page
*/
protected $page;
/**
* IContextSource if specified; otherwise we'll use the Context from the Page
- * @var IContextSource
+ * @var IContextSource $context
*/
protected $context;
/**
* The fields used to create the HTMLForm
- * @var Array
+ * @var Array $fields
*/
protected $fields;
@@ -78,7 +85,7 @@ abstract class Action {
* @param $action String
* @param $page Page
* @param $context IContextSource
- * @return Action|false|null false if the action is disabled, null
+ * @return Action|bool|null false if the action is disabled, null
* if it is not recognised
*/
public final static function factory( $action, Page $page, IContextSource $context = null ) {
@@ -128,7 +135,7 @@ abstract class Action {
if ( !$context->canUseWikiPage() ) {
return 'view';
}
-
+
$action = Action::factory( $actionName, $context->getWikiPage() );
if ( $action instanceof Action ) {
return $action->getName();
@@ -266,6 +273,7 @@ abstract class Action {
*
* @param $user User: the user to check, or null to use the context user
* @throws ErrorPageError
+ * @return bool True on success
*/
protected function checkCanExecute( User $user ) {
$right = $this->getRestriction();
@@ -277,7 +285,7 @@ abstract class Action {
}
if ( $this->requiresUnblock() && $user->isBlocked() ) {
- $block = $user->mBlock;
+ $block = $user->getBlock();
throw new UserBlockedError( $block );
}
@@ -287,6 +295,7 @@ abstract class Action {
if ( $this->requiresWrite() && wfReadOnly() ) {
throw new ReadOnlyError();
}
+ return true;
}
/**
@@ -332,7 +341,7 @@ abstract class Action {
* @return String
*/
protected function getDescription() {
- return wfMsgHtml( strtolower( $this->getName() ) );
+ return $this->msg( strtolower( $this->getName() ) )->escaped();
}
/**
@@ -350,6 +359,9 @@ abstract class Action {
public abstract function execute();
}
+/**
+ * An action which shows a form and does something based on the input from the form
+ */
abstract class FormAction extends Action {
/**
@@ -385,7 +397,7 @@ abstract class FormAction extends Action {
// Give hooks a chance to alter the form, adding extra fields or text etc
wfRunHooks( 'ActionModifyFormFields', array( $this->getName(), &$this->fields, $this->page ) );
- $form = new HTMLForm( $this->fields, $this->getContext() );
+ $form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() );
$form->setSubmitCallback( array( $this, 'onSubmit' ) );
// Retain query parameters (uselang etc)
@@ -444,8 +456,8 @@ abstract class FormAction extends Action {
/**
* @see Action::execute()
* @throws ErrorPageError
- * @param array|null $data
- * @param bool $captureErrors
+ * @param $data array|null
+ * @param $captureErrors bool
* @return bool
*/
public function execute( array $data = null, $captureErrors = true ) {
@@ -486,9 +498,7 @@ abstract class FormAction extends Action {
}
/**
- * 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).
+ * An action which just does something, without showing a form first.
*/
abstract class FormlessAction extends Action {
@@ -501,15 +511,23 @@ abstract class FormlessAction extends Action {
/**
* We don't want an HTMLForm
+ * @return bool
*/
protected function getFormFields() {
return false;
}
+ /**
+ * @param $data Array
+ * @return bool
+ */
public function onSubmit( $data ) {
return false;
}
+ /**
+ * @return bool
+ */
public function onSuccess() {
return false;
}