Index: trunk/extensions/NewUserNotif/README |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | NEW USER EMAIL NOTIFICATION EXTENSION |
| 3 | +(http://www.mediawiki.org/wiki/Extension:New_User_Email_Notification) |
3 | 4 | |
4 | 5 | Version 1.5 |
5 | 6 | © 2006-2007 Rob Church |
— | — | @@ -13,8 +14,9 @@ |
14 | 15 | 2. Installation requirements |
15 | 16 | 3. Installing the extension |
16 | 17 | 4. Editing the notification email |
17 | | - 5. Further configuration |
18 | | - 6. Feedback |
| 18 | + 5. Configuration |
| 19 | + 6. Advanced Configuration |
| 20 | + 7. Feedback |
19 | 21 | |
20 | 22 | == 1. Introduction == |
21 | 23 | |
— | — | @@ -51,9 +53,12 @@ |
52 | 54 | $2 is replaced with the username of the new user account; |
53 | 55 | $3 is replaced with the wiki site name from $wgSitename; |
54 | 56 | $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. |
55 | 59 | |
56 | | -== 5. Further configuration == |
57 | 60 | |
| 61 | +== 5. Configuration == |
| 62 | + |
58 | 63 | The behaviour of the extension can be tweaked using three configuration |
59 | 64 | variables. To override the defaults for these, set them in LocalSettings.php |
60 | 65 | underneath the call to the extension file. |
— | — | @@ -73,7 +78,76 @@ |
74 | 79 | $wgNewUserNotifEmailTargets |
75 | 80 | Array containing email addresses to which a notification should also be sent |
76 | 81 | Defaults to no additional addresses |
| 82 | + |
| 83 | +== 6. Advanced Configuration == |
77 | 84 | |
78 | | -== 6. Feedback == |
| 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. |
79 | 86 | |
80 | | -All feedback, bug reports, etc. welcome via <robchur@gmail.com>. |
\ No newline at end of file |
| 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.") or alternatively if you haven't customised the message you can edit NewUserNotif.i18n.php and make the change there to avoid creating a new wiki page (e.g. if your wiki is in English, change the 'en' array.) |
| 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 | + |
Index: trunk/extensions/NewUserNotif/NewUserNotif.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | $wgExtensionCredits['other'][] = array( |
17 | 17 | 'path' => __FILE__, |
18 | 18 | 'name' => 'New User Email Notification', |
19 | | - 'version' => '1.5.1', |
| 19 | + 'version' => '1.5.2', |
20 | 20 | 'author' => 'Rob Church', |
21 | 21 | 'url' => 'http://www.mediawiki.org/wiki/Extension:New_User_Email_Notification', |
22 | 22 | 'descriptionmsg' => 'newusernotif-desc', |
— | — | @@ -40,6 +40,26 @@ |
41 | 41 | * Additional email addresses to send mails to |
42 | 42 | */ |
43 | 43 | $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 $wfContLang, $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 | + ); |
44 | 64 | |
45 | 65 | /** |
46 | 66 | * Extension setup |
Index: trunk/extensions/NewUserNotif/NewUserNotif.class.php |
— | — | @@ -39,13 +39,13 @@ |
40 | 40 | * Send email to external addresses |
41 | 41 | */ |
42 | 42 | private function sendExternalMails() { |
43 | | - global $wgNewUserNotifEmailTargets, $wgSitename; |
| 43 | + global $wgNewUserNotifEmailTargets, $wgNewUserNotifSenderParam, $wgNewUserNotifSenderSubjParam; |
44 | 44 | foreach( $wgNewUserNotifEmailTargets as $target ) { |
45 | 45 | userMailer( |
46 | 46 | new MailAddress( $target ), |
47 | 47 | new MailAddress( $this->sender ), |
48 | | - wfMsgForContent( 'newusernotifsubj', $wgSitename ), |
49 | | - $this->makeMessage( $target, $this->user ) |
| 48 | + $this->makeMessage( $target, $this->user, 'newusernotifsubj', $wgNewUserNotifSenderSubjParam), |
| 49 | + $this->makeMessage( $target, $this->user, 'newusernotifbody', $wgNewUserNotifSenderParam) |
50 | 50 | ); |
51 | 51 | } |
52 | 52 | } |
— | — | @@ -54,13 +54,13 @@ |
55 | 55 | * Send email to users |
56 | 56 | */ |
57 | 57 | private function sendInternalMails() { |
58 | | - global $wgNewUserNotifTargets, $wgSitename; |
| 58 | + global $wgNewUserNotifTargets, $wgNewUserNotifSenderParam, $wgNewUserNotifSenderSubjParam; |
59 | 59 | foreach( $wgNewUserNotifTargets as $userSpec ) { |
60 | 60 | $user = $this->makeUser( $userSpec ); |
61 | 61 | if( $user instanceof User && $user->isEmailConfirmed() ) { |
62 | 62 | $user->sendMail( |
63 | | - wfMsgForContent( 'newusernotifsubj', $wgSitename ), |
64 | | - $this->makeMessage( $user->getName(), $this->user ), |
| 63 | + $this->makeMessage( $user->getName(), $this->user, 'newusernotifsubj', $wgNewUserNotifSenderSubjParam ), |
| 64 | + $this->makeMessage( $user->getName(), $this->user, 'newusernotifbody', $wgNewUserNotifSenderParam ), |
65 | 65 | $this->sender |
66 | 66 | ); |
67 | 67 | } |
— | — | @@ -82,22 +82,18 @@ |
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | | - * Build a notification email |
| 86 | + * Build a notification email message (body and subject) |
87 | 87 | * |
88 | | - * @param string $recipient Name of the recipient |
89 | | - * @param User $user User that was created |
| 88 | + * @param string $recipient Name of the new user notification email recipient |
| 89 | + * @param User $user User (object) created for new user |
| 90 | + * @param string $msgId Localised Message Identifier |
| 91 | + * @param string $parmArr Array of Strings eval'd to pass parameters to message |
| 92 | + * @return string |
90 | 93 | */ |
91 | | - private function makeMessage( $recipient, $user ) { |
92 | | - global $wgSitename, $wgContLang; |
93 | | - return wfMsgForContent( |
94 | | - 'newusernotifbody', |
95 | | - $recipient, |
96 | | - $user->getName(), |
97 | | - $wgSitename, |
98 | | - $wgContLang->timeAndDate( wfTimestampNow() ), |
99 | | - $wgContLang->date( wfTimestampNow() ), |
100 | | - $wgContLang->time( wfTimestampNow() ) |
101 | | - ); |
| 94 | + private function makeMessage( $recipient, $user, $msgId, $parmArr) { |
| 95 | + global $wgSitename,$wgContLang; |
| 96 | + eval( "\$retval = wfMsgForContent('".$msgId."',".implode(",",$parmArr).");" ); |
| 97 | + return ($retval); |
102 | 98 | } |
103 | 99 | |
104 | 100 | /** |