Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/213779

Change subject: WIP: Notify user on first translation
......................................................................

WIP: Notify user on first translation

TODO: Draft a proper message and summary, identify the milestone

Bug: T99071
Change-Id: Ib51c895ddfbd8325bde429bf5f793ba1adc2a8ff
---
M Autoload.php
M ContentTranslation.hooks.php
M ContentTranslation.php
M api/ApiContentTranslationPublish.php
M i18n/en.json
A includes/Notification.php
6 files changed, 85 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/79/213779/1

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..2b519a7 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -230,6 +230,56 @@
        }
 
        /**
+       * Add notification events to Echo
+       *
+       * @param $notifications array of Echo notifications
+       * @param $notificationCategories array of Echo notification categories
+       * @param $icons array of icon details
+       * @return bool
+       */
+       public static function onBeforeCreateEchoEvent( &$notifications, 
&$notificationCategories, &$icons ) {
+               $notificationCategories['cx'] = array(
+                   'priority' => 3,
+                   'tooltip' => 'echo-pref-tooltip-cx',
+               );
+
+               $notifications['cx-first-translation'] = array(
+                       'primary-link' => array( 'message' => 'cx', 
'destination' => 'Special:CX' ),
+                       'category' => 'cx',
+                       'group' => 'positive',
+                       'formatter-class' => 'EchoBasicFormatter',
+                       'title-message' => 'cx-notification-first-translation',
+                       'email-subject-message' => 
'cx-notification-first-translation-email-subject',
+                       // TODO: We need an icon
+                       'icon' => 'Gratitude.png',
+               );
+
+               return true;
+       }
+
+       /**
+       * Add user to be notified on echo event
+       * @param $event EchoEvent
+       * @param $users array
+       * @return bool
+       */
+       public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) 
{
+               switch ( $event->getType() ) {
+                       case 'cx-first-translation':
+                               $extra = $event->getExtra();
+                               if ( !$extra || !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 c87cade..eea522d 100644
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -209,6 +209,9 @@
                                $result['newrevid'] = intval( 
$saveresult['edit']['newrevid'] );
                        }
                        $this->saveTranslationHistory( $params );
+                       // Notify user
+                       //TODO: Idenfify the mile stone: Whether it is first 
translation.
+                       ContentTranslation\Notification::firstTranslation( 
$this->getUser() );
                } else {
                        $result = array(
                                'result' => 'error',
diff --git a/i18n/en.json b/i18n/en.json
index 6a7dc43..e1d6a9d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -176,5 +176,9 @@
        "cx-campaign-contributionsmenu-myuploads": "Uploaded media",
        "cx-trend-all-translations": "All translations",
        "cx-trend-translations-to": "Translations to $1 language",
-       "cx-stats-try-contenttranslation": "Content Translation is a tool to 
create new pages by translating from other languages. [$1 Try Content 
Translation]"
+       "cx-stats-try-contenttranslation": "Content Translation is a tool to 
create new pages by translating from other languages. [$1 Try Content 
Translation]",
+       "echo-category-title-cx": "Translations",
+       "echo-pref-tooltip-cx": "Notify me about my translations using Content 
Translation tool",
+       "cx-notification-first-translation": "Your first translation is 
published",
+       "cx-first-translation-summary": "Congratulations! Your first 
translation is published using Content translation tool. Keep 
[[Special:CX|translating]]."
 }
diff --git a/includes/Notification.php b/includes/Notification.php
new file mode 100644
index 0000000..6f0282a
--- /dev/null
+++ b/includes/Notification.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * ContentTranslation Translation Notifications
+ */
+
+namespace ContentTranslation;
+
+class Notification {
+       /*
+        * Notify the user on first published translation.
+        */
+       public static function firstTranslation( \User $recipient ) {
+               // Create the notification via Echo extension
+               \EchoEvent::create( array(
+                       'type' => 'cx-first-translation',
+                       'payload' => wfMessage('cx-first-translation-summary'),
+                       'extra' => array(
+                               'recipient' =>  $recipient->getId(),
+                       )
+               ) );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/213779
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib51c895ddfbd8325bde429bf5f793ba1adc2a8ff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to