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