From 7ccff4543c5eb566ddae26851c624cadaff41554 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Mon, 3 Nov 2008 21:31:47 +0000 Subject: [PATCH] (bug 15068) Added $wgEnotifUseRealName, which allows UserMailer to send out e-mails based on the user's real name if one is set. Defaults to false (use the username). Patch by ^demon (Chad Horohoe). Per suggestion of brion. --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 3 +++ includes/UserMailer.php | 16 +++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3372e8ce2b..bd4532f9e9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -56,6 +56,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Added $wgAllowUserSkin to let the wiki's owner disable user selectable skins on the wiki. If it's set to true, then the skin used will *always* be $wgDefaultSkin. +* Added $wgEnotifUseRealName, which allows UserMailer to send out e-mails based + on the user's real name if one is set. Defaults to false (use the username) === Migrated extensions === The following extensions are migrated into MediaWiki 1.14: diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f6b9f38826..e7263265cc 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1500,6 +1500,9 @@ $wgEnotifMaxRecips = 500; # Send mails via the job queue. $wgEnotifUseJobQ = false; +# Use real name instead of username in e-mail "from" field +$wgEnotifUseRealName = false; + /** * Array of usernames who will be sent a notification email for every change which occurs on a wiki */ diff --git a/includes/UserMailer.php b/includes/UserMailer.php index d3b2b5d989..010bc503be 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -32,18 +32,21 @@ class MailAddress { * @param $address Mixed: string with an email address, or a User object * @param $name String: human-readable name if a string address is given */ - function __construct( $address, $name=null ) { + function __construct( $address, $name = null, $realName = null ) { if( is_object( $address ) && $address instanceof User ) { $this->address = $address->getEmail(); $this->name = $address->getName(); + $this->realName = $address->getRealName(); } else { $this->address = strval( $address ); $this->name = strval( $name ); + $this->reaName = strval( $realName ); } } /** * Return formatted and quoted address to insert into SMTP headers + * @param bool $useRealName True will use real name instead of username * @return string */ function toString() { @@ -51,7 +54,9 @@ class MailAddress { # can't handle "Joe Bloggs " format email addresses, # so don't bother generating them if( $this->name != '' && !wfIsWindows() ) { - $quoted = wfQuotedPrintable( $this->name ); + global $wgEnotifUseRealName; + $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name; + $quoted = wfQuotedPrintable( $name ); if( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) { $quoted = '"' . $quoted . '"'; } @@ -427,7 +432,7 @@ class EmailNotification { function composeCommonMailtext() { global $wgPasswordSender, $wgNoReplyAddress; global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress; - global $wgEnotifImpersonal; + global $wgEnotifImpersonal, $wgEnotifUseRealName; $this->composed_common = true; @@ -481,7 +486,7 @@ class EmailNotification { # the user has not opted-out and the option is enabled at the # global configuration level. $editor = $this->editor; - $name = $editor->getName(); + $name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName(); $adminAddress = new MailAddress( $wgPasswordSender, 'WikiAdmin' ); $editorAddress = new MailAddress( $editor ); if( $wgEnotifRevealEditorAddress @@ -567,7 +572,8 @@ class EmailNotification { // Note: The to parameter cannot be an address in the form of "Something ". // The mail command will not parse this properly while talking with the MTA. $to = new MailAddress( $watchingUser ); - $body = str_replace( '$WATCHINGUSERNAME', $watchingUser->getName() , $this->body ); + $name = $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName(); + $body = str_replace( '$WATCHINGUSERNAME', $name , $this->body ); $timecorrection = $watchingUser->getOption( 'timecorrection' ); -- 2.20.1