23 $value = $request->getText( $this->mName, $this->
getDefault() ??
'' );
25 $usersArray = explode(
"\n", $value );
27 $usersArray = array_values( array_filter( $usersArray,
static function ( $username ) {
28 return trim( $username ) !==
'';
32 $normalizedUsers = [];
33 $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
35 foreach ( $usersArray as $user ) {
36 $canonicalUser =
false;
37 if ( IPUtils::isIPAddress( $user ) ) {
38 $parsedIPRange = IPUtils::parseRange( $user );
39 if ( !in_array( $parsedIPRange, $listOfIps ) ) {
40 $canonicalUser = IPUtils::sanitizeRange( $user );
41 $listOfIps[] = $parsedIPRange;
44 $canonicalUser = $userNameUtils->getCanonical(
45 $user, UserRigorOptions::RIGOR_NONE );
47 if ( $canonicalUser !==
false ) {
48 $normalizedUsers[] = $canonicalUser;
52 $uniqueUsers = array_unique( $normalizedUsers );
55 return implode(
"\n", $uniqueUsers );
59 if ( !$this->mParams[
'exists'] ) {
63 if ( $value ===
null ) {
68 $usersArray = explode(
"\n", $value );
70 if ( isset( $this->mParams[
'max'] ) && ( count( $usersArray ) > $this->mParams[
'max'] ) ) {
71 return $this->
msg(
'htmlform-multiselect-toomany', $this->mParams[
'max'] );
74 foreach ( $usersArray as $username ) {
75 $result = parent::validate( $username, $alldata );
76 if ( $result !==
true ) {
85 $this->mParent->getOutput()->enableOOUI();
90 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.TagMultiselectWidget.styles' );
94 if ( isset( $this->mParams[
'id'] ) ) {
95 $params[
'id'] = $this->mParams[
'id'];
98 if ( isset( $this->mParams[
'disabled'] ) ) {
99 $params[
'disabled'] = $this->mParams[
'disabled'];
102 if ( isset( $this->mParams[
'default'] ) ) {
103 $params[
'default'] = $this->mParams[
'default'];
106 $params[
'placeholder'] = $this->mParams[
'placeholder'] ??
107 $this->
msg(
'mw-widgets-usersmultiselect-placeholder' )->plain();
109 if ( isset( $this->mParams[
'max'] ) ) {
110 $params[
'tagLimit'] = $this->mParams[
'max'];
113 if ( isset( $this->mParams[
'ipallowed'] ) ) {
114 $params[
'ipAllowed'] = $this->mParams[
'ipallowed'];
117 if ( isset( $this->mParams[
'iprange'] ) ) {
118 $params[
'ipRangeAllowed'] = $this->mParams[
'iprange'];
121 if ( isset( $this->mParams[
'iprangelimits'] ) ) {
122 $params[
'ipRangeLimits'] = $this->mParams[
'iprangelimits'];
125 if ( isset( $this->mParams[
'input'] ) ) {
126 $params[
'input'] = $this->mParams[
'input'];
129 if ( $value !==
null ) {
131 $params[
'default'] = $value ===
'' ? [] : explode(
"\n", $value );
135 $params[
'infusable'] =
true;
136 $params[
'classes'] = [
'mw-htmlform-autoinfuse' ];
146 $widget->setAttributes( [
'data-mw-modules' => implode(
',', $this->
getOOUIModules() ) ] );
155 return [
'mediawiki.widgets.UsersMultiselectWidget' ];
Implements a text input field for user names.
Implements a tag multiselect input field for user names.
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
shouldInfuseOOUI()
Whether the field should be automatically infused.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
getInputWidget( $params)
Stability: stableto overrideWidget