23 $value = $request->getText( $this->mName, $this->
getDefault() ??
'' );
25 $tagsArray = explode(
"\n", $value );
27 $tagsArray = array_values( array_filter( $tagsArray,
static function ( $tag ) {
28 return trim( $tag ) !==
'';
31 $uniqueTags = array_unique( $tagsArray );
34 return implode(
"\n", $uniqueTags );
39 if ( $value ===
null ) {
44 $tagsArray = explode(
"\n", $value );
46 if ( isset( $this->mParams[
'max'] ) && ( count( $tagsArray ) > $this->mParams[
'max'] ) ) {
47 return $this->
msg(
'htmlform-multiselect-toomany', $this->mParams[
'max'] );
50 foreach ( $tagsArray as $tag ) {
51 $result = parent::validate( $tag, $alldata );
52 if ( $result !==
true ) {
56 if ( empty( $this->mParams[
'allowArbitrary'] ) && $tag ) {
57 $allowedValues = $this->mParams[
'allowedValues'] ?? [];
58 if ( !in_array( $tag, $allowedValues ) ) {
59 return $this->
msg(
'htmlform-tag-not-allowed', $tag )->escaped();
69 $this->mParent->getOutput()->enableOOUI();
75 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.TagMultiselectWidget.styles' );
79 if ( isset( $this->mParams[
'id'] ) ) {
80 $params[
'id'] = $this->mParams[
'id'];
83 if ( isset( $this->mParams[
'disabled'] ) ) {
84 $params[
'disabled'] = $this->mParams[
'disabled'];
87 if ( isset( $this->mParams[
'default'] ) ) {
88 $params[
'default'] = $this->mParams[
'default'];
91 $params[
'placeholder'] = $this->mParams[
'placeholder'] ??
92 $this->
msg(
'mw-widgets-tagmultiselect-placeholder' )->plain();
94 if ( isset( $this->mParams[
'max'] ) ) {
95 $params[
'tagLimit'] = $this->mParams[
'max'];
98 if ( isset( $this->mParams[
'allowArbitrary'] ) ) {
99 $params[
'allowArbitrary'] = $this->mParams[
'allowArbitrary'];
102 if ( isset( $this->mParams[
'allowedValues'] ) ) {
103 $params[
'allowedValues'] = $this->mParams[
'allowedValues'];
106 if ( isset( $this->mParams[
'input'] ) ) {
107 $params[
'input'] = $this->mParams[
'input'];
110 if ( $value !==
null ) {
112 $params[
'default'] = $value ===
'' ? [] : explode(
"\n", $value );
116 $params[
'infusable'] =
true;
117 $params[
'classes'] = [
'mw-htmlform-autoinfuse' ];
127 $widget->setAttributes( [
'data-mw-modules' => implode(
',', $this->
getOOUIModules() ) ] );
138 return [
'mediawiki.widgets.TagMultiselectWidget' ];
144class_alias( HTMLTagMultiselectField::class,
'HTMLTagMultiselectField' );