Merge "Fix parsing of <pre> tags generated by extension tag hooks"
[lhc/web/wiklou.git] / includes / specialpage / FormSpecialPage.php
index f727c05..66c7d47 100644 (file)
@@ -89,28 +89,36 @@ abstract class FormSpecialPage extends SpecialPage {
         * @return HTMLForm|null
         */
        protected function getForm() {
-               $this->fields = $this->getFormFields();
-
-               $form = HTMLForm::factory( $this->getDisplayFormat(), $this->fields, $this->getContext(), $this->getMessagePrefix() );
-               $form->setSubmitCallback( array( $this, 'onSubmit' ) );
-               $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
+               $form = HTMLForm::factory(
+                       $this->getDisplayFormat(),
+                       $this->getFormFields(),
+                       $this->getContext(),
+                       $this->getMessagePrefix()
+               );
+               $form->setSubmitCallback( [ $this, 'onSubmit' ] );
+               if ( $this->getDisplayFormat() !== 'ooui' ) {
+                       // No legend and wrapper by default in OOUI forms, but can be set manually
+                       // from alterForm()
+                       $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
+               }
 
                $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' );
                if ( !$headerMsg->isDisabled() ) {
                        $form->addHeaderText( $headerMsg->parseAsBlock() );
                }
 
-               // Retain query parameters (uselang etc)
-               $params = array_diff_key(
-                       $this->getRequest()->getQueryValues(), array( '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', array( $this->getName(), &$form ) );
+               Hooks::run( 'SpecialPageBeforeFormDisplay', [ $this->getName(), &$form ] );
 
                return $form;
        }
@@ -162,7 +170,6 @@ abstract class FormSpecialPage extends SpecialPage {
         * Failures here must throw subclasses of ErrorPageError.
         * @param User $user
         * @throws UserBlockedError
-        * @return bool True
         */
        protected function checkExecutePermissions( User $user ) {
                $this->checkPermissions();
@@ -175,8 +182,6 @@ abstract class FormSpecialPage extends SpecialPage {
                if ( $this->requiresWrite() ) {
                        $this->checkReadOnly();
                }
-
-               return true;
        }
 
        /**