6 class HTMLCheckField
extends HTMLFormField
{
7 function getInputHTML( $value ) {
8 global $wgUseMediaWikiUIEverywhere;
10 if ( !empty( $this->mParams
['invert'] ) ) {
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 $chkLabel = Xml
::check( $this->mName
, $value, $attr )
25 . Html
::rawElement( 'label', array( 'for' => $this->mID
), $this->mLabel
);
27 if ( $wgUseMediaWikiUIEverywhere ||
$this->mParent
instanceof VFormHTMLForm
) {
28 $chkLabel = Html
::rawElement(
30 array( 'class' => 'mw-ui-checkbox' ),
39 * Get the OOUI version of this field.
41 * @param string $value
42 * @return OOUI\CheckboxInputWidget The checkbox widget.
44 public function getInputOOUI( $value ) {
45 if ( !empty( $this->mParams
['invert'] ) ) {
49 $attr = $this->getTooltipAndAccessKey();
50 $attr['id'] = $this->mID
;
51 $attr['name'] = $this->mName
;
53 $attr +
= $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) );
55 if ( $this->mClass
!== '' ) {
56 $attr['classes'] = array( $this->mClass
);
59 $attr['selected'] = $value;
60 $attr['value'] = '1'; // Nasty hack, but needed to make this work
62 return new OOUI\
CheckboxInputWidget( $attr );
66 * For a checkbox, the label goes on the right hand side, and is
67 * added in getInputHTML(), rather than HTMLFormField::getRow()
69 * ...unless OOUI is being used, in which case we actually return
75 if ( $this->mParent
instanceof OOUIHTMLForm
) {
83 * Get label alignment when generating field for OOUI.
84 * @return string 'left', 'right', 'top' or 'inline'
86 protected function getLabelAlignOOUI() {
91 * checkboxes don't need a label.
94 protected function needsLabel() {
99 * @param WebRequest $request
103 function loadDataFromRequest( $request ) {
104 $invert = isset( $this->mParams
['invert'] ) && $this->mParams
['invert'];
106 // GetCheck won't work like we want for checks.
107 // Fetch the value in either one of the two following case:
108 // - we have a valid token (form got posted or GET forged by the user)
109 // - checkbox name has a value (false or true), ie is not null
110 if ( $request->getCheck( 'wpEditToken' ) ||
$request->getVal( $this->mName
) !== null ) {
112 ?
!$request->getBool( $this->mName
)
113 : $request->getBool( $this->mName
);
115 return $this->getDefault();