jenkins-bot has submitted this change and it was merged.
Change subject: Configurable target namespace for translated pages
......................................................................
Configurable target namespace for translated pages
Introduce wgContentTranslationTargetNamespace variable
for configuring where to publish translated articles.
By default, publish in the 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 Resources.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
8 files changed, 74 insertions(+), 10 deletions(-)
Approvals:
Amire80: Looks good to me, approved
jenkins-bot: Verified
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 db9a360..41b3fcc 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -148,3 +148,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/Resources.php b/Resources.php
index 4676767..dac99ce 100644
--- a/Resources.php
+++ b/Resources.php
@@ -467,6 +467,7 @@
'mediawiki.api.edit',
'mediawiki.cookie',
'ext.cx.publish.dialog',
+ 'ext.cx.sitemapper',
),
'messages' => array(
'cx-publish-page-success',
@@ -485,6 +486,7 @@
),
'dependencies' => array(
'ext.cx.model',
+ 'ext.cx.sitemapper',
),
'messages' => array(
'cx-publishing-dialog-message',
diff --git a/api/ApiContentTranslationPublish.php
b/api/ApiContentTranslationPublish.php
index 56b8992..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,9 +190,7 @@
$params['from'], $params['sourcetitle']
),
'targetURL' =>
ContentTranslation\SiteMapper::getPageURL(
- $params['to'],
- // TODO: Construction of this URL should be
configurable
- 'User:' . $this->getUser()->getName() . '/' .
$params['title']
+ $params['to'], $targetTitle
),
'status' => $params['status'],
'progress' => $params['progress'],
diff --git a/includes/SiteMapper.php b/includes/SiteMapper.php
index 37dd851..a0daffe 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: merged
Gerrit-Change-Id: I3801e82edff4c2f39531a76a3e98fc9dada7e0c0
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits