6 class HTMLCheckField
extends HTMLFormField
{
7 function getInputHTML( $value ) {
8 if ( !empty( $this->mParams
['invert'] ) ) {
12 $attr = $this->getTooltipAndAccessKey();
13 $attr['id'] = $this->mID
;
15 if ( !empty( $this->mParams
['disabled'] ) ) {
16 $attr['disabled'] = 'disabled';
19 if ( $this->mClass
!== '' ) {
20 $attr['class'] = $this->mClass
;
23 if ( $this->mParent
->isVForm() ) {
24 // Nest checkbox inside label.
25 return Html
::rawElement( 'label',
27 'class' => 'mw-ui-checkbox-label'
29 Xml
::check( $this->mName
, $value, $attr ) . // Html:rawElement doesn't escape contents.
30 htmlspecialchars( $this->mLabel
) );
32 return Xml
::check( $this->mName
, $value, $attr )
34 . Html
::rawElement( 'label', array( 'for' => $this->mID
), $this->mLabel
);
39 * For a checkbox, the label goes on the right hand side, and is
40 * added in getInputHTML(), rather than HTMLFormField::getRow()
48 * checkboxes don't need a label.
50 protected function needsLabel() {
55 * @param $request WebRequest
59 function loadDataFromRequest( $request ) {
61 if ( isset( $this->mParams
['invert'] ) && $this->mParams
['invert'] ) {
65 // GetCheck won't work like we want for checks.
66 // Fetch the value in either one of the two following case:
67 // - we have a valid token (form got posted or GET forged by the user)
68 // - checkbox name has a value (false or true), ie is not null
69 if ( $request->getCheck( 'wpEditToken' ) ||
$request->getVal( $this->mName
) !== null ) {
70 // XOR has the following truth table, which is what we want
71 // INVERT VALUE | OUTPUT
74 // false false | false
76 return $request->getBool( $this->mName
) xor $invert;
78 return $this->getDefault();