r99701 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99700‎ | r99701 | r99702 >
Date:16:58, 13 October 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
Follow up to r99685;
Modified paths:
  • /trunk/extensions/Contest/api/ApiMailContestants.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/api/ApiMailContestants.php
@@ -18,6 +18,7 @@
1919 parent::__construct( $main, $action );
2020 }
2121
 22+ // TODO
2223 public function execute() {
2324 global $wgUser;
2425
@@ -29,19 +30,35 @@
3031
3132 $everythingOk = true;
3233
33 - $contestIds = array();
34 - $challengeIds = array();
 34+ $contestIds = is_null( $params['contestids'] ) ? array() : $params['contestids'];
 35+ $challengeIds = is_null( $params['challengeids'] ) ? array() : $params['challengeids'];
3536
36 - if ( !is_null( 'challengetitles' ) ) {
 37+ if ( !is_null( $params['challengetitles'] ) ) {
 38+ $challenges = ContestChallenge::s()->select( 'id', array( 'title' => $params['challengetitles'] ) );
3739
 40+ if ( $challenges === false ) {
 41+ // TODO: error
 42+ }
 43+
 44+ foreach ( $challenges as /* ContestChallenge */ $challenge ) {
 45+ $challengeIds[] = $challenge->getId();
 46+ }
3847 }
3948
40 - if ( !is_null( 'contestnames' ) ) {
 49+ if ( !is_null( $params['contestnames'] ) ) {
 50+ $contests = Contest::s()->select( 'id', array( 'name' => $params['contestnames'] ) );
4151
 52+ if ( $contests === false ) {
 53+ // TODO: error
 54+ }
 55+
 56+ foreach ( $contests as /* Contest */ $contest ) {
 57+ $contestIds[] = $contest->getId();
 58+ }
4259 }
4360
4461 $conditions = array();
45 - // TODO
 62+
4663 if ( count( $contestIds ) > 0 ) {
4764 $conditions[] = array( 'contest_id' => $contestIds );
4865 }
@@ -60,11 +77,18 @@
6178 $recipients = array();
6279
6380 foreach ( $contestants as /* ContestContestant */ $contestant ) {
64 - $recipients[] = $contestant->getField( 'email' );
 81+ $recipients[] = new MailAddress( $contestant->getField( 'email' ) );
6582 }
6683
67 - $everythingOk = $this->sendReminderEmail( $recipients );
 84+ $everythingOk = $this->sendReminderEmail(
 85+ ContestUtils::getParsedArticleContent( $params['page'] ), // TODO: have some magic here for params such as daysleft
 86+ $recipients,
 87+ array( 'daysleft' => $this->getContest()->getDaysLeft() )
 88+ );
6889 }
 90+ else {
 91+ // TODO: error
 92+ }
6993
7094 $this->getResult()->addValue(
7195 null,
@@ -80,21 +104,22 @@
81105 *
82106 * @since 0.1
83107 *
 108+ * @param string $emailText
 109+ * @param array $recipients
 110+ *
84111 * @return Status
85112 */
86 - public function sendReminderEmail( array $recipients ) {
 113+ public function sendReminderEmail( $emailText, array /* of MailAddress */ $recipients, array $params ) {
87114 global $wgPasswordSender, $wgPasswordSenderName;
88115
89 - $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $this->getContest()->getDaysLeft() );
90 - $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'reminder_email' ) );
91 - $user = $this->getUser();
 116+ $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysleft'] );
92117 $sender = $wgPasswordSender;
93118 $senderName = $wgPasswordSenderName;
94119
95 - wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) );
 120+ wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$recipients, &$sender, &$senderName ) );
96121
97122 return UserMailer::send(
98 - new MailAddress( $user ),
 123+ $recipients,
99124 new MailAddress( $sender, $senderName ),
100125 $title,
101126 $emailText,
@@ -118,6 +143,11 @@
119144 */
120145 public function getAllowedParams() {
121146 return array(
 147+ 'page' => array(
 148+ ApiBase::PARAM_TYPE => 'string',
 149+ ApiBase::PARAM_REQUIRED => true,
 150+ ApiBase::PARAM_ISMULTI => false,
 151+ ),
122152 'ids' => array(
123153 ApiBase::PARAM_TYPE => 'integer',
124154 ApiBase::PARAM_REQUIRED => false,
@@ -149,14 +179,20 @@
150180
151181 public function getParamDescription() {
152182 return array(
 183+ 'page' => 'Name of the page from which to pull content for the email body',
153184 'ids' => 'The IDs of the contestants to mail',
 185+ 'contestids' => 'The IDs of the contests where of the contestants should be mailed',
 186+ 'contestnames' => 'The names of the contests where of the contestants should be mailed',
 187+ 'challengeids' => 'The IDs of the challenges where of the contestants should be mailed',
 188+ 'challengetitles' => 'The titles of the challenges where of the contestants should be mailed',
154189 'token' => 'Edit token',
155190 );
156191 }
157192
158193 public function getDescription() {
159194 return array(
160 - 'API module for mailing contestants. The provided conditions such as contest ids and challenge titles will be joined with AND.'
 195+ 'API module for mailing contestants. Selection criteria will be joined with AND,
 196+ except for the challange ids/titles and contest ids/names pairs, which will be joined wit OR.'
161197 );
162198 }
163199

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99685some initial work on contestant mailing functionalityjeroendedauw15:47, 13 October 2011

Status & tagging log