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() );
59 if ( $form->show() ) {
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
142 * @param HTMLForm $form
143 * @return Array( Array(message key, parameters)
145 public static function processUIUnblock( array $data, HTMLForm
$form ) {
146 return self
::processUnblock( $data, $form->getContext() );
153 * @param $context IContextSource
154 * @throws ErrorPageError
155 * @return Array( Array(message key, parameters) ) on failure, True on success
157 public static function processUnblock( array $data, IContextSource
$context ) {
158 $performer = $context->getUser();
159 $target = $data['Target'];
160 $block = Block
::newFromTarget( $data['Target'] );
162 if ( !$block instanceof Block
) {
163 return array( array( 'ipb_cant_unblock', $target ) );
166 # bug 15810: blocked admins should have limited access here. This
167 # won't allow sysops to remove autoblocks on themselves, but they
168 # should have ipblock-exempt anyway
169 $status = SpecialBlock
::checkUnblockSelf( $target, $performer );
170 if ( $status !== true ) {
171 throw new ErrorPageError( 'badaccess', $status );
174 # If the specified IP is a single address, and the block is a range block, don't
175 # unblock the whole range.
176 list( $target, $type ) = SpecialBlock
::getTargetAndType( $target );
177 if ( $block->getType() == Block
::TYPE_RANGE
&& $type == Block
::TYPE_IP
) {
178 $range = $block->getTarget();
179 return array( array( 'ipb_blocked_as_range', $target, $range ) );
182 # If the name was hidden and the blocking user cannot hide
183 # names, then don't allow any block removals...
184 if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName
) {
185 return array( 'unblock-hideuser' );
189 if ( !$block->delete() ) {
190 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
193 # Unset _deleted fields as needed
194 if ( $block->mHideName
) {
195 # Something is deeply FUBAR if this is not a User object, but who knows?
196 $id = $block->getTarget() instanceof User
197 ?
$block->getTarget()->getID()
198 : User
::idFromName( $block->getTarget() );
200 RevisionDeleteUser
::unsuppressUserName( $block->getTarget(), $id );
203 # Redact the name (IP address) for autoblocks
204 if ( $block->getType() == Block
::TYPE_AUTO
) {
205 $page = Title
::makeTitle( NS_USER
, '#' . $block->getId() );
207 $page = $block->getTarget() instanceof User
208 ?
$block->getTarget()->getUserpage()
209 : Title
::makeTitle( NS_USER
, $block->getTarget() );
213 $log = new LogPage( 'block' );
214 $log->addEntry( 'unblock', $page, $data['Reason'] );
219 protected function getGroupName() {