From f5aef17ef38a3d6fa70213a303933705d43d4f94 Mon Sep 17 00:00:00 2001 From: Justin Du Date: Fri, 30 Dec 2016 19:29:34 -0600 Subject: [PATCH] Add 'UnblockUser' and 'UnblockUserComplete' hooks to Special:Unblock 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 | 9 +++++++++ includes/specials/SpecialUnblock.php | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index b1652851ff..b6d37e07e1 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/specials/SpecialUnblock.php b/includes/specials/SpecialUnblock.php index 4e683f6e78..0d42e3fc70 100644 --- a/includes/specials/SpecialUnblock.php +++ b/includes/specials/SpecialUnblock.php @@ -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? -- 2.20.1