Merge "Allow using createAndPromote.php with custom groups"
[lhc/web/wiklou.git] / includes / htmlform / OOUIHTMLForm.php
1 <?php
2
3 /**
4 * HTML form generation and submission handling, OOUI style.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 */
23
24 /**
25 * Compact stacked vertical format for forms, implemented using OOUI widgets.
26 */
27 class OOUIHTMLForm extends HTMLForm {
28 /**
29 * Wrapper and its legend are never generated in OOUI mode.
30 * @var boolean
31 */
32 protected $mWrapperLegend = false;
33
34 public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
35 parent::__construct( $descriptor, $context, $messagePrefix );
36 $this->getOutput()->enableOOUI();
37 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
38 }
39
40 /**
41 * Symbolic display format name.
42 * @var string
43 */
44 protected $displayFormat = 'ooui';
45
46 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
47 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
48 $field->setShowEmptyLabel( false );
49 return $field;
50 }
51
52 function getButtons() {
53 $buttons = '';
54
55 if ( $this->mShowSubmit ) {
56 $attribs = array( 'infusable' => true );
57
58 if ( isset( $this->mSubmitID ) ) {
59 $attribs['id'] = $this->mSubmitID;
60 }
61
62 if ( isset( $this->mSubmitName ) ) {
63 $attribs['name'] = $this->mSubmitName;
64 }
65
66 if ( isset( $this->mSubmitTooltip ) ) {
67 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
68 }
69
70 $attribs['classes'] = array( 'mw-htmlform-submit' );
71 $attribs['type'] = 'submit';
72 $attribs['label'] = $this->getSubmitText();
73 $attribs['value'] = $this->getSubmitText();
74 $attribs['flags'] = array( $this->mSubmitFlag );
75
76 $buttons .= new OOUI\ButtonInputWidget( $attribs );
77 }
78
79 if ( $this->mShowReset ) {
80 $buttons .= new OOUI\ButtonInputWidget( array(
81 'type' => 'reset',
82 'label' => $this->msg( 'htmlform-reset' )->text(),
83 ) );
84 }
85
86 foreach ( $this->mButtons as $button ) {
87 $attrs = array();
88
89 if ( $button['attribs'] ) {
90 $attrs += $button['attribs'];
91 }
92
93 if ( isset( $button['id'] ) ) {
94 $attrs['id'] = $button['id'];
95 }
96
97 $attrs['classes'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : array();
98
99 $buttons .= new OOUI\ButtonInputWidget( array(
100 'type' => 'submit',
101 'name' => $button['name'],
102 'value' => $button['value'],
103 'label' => $button['value'],
104 ) + $attrs );
105 }
106
107 $html = Html::rawElement( 'div',
108 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
109
110 return $html;
111 }
112
113 function getFormAttributes() {
114 $attribs = parent::getFormAttributes();
115 if ( !isset( $attribs['class'] ) ) {
116 $attribs['class'] = '';
117 }
118
119 if ( is_string( $attribs['class'] ) ) {
120 $attribs['class'] = trim( $attribs['class'] . ' mw-htmlform-ooui' );
121 } else {
122 $attribs['class'][] = 'mw-htmlform-ooui';
123 }
124
125 return $attribs;
126 }
127
128 function wrapForm( $html ) {
129 // Always discard $this->mWrapperLegend
130 return Html::rawElement( 'form', $this->getFormAttributes(), $html );
131 }
132 }