HTMLForm: Move header formatting OOUI-specific code to OOUIHTMLForm
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 28 Jul 2015 22:08:40 +0000 (00:08 +0200)
committerJforrester <jforrester@wikimedia.org>
Fri, 21 Aug 2015 18:50:02 +0000 (18:50 +0000)
* Introduce a getter getHeaderText() and override it in OOUIHTMLForm.
* While we're at it, also introduce getFooterText() (although right
  now we have no need to override this one).
* Use both in HTMLForm where appropriate.

Change-Id: I9a7234ed75b024f24e0a087c9c000bb2024b405f

includes/htmlform/HTMLForm.php
includes/htmlform/OOUIHTMLForm.php

index 946fc72..38729a5 100644 (file)
@@ -710,6 +710,21 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * Get header text.
+        *
+        * @param string|null $section The section to get the header text for
+        * @since 1.26
+        * @return string
+        */
+       function getHeaderText( $section = null ) {
+               if ( is_null( $section ) ) {
+                       return $this->mHeader;
+               } else {
+                       return isset( $this->mSectionHeaders[$section] ) ? $this->mSectionHeaders[$section] : '';
+               }
+       }
+
        /**
         * Add footer text, inside the form.
         *
@@ -750,6 +765,21 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * Get footer text.
+        *
+        * @param string|null $section The section to get the footer text for
+        * @since 1.26
+        * @return string
+        */
+       function getFooterText( $section = null ) {
+               if ( is_null( $section ) ) {
+                       return $this->mFooter;
+               } else {
+                       return isset( $this->mSectionFooters[$section] ) ? $this->mSectionFooters[$section] : '';
+               }
+       }
+
        /**
         * Add text to the end of the display.
         *
@@ -871,12 +901,11 @@ class HTMLForm extends ContextSource {
 
                $html = ''
                        . $this->getErrors( $submitResult )
-                       // In OOUI forms, we handle mHeader elsewhere. FIXME This is horrible.
-                       . ( $this->getDisplayFormat() === 'ooui' ? '' : $this->mHeader )
+                       . $this->getHeaderText()
                        . $this->getBody()
                        . $this->getHiddenFields()
                        . $this->getButtons()
-                       . $this->mFooter;
+                       . $this->getFooterText();
 
                $html = $this->wrapForm( $html );
 
@@ -1372,12 +1401,9 @@ class HTMLForm extends ContextSource {
 
                                        $legend = $this->getLegend( $key );
 
-                                       if ( isset( $this->mSectionHeaders[$key] ) ) {
-                                               $section = $this->mSectionHeaders[$key] . $section;
-                                       }
-                                       if ( isset( $this->mSectionFooters[$key] ) ) {
-                                               $section .= $this->mSectionFooters[$key];
-                                       }
+                                       $section = $this->getHeaderText( $key ) .
+                                               $section .
+                                               $this->getFooterText( $key );
 
                                        $attributes = array();
                                        if ( $fieldsetIDPrefix ) {
index fed32d0..37badab 100644 (file)
@@ -133,6 +133,15 @@ class OOUIHTMLForm extends HTMLForm {
                return '';
        }
 
+       function getHeaderText( $section = null ) {
+               if ( is_null( $section ) ) {
+                       // We handle $this->mHeader elsewhere, in getBody()
+                       return '';
+               } else {
+                       return parent::getHeaderText( $section );
+               }
+       }
+
        function getBody() {
                $fieldset = parent::getBody();
                // FIXME This only works for forms with no subsections