Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / HTMLCheckField.php
blob5f70362a5aea7faa09cd96261e473e5c8cdd8cbb
1 <?php
3 /**
4 * A checkbox field
5 */
6 class HTMLCheckField extends HTMLFormField {
7 function getInputHTML( $value ) {
8 global $wgUseMediaWikiUIEverywhere;
10 if ( !empty( $this->mParams['invert'] ) ) {
11 $value = !$value;
14 $attr = $this->getTooltipAndAccessKey();
15 $attr['id'] = $this->mID;
17 $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
19 if ( $this->mClass !== '' ) {
20 $attr['class'] = $this->mClass;
23 if ( $this->mParent->isVForm() ) {
24 // Nest checkbox inside label.
25 return Html::rawElement( 'label',
26 array(
27 'class' => 'mw-ui-checkbox-label'
29 Xml::check( $this->mName, $value, $attr ) . $this->mLabel );
30 } else {
31 $chkLabel = Xml::check( $this->mName, $value, $attr )
32 . '&#160;'
33 . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
35 if ( $wgUseMediaWikiUIEverywhere ) {
36 $chkLabel = Html::rawElement(
37 'div',
38 array( 'class' => 'mw-ui-checkbox' ),
39 $chkLabel
43 return $chkLabel;
47 /**
48 * For a checkbox, the label goes on the right hand side, and is
49 * added in getInputHTML(), rather than HTMLFormField::getRow()
50 * @return string
52 function getLabel() {
53 return '&#160;';
56 /**
57 * checkboxes don't need a label.
58 * @return bool
60 protected function needsLabel() {
61 return false;
64 /**
65 * @param WebRequest $request
67 * @return string
69 function loadDataFromRequest( $request ) {
70 $invert = false;
71 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
72 $invert = true;
75 // GetCheck won't work like we want for checks.
76 // Fetch the value in either one of the two following case:
77 // - we have a valid token (form got posted or GET forged by the user)
78 // - checkbox name has a value (false or true), ie is not null
79 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
80 // XOR has the following truth table, which is what we want
81 // INVERT VALUE | OUTPUT
82 // true true | false
83 // false true | true
84 // false false | false
85 // true false | true
86 return $request->getBool( $this->mName ) xor $invert;
87 } else {
88 return $this->getDefault();