Index: trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php |
— | — | @@ -17,7 +17,11 @@ |
18 | 18 | */ |
19 | 19 | |
20 | 20 | 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 = ''; |
22 | 26 | |
23 | 27 | public function __construct() { |
24 | 28 | parent::__construct( 'NotifyTranslators' ); |
— | — | @@ -43,7 +47,7 @@ |
44 | 48 | $htmlForm->setId( 'notifytranslators-form' ); |
45 | 49 | $htmlForm->setSubmitText( $context->msg( 'translationnotifications-send-notification-button' )->text() ); |
46 | 50 | $htmlForm->setSubmitID( 'translationnotifications-send-notification-button' ); |
47 | | - $htmlForm->setSubmitCallback( array( $this, 'formSubmit' ) ); |
| 51 | + $htmlForm->setSubmitCallback( array( $this, 'submitNotifyTranslatorsForm' ) ); |
48 | 52 | $htmlForm->show(); |
49 | 53 | |
50 | 54 | $wgOut->addModules( 'ext.translationnotifications.notifytranslators' ); |
— | — | @@ -80,6 +84,7 @@ |
81 | 85 | 'rows' => 20, |
82 | 86 | 'cols' => 80, |
83 | 87 | 'label-message' => 'translationnotifications-languages-to-notify-label', |
| 88 | + 'required' => true, |
84 | 89 | ); |
85 | 90 | |
86 | 91 | // Priotity dropdown |
— | — | @@ -115,4 +120,90 @@ |
116 | 121 | |
117 | 122 | return $m; |
118 | 123 | } |
| 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 | + } |
119 | 210 | } |
Index: trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php |
— | — | @@ -50,6 +50,24 @@ |
51 | 51 | 'translationnotifications-priority-unset' => '(unset)', |
52 | 52 | 'translationnotifications-translatablepage-title' => 'Translatable page name:', |
53 | 53 | '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.', |
54 | 72 | ); |
55 | 73 | |
56 | 74 | /** Message documentation (Message documentation) |
— | — | @@ -95,6 +113,18 @@ |
96 | 114 | 'translationnotifications-priority-unset' => 'unset (priority), an item in a dropdown box.', |
97 | 115 | 'translationnotifications-translatablepage-title' => 'A label for language codes field. Can be translated as "A page designated for translation, intended for translation", etc.', |
98 | 116 | '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}}', |
99 | 129 | ); |
100 | 130 | |
101 | 131 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
— | — | @@ -355,7 +385,7 @@ |
356 | 386 | ); |
357 | 387 | |
358 | 388 | /** Hebrew (עברית) |
359 | | - * @author amire80 |
| 389 | + * @author Amire80 |
360 | 390 | */ |
361 | 391 | $messages['he'] = array( |
362 | 392 | 'translatorsignup' => 'רישום מתרגמים', |
— | — | @@ -386,6 +416,23 @@ |
387 | 417 | 'translationnotifications-send-notification-button' => 'שליחת מכתבים למתרגמים', |
388 | 418 | 'translationnotifications-deadline-label' => 'תאריך סופי שיתווסף להודעה:', |
389 | 419 | '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.', |
390 | 437 | ); |
391 | 438 | |
392 | 439 | /** Upper Sorbian (Hornjoserbsce) |