KartikMistry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184902
Change subject: Publishing options: Update version to highest version
automatically
......................................................................
Publishing options: Update version to highest version automatically
* If title for published article exists, shows dialog.
* If publish as draft is chosen, creates new draft in User space.
* If User space draft exists, increments version to highest version + 1
* If publish anyway is chosen, overwrites existing translation
Bug: T86665
Conflicts:
modules/publish/ext.cx.publish.dialog.js
Change-Id: I5210aa7119164acd79b7336651918dd5602569f4
---
M modules/publish/ext.cx.publish.dialog.js
M modules/publish/ext.cx.publish.js
2 files changed, 50 insertions(+), 28 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/02/184902/1
diff --git a/modules/publish/ext.cx.publish.dialog.js
b/modules/publish/ext.cx.publish.dialog.js
index eb4dbde..fe273ef 100644
--- a/modules/publish/ext.cx.publish.dialog.js
+++ b/modules/publish/ext.cx.publish.dialog.js
@@ -42,29 +42,15 @@
};
/**
- * Increase the version number of a title starting with 1
- * @param {string} title The title to increase the version on
- */
- function increaseVersion( title ) {
- var match, version;
-
- match = title.match( /^.*\((\d)\)$/ );
- if ( match ) {
- version = parseInt( match[ 1 ] ) + 1;
- return title.replace( /\(\d+\)$/, '(' + version + ')' );
- } else {
- return title + ' (1)';
- }
-
- }
-
- /**
* Renders the publishing options dialog.
* @param {string} title The title of the existing article
*/
CXPublishingDialog.prototype.render = function ( title ) {
- var $buttons, $keepButton, $publishAnywayButton,
+ var $buttons, $keepButton, $publishAnywayButton, username,
namespace,
cxPublishingDialog = this;
+
+ username = mw.user.getName();
+ namespace = mw.config.get(
'wgContentTranslationTargetNamespace' );
this.$dialog = $( '<div>' )
.addClass( 'cx-publishing-dialog' )
@@ -85,13 +71,17 @@
.addClass( 'cx-publishing-dialog__buttons' );
$keepButton = $( '<button>' )
- .addClass( 'cx-publishing-dialog__buttons-keep
mw-ui-button mw-ui-quiet' )
- .text( mw.msg( 'cx-publishing-dialog-keep-button' ) )
- .on( 'click', function () {
- var text = $( '.cx-column--translation > h2'
).text();
- $( '.cx-column--translation > h2' ).text(
increaseVersion( text ) );
+ .addClass( 'cx-publishing-dialog__buttons-keep
mw-ui-button mw-ui-quiet' );
+
+ if ( namespace === 'User' ) {
+ $keepButton.text( mw.msg(
'cx-publishing-dialog-keep-button' ) );
+ } else {
+ $keepButton.text( mw.msg(
'cx-publishing-dialog-publish-draft-button' ) );
+ }
+
+ $keepButton.on( 'click', function () {
cxPublishingDialog.$dialog.hide();
- mw.hook( 'mw.cx.publish' ).fire();
+ mw.hook( 'mw.cx.publish' ).fire( false );
} );
$publishAnywayButton = $( '<button>' )
diff --git a/modules/publish/ext.cx.publish.js
b/modules/publish/ext.cx.publish.js
index 745f885..95a1e7c 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -128,9 +128,28 @@
}
/**
- * Publish the translation
+ * Increase the version number of a title starting with 1.
+ * @param {string} title The title to increase the version on.
*/
- function publish( publishAnyway ) {
+ function increaseVersion( title ) {
+ var match, version;
+
+ match = title.match( /^.*\((\d+)\)$/ );
+ if ( match ) {
+ version = parseInt( match[ 1 ], 10 ) + 1;
+
+ return title.replace( /\(\d+\)$/, '(' + version + ')' );
+ }
+
+ return title + ' (1)';
+ }
+
+ /**
+ * Publish the translation
+ * @param {boolean} publishAnyway Flag to overwrite translation
+ * @param {string} title [optional], Optional title for the translation
+ */
+ function publish( publishAnyway, title ) {
var $publishArea, $publishButton, publisher, translatedTitle,
translatedContent, targetCategories, $draftButton,
targetTitle,
sortedKeys, i, categoryTitles, categories,
publishedTitle;
@@ -138,7 +157,7 @@
$publishArea = $( '.cx-header__publish' );
$publishButton = $publishArea.find(
'.cx-header__publish-button' );
$draftButton = $publishArea.find( '.cx-header__draft-button' );
- targetTitle = $( '.cx-column--translation > h2' ).text();
+ targetTitle = title || $( '.cx-column--translation > h2'
).text();
translatedContent = prepareTranslationForPublish(
$( '.cx-column--translation .cx-column__content'
).clone()
);
@@ -147,6 +166,10 @@
checkTargetTitle( publishedTitle )
.done( function ( titleExists ) {
+ var username;
+
+ username = mw.user.getName();
+
if ( titleExists === false || publishAnyway ===
true ) {
$publishButton
.prop( 'disabled', true )
@@ -172,7 +195,9 @@
categories: categories,
progress: JSON.stringify(
mw.cx.getProgress() )
} ).done( function () {
- mw.hook( 'mw.cx.success'
).fire( mw.message( 'cx-publish-page-success',
+ $( '.cx-column--translation >
h2' ).text( publishedTitle );
+ mw.hook( 'mw.cx.success' )
+ .fire( mw.message(
'cx-publish-page-success',
$( '<a>' ).attr( {
href:
mw.util.getUrl( publishedTitle ),
target: '_blank'
@@ -198,6 +223,13 @@
.prop( 'disabled', true
)
.text( mw.msg(
'cx-publish-button' ) );
} );
+ } else if ( publishAnyway === false ) {
+ if ( /^User:/.test( publishedTitle ) ) {
+ publishedTitle =
increaseVersion( publishedTitle );
+ } else {
+ publishedTitle = 'User:' +
username + '/' + publishedTitle;
+ }
+ publish( false, publishedTitle );
} else {
$publishButton.cxPublishingDialog();
}
--
To view, visit https://gerrit.wikimedia.org/r/184902
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5210aa7119164acd79b7336651918dd5602569f4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: wmf/1.25wmf14
Gerrit-Owner: KartikMistry <[email protected]>
Gerrit-Reviewer: Jsahleen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits