From 34ac5745f9d4634fc8800e363cb2060c4d30fd3a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 27 Nov 2004 23:57:55 +0000 Subject: [PATCH] Added event-hooking code for blocking users and IPs. Added a handler to the Syslog extension for blocked users to test this event. Added documentation for the event to hooks.doc. --- docs/hooks.doc | 9 ++++++++- extensions/Syslog.php | 8 ++++++++ includes/SpecialBlockip.php | 24 +++++++++++++++--------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/docs/hooks.doc b/docs/hooks.doc index 0e2d167fd2..26e3fa4590 100644 --- a/docs/hooks.doc +++ b/docs/hooks.doc @@ -226,6 +226,14 @@ hooks than for "complete" hooks. This is a list of known events and parameters; please add to it if you're going to add events to the MediaWiki code. +'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) + +'BlockIpComplete': after an IP address or user is blocked +$block: the Block object that was saved +$user: the user who did the block (not the one being blocked) + 'UserLoginComplete': after a user has logged in $user: the user object that was created on login @@ -235,4 +243,3 @@ $user: the user object that is about to be logged out 'UserLogoutComplete': after a user has logged out $user: the user object _after_ logout (won't have name, ID, etc.) - diff --git a/extensions/Syslog.php b/extensions/Syslog.php index 0e09b2c078..ffd3127535 100644 --- a/extensions/Syslog.php +++ b/extensions/Syslog.php @@ -45,6 +45,13 @@ if (defined('MEDIAWIKI')) { syslog(LOG_INFO, "User '" . $user->getName() . "' logged out."); return true; } + + function syslogBlockIp(&$block, &$user) { + syslog(LOG_INFO, "User '" . $user->getName() . + "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) . + "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'"); + return true; + } # Setup -- called once environment is configured @@ -57,6 +64,7 @@ if (defined('MEDIAWIKI')) { $wgHooks['UserLoginComplete'][] = syslogUserLogin; $wgHooks['UserLogout'][] = syslogUserLogout; + $wgHooks['BlockIpComplete'][] = syslogBlockIp; return true; } diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index f3e15342bc..9c698f544e 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -147,7 +147,7 @@ class IPBlockForm { return; } - $expiry = wfUnix2Timestamp( $expiry ); + $expiry = wfTimestamp( TS_MW, $expiry ); } @@ -161,15 +161,21 @@ class IPBlockForm { $ban = new Block( $this->BlockAddress, $userId, $wgUser->getID(), wfStrencode( $this->BlockReason ), wfTimestampNow(), 0, $expiry ); - $ban->insert(); - - # Make log entry - $log = new LogPage( 'block' ); - $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $this->BlockReason ); + + if (wfRunHooks('BlockIp', $ban, $wgUser)) { + + $ban->insert(); + + wfRunHooks('BlockIpComplete', $ban, $wgUser); + + # Make log entry + $log = new LogPage( 'block' ); + $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $this->BlockReason ); - # Report to the user - $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' ); - $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress ) ); + # Report to the user + $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' ); + $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress ) ); + } } function showSuccess() { -- 2.20.1