From: Aaron Schulz Date: Wed, 3 Sep 2008 04:17:20 +0000 (+0000) Subject: Move doMassUserBlock() to core X-Git-Tag: 1.31.0-rc.0~45513 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=e5899826e2a30311684965f3137b6ff5eb04d217;p=lhc%2Fweb%2Fwiklou.git Move doMassUserBlock() to core --- diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index 56cf9c6918..226be10dc6 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -491,4 +491,71 @@ class IPBlockForm { return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) ); } } + + /** + * Block a list of selected users + * @param array $users + * @param string $reason + * @param string $tag + * @returns array, list of html-safe usernames + */ + public static function doMassUserBlock( $users, $reason = '', $tag = '' ) { + global $wgUser; + $counter = $blockSize = 0; + $safeUsers = array(); + $log = new LogPage( 'block' ); + foreach( $users as $name ) { + # Enforce limits + $counter++; + $blockSize++; + # Lets not go *too* fast + if( $blockSize >= 20 ) { + $blockSize = 0; + wfWaitForSlaves( 5 ); + } + $u = User::newFromName( $name, false ); + // If user doesn't exist, it ought to be an IP then + if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) { + continue; + } + $usertitle = Title::makeTitle( NS_USER, $u->getName() ); + $userpage = new Article( $usertitle ); + $safeUsers[] = '[[' . $usertitle->getPrefixedText() . '|' . $usertitle->getText() . ']]'; + $expirestr = $u->getId() ? 'indefinite' : '1 week'; + $expiry = Block::parseExpiryInput( $expirestr ); + $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; + // Create the block + $block = new Block( $u->getName(), // victim + $u->getId(), // uid + $wgUser->getId(), // blocker + $reason, // comment + wfTimestampNow(), // block time + 0, // auto ? + $expiry, // duration + $anonOnly, // anononly? + 1, // block account creation? + 1, // autoblocking? + 0, // suppress name? + 0 // block from sending email? + ); + $oldblock = Block::newFromDB( $u->getName() ); + if( !$oldblock ) { + $block->insert(); + # Prepare log parameters + $logParams = array(); + $logParams[] = $expirestr; + if( $anonOnly ) { + $logParams[] = 'anononly'; + } + $logParams[] = 'nocreate'; + # Add log entry + $log->addEntry( 'block', $usertitle, $reason, $logParams ); + } + # Tag userpage! (check length to avoid mistakes) + if( strlen($tag) > 2 ) { + $userpage->doEdit( $tag, $reason, EDIT_MINOR ); + } + } + return $safeUsers; + } }