Index: trunk/extensions/ContactPage/SpecialContact.php |
— | — | @@ -15,9 +15,6 @@ |
16 | 16 | die( 1 ); |
17 | 17 | } |
18 | 18 | |
19 | | -global $IP; #needed when called from the autoloader |
20 | | -require_once("$IP/includes/UserMailer.php"); |
21 | | - |
22 | 19 | /** |
23 | 20 | * Provides the contact form |
24 | 21 | * @ingroup SpecialPage |
— | — | @@ -271,16 +268,17 @@ |
272 | 269 | |
273 | 270 | wfDebug( __METHOD__ . ": start\n" ); |
274 | 271 | |
275 | | - $to = new MailAddress( $this->target ); |
276 | | - $replyto = NULL; |
| 272 | + $targetAddress = new MailAddress( $this->target ); |
| 273 | + $replyto = null; |
| 274 | + $contactSender = new MailAddress( $csender, $cname ); |
277 | 275 | |
278 | 276 | if ( !$this->fromaddress ) { |
279 | | - $from = new MailAddress( $csender, $cname ); |
280 | | - } else if ( $wgUserEmailUseReplyTo ) { |
281 | | - $from = new MailAddress( $csender, $cname ); |
282 | | - $replyto = new MailAddress( $this->fromaddress, $this->fromname ); |
| 277 | + $submitterAddress = $contactSender; |
283 | 278 | } else { |
284 | | - $from = new MailAddress( $this->fromaddress, $this->fromname ); |
| 279 | + $submitterAddress = new MailAddress( $this->fromaddress, $this->fromname ); |
| 280 | + if ( $wgUserEmailUseReplyTo ) { |
| 281 | + $replyto = $submitterAddress; |
| 282 | + } |
285 | 283 | } |
286 | 284 | |
287 | 285 | $subject = trim( $this->subject ); |
— | — | @@ -295,48 +293,49 @@ |
296 | 294 | $subject = wfMsgForContent( 'contactpage-subject-and-sender', $subject, $this->fromaddress ); |
297 | 295 | } |
298 | 296 | |
299 | | - if( wfRunHooks( 'ContactForm', array( &$to, &$replyto, &$subject, &$this->text ) ) ) { |
| 297 | + if( !wfRunHooks( 'ContactForm', array( &$targetAddress, &$replyto, &$subject, &$this->text ) ) ) { |
| 298 | + wfDebug( __METHOD__ . ": aborted by hook\n" ); |
| 299 | + return; |
| 300 | + } |
300 | 301 | |
301 | | - wfDebug( __METHOD__ . ": sending mail from ".$from->toString()." to ".$to->toString()." replyto ".( $replyto == null ? '-/-' : $replyto->toString() )."\n" ); |
| 302 | + wfDebug( __METHOD__ . ": sending mail from ".$submitterAddress->toString(). |
| 303 | + " to ".$targetAddress->toString(). |
| 304 | + " replyto ".( $replyto == null ? '-/-' : $replyto->toString() )."\n" ); |
302 | 305 | |
303 | | - #HACK: in MW 1.9, replyto must be a string, in MW 1.10 it must be an object! |
304 | | - $ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] ); |
305 | | - $replyaddr = $replyto == null |
306 | | - ? NULL : version_compare( $ver, '1.10', '<' ) |
307 | | - ? $replyto->toString() : $replyto; |
| 306 | + $mailResult = UserMailer::send( $targetAddress, $submitterAddress, $subject, $this->text, $replyto ); |
308 | 307 | |
309 | | - $mailResult = userMailer( $to, $from, $subject, $this->text, $replyaddr ); |
| 308 | + if( WikiError::isError( $mailResult ) ) { |
| 309 | + $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage(); |
| 310 | + wfDebug( __METHOD__ . ": got error from UserMailer: " . $mailResult->getMessage() . "\n" ); |
| 311 | + return; |
| 312 | + } |
310 | 313 | |
311 | | - if( WikiError::isError( $mailResult ) ) { |
312 | | - $wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage(); |
313 | | - } else { |
314 | | - // if the user requested a copy of this mail, do this now, |
315 | | - // unless they are emailing themselves, in which case one copy of the message is sufficient. |
316 | | - if( $this->cc_me && $replyto ) { |
317 | | - $cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject); |
318 | | - if( wfRunHooks( 'ContactForm', array( &$from, &$replyto, &$cc_subject, &$this->text ) ) ) { |
319 | | - wfDebug( __METHOD__ . ": sending cc mail from ".$from->toString()." to ".$replyto->toString()."\n" ); |
320 | | - $ccResult = userMailer( $replyto, $from, $cc_subject, $this->text ); |
321 | | - if( WikiError::isError( $ccResult ) ) { |
322 | | - // At this stage, the user's CC mail has failed, but their |
323 | | - // original mail has succeeded. It's unlikely, but still, what to do? |
324 | | - // We can either show them an error, or we can say everything was fine, |
325 | | - // or we can say we sort of failed AND sort of succeeded. Of these options, |
326 | | - // simply saying there was an error is probably best. |
327 | | - $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult ); |
328 | | - return; |
329 | | - } |
330 | | - } |
| 314 | + // if the user requested a copy of this mail, do this now, |
| 315 | + // unless they are emailing themselves, in which case one copy of the message is sufficient. |
| 316 | + if( $this->cc_me && $this->fromaddress ) { |
| 317 | + $cc_subject = wfMsg('emailccsubject', $this->target->getName(), $subject); |
| 318 | + if( wfRunHooks( 'ContactForm', array( &$submitterAddress, &$contactSender, &$cc_subject, &$this->text ) ) ) { |
| 319 | + wfDebug( __METHOD__ . ": sending cc mail from ".$contactSender->toString(). |
| 320 | + " to ".$submitterAddress->toString()."\n" ); |
| 321 | + $ccResult = UserMailer::send( $submitterAddress, $contactSender, $cc_subject, $this->text ); |
| 322 | + if( WikiError::isError( $ccResult ) ) { |
| 323 | + // At this stage, the user's CC mail has failed, but their |
| 324 | + // original mail has succeeded. It's unlikely, but still, what to do? |
| 325 | + // We can either show them an error, or we can say everything was fine, |
| 326 | + // or we can say we sort of failed AND sort of succeeded. Of these options, |
| 327 | + // simply saying there was an error is probably best. |
| 328 | + $wgOut->addWikiText( wfMsg( 'usermailererror' ) . $ccResult ); |
| 329 | + return; |
331 | 330 | } |
332 | | - |
333 | | - wfDebug( __METHOD__ . ": success\n" ); |
334 | | - |
335 | | - $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
336 | | - $wgOut->redirect( $titleObj->getFullURL( "action=success" ) ); |
337 | | - wfRunHooks( 'ContactFromComplete', array( $to, $replyto, $subject, $this->text ) ); |
338 | 331 | } |
339 | 332 | } |
340 | 333 | |
| 334 | + wfDebug( __METHOD__ . ": success\n" ); |
| 335 | + |
| 336 | + $titleObj = SpecialPage::getTitleFor( 'Contact' ); |
| 337 | + $wgOut->redirect( $titleObj->getFullURL( "action=success" ) ); |
| 338 | + wfRunHooks( 'ContactFromComplete', array( $targetAddress, $replyto, $subject, $this->text ) ); |
| 339 | + |
341 | 340 | wfDebug( __METHOD__ . ": end\n" ); |
342 | 341 | } |
343 | 342 | |
— | — | @@ -348,4 +347,4 @@ |
349 | 348 | |
350 | 349 | $wgOut->returnToMain( false ); |
351 | 350 | } |
352 | | -} |
\ No newline at end of file |
| 351 | +} |