<?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
*
* @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;
* @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 ) {
if ( !$context->canUseWikiPage() ) {
return 'view';
}
-
+
$action = Action::factory( $actionName, $context->getWikiPage() );
if ( $action instanceof Action ) {
return $action->getName();
*
* @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();
}
if ( $this->requiresUnblock() && $user->isBlocked() ) {
- $block = $user->mBlock;
+ $block = $user->getBlock();
throw new UserBlockedError( $block );
}
if ( $this->requiresWrite() && wfReadOnly() ) {
throw new ReadOnlyError();
}
+ return true;
}
/**
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 {
/**
/**
* @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 ) {
}
/**
- * 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 {
/**
* 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;
}