From 7bee1a23046981c9bb34730f2af60364e5e268c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 15 Sep 2017 22:26:11 +0200 Subject: [PATCH] HTMLForm: Do not generate wrappers for empty sections This affects Special:Preferences, where there will no longer be an empty
after every toplevel section heading. Change-Id: Icb6fe957024843f2b08720715054b9afb657f395 --- includes/htmlform/HTMLForm.php | 6 ++++++ includes/htmlform/OOUIHTMLForm.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 465736bb06..d959dd2adc 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -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 ); diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index e47de61a4c..1755e98cfb 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -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, ]; -- 2.20.1