Merge "Auto-forward to search suggestion when zero results"
[lhc/web/wiklou.git] / includes / htmlform / OOUIHTMLForm.php
index 6c9952a..eec13ee 100644 (file)
  * 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();
-               $this->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
                $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
        }
 
@@ -54,7 +47,7 @@ class OOUIHTMLForm extends HTMLForm {
                $buttons = '';
 
                if ( $this->mShowSubmit ) {
-                       $attribs = array();
+                       $attribs = array( 'infusable' => true );
 
                        if ( isset( $this->mSubmitID ) ) {
                                $attribs['id'] = $this->mSubmitID;
@@ -68,15 +61,11 @@ class OOUIHTMLForm extends HTMLForm {
                                $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
                        }
 
-                       $attribs['classes'] = array(
-                               'mw-htmlform-submit',
-                               $this->mSubmitModifierClass,
-                       );
-
+                       $attribs['classes'] = array( 'mw-htmlform-submit' );
                        $attribs['type'] = 'submit';
                        $attribs['label'] = $this->getSubmitText();
                        $attribs['value'] = $this->getSubmitText();
-                       $attribs['flags'] = array( 'primary', 'constructive' );
+                       $attribs['flags'] = $this->mSubmitFlags;
 
                        $buttons .= new OOUI\ButtonInputWidget( $attribs );
                }
@@ -115,23 +104,30 @@ class OOUIHTMLForm extends HTMLForm {
                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;
        }
 }