Give links to a user's suppressed edits on Special:Contribs
[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 $valInSelect = in_array( $value, HTMLFormField::flattenOptions( $this->getOptions() ) );
25 }
26
27 $selected = $valInSelect ? $value : 'other';
28
29 $select = new XmlSelect( $this->mName, $this->mID, $selected );
30 $select->addOptions( $this->getOptions() );
31
32 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
33
34 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() );
35
36 if ( !empty( $this->mParams['disabled'] ) ) {
37 $select->setAttribute( 'disabled', 'disabled' );
38 $tbAttribs['disabled'] = 'disabled';
39 }
40
41 if ( isset( $this->mParams['tabindex'] ) ) {
42 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
43 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
44 }
45
46 $select = $select->getHTML();
47
48 if ( isset( $this->mParams['maxlength'] ) ) {
49 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
50 }
51
52 if ( $this->mClass !== '' ) {
53 $tbAttribs['class'] = $this->mClass;
54 }
55
56 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
57
58 return "$select<br />\n$textbox";
59 }
60
61 /**
62 * @param $request WebRequest
63 *
64 * @return String
65 */
66 function loadDataFromRequest( $request ) {
67 if ( $request->getCheck( $this->mName ) ) {
68 $val = $request->getText( $this->mName );
69
70 if ( $val == 'other' ) {
71 $val = $request->getText( $this->mName . '-other' );
72 }
73
74 return $val;
75 } else {
76 return $this->getDefault();
77 }
78 }
79 }