From 965ffc3b1a78b438b8171442edd64b85672421f0 Mon Sep 17 00:00:00 2001 From: NikG Date: Wed, 11 Jan 2023 18:05:29 +0200 Subject: [PATCH] Add language settings button inside dropdown for non-content pages NOTE: This patch is identical to patch with change-id: Ifdf2a529b30e5a2df8867b606a525c9f7b3bdb6c The above patch has been merged but reverted because of the usage of '$skin->getTemplateDate()' method, which should be avoided. The current patch replaces the usage of this method, with the usage of the output page title ($out->getTitle()). All the rest of the code has been kept the same. Bug: T316559 Change-Id: Ibef9f6fd46d9055c3e0865905fb8aa8d031c1940 --- includes/Hooks.php | 6 ++++ resources/css/ext.uls.interface.less | 4 +++ resources/js/ext.uls.interface.js | 47 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/includes/Hooks.php b/includes/Hooks.php index 5f2bf575..f1cf19a9 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -170,6 +170,12 @@ class Hooks implements if ( $this->isEnabled() ) { // Enable UI language selection for the user. $out->addModules( 'ext.uls.interface' ); + + $title = $out->getTitle(); + $isContentPage = $title && $title->exists() && $title->isContentPage(); + // if current page is not a content page, we should use a different layout inside ULS + // according to T316559. Add JS config variable here, to let frontend know, when this is the case + $config[ 'wgULSisLanguageSelectorEmpty' ] = !$isContentPage; } // This is added here, and not in onResourceLoaderGetConfigVars to allow skins and extensions diff --git a/resources/css/ext.uls.interface.less b/resources/css/ext.uls.interface.less index a730eaa0..81dd2a6f 100644 --- a/resources/css/ext.uls.interface.less +++ b/resources/css/ext.uls.interface.less @@ -70,3 +70,7 @@ margin: 1em 0; } } + +.empty-language-selector__language-settings-button { + margin: 12px; +} diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 4f98290a..ded3a40e 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -717,7 +717,54 @@ } } + /** + * The new Vector 2022 skin uses a less prominent language button for non-content pages. + * For these pages, the ULS should not be displayed, but a dropdown with an appropriate message + * should appear. The UniversalLanguageSelector extension should add a button to open the + * language settings, inside this dropdown. + * This method adds this button inside the dropdown. + */ + function addLanguageSettingsToNonContentPages() { + var $languageBtn = $( '#p-lang-btn' ); + var clickHandler = function ( event ) { + event.stopPropagation(); + mw.loader.using( languageSettingsModules ).then( function () { + $( event.target ).languagesettings( { + autoOpen: true, + onPosition: function () { + var offset = $languageBtn.offset(); + var top = offset.top + $languageBtn.outerHeight(); + var right = $( window ).width() - offset.left - $languageBtn.outerWidth(); + return { top: top, right: right }; + } + } ); + } ); + }; + // the first time the language button is clicked inside a non-content page, + // we should add the "Open language settings" button inside the dropdown + $languageBtn.one( 'mouseover', function () { + mw.loader.using( [ 'oojs-ui-widgets', 'oojs-ui.styles.icons-interactions', 'ext.uls.messages' ] ) + .done( function () { + var actionButton = new ActionsMenuItem( + 'settings', + $.i18n( 'ext-uls-actions-menu-language-settings-item-label' ), + clickHandler, + null + ).render(); + actionButton.$element.addClass( 'empty-language-selector__language-settings-button' ); + var $emptyLanguageSelectorBody = $( '.mw-portlet-empty-language-selector-body' ); + $emptyLanguageSelectorBody.after( actionButton.$element ); + } ); + } ); + } function init() { + // if it's not Vector skin, nothing to be done here + if ( mw.config.get( 'skin' ) === 'vector-2022' && mw.config.get( 'wgULSisLanguageSelectorEmpty' ) ) { + // if this is a non-content page, we should add the "Open language settings" button + // inside the language dropdown + addLanguageSettingsToNonContentPages(); + } + initLanguageChangeUndoTooltip(); initIme();