FormSpecialPage: Only add redirectparams for POST forms

If the form is submitted via GET, using redirectparams doesn't make
sense, and you end up with redirect params being included in the GET
query string. And then if the form is submitted again, the
redirectparams include the previous redirectparams, and so on.

Change-Id: I9bc930e5dca557571b4658444fea6aec59c5797a
This commit is contained in:
Kunal Mehta 2016-10-18 14:16:04 -07:00
parent 4465a9fb5a
commit eec74de16a

View file

@ -107,14 +107,15 @@ abstract class FormSpecialPage extends SpecialPage {
$form->addHeaderText( $headerMsg->parseAsBlock() );
}
// Retain query parameters (uselang etc)
$params = array_diff_key(
$this->getRequest()->getQueryValues(), [ 'title' => null ] );
$form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
$form->addPreText( $this->preText() );
$form->addPostText( $this->postText() );
$this->alterForm( $form );
if ( $form->getMethod() == 'post' ) {
// Retain query parameters (uselang etc) on POST requests
$params = array_diff_key(
$this->getRequest()->getQueryValues(), [ 'title' => null ] );
$form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
}
// Give hooks a chance to alter the form, adding extra fields or text etc
Hooks::run( 'SpecialPageBeforeFormDisplay', [ $this->getName(), &$form ] );