Index: trunk/extensions/EmailCapture/EmailCapture.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | $wgEmailCaptureSendAutoResponse = true; |
20 | 20 | $wgEmailCaptureAutoResponse = array( |
21 | 21 | 'from' => $wgPasswordSender, |
| 22 | + 'from-name' => $wgSitename, |
22 | 23 | 'subject-msg' => 'emailcapture-response-subject', |
23 | 24 | 'body-msg' => 'emailcapture-response-body', |
24 | 25 | 'reply-to' => null, |
Index: trunk/extensions/EmailCapture/api/ApiEmailCapture.php |
— | — | @@ -9,46 +9,49 @@ |
10 | 10 | $params = $this->extractRequestParams(); |
11 | 11 | |
12 | 12 | // Validation |
13 | | - if ( !User:isValidEmailAddr( $params['email'] ) ) { |
| 13 | + if ( !User::isValidEmailAddr( $params['email'] ) ) { |
14 | 14 | $this->dieUsage( 'The email address does not appear to be valid', 'invalidemail' ); |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Verification code |
18 | | - $code = md5( 'EmailCapture' . time() . $params['email'] . $params['info'] ) |
| 18 | + $code = md5( 'EmailCapture' . time() . $params['email'] . $params['info'] ); |
19 | 19 | |
20 | 20 | // Insert |
21 | 21 | $dbw = wfGetDB( DB_MASTER ); |
22 | | - $affectedRows = $dbw->insert( |
| 22 | + $dbw->insert( |
23 | 23 | 'email_capture', |
24 | 24 | array( |
25 | 25 | 'ec_email' => $params['email'], |
26 | | - 'ec_info' => isset( $params['info'] ) ? $params['email'] : null, |
| 26 | + 'ec_info' => isset( $params['info'] ) ? $params['info'] : null, |
27 | 27 | 'ec_code' => $code, |
28 | | - ) |
| 28 | + ), |
| 29 | + __METHOD__, |
| 30 | + array( 'IGNORE' ) |
29 | 31 | ); |
30 | 32 | |
31 | | - // Send auto-response |
32 | | - global $wgUser, $wgEmailCaptureSendAutoResponse, $wgEmailCaptureAutoResponse; |
33 | | - $link = $wgUser->getSkin()->link( 'Special:EmailCapture' ); |
34 | | - $fullLink = $wgUser->getSkin()->link( |
35 | | - 'Special:EmailCapture', null, array(), array( 'verify' => $code ) |
36 | | - ); |
37 | | - if ( $wgEmailCaptureSendAutoResponse ) { |
38 | | - UserMailer::send( |
39 | | - $params['email'], |
40 | | - $wgEmailCaptureAutoResponse['from'], |
41 | | - wfMsg( $wgEmailCaptureAutoResponse['subject-msg'] ), |
42 | | - wfMsg( $wgEmailCaptureAutoResponse['body-msg'], $link, $code, $fullLink ), |
43 | | - $wgEmailCaptureAutoResponse['reply-to'], |
44 | | - $wgEmailCaptureAutoResponse['content-type'], |
| 33 | + if ( $dbw->affectedRows() ) { |
| 34 | + // Send auto-response |
| 35 | + global $wgUser, $wgEmailCaptureSendAutoResponse, $wgEmailCaptureAutoResponse; |
| 36 | + $link = $wgUser->getSkin()->link( 'Special:EmailCapture' ); |
| 37 | + $fullLink = $wgUser->getSkin()->link( |
| 38 | + 'Special:EmailCapture', null, array(), array( 'verify' => $code ) |
45 | 39 | ); |
46 | | - } |
47 | | - |
48 | | - // Result |
49 | | - if ( $affectedRows === 0 ) { |
| 40 | + if ( $wgEmailCaptureSendAutoResponse ) { |
| 41 | + UserMailer::send( |
| 42 | + new MailAddress( $params['email'] ), |
| 43 | + new MailAddress( |
| 44 | + $wgEmailCaptureAutoResponse['from'], |
| 45 | + $wgEmailCaptureAutoResponse['from-name'] |
| 46 | + ), |
| 47 | + wfMsg( $wgEmailCaptureAutoResponse['subject-msg'] ), |
| 48 | + wfMsg( $wgEmailCaptureAutoResponse['body-msg'], $link, $code, $fullLink ), |
| 49 | + $wgEmailCaptureAutoResponse['reply-to'], |
| 50 | + $wgEmailCaptureAutoResponse['content-type'] |
| 51 | + ); |
| 52 | + } |
| 53 | + $r = array( 'result' => 'Success' ); |
| 54 | + } else { |
50 | 55 | $r = array( 'result' => 'Failure', 'message' => 'Duplicate email address' ); |
51 | | - } else { |
52 | | - $r = array( 'result' => 'Success' ); |
53 | 56 | } |
54 | 57 | $this->getResult()->addValue( null, $this->getModuleName(), $r ); |
55 | 58 | } |