r113809 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113808‎ | r113809 | r113810 >
Date:13:23, 14 March 2012
Author:amire80
Status:ok
Tags:i18nreview 
Comment:
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 (modified) (history)
  • /trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
@@ -17,7 +17,11 @@
1818 */
1919
2020 class SpecialNotifyTranslators extends SpecialPage {
21 - protected static $right = 'translate-manage';
 21+ private static $right = 'translate-manage';
 22+ private static $notificationText = '';
 23+ private static $translatablePageTitle = '';
 24+ private static $deadlineDate = '';
 25+ private static $priority = '';
2226
2327 public function __construct() {
2428 parent::__construct( 'NotifyTranslators' );
@@ -43,7 +47,7 @@
4448 $htmlForm->setId( 'notifytranslators-form' );
4549 $htmlForm->setSubmitText( $context->msg( 'translationnotifications-send-notification-button' )->text() );
4650 $htmlForm->setSubmitID( 'translationnotifications-send-notification-button' );
47 - $htmlForm->setSubmitCallback( array( $this, 'formSubmit' ) );
 51+ $htmlForm->setSubmitCallback( array( $this, 'submitNotifyTranslatorsForm' ) );
4852 $htmlForm->show();
4953
5054 $wgOut->addModules( 'ext.translationnotifications.notifytranslators' );
@@ -80,6 +84,7 @@
8185 'rows' => 20,
8286 'cols' => 80,
8387 'label-message' => 'translationnotifications-languages-to-notify-label',
 88+ 'required' => true,
8489 );
8590
8691 // Priotity dropdown
@@ -115,4 +120,90 @@
116121
117122 return $m;
118123 }
 124+
 125+ /**
 126+ * Callback for the submit button.
 127+ *
 128+ * TODO: document
 129+ */
 130+ public function submitNotifyTranslatorsForm( $formData, $form ) {
 131+ self::$translatablePageTitle = Title::newFromID( $formData['TranslatablePage'] )->getText();
 132+ self::$notificationText = $formData['NotificationText'];
 133+ self::$priority = $formData['Priority'];
 134+ self::$deadlineDate = $formData['DeadlineDate'];
 135+
 136+ $languagesToNotify = explode( ',', $formData['LanguagesToNotify'] );
 137+ $langPropertyPrefix = 'translationnotifications-lang-';
 138+
 139+ $dbr = wfGetDB( DB_SLAVE );
 140+ $propertyLikePattern = $dbr->buildLike( $langPropertyPrefix, $dbr->anyString() );
 141+ $translators = $dbr->select(
 142+ 'user_properties',
 143+ 'up_user',
 144+ array(
 145+ "up_property $propertyLikePattern",
 146+ 'up_value' => $languagesToNotify,
 147+ ),
 148+ __METHOD__,
 149+ 'DISTINCT'
 150+ );
 151+
 152+ foreach ( $translators as $row ) {
 153+ $this->sendTranslationNotificationEmail( $row->up_user );
 154+ }
 155+
 156+ self::$translatablePageTitle = '';
 157+ self::$notificationText = '';
 158+ self::$deadlineDate = '';
 159+ self::$priority = '';
 160+ }
 161+
 162+ private function sendTranslationNotificationEmail( $userID ) {
 163+ $user = User::newFromID( $userID );
 164+
 165+ $dbr = wfGetDB( DB_SLAVE );
 166+ $userFirstLanguageRow = $dbr->select(
 167+ 'user_properties',
 168+ 'up_value',
 169+ array(
 170+ 'up_user' => $userID,
 171+ 'up_property' => 'translationnotifications-lang-1'
 172+ ),
 173+ __METHOD__
 174+ )->fetchRow();
 175+ $languageCode = $userFirstLanguageRow['up_value'];
 176+ $userFirstLanguage = Language::factory( $languageCode );
 177+
 178+ $emailSubject = wfMessage(
 179+ 'translationnotifications-email-subject',
 180+ self::$translatablePageTitle
 181+ )->inLanguage( $userFirstLanguage )->text();
 182+
 183+ $userName = $user->getRealName();
 184+ if ( $userName === '' ) {
 185+ $userName = $user->getName();
 186+ }
 187+ $languageName = $userFirstLanguage->getLanguageName();
 188+ $priorityClause = ( self::$priority === 'unset' )
 189+ ? ''
 190+ : wfMessage( 'translationnotifications-email-priority', self::$priority );
 191+ $deadlineClause = ( self::$deadlineDate === '' )
 192+ ? ''
 193+ : wfMessage( 'translationnotifications-email-deadline', self::$deadlineDate );
 194+ // XXX
 195+ $translationURL = 'title=Special:Translate&taction=translate&group=page-' . self::$translatablePageTitle
 196+ . '&language=' . $languageCode
 197+ . '&task=view';
 198+
 199+ $emailBody = wfMessage(
 200+ 'translationnotifications-email-body',
 201+ $userName,
 202+ $languageName,
 203+ self::$translatablePageTitle,
 204+ $translationURL,
 205+ $priorityClause,
 206+ $deadlineClause,
 207+ self::$notificationText
 208+ )->inLanguage( $userFirstLanguage )->text();;
 209+ }
119210 }
Index: trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
@@ -50,6 +50,24 @@
5151 'translationnotifications-priority-unset' => '(unset)',
5252 'translationnotifications-translatablepage-title' => 'Translatable page name:',
5353 'translationnotifications-error-no-translatable-pages' => 'There are no translatable pages in this wiki.',
 54+ 'translationnotifications-email-subject' => 'Please translate the page $1',
 55+ 'translationnotifications-email-body' => 'Hello $1,
 56+
 57+You are receiving this email because you signed up as a translator to $2 on {{SITENAME}}.
 58+
 59+There is a new page to translate there: $3.
 60+Please translate it by clicking the following link:
 61+$4
 62+
 63+$5
 64+$6
 65+
 66+$7
 67+
 68+Thank you!
 69+{{SITENAME}} staff',
 70+ 'translationnotifications-email-priority' => 'The priority of this page is $1.',
 71+ 'translationnotifications-email-deadline' => 'The deadline for translating this page is $1.',
5472 );
5573
5674 /** Message documentation (Message documentation)
@@ -95,6 +113,18 @@
96114 'translationnotifications-priority-unset' => 'unset (priority), an item in a dropdown box.',
97115 'translationnotifications-translatablepage-title' => 'A label for language codes field. Can be translated as "A page designated for translation, intended for translation", etc.',
98116 'translationnotifications-error-no-translatable-pages' => 'An error message.',
 117+ 'translationnotifications-email-subject' => 'A subject for the email sent to translators.',
 118+ 'translationnotifications-email-body' => 'The body of the email message sent to translators.
 119+
 120+* $1 - Translator\'s username or real name, if specified.
 121+* $2 - Language name.
 122+* $3 - Translatable page name.
 123+* $4 - URL.
 124+* $5 - The message {{msg-mw|translationnotifications-email-priority}}. Empty if no priority was specified.
 125+* $6 - The message {{msg-mw|translationnotifications-email-deadline}}. Empty if no deadline was specified.
 126+* $7 - A custom message that can be added by the notification sender.',
 127+ 'translationnotifications-email-priority' => 'Used in {{msg-mw|translationnotifications-email-body}}',
 128+ 'translationnotifications-email-deadline' => 'Used in {{msg-mw|translationnotifications-email-body}}',
99129 );
100130
101131 /** Belarusian (Taraškievica orthography) (‪Беларуская (тарашкевіца)‬)
@@ -355,7 +385,7 @@
356386 );
357387
358388 /** Hebrew (עברית)
359 - * @author amire80
 389+ * @author Amire80
360390 */
361391 $messages['he'] = array(
362392 'translatorsignup' => 'רישום מתרגמים',
@@ -386,6 +416,23 @@
387417 'translationnotifications-send-notification-button' => 'שליחת מכתבים למתרגמים',
388418 'translationnotifications-deadline-label' => 'תאריך סופי שיתווסף להודעה:',
389419 'translationnotifications-languages-to-notify-label' => 'רשימת שפות שהמתרגמים אליהן יקבלו את ההודעה (בקודים):',
 420+ 'translationnotifications-email-subject' => 'נא לתרגם את הדף $1',
 421+ 'translationnotifications-email-body' => 'שלום $1,
 422+
 423+קיבלת את המכתב הזה כי נרשמת בתור מתרגם ל$2 באתר {{SITENAME}}.
 424+
 425+יש שם דף חדש שצריך לתרגם: $3.
 426+אפשר לתרגם אותו על־ידי לחיצה על הקישור הבא:
 427+$4
 428+
 429+$5
 430+$6
 431+$7
 432+
 433+תודה!
 434+צוות {{SITENAME}}',
 435+ 'translationnotifications-email-priority' => 'העדיפות של הדף הזה: $1.',
 436+ 'translationnotifications-email-deadline' => 'התאריך הסופי לתרגום הדף הזה הוא $1.',
390437 );
391438
392439 /** Upper Sorbian (Hornjoserbsce)

Status & tagging log