From dd04b310527c3ce69911789254939e9a2b627ada Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 1 Sep 2015 15:03:07 +0200 Subject: [PATCH] OOUIHTMLForm: Make boolean form field parameters actually work everywhere HTMLFormField::getAttributes() is unfortunately reused both for generating HTML tag attributes and generating OOUI widget configuration. For boolean ones passing '' for true (empty string) works for HTML (where the attribute only has to be present), but not for OOUI (where the configuration option has to be truthy). It would be cleanest to pass true/false, which is the expected input for OOUI widgets and which the Html class handles intuitively, but it seems that these values often end up in the Xml class's methods instead (somebody remind me why do we even have that?). So let's play it safe and pass the name of the parameter instead, which is okay for both HTML/XML (both disabled="" and disabled="disabled" work the same) and OOUI widgets. (Note also that the whole thing relies on the default value of these boolean parameters/attributes being false.) This was not spotted before because we had hacks for this problem in all the important places. This commit reverts three such hacky patches that missed the underlying problem: * e25eb30ea81eda82b57a4e3c84f4e1afdf3b6080 * 70910cd13cdb5d67f1dda2d9ccffbc8e30787352 * 8a164ff9f9f5b4691e40f1219358ca45c8b61c3d Change-Id: Ic6a1f3758cba62147f7fe8127cc0a83c695b0212 --- includes/htmlform/HTMLFormField.php | 4 ++-- includes/htmlform/HTMLTextAreaField.php | 5 ----- includes/htmlform/HTMLTextField.php | 5 ----- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 0fab033dce..13756e3d64 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -920,7 +920,7 @@ abstract class HTMLFormField { * @return array Attributes */ public function getAttributes( array $list, array $mappings = null ) { - static $boolAttribs = array( 'disabled', 'required', 'multiple', 'readonly' ); + static $boolAttribs = array( 'disabled', 'required', 'autofocus', 'multiple', 'readonly' ); $ret = array(); foreach ( $list as $key ) { @@ -928,7 +928,7 @@ abstract class HTMLFormField { if ( in_array( $key, $boolAttribs ) ) { if ( !empty( $this->mParams[$key] ) ) { - $ret[$mappedKey] = ''; + $ret[$mappedKey] = $mappedKey; } } elseif ( isset( $this->mParams[$key] ) ) { $ret[$mappedKey] = $this->mParams[$key]; diff --git a/includes/htmlform/HTMLTextAreaField.php b/includes/htmlform/HTMLTextAreaField.php index 5cfea63db3..aeb4b7c22a 100644 --- a/includes/htmlform/HTMLTextAreaField.php +++ b/includes/htmlform/HTMLTextAreaField.php @@ -71,11 +71,6 @@ class HTMLTextAreaField extends HTMLFormField { 'readonly' => 'readOnly', ) ); - if ( isset( $attribs['readOnly'] ) ) { - // this needs to be set to a boolean value - hack?? - $attribs['readOnly'] = true; - } - return new OOUI\TextInputWidget( array( 'id' => $this->mID, 'name' => $this->mName, diff --git a/includes/htmlform/HTMLTextField.php b/includes/htmlform/HTMLTextField.php index 40cff47e42..157116d829 100644 --- a/includes/htmlform/HTMLTextField.php +++ b/includes/htmlform/HTMLTextField.php @@ -113,11 +113,6 @@ class HTMLTextField extends HTMLFormField { 'tabindex' => 'tabIndex', ) ); - if ( isset( $attribs['readOnly'] ) ) { - // This needs to be set to a boolean value - $attribs['readOnly'] = true; - } - $type = $this->getType( $attribs ); return $this->getInputWidget( array( -- 2.20.1