Move up devunt's name to Developers
[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 = isset( $this->mParams['invert'] ) && $this->mParams['invert'];
62
63 // GetCheck won't work like we want for checks.
64 // Fetch the value in either one of the two following case:
65 // - we have a valid token (form got posted or GET forged by the user)
66 // - checkbox name has a value (false or true), ie is not null
67 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
68 return $invert
69 ? !$request->getBool( $this->mName )
70 : $request->getBool( $this->mName );
71 } else {
72 return $this->getDefault();
73 }
74 }
75 }