MediaWiki REL1_32
SpecialUnblock.php
Go to the documentation of this file.
1<?php
30
31 protected $target;
32 protected $type;
33 protected $block;
34
35 public function __construct() {
36 parent::__construct( 'Unblock', 'block' );
37 }
38
39 public function doesWrites() {
40 return true;
41 }
42
43 public function execute( $par ) {
44 $this->checkPermissions();
45 $this->checkReadOnly();
46
47 list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
48 $this->block = Block::newFromTarget( $this->target );
49 if ( $this->target instanceof User ) {
50 # Set the 'relevant user' in the skin, so it displays links like Contributions,
51 # User logs, UserRights, etc.
52 $this->getSkin()->setRelevantUser( $this->target );
53 }
54
55 $this->setHeaders();
56 $this->outputHeader();
57
58 $out = $this->getOutput();
59 $out->setPageTitle( $this->msg( 'unblockip' ) );
60 $out->addModules( [ 'mediawiki.userSuggest' ] );
61
62 $form = HTMLForm::factory( 'ooui', $this->getFields(), $this->getContext() );
63 $form->setWrapperLegendMsg( 'unblockip' );
64 $form->setSubmitCallback( [ __CLASS__, 'processUIUnblock' ] );
65 $form->setSubmitTextMsg( 'ipusubmit' );
66 $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
67
68 if ( $form->show() ) {
69 switch ( $this->type ) {
70 case Block::TYPE_IP:
71 $out->addWikiMsg( 'unblocked-ip', wfEscapeWikiText( $this->target ) );
72 break;
74 $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) );
75 break;
77 $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) );
78 break;
79 case Block::TYPE_ID:
81 $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) );
82 break;
83 }
84 }
85 }
86
87 protected function getFields() {
88 $fields = [
89 'Target' => [
90 'type' => 'text',
91 'label-message' => 'ipaddressorusername',
92 'autofocus' => true,
93 'size' => '45',
94 'required' => true,
95 'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
96 ],
97 'Name' => [
98 'type' => 'info',
99 'label-message' => 'ipaddressorusername',
100 ],
101 'Reason' => [
102 'type' => 'text',
103 'label-message' => 'ipbreason',
104 ]
105 ];
106
107 if ( $this->block instanceof Block ) {
108 list( $target, $type ) = $this->block->getTargetAndType();
109
110 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
111 # User:Foo, and we've just got any block, auto or not, that applies to a target
112 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
113 # so don't show any distinction between unblocked IPs and autoblocked IPs
114 if ( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ) {
115 $fields['Target']['default'] = $this->target;
116 unset( $fields['Name'] );
117 } else {
118 $fields['Target']['default'] = $target;
119 $fields['Target']['type'] = 'hidden';
120 switch ( $type ) {
121 case Block::TYPE_IP:
122 $fields['Name']['default'] = $this->getLinkRenderer()->makeKnownLink(
123 SpecialPage::getTitleFor( 'Contributions', $target->getName() ),
124 $target->getName()
125 );
126 $fields['Name']['raw'] = true;
127 break;
128 case Block::TYPE_USER:
129 $fields['Name']['default'] = $this->getLinkRenderer()->makeLink(
130 $target->getUserPage(),
131 $target->getName()
132 );
133 $fields['Name']['raw'] = true;
134 break;
135
136 case Block::TYPE_RANGE:
137 $fields['Name']['default'] = $target;
138 break;
139
140 case Block::TYPE_AUTO:
141 $fields['Name']['default'] = $this->block->getRedactedName();
142 $fields['Name']['raw'] = true;
143 # Don't expose the real target of the autoblock
144 $fields['Target']['default'] = "#{$this->target}";
145 break;
146 }
147 // target is hidden, so the reason is the first element
148 $fields['Target']['autofocus'] = false;
149 $fields['Reason']['autofocus'] = true;
150 }
151 } else {
152 $fields['Target']['default'] = $this->target;
153 unset( $fields['Name'] );
154 }
155
156 return $fields;
157 }
158
165 public static function processUIUnblock( array $data, HTMLForm $form ) {
166 return self::processUnblock( $data, $form->getContext() );
167 }
168
180 public static function processUnblock( array $data, IContextSource $context ) {
181 $performer = $context->getUser();
182 $target = $data['Target'];
183 $block = Block::newFromTarget( $data['Target'] );
184
185 if ( !$block instanceof Block ) {
186 return [ [ 'ipb_cant_unblock', $target ] ];
187 }
188
189 # T17810: blocked admins should have limited access here. This
190 # won't allow sysops to remove autoblocks on themselves, but they
191 # should have ipblock-exempt anyway
192 $status = SpecialBlock::checkUnblockSelf( $target, $performer );
193 if ( $status !== true ) {
194 throw new ErrorPageError( 'badaccess', $status );
195 }
196
197 # If the specified IP is a single address, and the block is a range block, don't
198 # unblock the whole range.
199 list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
200 if ( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
201 $range = $block->getTarget();
202
203 return [ [ 'ipb_blocked_as_range', $target, $range ] ];
204 }
205
206 # If the name was hidden and the blocking user cannot hide
207 # names, then don't allow any block removals...
208 if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
209 return [ 'unblock-hideuser' ];
210 }
211
212 $reason = [ 'hookaborted' ];
213 if ( !Hooks::run( 'UnblockUser', [ &$block, &$performer, &$reason ] ) ) {
214 return $reason;
215 }
216
217 # Delete block
218 if ( !$block->delete() ) {
219 return [ [ 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) ] ];
220 }
221
222 Hooks::run( 'UnblockUserComplete', [ $block, $performer ] );
223
224 # Unset _deleted fields as needed
225 if ( $block->mHideName ) {
226 # Something is deeply FUBAR if this is not a User object, but who knows?
227 $id = $block->getTarget() instanceof User
228 ? $block->getTarget()->getId()
229 : User::idFromName( $block->getTarget() );
230
231 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
232 }
233
234 # Redact the name (IP address) for autoblocks
235 if ( $block->getType() == Block::TYPE_AUTO ) {
236 $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
237 } else {
238 $page = $block->getTarget() instanceof User
239 ? $block->getTarget()->getUserPage()
240 : Title::makeTitle( NS_USER, $block->getTarget() );
241 }
242
243 # Make log entry
244 $logEntry = new ManualLogEntry( 'block', 'unblock' );
245 $logEntry->setTarget( $page );
246 $logEntry->setComment( $data['Reason'] );
247 $logEntry->setPerformer( $performer );
248 if ( isset( $data['Tags'] ) ) {
249 $logEntry->setTags( $data['Tags'] );
250 }
251 $logId = $logEntry->insert();
252 $logEntry->publish( $logId );
253
254 return true;
255 }
256
265 public function prefixSearchSubpages( $search, $limit, $offset ) {
266 $user = User::newFromName( $search );
267 if ( !$user ) {
268 // No prefix suggestion for invalid user
269 return [];
270 }
271 // Autocomplete subpage as user list - public to allow caching
272 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
273 }
274
275 protected function getGroupName() {
276 return 'users';
277 }
278}
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
const TYPE_ID
Definition Block.php:87
const TYPE_RANGE
Definition Block.php:85
const TYPE_USER
Definition Block.php:83
const TYPE_AUTO
Definition Block.php:86
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
Definition Block.php:1174
const TYPE_IP
Definition Block.php:84
static getTargetAndType( $par, WebRequest $request=null)
Determine the target of the block, and the type of target.
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)
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.
A special page for unblocking users.
doesWrites()
Indicates whether this special page may perform database writes.
execute( $par)
Default execute method Checks user permissions.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters block
Definition hooks.txt:2248
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:894
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36