Only store currently-existing categories in the categories table
[mediawiki.git] / includes / htmlform / VFormHTMLForm.php
blobc920ac3188ad223f941536714e284d90353e43fd
1 <?php
3 /**
4 * HTML form generation and submission handling, vertical-form 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
21 * @file
24 /**
25 * Compact stacked vertical format for forms.
27 class VFormHTMLForm extends HTMLForm {
28 /**
29 * Wrapper and its legend are never generated in VForm mode.
30 * @var bool
32 protected $mWrapperLegend = false;
34 /**
35 * Symbolic display format name.
36 * @var string
38 protected $displayFormat = 'vform';
40 public function isVForm() {
41 wfDeprecated( __METHOD__, '1.25' );
42 return true;
45 public static function loadInputFromParameters( $fieldname, $descriptor,
46 HTMLForm $parent = null
47 ) {
48 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
49 $field->setShowEmptyLabel( false );
50 return $field;
53 function getHTML( $submitResult ) {
54 // This is required for VForm HTMLForms that use that style regardless
55 // of wgUseMediaWikiUIEverywhere (since they pre-date it).
56 // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated
57 // with the addModuleStyles in SpecialPage->setHeaders.
58 $this->getOutput()->addModuleStyles( [
59 'mediawiki.ui',
60 'mediawiki.ui.button',
61 'mediawiki.ui.input',
62 'mediawiki.ui.checkbox',
63 ] );
65 return parent::getHTML( $submitResult );
68 protected function getFormAttributes() {
69 $attribs = parent::getFormAttributes();
70 $attribs['class'] = [ 'mw-ui-vform', 'mw-ui-container', 'visualClear' ];
71 return $attribs;
74 function wrapForm( $html ) {
75 // Always discard $this->mWrapperLegend
76 return Html::rawElement( 'form', $this->getFormAttributes(), $html );
79 function getButtons() {
80 $buttons = '';
82 if ( $this->mShowSubmit ) {
83 $attribs = [];
85 if ( isset( $this->mSubmitID ) ) {
86 $attribs['id'] = $this->mSubmitID;
89 if ( isset( $this->mSubmitName ) ) {
90 $attribs['name'] = $this->mSubmitName;
93 if ( isset( $this->mSubmitTooltip ) ) {
94 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
97 $attribs['class'] = [
98 'mw-htmlform-submit',
99 'mw-ui-button mw-ui-big mw-ui-block',
101 foreach ( $this->mSubmitFlags as $flag ) {
102 $attribs['class'][] = 'mw-ui-' . $flag;
105 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
108 if ( $this->mShowReset ) {
109 $buttons .= Html::element(
110 'input',
112 'type' => 'reset',
113 'value' => $this->msg( 'htmlform-reset' )->text(),
114 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
116 ) . "\n";
119 if ( $this->mShowCancel ) {
120 $target = $this->mCancelTarget ?: Title::newMainPage();
121 if ( $target instanceof Title ) {
122 $target = $target->getLocalURL();
124 $buttons .= Html::element(
125 'a',
127 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
128 'href' => $target,
130 $this->msg( 'cancel' )->text()
131 ) . "\n";
134 foreach ( $this->mButtons as $button ) {
135 $attrs = [
136 'type' => 'submit',
137 'name' => $button['name'],
138 'value' => $button['value']
141 if ( $button['attribs'] ) {
142 $attrs += $button['attribs'];
145 if ( isset( $button['id'] ) ) {
146 $attrs['id'] = $button['id'];
149 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
150 $attrs['class'][] = 'mw-ui-button mw-ui-big mw-ui-block';
152 $buttons .= Html::element( 'input', $attrs ) . "\n";
155 if ( !$buttons ) {
156 return '';
159 return Html::rawElement( 'div',
160 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";