MediaWiki
REL1_24
|
00001 <?php 00002 00006 class HTMLRadioField extends HTMLFormField { 00007 function validate( $value, $alldata ) { 00008 $p = parent::validate( $value, $alldata ); 00009 00010 if ( $p !== true ) { 00011 return $p; 00012 } 00013 00014 if ( !is_string( $value ) && !is_int( $value ) ) { 00015 return false; 00016 } 00017 00018 $validOptions = HTMLFormField::flattenOptions( $this->getOptions() ); 00019 00020 if ( in_array( strval( $value ), $validOptions, true ) ) { 00021 return true; 00022 } else { 00023 return $this->msg( 'htmlform-select-badoption' )->parse(); 00024 } 00025 } 00026 00035 function getInputHTML( $value ) { 00036 $html = $this->formatOptions( $this->getOptions(), strval( $value ) ); 00037 00038 return $html; 00039 } 00040 00041 function formatOptions( $options, $value ) { 00042 $html = ''; 00043 00044 $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) ); 00045 $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ); 00046 00047 # @todo Should this produce an unordered list perhaps? 00048 foreach ( $options as $label => $info ) { 00049 if ( is_array( $info ) ) { 00050 $html .= Html::rawElement( 'h1', array(), $label ) . "\n"; 00051 $html .= $this->formatOptions( $info, $value ); 00052 } else { 00053 $id = Sanitizer::escapeId( $this->mID . "-$info" ); 00054 $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + array( 'id' => $id ) ); 00055 $radio .= ' ' . call_user_func( $elementFunc, 'label', array( 'for' => $id ), $label ); 00056 00057 $html .= ' ' . Html::rawElement( 00058 'div', 00059 array( 'class' => 'mw-htmlform-flatlist-item' ), 00060 $radio 00061 ); 00062 } 00063 } 00064 00065 return $html; 00066 } 00067 00068 protected function needsLabel() { 00069 return false; 00070 } 00071 }