Follow-up r92220: changed autoblock handling to use PerformRetroactiveAutoblock hook...
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 15 Jul 2011 00:48:02 +0000 (00:48 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 15 Jul 2011 00:48:02 +0000 (00:48 +0000)
docs/hooks.txt
includes/Block.php
includes/DefaultSettings.php

index f2b5101..9174351 100644 (file)
@@ -595,6 +595,10 @@ $image: File
 &$scalerParams: Array with scaler parameters 
 &$mto: null, set to a MediaTransformOutput
 
+'PerformRetroactiveAutoblock': called before a retroactive autoblock is applied to a user
+$block: Block object (which is set to be autoblocking)
+&$blockIds: Array of block IDs of the autoblock
+
 'BlockIp': before an IP address or user is blocked
 $block: the Block object about to be saved
 $user: the user _doing_ the block (not the one being blocked)
index e3bb0c4..ba875fa 100644 (file)
@@ -486,27 +486,18 @@ class Block {
         * @return Array: block IDs of retroactive autoblocks made
         */
        protected function doRetroactiveAutoblock() {
-               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" );
 
-                       $call = isset( $wgAutoblockHandlers['retroactiveAutoblock'] )
-                               ? $wgAutoblockHandlers['retroactiveAutoblock']
-                               : null; // default
+                       $continue = wfRunHooks(
+                               'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
 
-                       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 );
+                       if ( $continue ) {
+                               self::defaultRetroactiveAutoblock( $this, $blockIds );
                        }
                }
-
                return $blockIds;
        }
 
@@ -514,9 +505,11 @@ class Block {
         * Retroactively autoblocks the last IP used by the user (if it is a user)
         * blocked by this Block. This will use the recentchanges table.
         *
+        * @param Block $block
+        * @param Array &$blockIds
         * @return Array: block IDs of retroactive autoblocks made
         */
-       protected static function defaultRetroactiveAutoblock( Block $block ) {
+       protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
                $dbr = wfGetDB( DB_SLAVE );
 
                $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
@@ -539,8 +532,6 @@ class Block {
                                }
                        }
                }
-
-               return $blockIds;
        }
 
        /**
index 422cb4d..3ddddd7 100644 (file)
@@ -3260,14 +3260,6 @@ $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