From 0a6803e1e5bfc6940e41751bf79b1997e6db52ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 29 Jul 2015 00:08:40 +0200 Subject: [PATCH] HTMLForm: Move header formatting OOUI-specific code to OOUIHTMLForm * 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 | 44 ++++++++++++++++++++++++------ includes/htmlform/OOUIHTMLForm.php | 9 ++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 946fc72c2d..38729a5ec3 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -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 ) { diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index fed32d0d4a..37badabb07 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -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 -- 2.20.1