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
{
29 * Wrapper and its legend are never generated in OOUI mode.
32 protected $mWrapperLegend = false;
34 public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
35 parent
::__construct( $descriptor, $context, $messagePrefix );
36 $this->getOutput()->enableOOUI();
37 $this->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
38 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
42 * Symbolic display format name.
45 protected $displayFormat = 'ooui';
47 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm
$parent = null ) {
48 $field = parent
::loadInputFromParameters( $fieldname, $descriptor, $parent );
49 $field->setShowEmptyLabel( false );
53 function getButtons() {
56 if ( $this->mShowSubmit
) {
59 if ( isset( $this->mSubmitID
) ) {
60 $attribs['id'] = $this->mSubmitID
;
63 if ( isset( $this->mSubmitName
) ) {
64 $attribs['name'] = $this->mSubmitName
;
67 if ( isset( $this->mSubmitTooltip
) ) {
68 $attribs +
= Linker
::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip
);
71 $attribs['classes'] = array(
73 $this->mSubmitModifierClass
,
76 $attribs['type'] = 'submit';
77 $attribs['label'] = $this->getSubmitText();
78 $attribs['value'] = $this->getSubmitText();
79 $attribs['flags'] = array( 'primary', 'constructive' );
81 $buttons .= new OOUI\
ButtonInputWidget( $attribs );
84 if ( $this->mShowReset
) {
85 $buttons .= new OOUI\
ButtonInputWidget( array(
87 'label' => $this->msg( 'htmlform-reset' )->text(),
91 foreach ( $this->mButtons
as $button ) {
94 if ( $button['attribs'] ) {
95 $attrs +
= $button['attribs'];
98 if ( isset( $button['id'] ) ) {
99 $attrs['id'] = $button['id'];
102 $attrs['classes'] = isset( $attrs['class'] ) ?
(array)$attrs['class'] : array();
104 $buttons .= new OOUI\
ButtonInputWidget( array(
106 'name' => $button['name'],
107 'value' => $button['value'],
108 'label' => $button['value'],
112 $html = Html
::rawElement( 'div',
113 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
118 function getFormAttributes() {
119 $attribs = parent
::getFormAttributes();
120 if ( !isset( $attribs['class'] ) ) {
121 $attribs['class'] = '';
124 if ( is_string( $attribs['class'] ) ) {
125 $attribs['class'] = trim( $attribs['class'] . ' mw-htmlform-ooui' );
127 $attribs['class'][] = 'mw-htmlform-ooui';
133 function wrapForm( $html ) {
134 // Always discard $this->mWrapperLegend
135 return Html
::rawElement( 'form', $this->getFormAttributes(), $html );