MediaWiki REL1_35
VFormHTMLForm.php
Go to the documentation of this file.
1<?php
2
29class VFormHTMLForm extends HTMLForm {
34 protected $mWrapperLegend = false;
35
40 protected $displayFormat = 'vform';
41
42 public static function loadInputFromParameters( $fieldname, $descriptor,
43 HTMLForm $parent = null
44 ) {
45 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
46 $field->setShowEmptyLabel( false );
47 return $field;
48 }
49
50 public function getHTML( $submitResult ) {
51 // This is required for VForm HTMLForms that use that style regardless
52 // of wgUseMediaWikiUIEverywhere (since they pre-date it).
53 // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated
54 // with the addModuleStyles in SpecialPage->setHeaders.
55 $this->getOutput()->addModuleStyles( [
56 'mediawiki.ui',
57 'mediawiki.ui.button',
58 'mediawiki.ui.input',
59 'mediawiki.ui.checkbox',
60 ] );
61
62 return parent::getHTML( $submitResult );
63 }
64
65 protected function getFormAttributes() {
66 $attribs = parent::getFormAttributes();
67 $attribs['class'] = [ 'mw-htmlform', 'mw-ui-vform', 'mw-ui-container' ];
68 return $attribs;
69 }
70
71 public function wrapForm( $html ) {
72 // Always discard $this->mWrapperLegend
73 return Html::rawElement( 'form', $this->getFormAttributes(), $html );
74 }
75
76 public function getButtons() {
77 $buttons = '';
78
79 if ( $this->mShowSubmit ) {
80 $attribs = [];
81
82 if ( isset( $this->mSubmitID ) ) {
83 $attribs['id'] = $this->mSubmitID;
84 }
85
86 if ( isset( $this->mSubmitName ) ) {
87 $attribs['name'] = $this->mSubmitName;
88 }
89
90 if ( isset( $this->mSubmitTooltip ) ) {
91 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
92 }
93
94 $attribs['class'] = [
95 'mw-htmlform-submit',
96 'mw-ui-button mw-ui-big mw-ui-block',
97 ];
98 foreach ( $this->mSubmitFlags as $flag ) {
99 $attribs['class'][] = 'mw-ui-' . $flag;
100 }
101
102 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
103 }
104
105 if ( $this->mShowReset ) {
106 $buttons .= Html::element(
107 'input',
108 [
109 'type' => 'reset',
110 'value' => $this->msg( 'htmlform-reset' )->text(),
111 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
112 ]
113 ) . "\n";
114 }
115
116 if ( $this->mShowCancel ) {
117 $target = $this->mCancelTarget ?: Title::newMainPage();
118 if ( $target instanceof Title ) {
119 $target = $target->getLocalURL();
120 }
121 $buttons .= Html::element(
122 'a',
123 [
124 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
125 'href' => $target,
126 ],
127 $this->msg( 'cancel' )->text()
128 ) . "\n";
129 }
130
131 foreach ( $this->mButtons as $button ) {
132 $attrs = [
133 'type' => 'submit',
134 'name' => $button['name'],
135 'value' => $button['value']
136 ];
137
138 if ( $button['attribs'] ) {
139 $attrs += $button['attribs'];
140 }
141
142 if ( isset( $button['id'] ) ) {
143 $attrs['id'] = $button['id'];
144 }
145
146 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
147 $attrs['class'][] = 'mw-ui-button mw-ui-big mw-ui-block';
148
149 $buttons .= Html::element( 'input', $attrs ) . "\n";
150 }
151
152 if ( !$buttons ) {
153 return '';
154 }
155
156 return Html::rawElement( 'div',
157 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
158 }
159}
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:135
getSubmitText()
Get the text for the submit button, either customised or a default.
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition Linker.php:2304
Represents a title within MediaWiki.
Definition Title.php:42
Compact stacked vertical format for forms.
getHTML( $submitResult)
Returns the raw HTML generated by the form.
string $displayFormat
Symbolic display format name.
getFormAttributes()
Get HTML attributes for the <form> tag.
getButtons()
Get the submit and (potentially) reset buttons.
bool $mWrapperLegend
Wrapper and its legend are never generated in VForm mode.
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field Stable to override.
wrapForm( $html)
Wrap the form innards in an actual "<form>" element Stable to override.