jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/393940 )

Change subject: Post refactor cleanup
......................................................................


Post refactor cleanup

- Remove unused and duplicated "New translation" messages.

- Rename message keys used in newly introduced SourcePageSelector and
SelectedSourcePage classes.
This is done so old names and concepts (like embedded)
are no longer used, to avoid confusion for newcomers to codebase.

- Improve message documentation to remove obsolete concepts as arbitrary
source page title.

- Take further measures to prevent selection of same source and target
language in some obscure cases, when there are little valid source
languages to choose from when swapping languages.

Change-Id: I1d8c2f655ab99fb985d63fcd74231f290e4ae158
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/source/ext.cx.SelectedSourcePage.js
M modules/source/ext.cx.SourcePageSelector.js
M modules/stats/ext.cx.stats.js
M modules/ui/mw.cx.ui.LanguageFilter.js
M modules/ui/widgets/mw.cx.ui.TitleOptionWidget.js
8 files changed, 73 insertions(+), 59 deletions(-)

Approvals:
  jenkins-bot: Verified
  Nikerabbit: Looks good to me, approved



diff --git a/extension.json b/extension.json
index 94d4c90..204c8dc 100644
--- a/extension.json
+++ b/extension.json
@@ -351,10 +351,10 @@
                                "oojs"
                        ],
                        "messages": [
-                               
"cx-sourceselector-embedded-source-page-placeholder",
-                               
"cx-sourceselector-embedded-recent-edits-header",
-                               
"cx-sourceselector-embedded-recent-edits-no-results",
-                               "cx-sourceselector-embedded-search-no-results"
+                               "cx-source-page-selector-input-placeholder",
+                               "cx-source-page-selector-recent-edits-header",
+                               
"cx-source-page-selector-recent-edits-no-results",
+                               "cx-source-page-selector-no-search-results"
                        ]
                },
                "ext.cx.SelectedSourcePage": {
@@ -381,11 +381,11 @@
                                "oojs"
                        ],
                        "messages": [
-                               
"cx-sourceselector-dialog-button-start-translation",
-                               
"cx-sourceselector-dialog-error-page-and-title-exist",
-                               "cx-sourceselector-dialog-error-page-exists",
-                               "cx-sourceselector-dialog-error-title-in-use",
-                               
"cx-sourceselector-embedded-selected-item-pageviews",
+                               
"cx-selected-source-page-start-translation-button",
+                               
"cx-selected-source-page-error-page-and-title-exist",
+                               "cx-selected-source-page-error-page-exists",
+                               "cx-selected-source-page-error-title-in-use",
+                               "cx-selected-source-page-view-count",
                                "cx-license-agreement"
                        ]
                },
@@ -1549,7 +1549,7 @@
                                "ui/styles/mw.cx.ui.Infobar.less"
                        ],
                        "messages": [
-                               "cx-header-new-translation",
+                               "cx-create-new-translation",
                                "cx-header-all-translations",
                                "cx-special-login-error",
                                "cx-translation-target-page-exists"
@@ -2079,8 +2079,8 @@
                                
"ui/styles/widgets/mw.cx.ui.TitleOptionWidget.less"
                        ],
                        "messages": [
-                               "cx-sourceselector-missing-in-target-language",
-                               "cx-sourceselector-number-of-languages"
+                               "cx-page-missing-in-target-language",
+                               "cx-page-number-of-languages"
                        ],
                        "dependencies": [
                                "mw.cx.ui",
diff --git a/i18n/en.json b/i18n/en.json
index a1e10fd..a068046 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -25,7 +25,6 @@
        "cx-header-progressbar-text": "$1% {{PLURAL:$1|translated}}",
        "cx-header-progressbar-text-mt": "($1% from {{PLURAL:$1|machine 
translation}})",
        "cx-header-translation-center": "Translation center",
-       "cx-header-new-translation": "New translation",
        "cx-header-all-translations": "All translations",
        "cx-source-view-page": "view page",
        "cx-publish-page-success": "Page published at $1",
@@ -86,18 +85,17 @@
        "cx-tools-link-hover-tooltip": "Click to open",
        "cx-warning-unsaved-translation": "You have unsaved translations.",
        "cx-error-page-not-found": "The \"$1\" page could not be found in $2 
Wikipedia",
-       "cx-sourceselector-dialog-new-translation": "New translation",
-       "cx-sourceselector-dialog-button-start-translation": "Start 
translation",
-       "cx-sourceselector-embedded-source-page-placeholder": "Search for a 
page to translate",
-       "cx-sourceselector-dialog-error-page-and-title-exist": "This title is 
already used in [$1 $2] for [$3 a different page]",
-       "cx-sourceselector-dialog-error-page-exists": "The page [$1 already 
exists] in $2",
-       "cx-sourceselector-dialog-error-title-in-use": "The title for the new 
page is [$1 already in use]",
-       "cx-sourceselector-missing-in-target-language": "Missing in $1",
-       "cx-sourceselector-number-of-languages": "Number of languages",
-       "cx-sourceselector-embedded-selected-item-pageviews": "{{PLURAL:$1|$1 
visit per|$1 visits per|0=No visits this}} week",
-       "cx-sourceselector-embedded-recent-edits-header": "Recently edited by 
you",
-       "cx-sourceselector-embedded-recent-edits-no-results": "Think of any 
topic of your interest. You don’t need to be an expert to create a great 
translation.",
-       "cx-sourceselector-embedded-search-no-results": "No pages found for 
\"$1\" in $2",
+       "cx-selected-source-page-start-translation-button": "Start translation",
+       "cx-source-page-selector-input-placeholder": "Search for a page to 
translate",
+       "cx-selected-source-page-error-page-and-title-exist": "This title is 
already used in [$1 $2] for [$3 a different page]",
+       "cx-selected-source-page-error-page-exists": "The page [$1 already 
exists] in $2",
+       "cx-selected-source-page-error-title-in-use": "The title for the new 
page is [$1 already in use]",
+       "cx-page-missing-in-target-language": "Missing in $1",
+       "cx-page-number-of-languages": "Number of languages",
+       "cx-selected-source-page-view-count": "{{PLURAL:$1|$1 visit per|$1 
visits per|0=No visits this}} week",
+       "cx-source-page-selector-recent-edits-header": "Recently edited by you",
+       "cx-source-page-selector-recent-edits-no-results": "Think of any topic 
of your interest. You don’t need to be an expert to create a great 
translation.",
+       "cx-source-page-selector-no-search-results": "No pages found for \"$1\" 
in $2",
        "cx-mt-abuse-warning-title": "Your translation {{PLURAL:$1|contains}} 
$1% of unmodified machine-translated text",
        "cx-mt-abuse-warning-text": "Machine translation is provided only as a 
starting point. You need to make sure that the content is accurate and reads 
naturally in your language.",
        "cx-publish-captcha-title": "Security question",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index de67707..f501c72 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -34,7 +34,6 @@
        "cx-header-progressbar-text": "Text to be shown with the progress bar 
in [[Special:ContentTranslation]]. $1 is the percent of translation 
progress.\n{{Identical|Translated}}",
        "cx-header-progressbar-text-mt": "Text to be shown with the progress 
bar in [[Special:ContentTranslation]]. $1 is the estimated percent of 
machine-translated text out of all the translation text that was written so 
far.",
        "cx-header-translation-center": "Text for the translation center 
title.",
-       "cx-header-new-translation": "A link at the top of the translation 
interface to the main Special:ContentTranslation page that creates a new 
translation.\n{{Identical|New translation}}",
        "cx-header-all-translations": "A link at the top of the translation 
interface to the main [[Special:ContentTranslation]] page that lists all 
translations by the user.\n{{Identical|All translations}}",
        "cx-source-view-page": "A link that points to the source page under the 
heading of the source column.\n{{Identical|View page}}",
        "cx-publish-page-success": "Message shown when page is published 
successfully. Parameters:\n* $1 - Link to the published page",
@@ -95,18 +94,17 @@
        "cx-tools-link-hover-tooltip": "Tooltip text shown when the mouse is 
over the link with shift or control key is pressed.",
        "cx-warning-unsaved-translation": "Warning message shown when user 
tried to navigate away when translation is not saved.",
        "cx-error-page-not-found": "Error message shown when a page is not 
found in a given language wikipedia\n\nParameters:\n* $1 - the title of the 
page.\n* $2 - The language name",
-       "cx-sourceselector-dialog-new-translation": "Title of language and 
title selector on on Special:ContentTranslation.",
-       "cx-sourceselector-dialog-button-start-translation": "Button label for 
translation selector. Clicking on it starts a new translation in 
Special:ContentTranslation.",
-       "cx-sourceselector-embedded-source-page-placeholder": "Placeholder for 
the source page input field. Used on Content Translation page for new 
translation dialog and provides prompt to search for source page to start 
translation.",
-       "cx-sourceselector-dialog-error-page-and-title-exist": "An error 
message that indicates that there is page in the target wiki with the same 
title as the proposed source title and the target title is used 
elsewhere.\n\nParameters:\n* $1 - link to existing target page.\n* $2 - target 
language name.\n* $3 - link to article using proposed target title.",
-       "cx-sourceselector-dialog-error-page-exists": "An error message that 
indicates there is a page in the target wiki with the same title as the 
proposed source title.\n\nParameters:\n* $1 - link to existing target page.\n* 
$2 - target language name.",
-       "cx-sourceselector-dialog-error-title-in-use": "Error that indicates 
there is already a page in the target wiki with the same title as the proposed 
target title.\n\nParameters:\n* $1 - link to target page with same title",
-       "cx-sourceselector-missing-in-target-language": "Label appended to 
search result in Special:ContentTranslation when using the \"Start new 
article\" feature, which indicates that matching article is missing in target 
language.\n\nParameters:\n* $1 - The autonym of the language",
-       "cx-sourceselector-number-of-languages": "Tooltip shown in 
Special:ContentTranslation over the icon that shows many languages the article 
is available in",
-       "cx-sourceselector-embedded-selected-item-pageviews": "Label appended 
to selected item in New translation embedded dialog on Content Translation 
dashboard, used for representing number of page visits in the last week.\n$1 - 
number of visits per week",
-       "cx-sourceselector-embedded-recent-edits-header": "Label used in New 
translation embedded dialog, above the suggestions based on user's Recently 
edited pages.",
-       "cx-sourceselector-embedded-recent-edits-no-results": "Message used in 
New translation embedded dialog, when there are no suggestions based on user's 
Recently edited pages.",
-       "cx-sourceselector-embedded-search-no-results": "Message used in New 
translation embedded dialog, displayed when there are no search results for 
user's input query.\n\nParameters:\n* $1 - User's input query\n* $2 - Autonym 
name of currently selected source language",
+       "cx-selected-source-page-start-translation-button": "Button label 
displayed when page to be translated is selected on Content Translation 
dashboard. Clicking on it starts a new translation in 
Special:ContentTranslation.",
+       "cx-source-page-selector-input-placeholder": "Placeholder for the 
source page input field. Used on Content Translation page for \"New 
translation\" dialog and provides prompt to search for source page to start 
translation.",
+       "cx-selected-source-page-error-page-and-title-exist": "An error message 
that indicates that there is already a version of a selected page in the target 
wiki and the proposed target title is used elsewhere.\n\nParameters:\n* $1 - 
link to existing target page.\n* $2 - target language name.\n* $3 - link to 
article using proposed target title.",
+       "cx-selected-source-page-error-page-exists": "An error message that 
indicates that there is already a version of a selected page in the target 
wiki.\n\nParameters:\n* $1 - link to existing target page.\n* $2 - target 
language name.",
+       "cx-selected-source-page-error-title-in-use": "Error that indicates 
there is already a page in the target wiki with the same title as the proposed 
target title.\n\nParameters:\n* $1 - link to target page with same title",
+       "cx-page-missing-in-target-language": "Label appended to search result 
in Special:ContentTranslation when using the \"Start new article\" feature, 
which indicates that matching article is missing in target 
language.\n\nParameters:\n* $1 - The autonym of the language",
+       "cx-page-number-of-languages": "Tooltip shown in 
Special:ContentTranslation over the icon that shows how many languages the 
article is available in",
+       "cx-selected-source-page-view-count": "Label appended to selected item 
in \"New translation\" dialog on Content Translation dashboard, used for 
representing number of page visits in the last week.\n$1 - number of visits per 
week",
+       "cx-source-page-selector-recent-edits-header": "Label used in \"New 
translation\" dialog, above the suggestions based on user's recently edited 
pages.",
+       "cx-source-page-selector-recent-edits-no-results": "Message used in 
\"New translation\" dialog, when there are no suggestions based on user's 
recently edited pages.",
+       "cx-source-page-selector-no-search-results": "Message used in \"New 
translation\" dialog, displayed when there are no search results for user's 
input query.\n\nParameters:\n* $1 - User's input query\n* $2 - Autonym name of 
currently selected source language",
        "cx-mt-abuse-warning-title": "Title text shown in machine translation 
abuse card.\n* $1: Percentage of machine translation",
        "cx-mt-abuse-warning-text": "Detailed explanation of machine 
translation abuse.",
        "cx-publish-captcha-title": "Title of captcha form while publishing the 
translation",
diff --git a/modules/source/ext.cx.SelectedSourcePage.js 
b/modules/source/ext.cx.SelectedSourcePage.js
index 7804cc7..e49251a 100644
--- a/modules/source/ext.cx.SelectedSourcePage.js
+++ b/modules/source/ext.cx.SelectedSourcePage.js
@@ -108,7 +108,7 @@
                        .append( this.$messageText )
                        .hide();
 
-               translateButtonLabel = mw.msg( 
'cx-sourceselector-dialog-button-start-translation' );
+               translateButtonLabel = mw.msg( 
'cx-selected-source-page-start-translation-button' );
                this.startTranslationButton = new OO.ui.ButtonWidget( {
                        flags: [ 'primary', 'progressive' ],
                        label: translateButtonLabel
@@ -363,7 +363,7 @@
                }
 
                this.$selectedSourcePageViewsCount.text(
-                       mw.msg( 
'cx-sourceselector-embedded-selected-item-pageviews', 
mw.language.convertNumber( pageViews ) )
+                       mw.msg( 'cx-selected-source-page-view-count', 
mw.language.convertNumber( pageViews ) )
                );
        };
 
@@ -466,7 +466,7 @@
                existingTargetTitleLink = this.siteMapper.getPageUrl( 
targetLanguage, existingTargetTitle );
 
                message = mw.message(
-                       'cx-sourceselector-dialog-error-page-and-title-exist',
+                       'cx-selected-source-page-error-page-and-title-exist',
                        equivalentTargetPageLink,
                        targetLanguageDisplay,
                        existingTargetTitleLink
@@ -488,7 +488,7 @@
                targetLanguageDisplay = $.uls.data.getAutonym( targetLanguage );
 
                message = mw.message(
-                       'cx-sourceselector-dialog-error-page-exists',
+                       'cx-selected-source-page-error-page-exists',
                        equivalentTargetPageLink, targetLanguageDisplay
                );
 
@@ -507,7 +507,7 @@
                existingTargetTitleLink = this.siteMapper.getPageUrl( 
targetLanguage, existingTargetTitle );
 
                message = mw.message(
-                       'cx-sourceselector-dialog-error-title-in-use',
+                       'cx-selected-source-page-error-title-in-use',
                        existingTargetTitleLink
                );
 
diff --git a/modules/source/ext.cx.SourcePageSelector.js 
b/modules/source/ext.cx.SourcePageSelector.js
index b766300..553e57f 100644
--- a/modules/source/ext.cx.SourcePageSelector.js
+++ b/modules/source/ext.cx.SourcePageSelector.js
@@ -75,7 +75,7 @@
                        this.show();
 
                        this.$searchResultsMessage.text(
-                               mw.msg( 
'cx-sourceselector-embedded-search-no-results',
+                               mw.msg( 
'cx-source-page-selector-no-search-results',
                                        this.pageSelector.getQueryValue(),
                                        $.uls.data.getAutonym( 
this.languageFilter.getSourceLanguage() )
                                )
@@ -170,7 +170,7 @@
 
                this.pageSelector.on( 'change', function () {
                        self.$searchResultsMessage.text(
-                               mw.msg( 
'cx-sourceselector-embedded-search-no-results',
+                               mw.msg( 
'cx-source-page-selector-no-search-results',
                                        self.pageSelector.getQueryValue(),
                                        $.uls.data.getAutonym( 
self.languageFilter.getSourceLanguage() )
                                )
@@ -250,9 +250,9 @@
                this.$container.hide(); // Starts as hidden, shown on 
this.$trigger button click
 
                this.$searchResultsMessage = $( '<span>' )
-                       .text( mw.msg( 
'cx-sourceselector-embedded-search-no-results' ) );
+                       .text( mw.msg( 
'cx-source-page-selector-no-search-results' ) );
                $recentEditsMessage = $( '<span>' )
-                       .text( mw.msg( 
'cx-sourceselector-embedded-recent-edits-no-results' ) );
+                       .text( mw.msg( 
'cx-source-page-selector-recent-edits-no-results' ) );
 
                $searchMessage = $( '<div>' )
                        .addClass( 'cx-source-page-selector__search-message' )
@@ -262,7 +262,7 @@
                        .append( $recentEditsMessage );
                $recentEditsHeader = $( '<div>' )
                        .addClass( 
'cx-source-page-selector__recent-edits-header' )
-                       .text( mw.msg( 
'cx-sourceselector-embedded-recent-edits-header' ) );
+                       .text( mw.msg( 
'cx-source-page-selector-recent-edits-header' ) );
                this.$searchResults = $( '<div>' )
                        .addClass( 'cx-source-page-selector__search-results' )
                        .append( $recentEditsHeader, 
$recentEditsMessageContainer, $searchMessage );
@@ -280,7 +280,7 @@
                        siteMapper: this.siteMapper,
                        value: this.options.sourceTitle,
                        validateTitle: true,
-                       placeholder: mw.msg( 
'cx-sourceselector-embedded-source-page-placeholder' ),
+                       placeholder: mw.msg( 
'cx-source-page-selector-input-placeholder' ),
                        showRedirectTargets: true,
                        $overlay: this.$searchResults,
                        $container: this.$searchResults
diff --git a/modules/stats/ext.cx.stats.js b/modules/stats/ext.cx.stats.js
index 0b1248f..17c22d9 100644
--- a/modules/stats/ext.cx.stats.js
+++ b/modules/stats/ext.cx.stats.js
@@ -840,7 +840,7 @@
                        $( '.cx-header__bar' ).hide();
                        mw.hook( 'mw.cx.error' ).fire( mw.message( 
'cx-stats-try-contenttranslation', cxLink ) );
                } else {
-                       $header.find( '.cx-header__translation-center a' 
).text( mw.msg( 'cx-header-new-translation' ) );
+                       $header.find( '.cx-header__translation-center a' 
).text( mw.msg( 'cx-create-new-translation' ) );
                }
        } );
 }( jQuery, mediaWiki ) );
diff --git a/modules/ui/mw.cx.ui.LanguageFilter.js 
b/modules/ui/mw.cx.ui.LanguageFilter.js
index eb804ce..5b96f31 100644
--- a/modules/ui/mw.cx.ui.LanguageFilter.js
+++ b/modules/ui/mw.cx.ui.LanguageFilter.js
@@ -79,7 +79,7 @@
  * @param {number} languagesCount Number of languages
  * @return {string} wide, medium or narrow
  */
-mw.cx.ui.LanguageFilter.prototype.getUlsMenuWidth = function getUlsMenuWidth( 
languagesCount ) {
+mw.cx.ui.LanguageFilter.prototype.getUlsMenuWidth = function ( languagesCount 
) {
        var screenWidth = document.documentElement.clientWidth;
 
        // 1200px is "wide" limit for Content Translation dashboard
@@ -98,7 +98,7 @@
 /**
  * Calculate position for ULS, depending on directionality
  */
-mw.cx.ui.LanguageFilter.prototype.calculateUlsPosition = function 
calculateUlsPosition() {
+mw.cx.ui.LanguageFilter.prototype.calculateUlsPosition = function () {
        var isRtl = $( 'html' ).prop( 'dir' ) === 'rtl',
                left = this.$element.offset().left,
                right = left + this.$element.parent().width() - 
this.$menu.width(),
@@ -155,7 +155,7 @@
  * @param {string} language A language code
  */
 mw.cx.ui.LanguageFilter.prototype.setSourceLanguage = function ( language ) {
-       var currentSource;
+       var currentSource, i, length, quickListLanguages, quickListLang;
 
        if ( language === 'x-all' ) {
                language = null;
@@ -176,10 +176,22 @@
                        this.sourceLanguage = language;
                        this.setTargetLanguage( currentSource );
                } else {
-                       this.setTargetLanguage(
-                               this.$targetLanguageFilter.data( 'uls' 
).options.quickList()[ 0 ]
-                       );
+                       quickListLanguages = this.$targetLanguageFilter.data( 
'uls' ).options.quickList();
+                       for ( i = 0, length = quickListLanguages.length; i < 
length; i++ ) {
+                               quickListLang = quickListLanguages[ i ];
+
+                               if ( this.isValidTarget( quickListLang ) && 
quickListLang !== language ) {
+                                       this.setTargetLanguage( quickListLang );
+                                       break;
+                               }
+                       }
                }
+       }
+
+       // If we still don't have a valid source language, return,
+       // so we prevent same source and target language
+       if ( !this.canBeSame && language === this.getTargetLanguage() ) {
+               return;
        }
 
        this.sourceLanguage = language;
@@ -220,7 +232,7 @@
  * @param {string} language A language code
  */
 mw.cx.ui.LanguageFilter.prototype.setTargetLanguage = function ( language ) {
-       var currentTarget, quickListLanguages, i, length, quickListLang;
+       var currentTarget, i, length, quickListLanguages, quickListLang;
 
        if ( language === 'x-all' ) {
                language = null;
@@ -260,6 +272,12 @@
                }
        }
 
+       // If we still don't have a valid source language, return,
+       // so we prevent same source and target language
+       if ( !this.canBeSame && language === this.getSourceLanguage() ) {
+               return;
+       }
+
        this.targetLanguage = language;
        this.setFilterLabel( this.$targetLanguageFilter, this.targetLanguage );
 
diff --git a/modules/ui/widgets/mw.cx.ui.TitleOptionWidget.js 
b/modules/ui/widgets/mw.cx.ui.TitleOptionWidget.js
index af55412..62b7c59 100644
--- a/modules/ui/widgets/mw.cx.ui.TitleOptionWidget.js
+++ b/modules/ui/widgets/mw.cx.ui.TitleOptionWidget.js
@@ -36,7 +36,7 @@
 
                        languageIcon = new OO.ui.IconWidget( {
                                icon: 'language',
-                               iconTitle: mw.msg( 
'cx-sourceselector-number-of-languages' )
+                               iconTitle: mw.msg( 
'cx-page-number-of-languages' )
                        } );
                        languageLabel = new OO.ui.LabelWidget( {
                                label: mw.language.convertNumber( 
config.numOfLanguages )
@@ -55,7 +55,7 @@
                        this.$element.append(
                                $( '<span>' )
                                        .addClass( 
'mw-cx-widget-titleOptionWidget-missing' )
-                                       .text( mw.msg( 
'cx-sourceselector-missing-in-target-language',
+                                       .text( mw.msg( 
'cx-page-missing-in-target-language',
                                                $.uls.data.getAutonym( 
config.targetLanguage ) )
                                        )
                        );

-- 
To view, visit https://gerrit.wikimedia.org/r/393940
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1d8c2f655ab99fb985d63fcd74231f290e4ae158
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Petar.petkovic <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Petar.petkovic <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to