2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
/**
|
|
|
|
|
* A checkbox field
|
|
|
|
|
*/
|
|
|
|
|
class HTMLCheckField extends HTMLFormField {
|
|
|
|
|
function getInputHTML( $value ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( !empty( $this->mParams['invert'] ) ) {
|
|
|
|
|
$value = !$value;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$attr = $this->getTooltipAndAccessKey();
|
2013-11-19 13:08:16 +00:00
|
|
|
$attr['id'] = $this->mID;
|
2013-11-19 12:55:50 +00:00
|
|
|
|
2013-05-02 18:27:44 +00:00
|
|
|
$attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$attr['class'] = $this->mClass;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->mParent->isVForm() ) {
|
|
|
|
|
// Nest checkbox inside label.
|
2013-11-19 13:08:16 +00:00
|
|
|
return Html::rawElement( 'label',
|
|
|
|
|
array(
|
2013-11-19 12:55:50 +00:00
|
|
|
'class' => 'mw-ui-checkbox-label'
|
2013-11-19 13:08:16 +00:00
|
|
|
),
|
2014-04-15 14:58:51 +00:00
|
|
|
Xml::check( $this->mName, $value, $attr ) . $this->mLabel );
|
2013-11-19 12:55:50 +00:00
|
|
|
} else {
|
2013-11-19 13:08:16 +00:00
|
|
|
return Xml::check( $this->mName, $value, $attr )
|
|
|
|
|
. ' '
|
|
|
|
|
. Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For a checkbox, the label goes on the right hand side, and is
|
|
|
|
|
* added in getInputHTML(), rather than HTMLFormField::getRow()
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return string
|
2013-11-19 12:55:50 +00:00
|
|
|
*/
|
|
|
|
|
function getLabel() {
|
|
|
|
|
return ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* checkboxes don't need a label.
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return bool
|
2013-11-19 12:55:50 +00:00
|
|
|
*/
|
|
|
|
|
protected function needsLabel() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param WebRequest $request
|
2013-11-19 12:55:50 +00:00
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return string
|
2013-11-19 12:55:50 +00:00
|
|
|
*/
|
|
|
|
|
function loadDataFromRequest( $request ) {
|
|
|
|
|
$invert = false;
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
$invert = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCheck won't work like we want for checks.
|
|
|
|
|
// Fetch the value in either one of the two following case:
|
|
|
|
|
// - we have a valid token (form got posted or GET forged by the user)
|
|
|
|
|
// - checkbox name has a value (false or true), ie is not null
|
|
|
|
|
if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
|
|
|
|
|
// XOR has the following truth table, which is what we want
|
|
|
|
|
// INVERT VALUE | OUTPUT
|
|
|
|
|
// true true | false
|
|
|
|
|
// false true | true
|
|
|
|
|
// false false | false
|
|
|
|
|
// true false | true
|
|
|
|
|
return $request->getBool( $this->mName ) xor $invert;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->getDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|