Merge "HTMLForm: Do not render hidden elements as elements"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 19 Nov 2015 16:28:05 +0000 (16:28 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 19 Nov 2015 16:28:05 +0000 (16:28 +0000)
includes/htmlform/HTMLApiField.php
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLHiddenField.php

index f988e62..24a253e 100644 (file)
@@ -16,4 +16,8 @@ class HTMLApiField extends HTMLFormField {
        public function getInputHTML( $value ) {
                return '';
        }
+
+       public function hasVisibleOutput() {
+               return false;
+       }
 }
index 2b9a49a..78dbd30 100644 (file)
@@ -1402,16 +1402,19 @@ class HTMLForm extends ContextSource {
                                $v = empty( $value->mParams['nodata'] )
                                        ? $this->mFieldData[$key]
                                        : $value->getDefault();
-                               $html[] = $value->$getFieldHtmlMethod( $v );
 
-                               $labelValue = trim( $value->getLabel() );
-                               if ( $labelValue != '&#160;' && $labelValue !== '' ) {
-                                       $hasLabel = true;
-                               }
+                               $retval = $value->$getFieldHtmlMethod( $v );
+
+                               // check, if the form field should be added to
+                               // the output.
+                               if ( $value->hasVisibleOutput() ) {
+                                       $html[] = $retval;
+
+                                       $labelValue = trim( $value->getLabel() );
+                                       if ( $labelValue != '&#160;' && $labelValue !== '' ) {
+                                               $hasLabel = true;
+                                       }
 
-                               if ( get_class( $value ) !== 'HTMLHiddenField' &&
-                                       get_class( $value ) !== 'HTMLApiField'
-                               ) {
                                        $hasUserVisibleFields = true;
                                }
                        } elseif ( is_array( $value ) ) {
index 2e3fdb0..28bfb66 100644 (file)
@@ -86,6 +86,15 @@ abstract class HTMLFormField {
                return call_user_func_array( $callback, $args );
        }
 
+       /**
+        * If this field has a user-visible output or not. If not,
+        * it will not be rendered
+        *
+        * @return bool
+        */
+       public function hasVisibleOutput() {
+               return true;
+       }
 
        /**
         * Fetch a field value from $alldata for the closest field matching a given
index e4695f7..00f7343 100644 (file)
@@ -59,4 +59,8 @@ class HTMLHiddenField extends HTMLFormField {
        public function canDisplayErrors() {
                return false;
        }
+
+       public function hasVisibleOutput() {
+               return false;
+       }
 }