Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / htmlform / HTMLCheckField.php
blob4942327fc7f02ed8eb4dce4a61437bc19db2192e
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 $chkLabel = Xml::check( $this->mName, $value, $attr )
24 . '&#160;'
25 . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
27 if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
28 $chkLabel = Html::rawElement(
29 'div',
30 array( 'class' => 'mw-ui-checkbox' ),
31 $chkLabel
35 return $chkLabel;
38 /**
39 * For a checkbox, the label goes on the right hand side, and is
40 * added in getInputHTML(), rather than HTMLFormField::getRow()
41 * @return string
43 function getLabel() {
44 return '&#160;';
47 /**
48 * checkboxes don't need a label.
49 * @return bool
51 protected function needsLabel() {
52 return false;
55 /**
56 * @param WebRequest $request
58 * @return string
60 function loadDataFromRequest( $request ) {
61 $invert = isset( $this->mParams['invert'] ) && $this->mParams['invert'];
63 // GetCheck won't work like we want for checks.
64 // Fetch the value in either one of the two following case:
65 // - we have a valid token (form got posted or GET forged by the user)
66 // - checkbox name has a value (false or true), ie is not null
67 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
68 return $invert
69 ? !$request->getBool( $this->mName )
70 : $request->getBool( $this->mName );
71 } else {
72 return $this->getDefault();