[MediaWiki-commits] [Gerrit] Code cleanup in ext.cx.publish.js - change (mediawiki...ContentTranslation)
jenkins-bot has submitted this change and it was merged. Change subject: Code cleanup in ext.cx.publish.js .. Code cleanup in ext.cx.publish.js * Simplified jQuery selector for removing elements * Comments and whitespace * Shorten long lines Change-Id: Id7945105fc9907fa1fd2c8fb92d4f8c7f5a0cdab --- M modules/publish/ext.cx.publish.js 1 file changed, 36 insertions(+), 17 deletions(-) Approvals: KartikMistry: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/publish/ext.cx.publish.js b/modules/publish/ext.cx.publish.js index 0991f9a..b05e9dd 100644 --- a/modules/publish/ext.cx.publish.js +++ b/modules/publish/ext.cx.publish.js @@ -27,7 +27,9 @@ var apiParams, self = this; - this.targetTitle = ( params params.title ) || $( '.cx-column--translation h2' ).text(); + this.targetTitle = ( params params.title ) || + $( '.cx-column--translation h2' ).text(); + apiParams = $.extend( {}, params, { action: 'cxpublish', from: mw.cx.sourceLanguage, @@ -44,7 +46,6 @@ this.$trigger.prop( 'disabled', true ).text( mw.msg( 'cx-publish-button-publishing' ) ); return this.checkTargetTitle( this.targetTitle ).then( function ( title ) { - apiParams.title = self.targetTitle = title; return new mw.Api().postWithToken( 'edit', apiParams, { @@ -54,14 +55,17 @@ } ).done( function ( response ) { if ( response.cxpublish.result === 'success' ) { self.onSuccess(); + return; } + if ( response.cxpublish.edit.captcha ) { return self.captchaHandler( response.cxpublish.edit.captcha ) .then( function ( captchaResult ) { return self.publish( $.extend( params, captchaResult ) ); } ); } + // Any other failure self.onFail( 'cxpublish', response.cxpublish ); } ).fail( function ( code, details ) { @@ -127,7 +131,7 @@ }; /** -* Checks to see if there is already a published article with the title +* Checks to see if there is already a published article with the title. * @param {string} title The title to check * @return {jQuery.promise} */ @@ -153,7 +157,7 @@ }; /** -* Generate an alternate title in case of title collision +* Generate an alternate title in case of title collision. * @param {string} title The title * @return {string} */ @@ -162,6 +166,7 @@ username = mw.user.getName(); mwTitle = mw.Title.newFromText( title ); + if ( mwTitle mwTitle.getNamespaceId() === 2 ) { return increaseVersion( title ); } else { @@ -179,19 +184,23 @@ var self = this; title = mw.cx.SiteMapper.prototype.getTargetTitle( title ); + return this.titleExists( title ).then( function ( titleExists ) { var $dialog; if ( !titleExists ) { return title; } + // Show a dialog to decide what to do now self.$trigger.cxPublishingDialog(); $dialog = self.$trigger.data( 'cxPublishingDialog' ); + return $dialog.listen().then( function ( overwrite ) { if ( overwrite ) { return title; } + return getAlternateTitle( title ); } ); } ); @@ -216,26 +225,29 @@ } /** -* Get categories for the current translation pair +* Get categories for the current translation pair. * @return {string[]} Category titles */ CXPublish.prototype.getCategories = function () { - var i, sortedKeys, categoryTitles, targetCategories; + var targetCategories, sortedKeys, categoryTitles, i; targetCategories = mw.cx.categoryTool.categories.target; if ( !targetCategories ) { return []; } + sortedKeys = Object.keys( targetCategories ).sort(); categoryTitles
[MediaWiki-commits] [Gerrit] Code cleanup in ext.cx.publish.js - change (mediawiki...ContentTranslation)
Amire80 has uploaded a new change for review. https://gerrit.wikimedia.org/r/214118 Change subject: Code cleanup in ext.cx.publish.js .. Code cleanup in ext.cx.publish.js * Shorten long lines * Add empty lines for readability Change-Id: Ib7fc472999ab022063e263e91b61e6fa8a476400 --- M modules/publish/ext.cx.publish.js 1 file changed, 28 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/18/214118/1 diff --git a/modules/publish/ext.cx.publish.js b/modules/publish/ext.cx.publish.js index 0991f9a..210e3b1 100644 --- a/modules/publish/ext.cx.publish.js +++ b/modules/publish/ext.cx.publish.js @@ -27,7 +27,9 @@ var apiParams, self = this; - this.targetTitle = ( params params.title ) || $( '.cx-column--translation h2' ).text(); + this.targetTitle = ( params params.title ) || + $( '.cx-column--translation h2' ).text(); + apiParams = $.extend( {}, params, { action: 'cxpublish', from: mw.cx.sourceLanguage, @@ -44,7 +46,6 @@ this.$trigger.prop( 'disabled', true ).text( mw.msg( 'cx-publish-button-publishing' ) ); return this.checkTargetTitle( this.targetTitle ).then( function ( title ) { - apiParams.title = self.targetTitle = title; return new mw.Api().postWithToken( 'edit', apiParams, { @@ -54,14 +55,17 @@ } ).done( function ( response ) { if ( response.cxpublish.result === 'success' ) { self.onSuccess(); + return; } + if ( response.cxpublish.edit.captcha ) { return self.captchaHandler( response.cxpublish.edit.captcha ) .then( function ( captchaResult ) { return self.publish( $.extend( params, captchaResult ) ); } ); } + // Any other failure self.onFail( 'cxpublish', response.cxpublish ); } ).fail( function ( code, details ) { @@ -127,7 +131,7 @@ }; /** -* Checks to see if there is already a published article with the title +* Checks to see if there is already a published article with the title. * @param {string} title The title to check * @return {jQuery.promise} */ @@ -153,7 +157,7 @@ }; /** -* Generate an alternate title in case of title collision +* Generate an alternate title in case of title collision. * @param {string} title The title * @return {string} */ @@ -162,6 +166,7 @@ username = mw.user.getName(); mwTitle = mw.Title.newFromText( title ); + if ( mwTitle mwTitle.getNamespaceId() === 2 ) { return increaseVersion( title ); } else { @@ -179,19 +184,23 @@ var self = this; title = mw.cx.SiteMapper.prototype.getTargetTitle( title ); + return this.titleExists( title ).then( function ( titleExists ) { var $dialog; if ( !titleExists ) { return title; } + // Show a dialog to decide what to do now self.$trigger.cxPublishingDialog(); $dialog = self.$trigger.data( 'cxPublishingDialog' ); + return $dialog.listen().then( function ( overwrite ) { if ( overwrite ) { return title; } + return getAlternateTitle( title ); } ); } ); @@ -216,7 +225,7 @@ } /** -* Get categories for the current translation pair +* Get categories for the current translation pair. * @return {string[]} Category titles */ CXPublish.prototype.getCategories = function () { @@ -226,16 +235,19 @@ if ( !targetCategories ) { return []; } + sortedKeys = Object.keys( targetCategories ).sort(); categoryTitles = []; + for ( i = 0; i sortedKeys.length; i++ ) { categoryTitles.push( targetCategories[ sortedKeys[ i ] ] ); } +