Merge "UnregisteredLocalFile.php: Override File::getBitDepth() stub"
[lhc/web/wiklou.git] / includes / htmlform / HTMLCheckField.php
1 <?php
2
3 /**
4 * A checkbox field
5 */
6 class HTMLCheckField extends HTMLFormField {
7 function getInputHTML( $value ) {
8 global $wgUseMediaWikiUIEverywhere;
9
10 if ( !empty( $this->mParams['invert'] ) ) {
11 $value = !$value;
12 }
13
14 $attr = $this->getTooltipAndAccessKey();
15 $attr['id'] = $this->mID;
16
17 $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
18
19 if ( $this->mClass !== '' ) {
20 $attr['class'] = $this->mClass;
21 }
22
23 $chkLabel = Xml::check( $this->mName, $value, $attr )
24 . '&#160;'
25 . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
26
27 if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
28 $chkLabel = Html::rawElement(
29 'div',
30 array( 'class' => 'mw-ui-checkbox' ),
31 $chkLabel
32 );
33 }
34
35 return $chkLabel;
36 }
37
38 /**
39 * For a checkbox, the label goes on the right hand side, and is
40 * added in getInputHTML(), rather than HTMLFormField::getRow()
41 * @return string
42 */
43 function getLabel() {
44 return '&#160;';
45 }
46
47 /**
48 * checkboxes don't need a label.
49 * @return bool
50 */
51 protected function needsLabel() {
52 return false;
53 }
54
55 /**
56 * @param WebRequest $request
57 *
58 * @return string
59 */
60 function loadDataFromRequest( $request ) {
61 $invert = false;
62 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
63 $invert = true;
64 }
65
66 // GetCheck won't work like we want for checks.
67 // Fetch the value in either one of the two following case:
68 // - we have a valid token (form got posted or GET forged by the user)
69 // - checkbox name has a value (false or true), ie is not null
70 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
71 // XOR has the following truth table, which is what we want
72 // INVERT VALUE | OUTPUT
73 // true true | false
74 // false true | true
75 // false false | false
76 // true false | true
77 return $request->getBool( $this->mName ) xor $invert;
78 } else {
79 return $this->getDefault();
80 }
81 }
82 }