Index: trunk/extensions/Contest/includes/ContestContestant.php |
— | — | @@ -445,16 +445,72 @@ |
446 | 446 | * @see ContestDBObject::insertIntoDB() |
447 | 447 | */ |
448 | 448 | protected function insertIntoDB() { |
| 449 | + wfRunHooks( 'ContestBeforeContestantInsert', array( &$this ) ); |
| 450 | + |
449 | 451 | $success = parent::insertIntoDB(); |
450 | 452 | |
451 | 453 | if ( $success ) { |
452 | 454 | $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 ); |
| 455 | + $this->sendSignupEmail(); |
| 456 | + |
| 457 | + wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) ); |
453 | 458 | } |
454 | 459 | |
455 | 460 | return $success; |
456 | 461 | } |
457 | 462 | |
458 | 463 | /** |
| 464 | + * Send the ignup email. |
| 465 | + * TODO: use actual config |
| 466 | + * TODO: test code on machine that is properly configured for email sending |
| 467 | + * |
| 468 | + * @since 0.1 |
| 469 | + * |
| 470 | + * @return Status |
| 471 | + */ |
| 472 | + public function sendSignupEmail() { |
| 473 | + global $wgPasswordSender, $wgPasswordSenderName; |
| 474 | + |
| 475 | + $title = 'Thanks for joining the challenge!'; |
| 476 | + $emailText = $this->getArticleContent( 'Email' ); |
| 477 | + $user = $this->getUser(); |
| 478 | + $sender = $wgPasswordSender; |
| 479 | + $senderName = $wgPasswordSenderName; |
| 480 | + |
| 481 | + wfRunHooks( 'ContestBeforeSignupEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) ); |
| 482 | + |
| 483 | + return UserMailer::send( |
| 484 | + new MailAddress( $user ), |
| 485 | + new MailAddress( $sender, $senderName ), |
| 486 | + $title, |
| 487 | + $emailText, |
| 488 | + null, |
| 489 | + 'text/html; charset=ISO-8859-1' |
| 490 | + ); |
| 491 | + } |
| 492 | + |
| 493 | + /** |
| 494 | + * Gets the content of the article with the provided page name, |
| 495 | + * or an empty string when there is no such article. |
| 496 | + * |
| 497 | + * @since 0.1 |
| 498 | + * |
| 499 | + * @param string $pageName |
| 500 | + * |
| 501 | + * @return string |
| 502 | + */ |
| 503 | + protected function getArticleContent( $pageName ) { |
| 504 | + $title = Title::newFromText( $pageName ); |
| 505 | + |
| 506 | + if ( is_null( $title ) ) { |
| 507 | + return ''; |
| 508 | + } |
| 509 | + |
| 510 | + $article = new Article( $title, 0 ); |
| 511 | + return $article->getContent(); |
| 512 | + } |
| 513 | + |
| 514 | + /** |
459 | 515 | * Update the vote count and avarage vote fields. |
460 | 516 | * This does not write the changes to the database, |
461 | 517 | * if this is required, call writeToDB. |