Merge "Rename Skin::getUsableSkins() to Skin::getAllowedSkins()"
[lhc/web/wiklou.git] / includes / htmlform / HTMLSelectOrOtherField.php
1 <?php
2
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';
16 }
17
18 }
19
20 function getInputHTML( $value ) {
21 $valInSelect = false;
22
23 if ( $value !== false ) {
24 $value = strval( $value );
25 $valInSelect = in_array(
26 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true
27 );
28 }
29
30 $selected = $valInSelect ? $value : 'other';
31
32 $select = new XmlSelect( $this->mName, $this->mID, $selected );
33 $select->addOptions( $this->getOptions() );
34
35 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
36
37 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() );
38
39 if ( !empty( $this->mParams['disabled'] ) ) {
40 $select->setAttribute( 'disabled', 'disabled' );
41 $tbAttribs['disabled'] = 'disabled';
42 }
43
44 if ( isset( $this->mParams['tabindex'] ) ) {
45 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
46 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
47 }
48
49 $select = $select->getHTML();
50
51 if ( isset( $this->mParams['maxlength'] ) ) {
52 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
53 }
54
55 if ( $this->mClass !== '' ) {
56 $tbAttribs['class'] = $this->mClass;
57 }
58
59 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
60
61 return "$select<br />\n$textbox";
62 }
63
64 /**
65 * @param $request WebRequest
66 *
67 * @return String
68 */
69 function loadDataFromRequest( $request ) {
70 if ( $request->getCheck( $this->mName ) ) {
71 $val = $request->getText( $this->mName );
72
73 if ( $val === 'other' ) {
74 $val = $request->getText( $this->mName . '-other' );
75 }
76
77 return $val;
78 } else {
79 return $this->getDefault();
80 }
81 }
82 }