MediaWiki REL1_37
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->getCancelTargetURL();
118 $buttons .= Html::element(
119 'a',
120 [
121 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
122 'href' => $target,
123 ],
124 $this->msg( 'cancel' )->text()
125 ) . "\n";
126 }
127
128 foreach ( $this->mButtons as $button ) {
129 $attrs = [
130 'type' => 'submit',
131 'name' => $button['name'],
132 'value' => $button['value']
133 ];
134
135 if ( $button['attribs'] ) {
136 $attrs += $button['attribs'];
137 }
138
139 if ( isset( $button['id'] ) ) {
140 $attrs['id'] = $button['id'];
141 }
142
143 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
144 $attrs['class'][] = 'mw-ui-button mw-ui-big mw-ui-block';
145
146 $buttons .= Html::element( 'input', $attrs ) . "\n";
147 }
148
149 if ( !$buttons ) {
150 return '';
151 }
152
153 return Html::rawElement( 'div',
154 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
155 }
156}
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:143
getSubmitText()
Get the text for the submit button, either customised or a default.
getCancelTargetURL()
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition Linker.php:2455
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.
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.