r100274 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100273‎ | r100274 | r100275 >
Date:20:46, 19 October 2011
Author:jeroendedauw
Status:ok (Comments)
Tags:
Comment:
created basic reminder email functionality
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiMailContestants.php (modified) (history)
  • /trunk/extensions/Contest/resources/contest.special.contest.js (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -154,10 +154,17 @@
155155 'contest-contest-reminder-page' => 'The content for the reminder e-mail comes from [[$1|this page]].',
156156 'contest-contest-send-reminder' => 'Send reminder',
157157
 158+ // Special:Contest, reminder email JS
158159 'contest-contest-reminder-preview' => 'Preview of the reminder e-mail:',
159160 'contest-contest-reminder-title' => 'Reminder e-mail',
160161 'contest-contest-reminder-send' => 'Send reminder',
161162 'contest-contest-reminder-cancel' => 'Cancel',
 163+ 'contest-contest-reminder-sending' => 'Sending...',
 164+ // We really want // {{PLURAL:$1|contestant|contestants}} here, but the JS i18n shizzle does not support it yet :/
 165+ 'contest-contest-reminder-success' => 'Successfully send the reminder email to $1 contestants',
 166+ 'contest-contest-reminder-close' => 'Close',
 167+ 'contest-contest-reminder-retry' => 'Retry sending',
 168+ 'contest-contest-reminder-failed' => 'Could not send the reminder emails.',
162169
163170 // Contestant pager
164171 'contest-contestant-id' => 'ID',
@@ -258,14 +265,10 @@
259266 'contest-contest-name' => 'Table row header',
260267 'contest-contest-status' => 'Table row header',
261268 'contest-contest-submissioncount' => 'Table row header',
 269+ 'contest-contest-end' => 'Table row header',
262270 'contest-contest-contestants' => 'Page section header',
263 - 'contest-contest-reminder-mail' => 'Reminder email',
264 - 'contest-contest-reminder-page' => 'Text explaining the email content is pulled from a page, $1 is the page name.',
265 - 'contest-contest-send-reminder' => 'Send reminder button text',
266 - 'contest-contest-reminder-preview' => 'Text indicating that the following content is the preview for the reminder email.',
267 - 'contest-contest-reminder-title' => 'Dialog title',
268 - 'contest-contest-reminder-send' => 'Send button text',
269 - 'contest-contest-reminder-cancel' => 'Cancel button text',
 271+ 'contest-contest-days-ago' => '$1 is a date, $2 is an integer, the amount of days',
 272+ 'contest-contest-days-left' => '$1 is a date, $2 is an integer, the amount of days',
270273 'contest-contestant-id' => 'Table column header',
271274 'contest-contestant-volunteer' => 'Table column header',
272275 'contest-contestant-wmf' => 'Table column header',
@@ -293,6 +296,22 @@
294297 'contest-contestant-permalink' => 'Hover-text for comment permalinks',
295298 'contest-email-signup-title' => 'Title for signup e-mails',
296299 'contest-email-reminder-title' => 'Title for reminder e-mails',
 300+
 301+ // Special:Contest, reminder email
 302+ 'contest-contest-reminder-mail' => 'Reminder email',
 303+ 'contest-contest-reminder-page' => 'Text explaining the email content is pulled from a page, $1 is the page name.',
 304+ 'contest-contest-send-reminder' => 'Send reminder button text',
 305+ 'contest-contest-reminder-preview' => 'Text indicating that the following content is the preview for the reminder email.',
 306+ 'contest-contest-reminder-title' => 'Dialog title',
 307+ 'contest-contest-reminder-send' => 'Send button text',
 308+ 'contest-contest-reminder-cancel' => 'Cancel button text',
 309+ 'contest-contest-reminder-sending' => 'Send button text after clicking it',
 310+ 'contest-contest-reminder-success' => 'Success message, $1 is the amount of contesnats. No PLURAL for now, just assume there are multiple untill MWs JS supports plural.',
 311+ 'contest-contest-reminder-close' => 'Close button text',
 312+ 'contest-contest-reminder-retry' => 'Retry button text',
 313+ 'contest-contest-reminder-failed' => 'Failiure message, displayed in an alert box',
 314+
 315+ // Special:MyContests
297316 'contest-mycontests-toplink' => 'Text for link in the user menu (i.e. where watchlist and preferences are linked)',
298317 'contest-mycontests-no-contests' => 'Message indicating there are no contests for the user, displayed instead of a list.',
299318 'contest-mycontests-active-header' => 'Page header (h2)',
Index: trunk/extensions/Contest/specials/SpecialContest.php
@@ -140,6 +140,8 @@
141141 'button',
142142 array(
143143 'id' => 'send-reminder',
 144+ 'data-token' => $this->getUser()->editToken(),
 145+ 'data-contest-id' => $contest->getId()
144146 ),
145147 wfMsg( 'contest-contest-send-reminder' )
146148 ) );
Index: trunk/extensions/Contest/Contest.php
@@ -163,7 +163,12 @@
164164 'contest-contest-reminder-title',
165165 'contest-contest-reminder-cancel',
166166 'contest-contest-reminder-send',
167 - 'contest-contest-reminder-preview'
 167+ 'contest-contest-reminder-preview',
 168+ 'contest-contest-reminder-sending',
 169+ 'contest-contest-reminder-success',
 170+ 'contest-contest-reminder-close',
 171+ 'contest-contest-reminder-retry',
 172+ 'contest-contest-reminder-failed',
168173 ),
169174 'dependencies' => array(
170175 'jquery.ui.button', 'jquery.ui.dialog',
Index: trunk/extensions/Contest/api/ApiMailContestants.php
@@ -18,7 +18,6 @@
1919 parent::__construct( $main, $action );
2020 }
2121
22 - // TODO
2322 public function execute() {
2423 global $wgUser;
2524
@@ -71,11 +70,11 @@
7271 $conditions['id'] = $params['ids'];
7372 }
7473
75 - $contestants = ContestContestant::s()->select( 'email', $conditions );
 74+ $contestants = ContestContestant::s()->select( array( 'contest_id', 'email' ), $conditions );
7675
7776 if ( $contestants !== false && count( $contestants ) > 0 ) {
7877 $setSize = ContestSettings::get( 'reminderJobSize' );
79 - $limit = count( $contestants ) - $setSize;
 78+ $limit = count( $contestants );
8079
8180 for ( $i = 0; $i <= $limit; $i += $setSize ) {
8281 $this->createReminderJob( array_splice( $contestants, $i, $setSize ) );
Index: trunk/extensions/Contest/resources/contest.special.contest.js
@@ -10,22 +10,59 @@
1111
1212 var _this = this;
1313
14 - this.sendReminder = function() {
 14+ this.sendReminder = function( callback ) {
 15+ var requestArgs = {
 16+ 'action': 'mailcontestants',
 17+ 'format': 'json',
 18+ 'token': $( '#send-reminder' ).attr( 'data-token' ),
 19+ 'contestids': $( '#send-reminder' ).attr( 'data-contest-id' )
 20+ };
1521
 22+ $.post(
 23+ wgScriptPath + '/api.php',
 24+ requestArgs,
 25+ function( data ) {
 26+ callback( data );
 27+ }
 28+ );
1629 };
1730
1831 this.showReminderDialog = function() {
 32+ var $dialog = null;
 33+
1934 $dialog = $( '<div />' ).html( '' ).dialog( {
2035 'title': mw.msg( 'contest-contest-reminder-title' ),
2136 'buttons': [
2237 {
2338 'text': mw.msg( 'contest-contest-reminder-send' ),
24 - 'click': function() { _this.sendReminder(); }
 39+ 'id': 'reminder-send-button',
 40+ 'click': function() {
 41+ var $send = $( '#reminder-send-button' );
 42+ var $cancel = $( '#reminder-cancel-button' );
 43+
 44+ $send.button( 'option', 'disabled', true );
 45+ $send.button( 'option', 'label', mw.msg( 'contest-contest-reminder-sending' ) );
 46+
 47+ _this.sendReminder( function( data ) {
 48+ if ( data.success ) {
 49+ $dialog.text( mw.msg( 'contest-contest-reminder-success', data.contestantcount ) );
 50+ $send.remove();
 51+ $cancel.button( 'option', 'label', mw.msg( 'contest-contest-reminder-close' ) );
 52+ }
 53+ else {
 54+ $send.button( 'option', 'label', mw.msg( 'contest-contest-reminder-retry' ) );
 55+ $send.button( 'option', 'disabled', false );
 56+
 57+ alert( mw.msg( 'contest-contest-reminder-failed' ) );
 58+ }
 59+ } );
 60+ }
2561 },
2662 {
2763 'text': mw.msg( 'contest-contest-reminder-cancel' ),
 64+ 'id': 'reminder-cancel-button',
2865 'click': function() {
29 - $( this ).dialog( 'close' );
 66+ $dialog.dialog( 'close' );
3067 }
3168 }
3269 ]

Follow-up revisions

RevisionCommit summaryAuthorDate
r1002971.18wmf1 MFT r100251, r100255, r100258, r100259, r100274, r100276, r100278reedy23:52, 19 October 2011
r108809follow up to r100274 - plural use in js messagesjeroendedauw13:55, 13 January 2012

Comments

#Comment by Siebrand (talk | contribs)   17:02, 23 December 2011

+ 'contest-contest-reminder-success' => 'Successfully send the reminder email to $1 contestants',

This needs plural support. Plural for JavaScript is now present in both 1.18-wmf1 as well as trunk.

#Comment by Liangent (talk | contribs)   17:42, 23 December 2011

Also + 'contest-contest-reminder-failed' => 'Could not send the reminder emails.', for "emails".

#Comment by Jeroen De Dauw (talk | contribs)   00:24, 4 January 2012

So I can just use Template:PLURAL and pass an extra arg to mw.msg as done in wfMsgExt?

#Comment by Krinkle (talk | contribs)   01:04, 4 January 2012

I don't know about {{PLURAL:}}, but mw.msg takes a variadic list of arguments (excluding the first argument) and eventually stores it as an array in the Message instance for use in the variable replacement parser.

Expanding the steps, each of the following is the same :)

mw.msg( 'foo', 'bar' );
mw.message( 'foo', bar' ).toString();
new Message( mw.messages, 'foo', [ 'bar' ] );

Note that Message is not directly publicly accessible.

Status & tagging log