Santhosh has uploaded a new change for review.

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

Change subject: Propagate CX beta feature option of user to target language wiki
......................................................................

Propagate CX beta feature option of user to target language wiki

Propagate CX beta feature option of user from source language
wiki to target target language wiki.

Show a tipsy notification with the beta feature link in
personal toolbar that the Content Translation is enabled.

Bug: T89812
Change-Id: If910cf88f66d35fcd5f8cb4a9dcbbb85425b7635
---
M Resources.php
M i18n/en.json
M i18n/qqq.json
A modules/entrypoint/ext.cx.betafeature.notification.js
M specials/SpecialContentTranslation.php
5 files changed, 68 insertions(+), 15 deletions(-)


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

diff --git a/Resources.php b/Resources.php
index 27d6ec1..1d5ff74 100644
--- a/Resources.php
+++ b/Resources.php
@@ -646,6 +646,20 @@
        )
 ) + $resourcePaths;
 
+$wgResourceModules['ext.cx.beta.notification'] = array(
+       'scripts' => array(
+               'entrypoint/ext.cx.betafeature.notification.js',
+       ),
+       'dependencies' => array(
+               'jquery.tipsy',
+               'jquery.uls.data',
+       ),
+       'messages' => array(
+               'cx-beta-feature-enabled-notificaiton',
+       ),
+) + $resourcePaths;
+
+
 $wgHooks['ResourceLoaderTestModules'][] = function ( array &$modules ) {
        $resourcePaths = array(
                'localBasePath' => __DIR__,
diff --git a/i18n/en.json b/i18n/en.json
index df91012..32bb6c8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -145,5 +145,6 @@
        "cx-stats-published-translators-title": "Number of translators",
        "cx-draft-discard-confirmaton-message": "Are you sure you want to 
permanently delete this translation?",
        "cx-draft-cancel-button-label": "Cancel",
-       "cx-draft-discard-button-label": "Delete translation"
+       "cx-draft-discard-button-label": "Delete translation",
+       "cx-beta-feature-enabled-notificaiton": "Content Translation has been 
activated for $1."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 993968c..7ae6d62 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -150,5 +150,6 @@
        "cx-stats-published-translators-title": "Section title for stats about 
number of translators who published articles across languages",
        "cx-draft-discard-confirmaton-message": "Confirmation message when user 
attempts to delete a translation.\n\nYou can use 
<nowiki>{{GENDER:|you}}</nowiki>.",
        "cx-draft-cancel-button-label": "Cancel button 
label\n{{Identical|Cancel}}",
-       "cx-draft-discard-button-label": "Label for delete button"
+       "cx-draft-discard-button-label": "Label for delete button",
+       "cx-beta-feature-enabled-notificaiton": "Notification shown when 
content translation enabled for a user. This is a tooltip text shown next to 
the beta feature link in the page"
 }
diff --git a/modules/entrypoint/ext.cx.betafeature.notification.js 
b/modules/entrypoint/ext.cx.betafeature.notification.js
new file mode 100644
index 0000000..be36219
--- /dev/null
+++ b/modules/entrypoint/ext.cx.betafeature.notification.js
@@ -0,0 +1,25 @@
+/**
+ * ContentTranslation Tools
+ * A tool that allows editors to translate pages from one language
+ * to another with the help of machine translation and other translation tools
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+( function ( $, mw ) {
+       'use strict';
+
+       $( function () {
+               var $betaTrigger, currentLanguage;
+
+               $betaTrigger = $( '#pt-betafeatures' );
+               currentLanguage = mw.config.get( 'wgContentLanguage' );
+               $betaTrigger.tipsy( {
+                       title: function () {
+                               return mw.msg( 
'cx-beta-feature-enabled-notificaiton', $.uls.data.getAutonym( currentLanguage 
) );
+                       }
+               } ).tipsy( 'show' );
+       } );
+}( jQuery, mediaWiki ) );
diff --git a/specials/SpecialContentTranslation.php 
b/specials/SpecialContentTranslation.php
index 4214e4e..d414dba 100644
--- a/specials/SpecialContentTranslation.php
+++ b/specials/SpecialContentTranslation.php
@@ -25,32 +25,44 @@
                return ContentTranslationHooks::isEnabledForUser( 
$this->getUser() );
        }
 
-       public function execute( $parameters ) {
+       public function enableCXBetaFeature() {
+               $user = $this->getUser();
                $out = $this->getOutput();
-               $skin = $this->getSkin();
-               $request = $this->getRequest();
+               $user->setOption( 'cx', 1 );
+               $user->saveSettings();
+               $out->addModules( 'ext.cx.beta.notification' );
+       }
 
+       public function hasToken() {
+               $request = $this->getRequest();
                $token = implode( '_', array(
                        'cx',
                        preg_replace( "/\s/", "-", urldecode( $request->getVal( 
'page' ) ) ),
                        $request->getVal( 'from' ),
                        $request->getVal( 'to' ),
                ) );
+               // With a valid cx token or draft id, override beta feature 
settings.
+               return $request->getCookie( $token, '' ) !== null || 
$request->getVal( 'draft' ) !== null;
+       }
 
+       public function execute( $parameters ) {
+               $out = $this->getOutput();
+               $skin = $this->getSkin();
+               $request = $this->getRequest();
+               $user = $this->getUser();
                // Direct access, isListed only affects Special:SpecialPages
-               if ( !ContentTranslationHooks::isEnabledForUser( 
$this->getUser() ) &&
-                       // With a valid cx token or draft id, override beta 
feature settings.
-                       $request->getCookie( $token, '' ) === null &&
-                       $request->getVal( 'draft' ) === null
-               ) {
-                       $out->showErrorPage( 'nosuchspecialpage', 
'nospecialpagetext' );
-                       return;
+               if ( !ContentTranslationHooks::isEnabledForUser( $user ) ) {
+                       if ( $this->hasToken() ) {
+                               // User has a token. Enabled cx for the user in 
this wiki.
+                               $this->enableCXBetaFeature();
+                       } else {
+                               $out->showErrorPage( 'nosuchspecialpage', 
'nospecialpagetext' );
+                               return;
+                       }
                }
 
                $out->addModuleStyles( 'mediawiki.ui.button' );
-               if ( $request->getCookie( $token, '' ) === null &&
-                       $request->getVal( 'draft' ) === null
-               ) {
+               if ( !$this->hasToken() ) {
                        $out->addModules( 'ext.cx.dashboard' );
                } else {
                        $out->addModules( 'ext.cx.translationview' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If910cf88f66d35fcd5f8cb4a9dcbbb85425b7635
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to