handlePost is now more naturally called and doesn't require a separate
'handle' function for each subclass.
protected $ajax = false;
protected $menus = true;
protected $needLogin = false;
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;
// The currently scoped profile (normally Profile::current; from $this->auth_user for API)
protected $scoped = null;
$this->clientError(_('This method requires a POST.'), 405);
}
$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
$this->args = common_copy_args($args);
// This could be set with get_called_action and then
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
* @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 $form = null;
protected $type = null;
protected $needLogin = true;
+ protected $canPost = true;
protected function prepare(array $args=array()) {
parent::prepare($args);
protected function prepare(array $args=array()) {
parent::prepare($args);
- 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();
}
public function isReadOnly($args) {
return !$this->isPost();
}
- 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()
{
/**
* 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) {
// check for this before token since all POST and FILES data
// is losts when size is exceeded
if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
+ if ($this->canPost && $this->isPost()) {
+ try {
+ $this->msg = $this->handlePost();
+ } catch (Exception $e) {
+ $this->error = $e->getMessage();
+ }
+ }
+
if (StatusNet::isAjax()) {
$this->showAjax();
} else {
if (StatusNet::isAjax()) {
$this->showAjax();
} else {
+ 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');
public function showAjax()
{
$this->startHTML('text/xml;charset=utf-8');