From 778c431bfc2b47db281c979657d2514da0a4fc16 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 29 Nov 2004 04:23:12 +0000 Subject: [PATCH] Added hook events for "E-mail this user" feature. Documented in hooks.doc, and added a sample hook to Syslog extension. --- docs/hooks.doc | 12 ++++++++++++ extensions/Syslog.php | 5 +++++ includes/SpecialEmailuser.php | 22 +++++++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/hooks.doc b/docs/hooks.doc index 34cd050b1a..2032aacbcc 100644 --- a/docs/hooks.doc +++ b/docs/hooks.doc @@ -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 diff --git a/extensions/Syslog.php b/extensions/Syslog.php index f9afe1dc54..3f69bf9246 100644 --- a/extensions/Syslog.php +++ b/extensions/Syslog.php @@ -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; } diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 8aed0f2022..5da20d8d20 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -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() { -- 2.20.1