Use default value instead of submitted value in HTMLForm buttons
authorGergő Tisza <tgr.huwiki@gmail.com>
Fri, 1 Apr 2016 11:49:49 +0000 (14:49 +0300)
committerGergő Tisza <tgr.huwiki@gmail.com>
Fri, 1 Apr 2016 12:14:36 +0000 (15:14 +0300)
In some exotic use cases where the form is rendered straight from
a successful submit this prevents unexpected button text changes.

Change-Id: I61619b6222d9fb29c63ce7c1f3ceff512143c4f7

includes/htmlform/HTMLButtonField.php

index 16417fc..1c4daf3 100644 (file)
@@ -79,13 +79,14 @@ class HTMLButtonField extends HTMLFormField {
                        'id' => $this->mID,
                        'type' => $this->buttonType,
                        'name' => $this->mName,
-                       'value' => $value,
+                       'value' => $this->getDefault(),
                ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
 
                if ( $this->isBadIE() ) {
                        return Html::element( 'input', $attr );
                } else {
-                       return Html::rawElement( 'button', $attr, $this->buttonLabel ?: htmlspecialchars( $value ) );
+                       return Html::rawElement( 'button', $attr,
+                               $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
                }
        }
 
@@ -97,10 +98,10 @@ class HTMLButtonField extends HTMLFormField {
        public function getInputOOUI( $value ) {
                return new OOUI\ButtonInputWidget( [
                        'name' => $this->mName,
-                       'value' => $value,
+                       'value' => $this->getDefault(),
                        'label' => !$this->isBadIE() && $this->buttonLabel
                                ? new OOUI\HtmlSnippet( $this->buttonLabel )
-                               : $value,
+                               : $this->getDefault(),
                        'type' => $this->buttonType,
                        'classes' => [ 'mw-htmlform-submit', $this->mClass ],
                        'id' => $this->mID,