Amire80 has uploaded a new change for review. https://gerrit.wikimedia.org/r/203618
Change subject: Show an invitation to translate an article instead of creating ...................................................................... Show an invitation to translate an article instead of creating Bug: T88600 Change-Id: I402108656ccf52350d958951cc703c39cdc0110d --- M Resources.php M i18n/en.json M i18n/qqq.json M modules/campaigns/ext.cx.campaigns.contributionsmenu.js M modules/campaigns/styles/ext.cx.campaigns.contributionsmenu.less 5 files changed, 93 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/18/203618/1 diff --git a/Resources.php b/Resources.php index fc8428e..4c15b49 100644 --- a/Resources.php +++ b/Resources.php @@ -752,7 +752,10 @@ 'messages' => array( 'cx-campaign-contributionsmenu-mycontributions', 'cx-campaign-contributionsmenu-mytranslations', + 'cx-campaign-contributionsmenu-translate-instead', + 'cx-campaign-contributionsmenu-might-be-available', 'cx-campaign-contributionsmenu-myuploads', + 'quotation-marks', ) ) + $resourcePaths; diff --git a/i18n/en.json b/i18n/en.json index c4ac923..540e4f2 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -171,6 +171,8 @@ "cx-campaign-try": "Try Content Translation", "cx-campaign-contributionsmenu-mycontributions": "Contributions", "cx-campaign-contributionsmenu-mytranslations": "Translations", + "cx-campaign-contributionsmenu-translate-instead": "Translate instead of writing from scratch", + "cx-campaign-contributionsmenu-might-be-available": "$1 might be already available in other languages", "cx-campaign-contributionsmenu-myuploads": "Uploaded media", "cx-trend-all-translations": "All translations", "cx-trend-translations-to": "Translations to $1 language" diff --git a/i18n/qqq.json b/i18n/qqq.json index d07b425..74816c7 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -175,6 +175,8 @@ "cx-campaign-try": "Button label to try Content Translation beta feature", "cx-campaign-contributionsmenu-mycontributions": "Menu item for menu shown while hovering the contributions link in personal toolbar. Points to [[Special:MyContributions]]", "cx-campaign-contributionsmenu-mytranslations": "Menu item for menu shown while hovering the contributions link in personal toolbar. Points to the Content Translation dashboard\n{{Identical|Translation}}", + "cx-campaign-contributionsmenu-translate-instead": "Menu item for menu shown while hovering the contributions link in personal toolbar while a new page is being created. Points to the Content Translation dashboard\n{{Identical|Translation}}", + "cx-campaign-contributionsmenu-might-be-available": "Appears under {{msg-mw|cx-campaign-contributionsmenu-translate-instead}}. $1 is the title of the article being created, in quotation marks.", "cx-campaign-contributionsmenu-myuploads": "Menu item for menu shown while hovering the contributions link in personal toolbar. Points to the Special:MyUploads in commons", "cx-trend-all-translations": "Label shown in the legend section Content translation trends(graph visualization)", "cx-trend-translations-to": "Label shown in the legend section Content translation trends(graph visualization)\n$1 - language name" diff --git a/modules/campaigns/ext.cx.campaigns.contributionsmenu.js b/modules/campaigns/ext.cx.campaigns.contributionsmenu.js index 9489fa8..b162ce3 100644 --- a/modules/campaigns/ext.cx.campaigns.contributionsmenu.js +++ b/modules/campaigns/ext.cx.campaigns.contributionsmenu.js @@ -10,42 +10,85 @@ var campaign = 'contributionsmenu'; + function isPageCreation() { + return mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 0; + } + + function itemTitle( message ) { + return $( '<div>' ) + .addClass( 'cx-campaign-contributionsmenu__item-title' ) + .text( mw.msg( message ) ); + } + + function translationsItem() { + var cxUrlParams, creatingArticle, + message, $pageTitle, $expansion, + cxUrl, $link, $item; + + cxUrlParams = { + campaign: campaign, + to: mw.config.get( 'wgContentLanguage' ) + }; + + if ( isPageCreation() ) { + message = 'cx-campaign-contributionsmenu-translate-instead'; + $pageTitle = $( '<em>' ) + .text( mw.msg( 'quotation-marks', mw.config.get( 'wgTitle' ) ) ); + + $expansion = $( '<div>' ) + .addClass( 'cx-campaign-contributionsmenu__expansion' ) + .html( mw.msg( + 'cx-campaign-contributionsmenu-might-be-available', + $pageTitle[ 0 ].outerHTML + ) ); + + cxUrlParams.targettitle = mw.config.get( 'wgTitle' ); + } else { + message = 'cx-campaign-contributionsmenu-mytranslations'; + $expansion = $( [] ); + } + + cxUrl = mw.util.getUrl( 'Special:ContentTranslation', cxUrlParams ); + + $link = $( '<a>' ) + .append( + itemTitle( message ), + $expansion + ) + .attr( 'href', cxUrl ); + + $item = $( '<li>' ) + .addClass( 'cx-campaign-translations' ) + .append( $link ); + + return $item; + } + function showInvitation() { - var $trigger, cxLink, $menu, callout, - $myContributions, $myTranslations, $myUploads; + var $trigger, + $myContributions, $myTranslations, $myUploads, + $menu, callout; $trigger = $( '#pt-mycontris a' ); - cxLink = mw.util.getUrl( 'Special:ContentTranslation', { - campaign: campaign, - to: mw.config.get( 'wgContentLanguage' ) - } ); - $myContributions = $( '<li>' ) .addClass( 'cx-campaign-contributions' ) - .append( - $( '<a>' ) - .text( mw.msg( 'cx-campaign-contributionsmenu-mycontributions' ) ) + .append( $( '<a>' ) + .append( itemTitle( 'cx-campaign-contributionsmenu-mycontributions' ) ) .attr( 'href', $trigger.attr( 'href' ) ) ); - $myTranslations = $( '<li>' ) - .addClass( 'cx-campaign-translations' ) - .append( - $( '<a>' ) - .text( mw.msg( 'cx-campaign-contributionsmenu-mytranslations' ) ) - .attr( 'href', cxLink ) - ); + $myTranslations = translationsItem(); + if ( $( '.mw-special-Preferences' ).length ) { $myTranslations.addClass( 'cx-campaign-new-beta-feature' ); } $myUploads = $( '<li>' ) .addClass( 'cx-campaign-uploads' ) - .append( - $( '<a>' ) - .text( mw.msg( 'cx-campaign-contributionsmenu-myuploads' ) ) - .attr( 'href', '//commons.wikimedia.org/wiki/Special:MyUploads' ) + .append( $( '<a>' ) + .append( itemTitle( 'cx-campaign-contributionsmenu-myuploads' ) ) + .attr( 'href', '//commons.wikimedia.org/wiki/Special:MyUploads' ) ); $menu = $( '<ul>' ) @@ -73,13 +116,19 @@ // But it can be easily tracked if somebody uses it to reach CX. } - $trigger.on( 'mouseover', show ); - - mw.hook( 'mw.cx.betafeature.enabled' ).add( function () { + function ctaShow() { // Show after a few milliseconds to get all position calculation correct setTimeout( show, 500 ); mw.hook( 'mw.cx.cta.shown' ).fire( campaign ); - } ); + } + + $trigger.on( 'mouseover', show ); + + mw.hook( 'mw.cx.betafeature.enabled' ).add( ctaShow ); + + if ( isPageCreation() && mw.user.options.get( 'cx' ) ) { + ctaShow(); + } } $( function () { diff --git a/modules/campaigns/styles/ext.cx.campaigns.contributionsmenu.less b/modules/campaigns/styles/ext.cx.campaigns.contributionsmenu.less index 91a7d70..c8315e6 100644 --- a/modules/campaigns/styles/ext.cx.campaigns.contributionsmenu.less +++ b/modules/campaigns/styles/ext.cx.campaigns.contributionsmenu.less @@ -15,14 +15,17 @@ border-bottom: 1px solid #ccc; min-width: 250px; background-size: 24px; - background-position: left 10px center; + background-position: left 5px top 5px; background-repeat: no-repeat; a { text-decoration: none; color: #565656; - padding: 5px 10px 5px 40px; display: block; + } + + .cx-campaign-contributionsmenu__item-title { + padding: 5px 10px 5px 40px; } &:hover { @@ -47,5 +50,12 @@ background-repeat: no-repeat; background-size: 24px; } + + .cx-campaign-contributionsmenu__expansion { + margin: 2px 5px 2px 5px; + padding: 1px; + color: #555; + background-color: #eff; + } } } -- To view, visit https://gerrit.wikimedia.org/r/203618 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I402108656ccf52350d958951cc703c39cdc0110d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits