Set values from query params (bug 12750)
[lhc/web/wiklou.git] / includes / Block.php
index b400912..30991c5 100644 (file)
@@ -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." );
@@ -532,6 +540,7 @@ class Block
                $ipblock->mAddress = $autoblockip;
                $ipblock->mUser = 0;
                $ipblock->mBy = $this->mBy;
+               $ipblock->mByName = $this->mByName;
                $ipblock->mReason = wfMsgForContent( 'autoblocker', $this->mAddress, $this->mReason );
                $ipblock->mTimestamp = wfTimestampNow();
                $ipblock->mAuto = 1;