Change usages of $wgUser->getSkin() in special pages to use $this->getSkin()
[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(), $this->getContext() );
65 $form->setWrapperLegend( wfMsg( 'unblockip' ) );
66 $form->setSubmitCallback( array( __CLASS__, 'processUnblock' ) );
67 $form->setSubmitText( wfMsg( 'ipusubmit' ) );
68 $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) );
69
70 if( $form->show() ){
71 switch( $this->type ){
72 case Block::TYPE_USER:
73 case Block::TYPE_IP:
74 $wgOut->addWikiMsg( 'unblocked', $this->target );
75 break;
76 case Block::TYPE_RANGE:
77 $wgOut->addWikiMsg( 'unblocked-range', $this->target );
78 break;
79 case Block::TYPE_ID:
80 case Block::TYPE_AUTO:
81 $wgOut->addWikiMsg( 'unblocked-id', $this->target );
82 break;
83 }
84 }
85 }
86
87 protected function getFields(){
88 $fields = array(
89 'Target' => array(
90 'type' => 'text',
91 'label-message' => 'ipadressorusername',
92 'tabindex' => '1',
93 'size' => '45',
94 'required' => true,
95 ),
96 'Name' => array(
97 'type' => 'info',
98 'label-message' => 'ipadressorusername',
99 ),
100 'Reason' => array(
101 'type' => 'text',
102 'label-message' => 'ipbreason',
103 )
104 );
105
106 if( $this->block instanceof Block ){
107 list( $target, $type ) = $this->block->getTargetAndType();
108
109 # Autoblocks are logged as "autoblock #123 because the IP was recently used by
110 # User:Foo, and we've just got any block, auto or not, that applies to a target
111 # the user has specified. Someone could be fishing to connect IPs to autoblocks,
112 # so don't show any distinction between unblocked IPs and autoblocked IPs
113 if( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ){
114 $fields['Target']['default'] = $this->target;
115 unset( $fields['Name'] );
116
117 } else {
118 $fields['Target']['default'] = $target;
119 $fields['Target']['type'] = 'hidden';
120 switch( $type ){
121 case Block::TYPE_USER:
122 case Block::TYPE_IP:
123 $skin = $this->getSkin();
124 $fields['Name']['default'] = $skin->link(
125 $target->getUserPage(),
126 $target->getName()
127 );
128 $fields['Name']['raw'] = true;
129 break;
130
131 case Block::TYPE_RANGE:
132 $fields['Name']['default'] = $target;
133 break;
134
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}";
140 break;
141 }
142 }
143
144 } else {
145 $fields['Target']['default'] = $this->target;
146 unset( $fields['Name'] );
147 }
148 return $fields;
149 }
150
151 /**
152 * Process the form
153 * @return Array( Array(message key, parameters) ) on failure, True on success
154 */
155 public static function processUnblock( array $data ){
156 global $wgUser;
157
158 $target = $data['Target'];
159 $block = Block::newFromTarget( $data['Target'] );
160
161 if( !$block instanceof Block ){
162 return array( array( 'ipb_cant_unblock', $target ) );
163 }
164
165 # If the specified IP is a single address, and the block is a range block, don't
166 # unblock the whole range.
167 list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
168 if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
169 $range = $block->getTarget();
170 return array( array( 'ipb_blocked_as_range', $target, $range ) );
171 }
172
173 # If the name was hidden and the blocking user cannot hide
174 # names, then don't allow any block removals...
175 if( !$wgUser->isAllowed( 'hideuser' ) && $block->mHideName ) {
176 return array( 'unblock-hideuser' );
177 }
178
179 # Delete block
180 if ( !$block->delete() ) {
181 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
182 }
183
184 # Unset _deleted fields as needed
185 if( $block->mHideName ) {
186 # Something is deeply FUBAR if this is not a User object, but who knows?
187 $id = $block->getTarget() instanceof User
188 ? $block->getTarget()->getID()
189 : User::idFromName( $block->getTarget() );
190
191 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
192 }
193
194 # Make log entry
195 $log = new LogPage( 'block' );
196 $page = $block->getTarget() instanceof User
197 ? $block->getTarget()->getUserpage()
198 : Title::makeTitle( NS_USER, $block->getTarget() );
199 $log->addEntry( 'unblock', $page, $data['Reason'] );
200
201 return true;
202 }
203 }