2021-07-26 21:00:38 +00:00
|
|
|
/**
|
2022-10-17 20:09:53 +00:00
|
|
|
* Copies interwiki links to main menu
|
2021-07-26 21:00:38 +00:00
|
|
|
*
|
|
|
|
* Temporary solution to T287206, can be removed when the new ULS built in Vue.js
|
|
|
|
* has been released and contains this
|
|
|
|
*/
|
2022-10-17 20:09:53 +00:00
|
|
|
function addInterwikiLinkToMainMenu() {
|
2023-05-31 18:04:38 +00:00
|
|
|
const editLink = /** @type {HTMLElement|null} */ (
|
|
|
|
document.querySelector( '#p-lang-btn .wbc-editpage' )
|
|
|
|
);
|
2023-03-07 04:15:25 +00:00
|
|
|
|
2023-04-12 22:37:36 +00:00
|
|
|
if ( !editLink ) {
|
2023-03-07 04:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-04-12 22:37:36 +00:00
|
|
|
const title = editLink.getAttribute( 'title' ) || '';
|
2023-03-07 04:15:25 +00:00
|
|
|
|
2023-04-11 17:22:58 +00:00
|
|
|
const addInterlanguageLink = mw.util.addPortletLink(
|
2023-03-07 04:15:25 +00:00
|
|
|
'p-tb',
|
2023-04-12 22:37:36 +00:00
|
|
|
editLink.getAttribute( 'href' ) || '#',
|
2023-03-07 04:15:25 +00:00
|
|
|
// Original text is "Edit links".
|
|
|
|
// Since its taken out of context the title is more descriptive.
|
2023-03-28 18:45:35 +00:00
|
|
|
title,
|
2023-03-07 04:15:25 +00:00
|
|
|
'wbc-editpage',
|
2023-03-28 18:45:35 +00:00
|
|
|
title
|
2023-03-07 04:15:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( addInterlanguageLink ) {
|
2024-06-06 15:22:05 +00:00
|
|
|
addInterlanguageLink.addEventListener( 'click', ( /** @type {Event} */ e ) => {
|
2023-03-07 04:15:25 +00:00
|
|
|
e.preventDefault();
|
|
|
|
// redirect to the detached and original edit link
|
2023-05-31 18:04:38 +00:00
|
|
|
editLink.click();
|
2023-03-07 04:15:25 +00:00
|
|
|
} );
|
2021-07-26 21:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 15:40:31 +00:00
|
|
|
/**
|
|
|
|
* Checks if ULS is disabled, and makes sure the language dropdown continues
|
|
|
|
* to work if it is.
|
|
|
|
*/
|
|
|
|
function checkIfULSDisabled() {
|
|
|
|
const langModuleState = mw.loader.getState( 'ext.uls.interface' );
|
|
|
|
if ( langModuleState === null || langModuleState === 'registered' ) {
|
|
|
|
document.documentElement.classList.add( 'vector-uls-disabled' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 21:32:25 +00:00
|
|
|
/**
|
|
|
|
* Initialize the language button.
|
|
|
|
*/
|
|
|
|
module.exports = function () {
|
2023-07-07 15:40:31 +00:00
|
|
|
checkIfULSDisabled();
|
2022-10-17 20:09:53 +00:00
|
|
|
addInterwikiLinkToMainMenu();
|
2021-03-01 21:32:25 +00:00
|
|
|
};
|