Use class name Html in canonical form.
[lhc/web/wiklou.git] / includes / specials / SpecialUnblock.php
1 <?php
2 /**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup SpecialPage
20 */
21
22 /**
23 * A special page for unblocking users
24 *
25 * @ingroup SpecialPage
26 */
27 class SpecialUnblock extends SpecialPage {
28
29 protected $target;
30 protected $type;
31 protected $block;
32
33 public function __construct(){
34 parent::__construct( 'Unblock', 'block' );
35 }
36
37 public function execute( $par ){
38 global $wgUser, $wgOut, $wgRequest;
39
40 # Check permissions
41 if( !$wgUser->isAllowed( 'block' ) ) {
42 $wgOut->permissionRequired( 'block' );
43 return;
44 }
45 # Check for database lock
46 if( wfReadOnly() ) {
47 $wgOut->readOnlyPage();
48 return;
49 }
50
51 list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $wgRequest );
52 $this->block = Block::newFromTarget( $this->target );
53
54 # bug 15810: blocked admins should have limited access here. This won't allow sysops
55 # to remove autoblocks on themselves, but they should have ipblock-exempt anyway
56 $status = SpecialBlock::checkUnblockSelf( $this->target );
57 if ( $status !== true ) {
58 throw new ErrorPageError( 'badaccess', $status );
59 }
60
61 $wgOut->setPageTitle( wfMsg( 'unblockip' ) );
62 $wgOut->addModules( 'mediawiki.special' );
63
64 $form = new HTMLForm( $this->getFields() );
65 $form->setTitle( $this->getTitle() );
66 $form->setWrapperLegend( wfMsg( 'unblockip' ) );
67 $form->setSubmitCallback( array( __CLASS__, 'processUnblock' ) );
68 $form->setSubmitText( wfMsg( 'ipusubmit' ) );
69 $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) );
70
71 if( $form->show() ){
72 switch( $this->type ){
73 case Block::TYPE_USER:
74 case Block::TYPE_IP:
75 $wgOut->addWikiMsg( 'unblocked', $this->target );
76 break;
77 case Block::TYPE_RANGE:
78 $wgOut->addWikiMsg( 'unblocked-range', $this->target );
79 break;
80 case Block::TYPE_ID:
81 case Block::TYPE_AUTO:
82 $wgOut->addWikiMsg( 'unblocked-id', $this->target );
83 break;
84 }
85 }
86 }
87
88 protected function getFields(){
89 $fields = array(
90 'Target' => array(
91 'type' => 'text',
92 'label-message' => 'ipadressorusername',
93 'tabindex' => '1',
94 'size' => '45',
95 'required' => true,
96 ),
97 'Name' => array(
98 'type' => 'info',
99 'label-message' => 'ipadressorusername',
100 ),
101 'Reason' => array(
102 'type' => 'text',
103 'label-message' => 'ipbreason',
104 )
105 );
106
107 if( $this->block instanceof Block ){
108 list( $target, $type ) = $this->block->getTargetAndType();
109
110 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
111 # User:Foo, and we've just got any block, auto or not, that applies to a target
112 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
113 # so don't show any distinction between unblocked IPs and autoblocked IPs
114 if( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ){
115 $fields['Target']['default'] = $this->target;
116 unset( $fields['Name'] );
117
118 } else {
119 global $wgUser;
120
121 $fields['Target']['default'] = $target;
122 $fields['Target']['type'] = 'hidden';
123 switch( $type ){
124 case Block::TYPE_USER:
125 case Block::TYPE_IP:
126 $skin = $wgUser->getSkin();
127 $fields['Name']['default'] = $skin->link(
128 $target->getUserPage(),
129 $target->getName()
130 );
131 $fields['Name']['raw'] = true;
132 break;
133
134 case Block::TYPE_RANGE:
135 $fields['Name']['default'] = $target;
136 break;
137
138 case Block::TYPE_AUTO:
139 $fields['Name']['default'] = $this->block->getRedactedName();
140 $fields['Name']['raw'] = true;
141 # Don't expose the real target of the autoblock
142 $fields['Target']['default'] = "#{$this->target}";
143 break;
144 }
145 }
146
147 } else {
148 $fields['Target']['default'] = $this->target;
149 unset( $fields['Name'] );
150 }
151 return $fields;
152 }
153
154 /**
155 * Process the form
156 * @return Array( Array(message key, parameters) ) on failure, True on success
157 */
158 public static function processUnblock( array $data ){
159 global $wgUser;
160
161 $target = $data['Target'];
162 $block = Block::newFromTarget( $data['Target'] );
163
164 if( !$block instanceof Block ){
165 return array( array( 'ipb_cant_unblock', $target ) );
166 }
167
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 ) );
174 }
175
176 # If the name was hidden and the blocking user cannot hide
177 # names, then don't allow any block removals...
178 if( !$wgUser->isAllowed( 'hideuser' ) && $block->mHideName ) {
179 return array( 'unblock-hideuser' );
180 }
181
182 # Delete block
183 if ( !$block->delete() ) {
184 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
185 }
186
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() );
193
194 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
195 }
196
197 # Make log entry
198 $log = new LogPage( 'block' );
199 $page = $block->getTarget() instanceof User
200 ? $block->getTarget()->getUserpage()
201 : Title::makeTitle( NS_USER, $block->getTarget() );
202 $log->addEntry( 'unblock', $page, $data['Reason'] );
203
204 return true;
205 }
206 }