Add 'UnblockUser' and 'UnblockUserComplete' hooks to Special:Unblock
authorJustin Du <justin.d128@gmail.com>
Sat, 31 Dec 2016 01:29:34 +0000 (19:29 -0600)
committerJustin Du <justin.d128@gmail.com>
Sat, 31 Dec 2016 01:34:20 +0000 (19:34 -0600)
Currently, there are two hooks ('BlockIP' and 'BlockIPComplete') that run when a user or IP is blocked in Special:Block, but no similar hooks when a user is unblocked in Special:Unblock. Adding these two hooks allows an extension to add and remove criteria about a user/IP unblock before it occurs and for possible action after an unblock is completed.

Bug: T50546
Change-Id: I9d9888dc5f1bb6a8bc62e90e6a423bf56b05173b

docs/hooks.txt
includes/specials/SpecialUnblock.php

index b165285..b6d37e0 100644 (file)
@@ -3379,6 +3379,15 @@ $user: Current user object
 $title: Title object to purge
 &$urls: An array of URLs to purge from the caches, to be manipulated.
 
+'UnblockUser': Before an IP address or user is unblocked.
+&$block: The Block object about to be saved
+&$user: The user performing the unblock (not the one being unblocked)
+&$reason: If the hook is aborted, the error message to be returned in an array
+
+'UnblockUserComplete': After an IP address or user has been unblocked.
+$block: The Block object that was saved
+$user: The user who performed the unblock (not the one being unblocked)
+
 'UndeleteForm::showHistory': Called in UndeleteForm::showHistory, after a
 PageArchive object has been created but before any further processing is done.
 &$archive: PageArchive object
index 4e683f6..0d42e3f 100644 (file)
@@ -209,11 +209,18 @@ class SpecialUnblock extends SpecialPage {
                        return [ 'unblock-hideuser' ];
                }
 
+               $reason = [ 'hookaborted' ];
+               if ( !Hooks::run( 'UnblockUser', [ &$block, &$performer, &$reason ] ) ) {
+                       return $reason;
+               }
+
                # Delete block
                if ( !$block->delete() ) {
                        return [ [ 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) ] ];
                }
 
+               Hooks::run( 'UnblockUserComplete', [ $block, $performer ] );
+
                # Unset _deleted fields as needed
                if ( $block->mHideName ) {
                        # Something is deeply FUBAR if this is not a User object, but who knows?