Added hook events for "E-mail this user" feature. Documented in
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 04:23:12 +0000 (04:23 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 04:23:12 +0000 (04:23 +0000)
hooks.doc, and added a sample hook to Syslog extension.

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

index 34cd050..2032aac 100644 (file)
@@ -276,6 +276,18 @@ $user: the user _doing_ the block (not the one being blocked)
 $block: the Block object that was saved
 $user: the user who did the block (not the one being blocked)
 
+'EmailUser': before sending email from one user to another
+$to: address of receiving user
+$from: address of sending user
+$subject: subject of the mail
+$text: text of the mail
+
+'EmailUserComplete': after sending email from one user to another
+$to: address of receiving user
+$from: address of sending user
+$subject: subject of the mail
+$text: text of the mail
+
 'UnknownAction': An unknown "action" has occured (useful for defining
                 your own actions)
 $action: action name
index f9afe1d..3f69bf9 100644 (file)
@@ -88,6 +88,10 @@ if (defined('MEDIAWIKI')) {
                return true;
        }
 
+       function syslogEmailUser(&$to, &$from, &$subject, &$text) {
+               syslog(LOG_INFO, "Email sent from '$from' to '$to' with subject '$subject'");
+       }
+       
        # Setup -- called once environment is configured
        
        function setupSyslog() {
@@ -103,6 +107,7 @@ if (defined('MEDIAWIKI')) {
                $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect';
                $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
                $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
+               $wgHooks['EmailUserComplete'][] = 'syslogEmailUser';
                
                return true;
        }
index 8aed0f2..5da20d8 100644 (file)
@@ -137,17 +137,21 @@ class EmailUserForm {
                global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
            
                $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
+               $subject = wfQuotedPrintable( $this->subject );
                
-               $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text );
-
-               if (! $mailResult)
-               {
-                       $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
-                       $encTarget = wfUrlencode( $this->target );
-                       $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
+               if (wfRunHooks('EmailUser', $this->mAddress, $from, $subject, $this->text)) {
+                       
+                       $mailResult = userMailer( $this->mAddress, $from, $subject, $this->text );
+                       
+                       if (!$mailResult) {
+                               $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
+                               $encTarget = wfUrlencode( $this->target );
+                               $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
+                               wfRunHooks('EmailUserComplete', $this->mAddress, $from, $subject, $this->text);
+                       } else {
+                         $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
+                       }
                }
-               else
-                       $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
        }
 
        function showSuccess() {