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->setWrapperLegendMsg( 'unblockip' );
53 $form->setSubmitCallback( array( __CLASS__
, 'processUIUnblock' ) );
54 $form->setSubmitTextMsg( 'ipusubmit' );
55 $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
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
139 * @return Array( Array(message key, parameters)
141 public static function processUIUnblock( array $data, HTMLForm
$form ) {
142 return self
::processUnblock( $data, $form->getContext() );
149 * @param $context IContextSource
150 * @return Array( Array(message key, parameters) ) on failure, True on success
152 public static function processUnblock( array $data, IContextSource
$context ){
153 $performer = $context->getUser();
154 $target = $data['Target'];
155 $block = Block
::newFromTarget( $data['Target'] );
157 if( !$block instanceof Block
){
158 return array( array( 'ipb_cant_unblock', $target ) );
161 # bug 15810: blocked admins should have limited access here. This
162 # won't allow sysops to remove autoblocks on themselves, but they
163 # should have ipblock-exempt anyway
164 $status = SpecialBlock
::checkUnblockSelf( $target, $performer );
165 if ( $status !== true ) {
166 throw new ErrorPageError( 'badaccess', $status );
169 # If the specified IP is a single address, and the block is a range block, don't
170 # unblock the whole range.
171 list( $target, $type ) = SpecialBlock
::getTargetAndType( $target );
172 if( $block->getType() == Block
::TYPE_RANGE
&& $type == Block
::TYPE_IP
) {
173 $range = $block->getTarget();
174 return array( array( 'ipb_blocked_as_range', $target, $range ) );
177 # If the name was hidden and the blocking user cannot hide
178 # names, then don't allow any block removals...
179 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName
) {
180 return array( 'unblock-hideuser' );
184 if ( !$block->delete() ) {
185 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
188 # Unset _deleted fields as needed
189 if( $block->mHideName
) {
190 # Something is deeply FUBAR if this is not a User object, but who knows?
191 $id = $block->getTarget() instanceof User
192 ?
$block->getTarget()->getID()
193 : User
::idFromName( $block->getTarget() );
195 RevisionDeleteUser
::unsuppressUserName( $block->getTarget(), $id );
198 # Redact the name (IP address) for autoblocks
199 if ( $block->getType() == Block
::TYPE_AUTO
) {
200 $page = Title
::makeTitle( NS_USER
, '#' . $block->getId() );
202 $page = $block->getTarget() instanceof User
203 ?
$block->getTarget()->getUserpage()
204 : Title
::makeTitle( NS_USER
, $block->getTarget() );
208 $log = new LogPage( 'block' );
209 $log->addEntry( 'unblock', $page, $data['Reason'] );