Merge "Consistently follow conventions for documenting parameters"
[lhc/web/wiklou.git] / includes / HTMLForm.php
index e06a934..5de34d6 100644 (file)
@@ -574,6 +574,21 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * Add an array of hidden fields to the output
+        *
+        * @since 1.22
+        * @param array $fields Associative array of fields to add;
+        *        mapping names to their values
+        * @return HTMLForm $this for chaining calls
+        */
+       public function addHiddenFields( array $fields ) {
+               foreach ( $fields as $name => $value ) {
+                       $this->mHiddenFields[] = array( $value, array( 'name' => $name ) );
+               }
+               return $this;
+       }
+
        /**
         * Add a button to the form
         * @param string $name field name.
@@ -685,7 +700,7 @@ class HTMLForm extends ContextSource {
         * @return String HTML.
         */
        function getButtons() {
-               $html = '';
+               $html = '<span class="mw-htmlform-submit-buttons">';
 
                if ( $this->mShowSubmit ) {
                        $attribs = array();
@@ -735,6 +750,8 @@ class HTMLForm extends ContextSource {
                        $html .= Html::element( 'input', $attrs );
                }
 
+               $html .= '</span>';
+
                return $html;
        }
 
@@ -968,9 +985,10 @@ class HTMLForm extends ContextSource {
         * @param $fields array[]|HTMLFormField[] array of fields (either arrays or objects)
         * @param string $sectionName ID attribute of the "<table>" tag for this section, ignored if empty
         * @param string $fieldsetIDPrefix ID prefix for the "<fieldset>" tag of each subsection, ignored if empty
+        * @param boolean &$hasUserVisibleFields Whether the section had user-visible fields
         * @return String
         */
-       public function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '' ) {
+       public function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '', &$hasUserVisibleFields = false ) {
                $displayFormat = $this->getDisplayFormat();
 
                $html = '';
@@ -990,20 +1008,38 @@ class HTMLForm extends ContextSource {
                                if ( $labelValue != '&#160;' && $labelValue !== '' ) {
                                        $hasLabel = true;
                                }
-                       } elseif ( is_array( $value ) ) {
-                               $section = $this->displaySection( $value, "mw-htmlform-$key", "$fieldsetIDPrefix$key-" );
-                               $legend = $this->getLegend( $key );
-                               if ( isset( $this->mSectionHeaders[$key] ) ) {
-                                       $section = $this->mSectionHeaders[$key] . $section;
-                               }
-                               if ( isset( $this->mSectionFooters[$key] ) ) {
-                                       $section .= $this->mSectionFooters[$key];
+
+                               if ( get_class( $value ) !== 'HTMLHiddenField' &&
+                                               get_class( $value ) !== 'HTMLApiField' ) {
+                                       $hasUserVisibleFields = true;
                                }
-                               $attributes = array();
-                               if ( $fieldsetIDPrefix ) {
-                                       $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
+                       } elseif ( is_array( $value ) ) {
+                               $subsectionHasVisibleFields = false;
+                               $section = $this->displaySection( $value, "mw-htmlform-$key", "$fieldsetIDPrefix$key-", $subsectionHasVisibleFields );
+                               $legend = null;
+
+                               if ( $subsectionHasVisibleFields === true ) {
+                                       // Display the section with various niceties.
+                                       $hasUserVisibleFields = true;
+
+                                       $legend = $this->getLegend( $key );
+
+                                       if ( isset( $this->mSectionHeaders[$key] ) ) {
+                                               $section = $this->mSectionHeaders[$key] . $section;
+                                       }
+                                       if ( isset( $this->mSectionFooters[$key] ) ) {
+                                               $section .= $this->mSectionFooters[$key];
+                                       }
+
+                                       $attributes = array();
+                                       if ( $fieldsetIDPrefix ) {
+                                               $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
+                                       }
+                                       $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
+                               } else {
+                                       // Just return the inputs, nothing fancy.
+                                       $subsectionHtml .= $section;
                                }
-                               $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
                        }
                }