jenkins-bot has submitted this change and it was merged. Change subject: Improve contributions page entry point by adding 3 ways to contribute ......................................................................
Improve contributions page entry point by adding 3 ways to contribute Also includes eventlogging tooling. Bug: T92939 Change-Id: If6670eb05106516637221a24f0a64e084f27626b --- M ContentTranslation.hooks.php M Resources.php M i18n/en.json M i18n/qqq.json M modules/entrypoint/ext.cx.contributions.init.js M modules/entrypoint/ext.cx.contributions.js D modules/entrypoint/images/dropdown.png D modules/entrypoint/images/dropdown.svg A modules/entrypoint/images/editarticle.png A modules/entrypoint/images/editarticle.svg A modules/entrypoint/images/translation.png A modules/entrypoint/images/translation.svg A modules/entrypoint/images/upload.png A modules/entrypoint/images/upload.svg M modules/entrypoint/styles/ext.cx.contributions.less 15 files changed, 134 insertions(+), 95 deletions(-) Approvals: Nikerabbit: Looks good to me, approved jenkins-bot: Verified diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php index 991bd46..ac18b64 100644 --- a/ContentTranslation.hooks.php +++ b/ContentTranslation.hooks.php @@ -116,9 +116,15 @@ * @param SpecialPage $page */ public static function addNewContributionButton( $id, User $user, SpecialPage $page ) { + global $wgContentTranslationEventLogging; + if ( $user->getId() === $page->getUser()->getId() && ContentTranslationHooks::isEnabledForUser( $user ) ) { + // If EventLogging integration is enabled, load the event logging functions module + if ( $wgContentTranslationEventLogging ) { + $page->getOutput()->addModules( 'ext.cx.eventlogging' ); + } $page->getOutput()->addModules( 'ext.cx.contributions.init' ); } } diff --git a/Resources.php b/Resources.php index 4304ade..8fb2841 100644 --- a/Resources.php +++ b/Resources.php @@ -26,9 +26,13 @@ 'mediawiki.ui.button', ), 'messages' => array( - 'cx-contributions', + 'cx-contributions-new-contributions', + 'cx-contributions-new-article', 'cx-contributions-translation', - 'cx-contributions-media', + 'cx-contributions-upload', + 'cx-contributions-new-article-tooltip', + 'cx-contributions-translation-tooltip', + 'cx-contributions-upload-tooltip', ), ) + $resourcePaths; diff --git a/i18n/en.json b/i18n/en.json index aba65c9..b0206d9 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -132,9 +132,13 @@ "cx-save-draft-save-success": "Saved {{PLURAL:$1|a minute ago|$1 minutes ago|0=just now}}", "cx-save-draft-saving": "Saving...", "cx-save-draft-tooltip": "Translation drafts are saved automatically", - "cx-contributions": "New contribution", + "cx-contributions-new-contributions": "New contribution", + "cx-contributions-new-article": "New page", "cx-contributions-translation": "Translation", - "cx-contributions-media": "Upload media file", + "cx-contributions-upload": "Upload media", + "cx-contributions-new-article-tooltip": "Start writing a new page", + "cx-contributions-translation-tooltip": "Translate existing pages", + "cx-contributions-upload-tooltip": "Upload pictures, audio and video to use in pages", "cx-publishing-dialog-message": "The page $1 already exists. The current content will be replaced by your translation. Do you want to publish anyway?", "cx-publishing-dialog-keep-button": "Keep both versions", "cx-publishing-dialog-publish-anyway-button": "Publish anyway", diff --git a/i18n/qqq.json b/i18n/qqq.json index a546ece..2f2e59c 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -139,9 +139,13 @@ "cx-save-draft-save-success": "\"Saved\" refers to a draft of a translated page that was saved recently.", "cx-save-draft-saving": "Label of button to save the translation as draft while saving is in progress\n{{Identical|Saving}}", "cx-save-draft-tooltip": "Tooltip text shown for the save status indicator text in the header of [[Special:ContentTranslation]].\n\nParameters: \n* $1 - the number of minutes ago the translation was saved.", - "cx-contributions": "Text of a button which opens a dropdown", - "cx-contributions-translation": "Dropdown item\n{{Identical|Translation}}", - "cx-contributions-media": "Dropdown item", + "cx-contributions-new-contributions": "Header text shown in [[Special:Contributions]]", + "cx-contributions-new-article": "Button label", + "cx-contributions-translation": "Button label", + "cx-contributions-upload": "Button label", + "cx-contributions-new-article": "Button label tooltip", + "cx-contributions-translation": "Button label tooltip", + "cx-contributions-upload": "Button label tooltip", "cx-publishing-dialog-message": "Message that shows in the publishing options dialog when there is an existing page with the same title already published.\n\nParameters:\n* $1 - The link to the existing page with just the title as text.", "cx-publishing-dialog-keep-button": "Button label for publishing options dialog. Clicking button preserves both the existing translation and the new translation.", "cx-publishing-dialog-publish-anyway-button": "Button label for publishing options dialog. Clicking button overwrites the existing translation with the new translation.", diff --git a/modules/entrypoint/ext.cx.contributions.init.js b/modules/entrypoint/ext.cx.contributions.init.js index c0ac660..7dee976 100644 --- a/modules/entrypoint/ext.cx.contributions.init.js +++ b/modules/entrypoint/ext.cx.contributions.init.js @@ -12,7 +12,7 @@ var $element = $( '<span>' ); $element.cxContributions(); - $element.insertBefore( $( '.mw-contributions-form' ) ); + $( '#firstHeading' ).before( $element ); } ); }( jQuery ) ); diff --git a/modules/entrypoint/ext.cx.contributions.js b/modules/entrypoint/ext.cx.contributions.js index cbb42ff..d577526 100644 --- a/modules/entrypoint/ext.cx.contributions.js +++ b/modules/entrypoint/ext.cx.contributions.js @@ -8,16 +8,14 @@ ( function ( $, mw ) { 'use strict'; + var entrypointName = 'contributions-page'; /** * @class */ - function CXContributions( element, options ) { + function CXContributions( element ) { this.$element = $( element ); - this.options = $.extend( {}, $.fn.cxContributions.defaults, options ); + this.$container = null; this.init(); - - this.$trigger = null; - this.$menu = null; } /** @@ -29,66 +27,59 @@ }; CXContributions.prototype.render = function () { - var $menuContainer; - - this.$trigger = $( '<button>' ) - .text( mw.msg( 'cx-contributions' ) ) - .addClass( 'mw-ui-button mw-ui-progressive' ) - .addClass( 'cx-contributions__trigger' ); - - this.$menu = $( '<ul>' ) - .addClass( 'cx-contributions__menu' ); - this.$menu.hide(); - - this.$menu.append( - $.map( this.getActivities(), function ( item ) { - return $( '<li>' ).text( item.text ).data( 'url', item.url ); - } ) - ); - - $menuContainer = $( '<div>' ) + var $sectionHeader; + $sectionHeader = $( '<h1>' ) + .text( mw.msg( 'cx-contributions-new-contributions' ) ); + this.$container = $( '<div>' ) .addClass( 'cx-contributions' ) - .append( this.$trigger, this.$menu ); + .append( $.map( this.getActivities(), function ( item ) { + return $( '<button>' ) + .addClass( item.class ) + .text( item.text ) + .attr( 'title', item.tooltip ) + .data( 'url', item.url ); + } ) ); - this.$element.append( $menuContainer ); + this.$element.append( $sectionHeader, this.$container ); + mw.hook( 'mw.cx.cta.shown' ).fire( entrypointName ); }; + + /** + * A weak and inaccurate way to guess if this user has done + * any contribution using CX. + * @return {boolean} + */ + function isNewToCX() { + return $( '.mw-tag-marker-contenttranslation' ).length === 0; + } CXContributions.prototype.getActivities = function () { return [ { - text: mw.msg( 'cx-contributions-translation' ), - url: mw.util.getUrl( 'Special:ContentTranslation' ) + text: mw.msg( 'cx-contributions-new-article' ), + class: 'cx-contributions-new-article', + url: mw.util.getUrl( 'Special:WantedPages' ), + tooltip: mw.msg( 'cx-contributions-new-article-tooltip' ) }, { - text: mw.msg( 'cx-contributions-media' ), - url: 'https://commons.wikimedia.org/wiki/Special:UploadWizard' - } + text: mw.msg( 'cx-contributions-upload' ), + class: 'cx-contributions-upload', + url: 'https://commons.wikimedia.org/wiki/Special:UploadWizard', + tooltip: mw.msg( 'cx-contributions-upload-tooltip' ) + }, + { + text: mw.msg( 'cx-contributions-translation' ), + class: 'cx-contributions-translation ' + ( isNewToCX() ? 'cx-contributions-new' : '' ), + url: mw.util.getUrl( 'Special:ContentTranslation', { + campaign: entrypointName + } ), + tooltip: mw.msg( 'cx-contributions-translation-tooltip' ) + }, ]; }; CXContributions.prototype.listen = function () { - var menu = this.$menu; - - menu.toggle = function ( e ) { - if ( menu.is( ':hidden' ) ) { - menu.show(); - $( document ).one( 'click', function () { - menu.hide(); - } ); - } else { - menu.hide(); - } - - e.stopPropagation(); - }; - - menu.on( 'click', '> li', this.startActivity ); - - this.$trigger.one( 'click', function () { - menu.css( 'min-width', $( this ).css( 'width' ) ); - } ); - this.$trigger.on( 'click', menu.toggle ); - + this.$container.on( 'click', '> button', this.startActivity ); }; CXContributions.prototype.startActivity = function () { @@ -108,7 +99,5 @@ } } ); }; - - $.fn.cxContributions.defaults = {}; }( jQuery, mediaWiki ) ); diff --git a/modules/entrypoint/images/dropdown.png b/modules/entrypoint/images/dropdown.png deleted file mode 100644 index 2e91490..0000000 --- a/modules/entrypoint/images/dropdown.png +++ /dev/null Binary files differ diff --git a/modules/entrypoint/images/dropdown.svg b/modules/entrypoint/images/dropdown.svg deleted file mode 100644 index c9fdc69..0000000 --- a/modules/entrypoint/images/dropdown.svg +++ /dev/null @@ -1 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.000001 11.71189"><g><g><path fill="#fff" d="M0 2.706L2.67.036l6.322 6.33 6.33-6.367 2.675 2.66L9 11.71z"/></g></g></svg> \ No newline at end of file diff --git a/modules/entrypoint/images/editarticle.png b/modules/entrypoint/images/editarticle.png new file mode 100644 index 0000000..0bfa608 --- /dev/null +++ b/modules/entrypoint/images/editarticle.png Binary files differ diff --git a/modules/entrypoint/images/editarticle.svg b/modules/entrypoint/images/editarticle.svg new file mode 100644 index 0000000..7909467 --- /dev/null +++ b/modules/entrypoint/images/editarticle.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8" ?> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24"> + <path d="M21 13l-7 7-.5 2.5 2.5-.5 7-7c0-1-1-2-2-2zm-6.1 7.8l-.5-.4 6.6-6.6c.2-.1.5.3.5.4l-6.6 6.6zM7 18v-1h8l1-1h-9v-1h9v1l2-2v-9h-13v13c0 1.7 1.3 3 3 3h4.5l.5-2 1-1h-7zm5-11h4v5h-4v-5zm-5 0h4v1h-4v-1zm0 2h4v1h-4v-1zm0 2h4v1h-4v-1zm0 2h9v1h-9v-1z" /> +</svg> diff --git a/modules/entrypoint/images/translation.png b/modules/entrypoint/images/translation.png new file mode 100644 index 0000000..008eabd --- /dev/null +++ b/modules/entrypoint/images/translation.png Binary files differ diff --git a/modules/entrypoint/images/translation.svg b/modules/entrypoint/images/translation.svg new file mode 100644 index 0000000..c660fbd --- /dev/null +++ b/modules/entrypoint/images/translation.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8" ?> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24"> + <path d="M11.1 13.1c-1.8-2.1-2.7-4.3-3-5.1h4.7l.7-2h-5.5v-3h-2v3h-5v2h5c-.2.9-1.3 4.8-5.1 7.6l1.2 1.6c2.7-2 4.3-4.5 5.1-6.4.7 1.3 1.7 3 3.2 4.5l.7-2.2zM12.5 20l1.3-4h5.3l1.3 4h2.2l-4.6-14h-3l-4.7 14h2.2zm4-12l2 6h-4l2-6z" /> +</svg> diff --git a/modules/entrypoint/images/upload.png b/modules/entrypoint/images/upload.png new file mode 100644 index 0000000..41cc6a9 --- /dev/null +++ b/modules/entrypoint/images/upload.png Binary files differ diff --git a/modules/entrypoint/images/upload.svg b/modules/entrypoint/images/upload.svg new file mode 100644 index 0000000..bf5e1b5 --- /dev/null +++ b/modules/entrypoint/images/upload.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8" ?> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24"> + <path d="M10 13c0 1.7 1.3 3 3 3v-7h3l-4.5-5-4.5 5h3v4zM17 13v5h-10c-.6 0-1-.4-1-1v-4h-2v4c0 1.9 1.3 3 3 3h12v-7h-2z" /> +</svg> diff --git a/modules/entrypoint/styles/ext.cx.contributions.less b/modules/entrypoint/styles/ext.cx.contributions.less index 0d219e6..ba6fde3 100644 --- a/modules/entrypoint/styles/ext.cx.contributions.less +++ b/modules/entrypoint/styles/ext.cx.contributions.less @@ -1,37 +1,58 @@ @import "mediawiki.mixins"; .cx-contributions { - position: relative; -} - -.cx-contributions__trigger { - &:after { - padding-left: 10px; - display: inline-block; - height: 10px; - width: 20px; - content: ''; - // PNG currently broken due to different size - .background-image-svg('../images/dropdown.svg', '../images/dropdown.png'); - background-position: right center; - background-repeat: no-repeat; - } -} - -.cx-contributions__menu { - position: absolute; - border: 1px solid #ccc; - box-shadow: 0 5px 10px rgba(0,0,0,0.2); - list-style: none; - margin: 0; - color: black; - background-color: white; - &> li { - padding: 5px; - } - - &> li:hover { + padding: 0; + margin: 30px 0; + button { + position: relative; + margin: 0; + padding: 50px 20px 10px 10px; cursor: pointer; - background-color: darken( white, 10% ); + background-color: #fff; + background-repeat: no-repeat; + background-position: 50% 20%; + background-size: 32px; + border: 1px solid #ccc; + font-size: 1em; + min-width: 150px; + + &:first-child { + border-radius: 2px 0 0 2px; + border-right: 0; + } + &:last-child { + border-radius: 0 2px 2px 0; + border-left: 0; + } + &:hover { + background-color: #eee; + } + &.cx-contributions-new-article { + .background-image-svg('../images/editarticle.svg', '../images/editarticle.png'); + } + &.cx-contributions-translation { + .background-image-svg('../images/translation.svg', '../images/translation.png'); + } + &.cx-contributions-upload { + .background-image-svg('../images/upload.svg', '../images/upload.png'); + } + &.cx-contributions-new::before { + content: ""; + position: absolute; + top: 0%; + right: 0; + width: 0; + height: 0; + border-top: 21px solid #4682B4; + border-left: 22px solid transparent; + } + &.cx-contributions-new::after { + content: "*"; + position: absolute; + color: #fff; + top: 0%; + right: 10px; + width: 0%; + } } -} \ No newline at end of file +} -- To view, visit https://gerrit.wikimedia.org/r/200120 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If6670eb05106516637221a24f0a64e084f27626b Gerrit-PatchSet: 7 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: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits