Santhosh has uploaded a new change for review.

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

Change subject: Configurable target namespace for translated pages
......................................................................

Configurable target namespace for translated pages

Introduce wgContentTranslationTargetNamespace configuration variable
for configuring where to publish translated articles.

By default, it publish in Main namespace

Added utility methods in js and php sitemapper modules to support this.

Bug: T76618
Bug: T78229
Change-Id: I3801e82edff4c2f39531a76a3e98fc9dada7e0c0
---
M ContentTranslation.hooks.php
M ContentTranslation.php
M api/ApiContentTranslationPublish.php
M includes/SiteMapper.php
M modules/base/ext.cx.sitemapper.js
M modules/publish/ext.cx.publish.dialog.js
M modules/publish/ext.cx.publish.js
7 files changed, 72 insertions(+), 8 deletions(-)


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

diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 772990d..d10a3fb 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -111,7 +111,8 @@
                        $wgContentTranslationTranslateInTarget,
                        $wgContentTranslationExperimentalFeatures,
                        $wgContentTranslationDatabase,
-                       $wgContentTranslationSiteTemplates;
+                       $wgContentTranslationSiteTemplates,
+                       $wgContentTranslationTargetNamespace;
 
                // Temporary BC code for old configuration
                if ( $wgContentTranslationServerURL !== null ) {
@@ -122,5 +123,6 @@
                $vars['wgContentTranslationTranslateInTarget'] = 
$wgContentTranslationTranslateInTarget;
                $vars['wgContentTranslationExperimentalFeatures'] = 
$wgContentTranslationExperimentalFeatures;
                $vars['wgContentTranslationDatabase'] = 
$wgContentTranslationDatabase;
+               $vars['wgContentTranslationTargetNamespace'] = 
$wgContentTranslationTargetNamespace;
        }
 }
diff --git a/ContentTranslation.php b/ContentTranslation.php
index 20dd765..1b57e98 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -147,3 +147,13 @@
  * users who have enabled the beta feature.
  */
 $GLOBALS['wgContentTranslationAsBetaFeature'] = true;
+
+/*
+ * Target namespace to publish articles. Values can be 'Main'
+ * or any valid Namepace without leading column.
+ * Example: 'User', 'MediaWiki', 'Draft'
+ * If the value is Main, article will be published in Main namespace.
+ * If the value is User, article will be published under 
User:UserName/PageTitle
+ * If it is another value like Foo, It will get published in Foo:PageTitle
+ */
+$GLOBALS['wgContentTranslationTargetNamespace'] = 'Main';
diff --git a/api/ApiContentTranslationPublish.php 
b/api/ApiContentTranslationPublish.php
index 2fab165..71204c8 100644
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -109,8 +109,11 @@
        public function publish() {
                $params = $this->extractRequestParams();
 
-               $title = Title::newFromText(
-                       'User:' . $this->getUser()->getName() . '/' . 
$params['title'] );
+               $targetTitle = ContentTranslation\SiteMapper::getTargetTitle(
+                       $params['title'],
+                       $this->getUser()->getName()
+               );
+               $title = Title::newFromText( $targetTitle );
 
                if ( !$title ) {
                        $this->dieUsageMsg( 'invalidtitle', $params['title'] );
@@ -174,6 +177,10 @@
                }
                $user = $this->getUser();
                $translator = new ContentTranslation\Translator( $user );
+               $targetTitle = ContentTranslation\SiteMapper::getTargetTitle(
+                       $params['title'],
+                       $this->getUser()->getName()
+               );
                $translation = new ContentTranslation\Translation( array(
                        'sourceTitle' => $params['sourcetitle'],
                        'targetTitle' => $params['title'],
@@ -183,7 +190,7 @@
                                $params['from'], $params['sourcetitle']
                        ),
                        'targetURL' => 
ContentTranslation\SiteMapper::getPageURL(
-                               $params['to'], $params['title']
+                               $params['to'], $targetTitle
                        ),
                        'status' => $params['status'],
                        'progress' => $params['progress'],
diff --git a/includes/SiteMapper.php b/includes/SiteMapper.php
index 37dd851..2899925 100644
--- a/includes/SiteMapper.php
+++ b/includes/SiteMapper.php
@@ -14,4 +14,21 @@
                );
        }
 
+       public static function getTargetTitle( $title, $userName ) {
+               global $wgContentTranslationTargetNamespace;
+
+               switch ( $wgContentTranslationTargetNamespace ) {
+                       case 'Main':
+                               $targetTitle = $title;
+                               break;
+                       case 'User':
+                               $targetTitle = 'User:'. $userName. '/' . $title;
+                               break;
+                       default:
+                               $targetTitle = 
$wgContentTranslationTargetNamespace. ':' . $title;
+                               break;
+               }
+
+               return $targetTitle;
+       }
 }
diff --git a/modules/base/ext.cx.sitemapper.js 
b/modules/base/ext.cx.sitemapper.js
index c0da65c..cfae7cb 100644
--- a/modules/base/ext.cx.sitemapper.js
+++ b/modules/base/ext.cx.sitemapper.js
@@ -27,7 +27,11 @@
         */
        mw.cx.SiteMapper.prototype.getApi = function ( language ) {
                var url = this.config.api.replace( '$1', language );
-               return new mw.Api( { ajax: { url: url } } );
+               return new mw.Api( {
+                       ajax: {
+                               url: url
+                       }
+               } );
        };
 
        /**
@@ -59,6 +63,30 @@
        };
 
        /**
+        * Get the target title to publish based on per wiki configuration.
+        * @param {string} title
+        * @return {string} target title
+        */
+       mw.cx.SiteMapper.prototype.getTargetTitle = function ( title ) {
+               var targetTitle, targetNameSpace;
+
+               targetNameSpace = mw.config.get( 
'wgContentTranslationTargetNamespace' );
+               switch ( targetNameSpace ) {
+               case 'Main':
+                       targetTitle = title;
+                       break;
+               case 'User':
+                       targetTitle = 'User:' + mw.user.getName() + '/' + title;
+                       break;
+               default:
+                       targetTitle = targetNameSpace + ':' + title;
+                       break;
+               }
+
+               return targetTitle;
+       };
+
+       /**
         * Do the content translation by going to Special:CX with the given
         * source-target title and target language.
         *
diff --git a/modules/publish/ext.cx.publish.dialog.js 
b/modules/publish/ext.cx.publish.dialog.js
index d8e2a3f..eb4dbde 100644
--- a/modules/publish/ext.cx.publish.dialog.js
+++ b/modules/publish/ext.cx.publish.dialog.js
@@ -119,12 +119,12 @@
        CXPublishingDialog.prototype.setMessage = function ( title ) {
                var publishedTitle, link;
 
-               publishedTitle = 'User:' + mw.user.getName() + '/' + title;
+               publishedTitle = mw.cx.SiteMapper.prototype.getTargetTitle( 
title );
 
                link = $( '<a>' ).attr( {
                        href: mw.util.getUrl( publishedTitle ),
                        target: '_blank'
-               } ).text( title )[ 0 ].outerHTML;
+               } ).text( publishedTitle )[ 0 ].outerHTML;
 
                this.$message.html( mw.msg( 'cx-publishing-dialog-message', 
link ) );
 
diff --git a/modules/publish/ext.cx.publish.js 
b/modules/publish/ext.cx.publish.js
index 9a332e4..745f885 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -143,7 +143,7 @@
                        $( '.cx-column--translation .cx-column__content' 
).clone()
                );
 
-               publishedTitle = 'User:' + mw.user.getName() + '/' + 
targetTitle;
+               publishedTitle = mw.cx.SiteMapper.prototype.getTargetTitle( 
targetTitle );
 
                checkTargetTitle( publishedTitle )
                        .done( function ( titleExists ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3801e82edff4c2f39531a76a3e98fc9dada7e0c0
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