From: Bartosz DziewoƄski Date: Tue, 28 Jul 2015 22:08:40 +0000 (+0200) Subject: HTMLForm: Move header formatting OOUI-specific code to OOUIHTMLForm X-Git-Tag: 1.31.0-rc.0~10317 X-Git-Url: http://git.cyclocoop.org/%22%20%20.%20generer_url_ecrire%28%22mots_tous%22%29%20.%20%22?a=commitdiff_plain;h=0a6803e1e5bfc6940e41751bf79b1997e6db52ec;p=lhc%2Fweb%2Fwiklou.git 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 --- 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