MediaWiki REL1_37
HTMLCheckField.php
Go to the documentation of this file.
1<?php
2
9
14 public function getInputHTML( $value ) {
16
17 if ( !empty( $this->mParams['invert'] ) ) {
18 $value = !$value;
19 }
20
21 $attr = $this->getTooltipAndAccessKey();
22 $attr['id'] = $this->mID;
23
24 $attr += $this->getAttributes( [ 'disabled', 'tabindex' ] );
25
26 if ( $this->mClass !== '' ) {
27 $attr['class'] = $this->mClass;
28 }
29
30 $attrLabel = [ 'for' => $this->mID ];
31 if ( isset( $attr['title'] ) ) {
32 // propagate tooltip to label
33 $attrLabel['title'] = $attr['title'];
34 }
35
36 $chkLabel = Xml::check( $this->mName, $value, $attr ) .
37 "\u{00A0}" .
38 Html::rawElement( 'label', $attrLabel, $this->mLabel );
39
40 if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
41 $chkLabel = Html::rawElement(
42 'div',
43 [ 'class' => 'mw-ui-checkbox' ],
44 $chkLabel
45 );
46 }
47
48 return $chkLabel;
49 }
50
58 public function getInputOOUI( $value ) {
59 if ( !empty( $this->mParams['invert'] ) ) {
60 $value = !$value;
61 }
62
63 $attr = $this->getTooltipAndAccessKeyOOUI();
64 $attr['id'] = $this->mID;
65 $attr['name'] = $this->mName;
66
67 $attr += OOUI\Element::configFromHtmlAttributes(
68 $this->getAttributes( [ 'disabled', 'tabindex' ] )
69 );
70
71 if ( $this->mClass !== '' ) {
72 $attr['classes'] = [ $this->mClass ];
73 }
74
75 $attr['selected'] = $value;
76 $attr['value'] = '1'; // Nasty hack, but needed to make this work
77
78 return new OOUI\CheckboxInputWidget( $attr );
79 }
80
91 public function getLabel() {
92 if ( $this->mParent instanceof OOUIHTMLForm ) {
93 return $this->mLabel;
94 } elseif (
95 $this->mParent instanceof HTMLForm &&
96 $this->mParent->getDisplayFormat() === 'div'
97 ) {
98 return '';
99 } else {
100 return "\u{00A0}";
101 }
102 }
103
109 protected function getLabelAlignOOUI() {
110 return 'inline';
111 }
112
118 protected function needsLabel() {
119 return false;
120 }
121
128 public function loadDataFromRequest( $request ) {
129 $invert = isset( $this->mParams['invert'] ) && $this->mParams['invert'];
130
131 // Fetch the value in either one of the two following case:
132 // - we have a valid submit attempt (form was just submitted)
133 // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier)
134 if ( $this->isSubmitAttempt( $request ) || $request->getCheck( $this->mName ) ) {
135 return $invert
136 ? !$request->getBool( $this->mName )
137 : $request->getBool( $this->mName );
138 } else {
139 return (bool)$this->getDefault();
140 }
141 }
142}
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
A checkbox field.
getLabel()
For a checkbox, the label goes on the right hand side, and is added in getInputHTML(),...
loadDataFromRequest( $request)
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getLabelAlignOOUI()
Get label alignment when generating field for OOUI.
getInputOOUI( $value)
Get the OOUI version of this field.
needsLabel()
checkboxes don't need a label.
The parent class to generate form fields.
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
isSubmitAttempt(WebRequest $request)
Can we assume that the request is an attempt to submit a HTMLForm, as opposed to an attempt to just v...
getAttributes(array $list)
Returns the given attributes from the parameters.
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:143
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:483
Compact stacked vertical format for forms, implemented using OOUI widgets.
Compact stacked vertical format for forms.