From 02af8ad230c00a8e1c62ea2920d3ae2e2c708c85 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 15 Jul 2011 00:05:50 +0000 Subject: [PATCH] * Removed angry autoblock code - unused by anything * Added $wgAutoblockHandlers variable for alternative autoblock handling functions * Gave CheckUser a potential $wgAutoblockHandlers function (bug 29330) --- includes/Block.php | 72 ++++++++++++++++++++++-------------- includes/DefaultSettings.php | 8 ++++ 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index d1218db7f0..e3bb0c48a0 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -20,7 +20,7 @@ * @file */ class Block { - /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock; + /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName; protected $mId, @@ -84,7 +84,6 @@ class Block { $this->prevents( 'editownusertalk', !$allowUsertalk ); $this->mFromMaster = false; - $this->mAngryAutoblock = false; } /** @@ -487,43 +486,60 @@ class Block { * @return Array: block IDs of retroactive autoblocks made */ protected function doRetroactiveAutoblock() { - $blockIds = array(); - - $dbr = wfGetDB( DB_SLAVE ); - # If autoblock is enabled, autoblock the LAST IP used - # - stolen shamelessly from CheckUser_body.php + global $wgAutoblockHandlers; + $blockIds = array(); + # If autoblock is enabled, autoblock the LAST IP(s) used if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) { wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" ); - $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); - $conds = array( 'rc_user_text' => (string)$this->getTarget() ); + $call = isset( $wgAutoblockHandlers['retroactiveAutoblock'] ) + ? $wgAutoblockHandlers['retroactiveAutoblock'] + : null; // default - if ( $this->mAngryAutoblock ) { - // Block any IP used in the last 7 days. Up to five IPs. - $conds[] = 'rc_timestamp < ' . - $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) ); - $options['LIMIT'] = 5; - } else { - // Just the last IP used. - $options['LIMIT'] = 1; + if ( is_callable( $call ) ) { // custom handler + $blockIds = MWFunction::call( $call, $this ); + } else { // regular handler + if ( $call !== null ) { // something given, but bad + wfWarn( 'doRetroactiveAutoblock given uncallable handler, check $wgAutoblockHandlers; using default handler.' ); + } + $blockIds = self::defaultRetroactiveAutoblock( $this ); } + } - $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds, - __METHOD__ , $options ); + return $blockIds; + } - if ( !$dbr->numRows( $res ) ) { - # No results, don't autoblock anything - wfDebug( "No IP found to retroactively autoblock\n" ); - } else { - foreach ( $res as $row ) { - if ( $row->rc_ip ) { - $id = $this->doAutoblock( $row->rc_ip ); - if ( $id ) $blockIds[] = $id; - } + /** + * Retroactively autoblocks the last IP used by the user (if it is a user) + * blocked by this Block. This will use the recentchanges table. + * + * @return Array: block IDs of retroactive autoblocks made + */ + protected static function defaultRetroactiveAutoblock( Block $block ) { + $dbr = wfGetDB( DB_SLAVE ); + + $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); + $conds = array( 'rc_user_text' => (string)$block->getTarget() ); + + // Just the last IP used. + $options['LIMIT'] = 1; + + $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds, + __METHOD__ , $options ); + + if ( !$dbr->numRows( $res ) ) { + # No results, don't autoblock anything + wfDebug( "No IP found to retroactively autoblock\n" ); + } else { + foreach ( $res as $row ) { + if ( $row->rc_ip ) { + $id = $block->doAutoblock( $row->rc_ip ); + if ( $id ) $blockIds[] = $id; } } } + return $blockIds; } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3ddddd72a9..422cb4df01 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3260,6 +3260,14 @@ $wgBlockCIDRLimit = array( 'IPv6' => 64, # 2^64 = ~1.8x10^19 addresses ); +/** + * Functions to handle autoblocking users. The default handlers will be used + * where null is given. They can otherwise be overridden with custom callbacks. + * + * 'retroactiveAutoblock' handlers must return the array of autoblock IDs + */ +$wgAutoblockHandlers = array( 'retroactiveAutoblock' => null ); + /** * If true, blocked users will not be allowed to login. When using this with * a public wiki, the effect of logging out blocked users may actually be -- 2.20.1