https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113809
Revision: 113809
Author: amire80
Date: 2012-03-14 13:23:36 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
Added logic for user selection and email subject and body composition. Doesn't
send an actual email yet.
Modified Paths:
--------------
trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
Modified: trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
===================================================================
--- trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
2012-03-14 12:41:01 UTC (rev 113808)
+++ trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
2012-03-14 13:23:36 UTC (rev 113809)
@@ -17,7 +17,11 @@
*/
class SpecialNotifyTranslators extends SpecialPage {
- protected static $right = 'translate-manage';
+ private static $right = 'translate-manage';
+ private static $notificationText = '';
+ private static $translatablePageTitle = '';
+ private static $deadlineDate = '';
+ private static $priority = '';
public function __construct() {
parent::__construct( 'NotifyTranslators' );
@@ -43,7 +47,7 @@
$htmlForm->setId( 'notifytranslators-form' );
$htmlForm->setSubmitText( $context->msg(
'translationnotifications-send-notification-button' )->text() );
$htmlForm->setSubmitID(
'translationnotifications-send-notification-button' );
- $htmlForm->setSubmitCallback( array( $this, 'formSubmit' ) );
+ $htmlForm->setSubmitCallback( array( $this,
'submitNotifyTranslatorsForm' ) );
$htmlForm->show();
$wgOut->addModules(
'ext.translationnotifications.notifytranslators' );
@@ -80,6 +84,7 @@
'rows' => 20,
'cols' => 80,
'label-message' =>
'translationnotifications-languages-to-notify-label',
+ 'required' => true,
);
// Priotity dropdown
@@ -115,4 +120,90 @@
return $m;
}
+
+ /**
+ * Callback for the submit button.
+ *
+ * TODO: document
+ */
+ public function submitNotifyTranslatorsForm( $formData, $form ) {
+ self::$translatablePageTitle = Title::newFromID(
$formData['TranslatablePage'] )->getText();
+ self::$notificationText = $formData['NotificationText'];
+ self::$priority = $formData['Priority'];
+ self::$deadlineDate = $formData['DeadlineDate'];
+
+ $languagesToNotify = explode( ',',
$formData['LanguagesToNotify'] );
+ $langPropertyPrefix = 'translationnotifications-lang-';
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $propertyLikePattern = $dbr->buildLike( $langPropertyPrefix,
$dbr->anyString() );
+ $translators = $dbr->select(
+ 'user_properties',
+ 'up_user',
+ array(
+ "up_property $propertyLikePattern",
+ 'up_value' => $languagesToNotify,
+ ),
+ __METHOD__,
+ 'DISTINCT'
+ );
+
+ foreach ( $translators as $row ) {
+ $this->sendTranslationNotificationEmail( $row->up_user
);
+ }
+
+ self::$translatablePageTitle = '';
+ self::$notificationText = '';
+ self::$deadlineDate = '';
+ self::$priority = '';
+ }
+
+ private function sendTranslationNotificationEmail( $userID ) {
+ $user = User::newFromID( $userID );
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $userFirstLanguageRow = $dbr->select(
+ 'user_properties',
+ 'up_value',
+ array(
+ 'up_user' => $userID,
+ 'up_property' =>
'translationnotifications-lang-1'
+ ),
+ __METHOD__
+ )->fetchRow();
+ $languageCode = $userFirstLanguageRow['up_value'];
+ $userFirstLanguage = Language::factory( $languageCode );
+
+ $emailSubject = wfMessage(
+ 'translationnotifications-email-subject',
+ self::$translatablePageTitle
+ )->inLanguage( $userFirstLanguage )->text();
+
+ $userName = $user->getRealName();
+ if ( $userName === '' ) {
+ $userName = $user->getName();
+ }
+ $languageName = $userFirstLanguage->getLanguageName();
+ $priorityClause = ( self::$priority === 'unset' )
+ ? ''
+ : wfMessage( 'translationnotifications-email-priority',
self::$priority );
+ $deadlineClause = ( self::$deadlineDate === '' )
+ ? ''
+ : wfMessage( 'translationnotifications-email-deadline',
self::$deadlineDate );
+ // XXX
+ $translationURL =
'title=Special:Translate&taction=translate&group=page-' .
self::$translatablePageTitle
+ . '&language=' . $languageCode
+ . '&task=view';
+
+ $emailBody = wfMessage(
+ 'translationnotifications-email-body',
+ $userName,
+ $languageName,
+ self::$translatablePageTitle,
+ $translationURL,
+ $priorityClause,
+ $deadlineClause,
+ self::$notificationText
+ )->inLanguage( $userFirstLanguage )->text();;
+ }
}
Modified:
trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
===================================================================
--- trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
2012-03-14 12:41:01 UTC (rev 113808)
+++ trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
2012-03-14 13:23:36 UTC (rev 113809)
@@ -50,6 +50,24 @@
'translationnotifications-priority-unset' => '(unset)',
'translationnotifications-translatablepage-title' => 'Translatable page
name:',
'translationnotifications-error-no-translatable-pages' => 'There are no
translatable pages in this wiki.',
+ 'translationnotifications-email-subject' => 'Please translate the page
$1',
+ 'translationnotifications-email-body' => 'Hello $1,
+
+You are receiving this email because you signed up as a translator to $2 on
{{SITENAME}}.
+
+There is a new page to translate there: $3.
+Please translate it by clicking the following link:
+$4
+
+$5
+$6
+
+$7
+
+Thank you!
+{{SITENAME}} staff',
+ 'translationnotifications-email-priority' => 'The priority of this page
is $1.',
+ 'translationnotifications-email-deadline' => 'The deadline for
translating this page is $1.',
);
/** Message documentation (Message documentation)
@@ -95,6 +113,18 @@
'translationnotifications-priority-unset' => 'unset (priority), an item
in a dropdown box.',
'translationnotifications-translatablepage-title' => 'A label for
language codes field. Can be translated as "A page designated for translation,
intended for translation", etc.',
'translationnotifications-error-no-translatable-pages' => 'An error
message.',
+ 'translationnotifications-email-subject' => 'A subject for the email
sent to translators.',
+ 'translationnotifications-email-body' => 'The body of the email message
sent to translators.
+
+* $1 - Translator\'s username or real name, if specified.
+* $2 - Language name.
+* $3 - Translatable page name.
+* $4 - URL.
+* $5 - The message {{msg-mw|translationnotifications-email-priority}}. Empty
if no priority was specified.
+* $6 - The message {{msg-mw|translationnotifications-email-deadline}}. Empty
if no deadline was specified.
+* $7 - A custom message that can be added by the notification sender.',
+ 'translationnotifications-email-priority' => 'Used in
{{msg-mw|translationnotifications-email-body}}',
+ 'translationnotifications-email-deadline' => 'Used in
{{msg-mw|translationnotifications-email-body}}',
);
/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
@@ -355,7 +385,7 @@
);
/** Hebrew (עברית)
- * @author amire80
+ * @author Amire80
*/
$messages['he'] = array(
'translatorsignup' => 'רישום מתרגמים',
@@ -386,6 +416,23 @@
'translationnotifications-send-notification-button' => 'שליחת מכתבים
למתרגמים',
'translationnotifications-deadline-label' => 'תאריך סופי שיתווסף
להודעה:',
'translationnotifications-languages-to-notify-label' => 'רשימת שפות
שהמתרגמים אליהן יקבלו את ההודעה (בקודים):',
+ 'translationnotifications-email-subject' => 'נא לתרגם את הדף $1',
+ 'translationnotifications-email-body' => 'שלום $1,
+
+קיבלת את המכתב הזה כי נרשמת בתור מתרגם ל$2 באתר {{SITENAME}}.
+
+יש שם דף חדש שצריך לתרגם: $3.
+אפשר לתרגם אותו על־ידי לחיצה על הקישור הבא:
+$4
+
+$5
+$6
+$7
+
+תודה!
+צוות {{SITENAME}}',
+ 'translationnotifications-email-priority' => 'העדיפות של הדף הזה: $1.',
+ 'translationnotifications-email-deadline' => 'התאריך הסופי לתרגום הדף
הזה הוא $1.',
);
/** Upper Sorbian (Hornjoserbsce)
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs