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
);
45 if ( $this->target
instanceof User
) {
46 # Set the 'relevant user' in the skin, so it displays links like Contributions,
47 # User logs, UserRights, etc.
48 $this->getSkin()->setRelevantUser( $this->target
);
52 $this->outputHeader();
54 $out = $this->getOutput();
55 $out->setPageTitle( $this->msg( 'unblockip' ) );
56 $out->addModules( 'mediawiki.special' );
58 $form = new HTMLForm( $this->getFields(), $this->getContext() );
59 $form->setWrapperLegendMsg( 'unblockip' );
60 $form->setSubmitCallback( array( __CLASS__
, 'processUIUnblock' ) );
61 $form->setSubmitTextMsg( 'ipusubmit' );
62 $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
64 if ( $form->show() ) {
65 switch ( $this->type
) {
67 $out->addWikiMsg( 'unblocked-ip', wfEscapeWikiText( $this->target
) );
69 case Block
::TYPE_USER
:
70 $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target
) );
72 case Block
::TYPE_RANGE
:
73 $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target
) );
76 case Block
::TYPE_AUTO
:
77 $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target
) );
83 protected function getFields() {
87 'label-message' => 'ipaddressorusername',
94 'label-message' => 'ipaddressorusername',
98 'label-message' => 'ipbreason',
102 if ( $this->block
instanceof Block
) {
103 list( $target, $type ) = $this->block
->getTargetAndType();
105 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
106 # User:Foo, and we've just got any block, auto or not, that applies to a target
107 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
108 # so don't show any distinction between unblocked IPs and autoblocked IPs
109 if ( $type == Block
::TYPE_AUTO
&& $this->type
== Block
::TYPE_IP
) {
110 $fields['Target']['default'] = $this->target
;
111 unset( $fields['Name'] );
113 $fields['Target']['default'] = $target;
114 $fields['Target']['type'] = 'hidden';
117 $fields['Name']['default'] = Linker
::linkKnown(
118 SpecialPage
::getTitleFor( 'Contributions', $target->getName() ),
121 $fields['Name']['raw'] = true;
123 case Block
::TYPE_USER
:
124 $fields['Name']['default'] = Linker
::link(
125 $target->getUserPage(),
128 $fields['Name']['raw'] = true;
131 case Block
::TYPE_RANGE
:
132 $fields['Name']['default'] = $target;
135 case Block
::TYPE_AUTO
:
136 $fields['Name']['default'] = $this->block
->getRedactedName();
137 $fields['Name']['raw'] = true;
138 # Don't expose the real target of the autoblock
139 $fields['Target']['default'] = "#{$this->target}";
142 // target is hidden, so the reason is the first element
143 $fields['Target']['autofocus'] = false;
144 $fields['Reason']['autofocus'] = true;
147 $fields['Target']['default'] = $this->target
;
148 unset( $fields['Name'] );
155 * Submit callback for an HTMLForm object
157 * @param HTMLForm $form
158 * @return array|bool Array(message key, parameters)
160 public static function processUIUnblock( array $data, HTMLForm
$form ) {
161 return self
::processUnblock( $data, $form->getContext() );
168 * @param IContextSource $context
169 * @throws ErrorPageError
170 * @return array|bool Array(message key, parameters) on failure, True on success
172 public static function processUnblock( array $data, IContextSource
$context ) {
173 $performer = $context->getUser();
174 $target = $data['Target'];
175 $block = Block
::newFromTarget( $data['Target'] );
177 if ( !$block instanceof Block
) {
178 return array( array( 'ipb_cant_unblock', $target ) );
181 # bug 15810: blocked admins should have limited access here. This
182 # won't allow sysops to remove autoblocks on themselves, but they
183 # should have ipblock-exempt anyway
184 $status = SpecialBlock
::checkUnblockSelf( $target, $performer );
185 if ( $status !== true ) {
186 throw new ErrorPageError( 'badaccess', $status );
189 # If the specified IP is a single address, and the block is a range block, don't
190 # unblock the whole range.
191 list( $target, $type ) = SpecialBlock
::getTargetAndType( $target );
192 if ( $block->getType() == Block
::TYPE_RANGE
&& $type == Block
::TYPE_IP
) {
193 $range = $block->getTarget();
195 return array( array( 'ipb_blocked_as_range', $target, $range ) );
198 # If the name was hidden and the blocking user cannot hide
199 # names, then don't allow any block removals...
200 if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName
) {
201 return array( 'unblock-hideuser' );
205 if ( !$block->delete() ) {
206 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
209 # Unset _deleted fields as needed
210 if ( $block->mHideName
) {
211 # Something is deeply FUBAR if this is not a User object, but who knows?
212 $id = $block->getTarget() instanceof User
213 ?
$block->getTarget()->getID()
214 : User
::idFromName( $block->getTarget() );
216 RevisionDeleteUser
::unsuppressUserName( $block->getTarget(), $id );
219 # Redact the name (IP address) for autoblocks
220 if ( $block->getType() == Block
::TYPE_AUTO
) {
221 $page = Title
::makeTitle( NS_USER
, '#' . $block->getId() );
223 $page = $block->getTarget() instanceof User
224 ?
$block->getTarget()->getUserpage()
225 : Title
::makeTitle( NS_USER
, $block->getTarget() );
229 $log = new LogPage( 'block' );
230 $log->addEntry( 'unblock', $page, $data['Reason'], array(), $performer );
235 protected function getGroupName() {