MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/73921
Change subject: Don't display empty preference sections
......................................................................
Don't display empty preference sections
If a preference section has only hidden or API preferences, there are no
contents. So it would be silly to display a section heading for it,
since the user cannot see anything inside.
Change-Id: Ia1d89032c45a06c5103e50d90f3ef147213dd571
---
M includes/HTMLForm.php
1 file changed, 28 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/21/73921/1
diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php
index 5af081b..d366a42 100644
--- a/includes/HTMLForm.php
+++ b/includes/HTMLForm.php
@@ -976,6 +976,7 @@
$html = '';
$subsectionHtml = '';
$hasLabel = false;
+ $hasContents = false;
$getFieldHtmlMethod = ( $displayFormat == 'table' ) ?
'getTableRow' : 'get' . ucfirst( $displayFormat );
@@ -990,23 +991,39 @@
if ( $labelValue != ' ' && $labelValue !==
'' ) {
$hasLabel = true;
}
+
+ if ( get_class( $value ) !== 'HTMLHiddenField'
&&
+ get_class( $value ) !==
'HTMLApiField' ) {
+ $hasContents = 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 ( $section !== '' ) {
+ $hasContents = 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";
}
- 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";
}
}
+ // Either there are no fields or all the fields are of type
+ // HTMLHiddenField - valid use case.
+ if ( $hasContents === false ) {
+ return '';
+ }
+
if ( $displayFormat !== 'raw' ) {
$classes = array();
--
To view, visit https://gerrit.wikimedia.org/r/73921
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1d89032c45a06c5103e50d90f3ef147213dd571
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits