From 7106853462320a9786da8eedef79b2a1e65416b8 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 8 Aug 2008 05:56:43 +0000 Subject: [PATCH] Refactor out Block::isWhitelistedFromAutoblocks --- includes/Block.php | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index b208fa8aca..30991c5f51 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -458,25 +458,15 @@ class Block } } } - + /** - * Autoblocks the given IP, referring to this Block. - * @param string $autoblockip The IP to autoblock. - * @param bool $justInserted The main block was just inserted - * @return bool Whether or not an autoblock was inserted. - */ - function doAutoblock( $autoblockip, $justInserted = false ) { - # If autoblocks are disabled, go away. - if ( !$this->mEnableAutoblock ) { - return; - } - - # Check for presence on the autoblock whitelist + * Checks whether a given IP is on the autoblock whitelist. + * @param string $autoblockip The IP to check + */ + function isWhitelistedFromAutoblocks( $ip ) { # TODO cache this? $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) ); - $ip = $autoblockip; - wfDebug("Checking the autoblock whitelist..\n"); foreach( $lines as $line ) { @@ -493,14 +483,32 @@ class Block # Is the IP in this range? if (IP::isInRange( $ip, $wlEntry )) { wfDebug(" IP $ip matches $wlEntry, not autoblocking\n"); - #$autoblockip = null; # Don't autoblock a whitelisted IP. - return; #This /SHOULD/ introduce a dummy block - but - # I don't know a safe way to do so. -werdna + return true; } else { wfDebug( " No match\n" ); } } + return false; + } + + /** + * Autoblocks the given IP, referring to this Block. + * @param string $autoblockip The IP to autoblock. + * @param bool $justInserted The main block was just inserted + * @return bool Whether or not an autoblock was inserted. + */ + function doAutoblock( $autoblockip, $justInserted = false ) { + # If autoblocks are disabled, go away. + if ( !$this->mEnableAutoblock ) { + return; + } + + # Check for presence on the autoblock whitelist + if (Block::isWhitelistedFromAutoblocks($autoblockip)) { + return; + } + ## Allow hooks to cancel the autoblock. if (!wfRunHooks( 'AbortAutoblock', array( $autoblockip, &$this ) )) { wfDebug( "Autoblock aborted by hook." ); -- 2.20.1