HTMLForm: Do not generate wrappers for empty sections
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 15 Sep 2017 20:26:11 +0000 (22:26 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 16 Sep 2017 13:23:46 +0000 (15:23 +0200)
This affects Special:Preferences, where there will no longer be an
empty <table class="mw-htmlform-nolabel"><tbody></tbody></table>
after every toplevel section heading.

Change-Id: Icb6fe957024843f2b08720715054b9afb657f395

includes/htmlform/HTMLForm.php
includes/htmlform/OOUIHTMLForm.php

index 465736b..d959dd2 100644 (file)
@@ -1723,6 +1723,12 @@ class HTMLForm extends ContextSource {
         * @return string HTML
         */
        protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
+               if ( !$fieldsHtml ) {
+                       // Do not generate any wrappers for empty sections. Sections may be empty if they only have
+                       // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
+                       return '';
+               }
+
                $displayFormat = $this->getDisplayFormat();
                $html = implode( '', $fieldsHtml );
 
index e47de61..1755e98 100644 (file)
@@ -176,6 +176,12 @@ class OOUIHTMLForm extends HTMLForm {
         * @return string HTML
         */
        protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
+               if ( !$fieldsHtml ) {
+                       // Do not generate any wrappers for empty sections. Sections may be empty if they only have
+                       // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
+                       return '';
+               }
+
                $config = [
                        'items' => $fieldsHtml,
                ];