47 private $unblockUserFactory;
53 private $userNameUtils;
56 private $userNamePrefixSearch;
70 parent::__construct(
'Unblock',
'block' );
71 $this->unblockUserFactory = $unblockUserFactory;
72 $this->blockUtils = $blockUtils;
73 $this->userNameUtils = $userNameUtils;
74 $this->userNamePrefixSearch = $userNamePrefixSearch;
85 list( $this->target, $this->type ) = $this->getTargetAndType( $par, $this->
getRequest() );
86 $this->block = DatabaseBlock::newFromTarget( $this->target );
88 # Set the 'relevant user' in the skin, so it displays links like Contributions,
89 # User logs, UserRights, etc.
90 $this->
getSkin()->setRelevantUser( $this->target );
98 $out->setPageTitle( $this->
msg(
'unblockip' ) );
99 $out->addModules( [
'mediawiki.userSuggest' ] );
102 ->setWrapperLegendMsg(
'unblockip' )
103 ->setSubmitCallback(
function ( array $data,
HTMLForm $form ) {
104 return $this->unblockUserFactory->newUnblockUser(
111 ->setSubmitTextMsg(
'ipusubmit' )
112 ->addPreText( $this->
msg(
'unblockiptext' )->parseAsBlock() );
114 if ( $form->
show() ) {
115 switch ( $this->type ) {
116 case DatabaseBlock::TYPE_IP:
120 case DatabaseBlock::TYPE_USER:
124 case DatabaseBlock::TYPE_RANGE:
128 case DatabaseBlock::TYPE_ID:
129 case DatabaseBlock::TYPE_AUTO:
147 private function getTargetAndType( ?
string $par,
WebRequest $request ) {
149 $request->
getVal(
'wpTarget',
null ),
151 $request->
getVal(
'ip',
null ),
153 $request->
getVal(
'wpBlockAddress',
null ),
155 foreach ( $possibleTargets as $possibleTarget ) {
156 $targetAndType = $this->blockUtils->parseBlockTarget( $possibleTarget );
158 if ( $targetAndType[ 1 ] !==
null ) {
162 return $targetAndType;
169 'label-message' =>
'ipaddressorusername',
173 'cssclass' =>
'mw-autocomplete-user',
177 'label-message' =>
'ipaddressorusername',
181 'label-message' =>
'ipbreason',
186 $type = $this->block->getType();
187 $targetName = $this->block->getTargetName();
189 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
190 # User:Foo, and we've just got any block, auto or not, that applies to a target
191 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
192 # so don't show any distinction between unblocked IPs and autoblocked IPs
193 if ( $type == DatabaseBlock::TYPE_AUTO && $this->type == DatabaseBlock::TYPE_IP ) {
194 $fields['Target']['default'] = $this->target;
195 unset( $fields['Name'] );
197 $fields['Target']['default'] = $targetName;
198 $fields['Target']['type'] = 'hidden';
200 case DatabaseBlock::TYPE_IP:
201 $fields['Name']['default'] = $this->getLinkRenderer()->makeKnownLink(
202 $this->getSpecialPageFactory()->getTitleForAlias( 'Contributions/' . $targetName ),
205 $fields['Name']['raw'] = true;
207 case DatabaseBlock::TYPE_USER:
208 $fields['Name']['default'] = $this->getLinkRenderer()->makeLink(
209 new TitleValue( NS_USER, $targetName ),
212 $fields['Name']['raw'] = true;
215 case DatabaseBlock::TYPE_RANGE:
216 $fields['Name']['default'] = $targetName;
219 case DatabaseBlock::TYPE_AUTO:
220 $fields['Name']['default'] = $this->block->getRedactedName();
221 $fields['Name']['raw'] = true;
222 # Don't expose the real target of the autoblock
223 $fields['Target']['default'] = "#{$this->target}";
226 // target is hidden, so the reason is the first element
227 $fields['Target']['autofocus'] = false;
228 $fields['Reason']['autofocus'] = true;
231 $fields['Target']['default'] = $this->target;
232 unset( $fields['Name'] );
246 public function prefixSearchSubpages( $search, $limit, $offset ) {
247 $search = $this->userNameUtils->getCanonical( $search );
249 // No prefix suggestion for invalid user
252 // Autocomplete subpage as user list - public to allow caching
253 return $this->userNamePrefixSearch
254 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
257 protected function getGroupName() {
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getContext()
Get the base IContextSource object.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getSkin()
Shortcut to get the skin being used for this instance.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page for unblocking users.
UserIdentity string null $target
doesWrites()
Indicates whether this special page may perform database writes.
execute( $par)
Default execute method Checks user permissions.
__construct(UnblockUserFactory $unblockUserFactory, BlockUtils $blockUtils, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch)
int null $type
DatabaseBlock::TYPE_ constant.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
getVal( $name, $default=null)
Fetch a text string and partially normalized it.