MediaWiki  1.27.1
HTMLSelectOrOtherField.php
Go to the documentation of this file.
1 <?php
2 
10  function __construct( $params ) {
11  parent::__construct( $params );
12  $this->getOptions();
13  if ( !in_array( 'other', $this->mOptions, true ) ) {
14  $msg =
15  isset( $params['other'] )
16  ? $params['other']
17  : wfMessage( 'htmlform-selectorother-other' )->text();
18  // Have 'other' always as first element
19  $this->mOptions = [ $msg => 'other' ] + $this->mOptions;
20  }
21 
22  }
23 
24  function getInputHTML( $value ) {
25  $valInSelect = false;
26 
27  if ( $value !== false ) {
28  $value = strval( $value );
29  $valInSelect = in_array(
31  );
32  }
33 
34  $selected = $valInSelect ? $value : 'other';
35 
36  $select = new XmlSelect( $this->mName, $this->mID, $selected );
37  $select->addOptions( $this->getOptions() );
38 
39  $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
40 
41  $tbAttribs = [ 'id' => $this->mID . '-other', 'size' => $this->getSize() ];
42 
43  if ( !empty( $this->mParams['disabled'] ) ) {
44  $select->setAttribute( 'disabled', 'disabled' );
45  $tbAttribs['disabled'] = 'disabled';
46  }
47 
48  if ( isset( $this->mParams['tabindex'] ) ) {
49  $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
50  $tbAttribs['tabindex'] = $this->mParams['tabindex'];
51  }
52 
53  $select = $select->getHTML();
54 
55  if ( isset( $this->mParams['maxlength'] ) ) {
56  $tbAttribs['maxlength'] = $this->mParams['maxlength'];
57  }
58 
59  if ( $this->mClass !== '' ) {
60  $tbAttribs['class'] = $this->mClass;
61  }
62 
63  $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
64 
65  return "$select<br />\n$textbox";
66  }
67 
68  function getInputOOUI( $value ) {
69  return false;
70  }
71 
78  if ( $request->getCheck( $this->mName ) ) {
79  $val = $request->getText( $this->mName );
80 
81  if ( $val === 'other' ) {
82  $val = $request->getText( $this->mName . '-other' );
83  }
84 
85  return $val;
86  } else {
87  return $this->getDefault();
88  }
89  }
90 }
getOptions()
Fetch the array of options from the field's parameters.
Select dropdown field, with an additional "other" textbox.
Class for generating HTML " element.
Definition: Html.php:676
static flattenOptions($options)
flatten an array of options to a single array, for instance, a set of "" inside "...