22 $value = $request->getText( $this->mName, $this->
getDefault() ??
'' );
24 $tagsArray = explode(
"\n", $value );
26 $tagsArray = array_values( array_filter( $tagsArray,
static function ( $tag ) {
27 return trim( $tag ) !==
'';
30 $uniqueTags = array_unique( $tagsArray );
33 return implode(
"\n", $uniqueTags );
37 if ( $value ===
null ) {
42 $tagsArray = explode(
"\n", $value );
44 if ( isset( $this->mParams[
'max'] ) && ( count( $tagsArray ) > $this->mParams[
'max'] ) ) {
45 return $this->
msg(
'htmlform-multiselect-toomany', $this->mParams[
'max'] );
48 foreach ( $tagsArray as $tag ) {
49 $result = parent::validate( $tag, $alldata );
50 if ( $result !==
true ) {
54 if ( empty( $this->mParams[
'allowArbitrary'] ) && $tag ) {
55 $allowedValues = $this->mParams[
'allowedValues'] ?? [];
56 if ( !in_array( $tag, $allowedValues ) ) {
57 return $this->
msg(
'htmlform-tag-not-allowed', $tag )->escaped();
66 $this->mParent->getOutput()->enableOOUI();
71 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.TagMultiselectWidget.styles' );
75 if ( isset( $this->mParams[
'id'] ) ) {
76 $params[
'id'] = $this->mParams[
'id'];
79 if ( isset( $this->mParams[
'disabled'] ) ) {
80 $params[
'disabled'] = $this->mParams[
'disabled'];
83 if ( isset( $this->mParams[
'default'] ) ) {
84 $params[
'default'] = $this->mParams[
'default'];
87 $params[
'placeholder'] = $this->mParams[
'placeholder'] ??
88 $this->
msg(
'mw-widgets-tagmultiselect-placeholder' )->plain();
90 if ( isset( $this->mParams[
'max'] ) ) {
91 $params[
'tagLimit'] = $this->mParams[
'max'];
94 if ( isset( $this->mParams[
'allowArbitrary'] ) ) {
95 $params[
'allowArbitrary'] = $this->mParams[
'allowArbitrary'];
98 if ( isset( $this->mParams[
'allowedValues'] ) ) {
99 $params[
'allowedValues'] = $this->mParams[
'allowedValues'];
102 if ( isset( $this->mParams[
'input'] ) ) {
103 $params[
'input'] = $this->mParams[
'input'];
106 if ( $value !==
null ) {
108 $params[
'default'] = $value ===
'' ? [] : explode(
"\n", $value );
113 $params[
'classes'] = [
'mw-htmlform-autoinfuse' ];
123 $widget->setAttributes( [
'data-mw-modules' => implode(
',', $this->
getOOUIModules() ) ] );
132 return [
'mediawiki.widgets.TagMultiselectWidget' ];
138class_alias( HTMLTagMultiselectField::class,
'HTMLTagMultiselectField' );
array $params
The job parameters.