MediaWiki
REL1_24
|
00001 <?php 00002 00006 class HTMLSelectOrOtherField extends HTMLTextField { 00007 function __construct( $params ) { 00008 parent::__construct( $params ); 00009 $this->getOptions(); 00010 if ( !in_array( 'other', $this->mOptions, true ) ) { 00011 $msg = 00012 isset( $params['other'] ) 00013 ? $params['other'] 00014 : wfMessage( 'htmlform-selectorother-other' )->text(); 00015 // Have 'other' always as first element 00016 $this->mOptions = array( $msg => 'other' ) + $this->mOptions; 00017 } 00018 00019 } 00020 00021 function getInputHTML( $value ) { 00022 $valInSelect = false; 00023 00024 if ( $value !== false ) { 00025 $value = strval( $value ); 00026 $valInSelect = in_array( 00027 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true 00028 ); 00029 } 00030 00031 $selected = $valInSelect ? $value : 'other'; 00032 00033 $select = new XmlSelect( $this->mName, $this->mID, $selected ); 00034 $select->addOptions( $this->getOptions() ); 00035 00036 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' ); 00037 00038 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() ); 00039 00040 if ( !empty( $this->mParams['disabled'] ) ) { 00041 $select->setAttribute( 'disabled', 'disabled' ); 00042 $tbAttribs['disabled'] = 'disabled'; 00043 } 00044 00045 if ( isset( $this->mParams['tabindex'] ) ) { 00046 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] ); 00047 $tbAttribs['tabindex'] = $this->mParams['tabindex']; 00048 } 00049 00050 $select = $select->getHTML(); 00051 00052 if ( isset( $this->mParams['maxlength'] ) ) { 00053 $tbAttribs['maxlength'] = $this->mParams['maxlength']; 00054 } 00055 00056 if ( $this->mClass !== '' ) { 00057 $tbAttribs['class'] = $this->mClass; 00058 } 00059 00060 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs ); 00061 00062 return "$select<br />\n$textbox"; 00063 } 00064 00070 function loadDataFromRequest( $request ) { 00071 if ( $request->getCheck( $this->mName ) ) { 00072 $val = $request->getText( $this->mName ); 00073 00074 if ( $val === 'other' ) { 00075 $val = $request->getText( $this->mName . '-other' ); 00076 } 00077 00078 return $val; 00079 } else { 00080 return $this->getDefault(); 00081 } 00082 } 00083 }