r99848 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99847‎ | r99848 | r99849 >
Date:08:11, 15 October 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
work on reminder mailing functionality
Modified paths:
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/Contest.settings.php (modified) (history)
  • /trunk/extensions/Contest/INSTALL (modified) (history)
  • /trunk/extensions/Contest/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Contest/api/ApiMailContestants.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestReminderJob.php (added) (history)
  • /trunk/extensions/Contest/specials/SpecialContestant.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContestant.php
@@ -246,7 +246,7 @@
247247
248248 $out->addHTML( Html::element( 'p', array(), $message ) );
249249
250 - foreach ( ContestSettings::get( 'votevalues' ) as $value ) {
 250+ foreach ( ContestSettings::get( 'voteValues' ) as $value ) {
251251 $attribs = array(
252252 'type' => 'radio',
253253 'value' => $value,
Index: trunk/extensions/Contest/Contest.settings.php
@@ -28,9 +28,10 @@
2929 */
3030 protected static function getDefaultSettings() {
3131 return array(
32 - 'votevalues' => range( 0, 5 ),
 32+ 'voteValues' => range( 0, 5 ),
3333 'enableTopLink' => true,
3434 'submissionDomains' => array( 'github.com', 'gitorious.org' ),
 35+ 'reminderJobSize' => 50
3536 );
3637 }
3738
Index: trunk/extensions/Contest/Contest.php
@@ -63,6 +63,7 @@
6464 $wgAutoloadClasses['ContestComment'] = dirname( __FILE__ ) . '/includes/ContestComment.php';
6565 $wgAutoloadClasses['ContestContestant'] = dirname( __FILE__ ) . '/includes/ContestContestant.php';
6666 $wgAutoloadClasses['ContestDBObject'] = dirname( __FILE__ ) . '/includes/ContestDBObject.php';
 67+$wgAutoloadClasses['ContestReminderJob'] = dirname( __FILE__ ) . '/includes/ContestReminderJob.php';
6768 $wgAutoloadClasses['ContestUtils'] = dirname( __FILE__ ) . '/includes/ContestUtils.php';
6869 $wgAutoloadClasses['ContestVote'] = dirname( __FILE__ ) . '/includes/ContestVote.php';
6970
Index: trunk/extensions/Contest/INSTALL
@@ -40,3 +40,25 @@
4141 You should NOT modify the settings file, but can have a look at it to get an idea of
4242 how to use the settings, in case the below descriptions do not suffice.
4343
 44+{| class="wikitable sortable"
 45+! Name
 46+! Type
 47+! Default
 48+! Description
 49+|-
 50+| votevalues
 51+| array of integer
 52+| range( 0, 5 )
 53+| Values that can be voted by judges on a participant
 54+|-
 55+| enableTopLink
 56+| boolean
 57+| True
 58+| Enable display of the top link to Special:MyContests
 59+|-
 60+| submissionDomains
 61+| array of string
 62+| array( 'github.com', 'gitorious.org' )
 63+| Domains on which submissions can be placed
 64+|}
 65+
Index: trunk/extensions/Contest/RELEASE-NOTES
@@ -5,8 +5,13 @@
66
77
88 === Version 0.1 ===
9 -2011-xx-xx
 9+2011-10-xx
1010
1111 Initial release with these features:
1212
13 -*
\ No newline at end of file
 13+* Admin interface for managing contests and their challenges.
 14+* Landing and signup pages for each contest.
 15+* Personal contest list and submission interface for each user.
 16+* Summary pages per contest listing contestants, which can be filtered and sorted.
 17+* Judging interface that allows for rating and commenting on each participant.
 18+* All contests, challenges, contestants, comments and votes can be queried and exported via the API.
\ No newline at end of file
Index: trunk/extensions/Contest/includes/ContestReminderJob.php
@@ -0,0 +1,45 @@
 2+<?php
 3+
 4+/**
 5+ * Contest reminder job for email reminders.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file ContestReminderJob.php
 10+ * @ingroup Contest
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class ContestReminderJob extends Job {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @param Title $title
 21+ * @param array $params
 22+ * * contestants, array of ContestContestant, required
 23+ * * contest, Contest, required
 24+ */
 25+ public function __construct( Title $title, array $params ) {
 26+ parent::__construct( 'ContestReminderJob', $title, $params );
 27+ $this->params['emailText'] = ContestUtils::getParsedArticleContent( $this->params['reminder_email'] );
 28+ $this->params['daysLeft'] = $this->params['contest']->getDaysLeft();
 29+ }
 30+
 31+ /**
 32+ * Execute the job.
 33+ *
 34+ * @return bool
 35+ */
 36+ public function run() {
 37+ foreach ( $this->params['contestants'] as /* ContestContestant */ $contestant ) {
 38+ $contestant->sendReminderEmail( $this->params['emailText'], array(
 39+ 'daysLeft' => $this->params['daysLeft'],
 40+ ) );
 41+ }
 42+
 43+ return true;
 44+ }
 45+
 46+}
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -515,11 +515,14 @@
516516 *
517517 * @return Status
518518 */
519 - public function sendReminderEmail() {
 519+ public function sendReminderEmail( $emailText, array $params = array() ) {
520520 global $wgPasswordSender, $wgPasswordSenderName;
521521
522 - $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $this->getContest()->getDaysLeft() );
523 - $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'reminder_email' ) );
 522+ if ( !array_key_exists( 'daysLeft', $params ) ) {
 523+ $params['daysLeft'] = $this->getContest()->getDaysLeft();
 524+ }
 525+
 526+ $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysLeft'] );
524527 $user = $this->getUser();
525528 $sender = $wgPasswordSender;
526529 $senderName = $wgPasswordSenderName;
Index: trunk/extensions/Contest/api/ApiMailContestants.php
@@ -60,34 +60,29 @@
6161 $conditions = array();
6262
6363 if ( count( $contestIds ) > 0 ) {
64 - $conditions[] = array( 'contest_id' => $contestIds );
 64+ $conditions['contest_id'] = $contestIds;
6565 }
6666
6767 if ( count( $challengeIds ) > 0 ) {
68 - $conditions[] = array( 'challenge_id' => $challengeIds );
 68+ $conditions['challenge_id'] = $challengeIds;
6969 }
7070
7171 if ( !is_null( $params['ids'] ) && count( $params['ids'] ) > 0 ) {
72 - $conditions[] = array( 'id' => $params['ids'] );
 72+ $conditions['id'] = $params['ids'];
7373 }
7474
7575 $contestants = ContestContestant::s()->select( 'email', $conditions );
7676
7777 if ( $contestants !== false && count( $contestants ) > 0 ) {
78 - $recipients = array();
 78+ $setSize = ContestSettings::get( 'reminderJobSize' );
 79+ $limit = count( $contestants ) - $setSize;
7980
80 - foreach ( $contestants as /* ContestContestant */ $contestant ) {
81 - $recipients[] = new MailAddress( $contestant->getField( 'email' ) );
 81+ for ( $i = 0; $i <= $limit; $i += $setSize ) {
 82+ $this->createReminderJob( array_splice( $contestants, $i, $setSize ) );
8283 }
83 -
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 - );
8984 }
9085 else {
91 - // TODO: error
 86+ $everythingOk = false;
9287 }
9388
9489 $this->getResult()->addValue(
@@ -95,58 +90,42 @@
9691 'success',
9792 $everythingOk
9893 );
 94+
 95+ if ( $everythingOk ) {
 96+ $this->getResult()->addValue(
 97+ null,
 98+ 'contestantcount',
 99+ count( $contestants )
 100+ );
 101+ }
99102 }
100103
101 - /**
102 - * Send a reminder email.
103 - *
104 - * @since 0.1
105 - *
106 - * @param string $emailText
107 - * @param array $recipients
108 - * @param array $params
109 - *
110 - * @return Status
111 - */
112 - public function sendReminderEmail( $emailText, array /* of MailAddress */ $recipients, array $params ) {
113 - global $wgPasswordSender, $wgPasswordSenderName;
114 -
115 - $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysleft'] );
116 - $sender = $wgPasswordSender;
117 - $senderName = $wgPasswordSenderName;
118 -
119 - wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$recipients, &$sender, &$senderName ) );
120 -
121 - return UserMailer::send(
122 - $recipients,
123 - new MailAddress( $sender, $senderName ),
124 - $title,
125 - $emailText,
126 - null,
127 - 'text/html; charset=ISO-8859-1'
 104+ protected function createReminderJob( array /* of ContestContestant */ $contestants ) {
 105+ $job = new ContestReminderJob(
 106+ Title::newMainPage(), // WTF does this require a title for??
 107+ array(
 108+ 'contest' => $contestants[0]->getContest(),
 109+ 'contestants' => $contestants
 110+ )
128111 );
 112+ $job->insert();
129113 }
130 - /*
 114+
131115 public function needsToken() {
132116 return true;
133117 }
134118
135 - public function getTokenSalt() {
136 - $params = $this->extractRequestParams();
137 - return 'deletecontest' . implode( '|', $params['ids'] ); // TODO
138 - }
139 -
140119 public function mustBePosted() {
141120 return true;
142121 }
143 - */
 122+
144123 public function getAllowedParams() {
145124 return array(
146 - 'page' => array(
147 - ApiBase::PARAM_TYPE => 'string',
148 - ApiBase::PARAM_REQUIRED => true,
149 - ApiBase::PARAM_ISMULTI => false,
150 - ),
 125+// 'page' => array(
 126+// ApiBase::PARAM_TYPE => 'string',
 127+// ApiBase::PARAM_REQUIRED => true,
 128+// ApiBase::PARAM_ISMULTI => false,
 129+// ),
151130 'ids' => array(
152131 ApiBase::PARAM_TYPE => 'integer',
153132 ApiBase::PARAM_REQUIRED => false,
@@ -158,7 +137,7 @@
159138 ApiBase::PARAM_ISMULTI => true,
160139 ),
161140 'contestnames' => array(
162 - ApiBase::PARAM_TYPE => 'integer',
 141+ ApiBase::PARAM_TYPE => 'string',
163142 ApiBase::PARAM_REQUIRED => false,
164143 ApiBase::PARAM_ISMULTI => true,
165144 ),
@@ -168,7 +147,7 @@
169148 ApiBase::PARAM_ISMULTI => true,
170149 ),
171150 'challengetitles' => array(
172 - ApiBase::PARAM_TYPE => 'integer',
 151+ ApiBase::PARAM_TYPE => 'string',
173152 ApiBase::PARAM_REQUIRED => false,
174153 ApiBase::PARAM_ISMULTI => true,
175154 ),
@@ -178,7 +157,7 @@
179158
180159 public function getParamDescription() {
181160 return array(
182 - 'page' => 'Name of the page from which to pull content for the email body',
 161+// 'page' => 'Name of the page from which to pull content for the email body',
183162 'ids' => 'The IDs of the contestants to mail',
184163 'contestids' => 'The IDs of the contests where of the contestants should be mailed',
185164 'contestnames' => 'The names of the contests where of the contestants should be mailed',

Status & tagging log