Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/227604
Change subject: HTMLForm: Move section formatting OOUI-specific code to
OOUIHTMLForm
......................................................................
HTMLForm: Move section formatting OOUI-specific code to OOUIHTMLForm
* Introduce a new helper function formatSection() and override it
in OOUIHTMLForm.
* Bonus: Properly construct the form's FieldsetLayout,
thanks to I860a96858c4fcac62d63b46e35a9153f22c0a9c9.
* Bonus: Don't pass silly HTMLForm's classes which don't make
sense in OOUI mode.
Change-Id: I91af6efa8762e9676efea532381292e221255862
---
M includes/htmlform/HTMLForm.php
M includes/htmlform/OOUIHTMLForm.php
2 files changed, 63 insertions(+), 41 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/04/227604/1
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index ac064bc..0678bdd 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -1335,7 +1335,7 @@
&$hasUserVisibleFields = false ) {
$displayFormat = $this->getDisplayFormat();
- $html = '';
+ $html = array();
$subsectionHtml = '';
$hasLabel = false;
@@ -1347,7 +1347,7 @@
$v = empty( $value->mParams['nodata'] )
? $this->mFieldData[$key]
: $value->getDefault();
- $html .= $value->$getFieldHtmlMethod( $v );
+ $html[] = $value->$getFieldHtmlMethod( $v );
$labelValue = trim( $value->getLabel() );
if ( $labelValue != ' ' && $labelValue !==
'' ) {
@@ -1393,45 +1393,7 @@
}
}
- if ( $displayFormat !== 'raw' ) {
- $classes = array();
-
- if ( !$hasLabel ) { // Avoid strange spacing when no
labels exist
- $classes[] = 'mw-htmlform-nolabel';
- }
-
- $attribs = array(
- 'class' => implode( ' ', $classes ),
- );
-
- if ( $sectionName ) {
- $attribs['id'] = Sanitizer::escapeId(
$sectionName );
- }
-
- if ( $displayFormat === 'table' ) {
- $html = Html::rawElement( 'table',
- $attribs,
- Html::rawElement( 'tbody',
array(), "\n$html\n" ) ) . "\n";
- } elseif ( $displayFormat === 'inline' ) {
- $html = Html::rawElement( 'span', $attribs,
"\n$html\n" );
- } elseif ( $displayFormat === 'ooui' ) {
- $config = array(
- 'classes' => $classes,
- );
- if ( $sectionName ) {
- $config['id'] = Sanitizer::escapeId(
$sectionName );
- }
- if ( is_string( $this->mWrapperLegend ) ) {
- $config['label'] =
$this->mWrapperLegend;
- }
- $fieldset = new OOUI\FieldsetLayout( $config );
- // Ewww. We should pass this as
$config['items'], but there might be string snippets.
- $fieldset->group->appendContent( new
OOUI\HtmlSnippet( $html ) );
- $html = $fieldset;
- } else {
- $html = Html::rawElement( 'div', $attribs,
"\n$html\n" );
- }
- }
+ $html = $this->formatSection( $html, $sectionName, $hasLabel );
if ( $subsectionHtml ) {
if ( $this->mSubSectionBeforeFields ) {
@@ -1445,6 +1407,46 @@
}
/**
+ * Put a form section together from the individual fields' HTML,
merging it and wrapping.
+ * @param array $fieldsHtml
+ * @param string $sectionName
+ * @param bool $anyFieldHasLabel
+ * @return string HTML
+ */
+ protected function formatSection( array $fieldsHtml, $sectionName,
$anyFieldHasLabel ) {
+ $displayFormat = $this->getDisplayFormat();
+ $html = implode( '', $fieldsHtml );
+
+ if ( $displayFormat === 'raw' ) {
+ return $html;
+ }
+
+ $classes = array();
+
+ if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no
labels exist
+ $classes[] = 'mw-htmlform-nolabel';
+ }
+
+ $attribs = array(
+ 'class' => implode( ' ', $classes ),
+ );
+
+ if ( $sectionName ) {
+ $attribs['id'] = Sanitizer::escapeId( $sectionName );
+ }
+
+ if ( $displayFormat === 'table' ) {
+ return Html::rawElement( 'table',
+ $attribs,
+ Html::rawElement( 'tbody', array(),
"\n$html\n" ) ) . "\n";
+ } elseif ( $displayFormat === 'inline' ) {
+ return Html::rawElement( 'span', $attribs, "\n$html\n"
);
+ } else {
+ return Html::rawElement( 'div', $attribs, "\n$html\n" );
+ }
+ }
+
+ /**
* Construct the form fields from the Descriptor array
*/
function loadData() {
diff --git a/includes/htmlform/OOUIHTMLForm.php
b/includes/htmlform/OOUIHTMLForm.php
index af5b5f0..ca8ca0f 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -105,6 +105,26 @@
}
/**
+ * Put a form section together from the individual fields' HTML,
merging it and wrapping.
+ * @param OOUI\\FieldLayout[] $fieldsHtml
+ * @param string $sectionName
+ * @param bool $anyFieldHasLabel Unused
+ * @return string HTML
+ */
+ protected function formatSection( array $fieldsHtml, $sectionName,
$anyFieldHasLabel ) {
+ $config = array(
+ 'items' => $fieldsHtml,
+ );
+ if ( $sectionName ) {
+ $config['id'] = Sanitizer::escapeId( $sectionName );
+ }
+ if ( is_string( $this->mWrapperLegend ) ) {
+ $config['label'] = $this->mWrapperLegend;
+ }
+ return new OOUI\FieldsetLayout( $config );
+ }
+
+ /**
* @param string|array|Status $errors
* @return string
*/
--
To view, visit https://gerrit.wikimedia.org/r/227604
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I91af6efa8762e9676efea532381292e221255862
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits