MediaWiki
REL1_24
|
00001 <?php 00002 00006 class HTMLCheckField extends HTMLFormField { 00007 function getInputHTML( $value ) { 00008 global $wgUseMediaWikiUIEverywhere; 00009 00010 if ( !empty( $this->mParams['invert'] ) ) { 00011 $value = !$value; 00012 } 00013 00014 $attr = $this->getTooltipAndAccessKey(); 00015 $attr['id'] = $this->mID; 00016 00017 $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) ); 00018 00019 if ( $this->mClass !== '' ) { 00020 $attr['class'] = $this->mClass; 00021 } 00022 00023 if ( $this->mParent->isVForm() ) { 00024 // Nest checkbox inside label. 00025 return Html::rawElement( 'label', 00026 array( 00027 'class' => 'mw-ui-checkbox-label' 00028 ), 00029 Xml::check( $this->mName, $value, $attr ) . $this->mLabel ); 00030 } else { 00031 $chkLabel = Xml::check( $this->mName, $value, $attr ) 00032 . ' ' 00033 . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel ); 00034 00035 if ( $wgUseMediaWikiUIEverywhere ) { 00036 $chkLabel = Html::rawElement( 00037 'div', 00038 array( 'class' => 'mw-ui-checkbox' ), 00039 $chkLabel 00040 ); 00041 } 00042 00043 return $chkLabel; 00044 } 00045 } 00046 00052 function getLabel() { 00053 return ' '; 00054 } 00055 00060 protected function needsLabel() { 00061 return false; 00062 } 00063 00069 function loadDataFromRequest( $request ) { 00070 $invert = false; 00071 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) { 00072 $invert = true; 00073 } 00074 00075 // GetCheck won't work like we want for checks. 00076 // Fetch the value in either one of the two following case: 00077 // - we have a valid token (form got posted or GET forged by the user) 00078 // - checkbox name has a value (false or true), ie is not null 00079 if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) { 00080 // XOR has the following truth table, which is what we want 00081 // INVERT VALUE | OUTPUT 00082 // true true | false 00083 // false true | true 00084 // false false | false 00085 // true false | true 00086 return $request->getBool( $this->mName ) xor $invert; 00087 } else { 00088 return $this->getDefault(); 00089 } 00090 } 00091 }