MediaWiki r43155 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r43154‎ | r43155 (on ViewVC)‎ | r43156 >
Date:21:31, 3 November 2008
Author:siebrand
Status:old (Comments)
Tags:
Comment:
(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.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/UserMailer.php
===================================================================
--- trunk/phase3/includes/UserMailer.php	(revision 43154)
+++ trunk/phase3/includes/UserMailer.php	(revision 43155)
@@ -32,18 +32,21 @@
 	 * @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 @@
 		# can't handle "Joe Bloggs <joe@bloggs.com>" 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 @@
 	function composeCommonMailtext() {
 		global $wgPasswordSender, $wgNoReplyAddress;
 		global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
-		global $wgEnotifImpersonal;
+		global $wgEnotifImpersonal, $wgEnotifUseRealName;
 
 		$this->composed_common = true;
 
@@ -481,7 +486,7 @@
 		# 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 @@
 		//     Note:  The to parameter cannot be an address in the form of "Something <someone@example.com>".
 		//     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' );
 
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 43154)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 43155)
@@ -1500,6 +1500,9 @@
 # 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
  */
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 43154)
+++ trunk/phase3/RELEASE-NOTES	(revision 43155)
@@ -56,6 +56,8 @@
 * 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:

Follow-up revisions

Rev.Commit summaryAuthorDate
r43161Add missing global $wgEnotifUseRealName. Fix for undefined variable notice in...siebrand22:22, 3 November 2008
r43162Update documentation as pointed out by Aaron. Fix on r43155.siebrand22:26, 3 November 2008
r45880Fix typo in r43155...simetrical18:48, 18 January 2009

Comments

#Comment by Aaron Schulz (Talk | contribs)   22:22, 3 November 2008

'* @param bool $useRealName True will use real name instead of username' comment seems incorrect

#Comment by Siebrand (Talk | contribs)   22:27, 3 November 2008

Fixed in r43162. Thanks.

#Comment by Aaron Schulz (Talk | contribs)   22:34, 3 November 2008

Removed entirely in r43163

#Comment by Siebrand (Talk | contribs)   22:24, 3 November 2008

Fix undefined variable notice in r43161

Status & tagging log

  • 15:36, 12 September 2011 Meno25 (Talk | contribs) changed the status of r43155 [removed: resolved added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox