3 * Implements Special:Unblock
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page for unblocking users
27 * @ingroup SpecialPage
29 class SpecialUnblock
extends SpecialPage
{
35 public function __construct() {
36 parent
::__construct( 'Unblock', 'block' );
39 public function execute( $par ) {
40 $this->checkPermissions();
41 $this->checkReadOnly();
43 list( $this->target
, $this->type
) = SpecialBlock
::getTargetAndType( $par, $this->getRequest() );
44 $this->block
= Block
::newFromTarget( $this->target
);
47 $this->outputHeader();
49 $out = $this->getOutput();
50 $out->setPageTitle( $this->msg( 'unblockip' ) );
51 $out->addModules( 'mediawiki.special' );
53 $form = new HTMLForm( $this->getFields(), $this->getContext() );
54 $form->setWrapperLegendMsg( 'unblockip' );
55 $form->setSubmitCallback( array( __CLASS__
, 'processUIUnblock' ) );
56 $form->setSubmitTextMsg( 'ipusubmit' );
57 $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
60 switch( $this->type
) {
61 case Block
::TYPE_USER
:
63 $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target
) );
65 case Block
::TYPE_RANGE
:
66 $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target
) );
69 case Block
::TYPE_AUTO
:
70 $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target
) );
76 protected function getFields() {
80 'label-message' => 'ipadressorusername',
87 'label-message' => 'ipadressorusername',
91 'label-message' => 'ipbreason',
95 if( $this->block
instanceof Block
) {
96 list( $target, $type ) = $this->block
->getTargetAndType();
98 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
99 # User:Foo, and we've just got any block, auto or not, that applies to a target
100 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
101 # so don't show any distinction between unblocked IPs and autoblocked IPs
102 if( $type == Block
::TYPE_AUTO
&& $this->type
== Block
::TYPE_IP
) {
103 $fields['Target']['default'] = $this->target
;
104 unset( $fields['Name'] );
107 $fields['Target']['default'] = $target;
108 $fields['Target']['type'] = 'hidden';
110 case Block
::TYPE_USER
:
112 $fields['Name']['default'] = Linker
::link(
113 $target->getUserPage(),
116 $fields['Name']['raw'] = true;
119 case Block
::TYPE_RANGE
:
120 $fields['Name']['default'] = $target;
123 case Block
::TYPE_AUTO
:
124 $fields['Name']['default'] = $this->block
->getRedactedName();
125 $fields['Name']['raw'] = true;
126 # Don't expose the real target of the autoblock
127 $fields['Target']['default'] = "#{$this->target}";
133 $fields['Target']['default'] = $this->target
;
134 unset( $fields['Name'] );
140 * Submit callback for an HTMLForm object
141 * @return Array( Array(message key, parameters)
143 public static function processUIUnblock( array $data, HTMLForm
$form ) {
144 return self
::processUnblock( $data, $form->getContext() );
151 * @param $context IContextSource
152 * @throws ErrorPageError
153 * @return Array( Array(message key, parameters) ) on failure, True on success
155 public static function processUnblock( array $data, IContextSource
$context ) {
156 $performer = $context->getUser();
157 $target = $data['Target'];
158 $block = Block
::newFromTarget( $data['Target'] );
160 if( !$block instanceof Block
) {
161 return array( array( 'ipb_cant_unblock', $target ) );
164 # bug 15810: blocked admins should have limited access here. This
165 # won't allow sysops to remove autoblocks on themselves, but they
166 # should have ipblock-exempt anyway
167 $status = SpecialBlock
::checkUnblockSelf( $target, $performer );
168 if ( $status !== true ) {
169 throw new ErrorPageError( 'badaccess', $status );
172 # If the specified IP is a single address, and the block is a range block, don't
173 # unblock the whole range.
174 list( $target, $type ) = SpecialBlock
::getTargetAndType( $target );
175 if( $block->getType() == Block
::TYPE_RANGE
&& $type == Block
::TYPE_IP
) {
176 $range = $block->getTarget();
177 return array( array( 'ipb_blocked_as_range', $target, $range ) );
180 # If the name was hidden and the blocking user cannot hide
181 # names, then don't allow any block removals...
182 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName
) {
183 return array( 'unblock-hideuser' );
187 if ( !$block->delete() ) {
188 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
191 # Unset _deleted fields as needed
192 if( $block->mHideName
) {
193 # Something is deeply FUBAR if this is not a User object, but who knows?
194 $id = $block->getTarget() instanceof User
195 ?
$block->getTarget()->getID()
196 : User
::idFromName( $block->getTarget() );
198 RevisionDeleteUser
::unsuppressUserName( $block->getTarget(), $id );
201 # Redact the name (IP address) for autoblocks
202 if ( $block->getType() == Block
::TYPE_AUTO
) {
203 $page = Title
::makeTitle( NS_USER
, '#' . $block->getId() );
205 $page = $block->getTarget() instanceof User
206 ?
$block->getTarget()->getUserpage()
207 : Title
::makeTitle( NS_USER
, $block->getTarget() );
211 $log = new LogPage( 'block' );
212 $log->addEntry( 'unblock', $page, $data['Reason'] );
217 protected function getGroupName() {