X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Factions%2FFormAction.php;h=e94a18880ed434ed9cc0abada21cd1776ff577e2;hb=0295e7260bf52a1fc6c051ad010c40abd79e1721;hp=26f43cb0c25823af8fc2e63d70c692d032e7be6d;hpb=4d78d40d821227a9368e87306f447ffd3be5db88;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/actions/FormAction.php b/includes/actions/FormAction.php index 26f43cb0c2..e94a18880e 100644 --- a/includes/actions/FormAction.php +++ b/includes/actions/FormAction.php @@ -31,7 +31,10 @@ abstract class FormAction extends Action { * Get an HTMLForm descriptor array * @return array */ - abstract protected function getFormFields(); + protected function getFormFields() { + // Default to an empty form with just a submit button + return []; + } /** * Add pre- or post-text to the form @@ -63,33 +66,37 @@ abstract class FormAction extends Action { $this->fields = $this->getFormFields(); // Give hooks a chance to alter the form, adding extra fields or text etc - Hooks::run( 'ActionModifyFormFields', array( $this->getName(), &$this->fields, $this->page ) ); + Hooks::run( 'ActionModifyFormFields', [ $this->getName(), &$this->fields, $this->page ] ); $form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() ); - $form->setSubmitCallback( array( $this, 'onSubmit' ) ); + $form->setSubmitCallback( [ $this, 'onSubmit' ] ); + $title = $this->getTitle(); + $form->setAction( $title->getLocalURL( [ 'action' => $this->getName() ] ) ); // Retain query parameters (uselang etc) - $form->addHiddenField( 'action', $this->getName() ); // Might not be the same as the query string $params = array_diff_key( $this->getRequest()->getQueryValues(), - array( 'action' => null, 'title' => null ) + [ 'action' => null, 'title' => null ] ); - $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); + if ( $params ) { + $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); + } $form->addPreText( $this->preText() ); $form->addPostText( $this->postText() ); $this->alterForm( $form ); // Give hooks a chance to alter the form, adding extra fields or text etc - Hooks::run( 'ActionBeforeFormDisplay', array( $this->getName(), &$form, $this->page ) ); + Hooks::run( 'ActionBeforeFormDisplay', [ $this->getName(), &$form, $this->page ] ); return $form; } /** - * Process the form on POST submission. If you return false from getFormFields(), - * this will obviously never be reached. If you don't want to do anything with the - * form, just return false here + * Process the form on POST submission. + * + * If you don't want to do anything with the form, just return false here. + * * @param array $data * @return bool|array True for success, false for didn't-try, array of errors on failure */ @@ -120,4 +127,8 @@ abstract class FormAction extends Action { $this->onSuccess(); } } + + public function doesWrites() { + return true; + } }