Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / htmlform / VFormHTMLForm.php
1 <?php
2
3 /**
4 * HTML form generation and submission handling, vertical-form 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.
26 */
27 class VFormHTMLForm extends HTMLForm {
28 /**
29 * Wrapper and its legend are never generated in VForm mode.
30 * @var boolean
31 */
32 protected $mWrapperLegend = false;
33
34 /**
35 * Symbolic display format name.
36 * @var string
37 */
38 protected $displayFormat = 'vform';
39
40 public function isVForm() {
41 wfDeprecated( __METHOD__, '1.25' );
42 return true;
43 }
44
45 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
46 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
47 $field->setShowEmptyLabel( false );
48 return $field;
49 }
50
51 function getHTML( $submitResult ) {
52 // This is required for VForm HTMLForms that use that style regardless
53 // of wgUseMediaWikiUIEverywhere (since they pre-date it).
54 // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated
55 // with the addModuleStyles in SpecialPage->setHeaders.
56 $this->getOutput()->addModuleStyles( array(
57 'mediawiki.ui',
58 'mediawiki.ui.button',
59 'mediawiki.ui.input',
60 'mediawiki.ui.checkbox',
61 ) );
62
63 return parent::getHTML( $submitResult );
64 }
65
66 protected function getFormAttributes() {
67 $attribs = parent::getFormAttributes();
68 $attribs['class'] = array( 'mw-ui-vform', 'mw-ui-container', 'visualClear' );
69 return $attribs;
70 }
71
72 function wrapForm( $html ) {
73 // Always discard $this->mWrapperLegend
74 return Html::rawElement( 'form', $this->getFormAttributes(), $html );
75 }
76
77 function getButtons() {
78 $buttons = '';
79
80 if ( $this->mShowSubmit ) {
81 $attribs = array();
82
83 if ( isset( $this->mSubmitID ) ) {
84 $attribs['id'] = $this->mSubmitID;
85 }
86
87 if ( isset( $this->mSubmitName ) ) {
88 $attribs['name'] = $this->mSubmitName;
89 }
90
91 if ( isset( $this->mSubmitTooltip ) ) {
92 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
93 }
94
95 $attribs['class'] = array(
96 'mw-htmlform-submit',
97 'mw-ui-button mw-ui-big mw-ui-block',
98 );
99 foreach ( $this->mSubmitFlags as $flag ) {
100 $attribs['class'][] = 'mw-ui-' . $flag;
101 }
102
103 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
104 }
105
106 if ( $this->mShowReset ) {
107 $buttons .= Html::element(
108 'input',
109 array(
110 'type' => 'reset',
111 'value' => $this->msg( 'htmlform-reset' )->text(),
112 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
113 )
114 ) . "\n";
115 }
116
117 foreach ( $this->mButtons as $button ) {
118 $attrs = array(
119 'type' => 'submit',
120 'name' => $button['name'],
121 'value' => $button['value']
122 );
123
124 if ( $button['attribs'] ) {
125 $attrs += $button['attribs'];
126 }
127
128 if ( isset( $button['id'] ) ) {
129 $attrs['id'] = $button['id'];
130 }
131
132 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : array();
133 $attrs['class'][] = 'mw-ui-button mw-ui-big mw-ui-block';
134
135 $buttons .= Html::element( 'input', $attrs ) . "\n";
136 }
137
138 $html = Html::rawElement( 'div',
139 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
140
141 return $html;
142 }
143 }