5 class HTMLCheckField
extends HTMLFormField
{
6 function getInputHTML( $value ) {
7 if ( ! empty( $this->mParams
[ 'invert' ] ) ) {
11 $attr = $this->getTooltipAndAccessKey();
12 $attr[ 'id' ] = $this->mID
;
14 if ( ! empty( $this->mParams
[ 'disabled' ] ) ) {
15 $attr[ 'disabled' ] = 'disabled';
18 if ( $this->mClass
!== '' ) {
19 $attr[ 'class' ] = $this->mClass
;
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
) );
29 return Xml
::check( $this->mName
, $value, $attr ) . ' ' . Html
::rawElement( 'label', array( 'for' => $this->mID
), $this->mLabel
);
34 * For a checkbox, the label goes on the right hand side, and is
35 * added in getInputHTML(), rather than HTMLFormField::getRow()
43 * checkboxes don't need a label.
45 protected function needsLabel() {
50 * @param $request WebRequest
54 function loadDataFromRequest( $request ) {
56 if ( isset( $this->mParams
[ 'invert' ] ) && $this->mParams
[ 'invert' ] ) {
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
69 // false false | false
71 return $request->getBool( $this->mName
) xor $invert;
73 return $this->getDefault();