r81116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81115‎ | r81116 | r81117 >
Date:00:31, 28 January 2011
Author:brion
Status:ok
Tags:
Comment:
Partial revert of r68257: bizarre eval() stuff added to NewUserNotif contrary to MW coding practices
Left the removal of the require_once('UserMailer.php') as that's obsolete and caused fatal errors on newer code.
Modified paths:
  • /trunk/extensions/NewUserNotif/NewUserNotif.class.php (modified) (history)
  • /trunk/extensions/NewUserNotif/NewUserNotif.php (modified) (history)
  • /trunk/extensions/NewUserNotif/README (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserNotif/NewUserNotif.class.php
@@ -37,13 +37,13 @@
3838 * Send email to external addresses
3939 */
4040 private function sendExternalMails() {
41 - global $wgNewUserNotifEmailTargets, $wgNewUserNotifSenderParam, $wgNewUserNotifSenderSubjParam;
 41+ global $wgNewUserNotifEmailTargets, $wgSitename;
4242 foreach( $wgNewUserNotifEmailTargets as $target ) {
43 - UserMailer::send(
 43+ userMailer(
4444 new MailAddress( $target ),
4545 new MailAddress( $this->sender ),
46 - $this->makeMessage( $target, $this->user, 'newusernotifsubj', $wgNewUserNotifSenderSubjParam),
47 - $this->makeMessage( $target, $this->user, 'newusernotifbody', $wgNewUserNotifSenderParam)
 46+ wfMsgForContent( 'newusernotifsubj', $wgSitename ),
 47+ $this->makeMessage( $target, $this->user )
4848 );
4949 }
5050 }
@@ -52,13 +52,13 @@
5353 * Send email to users
5454 */
5555 private function sendInternalMails() {
56 - global $wgNewUserNotifTargets, $wgNewUserNotifSenderParam, $wgNewUserNotifSenderSubjParam;
 56+ global $wgNewUserNotifTargets, $wgSitename;
5757 foreach( $wgNewUserNotifTargets as $userSpec ) {
5858 $user = $this->makeUser( $userSpec );
5959 if( $user instanceof User && $user->isEmailConfirmed() ) {
6060 $user->sendMail(
61 - $this->makeMessage( $user->getName(), $this->user, 'newusernotifsubj', $wgNewUserNotifSenderSubjParam ),
62 - $this->makeMessage( $user->getName(), $this->user, 'newusernotifbody', $wgNewUserNotifSenderParam ),
 61+ wfMsgForContent( 'newusernotifsubj', $wgSitename ),
 62+ $this->makeMessage( $user->getName(), $this->user ),
6363 $this->sender
6464 );
6565 }
@@ -80,18 +80,22 @@
8181 }
8282
8383 /**
84 - * Build a notification email message (body and subject)
 84+ * Build a notification email
8585 *
86 - * @param string $recipient Name of the new user notification email recipient
87 - * @param User $user User (object) created for new user
88 - * @param string $msgId Localised Message Identifier
89 - * @param string $parmArr Array of Strings eval'd to pass parameters to message
90 - * @return string
 86+ * @param string $recipient Name of the recipient
 87+ * @param User $user User that was created
9188 */
92 - private function makeMessage( $recipient, $user, $msgId, $parmArr) {
93 - global $wgSitename,$wgContLang;
94 - eval( "\$retval = wfMsgForContent('".$msgId."',".implode(",",$parmArr).");" );
95 - return ($retval);
 89+ private function makeMessage( $recipient, $user ) {
 90+ global $wgSitename, $wgContLang;
 91+ return wfMsgForContent(
 92+ 'newusernotifbody',
 93+ $recipient,
 94+ $user->getName(),
 95+ $wgSitename,
 96+ $wgContLang->timeAndDate( wfTimestampNow() ),
 97+ $wgContLang->date( wfTimestampNow() ),
 98+ $wgContLang->time( wfTimestampNow() )
 99+ );
96100 }
97101
98102 /**
Index: trunk/extensions/NewUserNotif/README
@@ -1,5 +1,4 @@
22 NEW USER EMAIL NOTIFICATION EXTENSION
3 -(http://www.mediawiki.org/wiki/Extension:New_User_Email_Notification)
43
54 Version 1.5
65 © 2006-2007 Rob Church
@@ -14,9 +13,8 @@
1514 2. Installation requirements
1615 3. Installing the extension
1716 4. Editing the notification email
18 - 5. Configuration
19 - 6. Advanced Configuration
20 - 7. Feedback
 17+ 5. Further configuration
 18+ 6. Feedback
2119
2220 == 1. Introduction ==
2321
@@ -53,12 +51,9 @@
5452 $2 is replaced with the username of the new user account;
5553 $3 is replaced with the wiki site name from $wgSitename;
5654 $4 is replaced with the time and date of the account's creation.
57 - $5 is replaced with the date of the account's creation.
58 - $6 is replaced with the time of the account's creation.
5955
 56+== 5. Further configuration ==
6057
61 -== 5. Configuration ==
62 -
6358 The behaviour of the extension can be tweaked using three configuration
6459 variables. To override the defaults for these, set them in LocalSettings.php
6560 underneath the call to the extension file.
@@ -78,76 +73,7 @@
7974 $wgNewUserNotifEmailTargets
8075 Array containing email addresses to which a notification should also be sent
8176 Defaults to no additional addresses
82 -
83 -== 6. Advanced Configuration ==
8477
85 -As of version 1.5.2 of this extension, you can customize and add parameters passed to both the subject and body messages in your localsettings.php without modifying the extension code.
 78+== 6. Feedback ==
8679
87 -You can do this by adding (or changing) parameter values and/or functions that return the desired parameter values to the parameter definition arrays underneath the call to the extension file. In both cases you can use references to $this, $user (created user object), $recipient (target), or from globals $wfContLang, $wgSitename. (For advanced techniques and using other globals, see below).
88 -
89 -$wgNewUserNotifSenderSubjParam
90 - The list of evaluated parameters passed to the message subject(MediaWiki:Newusernotifsubj). Default is:
91 - '$wgSitename', // $1 Site Name
92 -
93 -$wgNewUserNotifSenderParam
94 - The list of evaluated parameters passed to the message body(MediaWiki:Newusernotifbody). Defaults are:
95 - '$recipient', // $1 Recipient (of notification message)
96 - '$user->getname()', // $2 User Name
97 - '$wgSitename', // $3 Site Name
98 - '$wgContLang->timeAndDate( wfTimestampNow() )', // $4 Time and date stamp
99 - '$wgContLang->date( wfTimestampNow() )', // $5 Date Stamp
100 - '$wgContLang->time( wfTimestampNow() )', // $6 Time Stamp
101 -
102 -You can then either edit MediaWiki:Newusernotifbody to make use of the new parameters (e.g. add "\n\nThe request came from $7.").
103 -
104 -=== 6.1 Upgrading from 1.5.1 ===
105 -
106 -If you did not customize the passed parameters, this extension works exactly as before and no action need to be taken.
107 -
108 -If you added to or changed the default passed parameters, you will need to correspondingly add to or change the corresponding arrays. You should be able to take the exact same code and add to or replace it in the arrays.
109 -
110 -For example, if you added a 7th parameter (in his case, the email address of the new user), you would just add it (in localsettings.php, below the extension reference) like this:
111 -
112 -<source lang="php">
113 -$wgNewUserNotifSenderParam[] = '$user->getEmail()'; // $7 new user email address
114 -</source>
115 -
116 -The code for the parameter to be passed should be exactly the same (except enclosed in quotes) as it is in your modified wfMsgForContent function call found in private function makeMessage.
117 -
118 -=== 6.2 Examples For Adding Additional Parameters ===
119 -
120 -Here are some commonly used additional parameter you could add to further customize your notification message subject and body:
121 -<source lang="php">
122 -$wgNewUserNotifSenderParam[] = '$user->getEmail()'; // $7 email
123 -$wgNewUserNotifSenderParam[] = 'rawurlencode($wgSitename)'; // $8 Escaped for email message
124 -$wgNewUserNotifSenderParam[] = 'wfGetIP()'; // $9 Submitter's IP Address
125 -</source>
126 -
127 -Of course if you wanted to pass these parameter(s) to the subject message, you would add them to the $wgNewUserNotifSenderSubjParam array instead of the $wgNewUserNotifSenderParam array.
128 -
129 -=== 6.4 Some Technique/Tricks for Adding Additional Parameters ===
130 -
131 -Let's say you wanted to use a global variable or reference other than $this, $user (created user object), $recipient (target), $wfContLang, or $wgSitename.
132 -
133 -You could do so by directly referencing a previously assigned global. Example:
134 -
135 -<source lang="php">
136 -$wgNewUserNotifSenderParam[] = '$GLOBALS["wgUser"]->getEmail()'; // $10 email
137 -</source>
138 -
139 -Note: This isn't the best example, because it would be easier to use the $user object ('$user->getEmail()'), but it gives you an idea how you could reference the global variable (in this case objec) $wgUser directly.
140 -
141 -=== 6.5 Advanced Customization Prior to 1.5.2 ===
142 -
143 -If you want to change the parameters passed in a version prior to 1.5.2, you would need to modify the extension code directly in wfMsgForContent function call found in private function makeMessage of NewUserNotif.class.php.
144 -
145 -== 7. Feedback ==
146 -
147 -Bugs and enhancement requests should be submitted through bugzilla for the MediaWiki Extensions at:
148 -
149 -https://bugzilla.wikimedia.org/enter_bug.cgi?product=MediaWiki%20extensions
150 -
151 -For comments and discussion, see:
152 -
153 -http://www.mediawiki.org/wiki/Extension_talk:New_User_Email_Notification
154 -
 80+All feedback, bug reports, etc. welcome via <robchur@gmail.com>.
\ No newline at end of file
Index: trunk/extensions/NewUserNotif/NewUserNotif.php
@@ -1,6 +1,6 @@
22 <?php
33 if ( ! defined( 'MEDIAWIKI' ) )
4 - die();
 4+ die();
55
66 /**
77 * Extension to provide customisable email notification of new user creation
@@ -13,9 +13,9 @@
1414 */
1515
1616 $wgExtensionCredits['other'][] = array(
17 - 'path' => __FILE__,
 17+ 'path' => __FILE__,
1818 'name' => 'New User Email Notification',
19 - 'version' => '1.5.2',
 19+ 'version' => '1.5.1',
2020 'author' => 'Rob Church',
2121 'url' => 'http://www.mediawiki.org/wiki/Extension:New_User_Email_Notification',
2222 'descriptionmsg' => 'newusernotif-desc',
@@ -40,26 +40,6 @@
4141 * Additional email addresses to send mails to
4242 */
4343 $wgNewUserNotifEmailTargets = array();
44 -/**
45 - * These are the parameters that will be passed into MediaWiki:newusernotifbody
46 - * Can use anthing available as part of $this, $user (created user object), $recipient (target),
47 - * or from globals $wgContLang, $wgSitename
48 - */
49 -$wgNewUserNotifSenderParam = array(
50 - '$recipient', // $1 Recipient (of notification message)
51 - '$user->getname()', // $2 User Name
52 - '$wgSitename', // $3 Site Name
53 - '$wgContLang->timeAndDate( wfTimestampNow() )', // $4 Time and date stamp
54 - '$wgContLang->date( wfTimestampNow() )', // $5 Date Stamp
55 - '$wgContLang->time( wfTimestampNow() )', // $6 Time Stamp
56 -);
57 -/**
58 - * These are the parameters that will be passed into MediaWiki:Newusernotifsubj (for use in the "subject:" line)
59 - * parameters defs have same options as $wgNewUserNotifSenderParam
60 - */
61 -$wgNewUserNotifSenderSubjParam = array(
62 - '$wgSitename', // $1 Site Name
63 -);
6444
6545 /**
6646 * Extension setup

Follow-up revisions

RevisionCommit summaryAuthorDate
r813941.17: MFT r81026, r81116, r81155, r81201, r81204, r81205, r81220, r81235, r81...catrope15:33, 2 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r682571.5.2 Allows you to add to or modify the parameters passed to both the email ...jdpond23:14, 18 June 2010

Status & tagging log