$html = ''
. $this->getErrors( $submitResult )
- . $this->mHeader
+ // In OOUI forms, we handle mHeader elsewhere. FIXME This is horrible.
+ . ( $this->getDisplayFormat() === 'ooui' ? '' : $this->mHeader )
. $this->getBody()
. $this->getHiddenFields()
. $this->getButtons()
$attribs = array(
'action' => $this->getAction(),
'method' => $this->getMethod(),
- 'class' => array( 'visualClear' ),
'enctype' => $encType,
);
if ( !empty( $this->mId ) ) {
function wrapForm( $html ) {
# Include a <fieldset> wrapper for style, if requested.
if ( $this->mWrapperLegend !== false ) {
- $html = Xml::fieldset( $this->mWrapperLegend, $html );
+ $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
+ $html = Xml::fieldset( $legend, $html );
}
- return Html::rawElement( 'form', $this->getFormAttributes(), $html );
+ return Html::rawElement( 'form', $this->getFormAttributes() + array( 'class' => 'visualClear' ), $html );
}
/**
* Prompt the whole form to be wrapped in a "<fieldset>", with
* this text as its "<legend>" element.
*
- * @param string|bool $legend HTML to go inside the "<legend>" element, or
- * false for no <legend>
- * Will be escaped
+ * @param string|bool $legend If false, no wrapper or legend will be displayed.
+ * If true, a wrapper will be displayed, but no legend.
+ * If a string, a wrapper will be displayed with that string as a legend.
+ * The string will be escaped before being output (this doesn't support HTML).
*
* @return HTMLForm $this for chaining calls (since 1.20)
*/
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->toString();
+ $html = $fieldset;
} else {
$html = Html::rawElement( 'div', $attribs, "\n$html\n" );
}
}
- if ( $this->mSubSectionBeforeFields ) {
- return $subsectionHtml . "\n" . $html;
+ if ( $subsectionHtml ) {
+ if ( $this->mSubSectionBeforeFields ) {
+ return $subsectionHtml . "\n" . $html;
+ } else {
+ return $html . "\n" . $subsectionHtml;
+ }
} else {
- return $html . "\n" . $subsectionHtml;
+ return $html;
}
}
* Compact stacked vertical format for forms, implemented using OOUI widgets.
*/
class OOUIHTMLForm extends HTMLForm {
- /**
- * Wrapper and its legend are never generated in OOUI mode.
- * @var boolean
- */
- protected $mWrapperLegend = false;
-
public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
parent::__construct( $descriptor, $context, $messagePrefix );
$this->getOutput()->enableOOUI();
return $html;
}
- function getFormAttributes() {
- $attribs = parent::getFormAttributes();
- if ( !isset( $attribs['class'] ) ) {
- $attribs['class'] = '';
+ function getBody() {
+ $fieldset = parent::getBody();
+ // FIXME This only works for forms with no subsections
+ if ( $fieldset instanceof OOUI\FieldsetLayout ) {
+ $fieldset->group->prependContent( new OOUI\HtmlSnippet( $this->mHeader ) );
}
-
- if ( is_string( $attribs['class'] ) ) {
- $attribs['class'] = trim( $attribs['class'] . ' mw-htmlform-ooui' );
- } else {
- $attribs['class'][] = 'mw-htmlform-ooui';
- }
-
- return $attribs;
+ return $fieldset;
}
function wrapForm( $html ) {
- // Always discard $this->mWrapperLegend
- return Html::rawElement( 'form', $this->getFormAttributes(), $html );
+ $form = new OOUI\FormLayout( $this->getFormAttributes() + array(
+ 'classes' => array( 'mw-htmlform-ooui' ),
+ 'content' => new OOUI\HtmlSnippet( $html ),
+ ) );
+
+ // Include a wrapper for style, if requested.
+ $form = new OOUI\PanelLayout( array(
+ 'classes' => array( 'mw-htmlform-ooui-wrapper' ),
+ 'expanded' => false,
+ 'padded' => $this->mWrapperLegend !== false,
+ 'framed' => $this->mWrapperLegend !== false,
+ 'content' => $form,
+ ) );
+
+ return $form;
}
}