MediaWiki
REL1_23
|
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 $this->mOptions[$msg] = 'other'; 00016 } 00017 00018 } 00019 00020 function getInputHTML( $value ) { 00021 $valInSelect = false; 00022 00023 if ( $value !== false ) { 00024 $value = strval( $value ); 00025 $valInSelect = in_array( 00026 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true 00027 ); 00028 } 00029 00030 $selected = $valInSelect ? $value : 'other'; 00031 00032 $select = new XmlSelect( $this->mName, $this->mID, $selected ); 00033 $select->addOptions( $this->getOptions() ); 00034 00035 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' ); 00036 00037 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() ); 00038 00039 if ( !empty( $this->mParams['disabled'] ) ) { 00040 $select->setAttribute( 'disabled', 'disabled' ); 00041 $tbAttribs['disabled'] = 'disabled'; 00042 } 00043 00044 if ( isset( $this->mParams['tabindex'] ) ) { 00045 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] ); 00046 $tbAttribs['tabindex'] = $this->mParams['tabindex']; 00047 } 00048 00049 $select = $select->getHTML(); 00050 00051 if ( isset( $this->mParams['maxlength'] ) ) { 00052 $tbAttribs['maxlength'] = $this->mParams['maxlength']; 00053 } 00054 00055 if ( $this->mClass !== '' ) { 00056 $tbAttribs['class'] = $this->mClass; 00057 } 00058 00059 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs ); 00060 00061 return "$select<br />\n$textbox"; 00062 } 00063 00069 function loadDataFromRequest( $request ) { 00070 if ( $request->getCheck( $this->mName ) ) { 00071 $val = $request->getText( $this->mName ); 00072 00073 if ( $val === 'other' ) { 00074 $val = $request->getText( $this->mName . '-other' ); 00075 } 00076 00077 return $val; 00078 } else { 00079 return $this->getDefault(); 00080 } 00081 } 00082 }