MWException: Don't send headers multiple times
[mediawiki.git] / includes / htmlform / HTMLCheckField.php
blobc7ec014772e2e4b59b1582c95db00f8b41a6cb00
1 <?php
3 /**
4 * A checkbox field
5 */
6 class HTMLCheckField extends HTMLFormField {
7 function getInputHTML( $value ) {
8 if ( !empty( $this->mParams['invert'] ) ) {
9 $value = !$value;
12 $attr = $this->getTooltipAndAccessKey();
13 $attr['id'] = $this->mID;
15 $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
17 if ( $this->mClass !== '' ) {
18 $attr['class'] = $this->mClass;
21 if ( $this->mParent->isVForm() ) {
22 // Nest checkbox inside label.
23 return Html::rawElement( 'label',
24 array(
25 'class' => 'mw-ui-checkbox-label'
27 Xml::check( $this->mName, $value, $attr ) . // Html:rawElement doesn't escape contents.
28 htmlspecialchars( $this->mLabel ) );
29 } else {
30 return Xml::check( $this->mName, $value, $attr )
31 . '&#160;'
32 . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
36 /**
37 * For a checkbox, the label goes on the right hand side, and is
38 * added in getInputHTML(), rather than HTMLFormField::getRow()
39 * @return string
41 function getLabel() {
42 return '&#160;';
45 /**
46 * checkboxes don't need a label.
47 * @return bool
49 protected function needsLabel() {
50 return false;
53 /**
54 * @param WebRequest $request
56 * @return string
58 function loadDataFromRequest( $request ) {
59 $invert = false;
60 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
61 $invert = true;
64 // GetCheck won't work like we want for checks.
65 // Fetch the value in either one of the two following case:
66 // - we have a valid token (form got posted or GET forged by the user)
67 // - checkbox name has a value (false or true), ie is not null
68 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
69 // XOR has the following truth table, which is what we want
70 // INVERT VALUE | OUTPUT
71 // true true | false
72 // false true | true
73 // false false | false
74 // true false | true
75 return $request->getBool( $this->mName ) xor $invert;
76 } else {
77 return $this->getDefault();