Merge "Added more filter options to $wgRCFeeds"
[mediawiki.git] / includes / htmlform / HTMLSelectOrOtherField.php
blob21f3b778ccfb46d303f91cb8374448251ac400a9
1 <?php
3 /**
4 * Select dropdown field, with an additional "other" textbox.
5 */
6 class HTMLSelectOrOtherField extends HTMLTextField {
7 function __construct( $params ) {
8 parent::__construct( $params );
9 $this->getOptions();
10 if ( !in_array( 'other', $this->mOptions, true ) ) {
11 $msg =
12 isset( $params['other'] )
13 ? $params['other']
14 : wfMessage( 'htmlform-selectorother-other' )->text();
15 $this->mOptions[$msg] = 'other';
20 function getInputHTML( $value ) {
21 $valInSelect = false;
23 if ( $value !== false ) {
24 $value = strval( $value );
25 $valInSelect = in_array(
26 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true
30 $selected = $valInSelect ? $value : 'other';
32 $select = new XmlSelect( $this->mName, $this->mID, $selected );
33 $select->addOptions( $this->getOptions() );
35 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
37 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() );
39 if ( !empty( $this->mParams['disabled'] ) ) {
40 $select->setAttribute( 'disabled', 'disabled' );
41 $tbAttribs['disabled'] = 'disabled';
44 if ( isset( $this->mParams['tabindex'] ) ) {
45 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
46 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
49 $select = $select->getHTML();
51 if ( isset( $this->mParams['maxlength'] ) ) {
52 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
55 if ( $this->mClass !== '' ) {
56 $tbAttribs['class'] = $this->mClass;
59 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
61 return "$select<br />\n$textbox";
64 /**
65 * @param $request WebRequest
67 * @return String
69 function loadDataFromRequest( $request ) {
70 if ( $request->getCheck( $this->mName ) ) {
71 $val = $request->getText( $this->mName );
73 if ( $val === 'other' ) {
74 $val = $request->getText( $this->mName . '-other' );
77 return $val;
78 } else {
79 return $this->getDefault();