3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup SpecialPage
23 * A special page for unblocking users
25 * @ingroup SpecialPage
27 class SpecialUnblock
extends SpecialPage
{
33 public function __construct(){
34 parent
::__construct( 'Unblock', 'block' );
37 public function execute( $par ){
38 $this->checkPermissions();
39 $this->checkReadOnly();
41 list( $this->target
, $this->type
) = SpecialBlock
::getTargetAndType( $par, $this->getRequest() );
42 $this->block
= Block
::newFromTarget( $this->target
);
45 $this->outputHeader();
47 $out = $this->getOutput();
48 $out->setPageTitle( $this->msg( 'unblockip' ) );
49 $out->addModules( 'mediawiki.special' );
51 $form = new HTMLForm( $this->getFields(), $this->getContext() );
52 $form->setWrapperLegend( wfMsg( 'unblockip' ) );
53 $form->setSubmitCallback( array( __CLASS__
, 'processUIUnblock' ) );
54 $form->setSubmitText( wfMsg( 'ipusubmit' ) );
55 $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) );
58 switch( $this->type
){
59 case Block
::TYPE_USER
:
61 $out->addWikiMsg( 'unblocked', $this->target
);
63 case Block
::TYPE_RANGE
:
64 $out->addWikiMsg( 'unblocked-range', $this->target
);
67 case Block
::TYPE_AUTO
:
68 $out->addWikiMsg( 'unblocked-id', $this->target
);
74 protected function getFields(){
78 'label-message' => 'ipadressorusername',
85 'label-message' => 'ipadressorusername',
89 'label-message' => 'ipbreason',
93 if( $this->block
instanceof Block
){
94 list( $target, $type ) = $this->block
->getTargetAndType();
96 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
97 # User:Foo, and we've just got any block, auto or not, that applies to a target
98 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
99 # so don't show any distinction between unblocked IPs and autoblocked IPs
100 if( $type == Block
::TYPE_AUTO
&& $this->type
== Block
::TYPE_IP
){
101 $fields['Target']['default'] = $this->target
;
102 unset( $fields['Name'] );
105 $fields['Target']['default'] = $target;
106 $fields['Target']['type'] = 'hidden';
108 case Block
::TYPE_USER
:
110 $fields['Name']['default'] = Linker
::link(
111 $target->getUserPage(),
114 $fields['Name']['raw'] = true;
117 case Block
::TYPE_RANGE
:
118 $fields['Name']['default'] = $target;
121 case Block
::TYPE_AUTO
:
122 $fields['Name']['default'] = $this->block
->getRedactedName();
123 $fields['Name']['raw'] = true;
124 # Don't expose the real target of the autoblock
125 $fields['Target']['default'] = "#{$this->target}";
131 $fields['Target']['default'] = $this->target
;
132 unset( $fields['Name'] );
138 * Submit callback for an HTMLForm object
140 public static function processUIUnblock( array $data, HTMLForm
$form ) {
141 return self
::processUnblock( $data, $form->getContext() );
148 * @param $context IContextSource
149 * @return Array( Array(message key, parameters) ) on failure, True on success
151 public static function processUnblock( array $data, IContextSource
$context ){
152 $performer = $context->getUser();
153 $target = $data['Target'];
154 $block = Block
::newFromTarget( $data['Target'] );
156 if( !$block instanceof Block
){
157 return array( array( 'ipb_cant_unblock', $target ) );
160 # bug 15810: blocked admins should have limited access here. This
161 # won't allow sysops to remove autoblocks on themselves, but they
162 # should have ipblock-exempt anyway
163 $status = SpecialBlock
::checkUnblockSelf( $target, $performer );
164 if ( $status !== true ) {
165 throw new ErrorPageError( 'badaccess', $status );
168 # If the specified IP is a single address, and the block is a range block, don't
169 # unblock the whole range.
170 list( $target, $type ) = SpecialBlock
::getTargetAndType( $target );
171 if( $block->getType() == Block
::TYPE_RANGE
&& $type == Block
::TYPE_IP
) {
172 $range = $block->getTarget();
173 return array( array( 'ipb_blocked_as_range', $target, $range ) );
176 # If the name was hidden and the blocking user cannot hide
177 # names, then don't allow any block removals...
178 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName
) {
179 return array( 'unblock-hideuser' );
183 if ( !$block->delete() ) {
184 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
187 # Unset _deleted fields as needed
188 if( $block->mHideName
) {
189 # Something is deeply FUBAR if this is not a User object, but who knows?
190 $id = $block->getTarget() instanceof User
191 ?
$block->getTarget()->getID()
192 : User
::idFromName( $block->getTarget() );
194 RevisionDeleteUser
::unsuppressUserName( $block->getTarget(), $id );
197 # Redact the name (IP address) for autoblocks
198 if ( $block->getType() == Block
::TYPE_AUTO
) {
199 $page = Title
::makeTitle( NS_USER
, '#' . $block->getId() );
201 $page = $block->getTarget() instanceof User
202 ?
$block->getTarget()->getUserpage()
203 : Title
::makeTitle( NS_USER
, $block->getTarget() );
207 $log = new LogPage( 'block' );
208 $log->addEntry( 'unblock', $page, $data['Reason'] );