Fix HTML output arround HTMLForm's submit buttons when in vform
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Thu, 21 Nov 2013 07:45:34 +0000 (08:45 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Sun, 15 Dec 2013 21:06:46 +0000 (22:06 +0100)
$html in HTMLForm::getButtons() is vrapped in a <div></div> when in
vform mode but it contains a <span> tag without its closing
counterpart, thus making the HTML invalid.

And while I'm at it: put line breaks at better places.

Change-Id: I7ffa1bdd72d95188320c1b29d1c46a5f6f434cbe

includes/htmlform/HTMLForm.php

index 5621b01..6af2f5f 100644 (file)
@@ -787,7 +787,7 @@ class HTMLForm extends ContextSource {
         * @return String HTML.
         */
        function getButtons() {
-               $html = '<span class="mw-htmlform-submit-buttons">';
+               $buttons = '';
 
                if ( $this->mShowSubmit ) {
                        $attribs = array();
@@ -812,24 +812,17 @@ class HTMLForm extends ContextSource {
                                array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-big', 'mw-ui-primary', 'mw-ui-block' );
                        }
 
-                       $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
-
-                       // Buttons are top-level form elements in table and div layouts,
-                       // but vform wants all elements inside divs to get spaced-out block
-                       // styling.
-                       if ( $this->isVForm() ) {
-                               $html = Html::rawElement( 'div', null, "\n$html\n" );
-                       }
+                       $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
                }
 
                if ( $this->mShowReset ) {
-                       $html .= Html::element(
-                                       'input',
-                                       array(
-                                               'type' => 'reset',
-                                               'value' => $this->msg( 'htmlform-reset' )->text()
-                                       )
-                               ) . "\n";
+                       $buttons .= Html::element(
+                               'input',
+                               array(
+                                       'type' => 'reset',
+                                       'value' => $this->msg( 'htmlform-reset' )->text()
+                               )
+                       ) . "\n";
                }
 
                foreach ( $this->mButtons as $button ) {
@@ -847,10 +840,18 @@ class HTMLForm extends ContextSource {
                                $attrs['id'] = $button['id'];
                        }
 
-                       $html .= Html::element( 'input', $attrs );
+                       $buttons .= Html::element( 'input', $attrs ) . "\n";
                }
 
-               $html .= '</span>';
+               $html = Html::rawElement( 'span',
+                       array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
+
+               // Buttons are top-level form elements in table and div layouts,
+               // but vform wants all elements inside divs to get spaced-out block
+               // styling.
+               if ( $this->mShowSubmit && $this->isVForm() ) {
+                       $html = Html::rawElement( 'div', null, "\n$html" ) . "\n";
+               }
 
                return $html;
        }