FormSpecialPage: Only add redirectparams for POST forms
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 18 Oct 2016 21:16:04 +0000 (14:16 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 18 Oct 2016 21:25:11 +0000 (14:25 -0700)
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

includes/specialpage/FormSpecialPage.php

index c28c456..66c7d47 100644 (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 ] );