Index: trunk/phase3/includes/specials/SpecialBlockip.php |
— | — | @@ -1,846 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Implements Special:Blockip |
5 | | - * |
6 | | - * This program is free software; you can redistribute it and/or modify |
7 | | - * it under the terms of the GNU General Public License as published by |
8 | | - * the Free Software Foundation; either version 2 of the License, or |
9 | | - * (at your option) any later version. |
10 | | - * |
11 | | - * This program is distributed in the hope that it will be useful, |
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | - * GNU General Public License for more details. |
15 | | - * |
16 | | - * You should have received a copy of the GNU General Public License along |
17 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
18 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | - * http://www.gnu.org/copyleft/gpl.html |
20 | | - * |
21 | | - * @file |
22 | | - * @ingroup SpecialPage |
23 | | - */ |
24 | | - |
25 | | -/** |
26 | | - * A special page that allows users with 'block' right to block users from |
27 | | - * editing pages and other actions |
28 | | - * |
29 | | - * @ingroup SpecialPage |
30 | | - */ |
31 | | -class IPBlockForm extends SpecialPage { |
32 | | - var $BlockAddress, $BlockExpiry, $BlockReason, $BlockReasonList, $BlockOther, $BlockAnonOnly, $BlockCreateAccount, |
33 | | - $BlockEnableAutoblock, $BlockEmail, $BlockHideName, $BlockAllowUsertalk, $BlockReblock, $BlockWatchUser; |
34 | | - // The maximum number of edits a user can have and still be hidden |
35 | | - const HIDEUSER_CONTRIBLIMIT = 1000; |
36 | | - |
37 | | - public function __construct() { |
38 | | - parent::__construct( 'Blockip', 'block' ); |
39 | | - } |
40 | | - |
41 | | - public function execute( $par ) { |
42 | | - global $wgUser, $wgOut, $wgRequest; |
43 | | - |
44 | | - # Can't block when the database is locked |
45 | | - if( wfReadOnly() ) { |
46 | | - $wgOut->readOnlyPage(); |
47 | | - return; |
48 | | - } |
49 | | - # Permission check |
50 | | - if( !$this->userCanExecute( $wgUser ) ) { |
51 | | - $wgOut->permissionRequired( 'block' ); |
52 | | - return; |
53 | | - } |
54 | | - |
55 | | - $this->setup( $par ); |
56 | | - |
57 | | - # bug 15810: blocked admins should have limited access here |
58 | | - if ( $wgUser->isBlocked() ) { |
59 | | - $status = IPBlockForm::checkUnblockSelf( $this->BlockAddress ); |
60 | | - if ( $status !== true ) { |
61 | | - throw new ErrorPageError( 'badaccess', $status ); |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - $action = $wgRequest->getVal( 'action' ); |
66 | | - if( 'success' == $action ) { |
67 | | - $this->showSuccess(); |
68 | | - } elseif( $wgRequest->wasPosted() && 'submit' == $action && |
69 | | - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
70 | | - $this->doSubmit(); |
71 | | - } else { |
72 | | - $this->showForm( '' ); |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - private function setup( $par ) { |
77 | | - global $wgRequest, $wgUser, $wgBlockAllowsUTEdit; |
78 | | - |
79 | | - $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) ); |
80 | | - $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' ); |
81 | | - $this->BlockReason = $wgRequest->getText( 'wpBlockReason' ); |
82 | | - $this->BlockReasonList = $wgRequest->getText( 'wpBlockReasonList' ); |
83 | | - $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) ); |
84 | | - $this->BlockOther = $wgRequest->getVal( 'wpBlockOther', '' ); |
85 | | - |
86 | | - # Unchecked checkboxes are not included in the form data at all, so having one |
87 | | - # that is true by default is a bit tricky |
88 | | - $byDefault = !$wgRequest->wasPosted(); |
89 | | - $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault ); |
90 | | - $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault ); |
91 | | - $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault ); |
92 | | - $this->BlockEmail = false; |
93 | | - if( self::canBlockEmail( $wgUser ) ) { |
94 | | - $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false ); |
95 | | - } |
96 | | - $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false ) && $wgUser->isLoggedIn(); |
97 | | - # Re-check user's rights to hide names, very serious, defaults to null |
98 | | - if( $wgUser->isAllowed( 'hideuser' ) ) { |
99 | | - $this->BlockHideName = $wgRequest->getBool( 'wpHideName', null ); |
100 | | - } else { |
101 | | - $this->BlockHideName = false; |
102 | | - } |
103 | | - $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit ); |
104 | | - $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false ); |
105 | | - |
106 | | - $this->wasPosted = $wgRequest->wasPosted(); |
107 | | - } |
108 | | - |
109 | | - public function showForm( $err ) { |
110 | | - global $wgOut, $wgUser; |
111 | | - |
112 | | - $wgOut->setPageTitle( wfMsg( 'blockip-title' ) ); |
113 | | - $wgOut->addWikiMsg( 'blockiptext' ); |
114 | | - |
115 | | - $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' ); |
116 | | - $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' ); |
117 | | - $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' ); |
118 | | - $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' ); |
119 | | - $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' ); |
120 | | - |
121 | | - $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
122 | | - $user = User::newFromName( $this->BlockAddress ); |
123 | | - if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) { |
124 | | - $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) ); |
125 | | - } |
126 | | - |
127 | | - $alreadyBlocked = false; |
128 | | - $otherBlockedMsgs = array(); |
129 | | - if( $err && $err[0] != 'ipb_already_blocked' ) { |
130 | | - $key = array_shift( $err ); |
131 | | - $msg = wfMsgExt( $key, 'parsemag', $err ); |
132 | | - $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
133 | | - $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) ); |
134 | | - } elseif( $this->BlockAddress !== null ) { |
135 | | - # Get other blocks, i.e. from GlobalBlocking or TorBlock extension |
136 | | - wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress ) ); |
137 | | - |
138 | | - $userId = is_object( $user ) ? $user->getId() : 0; |
139 | | - $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); |
140 | | - if( !is_null( $currentBlock ) && !$currentBlock->mAuto && # The block exists and isn't an autoblock |
141 | | - ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock |
142 | | - # or if it is, the range is what we're about to block |
143 | | - ( $currentBlock->mAddress == $this->BlockAddress ) ) |
144 | | - ) { |
145 | | - $alreadyBlocked = true; |
146 | | - # Set the block form settings to the existing block |
147 | | - if( !$this->wasPosted ) { |
148 | | - $this->BlockAnonOnly = $currentBlock->mAnonOnly; |
149 | | - $this->BlockCreateAccount = $currentBlock->mCreateAccount; |
150 | | - $this->BlockEnableAutoblock = $currentBlock->mEnableAutoblock; |
151 | | - $this->BlockEmail = $currentBlock->mBlockEmail; |
152 | | - $this->BlockHideName = $currentBlock->mHideName; |
153 | | - $this->BlockAllowUsertalk = $currentBlock->mAllowUsertalk; |
154 | | - if( $currentBlock->mExpiry == 'infinity' ) { |
155 | | - $this->BlockOther = 'indefinite'; |
156 | | - } else { |
157 | | - $this->BlockOther = wfTimestamp( TS_ISO_8601, $currentBlock->mExpiry ); |
158 | | - } |
159 | | - $this->BlockReason = $currentBlock->mReason; |
160 | | - } |
161 | | - } |
162 | | - } |
163 | | - |
164 | | - # Show other blocks from extensions, i.e. GlockBlocking and TorBlock |
165 | | - if( count( $otherBlockedMsgs ) ) { |
166 | | - $wgOut->addHTML( |
167 | | - Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n" |
168 | | - ); |
169 | | - $list = ''; |
170 | | - foreach( $otherBlockedMsgs as $link ) { |
171 | | - $list .= Html::rawElement( 'li', array(), $link ) . "\n"; |
172 | | - } |
173 | | - $wgOut->addHTML( Html::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" ); |
174 | | - } |
175 | | - |
176 | | - # Username/IP is blocked already locally |
177 | | - if( $alreadyBlocked ) { |
178 | | - $wgOut->wrapWikiMsg( "<div class='mw-ipb-needreblock'>\n$1\n</div>", array( 'ipb-needreblock', $this->BlockAddress ) ); |
179 | | - } |
180 | | - |
181 | | - $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); |
182 | | - |
183 | | - $showblockoptions = $scBlockExpiryOptions != '-'; |
184 | | - if( !$showblockoptions ) $mIpbother = $mIpbexpiry; |
185 | | - |
186 | | - $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' ); |
187 | | - foreach( explode( ',', $scBlockExpiryOptions ) as $option ) { |
188 | | - if( strpos( $option, ':' ) === false ) $option = "$option:$option"; |
189 | | - list( $show, $value ) = explode( ':', $option ); |
190 | | - $show = htmlspecialchars( $show ); |
191 | | - $value = htmlspecialchars( $value ); |
192 | | - $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ) . "\n"; |
193 | | - } |
194 | | - |
195 | | - $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', |
196 | | - wfMsgForContent( 'ipbreason-dropdown' ), |
197 | | - wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 ); |
198 | | - |
199 | | - # FIXME: this should actually use HTMLForm, not just some of its JavaScript |
200 | | - $wgOut->addModules( array( 'mediawiki.special.block', 'mediawiki.htmlform' ) ); |
201 | | - |
202 | | - $wgOut->addHTML( |
203 | | - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) . |
204 | | - Xml::openElement( 'fieldset' ) . |
205 | | - Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) . |
206 | | - Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) . |
207 | | - "<tr> |
208 | | - <td class='mw-label'> |
209 | | - {$mIpaddress} |
210 | | - </td> |
211 | | - <td class='mw-input'>" . |
212 | | - Html::input( 'wpBlockAddress', $this->BlockAddress, 'text', array( |
213 | | - 'tabindex' => '1', |
214 | | - 'id' => 'mw-bi-target', |
215 | | - 'size' => '45', |
216 | | - 'required' => '' |
217 | | - ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). " |
218 | | - </td> |
219 | | - </tr> |
220 | | - <tr> |
221 | | - <td class='mw-label'> |
222 | | - {$mIpbexpiry} |
223 | | - </td> |
224 | | - <td class='mw-input'>" |
225 | | - ); |
226 | | - if( $showblockoptions ) { |
227 | | - $wgOut->addHTML( |
228 | | - Xml::tags( 'select', |
229 | | - array( |
230 | | - 'id' => 'wpBlockExpiry', |
231 | | - 'name' => 'wpBlockExpiry', |
232 | | - 'class' => 'mw-htmlform-select-or-other', # FIXME: actually make this use HTMLForm |
233 | | - 'tabindex' => '2' ), |
234 | | - $blockExpiryFormOptions |
235 | | - ) . "<br/>\n" |
236 | | - ); |
237 | | - } |
238 | | - $wgOut->addHTML( |
239 | | - Xml::input( |
240 | | - 'wpBlockOther', |
241 | | - 45, |
242 | | - $this->BlockOther, |
243 | | - array( |
244 | | - 'tabindex' => '3', |
245 | | - 'id' => 'wpBlockExpiry-other' |
246 | | - ) |
247 | | - ) . " |
248 | | - </td> |
249 | | - </tr> |
250 | | - <tr> |
251 | | - <td class='mw-label'> |
252 | | - {$mIpbreasonother} |
253 | | - </td> |
254 | | - <td class='mw-input'> |
255 | | - {$reasonDropDown} |
256 | | - </td> |
257 | | - </tr> |
258 | | - <tr id=\"wpBlockReason\"> |
259 | | - <td class='mw-label'> |
260 | | - {$mIpbreason} |
261 | | - </td> |
262 | | - <td class='mw-input'>" . |
263 | | - Html::input( 'wpBlockReason', $this->BlockReason, 'text', array( |
264 | | - 'tabindex' => '5', |
265 | | - 'id' => 'mw-bi-reason', |
266 | | - 'maxlength' => '200', |
267 | | - 'size' => '45' |
268 | | - ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . " |
269 | | - </td> |
270 | | - </tr> |
271 | | - <tr id='wpCreateAccountRow'> |
272 | | - <td> </td> |
273 | | - <td class='mw-input'>" . |
274 | | - Xml::checkLabel( wfMsg( 'ipbcreateaccount' ), |
275 | | - 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount, |
276 | | - array( 'tabindex' => '7' ) ) . " |
277 | | - </td> |
278 | | - </tr>" |
279 | | - ); |
280 | | - |
281 | | - if( self::canBlockEmail( $wgUser ) ) { |
282 | | - $wgOut->addHTML(" |
283 | | - <tr id='wpEnableEmailBan'> |
284 | | - <td> </td> |
285 | | - <td class='mw-input'>" . |
286 | | - Xml::checkLabel( wfMsg( 'ipbemailban' ), |
287 | | - 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, |
288 | | - array( 'tabindex' => '9' ) ) . " |
289 | | - </td> |
290 | | - </tr>" |
291 | | - ); |
292 | | - } |
293 | | - |
294 | | - # Can we explicitly disallow the use of user_talk? |
295 | | - global $wgBlockAllowsUTEdit; |
296 | | - if( $wgBlockAllowsUTEdit ){ |
297 | | - $wgOut->addHTML(" |
298 | | - <tr id='wpAllowUsertalkRow'> |
299 | | - <td> </td> |
300 | | - <td class='mw-input'>" . |
301 | | - Xml::checkLabel( wfMsg( 'ipballowusertalk' ), |
302 | | - 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk, |
303 | | - array( 'tabindex' => '12' ) ) . " |
304 | | - </td> |
305 | | - </tr>" |
306 | | - ); |
307 | | - } |
308 | | - |
309 | | - $wgOut->addHTML( " |
310 | | - <tr id='wpEnableAutoblockRow'> |
311 | | - <td> </td> |
312 | | - <td class='mw-input'>" . |
313 | | - Xml::checkLabel( wfMsg( 'ipbenableautoblock' ), |
314 | | - 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock, |
315 | | - array( 'tabindex' => '8' ) ) . " |
316 | | - </td> |
317 | | - </tr>" |
318 | | - ); |
319 | | - |
320 | | - // Allow some users to hide name from block log, blocklist and listusers |
321 | | - if( $wgUser->isAllowed( 'hideuser' ) ) { |
322 | | - $wgOut->addHTML(" |
323 | | - <tr id='wpEnableHideUser'> |
324 | | - <td> </td> |
325 | | - <td class='mw-input'><strong>" . |
326 | | - Xml::checkLabel( wfMsg( 'ipbhidename' ), |
327 | | - 'wpHideName', 'wpHideName', $this->BlockHideName, |
328 | | - array( 'tabindex' => '10' ) |
329 | | - ) . " |
330 | | - </strong></td> |
331 | | - </tr>" |
332 | | - ); |
333 | | - } |
334 | | - |
335 | | - # Watchlist their user page? (Only if user is logged in) |
336 | | - if( $wgUser->isLoggedIn() ) { |
337 | | - $wgOut->addHTML(" |
338 | | - <tr id='wpEnableWatchUser'> |
339 | | - <td> </td> |
340 | | - <td class='mw-input'>" . |
341 | | - Xml::checkLabel( wfMsg( 'ipbwatchuser' ), |
342 | | - 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser, |
343 | | - array( 'tabindex' => '11' ) ) . " |
344 | | - </td> |
345 | | - </tr>" |
346 | | - ); |
347 | | - } |
348 | | - |
349 | | - $wgOut->addHTML(" |
350 | | - <tr id='wpAnonOnlyRow'> |
351 | | - <td> </td> |
352 | | - <td class='mw-input'>" . |
353 | | - Xml::checkLabel( wfMsg( 'ipbanononly' ), |
354 | | - 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly, |
355 | | - array( 'tabindex' => '6' ) ) . " |
356 | | - </td> |
357 | | - </tr> |
358 | | - <tr> |
359 | | - <td style='padding-top: 1em'> </td> |
360 | | - <td class='mw-submit' style='padding-top: 1em'>" . |
361 | | - Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ), |
362 | | - array( 'name' => 'wpBlock', 'tabindex' => '13' ) |
363 | | - + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'blockip-block' ) ). " |
364 | | - </td> |
365 | | - </tr>" . |
366 | | - Xml::closeElement( 'table' ) . |
367 | | - Html::hidden( 'wpEditToken', $wgUser->editToken() ) . |
368 | | - ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) . |
369 | | - Xml::closeElement( 'fieldset' ) . |
370 | | - Xml::closeElement( 'form' ) |
371 | | - ); |
372 | | - |
373 | | - $wgOut->addHTML( $this->getConvenienceLinks() ); |
374 | | - |
375 | | - if( is_object( $user ) ) { |
376 | | - $this->showLogFragment( $wgOut, $user->getUserPage() ); |
377 | | - } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) { |
378 | | - $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
379 | | - } elseif( preg_match( '/^\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}/', $this->BlockAddress ) ) { |
380 | | - $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
381 | | - } |
382 | | - } |
383 | | - |
384 | | - /** |
385 | | - * Can we do an email block? |
386 | | - * @param $user User: the sysop wanting to make a block |
387 | | - * @return Boolean |
388 | | - */ |
389 | | - public static function canBlockEmail( $user ) { |
390 | | - global $wgEnableUserEmail, $wgSysopEmailBans; |
391 | | - return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); |
392 | | - } |
393 | | - |
394 | | - /** |
395 | | - * bug 15810: blocked admins should not be able to block/unblock |
396 | | - * others, and probably shouldn't be able to unblock themselves |
397 | | - * either. |
398 | | - * @param $user User|Int|String |
399 | | - */ |
400 | | - public static function checkUnblockSelf( $user ) { |
401 | | - global $wgUser; |
402 | | - if ( is_int( $user ) ) { |
403 | | - $user = User::newFromId( $user ); |
404 | | - } elseif ( is_string( $user ) ) { |
405 | | - $user = User::newFromName( $user ); |
406 | | - } |
407 | | - if( $user instanceof User && $user->getId() == $wgUser->getId() ) { |
408 | | - # User is trying to unblock themselves |
409 | | - if ( $wgUser->isAllowed( 'unblockself' ) ) { |
410 | | - return true; |
411 | | - } else { |
412 | | - return 'ipbnounblockself'; |
413 | | - } |
414 | | - } else { |
415 | | - # User is trying to block/unblock someone else |
416 | | - return 'ipbblocked'; |
417 | | - } |
418 | | - } |
419 | | - |
420 | | - /** |
421 | | - * Backend block code. |
422 | | - * $userID and $expiry will be filled accordingly |
423 | | - * @return array(message key, arguments) on failure, empty array on success |
424 | | - */ |
425 | | - function doBlock( &$userId = null, &$expiry = null ) { |
426 | | - global $wgUser, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit; |
427 | | - |
428 | | - $userId = 0; |
429 | | - # Expand valid IPv6 addresses, usernames are left as is |
430 | | - $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress ); |
431 | | - # isIPv4() and IPv6() are used for final validation |
432 | | - $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; |
433 | | - $rxIP6 = '\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}'; |
434 | | - $rxIP = "($rxIP4|$rxIP6)"; |
435 | | - |
436 | | - # Check for invalid specifications |
437 | | - if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { |
438 | | - $matches = array(); |
439 | | - if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { |
440 | | - # IPv4 |
441 | | - if( $wgBlockCIDRLimit['IPv4'] != 32 ){ |
442 | | - if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] > 32 ) { |
443 | | - return array( 'ip_range_invalid' ); |
444 | | - } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) { |
445 | | - return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); |
446 | | - } |
447 | | - $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
448 | | - } else { |
449 | | - # Range block illegal |
450 | | - return array( 'range_block_disabled' ); |
451 | | - } |
452 | | - } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { |
453 | | - # IPv6 |
454 | | - if( $wgBlockCIDRLimit['IPv6'] != 128 ) { |
455 | | - if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] > 128 ) { |
456 | | - return array( 'ip_range_invalid' ); |
457 | | - } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) { |
458 | | - return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); |
459 | | - } |
460 | | - $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
461 | | - } else { |
462 | | - # Range block illegal |
463 | | - return array('range_block_disabled'); |
464 | | - } |
465 | | - } else { |
466 | | - # Username block |
467 | | - $user = User::newFromName( $this->BlockAddress ); |
468 | | - if( $user instanceof User && $user->getId() ) { |
469 | | - # Use canonical name |
470 | | - $userId = $user->getId(); |
471 | | - $this->BlockAddress = $user->getName(); |
472 | | - } else { |
473 | | - return array( 'nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) ); |
474 | | - } |
475 | | - } |
476 | | - } |
477 | | - |
478 | | - if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) { |
479 | | - return array( 'cant-block-while-blocked' ); |
480 | | - } |
481 | | - |
482 | | - $reasonstr = $this->BlockReasonList; |
483 | | - if( $reasonstr != 'other' && $this->BlockReason != '' ) { |
484 | | - // Entry from drop down menu + additional comment |
485 | | - $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason; |
486 | | - } elseif( $reasonstr == 'other' ) { |
487 | | - $reasonstr = $this->BlockReason; |
488 | | - } |
489 | | - |
490 | | - $expirestr = $this->BlockExpiry; |
491 | | - if( $expirestr == 'other' ) |
492 | | - $expirestr = $this->BlockOther; |
493 | | - |
494 | | - if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50 ) ) { |
495 | | - return array( 'ipb_expiry_invalid' ); |
496 | | - } |
497 | | - |
498 | | - if( false === ( $expiry = Block::parseExpiryInput( $expirestr ) ) ) { |
499 | | - // Bad expiry. |
500 | | - return array( 'ipb_expiry_invalid' ); |
501 | | - } |
502 | | - |
503 | | - if( $this->BlockHideName ) { |
504 | | - // Recheck params here... |
505 | | - if( !$userId || !$wgUser->isAllowed('hideuser') ) { |
506 | | - $this->BlockHideName = false; // IP users should not be hidden |
507 | | - } elseif( $expiry !== 'infinity' ) { |
508 | | - // Bad expiry. |
509 | | - return array( 'ipb_expiry_temp' ); |
510 | | - } elseif( User::edits( $userId ) > self::HIDEUSER_CONTRIBLIMIT ) { |
511 | | - // Typically, the user should have a handful of edits. |
512 | | - // Disallow hiding users with many edits for performance. |
513 | | - return array( 'ipb_hide_invalid' ); |
514 | | - } |
515 | | - } |
516 | | - |
517 | | - # Create block object |
518 | | - # Note: for a user block, ipb_address is only for display purposes |
519 | | - $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(), |
520 | | - $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, |
521 | | - $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, |
522 | | - $this->BlockEmail, |
523 | | - isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit |
524 | | - ); |
525 | | - |
526 | | - # Should this be privately logged? |
527 | | - $suppressLog = (bool)$this->BlockHideName; |
528 | | - if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { |
529 | | - # Try to insert block. Is there a conflicting block? |
530 | | - if( !$block->insert() ) { |
531 | | - # Show form unless the user is already aware of this... |
532 | | - if( !$this->BlockReblock ) { |
533 | | - return array( 'ipb_already_blocked' ); |
534 | | - # Otherwise, try to update the block... |
535 | | - } else { |
536 | | - # This returns direct blocks before autoblocks/rangeblocks, since we should |
537 | | - # be sure the user is blocked by now it should work for our purposes |
538 | | - $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); |
539 | | - if( $block->equals( $currentBlock ) ) { |
540 | | - return array( 'ipb_already_blocked' ); |
541 | | - } |
542 | | - # If the name was hidden and the blocking user cannot hide |
543 | | - # names, then don't allow any block changes... |
544 | | - if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) { |
545 | | - return array( 'cant-see-hidden-user' ); |
546 | | - } |
547 | | - $currentBlock->delete(); |
548 | | - $block->insert(); |
549 | | - # If hiding/unhiding a name, this should go in the private logs |
550 | | - $suppressLog = $suppressLog || (bool)$currentBlock->mHideName; |
551 | | - $log_action = 'reblock'; |
552 | | - # Unset _deleted fields if requested |
553 | | - if( $currentBlock->mHideName && !$this->BlockHideName ) { |
554 | | - RevisionDeleteUser::unsuppressUserName( $this->BlockAddress, $userId ); |
555 | | - } |
556 | | - } |
557 | | - } else { |
558 | | - $log_action = 'block'; |
559 | | - } |
560 | | - wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) ); |
561 | | - |
562 | | - # Set *_deleted fields if requested |
563 | | - if( $this->BlockHideName ) { |
564 | | - RevisionDeleteUser::suppressUserName( $this->BlockAddress, $userId ); |
565 | | - } |
566 | | - |
567 | | - # Only show watch link when this is no range block |
568 | | - if( $this->BlockWatchUser && $block->mRangeStart == $block->mRangeEnd ) { |
569 | | - $wgUser->addWatch( Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
570 | | - } |
571 | | - |
572 | | - # Block constructor sanitizes certain block options on insert |
573 | | - $this->BlockEmail = $block->mBlockEmail; |
574 | | - $this->BlockEnableAutoblock = $block->mEnableAutoblock; |
575 | | - |
576 | | - # Prepare log parameters |
577 | | - $logParams = array(); |
578 | | - $logParams[] = $expirestr; |
579 | | - $logParams[] = $this->blockLogFlags(); |
580 | | - |
581 | | - # Make log entry, if the name is hidden, put it in the oversight log |
582 | | - $log_type = $suppressLog ? 'suppress' : 'block'; |
583 | | - $log = new LogPage( $log_type ); |
584 | | - $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ), |
585 | | - $reasonstr, $logParams ); |
586 | | - |
587 | | - # Report to the user |
588 | | - return array(); |
589 | | - } else { |
590 | | - return array( 'hookaborted' ); |
591 | | - } |
592 | | - } |
593 | | - |
594 | | - # @deprecated since 1.18 |
595 | | - public static function suppressUserName( $name, $userId, $dbw = null ) { |
596 | | - return RevisionDeleteUser::suppressUserName( $name, $userId, $dbw ); |
597 | | - } |
598 | | - |
599 | | - # @deprecated since 1.18 |
600 | | - public static function unsuppressUserName( $name, $userId, $dbw = null ) { |
601 | | - return RevisionDeleteUser::unsuppressUserName( $name, $userId, $dbw ); |
602 | | - } |
603 | | - |
604 | | - /** |
605 | | - * UI entry point for blocking |
606 | | - * Wraps around doBlock() |
607 | | - */ |
608 | | - public function doSubmit() { |
609 | | - global $wgOut; |
610 | | - $retval = $this->doBlock(); |
611 | | - if( empty( $retval ) ) { |
612 | | - $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
613 | | - $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . |
614 | | - urlencode( $this->BlockAddress ) ) ); |
615 | | - return; |
616 | | - } |
617 | | - $this->showForm( $retval ); |
618 | | - } |
619 | | - |
620 | | - public function showSuccess() { |
621 | | - global $wgOut; |
622 | | - |
623 | | - $wgOut->setPageTitle( wfMsg( 'blockip-title' ) ); |
624 | | - $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); |
625 | | - $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress ); |
626 | | - $wgOut->addHTML( $text ); |
627 | | - } |
628 | | - |
629 | | - private function showLogFragment( $out, $title ) { |
630 | | - global $wgUser; |
631 | | - |
632 | | - // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog' |
633 | | - $userBlocked = $title->getText(); |
634 | | - |
635 | | - LogEventsList::showLogExtract( |
636 | | - $out, |
637 | | - 'block', |
638 | | - $title->getPrefixedText(), |
639 | | - '', |
640 | | - array( |
641 | | - 'lim' => 10, |
642 | | - 'msgKey' => array( |
643 | | - 'blocklog-showlog', |
644 | | - $userBlocked |
645 | | - ), |
646 | | - 'showIfEmpty' => false |
647 | | - ) |
648 | | - ); |
649 | | - |
650 | | - // Add suppression block entries if allowed |
651 | | - if( $wgUser->isAllowed( 'suppressionlog' ) ) { |
652 | | - LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '', |
653 | | - array( |
654 | | - 'lim' => 10, |
655 | | - 'conds' => array( |
656 | | - 'log_action' => array( |
657 | | - 'block', |
658 | | - 'reblock', |
659 | | - 'unblock' |
660 | | - ) |
661 | | - ), |
662 | | - 'msgKey' => array( |
663 | | - 'blocklog-showsuppresslog', |
664 | | - $userBlocked |
665 | | - ), |
666 | | - 'showIfEmpty' => false |
667 | | - ) |
668 | | - ); |
669 | | - } |
670 | | - } |
671 | | - |
672 | | - /** |
673 | | - * Return a comma-delimited list of "flags" to be passed to the log |
674 | | - * reader for this block, to provide more information in the logs |
675 | | - * |
676 | | - * @return array |
677 | | - */ |
678 | | - private function blockLogFlags() { |
679 | | - global $wgBlockAllowsUTEdit; |
680 | | - $flags = array(); |
681 | | - if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) ) |
682 | | - // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log |
683 | | - $flags[] = 'anononly'; |
684 | | - if( $this->BlockCreateAccount ) |
685 | | - $flags[] = 'nocreate'; |
686 | | - if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) ) |
687 | | - // Same as anononly, this is not displayed when blocking an IP address |
688 | | - $flags[] = 'noautoblock'; |
689 | | - if( $this->BlockEmail ) |
690 | | - $flags[] = 'noemail'; |
691 | | - if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit ) |
692 | | - $flags[] = 'nousertalk'; |
693 | | - if( $this->BlockHideName ) |
694 | | - $flags[] = 'hiddenname'; |
695 | | - return implode( ',', $flags ); |
696 | | - } |
697 | | - |
698 | | - /** |
699 | | - * Builds unblock and block list links |
700 | | - * |
701 | | - * @return string |
702 | | - */ |
703 | | - private function getConvenienceLinks() { |
704 | | - global $wgUser, $wgLang; |
705 | | - $skin = $wgUser->getSkin(); |
706 | | - if( $this->BlockAddress ) |
707 | | - $links[] = $this->getContribsLink( $skin ); |
708 | | - $links[] = $this->getUnblockLink( $skin ); |
709 | | - $links[] = $this->getBlockListLink( $skin ); |
710 | | - if ( $wgUser->isAllowed( 'editinterface' ) ) { |
711 | | - $title = Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ); |
712 | | - $links[] = $skin->link( |
713 | | - $title, |
714 | | - wfMsgHtml( 'ipb-edit-dropdown' ), |
715 | | - array(), |
716 | | - array( 'action' => 'edit' ) |
717 | | - ); |
718 | | - } |
719 | | - return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>'; |
720 | | - } |
721 | | - |
722 | | - /** |
723 | | - * Build a convenient link to a user or IP's contribs |
724 | | - * form |
725 | | - * |
726 | | - * @param $skin Skin to use |
727 | | - * @return string |
728 | | - */ |
729 | | - private function getContribsLink( $skin ) { |
730 | | - $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress ); |
731 | | - return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) ); |
732 | | - } |
733 | | - |
734 | | - /** |
735 | | - * Build a convenient link to unblock the given username or IP |
736 | | - * address, if available; otherwise link to a blank unblock |
737 | | - * form |
738 | | - * |
739 | | - * @param $skin Skin to use |
740 | | - * @return string |
741 | | - */ |
742 | | - private function getUnblockLink( $skin ) { |
743 | | - $list = SpecialPage::getTitleFor( 'Ipblocklist' ); |
744 | | - $query = array( 'action' => 'unblock' ); |
745 | | - |
746 | | - if( $this->BlockAddress ) { |
747 | | - $addr = strtr( $this->BlockAddress, '_', ' ' ); |
748 | | - $message = wfMsg( 'ipb-unblock-addr', $addr ); |
749 | | - $query['ip'] = $this->BlockAddress; |
750 | | - } else { |
751 | | - $message = wfMsg( 'ipb-unblock' ); |
752 | | - } |
753 | | - return $skin->linkKnown( |
754 | | - $list, |
755 | | - htmlspecialchars( $message ), |
756 | | - array(), |
757 | | - $query |
758 | | - ); |
759 | | - } |
760 | | - |
761 | | - /** |
762 | | - * Build a convenience link to the block list |
763 | | - * |
764 | | - * @param $skin Skin to use |
765 | | - * @return string |
766 | | - */ |
767 | | - private function getBlockListLink( $skin ) { |
768 | | - return $skin->linkKnown( |
769 | | - SpecialPage::getTitleFor( 'Ipblocklist' ), |
770 | | - wfMsg( 'ipb-blocklist' ) |
771 | | - ); |
772 | | - } |
773 | | - |
774 | | - /** |
775 | | - * Block a list of selected users |
776 | | - * |
777 | | - * @param $users Array |
778 | | - * @param $reason String |
779 | | - * @param $tag String: replaces user pages |
780 | | - * @param $talkTag String: replaces user talk pages |
781 | | - * @return Array: list of html-safe usernames |
782 | | - */ |
783 | | - public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) { |
784 | | - global $wgUser; |
785 | | - $counter = $blockSize = 0; |
786 | | - $safeUsers = array(); |
787 | | - $log = new LogPage( 'block' ); |
788 | | - foreach( $users as $name ) { |
789 | | - # Enforce limits |
790 | | - $counter++; |
791 | | - $blockSize++; |
792 | | - # Lets not go *too* fast |
793 | | - if( $blockSize >= 20 ) { |
794 | | - $blockSize = 0; |
795 | | - wfWaitForSlaves( 5 ); |
796 | | - } |
797 | | - $u = User::newFromName( $name, false ); |
798 | | - // If user doesn't exist, it ought to be an IP then |
799 | | - if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) { |
800 | | - continue; |
801 | | - } |
802 | | - $userTitle = $u->getUserPage(); |
803 | | - $userTalkTitle = $u->getTalkPage(); |
804 | | - $userpage = new Article( $userTitle ); |
805 | | - $usertalk = new Article( $userTalkTitle ); |
806 | | - $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]'; |
807 | | - $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
808 | | - $expiry = Block::parseExpiryInput( $expirestr ); |
809 | | - $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
810 | | - // Create the block |
811 | | - $block = new Block( $u->getName(), // victim |
812 | | - $u->getId(), // uid |
813 | | - $wgUser->getId(), // blocker |
814 | | - $reason, // comment |
815 | | - wfTimestampNow(), // block time |
816 | | - 0, // auto ? |
817 | | - $expiry, // duration |
818 | | - $anonOnly, // anononly? |
819 | | - 1, // block account creation? |
820 | | - 1, // autoblocking? |
821 | | - 0, // suppress name? |
822 | | - 0 // block from sending email? |
823 | | - ); |
824 | | - $oldblock = Block::newFromDB( $u->getName(), $u->getId() ); |
825 | | - if( !$oldblock ) { |
826 | | - $block->insert(); |
827 | | - # Prepare log parameters |
828 | | - $logParams = array(); |
829 | | - $logParams[] = $expirestr; |
830 | | - if( $anonOnly ) { |
831 | | - $logParams[] = 'anononly'; |
832 | | - } |
833 | | - $logParams[] = 'nocreate'; |
834 | | - # Add log entry |
835 | | - $log->addEntry( 'block', $userTitle, $reason, $logParams ); |
836 | | - } |
837 | | - # Tag userpage! (check length to avoid mistakes) |
838 | | - if( strlen( $tag ) > 2 ) { |
839 | | - $userpage->doEdit( $tag, $reason, EDIT_MINOR ); |
840 | | - } |
841 | | - if( strlen( $talkTag ) > 2 ) { |
842 | | - $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR ); |
843 | | - } |
844 | | - } |
845 | | - return $safeUsers; |
846 | | - } |
847 | | -} |
Index: trunk/phase3/includes/specials/SpecialBlock.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Implements Special:Block |
| 4 | + * Implements Special:Blockip |
5 | 5 | * |
6 | 6 | * This program is free software; you can redistribute it and/or modify |
7 | 7 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -27,24 +27,14 @@ |
28 | 28 | * |
29 | 29 | * @ingroup SpecialPage |
30 | 30 | */ |
31 | | -class SpecialBlock extends SpecialPage { |
32 | | - |
33 | | - # The maximum number of edits a user can have and still be hidden |
34 | | - # TODO: config setting? |
| 31 | +class IPBlockForm extends SpecialPage { |
| 32 | + var $BlockAddress, $BlockExpiry, $BlockReason, $BlockReasonList, $BlockOther, $BlockAnonOnly, $BlockCreateAccount, |
| 33 | + $BlockEnableAutoblock, $BlockEmail, $BlockHideName, $BlockAllowUsertalk, $BlockReblock, $BlockWatchUser; |
| 34 | + // The maximum number of edits a user can have and still be hidden |
35 | 35 | const HIDEUSER_CONTRIBLIMIT = 1000; |
36 | 36 | |
37 | | - # @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo) |
38 | | - # or as subpage (Special:Block/Foo) |
39 | | - protected $target; |
40 | | - |
41 | | - # @var Block::TYPE_ constant |
42 | | - protected $type; |
43 | | - |
44 | | - # @var Bool |
45 | | - protected $alreadyBlocked; |
46 | | - |
47 | 37 | public function __construct() { |
48 | | - parent::__construct( 'Block', 'block' ); |
| 38 | + parent::__construct( 'Blockip', 'block' ); |
49 | 39 | } |
50 | 40 | |
51 | 41 | public function execute( $par ) { |
— | — | @@ -61,689 +51,796 @@ |
62 | 52 | return; |
63 | 53 | } |
64 | 54 | |
65 | | - # Extract variables from the request. Try not to get into a situation where we |
66 | | - # need to extract *every* variable from the form just for processing here, but |
67 | | - # there are legitimate uses for some variables |
68 | | - list( $this->target, $this->type ) = self::getTargetAndType( $par, $wgRequest ); |
69 | | - if ( $this->target instanceof User ) { |
70 | | - # Set the 'relevant user' in the skin, so it displays links like Contributions, |
71 | | - # User logs, UserRights, etc. |
72 | | - $wgUser->getSkin()->setRelevantUser( $this->target ); |
73 | | - } |
| 55 | + $this->setup( $par ); |
74 | 56 | |
75 | 57 | # bug 15810: blocked admins should have limited access here |
76 | | - $status = self::checkUnblockSelf( $this->target ); |
77 | | - if ( $status !== true ) { |
78 | | - throw new ErrorPageError( 'badaccess', $status ); |
| 58 | + if ( $wgUser->isBlocked() ) { |
| 59 | + $status = IPBlockForm::checkUnblockSelf( $this->BlockAddress ); |
| 60 | + if ( $status !== true ) { |
| 61 | + throw new ErrorPageError( 'badaccess', $status ); |
| 62 | + } |
79 | 63 | } |
80 | 64 | |
81 | | - $wgOut->setPageTitle( wfMsg( 'blockip-title' ) ); |
82 | | - $wgOut->addModules( 'mediawiki.special', 'mediawiki.special.block' ); |
83 | | - |
84 | | - $fields = self::getFormFields(); |
85 | | - $this->alreadyBlocked = $this->maybeAlterFormDefaults( $fields ); |
86 | | - |
87 | | - $form = new HTMLForm( $fields ); |
88 | | - $form->setTitle( $this->getTitle() ); |
89 | | - $form->setWrapperLegend( wfMsg( 'blockip-legend' ) ); |
90 | | - $form->setSubmitCallback( array( __CLASS__, 'processForm' ) ); |
91 | | - |
92 | | - $t = $this->alreadyBlocked |
93 | | - ? wfMsg( 'ipb-change-block' ) |
94 | | - : wfMsg( 'ipbsubmit' ); |
95 | | - $form->setSubmitText( $t ); |
96 | | - |
97 | | - $this->doPreText( $form ); |
98 | | - $this->doPostText( $form ); |
99 | | - |
100 | | - if( $form->show() ){ |
101 | | - $wgOut->setPageTitle( wfMsg( 'blockipsuccesssub' ) ); |
102 | | - $wgOut->addHTML( wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->target ) ); |
| 65 | + $action = $wgRequest->getVal( 'action' ); |
| 66 | + if( 'success' == $action ) { |
| 67 | + $this->showSuccess(); |
| 68 | + } elseif( $wgRequest->wasPosted() && 'submit' == $action && |
| 69 | + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 70 | + $this->doSubmit(); |
| 71 | + } else { |
| 72 | + $this->showForm( '' ); |
103 | 73 | } |
104 | 74 | } |
105 | 75 | |
106 | | - /** |
107 | | - * Get the HTMLForm descriptor array for the block form |
108 | | - * @return Array |
109 | | - */ |
110 | | - protected static function getFormFields(){ |
111 | | - global $wgUser, $wgBlockAllowsUTEdit; |
| 76 | + private function setup( $par ) { |
| 77 | + global $wgRequest, $wgUser, $wgBlockAllowsUTEdit; |
112 | 78 | |
113 | | - $a = array( |
114 | | - 'Target' => array( |
115 | | - 'type' => 'text', |
116 | | - 'label-message' => 'ipadressorusername', |
117 | | - 'tabindex' => '1', |
118 | | - 'id' => 'mw-bi-target', |
119 | | - 'size' => '45', |
120 | | - 'required' => true, |
121 | | - ), |
122 | | - 'Expiry' => array( |
123 | | - 'type' => 'selectorother', |
124 | | - 'label-message' => 'ipbexpiry', |
125 | | - 'required' => true, |
126 | | - 'tabindex' => '2', |
127 | | - 'options' => self::getSuggestedDurations(), |
128 | | - 'other' => wfMsg( 'ipbother' ), |
129 | | - ), |
130 | | - 'Reason' => array( |
131 | | - 'type' => 'selectandother', |
132 | | - 'label-message' => 'ipbreason', |
133 | | - 'options-message' => 'ipbreason-dropdown', |
134 | | - ), |
135 | | - 'CreateAccount' => array( |
136 | | - 'type' => 'check', |
137 | | - 'label-message' => 'ipbcreateaccount', |
138 | | - 'default' => true, |
139 | | - ), |
140 | | - ); |
| 79 | + $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) ); |
| 80 | + $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' ); |
| 81 | + $this->BlockReason = $wgRequest->getText( 'wpBlockReason' ); |
| 82 | + $this->BlockReasonList = $wgRequest->getText( 'wpBlockReasonList' ); |
| 83 | + $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) ); |
| 84 | + $this->BlockOther = $wgRequest->getVal( 'wpBlockOther', '' ); |
141 | 85 | |
142 | | - if( wfMsgForContent( 'ipboptions' ) == '-' ){ |
143 | | - $a['Expiry']['type'] = 'text'; |
144 | | - } |
145 | | - |
| 86 | + # Unchecked checkboxes are not included in the form data at all, so having one |
| 87 | + # that is true by default is a bit tricky |
| 88 | + $byDefault = !$wgRequest->wasPosted(); |
| 89 | + $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault ); |
| 90 | + $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault ); |
| 91 | + $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault ); |
| 92 | + $this->BlockEmail = false; |
146 | 93 | if( self::canBlockEmail( $wgUser ) ) { |
147 | | - $a['DisableEmail'] = array( |
148 | | - 'type' => 'check', |
149 | | - 'label-message' => 'ipbemailban', |
150 | | - ); |
| 94 | + $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false ); |
151 | 95 | } |
152 | | - |
153 | | - if( $wgBlockAllowsUTEdit ){ |
154 | | - $a['DisableUTEdit'] = array( |
155 | | - 'type' => 'check', |
156 | | - 'label-message' => 'ipb-disableusertalk', |
157 | | - 'default' => false, |
158 | | - ); |
159 | | - } |
160 | | - |
161 | | - $a['AutoBlock'] = array( |
162 | | - 'type' => 'check', |
163 | | - 'label-message' => 'ipbenableautoblock', |
164 | | - 'default' => true, |
165 | | - ); |
166 | | - |
167 | | - # Allow some users to hide name from block log, blocklist and listusers |
| 96 | + $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false ) && $wgUser->isLoggedIn(); |
| 97 | + # Re-check user's rights to hide names, very serious, defaults to null |
168 | 98 | if( $wgUser->isAllowed( 'hideuser' ) ) { |
169 | | - $a['HideUser'] = array( |
170 | | - 'type' => 'check', |
171 | | - 'label-message' => 'ipbhidename', |
172 | | - 'cssclass' => 'mw-block-hideuser', |
173 | | - ); |
| 99 | + $this->BlockHideName = $wgRequest->getBool( 'wpHideName', null ); |
| 100 | + } else { |
| 101 | + $this->BlockHideName = false; |
174 | 102 | } |
175 | | - |
176 | | - # Watchlist their user page? (Only if user is logged in) |
177 | | - if( $wgUser->isLoggedIn() ) { |
178 | | - $a['Watch'] = array( |
179 | | - 'type' => 'check', |
180 | | - 'label-message' => 'ipbwatchuser', |
181 | | - ); |
182 | | - } |
183 | | - |
184 | | - $a['HardBlock'] = array( |
185 | | - 'type' => 'check', |
186 | | - 'label-message' => 'ipb-hardblock', |
187 | | - 'default' => false, |
188 | | - ); |
189 | | - |
190 | | - $a['AlreadyBlocked'] = array( |
191 | | - 'type' => 'hidden', |
192 | | - 'default' => false, |
193 | | - ); |
194 | | - |
195 | | - return $a; |
| 103 | + $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit ); |
| 104 | + $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false ); |
| 105 | + |
| 106 | + $this->wasPosted = $wgRequest->wasPosted(); |
196 | 107 | } |
197 | 108 | |
198 | | - /** |
199 | | - * If the user has already been blocked with similar settings, load that block |
200 | | - * and change the defaults for the form fields to match the existing settings. |
201 | | - * @param &$fields Array HTMLForm descriptor array |
202 | | - * @return Bool whether fields were altered (that is, whether the target is |
203 | | - * already blocked) |
204 | | - */ |
205 | | - protected function maybeAlterFormDefaults( &$fields ){ |
206 | | - $fields['Target']['default'] = $this->target; |
| 109 | + public function showForm( $err ) { |
| 110 | + global $wgOut, $wgUser; |
207 | 111 | |
208 | | - $block = self::getBlockFromTargetAndType( $this->target, $this->type ); |
| 112 | + $wgOut->setPageTitle( wfMsg( 'blockip-title' ) ); |
| 113 | + $wgOut->addWikiMsg( 'blockiptext' ); |
209 | 114 | |
210 | | - if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock |
211 | | - && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock |
212 | | - || $block->mAddress == $this->target ) # or if it is, the range is what we're about to block |
213 | | - ) |
214 | | - { |
215 | | - $fields['HardBlock']['default'] = !$block->mAnonOnly; |
216 | | - $fields['CreateAccount']['default'] = $block->mCreateAccount; |
217 | | - $fields['AutoBlock']['default'] = $block->mEnableAutoblock; |
218 | | - $fields['DisableEmail']['default'] = $block->mBlockEmail; |
219 | | - $fields['HideUser']['default'] = $block->mHideName; |
220 | | - $fields['DisableUTEdit']['default'] = !$block->mAllowUsertalk; |
221 | | - $fields['Reason']['default'] = $block->mReason; |
222 | | - $fields['AlreadyBlocked']['default'] = true; |
| 115 | + $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' ); |
| 116 | + $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' ); |
| 117 | + $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' ); |
| 118 | + $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' ); |
| 119 | + $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' ); |
223 | 120 | |
224 | | - if( $block->mExpiry == 'infinity' ) { |
225 | | - $fields['Expiry']['default'] = 'indefinite'; |
226 | | - } else { |
227 | | - $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry ); |
228 | | - } |
229 | | - |
230 | | - return true; |
| 121 | + $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
| 122 | + $user = User::newFromName( $this->BlockAddress ); |
| 123 | + if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) { |
| 124 | + $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) ); |
231 | 125 | } |
232 | | - return false; |
233 | | - } |
234 | 126 | |
235 | | - /** |
236 | | - * Add header elements like block log entries, etc. |
237 | | - * @param $form HTMLForm |
238 | | - * @return void |
239 | | - */ |
240 | | - protected function doPreText( HTMLForm &$form ){ |
241 | | - $form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) ); |
242 | | - |
243 | | - $otherBlockMessages = array(); |
244 | | - if( $this->target !== null ) { |
| 127 | + $alreadyBlocked = false; |
| 128 | + $otherBlockedMsgs = array(); |
| 129 | + if( $err && $err[0] != 'ipb_already_blocked' ) { |
| 130 | + $key = array_shift( $err ); |
| 131 | + $msg = wfMsgExt( $key, 'parsemag', $err ); |
| 132 | + $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
| 133 | + $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) ); |
| 134 | + } elseif( $this->BlockAddress !== null ) { |
245 | 135 | # Get other blocks, i.e. from GlobalBlocking or TorBlock extension |
246 | | - wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) ); |
| 136 | + wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress ) ); |
247 | 137 | |
248 | | - if( count( $otherBlockMessages ) ) { |
249 | | - $s = Html::rawElement( |
250 | | - 'h2', |
251 | | - array(), |
252 | | - wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) ) |
253 | | - ) . "\n"; |
254 | | - $list = ''; |
255 | | - foreach( $otherBlockMessages as $link ) { |
256 | | - $list .= Html::rawElement( 'li', array(), $link ) . "\n"; |
| 138 | + $userId = is_object( $user ) ? $user->getId() : 0; |
| 139 | + $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); |
| 140 | + if( !is_null( $currentBlock ) && !$currentBlock->mAuto && # The block exists and isn't an autoblock |
| 141 | + ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock |
| 142 | + # or if it is, the range is what we're about to block |
| 143 | + ( $currentBlock->mAddress == $this->BlockAddress ) ) |
| 144 | + ) { |
| 145 | + $alreadyBlocked = true; |
| 146 | + # Set the block form settings to the existing block |
| 147 | + if( !$this->wasPosted ) { |
| 148 | + $this->BlockAnonOnly = $currentBlock->mAnonOnly; |
| 149 | + $this->BlockCreateAccount = $currentBlock->mCreateAccount; |
| 150 | + $this->BlockEnableAutoblock = $currentBlock->mEnableAutoblock; |
| 151 | + $this->BlockEmail = $currentBlock->mBlockEmail; |
| 152 | + $this->BlockHideName = $currentBlock->mHideName; |
| 153 | + $this->BlockAllowUsertalk = $currentBlock->mAllowUsertalk; |
| 154 | + if( $currentBlock->mExpiry == 'infinity' ) { |
| 155 | + $this->BlockOther = 'indefinite'; |
| 156 | + } else { |
| 157 | + $this->BlockOther = wfTimestamp( TS_ISO_8601, $currentBlock->mExpiry ); |
| 158 | + } |
| 159 | + $this->BlockReason = $currentBlock->mReason; |
257 | 160 | } |
258 | | - $s .= Html::rawElement( |
259 | | - 'ul', |
260 | | - array( 'class' => 'mw-blockip-alreadyblocked' ), |
261 | | - $list |
262 | | - ) . "\n"; |
263 | | - $form->addPreText( $s ); |
264 | 161 | } |
265 | 162 | } |
266 | 163 | |
| 164 | + # Show other blocks from extensions, i.e. GlockBlocking and TorBlock |
| 165 | + if( count( $otherBlockedMsgs ) ) { |
| 166 | + $wgOut->addHTML( |
| 167 | + Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n" |
| 168 | + ); |
| 169 | + $list = ''; |
| 170 | + foreach( $otherBlockedMsgs as $link ) { |
| 171 | + $list .= Html::rawElement( 'li', array(), $link ) . "\n"; |
| 172 | + } |
| 173 | + $wgOut->addHTML( Html::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" ); |
| 174 | + } |
| 175 | + |
267 | 176 | # Username/IP is blocked already locally |
268 | | - if( $this->alreadyBlocked ) { |
269 | | - $form->addPreText( Html::rawElement( |
270 | | - 'div', |
271 | | - array( 'class' => 'mw-ipb-needreblock', ), |
272 | | - wfMsgExt( |
273 | | - 'ipb-needreblock', |
274 | | - array( 'parseinline' ), |
275 | | - $this->target |
276 | | - ) ) ); |
| 177 | + if( $alreadyBlocked ) { |
| 178 | + $wgOut->wrapWikiMsg( "<div class='mw-ipb-needreblock'>\n$1\n</div>", array( 'ipb-needreblock', $this->BlockAddress ) ); |
277 | 179 | } |
278 | | - } |
279 | 180 | |
280 | | - /** |
281 | | - * Add footer elements to the form |
282 | | - * @param $form HTMLForm |
283 | | - * @return void |
284 | | - */ |
285 | | - protected function doPostText( HTMLForm &$form ){ |
286 | | - global $wgUser, $wgLang; |
| 181 | + $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); |
287 | 182 | |
288 | | - $skin = $wgUser->getSkin(); |
| 183 | + $showblockoptions = $scBlockExpiryOptions != '-'; |
| 184 | + if( !$showblockoptions ) $mIpbother = $mIpbexpiry; |
289 | 185 | |
290 | | - # Link to the user's contributions, if applicable |
291 | | - if( $this->target instanceof User ){ |
292 | | - $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() ); |
293 | | - $links[] = $skin->link( |
294 | | - $contribsPage, |
295 | | - wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() ) |
| 186 | + $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' ); |
| 187 | + foreach( explode( ',', $scBlockExpiryOptions ) as $option ) { |
| 188 | + if( strpos( $option, ':' ) === false ) $option = "$option:$option"; |
| 189 | + list( $show, $value ) = explode( ':', $option ); |
| 190 | + $show = htmlspecialchars( $show ); |
| 191 | + $value = htmlspecialchars( $value ); |
| 192 | + $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ) . "\n"; |
| 193 | + } |
| 194 | + |
| 195 | + $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', |
| 196 | + wfMsgForContent( 'ipbreason-dropdown' ), |
| 197 | + wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 ); |
| 198 | + |
| 199 | + # FIXME: this should actually use HTMLForm, not just some of its JavaScript |
| 200 | + $wgOut->addModules( array( 'mediawiki.special.block', 'mediawiki.htmlform' ) ); |
| 201 | + |
| 202 | + $wgOut->addHTML( |
| 203 | + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) . |
| 204 | + Xml::openElement( 'fieldset' ) . |
| 205 | + Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) . |
| 206 | + Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) . |
| 207 | + "<tr> |
| 208 | + <td class='mw-label'> |
| 209 | + {$mIpaddress} |
| 210 | + </td> |
| 211 | + <td class='mw-input'>" . |
| 212 | + Html::input( 'wpBlockAddress', $this->BlockAddress, 'text', array( |
| 213 | + 'tabindex' => '1', |
| 214 | + 'id' => 'mw-bi-target', |
| 215 | + 'size' => '45', |
| 216 | + 'required' => '' |
| 217 | + ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). " |
| 218 | + </td> |
| 219 | + </tr> |
| 220 | + <tr> |
| 221 | + <td class='mw-label'> |
| 222 | + {$mIpbexpiry} |
| 223 | + </td> |
| 224 | + <td class='mw-input'>" |
| 225 | + ); |
| 226 | + if( $showblockoptions ) { |
| 227 | + $wgOut->addHTML( |
| 228 | + Xml::tags( 'select', |
| 229 | + array( |
| 230 | + 'id' => 'wpBlockExpiry', |
| 231 | + 'name' => 'wpBlockExpiry', |
| 232 | + 'class' => 'mw-htmlform-select-or-other', # FIXME: actually make this use HTMLForm |
| 233 | + 'tabindex' => '2' ), |
| 234 | + $blockExpiryFormOptions |
| 235 | + ) . "<br/>\n" |
296 | 236 | ); |
297 | 237 | } |
| 238 | + $wgOut->addHTML( |
| 239 | + Xml::input( |
| 240 | + 'wpBlockOther', |
| 241 | + 45, |
| 242 | + $this->BlockOther, |
| 243 | + array( |
| 244 | + 'tabindex' => '3', |
| 245 | + 'id' => 'wpBlockExpiry-other' |
| 246 | + ) |
| 247 | + ) . " |
| 248 | + </td> |
| 249 | + </tr> |
| 250 | + <tr> |
| 251 | + <td class='mw-label'> |
| 252 | + {$mIpbreasonother} |
| 253 | + </td> |
| 254 | + <td class='mw-input'> |
| 255 | + {$reasonDropDown} |
| 256 | + </td> |
| 257 | + </tr> |
| 258 | + <tr id=\"wpBlockReason\"> |
| 259 | + <td class='mw-label'> |
| 260 | + {$mIpbreason} |
| 261 | + </td> |
| 262 | + <td class='mw-input'>" . |
| 263 | + Html::input( 'wpBlockReason', $this->BlockReason, 'text', array( |
| 264 | + 'tabindex' => '5', |
| 265 | + 'id' => 'mw-bi-reason', |
| 266 | + 'maxlength' => '200', |
| 267 | + 'size' => '45' |
| 268 | + ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . " |
| 269 | + </td> |
| 270 | + </tr> |
| 271 | + <tr id='wpCreateAccountRow'> |
| 272 | + <td> </td> |
| 273 | + <td class='mw-input'>" . |
| 274 | + Xml::checkLabel( wfMsg( 'ipbcreateaccount' ), |
| 275 | + 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount, |
| 276 | + array( 'tabindex' => '7' ) ) . " |
| 277 | + </td> |
| 278 | + </tr>" |
| 279 | + ); |
298 | 280 | |
299 | | - # Link to unblock the specified user, or to a blank unblock form |
300 | | - $list = SpecialPage::getTitleFor( 'Ipblocklist' ); |
301 | | - $query = array( 'action' => 'unblock' ); |
302 | | - if( $this->target instanceof User ) { |
303 | | - $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() ); |
304 | | - $query['ip'] = $this->target->getName(); |
305 | | - } else { |
306 | | - $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) ); |
| 281 | + if( self::canBlockEmail( $wgUser ) ) { |
| 282 | + $wgOut->addHTML(" |
| 283 | + <tr id='wpEnableEmailBan'> |
| 284 | + <td> </td> |
| 285 | + <td class='mw-input'>" . |
| 286 | + Xml::checkLabel( wfMsg( 'ipbemailban' ), |
| 287 | + 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, |
| 288 | + array( 'tabindex' => '9' ) ) . " |
| 289 | + </td> |
| 290 | + </tr>" |
| 291 | + ); |
307 | 292 | } |
308 | | - $links[] = $skin->linkKnown( $list, $message, array(), $query ); |
309 | 293 | |
310 | | - # Link to the block list |
311 | | - $links[] = $skin->linkKnown( |
312 | | - SpecialPage::getTitleFor( 'Ipblocklist' ), |
313 | | - wfMsg( 'ipb-blocklist' ) |
| 294 | + # Can we explicitly disallow the use of user_talk? |
| 295 | + global $wgBlockAllowsUTEdit; |
| 296 | + if( $wgBlockAllowsUTEdit ){ |
| 297 | + $wgOut->addHTML(" |
| 298 | + <tr id='wpAllowUsertalkRow'> |
| 299 | + <td> </td> |
| 300 | + <td class='mw-input'>" . |
| 301 | + Xml::checkLabel( wfMsg( 'ipballowusertalk' ), |
| 302 | + 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk, |
| 303 | + array( 'tabindex' => '12' ) ) . " |
| 304 | + </td> |
| 305 | + </tr>" |
| 306 | + ); |
| 307 | + } |
| 308 | + |
| 309 | + $wgOut->addHTML( " |
| 310 | + <tr id='wpEnableAutoblockRow'> |
| 311 | + <td> </td> |
| 312 | + <td class='mw-input'>" . |
| 313 | + Xml::checkLabel( wfMsg( 'ipbenableautoblock' ), |
| 314 | + 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock, |
| 315 | + array( 'tabindex' => '8' ) ) . " |
| 316 | + </td> |
| 317 | + </tr>" |
314 | 318 | ); |
315 | 319 | |
316 | | - # Link to edit the block dropdown reasons, if applicable |
317 | | - if ( $wgUser->isAllowed( 'editinterface' ) ) { |
318 | | - $links[] = $skin->link( |
319 | | - Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ), |
320 | | - wfMsgHtml( 'ipb-edit-dropdown' ), |
321 | | - array(), |
322 | | - array( 'action' => 'edit' ) |
| 320 | + // Allow some users to hide name from block log, blocklist and listusers |
| 321 | + if( $wgUser->isAllowed( 'hideuser' ) ) { |
| 322 | + $wgOut->addHTML(" |
| 323 | + <tr id='wpEnableHideUser'> |
| 324 | + <td> </td> |
| 325 | + <td class='mw-input'><strong>" . |
| 326 | + Xml::checkLabel( wfMsg( 'ipbhidename' ), |
| 327 | + 'wpHideName', 'wpHideName', $this->BlockHideName, |
| 328 | + array( 'tabindex' => '10' ) |
| 329 | + ) . " |
| 330 | + </strong></td> |
| 331 | + </tr>" |
323 | 332 | ); |
324 | 333 | } |
325 | 334 | |
326 | | - $form->addPostText( Html::rawElement( |
327 | | - 'p', |
328 | | - array( 'class' => 'mw-ipb-conveniencelinks' ), |
329 | | - $wgLang->pipeList( $links ) |
330 | | - ) ); |
| 335 | + # Watchlist their user page? (Only if user is logged in) |
| 336 | + if( $wgUser->isLoggedIn() ) { |
| 337 | + $wgOut->addHTML(" |
| 338 | + <tr id='wpEnableWatchUser'> |
| 339 | + <td> </td> |
| 340 | + <td class='mw-input'>" . |
| 341 | + Xml::checkLabel( wfMsg( 'ipbwatchuser' ), |
| 342 | + 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser, |
| 343 | + array( 'tabindex' => '11' ) ) . " |
| 344 | + </td> |
| 345 | + </tr>" |
| 346 | + ); |
| 347 | + } |
331 | 348 | |
332 | | - if( $this->target instanceof User ){ |
333 | | - # Get relevant extracts from the block and suppression logs, if possible |
334 | | - $userpage = $this->target->getUserPage(); |
335 | | - $out = ''; |
| 349 | + $wgOut->addHTML(" |
| 350 | + <tr id='wpAnonOnlyRow'> |
| 351 | + <td> </td> |
| 352 | + <td class='mw-input'>" . |
| 353 | + Xml::checkLabel( wfMsg( 'ipbanononly' ), |
| 354 | + 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly, |
| 355 | + array( 'tabindex' => '6' ) ) . " |
| 356 | + </td> |
| 357 | + </tr> |
| 358 | + <tr> |
| 359 | + <td style='padding-top: 1em'> </td> |
| 360 | + <td class='mw-submit' style='padding-top: 1em'>" . |
| 361 | + Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ), |
| 362 | + array( 'name' => 'wpBlock', 'tabindex' => '13' ) |
| 363 | + + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'blockip-block' ) ). " |
| 364 | + </td> |
| 365 | + </tr>" . |
| 366 | + Xml::closeElement( 'table' ) . |
| 367 | + Html::hidden( 'wpEditToken', $wgUser->editToken() ) . |
| 368 | + ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) . |
| 369 | + Xml::closeElement( 'fieldset' ) . |
| 370 | + Xml::closeElement( 'form' ) |
| 371 | + ); |
336 | 372 | |
337 | | - LogEventsList::showLogExtract( |
338 | | - $out, |
339 | | - 'block', |
340 | | - $userpage->getPrefixedText(), |
341 | | - '', |
342 | | - array( |
343 | | - 'lim' => 10, |
344 | | - 'msgKey' => array( 'blocklog-showlog', $userpage->getText() ), |
345 | | - 'showIfEmpty' => false |
346 | | - ) |
347 | | - ); |
348 | | - $form->addPostText( $out ); |
| 373 | + $wgOut->addHTML( $this->getConvenienceLinks() ); |
349 | 374 | |
350 | | - # Add suppression block entries if allowed |
351 | | - if( $wgUser->isAllowed( 'suppressionlog' ) ) { |
352 | | - LogEventsList::showLogExtract( |
353 | | - $out, |
354 | | - 'suppress', |
355 | | - $userpage->getPrefixedText(), |
356 | | - '', |
357 | | - array( |
358 | | - 'lim' => 10, |
359 | | - 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ), |
360 | | - 'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ), |
361 | | - 'showIfEmpty' => false |
362 | | - ) |
363 | | - ); |
364 | | - $form->addPostText( $out ); |
365 | | - } |
| 375 | + if( is_object( $user ) ) { |
| 376 | + $this->showLogFragment( $wgOut, $user->getUserPage() ); |
| 377 | + } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) { |
| 378 | + $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
| 379 | + } elseif( preg_match( '/^\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}/', $this->BlockAddress ) ) { |
| 380 | + $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
366 | 381 | } |
367 | 382 | } |
368 | 383 | |
369 | 384 | /** |
370 | | - * Determine the target of the block, and the type of target |
371 | | - * TODO: should be in Block.php? |
372 | | - * @param $par String subpage parameter passed to setup, or data value from |
373 | | - * the HTMLForm |
374 | | - * @param $request WebRequest optionally try and get data from a request too |
375 | | - * @return void |
| 385 | + * Can we do an email block? |
| 386 | + * @param $user User: the sysop wanting to make a block |
| 387 | + * @return Boolean |
376 | 388 | */ |
377 | | - public static function getTargetAndType( $par, WebRequest $request = null ){ |
378 | | - $i = 0; |
379 | | - $target = null; |
380 | | - while( true ){ |
381 | | - switch( $i++ ){ |
382 | | - case 0: |
383 | | - # The HTMLForm will check wpTarget first and only if it doesn't get |
384 | | - # a value use the default, which will be generated from the options |
385 | | - # below; so this has to have a higher precedence here than $par, or |
386 | | - # we could end up with different values in $this->target and the HTMLForm! |
387 | | - if( $request instanceof WebRequest ){ |
388 | | - $target = $request->getText( 'wpTarget', null ); |
389 | | - } |
390 | | - break; |
391 | | - case 1: |
392 | | - $target = $par; |
393 | | - break; |
394 | | - case 2: |
395 | | - if( $request instanceof WebRequest ){ |
396 | | - $target = $request->getText( 'ip', null ); |
397 | | - } |
398 | | - break; |
399 | | - case 3: |
400 | | - # B/C @since 1.18 |
401 | | - if( $request instanceof WebRequest ){ |
402 | | - $target = $request->getText( 'wpBlockAddress', null ); |
403 | | - } |
404 | | - break; |
405 | | - case 4: |
406 | | - break 2; |
407 | | - } |
408 | | - |
409 | | - $userObj = User::newFromName( $target ); |
410 | | - if( $userObj instanceof User ){ |
411 | | - return array( $userObj, Block::TYPE_USER ); |
412 | | - } elseif( IP::isValid( $target ) ){ |
413 | | - # We can still create a User if it's an IP address, but we need to turn |
414 | | - # off validation checking (which would exclude IP addresses) |
415 | | - return array( |
416 | | - User::newFromName( IP::sanitizeIP( $target ), false ), |
417 | | - Block::TYPE_IP |
418 | | - ); |
419 | | - break; |
420 | | - } elseif( IP::isValidBlock( $target ) ){ |
421 | | - # Can't create a User from an IP range |
422 | | - return array( Block::normaliseRange( $target ), Block::TYPE_RANGE ); |
423 | | - } |
424 | | - } |
425 | | - return array( null, null ); |
| 389 | + public static function canBlockEmail( $user ) { |
| 390 | + global $wgEnableUserEmail, $wgSysopEmailBans; |
| 391 | + return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); |
426 | 392 | } |
427 | | - |
| 393 | + |
428 | 394 | /** |
429 | | - * Given a target and the target's type, get a block object if possible |
430 | | - * @param $target String|User |
431 | | - * @param $type Block::TYPE_ constant |
432 | | - * @return Block|null |
433 | | - * TODO: this probably belongs in Block.php when that mess is cleared up |
| 395 | + * bug 15810: blocked admins should not be able to block/unblock |
| 396 | + * others, and probably shouldn't be able to unblock themselves |
| 397 | + * either. |
| 398 | + * @param $user User|Int|String |
434 | 399 | */ |
435 | | - public static function getBlockFromTargetAndType( $target, $type ){ |
436 | | - if( $target instanceof User ){ |
437 | | - if( $type == Block::TYPE_IP ){ |
438 | | - return Block::newFromDB( $target->getName(), 0 ); |
439 | | - } elseif( $type == Block::TYPE_USER ) { |
440 | | - return Block::newFromDB( '', $target->getId() ); |
| 400 | + public static function checkUnblockSelf( $user ) { |
| 401 | + global $wgUser; |
| 402 | + if ( is_int( $user ) ) { |
| 403 | + $user = User::newFromId( $user ); |
| 404 | + } elseif ( is_string( $user ) ) { |
| 405 | + $user = User::newFromName( $user ); |
| 406 | + } |
| 407 | + if( $user instanceof User && $user->getId() == $wgUser->getId() ) { |
| 408 | + # User is trying to unblock themselves |
| 409 | + if ( $wgUser->isAllowed( 'unblockself' ) ) { |
| 410 | + return true; |
441 | 411 | } else { |
442 | | - # Should be unreachable; |
443 | | - return null; |
| 412 | + return 'ipbnounblockself'; |
444 | 413 | } |
445 | | - } elseif( $type == Block::TYPE_RANGE ){ |
446 | | - return Block::newFromDB( '', $target ); |
447 | 414 | } else { |
448 | | - return null; |
| 415 | + # User is trying to block/unblock someone else |
| 416 | + return 'ipbblocked'; |
449 | 417 | } |
450 | 418 | } |
451 | 419 | |
452 | 420 | /** |
453 | | - * Given the form data, actually implement a block |
454 | | - * @param $data Array |
455 | | - * @return Bool|String |
| 421 | + * Backend block code. |
| 422 | + * $userID and $expiry will be filled accordingly |
| 423 | + * @return array(message key, arguments) on failure, empty array on success |
456 | 424 | */ |
457 | | - public static function processForm( array $data ){ |
| 425 | + function doBlock( &$userId = null, &$expiry = null ) { |
458 | 426 | global $wgUser, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit; |
459 | 427 | |
460 | | - list( $target, $type ) = self::getTargetAndType( $data['Target'] ); |
| 428 | + $userId = 0; |
| 429 | + # Expand valid IPv6 addresses, usernames are left as is |
| 430 | + $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress ); |
| 431 | + # isIPv4() and IPv6() are used for final validation |
| 432 | + $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; |
| 433 | + $rxIP6 = '\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}'; |
| 434 | + $rxIP = "($rxIP4|$rxIP6)"; |
461 | 435 | |
462 | | - if( $type == Block::TYPE_USER ){ |
463 | | - # TODO: why do we not have a User->exists() method? |
464 | | - if( !$target->getId() ){ |
465 | | - return array( array( 'nosuchusershort', $target->getName() ) ); |
| 436 | + # Check for invalid specifications |
| 437 | + if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { |
| 438 | + $matches = array(); |
| 439 | + if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { |
| 440 | + # IPv4 |
| 441 | + if( $wgBlockCIDRLimit['IPv4'] != 32 ){ |
| 442 | + if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] > 32 ) { |
| 443 | + return array( 'ip_range_invalid' ); |
| 444 | + } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) { |
| 445 | + return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); |
| 446 | + } |
| 447 | + $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
| 448 | + } else { |
| 449 | + # Range block illegal |
| 450 | + return array( 'range_block_disabled' ); |
| 451 | + } |
| 452 | + } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { |
| 453 | + # IPv6 |
| 454 | + if( $wgBlockCIDRLimit['IPv6'] != 128 ) { |
| 455 | + if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] > 128 ) { |
| 456 | + return array( 'ip_range_invalid' ); |
| 457 | + } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) { |
| 458 | + return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); |
| 459 | + } |
| 460 | + $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
| 461 | + } else { |
| 462 | + # Range block illegal |
| 463 | + return array('range_block_disabled'); |
| 464 | + } |
| 465 | + } else { |
| 466 | + # Username block |
| 467 | + $user = User::newFromName( $this->BlockAddress ); |
| 468 | + if( $user instanceof User && $user->getId() ) { |
| 469 | + # Use canonical name |
| 470 | + $userId = $user->getId(); |
| 471 | + $this->BlockAddress = $user->getName(); |
| 472 | + } else { |
| 473 | + return array( 'nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) ); |
| 474 | + } |
466 | 475 | } |
| 476 | + } |
467 | 477 | |
468 | | - $status = self::checkUnblockSelf( $target ); |
469 | | - if ( $status !== true ) { |
470 | | - return array( array( 'badaccess', $status ) ); |
471 | | - } |
| 478 | + if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) { |
| 479 | + return array( 'cant-block-while-blocked' ); |
| 480 | + } |
472 | 481 | |
473 | | - $user = $target; |
474 | | - $target = $user->getName(); |
475 | | - $userId = $user->getId(); |
| 482 | + $reasonstr = $this->BlockReasonList; |
| 483 | + if( $reasonstr != 'other' && $this->BlockReason != '' ) { |
| 484 | + // Entry from drop down menu + additional comment |
| 485 | + $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason; |
| 486 | + } elseif( $reasonstr == 'other' ) { |
| 487 | + $reasonstr = $this->BlockReason; |
| 488 | + } |
476 | 489 | |
477 | | - } elseif( $type == Block::TYPE_RANGE ){ |
478 | | - list( $ip, $range ) = explode( '/', $target, 2 ); |
| 490 | + $expirestr = $this->BlockExpiry; |
| 491 | + if( $expirestr == 'other' ) |
| 492 | + $expirestr = $this->BlockOther; |
479 | 493 | |
480 | | - if( ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) |
481 | | - || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPV6'] == 128 ) ) |
482 | | - { |
483 | | - # Range block effectively disabled |
484 | | - return array( 'range_block_disabled' ); |
485 | | - } |
486 | | - |
487 | | - if( ( IP::isIPv4( $ip ) && $range > 32 ) |
488 | | - || ( IP::isIPv6( $ip ) && $range > 128 ) ) |
489 | | - { |
490 | | - # Dodgy range |
491 | | - return array( 'ip_range_invalid' ); |
492 | | - } |
493 | | - |
494 | | - if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) { |
495 | | - return array( array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ) ); |
496 | | - } |
497 | | - |
498 | | - if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) { |
499 | | - return array( array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ) ); |
500 | | - } |
501 | | - |
502 | | - $userId = 0; |
503 | | - |
504 | | - } elseif( $type == Block::TYPE_IP ){ |
505 | | - # All is well |
506 | | - $target = $target->getName(); |
507 | | - $userId = 0; |
508 | | - |
509 | | - } else { |
510 | | - return array( 'badipaddress' ); |
| 494 | + if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50 ) ) { |
| 495 | + return array( 'ipb_expiry_invalid' ); |
511 | 496 | } |
512 | | - |
513 | | - if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) |
514 | | - || !Block::parseExpiryInput( $data['Expiry'] ) ) |
515 | | - { |
| 497 | + |
| 498 | + if( false === ( $expiry = Block::parseExpiryInput( $expirestr ) ) ) { |
| 499 | + // Bad expiry. |
516 | 500 | return array( 'ipb_expiry_invalid' ); |
517 | 501 | } |
518 | 502 | |
519 | | - if( !$wgBlockAllowsUTEdit ){ |
520 | | - $data['PreventUTEdit'] = true; |
521 | | - } |
522 | | - |
523 | | - # If the user has done the form 'properly', they won't even have been given the |
524 | | - # option to suppress-block unless they have the 'hideuser' permission |
525 | | - if( !isset( $data['HideUser'] ) ){ |
526 | | - $data['HideUser'] = false; |
527 | | - } |
528 | | - if( $data['HideUser'] ) { |
529 | | - if( !$wgUser->isAllowed('hideuser') ){ |
530 | | - # this codepath is unreachable except by a malicious user spoofing forms, |
531 | | - # or by race conditions (user has oversight and sysop, loads block form, |
532 | | - # and is de-oversighted before submission); so need to fail completely |
533 | | - # rather than just silently disable hiding |
534 | | - return array( 'badaccess-group0' ); |
535 | | - } |
536 | | - |
537 | | - # Recheck params here... |
538 | | - if( $type != Block::TYPE_USER ) { |
539 | | - $data['HideUser'] = false; # IP users should not be hidden |
540 | | - |
541 | | - } elseif( !in_array( $data['Expiry'], array( 'inifinite', 'infinity', 'indefinite' ) ) ) { |
542 | | - # Bad expiry. |
| 503 | + if( $this->BlockHideName ) { |
| 504 | + // Recheck params here... |
| 505 | + if( !$userId || !$wgUser->isAllowed('hideuser') ) { |
| 506 | + $this->BlockHideName = false; // IP users should not be hidden |
| 507 | + } elseif( $expiry !== 'infinity' ) { |
| 508 | + // Bad expiry. |
543 | 509 | return array( 'ipb_expiry_temp' ); |
544 | | - |
545 | | - } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) { |
546 | | - # Typically, the user should have a handful of edits. |
547 | | - # Disallow hiding users with many edits for performance. |
| 510 | + } elseif( User::edits( $userId ) > self::HIDEUSER_CONTRIBLIMIT ) { |
| 511 | + // Typically, the user should have a handful of edits. |
| 512 | + // Disallow hiding users with many edits for performance. |
548 | 513 | return array( 'ipb_hide_invalid' ); |
549 | 514 | } |
550 | 515 | } |
551 | 516 | |
552 | | - # Create block object. Note that for a user block, ipb_address is only for display purposes |
553 | | - # FIXME: Why do we need to pass fourteen optional parameters to do this!?! |
554 | | - $block = new Block( |
555 | | - $target, # IP address or User name |
556 | | - $userId, # User id |
557 | | - $wgUser->getId(), # Blocker id |
558 | | - $data['Reason'][0], # Reason string |
559 | | - wfTimestampNow(), # Block Timestamp |
560 | | - 0, # Is this an autoblock (no) |
561 | | - Block::parseExpiryInput( $data['Expiry'] ), # Expiry time |
562 | | - !$data['HardBlock'], # Block anon only |
563 | | - $data['CreateAccount'], |
564 | | - $data['AutoBlock'], |
565 | | - $data['HideUser'], |
566 | | - $data['DisableEmail'], |
567 | | - !$data['DisableUTEdit'] # *Allow* UTEdit |
| 517 | + # Create block object |
| 518 | + # Note: for a user block, ipb_address is only for display purposes |
| 519 | + $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(), |
| 520 | + $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, |
| 521 | + $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, |
| 522 | + $this->BlockEmail, |
| 523 | + isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit |
568 | 524 | ); |
569 | 525 | |
570 | | - if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { |
571 | | - return array( 'hookaborted' ); |
572 | | - } |
573 | | - |
574 | | - # Try to insert block. Is there a conflicting block? |
575 | | - if( !$block->insert() ) { |
576 | | - |
577 | | - # Show form unless the user is already aware of this... |
578 | | - if( !$data['AlreadyBlocked'] ) { |
579 | | - return array( array( 'ipb_already_blocked', $data['Target'] ) ); |
580 | | - |
581 | | - # Otherwise, try to update the block... |
582 | | - } else { |
583 | | - |
584 | | - # This returns direct blocks before autoblocks/rangeblocks, since we should |
585 | | - # be sure the user is blocked by now it should work for our purposes |
586 | | - $currentBlock = Block::newFromDB( $target, $userId ); |
587 | | - |
588 | | - if( $block->equals( $currentBlock ) ) { |
| 526 | + # Should this be privately logged? |
| 527 | + $suppressLog = (bool)$this->BlockHideName; |
| 528 | + if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { |
| 529 | + # Try to insert block. Is there a conflicting block? |
| 530 | + if( !$block->insert() ) { |
| 531 | + # Show form unless the user is already aware of this... |
| 532 | + if( !$this->BlockReblock ) { |
589 | 533 | return array( 'ipb_already_blocked' ); |
| 534 | + # Otherwise, try to update the block... |
| 535 | + } else { |
| 536 | + # This returns direct blocks before autoblocks/rangeblocks, since we should |
| 537 | + # be sure the user is blocked by now it should work for our purposes |
| 538 | + $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); |
| 539 | + if( $block->equals( $currentBlock ) ) { |
| 540 | + return array( 'ipb_already_blocked' ); |
| 541 | + } |
| 542 | + # If the name was hidden and the blocking user cannot hide |
| 543 | + # names, then don't allow any block changes... |
| 544 | + if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) { |
| 545 | + return array( 'cant-see-hidden-user' ); |
| 546 | + } |
| 547 | + $currentBlock->delete(); |
| 548 | + $block->insert(); |
| 549 | + # If hiding/unhiding a name, this should go in the private logs |
| 550 | + $suppressLog = $suppressLog || (bool)$currentBlock->mHideName; |
| 551 | + $log_action = 'reblock'; |
| 552 | + # Unset _deleted fields if requested |
| 553 | + if( $currentBlock->mHideName && !$this->BlockHideName ) { |
| 554 | + RevisionDeleteUser::unsuppressUserName( $this->BlockAddress, $userId ); |
| 555 | + } |
590 | 556 | } |
| 557 | + } else { |
| 558 | + $log_action = 'block'; |
| 559 | + } |
| 560 | + wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) ); |
591 | 561 | |
592 | | - # If the name was hidden and the blocking user cannot hide |
593 | | - # names, then don't allow any block changes... |
594 | | - if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) { |
595 | | - return array( 'cant-see-hidden-user' ); |
596 | | - } |
| 562 | + # Set *_deleted fields if requested |
| 563 | + if( $this->BlockHideName ) { |
| 564 | + RevisionDeleteUser::suppressUserName( $this->BlockAddress, $userId ); |
| 565 | + } |
597 | 566 | |
598 | | - $currentBlock->delete(); |
599 | | - $block->insert(); |
600 | | - $logaction = 'reblock'; |
601 | | - |
602 | | - # Unset _deleted fields if requested |
603 | | - if( $currentBlock->mHideName && !$data['HideUser'] ) { |
604 | | - RevisionDeleteUser::unsuppressUserName( $target, $userId ); |
605 | | - } |
606 | | - |
607 | | - # If hiding/unhiding a name, this should go in the private logs |
608 | | - if( (bool)$currentBlock->mHideName ){ |
609 | | - $data['HideUser'] = true; |
610 | | - } |
| 567 | + # Only show watch link when this is no range block |
| 568 | + if( $this->BlockWatchUser && $block->mRangeStart == $block->mRangeEnd ) { |
| 569 | + $wgUser->addWatch( Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
611 | 570 | } |
612 | 571 | |
613 | | - } else { |
614 | | - $logaction = 'block'; |
615 | | - } |
| 572 | + # Block constructor sanitizes certain block options on insert |
| 573 | + $this->BlockEmail = $block->mBlockEmail; |
| 574 | + $this->BlockEnableAutoblock = $block->mEnableAutoblock; |
616 | 575 | |
617 | | - wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) ); |
| 576 | + # Prepare log parameters |
| 577 | + $logParams = array(); |
| 578 | + $logParams[] = $expirestr; |
| 579 | + $logParams[] = $this->blockLogFlags(); |
618 | 580 | |
619 | | - # Set *_deleted fields if requested |
620 | | - if( $data['HideUser'] ) { |
621 | | - RevisionDeleteUser::suppressUserName( $target, $userId ); |
622 | | - } |
| 581 | + # Make log entry, if the name is hidden, put it in the oversight log |
| 582 | + $log_type = $suppressLog ? 'suppress' : 'block'; |
| 583 | + $log = new LogPage( $log_type ); |
| 584 | + $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ), |
| 585 | + $reasonstr, $logParams ); |
623 | 586 | |
624 | | - # Can't watch a rangeblock |
625 | | - if( $type != Block::TYPE_RANGE && $data['Watch'] ) { |
626 | | - $wgUser->addWatch( Title::makeTitle( NS_USER, $target ) ); |
| 587 | + # Report to the user |
| 588 | + return array(); |
| 589 | + } else { |
| 590 | + return array( 'hookaborted' ); |
627 | 591 | } |
| 592 | + } |
628 | 593 | |
629 | | - # Block constructor sanitizes certain block options on insert |
630 | | - $data['BlockEmail'] = $block->mBlockEmail; |
631 | | - $data['AutoBlock'] = $block->mEnableAutoblock; |
| 594 | + # @deprecated since 1.18 |
| 595 | + public static function suppressUserName( $name, $userId, $dbw = null ) { |
| 596 | + return RevisionDeleteUser::suppressUserName( $name, $userId, $dbw ); |
| 597 | + } |
632 | 598 | |
633 | | - # Prepare log parameters |
634 | | - $logParams = array(); |
635 | | - $logParams[] = $data['Expiry']; |
636 | | - $logParams[] = self::blockLogFlags( $data, $type ); |
637 | | - |
638 | | - # Make log entry, if the name is hidden, put it in the oversight log |
639 | | - $log_type = $data['HideUser'] ? 'suppress' : 'block'; |
640 | | - $log = new LogPage( $log_type ); |
641 | | - $log->addEntry( |
642 | | - $logaction, |
643 | | - Title::makeTitle( NS_USER, $target ), |
644 | | - $data['Reason'][0], |
645 | | - $logParams |
646 | | - ); |
647 | | - |
648 | | - # Report to the user |
649 | | - return true; |
| 599 | + # @deprecated since 1.18 |
| 600 | + public static function unsuppressUserName( $name, $userId, $dbw = null ) { |
| 601 | + return RevisionDeleteUser::unsuppressUserName( $name, $userId, $dbw ); |
650 | 602 | } |
651 | 603 | |
652 | 604 | /** |
653 | | - * Get an array of suggested block durations from MediaWiki:Ipboptions |
654 | | - * FIXME: this uses a rather odd syntax for the options, should it be converted |
655 | | - * to the standard "**<duration>|<displayname>" format? |
656 | | - * @return Array |
| 605 | + * UI entry point for blocking |
| 606 | + * Wraps around doBlock() |
657 | 607 | */ |
658 | | - protected static function getSuggestedDurations(){ |
659 | | - $a = array(); |
660 | | - foreach( explode( ',', wfMsgForContent( 'ipboptions' ) ) as $option ) { |
661 | | - if( strpos( $option, ':' ) === false ) $option = "$option:$option"; |
662 | | - list( $show, $value ) = explode( ':', $option ); |
663 | | - $a[htmlspecialchars( $show )] = htmlspecialchars( $value ); |
| 608 | + public function doSubmit() { |
| 609 | + global $wgOut; |
| 610 | + $retval = $this->doBlock(); |
| 611 | + if( empty( $retval ) ) { |
| 612 | + $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
| 613 | + $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . |
| 614 | + urlencode( $this->BlockAddress ) ) ); |
| 615 | + return; |
664 | 616 | } |
665 | | - return $a; |
| 617 | + $this->showForm( $retval ); |
666 | 618 | } |
667 | 619 | |
668 | | - /** |
669 | | - * Can we do an email block? |
670 | | - * @param $user User: the sysop wanting to make a block |
671 | | - * @return Boolean |
672 | | - */ |
673 | | - public static function canBlockEmail( $user ) { |
674 | | - global $wgEnableUserEmail, $wgSysopEmailBans; |
675 | | - return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); |
| 620 | + public function showSuccess() { |
| 621 | + global $wgOut; |
| 622 | + |
| 623 | + $wgOut->setPageTitle( wfMsg( 'blockip-title' ) ); |
| 624 | + $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); |
| 625 | + $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress ); |
| 626 | + $wgOut->addHTML( $text ); |
676 | 627 | } |
677 | 628 | |
678 | | - /** |
679 | | - * bug 15810: blocked admins should not be able to block/unblock |
680 | | - * others, and probably shouldn't be able to unblock themselves |
681 | | - * either. |
682 | | - * @param $user User|Int|String |
683 | | - */ |
684 | | - public static function checkUnblockSelf( $user ) { |
| 629 | + private function showLogFragment( $out, $title ) { |
685 | 630 | global $wgUser; |
686 | | - if ( is_int( $user ) ) { |
687 | | - $user = User::newFromId( $user ); |
688 | | - } elseif ( is_string( $user ) ) { |
689 | | - $user = User::newFromName( $user ); |
| 631 | + |
| 632 | + // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog' |
| 633 | + $userBlocked = $title->getText(); |
| 634 | + |
| 635 | + LogEventsList::showLogExtract( |
| 636 | + $out, |
| 637 | + 'block', |
| 638 | + $title->getPrefixedText(), |
| 639 | + '', |
| 640 | + array( |
| 641 | + 'lim' => 10, |
| 642 | + 'msgKey' => array( |
| 643 | + 'blocklog-showlog', |
| 644 | + $userBlocked |
| 645 | + ), |
| 646 | + 'showIfEmpty' => false |
| 647 | + ) |
| 648 | + ); |
| 649 | + |
| 650 | + // Add suppression block entries if allowed |
| 651 | + if( $wgUser->isAllowed( 'suppressionlog' ) ) { |
| 652 | + LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '', |
| 653 | + array( |
| 654 | + 'lim' => 10, |
| 655 | + 'conds' => array( |
| 656 | + 'log_action' => array( |
| 657 | + 'block', |
| 658 | + 'reblock', |
| 659 | + 'unblock' |
| 660 | + ) |
| 661 | + ), |
| 662 | + 'msgKey' => array( |
| 663 | + 'blocklog-showsuppresslog', |
| 664 | + $userBlocked |
| 665 | + ), |
| 666 | + 'showIfEmpty' => false |
| 667 | + ) |
| 668 | + ); |
690 | 669 | } |
691 | | - if( $wgUser->isBlocked() ){ |
692 | | - if( $user instanceof User && $user->getId() == $wgUser->getId() ) { |
693 | | - # User is trying to unblock themselves |
694 | | - if ( $wgUser->isAllowed( 'unblockself' ) ) { |
695 | | - return true; |
696 | | - } else { |
697 | | - return 'ipbnounblockself'; |
698 | | - } |
699 | | - } else { |
700 | | - # User is trying to block/unblock someone else |
701 | | - return 'ipbblocked'; |
702 | | - } |
703 | | - } else { |
704 | | - return true; |
705 | | - } |
706 | 670 | } |
707 | 671 | |
708 | 672 | /** |
709 | 673 | * Return a comma-delimited list of "flags" to be passed to the log |
710 | 674 | * reader for this block, to provide more information in the logs |
711 | | - * @param $data Array from HTMLForm data |
712 | | - * @param $type Block::TYPE_ constant |
| 675 | + * |
713 | 676 | * @return array |
714 | 677 | */ |
715 | | - protected static function blockLogFlags( array $data, $type ) { |
| 678 | + private function blockLogFlags() { |
716 | 679 | global $wgBlockAllowsUTEdit; |
717 | 680 | $flags = array(); |
718 | | - |
719 | | - # when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log |
720 | | - if( !$data['HardBlock'] && $type != Block::TYPE_USER ){ |
| 681 | + if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) ) |
| 682 | + // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log |
721 | 683 | $flags[] = 'anononly'; |
722 | | - } |
723 | | - |
724 | | - if( $data['CreateAccount'] ){ |
| 684 | + if( $this->BlockCreateAccount ) |
725 | 685 | $flags[] = 'nocreate'; |
726 | | - } |
727 | | - |
728 | | - # Same as anononly, this is not displayed when blocking an IP address |
729 | | - if( !$data['AutoBlock'] && $type != Block::TYPE_IP ){ |
| 686 | + if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) ) |
| 687 | + // Same as anononly, this is not displayed when blocking an IP address |
730 | 688 | $flags[] = 'noautoblock'; |
731 | | - } |
732 | | - |
733 | | - if( $data['DisableEmail'] ){ |
| 689 | + if( $this->BlockEmail ) |
734 | 690 | $flags[] = 'noemail'; |
735 | | - } |
| 691 | + if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit ) |
| 692 | + $flags[] = 'nousertalk'; |
| 693 | + if( $this->BlockHideName ) |
| 694 | + $flags[] = 'hiddenname'; |
| 695 | + return implode( ',', $flags ); |
| 696 | + } |
736 | 697 | |
737 | | - if( $data['DisableUTEdit'] && $wgBlockAllowsUTEdit ){ |
738 | | - $flags[] = 'nousertalk'; |
| 698 | + /** |
| 699 | + * Builds unblock and block list links |
| 700 | + * |
| 701 | + * @return string |
| 702 | + */ |
| 703 | + private function getConvenienceLinks() { |
| 704 | + global $wgUser, $wgLang; |
| 705 | + $skin = $wgUser->getSkin(); |
| 706 | + if( $this->BlockAddress ) |
| 707 | + $links[] = $this->getContribsLink( $skin ); |
| 708 | + $links[] = $this->getUnblockLink( $skin ); |
| 709 | + $links[] = $this->getBlockListLink( $skin ); |
| 710 | + if ( $wgUser->isAllowed( 'editinterface' ) ) { |
| 711 | + $title = Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ); |
| 712 | + $links[] = $skin->link( |
| 713 | + $title, |
| 714 | + wfMsgHtml( 'ipb-edit-dropdown' ), |
| 715 | + array(), |
| 716 | + array( 'action' => 'edit' ) |
| 717 | + ); |
739 | 718 | } |
| 719 | + return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>'; |
| 720 | + } |
740 | 721 | |
741 | | - if( $data['HideUser'] ){ |
742 | | - $flags[] = 'hiddenname'; |
| 722 | + /** |
| 723 | + * Build a convenient link to a user or IP's contribs |
| 724 | + * form |
| 725 | + * |
| 726 | + * @param $skin Skin to use |
| 727 | + * @return string |
| 728 | + */ |
| 729 | + private function getContribsLink( $skin ) { |
| 730 | + $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress ); |
| 731 | + return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) ); |
| 732 | + } |
| 733 | + |
| 734 | + /** |
| 735 | + * Build a convenient link to unblock the given username or IP |
| 736 | + * address, if available; otherwise link to a blank unblock |
| 737 | + * form |
| 738 | + * |
| 739 | + * @param $skin Skin to use |
| 740 | + * @return string |
| 741 | + */ |
| 742 | + private function getUnblockLink( $skin ) { |
| 743 | + $list = SpecialPage::getTitleFor( 'Ipblocklist' ); |
| 744 | + $query = array( 'action' => 'unblock' ); |
| 745 | + |
| 746 | + if( $this->BlockAddress ) { |
| 747 | + $addr = strtr( $this->BlockAddress, '_', ' ' ); |
| 748 | + $message = wfMsg( 'ipb-unblock-addr', $addr ); |
| 749 | + $query['ip'] = $this->BlockAddress; |
| 750 | + } else { |
| 751 | + $message = wfMsg( 'ipb-unblock' ); |
743 | 752 | } |
| 753 | + return $skin->linkKnown( |
| 754 | + $list, |
| 755 | + htmlspecialchars( $message ), |
| 756 | + array(), |
| 757 | + $query |
| 758 | + ); |
| 759 | + } |
744 | 760 | |
745 | | - return implode( ',', $flags ); |
| 761 | + /** |
| 762 | + * Build a convenience link to the block list |
| 763 | + * |
| 764 | + * @param $skin Skin to use |
| 765 | + * @return string |
| 766 | + */ |
| 767 | + private function getBlockListLink( $skin ) { |
| 768 | + return $skin->linkKnown( |
| 769 | + SpecialPage::getTitleFor( 'Ipblocklist' ), |
| 770 | + wfMsg( 'ipb-blocklist' ) |
| 771 | + ); |
746 | 772 | } |
| 773 | + |
| 774 | + /** |
| 775 | + * Block a list of selected users |
| 776 | + * |
| 777 | + * @param $users Array |
| 778 | + * @param $reason String |
| 779 | + * @param $tag String: replaces user pages |
| 780 | + * @param $talkTag String: replaces user talk pages |
| 781 | + * @return Array: list of html-safe usernames |
| 782 | + */ |
| 783 | + public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) { |
| 784 | + global $wgUser; |
| 785 | + $counter = $blockSize = 0; |
| 786 | + $safeUsers = array(); |
| 787 | + $log = new LogPage( 'block' ); |
| 788 | + foreach( $users as $name ) { |
| 789 | + # Enforce limits |
| 790 | + $counter++; |
| 791 | + $blockSize++; |
| 792 | + # Lets not go *too* fast |
| 793 | + if( $blockSize >= 20 ) { |
| 794 | + $blockSize = 0; |
| 795 | + wfWaitForSlaves( 5 ); |
| 796 | + } |
| 797 | + $u = User::newFromName( $name, false ); |
| 798 | + // If user doesn't exist, it ought to be an IP then |
| 799 | + if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) { |
| 800 | + continue; |
| 801 | + } |
| 802 | + $userTitle = $u->getUserPage(); |
| 803 | + $userTalkTitle = $u->getTalkPage(); |
| 804 | + $userpage = new Article( $userTitle ); |
| 805 | + $usertalk = new Article( $userTalkTitle ); |
| 806 | + $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]'; |
| 807 | + $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
| 808 | + $expiry = Block::parseExpiryInput( $expirestr ); |
| 809 | + $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
| 810 | + // Create the block |
| 811 | + $block = new Block( $u->getName(), // victim |
| 812 | + $u->getId(), // uid |
| 813 | + $wgUser->getId(), // blocker |
| 814 | + $reason, // comment |
| 815 | + wfTimestampNow(), // block time |
| 816 | + 0, // auto ? |
| 817 | + $expiry, // duration |
| 818 | + $anonOnly, // anononly? |
| 819 | + 1, // block account creation? |
| 820 | + 1, // autoblocking? |
| 821 | + 0, // suppress name? |
| 822 | + 0 // block from sending email? |
| 823 | + ); |
| 824 | + $oldblock = Block::newFromDB( $u->getName(), $u->getId() ); |
| 825 | + if( !$oldblock ) { |
| 826 | + $block->insert(); |
| 827 | + # Prepare log parameters |
| 828 | + $logParams = array(); |
| 829 | + $logParams[] = $expirestr; |
| 830 | + if( $anonOnly ) { |
| 831 | + $logParams[] = 'anononly'; |
| 832 | + } |
| 833 | + $logParams[] = 'nocreate'; |
| 834 | + # Add log entry |
| 835 | + $log->addEntry( 'block', $userTitle, $reason, $logParams ); |
| 836 | + } |
| 837 | + # Tag userpage! (check length to avoid mistakes) |
| 838 | + if( strlen( $tag ) > 2 ) { |
| 839 | + $userpage->doEdit( $tag, $reason, EDIT_MINOR ); |
| 840 | + } |
| 841 | + if( strlen( $talkTag ) > 2 ) { |
| 842 | + $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR ); |
| 843 | + } |
| 844 | + } |
| 845 | + return $safeUsers; |
| 846 | + } |
747 | 847 | } |
748 | | - |
749 | | -# BC @since 1.18 |
750 | | -class IPBlockForm extends SpecialBlock {} |
Property changes on: trunk/phase3/includes/specials/SpecialBlock.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
751 | 848 | Merged /branches/REL1_15/phase3/includes/specials/SpecialBlockip.php:r51646 |
752 | 849 | Merged /branches/sqlite/includes/specials/SpecialBlockip.php:r58211-58321 |
753 | 850 | Merged /branches/wmf-deployment/includes/specials/SpecialBlockip.php:r53381,56967 |
Added: svn:keywords |
754 | 851 | + Author Date Id Revision |