Index: trunk/phase3/includes/specials/SpecialBlockip.php |
— | — | @@ -491,4 +491,71 @@ |
492 | 492 | return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) ); |
493 | 493 | } |
494 | 494 | } |
| 495 | + |
| 496 | + /** |
| 497 | + * Block a list of selected users |
| 498 | + * @param array $users |
| 499 | + * @param string $reason |
| 500 | + * @param string $tag |
| 501 | + * @returns array, list of html-safe usernames |
| 502 | + */ |
| 503 | + public static function doMassUserBlock( $users, $reason = '', $tag = '' ) { |
| 504 | + global $wgUser; |
| 505 | + $counter = $blockSize = 0; |
| 506 | + $safeUsers = array(); |
| 507 | + $log = new LogPage( 'block' ); |
| 508 | + foreach( $users as $name ) { |
| 509 | + # Enforce limits |
| 510 | + $counter++; |
| 511 | + $blockSize++; |
| 512 | + # Lets not go *too* fast |
| 513 | + if( $blockSize >= 20 ) { |
| 514 | + $blockSize = 0; |
| 515 | + wfWaitForSlaves( 5 ); |
| 516 | + } |
| 517 | + $u = User::newFromName( $name, false ); |
| 518 | + // If user doesn't exist, it ought to be an IP then |
| 519 | + if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) { |
| 520 | + continue; |
| 521 | + } |
| 522 | + $usertitle = Title::makeTitle( NS_USER, $u->getName() ); |
| 523 | + $userpage = new Article( $usertitle ); |
| 524 | + $safeUsers[] = '[[' . $usertitle->getPrefixedText() . '|' . $usertitle->getText() . ']]'; |
| 525 | + $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
| 526 | + $expiry = Block::parseExpiryInput( $expirestr ); |
| 527 | + $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
| 528 | + // Create the block |
| 529 | + $block = new Block( $u->getName(), // victim |
| 530 | + $u->getId(), // uid |
| 531 | + $wgUser->getId(), // blocker |
| 532 | + $reason, // comment |
| 533 | + wfTimestampNow(), // block time |
| 534 | + 0, // auto ? |
| 535 | + $expiry, // duration |
| 536 | + $anonOnly, // anononly? |
| 537 | + 1, // block account creation? |
| 538 | + 1, // autoblocking? |
| 539 | + 0, // suppress name? |
| 540 | + 0 // block from sending email? |
| 541 | + ); |
| 542 | + $oldblock = Block::newFromDB( $u->getName() ); |
| 543 | + if( !$oldblock ) { |
| 544 | + $block->insert(); |
| 545 | + # Prepare log parameters |
| 546 | + $logParams = array(); |
| 547 | + $logParams[] = $expirestr; |
| 548 | + if( $anonOnly ) { |
| 549 | + $logParams[] = 'anononly'; |
| 550 | + } |
| 551 | + $logParams[] = 'nocreate'; |
| 552 | + # Add log entry |
| 553 | + $log->addEntry( 'block', $usertitle, $reason, $logParams ); |
| 554 | + } |
| 555 | + # Tag userpage! (check length to avoid mistakes) |
| 556 | + if( strlen($tag) > 2 ) { |
| 557 | + $userpage->doEdit( $tag, $reason, EDIT_MINOR ); |
| 558 | + } |
| 559 | + } |
| 560 | + return $safeUsers; |
| 561 | + } |
495 | 562 | } |
Index: trunk/extensions/CheckUser/CheckUser_body.php |
— | — | @@ -222,70 +222,7 @@ |
223 | 223 | $wgOut->addWikiText( wfMsgExt('checkuser-block-noreason',array('parsemag')) ); |
224 | 224 | return; |
225 | 225 | } |
226 | | - $counter = $blockSize = 0; |
227 | | - $safeUsers = array(); |
228 | | - $log = new LogPage( 'block' ); |
229 | | - foreach( $users as $name ) { |
230 | | - # Enforce limits |
231 | | - $counter++; |
232 | | - $blockSize++; |
233 | | - if( $counter > $wgCheckUserMaxBlocks ) { |
234 | | - break; |
235 | | - } |
236 | | - # Lets not go *too* fast |
237 | | - if( $blockSize >= 20 ) { |
238 | | - $blockSize = 0; |
239 | | - wfWaitForSlaves( 5 ); |
240 | | - } |
241 | | - $u = User::newFromName( $name, false ); |
242 | | - // If user doesn't exist, it ought to be an IP then |
243 | | - if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) { |
244 | | - continue; |
245 | | - } |
246 | | - $usertitle = Title::makeTitle( NS_USER, $u->getName() ); |
247 | | - $userpage = new Article( $usertitle ); |
248 | | - $safeUsers[] = '[[' . $usertitle->getPrefixedText() . '|' . $usertitle->getText() . ']]'; |
249 | | - $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
250 | | - $expiry = Block::parseExpiryInput( $expirestr ); |
251 | | - $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
252 | | - // Create the block |
253 | | - $block = new Block( $u->getName(), // victim |
254 | | - $u->getId(), // uid |
255 | | - $wgUser->getId(), // blocker |
256 | | - $reason, // comment |
257 | | - wfTimestampNow(), // block time |
258 | | - 0, // auto ? |
259 | | - $expiry, // duration |
260 | | - $anonOnly, // anononly? |
261 | | - 1, // block account creation? |
262 | | - 1, // autoblocking? |
263 | | - 0, // suppress name? |
264 | | - 0 // block from sending email? |
265 | | - ); |
266 | | - $oldblock = Block::newFromDB( $u->getName() ); |
267 | | - /* |
268 | | - // Kill old blocks, but leave range blocks |
269 | | - if( $oldblock && $oldblock->mAddress == $u->getName() && $block->mRangeStart == $block->mRangeEnd ) { |
270 | | - $oldblock->delete(); |
271 | | - } |
272 | | - */ |
273 | | - if( !$oldblock ) { |
274 | | - $block->insert(); |
275 | | - # Prepare log parameters |
276 | | - $logParams = array(); |
277 | | - $logParams[] = $expirestr; |
278 | | - if( $anonOnly ) { |
279 | | - $logParams[] = 'anononly'; |
280 | | - } |
281 | | - $logParams[] = 'nocreate'; |
282 | | - # Add log entry |
283 | | - $log->addEntry( 'block', $usertitle, $reason, $logParams ); |
284 | | - } |
285 | | - # Tag userpage! (check length to avoid mistakes) |
286 | | - if( strlen($tag) > 2 ) { |
287 | | - $userpage->doEdit( $tag, $reason, EDIT_MINOR ); |
288 | | - } |
289 | | - } |
| 226 | + $safeUsers = IPBlockForm::doMassUserBlock( $users, $reason, $tag ); |
290 | 227 | if( !empty($safeUsers) ) { |
291 | 228 | $n = count($safeUsers); |
292 | 229 | $ulist = implode(', ',$safeUsers); |