jenkins-bot has submitted this change and it was merged.

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
Change-Id: I5210aa7119164acd79b7336651918dd5602569f4
---
M modules/publish/ext.cx.publish.dialog.js
M modules/publish/ext.cx.publish.js
2 files changed, 37 insertions(+), 31 deletions(-)

Approvals:
  Santhosh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/publish/ext.cx.publish.dialog.js 
b/modules/publish/ext.cx.publish.dialog.js
index c873da0..fe273ef 100644
--- a/modules/publish/ext.cx.publish.dialog.js
+++ b/modules/publish/ext.cx.publish.dialog.js
@@ -42,23 +42,6 @@
        };
 
        /**
-        * 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 ], 10 ) + 1;
-
-                       return title.replace( /\(\d+\)$/, '(' + version + ')' );
-               }
-
-               return title + ' (1)';
-       }
-
-       /**
         * Renders the publishing options dialog.
         * @param {string} title The title of the existing article
         */
@@ -97,17 +80,8 @@
                }
 
                $keepButton.on( 'click', function () {
-                               var text = $( '.cx-column--translation > h2' 
).text();
-                               if ( /^User:/.test( text ) ||
-                                       namespace === 'User'
-                               ) {
-                                       text = increaseVersion( text );
-                               } else {
-                                       text = 'User:' + username + '/' + text;
-                               }
-                               $( '.cx-column--translation > h2' ).text( text 
);
                                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 55fc8fd..0d53c03 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'
@@ -199,6 +224,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/184714
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5210aa7119164acd79b7336651918dd5602569f4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Jsahleen <[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

Reply via email to