Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/100700
Change subject: Simplify the reminders and emails code
......................................................................
Simplify the reminders and emails code
Change-Id: I82370b2d7db701b966e124ee2d092e9989838489
---
M Resources.php
M TranslateSandbox.i18n.php
M api/ApiTranslateSandbox.php
M resources/js/ext.translate.special.translatesandbox.js
M utils/TranslateSandbox.php
5 files changed, 66 insertions(+), 140 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/00/100700/1
diff --git a/Resources.php b/Resources.php
index e19f741..2cf6aba 100644
--- a/Resources.php
+++ b/Resources.php
@@ -380,6 +380,9 @@
'tsb-accept-all-button-label',
'tsb-reject-all-button-label',
'tsb-reminder-link-text',
+ 'tsb-reminder-link-sending',
+ 'tsb-reminder-link-sent',
+ 'tsb-reminder-link-failed',
'tsb-didnt-make-any-translations',
'tsb-translations-source',
'tsb-translations-user',
diff --git a/TranslateSandbox.i18n.php b/TranslateSandbox.i18n.php
index 584c295..56641e2 100644
--- a/TranslateSandbox.i18n.php
+++ b/TranslateSandbox.i18n.php
@@ -19,14 +19,21 @@
'tsb-filter-pending' => 'Pending requests',
// Reminders
- 'tsb-reminder-title-generic' => 'Complete your introduction to become a
verified translator',
+ 'tsb-reminder-title-generic' => 'Complete your introduction to become a
translator',
'tsb-reminder-content-generic' => 'Hi $1,
-Thanks for registering with {{SITENAME}}. If you complete your test
-translations, the administrators can soon grant you full translation
-access.
+Thanks for registering with {{SITENAME}}.
-Please come to $2 and make some more translations.',
+If you complete your test translations, the administrators will grant you full
translation access soon afterwards.
+
+Please come to and make some more translations here:
+$2
+
+$3,
+{{SITENAME}} staff',
+ 'tsb-reminder-link-sending' => 'Sending the reminder...',
+ 'tsb-reminder-link-sent' => 'Sent the reminder',
+ 'tsb-reminder-link-failed' => 'Sending the reminder failed',
'tsb-email-promoted-subject' => 'You are now a translator at
{{SITENAME}}',
'tsb-email-promoted-body' => 'Hi $1,
@@ -89,6 +96,9 @@
'tsb-reminder-content-generic' => 'Body of an email. Parameters:
* $1 - user name of the recipient
* $3 - URL to the website',
+ 'tsb-reminder-link-sending' => 'Replaces
{{mw-msg|tsb-reminder-link-text}}, while the reminder email is being sent.',
+ 'tsb-reminder-link-sent' => 'Replaces
{{mw-msg|tsb-reminder-link-sending}} after the reminder email was successfully
sent.',
+ 'tsb-reminder-link-failed' => 'Replaces
{{mw-msg|tsb-reminder-link-sending}} if sending the reminder email failed.',
'tsb-email-promoted-subject' => 'The subject for an email that
announces that a user received full translation rights ("promoted").',
'tsb-email-promoted-body' => 'The body text for an email that announces
that a user received full translation rights ("promoted"). Parameters:
* $1 - the username of the new user who was promoted
diff --git a/api/ApiTranslateSandbox.php b/api/ApiTranslateSandbox.php
index 54e093b..fadee0a 100644
--- a/api/ApiTranslateSandbox.php
+++ b/api/ApiTranslateSandbox.php
@@ -116,7 +116,7 @@
$this->dieUsage( $e->getMessage(),
'invalidparam' );
}
- TranslateSandbox::sendPromotionEmail( $this->getUser(),
$user );
+ TranslateSandbox::sendEmail( $this->getUser(), $user,
'promotion' );
$logEntry = new ManualLogEntry( 'translatorsandbox',
'promoted' );
$logEntry->setPerformer( $this->getUser() );
@@ -134,18 +134,11 @@
protected function doRemind() {
$params = $this->extractRequestParams();
- // Do validations
- foreach ( explode( '|', 'subject|body' ) as $field ) {
- if ( !isset( $params[$field] ) ) {
- $this->dieUsage( "Missing parameter $field",
'missingparam' );
- }
- }
-
foreach ( $params['userid'] as $user ) {
$user = User::newFromId( $user );
try {
- TranslateSandbox::sendReminder(
$this->getUser(), $user, $params['subject'], $params['body'] );
+ TranslateSandbox::sendEmail( $this->getUser(),
$user, 'reminder' );
} catch ( MWException $e ) {
$this->dieUsage( $e->getMessage(),
'invalidparam' );
}
@@ -192,8 +185,6 @@
'username' => array( ApiBase::PARAM_TYPE => 'string' ),
'password' => array( ApiBase::PARAM_TYPE => 'string' ),
'email' => array( ApiBase::PARAM_TYPE => 'string' ),
- 'subject' => array( ApiBase::PARAM_TYPE => 'string' ),
- 'body' => array( ApiBase::PARAM_TYPE => 'string' ),
);
}
@@ -207,8 +198,6 @@
'username' => 'Username when creating user',
'password' => 'Password when creating user',
'email' => 'Email when creating user',
- 'subject' => 'Subject of the reminder email when
reminding',
- 'body' => 'Body of the reminder email when reminding',
);
}
diff --git a/resources/js/ext.translate.special.translatesandbox.js
b/resources/js/ext.translate.special.translatesandbox.js
index fd5e271..1efe812 100644
--- a/resources/js/ext.translate.special.translatesandbox.js
+++ b/resources/js/ext.translate.special.translatesandbox.js
@@ -21,93 +21,6 @@
.promise();
}
- /**
- * Gets arbitrary messages in chosen language via the API.
- * @param {Array} names Message keys.
- * @param {String} [language] Language to use. Defaults to English.
- * @return {jQuery.Deferred}
- */
- function getMessages( names, language ) {
- var req,
- api = new mw.Api(),
- deferred = new $.Deferred();
-
- req = api.post( {
- action: 'query',
- meta: 'allmessages',
- ammessages: names.join( '|' ),
- amlang: language || 'en'
- } );
-
- req.done( function ( data ) {
- var i,
- output = {};
-
- for ( i = 0; i < data.query.allmessages.length; i++ ) {
- output[data.query.allmessages[i].name] =
data.query.allmessages[i]['*'];
- }
-
- deferred.resolve( output );
- } );
-
- req.fail( deferred.reject );
-
- return deferred;
- }
-
- /**
- * Dialog where the user can tweak reminder email if wanted.
- * @param {Object} request
- */
- function reminderDialog( request ) {
- var $dialog,
- keys = [ 'tsb-reminder-title-generic',
'tsb-reminder-content-generic' ];
-
- getMessages( keys ).done( function ( data ) {
- // FIXME i18n
- $dialog = $( '<div class="grid">' ).append(
- $( '<form>' ).append(
- $( '<div class="row">' ).append(
- $( '<div class="three columns
text-left">' ).text( 'From:' ),
- $( '<div class="nine columns">'
).text( mw.config.get( 'wgUserName' ) + ' <your email>' )
- ),
- $( '<div class="row">' ).append(
- $( '<div class="three
columns">' ).text( 'To:' ),
- $( '<div class="nine columns">'
).text( request.email )
- ),
- $( '<div class="row">' ).append(
- $( '<div class="three
columns">' ).text( 'Subject:' ),
- $( '<input class="nine columns
subject">' ).val( data['tsb-reminder-title-generic'] )
- ),
- $( '<div class="row">' ).append(
- $( '<div class="three
columns">' ).text( 'Body:' ),
- $( '<textarea class="nine
columns body">' ).val( data['tsb-reminder-content-generic'] )
- )
- )
- );
-
- $dialog.dialog( {
- autoOpen: true,
- modal: true,
- width: '650px',
- buttons: {
- 'Send': function () {
- doApiAction( {
- userid: request.userid,
- 'do': 'remind',
- subject: $dialog.find(
'.subject' ).val(),
- body: $dialog.find(
'.body' ).val()
- } );
- $( this ).dialog( 'destroy' );
- },
- 'Cancel': function () {
- $( this ).dialog( 'destroy' );
- }
- }
- } );
- } );
- }
-
function removeSelectedRequests() {
var $nextRequest,
$selectedRequests = $( '.request-selector:checked' );
@@ -175,12 +88,30 @@
$( '<div>' )
.addClass( 'reminder row' )
.append(
- $( '<a href="#"></a>' )
+ $( '<a>' )
+ .prop( 'href', '#' )
.addClass( 'remind link' )
.text( mw.msg(
'tsb-reminder-link-text' ) )
.on( 'click', function ( e ) {
+ var $reminderLink;
+
e.preventDefault();
- reminderDialog( request
);
+
+ $reminderLink = $( this
);
+ $reminderLink.text(
mw.msg( 'tsb-reminder-link-sending' ) );
+
+ doApiAction( {
+ 'do': 'remind',
+ userid:
request.userid
+ } ).done( function () {
+
window.setTimeout( function () {
+
$reminderLink.text( mw.msg( 'tsb-reminder-link-sent' ) );
+ }, 500 );
+ } ).fail( function () {
+
window.setTimeout( function () {
+
$reminderLink.text( mw.msg( 'tsb-reminder-link-failed' ) );
+ }, 500 );
+ } );
} )
),
$( '<div>' )
diff --git a/utils/TranslateSandbox.php b/utils/TranslateSandbox.php
index 62acd7f..66b2437 100644
--- a/utils/TranslateSandbox.php
+++ b/utils/TranslateSandbox.php
@@ -121,47 +121,40 @@
* Sends a reminder to the user.
* @param User $sender
* @param User $target
- * @param string $subject Subject of the email.
- * @param string $body Body of the email.
+ * @param string $type 'reminder' or 'promotion'
* @throws MWException
* @since 2013.12
*/
- public static function sendReminder( User $sender, User $target,
$subject, $body ) {
+ public static function sendEmail( User $sender, User $target, $type ) {
global $wgNoReplyAddress;
- if ( !self::isSandboxed( $target ) ) {
- throw new MWException( 'Not a sandboxed user' );
+ switch ( $type ) {
+ case 'reminder':
+ if ( !self::isSandboxed( $target ) ) {
+ throw new MWException( 'Not a sandboxed
user' );
+ }
+
+ $subjectMsg = 'tsb-reminder-title-generic';
+ $bodyMsg = 'tsb-reminder-content-generic';
+ $targetSpecialPage = 'TranslationStash';
+
+ break;
+ case 'promotion':
+ $subjectMsg = 'tsb-email-promoted-subject';
+ $bodyMsg = 'tsb-email-promoted-body';
+ $targetSpecialPage = 'Translate';
+
+ break;
+ default:
+ throw new MWException( "'$type' is an invalid
type of translate sandbox email" );
}
- $params = array(
- 'user' => $target->getId(),
- 'to' => $target->getEmail(),
- 'from' => $sender->getEmail(),
- 'replyto' => $wgNoReplyAddress,
- 'subj' => $subject,
- 'body' => $body,
- 'emailType' => 'reminder',
- );
-
- TranslateSandboxEmailJob::newJob( $params )->insert();
- }
-
- /**
- * Sends an email to the user about promotion.
- * @param User $sender
- * @param User $target
- * @throws MWException
- * @since 2013.12
- */
- public static function sendPromotionEmail( User $sender, User $target )
{
- global $wgNoReplyAddress, $wgUser;
-
- $subject = wfMessage( 'tsb-email-promoted-subject' )->text();
+ $subject = wfMessage( $subjectMsg )->text();
$body = wfMessage(
- 'tsb-email-promoted-body',
+ $bodyMsg,
$target->getName(),
- SpecialPage::getTitleFor( 'Translate'
)->getCanonicalUrl(),
- $wgUser->getName()
+ SpecialPage::getTitleFor( $targetSpecialPage
)->getCanonicalUrl(),
+ $sender->getName()
)->inLanguage( $target->getOption( 'language' ) )->text();
$params = array(
@@ -171,7 +164,7 @@
'replyto' => $wgNoReplyAddress,
'subj' => $subject,
'body' => $body,
- 'emailType' => 'promotion',
+ 'emailType' => $type,
);
TranslateSandboxEmailJob::newJob( $params )->insert();
--
To view, visit https://gerrit.wikimedia.org/r/100700
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82370b2d7db701b966e124ee2d092e9989838489
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits