Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / includes / specials / SpecialUnblock.php
1 <?php
2 /**
3 * Implements Special:Unblock
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page for unblocking users
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialUnblock extends SpecialPage {
30
31 protected $target;
32 protected $type;
33 protected $block;
34
35 public function __construct(){
36 parent::__construct( 'Unblock', 'block' );
37 }
38
39 public function execute( $par ){
40 $this->checkPermissions();
41 $this->checkReadOnly();
42
43 list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
44 $this->block = Block::newFromTarget( $this->target );
45
46 $this->setHeaders();
47 $this->outputHeader();
48
49 $out = $this->getOutput();
50 $out->setPageTitle( $this->msg( 'unblockip' ) );
51 $out->addModules( 'mediawiki.special' );
52
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() );
58
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;
72 }
73 }
74 }
75
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,
84 ),
85 'Name' => array(
86 'type' => 'info',
87 'label-message' => 'ipadressorusername',
88 ),
89 'Reason' => array(
90 'type' => 'text',
91 'label-message' => 'ipbreason',
92 )
93 );
94
95 if( $this->block instanceof Block ){
96 list( $target, $type ) = $this->block->getTargetAndType();
97
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'] );
105
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()
115 );
116 $fields['Name']['raw'] = true;
117 break;
118
119 case Block::TYPE_RANGE:
120 $fields['Name']['default'] = $target;
121 break;
122
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;
129 }
130 }
131
132 } else {
133 $fields['Target']['default'] = $this->target;
134 unset( $fields['Name'] );
135 }
136 return $fields;
137 }
138
139 /**
140 * Submit callback for an HTMLForm object
141 * @return Array( Array(message key, parameters)
142 */
143 public static function processUIUnblock( array $data, HTMLForm $form ) {
144 return self::processUnblock( $data, $form->getContext() );
145 }
146
147 /**
148 * Process the form
149 *
150 * @param $data Array
151 * @param $context IContextSource
152 * @throws ErrorPageError
153 * @return Array( Array(message key, parameters) ) on failure, True on success
154 */
155 public static function processUnblock( array $data, IContextSource $context ){
156 $performer = $context->getUser();
157 $target = $data['Target'];
158 $block = Block::newFromTarget( $data['Target'] );
159
160 if( !$block instanceof Block ){
161 return array( array( 'ipb_cant_unblock', $target ) );
162 }
163
164 # bug 15810: blocked admins should have limited access here. This
165 # won't allow sysops to remove autoblocks on themselves, but they
166 # should have ipblock-exempt anyway
167 $status = SpecialBlock::checkUnblockSelf( $target, $performer );
168 if ( $status !== true ) {
169 throw new ErrorPageError( 'badaccess', $status );
170 }
171
172 # If the specified IP is a single address, and the block is a range block, don't
173 # unblock the whole range.
174 list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
175 if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
176 $range = $block->getTarget();
177 return array( array( 'ipb_blocked_as_range', $target, $range ) );
178 }
179
180 # If the name was hidden and the blocking user cannot hide
181 # names, then don't allow any block removals...
182 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
183 return array( 'unblock-hideuser' );
184 }
185
186 # Delete block
187 if ( !$block->delete() ) {
188 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
189 }
190
191 # Unset _deleted fields as needed
192 if( $block->mHideName ) {
193 # Something is deeply FUBAR if this is not a User object, but who knows?
194 $id = $block->getTarget() instanceof User
195 ? $block->getTarget()->getID()
196 : User::idFromName( $block->getTarget() );
197
198 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
199 }
200
201 # Redact the name (IP address) for autoblocks
202 if ( $block->getType() == Block::TYPE_AUTO ) {
203 $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
204 } else {
205 $page = $block->getTarget() instanceof User
206 ? $block->getTarget()->getUserpage()
207 : Title::makeTitle( NS_USER, $block->getTarget() );
208 }
209
210 # Make log entry
211 $log = new LogPage( 'block' );
212 $log->addEntry( 'unblock', $page, $data['Reason'] );
213
214 return true;
215 }
216 }