Merge "Revert "Convert mediawiki.toc and mediawiki.user to using mw.cookie""
[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 $this->getOutput()->enableOOUI();
36 $this->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
37 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
38 parent::__construct( $descriptor, $context, $messagePrefix );
39 }
40
41 /**
42 * Symbolic display format name.
43 * @var string
44 */
45 protected $displayFormat = 'ooui';
46
47 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
48 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
49 $field->setShowEmptyLabel( false );
50 return $field;
51 }
52
53 function getButtons() {
54 $buttons = '';
55
56 if ( $this->mShowSubmit ) {
57 $attribs = array();
58
59 if ( isset( $this->mSubmitID ) ) {
60 $attribs['id'] = $this->mSubmitID;
61 }
62
63 if ( isset( $this->mSubmitName ) ) {
64 $attribs['name'] = $this->mSubmitName;
65 }
66
67 if ( isset( $this->mSubmitTooltip ) ) {
68 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
69 }
70
71 $attribs['classes'] = array(
72 'mw-htmlform-submit',
73 $this->mSubmitModifierClass,
74 );
75
76 $attribs['type'] = 'submit';
77 $attribs['label'] = $this->getSubmitText();
78 $attribs['value'] = $this->getSubmitText();
79 $attribs['flags'] = array( 'primary', 'constructive' );
80
81 $buttons .= new OOUI\ButtonInputWidget( $attribs );
82 }
83
84 if ( $this->mShowReset ) {
85 $buttons .= new OOUI\ButtonInputWidget( array(
86 'type' => 'reset',
87 'label' => $this->msg( 'htmlform-reset' )->text(),
88 ) );
89 }
90
91 foreach ( $this->mButtons as $button ) {
92 $attrs = array();
93
94 if ( $button['attribs'] ) {
95 $attrs += $button['attribs'];
96 }
97
98 if ( isset( $button['id'] ) ) {
99 $attrs['id'] = $button['id'];
100 }
101
102 $attrs['classes'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : array();
103
104 $buttons .= new OOUI\ButtonInputWidget( array(
105 'type' => 'submit',
106 'name' => $button['name'],
107 'value' => $button['value'],
108 'label' => $button['value'],
109 ) + $attrs );
110 }
111
112 $html = Html::rawElement( 'div',
113 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
114
115 return $html;
116 }
117
118 function getFormAttributes() {
119 $attribs = parent::getFormAttributes();
120 if ( !isset( $attribs['class'] ) ) {
121 $attribs['class'] = '';
122 }
123
124 if ( is_string( $attribs['class'] ) ) {
125 $attribs['class'] = trim( $attribs['class'] . ' mw-htmlform-ooui' );
126 } else {
127 $attribs['class'][] = 'mw-htmlform-ooui';
128 }
129
130 return $attribs;
131 }
132
133 function wrapForm( $html ) {
134 // Always discard $this->mWrapperLegend
135 return Html::rawElement( 'form', $this->getFormAttributes(), $html );
136 }
137 }