Added event-hooking code for blocking users and IPs. Added a handler
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Sat, 27 Nov 2004 23:57:55 +0000 (23:57 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Sat, 27 Nov 2004 23:57:55 +0000 (23:57 +0000)
to the Syslog extension for blocked users to test this event. Added
documentation for the event to hooks.doc.

docs/hooks.doc
extensions/Syslog.php
includes/SpecialBlockip.php

index 0e2d167..26e3fa4 100644 (file)
@@ -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.)
                      
-            
index 0e09b2c..ffd3127 100644 (file)
@@ -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;
        }
index f3e1534..9c698f5 100644 (file)
@@ -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() {