FormAction extends ManagedAction
handlePost is now more naturally called and doesn't require a separate 'handle' function for each subclass.
This commit is contained in:
parent
b48e3a22bf
commit
23c288c699
|
@ -58,7 +58,8 @@ class Action extends HTMLOutputter // lawsuit
|
|||
protected $ajax = false;
|
||||
protected $menus = true;
|
||||
protected $needLogin = false;
|
||||
protected $needPost = false;
|
||||
protected $needPost = false; // implies canPost if true
|
||||
protected $canPost = false; // can this action handle POST method?
|
||||
|
||||
// The currently scoped profile (normally Profile::current; from $this->auth_user for API)
|
||||
protected $scoped = null;
|
||||
|
@ -143,6 +144,11 @@ class Action extends HTMLOutputter // lawsuit
|
|||
$this->clientError(_('This method requires a POST.'), 405);
|
||||
}
|
||||
|
||||
// needPost, of course, overrides canPost if true
|
||||
if (!$this->canPost) {
|
||||
$this->canPost = $this->needPost;
|
||||
}
|
||||
|
||||
$this->args = common_copy_args($args);
|
||||
|
||||
// This could be set with get_called_action and then
|
||||
|
|
|
@ -41,11 +41,12 @@ if (!defined('STATUSNET')) {
|
|||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class FormAction extends Action
|
||||
class FormAction extends ManagedAction
|
||||
{
|
||||
protected $form = null;
|
||||
protected $type = null;
|
||||
protected $needLogin = true;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function prepare(array $args=array()) {
|
||||
parent::prepare($args);
|
||||
|
@ -63,22 +64,6 @@ class FormAction extends Action
|
|||
return true;
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
parent::handle();
|
||||
|
||||
if ($this->isPost()) {
|
||||
try {
|
||||
$msg = $this->handlePost();
|
||||
$this->showForm($msg, true);
|
||||
} catch (Exception $e) {
|
||||
$this->showForm($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$this->showForm();
|
||||
}
|
||||
}
|
||||
|
||||
public function isReadOnly($args) {
|
||||
return !$this->isPost();
|
||||
}
|
||||
|
@ -113,22 +98,14 @@ class FormAction extends Action
|
|||
return null;
|
||||
}
|
||||
|
||||
public function showForm($msg=null, $success=false)
|
||||
{
|
||||
if ($success) {
|
||||
$this->msg = $msg;
|
||||
} else {
|
||||
$this->error = $msg;
|
||||
}
|
||||
$this->showPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called from handle() if isPost() is true;
|
||||
* @return void
|
||||
*/
|
||||
protected function handlePost()
|
||||
{
|
||||
parent::handlePost();
|
||||
|
||||
// check for this before token since all POST and FILES data
|
||||
// is losts when size is exceeded
|
||||
if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
|
||||
|
|
|
@ -39,6 +39,14 @@ class ManagedAction extends Action
|
|||
{
|
||||
parent::handle();
|
||||
|
||||
if ($this->canPost && $this->isPost()) {
|
||||
try {
|
||||
$this->msg = $this->handlePost();
|
||||
} catch (Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
if (StatusNet::isAjax()) {
|
||||
$this->showAjax();
|
||||
} else {
|
||||
|
@ -46,6 +54,11 @@ class ManagedAction extends Action
|
|||
}
|
||||
}
|
||||
|
||||
protected function handlePost()
|
||||
{
|
||||
// This will only be run if the Action has the property canPost==true
|
||||
}
|
||||
|
||||
public function showAjax()
|
||||
{
|
||||
$this->startHTML('text/xml;charset=utf-8');
|
||||
|
|
Loading…
Reference in New Issue
Block a user