Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / specials / SpecialUnblock.php
blob4da5155a214bf30335dc998abb8d13a5a65eebbe
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page for unblocking users
27 * @ingroup SpecialPage
29 class SpecialUnblock extends SpecialPage {
31 protected $target;
32 protected $type;
33 protected $block;
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 );
46 $this->setHeaders();
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:
62 case Block::TYPE_IP:
63 $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) );
64 break;
65 case Block::TYPE_RANGE:
66 $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) );
67 break;
68 case Block::TYPE_ID:
69 case Block::TYPE_AUTO:
70 $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) );
71 break;
76 protected function getFields() {
77 $fields = array(
78 'Target' => array(
79 'type' => 'text',
80 'label-message' => 'ipadressorusername',
81 'tabindex' => '1',
82 'size' => '45',
83 'required' => true,
85 'Name' => array(
86 'type' => 'info',
87 'label-message' => 'ipadressorusername',
89 'Reason' => array(
90 'type' => 'text',
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'] );
106 } else {
107 $fields['Target']['default'] = $target;
108 $fields['Target']['type'] = 'hidden';
109 switch ( $type ) {
110 case Block::TYPE_USER:
111 case Block::TYPE_IP:
112 $fields['Name']['default'] = Linker::link(
113 $target->getUserPage(),
114 $target->getName()
116 $fields['Name']['raw'] = true;
117 break;
119 case Block::TYPE_RANGE:
120 $fields['Name']['default'] = $target;
121 break;
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}";
128 break;
132 } else {
133 $fields['Target']['default'] = $this->target;
134 unset( $fields['Name'] );
136 return $fields;
140 * Submit callback for an HTMLForm object
141 * @param array $data
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() );
150 * Process the form
152 * @param $data Array
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' );
188 # Delete block
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() );
206 } else {
207 $page = $block->getTarget() instanceof User
208 ? $block->getTarget()->getUserpage()
209 : Title::makeTitle( NS_USER, $block->getTarget() );
212 # Make log entry
213 $log = new LogPage( 'block' );
214 $log->addEntry( 'unblock', $page, $data['Reason'] );
216 return true;
219 protected function getGroupName() {
220 return 'users';