jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/327167 )
Change subject: Use new recommendation tool API ...................................................................... Use new recommendation tool API Introduce wgRecommendToolAPIURL configuration parameter The campaign parameter from recommendation tool will have the algorithm as suffix. For example: campaign=suggestion-type-5-related-articles Bug: T153187 Change-Id: If3abe05ff62f0adef35fa8cd06dfa374b023702f --- M ContentTranslation.hooks.php M extension.json M modules/dashboard/ext.cx.recommendtool.client.js M modules/dashboard/ext.cx.suggestionlist.js 4 files changed, 27 insertions(+), 17 deletions(-) Approvals: jenkins-bot: Verified Nikerabbit: Looks good to me, approved diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php index b740ce8..99fb20e 100644 --- a/ContentTranslation.hooks.php +++ b/ContentTranslation.hooks.php @@ -173,7 +173,8 @@ $wgContentTranslationCampaigns, $wgContentTranslationBrowserBlacklist, $wgContentTranslationDefaultSourceLanguage, - $wgContentTranslationTargetNamespace; + $wgContentTranslationTargetNamespace, + $wgRecommendToolAPIURL; $vars['wgContentTranslationTranslateInTarget'] = $wgContentTranslationTranslateInTarget; $vars['wgContentTranslationDomainCodeMapping'] = $wgContentTranslationDomainCodeMapping; @@ -185,6 +186,7 @@ $vars['wgContentTranslationBrowserBlacklist'] = $wgContentTranslationBrowserBlacklist; $vars['wgContentTranslationDefaultSourceLanguage'] = $wgContentTranslationDefaultSourceLanguage; $vars['wgContentTranslationTargetNamespace'] = $wgContentTranslationTargetNamespace; + $vars['wgRecommendToolAPIURL'] = $wgRecommendToolAPIURL; } /** diff --git a/extension.json b/extension.json index e991c32..7840ffd 100644 --- a/extension.json +++ b/extension.json @@ -150,7 +150,9 @@ "key": "", "age": "3600" }, - "ContentTranslationEnableSuggestions": false + "ContentTranslationEnableSuggestions": false, + "@RecommendToolAPIURL": "Web API URL for translation recommendation tool", + "RecommendToolAPIURL": "https://recommend-test.wmflabs.org/types/translation/v1/articles" }, "ResourceModules": { "Base64.js": { diff --git a/modules/dashboard/ext.cx.recommendtool.client.js b/modules/dashboard/ext.cx.recommendtool.client.js index ad73ddd..8dd3c45 100644 --- a/modules/dashboard/ext.cx.recommendtool.client.js +++ b/modules/dashboard/ext.cx.recommendtool.client.js @@ -22,7 +22,6 @@ function RecommendTool( from, to ) { this.sourceLanguage = from; this.targetLanguage = to; - this.algorithms = [ 'wiki', 'morelike' ]; this.seeds = null; } @@ -68,20 +67,21 @@ * @return {jQuery.Promise} */ RecommendTool.prototype.getSuggestionList = function () { - var self = this, - algorithm; + var self = this; - // Choose a random algorithm - algorithm = this.algorithms[ Math.floor( Math.random() * this.algorithms.length ) ]; return this.getSeedPages().then( function ( seedPages ) { - return $.get( 'https://recommend.wmflabs.org/api/', { - s: self.sourceLanguage, - t: self.targetLanguage, - article: seedPages.join( '|' ), + var algorithms, algorithm; + + algorithms = [ 'morelike', 'related_articles' ]; + algorithm = algorithms[ Math.floor( Math.random() * algorithms.length ) ]; + return $.get( mw.config.get( 'wgRecommendToolAPIURL' ), { + source: self.sourceLanguage, + target: self.targetLanguage, + seed: seedPages.join( '|' ), search: algorithm, application: 'CX' - } ).then( function ( response ) { - return self.adapt( response.articles, algorithm ); + } ).then( function ( articles ) { + return self.adapt( articles, algorithm ); } ); } ); }; @@ -107,6 +107,7 @@ sourceLanguage: this.sourceLanguage, targetLanguage: this.targetLanguage, pageviews: articles[ i ].pageviews, + wikidataId: articles[ i ].wikidata_id, listId: 'trex' } ); } diff --git a/modules/dashboard/ext.cx.suggestionlist.js b/modules/dashboard/ext.cx.suggestionlist.js index d8efdb1..526467b 100644 --- a/modules/dashboard/ext.cx.suggestionlist.js +++ b/modules/dashboard/ext.cx.suggestionlist.js @@ -726,7 +726,7 @@ var self = this; this.$suggestionsContainer.on( 'click', '.cx-suggestionlist .cx-slitem', function () { - var cxSelector, suggestion, campaign; + var cxSelector, suggestion, campaign, type, algorithm; cxSelector = $( this ).data( 'cxsourceselector' ); @@ -734,13 +734,18 @@ cxSelector.prefill(); } else { suggestion = $( this ).find( '.cx-slitem__translation-link' ).data( 'suggestion' ); - // Capture the list type for the campaign identifier - campaign = 'suggestions-type-' + self.lists[ suggestion.listId ].type; + // Capture the list type and algorithm if any, for the campaign identifier + type = self.lists[ suggestion.listId ].type; + campaign = [ 'suggestions-type', type ]; + algorithm = self.lists[ suggestion.listId ].algorithm; + if ( algorithm ) { + campaign.push( algorithm ); + } $( this ).cxSourceSelector( { sourceLanguage: suggestion.sourceLanguage, targetLanguage: suggestion.targetLanguage, sourceTitle: suggestion.title, - campaign: campaign + campaign: campaign.join( '-' ) } ); } } ); -- To view, visit https://gerrit.wikimedia.org/r/327167 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If3abe05ff62f0adef35fa8cd06dfa374b023702f Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits