MediaWiki  REL1_23
HTMLCheckField.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLCheckField extends HTMLFormField {
00007     function getInputHTML( $value ) {
00008         if ( !empty( $this->mParams['invert'] ) ) {
00009             $value = !$value;
00010         }
00011 
00012         $attr = $this->getTooltipAndAccessKey();
00013         $attr['id'] = $this->mID;
00014 
00015         $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
00016 
00017         if ( $this->mClass !== '' ) {
00018             $attr['class'] = $this->mClass;
00019         }
00020 
00021         if ( $this->mParent->isVForm() ) {
00022             // Nest checkbox inside label.
00023             return Html::rawElement( 'label',
00024                 array(
00025                     'class' => 'mw-ui-checkbox-label'
00026                 ),
00027                 Xml::check( $this->mName, $value, $attr ) . // Html:rawElement doesn't escape contents.
00028                 htmlspecialchars( $this->mLabel ) );
00029         } else {
00030             return Xml::check( $this->mName, $value, $attr )
00031             . '&#160;'
00032             . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
00033         }
00034     }
00035 
00041     function getLabel() {
00042         return '&#160;';
00043     }
00044 
00048     protected function needsLabel() {
00049         return false;
00050     }
00051 
00057     function loadDataFromRequest( $request ) {
00058         $invert = false;
00059         if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
00060             $invert = true;
00061         }
00062 
00063         // GetCheck won't work like we want for checks.
00064         // Fetch the value in either one of the two following case:
00065         // - we have a valid token (form got posted or GET forged by the user)
00066         // - checkbox name has a value (false or true), ie is not null
00067         if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
00068             // XOR has the following truth table, which is what we want
00069             // INVERT VALUE | OUTPUT
00070             // true   true  | false
00071             // false  true  | true
00072             // false  false | false
00073             // true   false | true
00074             return $request->getBool( $this->mName ) xor $invert;
00075         } else {
00076             return $this->getDefault();
00077         }
00078     }
00079 }