4 * HTML form generation and submission handling, OOUI style.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 * Compact stacked vertical format for forms, implemented using OOUI widgets.
27 class OOUIHTMLForm
extends HTMLForm
{
28 public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
29 parent
::__construct( $descriptor, $context, $messagePrefix );
30 $this->getOutput()->enableOOUI();
31 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
35 * Symbolic display format name.
38 protected $displayFormat = 'ooui';
40 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm
$parent = null ) {
41 $field = parent
::loadInputFromParameters( $fieldname, $descriptor, $parent );
42 $field->setShowEmptyLabel( false );
46 function getButtons() {
49 if ( $this->mShowSubmit
) {
50 $attribs = array( 'infusable' => true );
52 if ( isset( $this->mSubmitID
) ) {
53 $attribs['id'] = $this->mSubmitID
;
56 if ( isset( $this->mSubmitName
) ) {
57 $attribs['name'] = $this->mSubmitName
;
60 if ( isset( $this->mSubmitTooltip
) ) {
61 $attribs +
= Linker
::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip
);
64 $attribs['classes'] = array( 'mw-htmlform-submit' );
65 $attribs['type'] = 'submit';
66 $attribs['label'] = $this->getSubmitText();
67 $attribs['value'] = $this->getSubmitText();
68 $attribs['flags'] = $this->mSubmitFlags
;
70 $buttons .= new OOUI\
ButtonInputWidget( $attribs );
73 if ( $this->mShowReset
) {
74 $buttons .= new OOUI\
ButtonInputWidget( array(
76 'label' => $this->msg( 'htmlform-reset' )->text(),
80 foreach ( $this->mButtons
as $button ) {
83 if ( $button['attribs'] ) {
84 $attrs +
= $button['attribs'];
87 if ( isset( $button['id'] ) ) {
88 $attrs['id'] = $button['id'];
91 $attrs['classes'] = isset( $attrs['class'] ) ?
(array)$attrs['class'] : array();
93 $buttons .= new OOUI\
ButtonInputWidget( array(
95 'name' => $button['name'],
96 'value' => $button['value'],
97 'label' => $button['value'],
101 $html = Html
::rawElement( 'div',
102 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
108 $fieldset = parent
::getBody();
109 // FIXME This only works for forms with no subsections
110 if ( $fieldset instanceof OOUI\FieldsetLayout
) {
111 $fieldset->group
->prependContent( new OOUI\
HtmlSnippet( $this->mHeader
) );
116 function wrapForm( $html ) {
117 $form = new OOUI\
FormLayout( $this->getFormAttributes() +
array(
118 'classes' => array( 'mw-htmlform-ooui' ),
119 'content' => new OOUI\
HtmlSnippet( $html ),
122 // Include a wrapper for style, if requested.
123 $form = new OOUI\
PanelLayout( array(
124 'classes' => array( 'mw-htmlform-ooui-wrapper' ),
126 'padded' => $this->mWrapperLegend
!== false,
127 'framed' => $this->mWrapperLegend
!== false,