HTMLForm: Move section formatting OOUI-specific code to OOUIHTMLForm
[lhc/web/wiklou.git] / includes / htmlform / HTMLForm.php
index b10d789..946fc72 100644 (file)
  *    'size'                -- the length of text fields
  *    'filter-callback      -- a function name to give you the chance to
  *                             massage the inputted value before it's processed.
- *                             @see HTMLForm::filter()
+ *                             @see HTMLFormField::filter()
  *    'validation-callback' -- a function name to give you the chance
  *                             to impose extra validation on the field input.
- *                             @see HTMLForm::validate()
+ *                             @see HTMLFormField::validate()
  *    'name'                -- By default, the 'name' attribute of the input field
  *                             is "wp{$fieldname}".  If you want a different name
  *                             (eg one without the "wp" prefix), specify it here and
@@ -140,8 +140,6 @@ class HTMLForm extends ContextSource {
                'selectandother' => 'HTMLSelectAndOtherField',
                'namespaceselect' => 'HTMLSelectNamespace',
                'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton',
-               'advancednamespaceselect' => 'HTMLAdvancedSelectNamespace',
-               'advancednamespaceselectwithbutton' => 'HTMLAdvancedSelectNamespaceWithButton',
                'tagfilter' => 'HTMLTagFilter',
                'submit' => 'HTMLSubmitField',
                'hidden' => 'HTMLHiddenField',
@@ -1335,7 +1333,7 @@ class HTMLForm extends ContextSource {
                &$hasUserVisibleFields = false ) {
                $displayFormat = $this->getDisplayFormat();
 
-               $html = '';
+               $html = array();
                $subsectionHtml = '';
                $hasLabel = false;
 
@@ -1347,7 +1345,7 @@ class HTMLForm extends ContextSource {
                                $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 +1391,7 @@ class HTMLForm extends ContextSource {
                        }
                }
 
-               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 ) {
@@ -1444,6 +1404,46 @@ class HTMLForm extends ContextSource {
                }
        }
 
+       /**
+        * 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
         */