r85815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85814‎ | r85815 | r85816 >
Date:18:52, 11 April 2011
Author:tparscal
Status:resolved
Tags:
Comment:
Added from-name for outgoing emails. Fixed API syntax errors and use of affectedRows (was never tested before)
Modified paths:
  • /trunk/extensions/EmailCapture/EmailCapture.php (modified) (history)
  • /trunk/extensions/EmailCapture/api/ApiEmailCapture.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EmailCapture/EmailCapture.php
@@ -18,6 +18,7 @@
1919 $wgEmailCaptureSendAutoResponse = true;
2020 $wgEmailCaptureAutoResponse = array(
2121 'from' => $wgPasswordSender,
 22+ 'from-name' => $wgSitename,
2223 'subject-msg' => 'emailcapture-response-subject',
2324 'body-msg' => 'emailcapture-response-body',
2425 'reply-to' => null,
Index: trunk/extensions/EmailCapture/api/ApiEmailCapture.php
@@ -9,46 +9,49 @@
1010 $params = $this->extractRequestParams();
1111
1212 // Validation
13 - if ( !User:isValidEmailAddr( $params['email'] ) ) {
 13+ if ( !User::isValidEmailAddr( $params['email'] ) ) {
1414 $this->dieUsage( 'The email address does not appear to be valid', 'invalidemail' );
1515 }
1616
1717 // Verification code
18 - $code = md5( 'EmailCapture' . time() . $params['email'] . $params['info'] )
 18+ $code = md5( 'EmailCapture' . time() . $params['email'] . $params['info'] );
1919
2020 // Insert
2121 $dbw = wfGetDB( DB_MASTER );
22 - $affectedRows = $dbw->insert(
 22+ $dbw->insert(
2323 'email_capture',
2424 array(
2525 'ec_email' => $params['email'],
26 - 'ec_info' => isset( $params['info'] ) ? $params['email'] : null,
 26+ 'ec_info' => isset( $params['info'] ) ? $params['info'] : null,
2727 'ec_code' => $code,
28 - )
 28+ ),
 29+ __METHOD__,
 30+ array( 'IGNORE' )
2931 );
3032
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 )
4539 );
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 {
5055 $r = array( 'result' => 'Failure', 'message' => 'Duplicate email address' );
51 - } else {
52 - $r = array( 'result' => 'Success' );
5356 }
5457 $this->getResult()->addValue( null, $this->getModuleName(), $r );
5558 }

Status & tagging log