5use InvalidArgumentException;
48 'require-match' =>
false,
53 if ( array_key_exists(
'autocomplete-data-messages', $this->mParams ) ) {
54 foreach ( $this->mParams[
'autocomplete-data-messages'] as $key => $value ) {
55 $key = $this->
msg( $key )->plain();
56 $this->autocompleteData[$key] = strval( $value );
58 } elseif ( array_key_exists(
'autocomplete-data', $this->mParams ) ) {
59 foreach ( $this->mParams[
'autocomplete-data'] as $key => $value ) {
60 $this->autocompleteData[$key] = strval( $value );
63 if ( !is_array( $this->autocompleteData ) || !$this->autocompleteData ) {
64 throw new InvalidArgumentException(
'HTMLAutoCompleteSelectField called without any autocompletions' );
68 if ( $this->mOptions && !in_array(
'other', $this->mOptions,
true ) ) {
69 if ( isset(
$params[
'other-message'] ) ) {
71 } elseif ( isset(
$params[
'other'] ) ) {
74 $msg =
wfMessage(
'htmlform-selectorother-other' )->text();
76 $this->mOptions[$msg] =
'other';
81 if ( $request->getCheck( $this->mName ) ) {
82 $val = $request->getText( $this->mName .
'-select',
'other' );
84 if ( $val ===
'other' ) {
85 $val = $request->getText( $this->mName );
86 if ( isset( $this->autocompleteData[$val] ) ) {
87 $val = $this->autocompleteData[$val];
98 $p = parent::validate( $value, $alldata );
107 in_array( strval( $value ), $validOptions,
true ) ||
108 in_array( strval( $value ), $this->autocompleteData,
true )
111 } elseif ( $this->mParams[
'require-match'] ) {
112 return $this->
msg(
'htmlform-select-badoption' );
122 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocompleteData ) ),
123 ] + parent::getAttributes( $list );
126 $attribs[
'data-cond-state'] = FormatJson::encode( [
127 'hide' => [
'!==', $this->mName .
'-select',
'other' ],
136 $classes = (array)$this->mClass;
138 $valInSelect =
false;
142 if ( $value !==
false ) {
143 $value = strval( $value );
144 $valInSelect = in_array(
149 $selected = $valInSelect ? $value :
'other';
150 $select =
new XmlSelect( $this->mName .
'-select', $this->mID .
'-select', $selected );
153 if ( !empty( $this->mParams[
'disabled'] ) ) {
154 $select->setAttribute(
'disabled',
'disabled' );
157 if ( isset( $this->mParams[
'tabindex'] ) ) {
158 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
161 $ret = $select->getHTML() .
"<br />\n";
163 $classes[] =
'mw-htmlform-hide-if';
166 if ( $valInSelect ) {
169 $key = array_search( strval( $value ), $this->autocompleteData,
true );
170 if ( $key !==
false ) {
175 $classes[] =
'mw-htmlform-autocomplete';
176 $this->mClass = implode(
' ', $classes );
177 $ret .= parent::getInputHTML( $valInSelect ?
'' : $value );
178 $this->mClass = $oldClass;
195class_alias( HTMLAutoCompleteSelectField::class,
'HTMLAutoCompleteSelectField' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.