6use InvalidArgumentException;
24 private const FIELD_CLASS =
'mw-htmlform-select-and-other-field';
26 private $mFlatOptions;
33 if ( array_key_exists(
'other',
$params ) ) {
35 } elseif ( array_key_exists(
'other-message',
$params ) ) {
38 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
44 throw new InvalidArgumentException(
'HTMLSelectAndOtherField called without any options' );
46 if ( !in_array(
'other', $this->mOptions,
true ) ) {
54 $select = parent::getInputHTML( $value[1] );
60 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
61 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
76 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
80 'class' => self::FIELD_CLASS
82 if ( $this->mClass !==
'' ) {
85 return Html::rawElement(
88 "$select<br />\n$textbox"
93 return [
'mediawiki.widgets.SelectWithInputWidget' ];
97 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
101 'name' => $this->mName .
'-other',
102 'value' => $value[2],
114 $textAttribs += \OOUI\Element::configFromHtmlAttributes(
119 $dropdownInputAttribs = [
122 'value' => $value[1],
130 $dropdownInputAttribs += \OOUI\Element::configFromHtmlAttributes(
135 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
139 $inputClasses = [ self::FIELD_CLASS ];
140 if ( $this->mClass !==
'' ) {
141 $inputClasses = array_merge( $inputClasses, explode(
' ', $this->mClass ) );
145 'disabled' => $disabled,
146 'textinput' => $textAttribs,
147 'dropdowninput' => $dropdownInputAttribs,
149 'required' => $this->mParams[
'required' ] ??
false,
150 'classes' => $inputClasses,
152 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
167 $select = parent::getInputCodex( $value[1], $hasErrors );
170 $textInputAttribs = [
172 'name' => $this->mName .
'-other'
175 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
176 $textInputAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
196 $this->mName .
'-other',
203 'class' => [ self::FIELD_CLASS ]
205 if ( $this->mClass !==
'' ) {
208 return Html::rawElement(
211 "$select<br />\n$textInput"
219 $default = parent::getDefault();
226 if ( $default !==
null ) {
231 foreach ( $this->mFlatOptions as $option ) {
232 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
233 if ( str_starts_with( $final, $match ) ) {
235 $text = substr( $final, strlen( $match ) );
241 return [ $final, $list, $text ];
250 if ( $request->getCheck( $this->mName ) ) {
251 $list = $request->getText( $this->mName );
252 $text = $request->getText( $this->mName .
'-other' );
255 if ( $list ==
'other' ) {
257 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
258 # User has spoofed the select form to give an option which wasn't
259 # in the original offer. Sulk...
261 } elseif ( $text ==
'' ) {
264 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
266 return [ $final, $list, $text ];
272 return $this->mParams[
'size'] ?? 45;
276 # HTMLSelectField forces $value to be one of the options in the select
277 # field, which is not useful here. But we do want the validation further up
279 $p = parent::validate( $value[1], $alldata );
285 if ( isset( $this->mParams[
'required'] )
286 && $this->mParams[
'required'] !==
false
289 return $this->
msg(
'htmlform-required' );
297class_alias( HTMLSelectAndOtherField::class,
'HTMLSelectAndOtherField' );
array $params
The job parameters.
static buildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs)
Build the markup of the Codex component.