180 public static function processUnblock( array $data, IContextSource $context ) {
181 $performer = $context->getUser();
182 $target = $data['Target'];
183 $block = Block::newFromTarget( $data['Target'] );
185 if ( !$block instanceof Block ) {
186 return [ [ 'ipb_cant_unblock', $target ] ];
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 );
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();
203 return [ [ 'ipb_blocked_as_range', $target, $range ] ];
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' ];
212 $reason = [ 'hookaborted' ];
213 if ( !Hooks::run( 'UnblockUser', [ &$block, &$performer, &$reason ] ) ) {
218 if ( !$block->delete() ) {
219 return [ [ 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) ] ];
222 Hooks::run( 'UnblockUserComplete', [ $block, $performer ] );
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() );
231 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
234 # Redact the name (IP address) for autoblocks
235 if ( $block->getType() == Block::TYPE_AUTO ) {
236 $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
238 $page = $block->getTarget() instanceof User
239 ? $block->getTarget()->getUserPage()
240 : Title::makeTitle( NS_USER, $block->getTarget() );
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'] );
251 $logId = $logEntry->insert();
252 $logEntry->publish( $logId );