Properly deprecate srprop=score|hasrelated
[mediawiki.git] / includes / htmlform / HTMLSelectOrOtherField.php
blobcbf7d122d71786eb17f7472d685dbc60cdbaf2ef
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 // Have 'other' always as first element
16 $this->mOptions = array( $msg => 'other' ) + $this->mOptions;
21 function getInputHTML( $value ) {
22 $valInSelect = false;
24 if ( $value !== false ) {
25 $value = strval( $value );
26 $valInSelect = in_array(
27 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true
31 $selected = $valInSelect ? $value : 'other';
33 $select = new XmlSelect( $this->mName, $this->mID, $selected );
34 $select->addOptions( $this->getOptions() );
36 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
38 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() );
40 if ( !empty( $this->mParams['disabled'] ) ) {
41 $select->setAttribute( 'disabled', 'disabled' );
42 $tbAttribs['disabled'] = 'disabled';
45 if ( isset( $this->mParams['tabindex'] ) ) {
46 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
47 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
50 $select = $select->getHTML();
52 if ( isset( $this->mParams['maxlength'] ) ) {
53 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
56 if ( $this->mClass !== '' ) {
57 $tbAttribs['class'] = $this->mClass;
60 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
62 return "$select<br />\n$textbox";
65 /**
66 * @param WebRequest $request
68 * @return string
70 function loadDataFromRequest( $request ) {
71 if ( $request->getCheck( $this->mName ) ) {
72 $val = $request->getText( $this->mName );
74 if ( $val === 'other' ) {
75 $val = $request->getText( $this->mName . '-other' );
78 return $val;
79 } else {
80 return $this->getDefault();