jenkins-bot has submitted this change and it was merged. Change subject: Notify user on first translation ......................................................................
Notify user on first translation Bug: T99071 Change-Id: Ib51c895ddfbd8325bde429bf5f793ba1adc2a8ff --- M Autoload.php M ContentTranslation.hooks.php M ContentTranslation.php M api/ApiContentTranslationPublish.php M i18n/en.json M i18n/qqq.json A images/cx-notification-green.svg A includes/Notification.php M includes/Translator.php 9 files changed, 128 insertions(+), 5 deletions(-) Approvals: Nikerabbit: Looks good to me, approved jenkins-bot: Verified diff --git a/Autoload.php b/Autoload.php index abec7cd..9c7c5e6 100644 --- a/Autoload.php +++ b/Autoload.php @@ -22,6 +22,7 @@ 'ContentTranslation\Database' => "$dir/includes/Database.php", 'ContentTranslation\Draft' => "$dir/includes/Draft.php", 'ContentTranslation\GlobalUser' => "$dir/includes/GlobalUser.php", + 'ContentTranslation\Notification' => "$dir/includes/Notification.php", 'ContentTranslation\SiteMapper' => "$dir/includes/SiteMapper.php", 'ContentTranslation\Stats' => "$dir/includes/Stats.php", 'ContentTranslation\Translation' => "$dir/includes/Translation.php", diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php index 6d509c1..3dc12f7 100644 --- a/ContentTranslation.hooks.php +++ b/ContentTranslation.hooks.php @@ -230,6 +230,58 @@ } /** + * Add notification events to Echo + * + * @param array $notifications array of Echo notifications + * @param array $notificationCategories array of Echo notification categories + * @param array $icons array of icon details + */ + public static function onBeforeCreateEchoEvent( + &$notifications, &$notificationCategories, &$icons + ) { + $notificationCategories['cx'] = array( + 'priority' => 3, + 'tooltip' => 'echo-pref-tooltip-cx', + ); + + $notifications['cx-first-translation'] = array( + 'category' => 'cx', + 'group' => 'positive', + 'formatter-class' => 'EchoBasicFormatter', + 'title-message' => 'cx-notification-first-translation', + 'email-subject-message' => 'cx-notification-first-translation-email-subject', + 'icon' => 'cx', + ); + + $icons['cx'] = array( + 'path' => 'ContentTranslation/images/cx-notification-green.svg', + ); + + } + + /** + * Add user to be notified on echo event + * @param EchoEvent $event + * @param array $users + * @return bool + */ + public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) { + switch ( $event->getType() ) { + case 'cx-first-translation': + $extra = $event->getExtra(); + if ( !isset( $extra['recipient'] ) ) { + break; + } + $recipientId = $extra['recipient']; + $recipient = User::newFromId( $recipientId ); + $users[$recipientId] = $recipient; + break; + } + + return true; + } + + /** * Hook: ResourceLoaderTestModules */ public static function onResourceLoaderTestModules( array &$modules ) { diff --git a/ContentTranslation.php b/ContentTranslation.php index 5ebda08..9c757ed 100644 --- a/ContentTranslation.php +++ b/ContentTranslation.php @@ -76,9 +76,11 @@ 'ContentTranslationHooks::newArticleCampaign'; $GLOBALS['wgHooks']['ResourceLoaderTestModules'][] = 'ContentTranslationHooks::onResourceLoaderTestModules'; - +$GLOBALS['wgHooks']['BeforeCreateEchoEvent'][] = 'ContentTranslationHooks::onBeforeCreateEchoEvent'; +$GLOBALS['wgHooks']['EchoGetDefaultNotifiedUsers'][] = + 'ContentTranslationHooks::onEchoGetDefaultNotifiedUsers'; // Globals for this extension - +$GLOBALS['wgDefaultUserOptions']['echo-subscriptions-web-cx'] = true; $GLOBALS['wgContentTranslationExperimentalFeatures'] = false; $GLOBALS['wgContentTranslationParsoid'] = array( 'url' => 'http://parsoid-lb.eqiad.wikimedia.org/', diff --git a/api/ApiContentTranslationPublish.php b/api/ApiContentTranslationPublish.php index 473ecba..740ddc6 100755 --- a/api/ApiContentTranslationPublish.php +++ b/api/ApiContentTranslationPublish.php @@ -168,10 +168,11 @@ public function publish() { $params = $this->extractRequestParams(); + $user = $this->getUser(); $targetTitle = ContentTranslation\SiteMapper::getTargetTitle( $params['title'], - $this->getUser()->getName() + $user->getName() ); $title = Title::newFromText( $targetTitle ); @@ -213,6 +214,12 @@ $result['newrevid'] = intval( $saveresult['edit']['newrevid'] ); } $this->saveTranslationHistory( $params ); + // Notify user about milestones + $translator = new ContentTranslation\Translator( $user ); + if ( $translator->getTranslationsCount() === 1 ) { + ContentTranslation\Notification::firstTranslation( $user ); + } + // TODO: Add other milestones } else { $result = array( 'result' => 'error', diff --git a/i18n/en.json b/i18n/en.json index db1e395..19d8e8c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -196,5 +196,10 @@ "cx-tools-missing-link-text": "{{GENDER:|Mark}} the page as missing to encourage its creation.", "cx-tools-missing-link-tooltip": "Translate (in new window)", "cx-tools-missing-link-title": "Missing link", - "cx-tools-missing-link-mark-link": "{{GENDER:|Mark}} as missing" + "cx-tools-missing-link-mark-link": "{{GENDER:|Mark}} as missing", + "cx-tools-missing-link-mark-link": "Mark as missing", + "echo-category-title-cx": "Translations", + "echo-pref-tooltip-cx": "Notify me about my translations created using Content Translation tool", + "cx-notification-first-translation": "Congratulations for your first translation! Find more pages to translate at [[Special:MyContributions|your contributions page]].", + "cx-notification-first-translation-email-subject": "Congratulations for your first translation" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 4c96746..7372f52 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -200,5 +200,9 @@ "cx-tools-missing-link-text": "Message with instructions for marking links as missing", "cx-tools-missing-link-tooltip": "Tooltip that shows when hovering over target link card link when working with missing links.\nClicking on link opens a new translation view for the missing link.", "cx-tools-missing-link-title": "Title for target link card when card is used for working with missing links", - "cx-tools-missing-link-mark-link": "Text for mark as missing link control" + "cx-tools-missing-link-mark-link": "Text for mark as missing link control", + "echo-category-title-cx": "Title of CX Echo notifications. Shown in [[Special:Preferences]] page to configure notifications", + "echo-pref-tooltip-cx": "A tooltip text about CX notifcations.Shown in [[Special:Preferences]] page to configure notifications", + "cx-notification-first-translation": "Echo notification congratulating the user for first published translation.", + "cx-notification-first-translation-email-subject": "Email subject to congratulate the user for first published translation." } diff --git a/images/cx-notification-green.svg b/images/cx-notification-green.svg new file mode 100644 index 0000000..4b1aede --- /dev/null +++ b/images/cx-notification-green.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30"> + <g fill="#00af89"><path d="M21.129 17.268l-1.816-5.443-1.816 5.443z"/><path d="M2.813 0v24.375c0 3.188 2.438 5.625 5.625 5.625h18.75v-30h-24.375zm3.428 20.174l-1.09-1.453c3.451-2.543 4.447-6.082 4.629-6.902h-4.541v-1.816h4.541v-2.725h1.816v2.725h4.992l-.633 1.816h-4.266c.27.727 1.09 2.725 2.725 4.629l-.633 1.998c-1.359-1.359-2.268-2.906-2.906-4.084-.732 1.729-2.186 3.996-4.635 5.813zm16.611 2.543l-1.178-3.633h-4.811l-1.178 3.633h-1.998l4.266-12.709h2.725l4.178 12.709h-2.004z"/></g> +</svg> diff --git a/includes/Notification.php b/includes/Notification.php new file mode 100644 index 0000000..a36eaf8 --- /dev/null +++ b/includes/Notification.php @@ -0,0 +1,21 @@ +<?php +/** + * ContentTranslation Translation Notifications + */ + +namespace ContentTranslation; + +class Notification { + + /** + * Notify the user on first published translation. + */ + public static function firstTranslation( \User $recipient ) { + \EchoEvent::create( array( + 'type' => 'cx-first-translation', + 'extra' => array( + 'recipient' => $recipient->getId(), + ) + ) ); + } +} diff --git a/includes/Translator.php b/includes/Translator.php index 912fe8c..4dcdd88 100644 --- a/includes/Translator.php +++ b/includes/Translator.php @@ -87,6 +87,33 @@ } /** + * Get the number of published translation by current translator. + * @return Integer + */ + public function getTranslationsCount() { + $dbr = Database::getConnection( DB_SLAVE ); + $count = $dbr->selectField( + array( 'cx_translators', 'cx_translations' ), + 'count(*)', + array( + 'translator_user_id' => $this->getGlobalUserId(), + 'translator_translation_id = translation_id', + // And it is published + $dbr->makeList( + array( + 'translation_status' => 'published', + 'translation_target_url IS NOT NULL', + ), + LIST_OR + ) + ), + __METHOD__ + ); + + return intval( $count ); + } + + /** * Get the stats for all translator counts. */ public static function getStats() { -- To view, visit https://gerrit.wikimedia.org/r/213779 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib51c895ddfbd8325bde429bf5f793ba1adc2a8ff Gerrit-PatchSet: 12 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits