Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
HTMLUserTextField.php
Go to the documentation of this file.
1<?php
2
3namespaceMediaWiki\HTMLForm\Field;
4
5useMediaWiki\MediaWikiServices;
6useMediaWiki\Message\Message;
7useMediaWiki\User\ExternalUserNames;
8useMediaWiki\Widget\UserInputWidget;
9use Wikimedia\IPUtils;
10
29classHTMLUserTextFieldextendsHTMLTextField {
34publicfunction__construct( $params ) {
35 $params =wfArrayPlus2d( $params, [
36'exists' =>false,
37'external' =>false,
38'ipallowed' =>false,
39'usemodwiki-ipallowed' =>false,
40'iprange' =>false,
41'iprangelimits' => [
42'IPv4' => 0,
43'IPv6' => 0,
44 ],
45'excludenamed' =>false,
46'excludetemp' =>false,
47 ]
48 );
49
50 parent::__construct( $params );
51 }
52
54publicfunctionvalidate( $value, $alldata ) {
55// If the value is null, reset it to an empty string which is what is expected by the parent.
56 $value ??='';
57
58// If the value is empty, there are no additional checks that can be performed.
59if ( $value ==='' ) {
60return parent::validate( $value, $alldata );
61 }
62
63// check if the input is a valid username
64 $user =MediaWikiServices::getInstance()->getUserFactory()->newFromName( $value );
65if ( $user ) {
66// check if the user exists, if requested
67if ( $this->mParams['exists'] && !(
68 $user->isRegistered() &&
69// Treat hidden users as unregistered if current user can't view them (T309894)
70 !( $user->isHidden() && !( $this->mParent && $this->mParent->getUser()->isAllowed('hideuser' ) ) )
71 ) ) {
72return $this->msg('htmlform-user-not-exists',wfEscapeWikiText( $user->getName() ) );
73 }
74
75// check if the user account type matches the account type filter
76 $excludeNamed = $this->mParams['excludenamed'] ??null;
77 $excludeTemp = $this->mParams['excludetemp'] ??null;
78if ( ( $excludeTemp && $user->isTemp() ) || ( $excludeNamed && $user->isNamed() ) ) {
79return $this->msg('htmlform-user-not-valid',wfEscapeWikiText( $user->getName() ) );
80 }
81 }else {
82// not a valid username
83 $valid =false;
84// check if the input is a valid external user
85if ( $this->mParams['external'] && ExternalUserNames::isExternal( $value ) ) {
86 $valid =true;
87 }
88// check if the input is a valid IP address, optionally also checking for usemod wiki IPs
89if ( $this->mParams['ipallowed'] ) {
90 $b = IPUtils::RE_IP_BYTE;
91if ( IPUtils::isValid( $value ) ) {
92 $valid =true;
93 } elseif ( $this->mParams['usemodwiki-ipallowed'] && preg_match("/^$b\.$b\.$b\.xxx$/", $value ) ) {
94 $valid =true;
95 }
96 }
97// check if the input is a valid IP range
98if ( $this->mParams['iprange'] ) {
99 $rangeError = $this->isValidIPRange( $value );
100if ( $rangeError ===true ) {
101 $valid =true;
102 } elseif ( $rangeError !==false ) {
103return $rangeError;
104 }
105 }
106if ( !$valid ) {
107return $this->msg('htmlform-user-not-valid',wfEscapeWikiText( $value ) );
108 }
109 }
110
111return parent::validate( $value, $alldata );
112 }
113
118protectedfunctionisValidIPRange( $value ) {
119 $cidrIPRanges = $this->mParams['iprangelimits'];
120
121if ( !IPUtils::isValidRange( $value ) ) {
122returnfalse;
123 }
124
125 [ $ip, $range ] = explode('/', $value, 2 );
126
127if (
128 ( IPUtils::isIPv4( $ip ) && $cidrIPRanges['IPv4'] == 32 ) ||
129 ( IPUtils::isIPv6( $ip ) && $cidrIPRanges['IPv6'] == 128 )
130 ) {
131// Range block effectively disabled
132return $this->msg('ip_range_toolow' );
133 }
134
135if (
136 ( IPUtils::isIPv4( $ip ) && $range > 32 ) ||
137 ( IPUtils::isIPv6( $ip ) && $range > 128 )
138 ) {
139// Dodgy range
140return $this->msg('ip_range_invalid' );
141 }
142
143if ( IPUtils::isIPv4( $ip ) && $range < $cidrIPRanges['IPv4'] ) {
144return $this->msg('ip_range_exceeded', $cidrIPRanges['IPv4'] );
145 }
146
147if ( IPUtils::isIPv6( $ip ) && $range < $cidrIPRanges['IPv6'] ) {
148return $this->msg('ip_range_exceeded', $cidrIPRanges['IPv6'] );
149 }
150
151returntrue;
152 }
153
155protectedfunctiongetInputWidget( $params ) {
156if ( isset( $this->mParams['excludenamed'] ) ) {
157 $params['excludenamed'] = $this->mParams['excludenamed'];
158 }
159
160if ( isset( $this->mParams['excludetemp'] ) ) {
161 $params['excludetemp'] = $this->mParams['excludetemp'];
162 }
163
164returnnewUserInputWidget( $params );
165 }
166
168protectedfunctionshouldInfuseOOUI() {
169returntrue;
170 }
171
173protectedfunctiongetOOUIModules() {
174return ['mediawiki.widgets.UserInputWidget' ];
175 }
176
178publicfunctiongetInputHtml( $value ) {
179// add the required module and css class for user suggestions in non-OOUI mode
180 $this->mParent->getOutput()->addModules('mediawiki.userSuggest' );
181 $this->mClass .=' mw-autocomplete-user';
182
183// return parent html
184return parent::getInputHTML( $value );
185 }
186}
187
189class_alias( HTMLUserTextField::class,'HTMLUserTextField' );
wfEscapeWikiText
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
DefinitionGlobalFunctions.php:1060
wfArrayPlus2d
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
DefinitionGlobalFunctions.php:2028
MediaWiki\HTMLForm\Field\HTMLTextField
<input> field.
DefinitionHTMLTextField.php:19
MediaWiki\HTMLForm\Field\HTMLUserTextField
Implements a text input field for user names.
DefinitionHTMLUserTextField.php:29
MediaWiki\HTMLForm\Field\HTMLUserTextField\getInputHtml
getInputHtml( $value)
DefinitionHTMLUserTextField.php:178
MediaWiki\HTMLForm\Field\HTMLUserTextField\isValidIPRange
isValidIPRange( $value)
DefinitionHTMLUserTextField.php:118
MediaWiki\HTMLForm\Field\HTMLUserTextField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
DefinitionHTMLUserTextField.php:54
MediaWiki\HTMLForm\Field\HTMLUserTextField\__construct
__construct( $params)
DefinitionHTMLUserTextField.php:34
MediaWiki\HTMLForm\Field\HTMLUserTextField\shouldInfuseOOUI
shouldInfuseOOUI()
Whether the field should be automatically infused.Note that all OOUI HTMLForm fields are infusable (y...
DefinitionHTMLUserTextField.php:168
MediaWiki\HTMLForm\Field\HTMLUserTextField\getOOUIModules
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
DefinitionHTMLUserTextField.php:173
MediaWiki\HTMLForm\Field\HTMLUserTextField\getInputWidget
getInputWidget( $params)
to overrideWidget
DefinitionHTMLUserTextField.php:155
MediaWiki\HTMLForm\HTMLFormField\msg
msg( $key,... $params)
Get a translated interface message.
DefinitionHTMLFormField.php:142
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
DefinitionMediaWikiServices.php:256
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
DefinitionMediaWikiServices.php:344
MediaWiki\Message\Message
The Message class deals with fetching and processing of interface message into a variety of formats.
DefinitionMessage.php:144
MediaWiki\User\ExternalUserNames
Class to parse and build external user names.
DefinitionExternalUserNames.php:19
MediaWiki\Widget\UserInputWidget
User input widget.
DefinitionUserInputWidget.php:13
MediaWiki\HTMLForm\Field
DefinitionHTMLApiField.php:3

[8]ページ先頭

©2009-2025 Movatter.jp