Jsahleen has uploaded a new change for review.

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

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, 35 insertions(+), 13 deletions(-)


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

diff --git a/modules/publish/ext.cx.publish.dialog.js 
b/modules/publish/ext.cx.publish.dialog.js
index c873da0..8c2b889 100644
--- a/modules/publish/ext.cx.publish.dialog.js
+++ b/modules/publish/ext.cx.publish.dialog.js
@@ -97,17 +97,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..66182eb 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -128,9 +128,26 @@
        }
 
        /**
+        * 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)';
+       }
+
+       /**
         * Publish the translation
         */
-       function publish( publishAnyway ) {
+       function publish( publishAnyway, title ) {
                var $publishArea, $publishButton, publisher, translatedTitle,
                        translatedContent, targetCategories, $draftButton, 
targetTitle,
                        sortedKeys, i, categoryTitles, categories, 
publishedTitle;
@@ -138,7 +155,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 +164,11 @@
 
                checkTargetTitle( publishedTitle )
                        .done( function ( titleExists ) {
+                               var targetNamespace, username;
+
+                               targetNamespace = mw.config.get( 
'wgContentTranslationTargettargetNamespace' );
+                               username = mw.user.getName();
+
                                if ( titleExists === false || publishAnyway === 
true ) {
                                        $publishButton
                                                .prop( 'disabled', true )
@@ -172,7 +194,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 +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/184714
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: master
Gerrit-Owner: Jsahleen <[email protected]>

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

Reply via email to