r99408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99407‎ | r99408 | r99409 >
Date:16:41, 10 October 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
some initial work on sending emails
Modified paths:
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -445,16 +445,72 @@
446446 * @see ContestDBObject::insertIntoDB()
447447 */
448448 protected function insertIntoDB() {
 449+ wfRunHooks( 'ContestBeforeContestantInsert', array( &$this ) );
 450+
449451 $success = parent::insertIntoDB();
450452
451453 if ( $success ) {
452454 $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
 455+ $this->sendSignupEmail();
 456+
 457+ wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) );
453458 }
454459
455460 return $success;
456461 }
457462
458463 /**
 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+ /**
459515 * Update the vote count and avarage vote fields.
460516 * This does not write the changes to the database,
461517 * if this is required, call writeToDB.

Follow-up revisions

RevisionCommit summaryAuthorDate
r99410follow up to r99408jeroendedauw17:36, 10 October 2011
r99493Follow up to r99408;jeroendedauw16:45, 11 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   16:07, 11 October 2011

Typo ignup email. Are you sure you want to use Article->getContent() with all those side effects instead of getting the text using Revision class?

Has hardcoded text, hardcoded non utf-8 encoding?

#Comment by Jeroen De Dauw (talk | contribs)   16:47, 11 October 2011

Typo fixed in some later revision. I changed the getContent call to fetchContent, which does not have a side effects warning in the docs. Is that ok, or should I use the Revision thing? (if so, please specify what method)

Hardcoded text replaced in some later revision (see TODO :p).

#Comment by Nikerabbit (talk | contribs)   17:27, 11 October 2011

It seems quite ok, except the following code:

                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
                $t = $this->getTitle()->getPrefixedText();
                $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
                $this->mContent = wfMsgNoTrans( 'missing-article', $t, $d ) ;

It also runs some hooks over the content, but that might be a good thing.

Status & tagging log