Diferencia entre revisiones de «MediaWiki:Common.js»
Ir a la navegación
Ir a la búsqueda
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: паааатааааааааааааааааааа") |
Sin resumen de edición |
||
Línea 1: | Línea 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
// #region I18n accessor factory | |||
// This takes in a module name and a localised string table (map[language -> map[name -> string]]), | |||
// and returns a function to look-up a string by its name. | |||
// Translations should either be put into the script's string table, or provided locally via | |||
// [[MediaWiki:Common.js]]. | |||
// To provide a string locally, provide window.arkLocalI18n (map[module -> map[name -> string]]). | |||
window.arkCreateI18nInterface = function(module, strings) { | |||
var lang = mw.config.get('wgPageContentLanguage'); | |||
var localStrings = window.arkLocalI18n && window.arkLocalI18n[module]; | |||
return function (key) { | |||
return ( // try from local store | |||
(localStrings && localStrings[key]) | |||
// try from script store | |||
|| (strings[lang] && strings[lang][key] || strings['en'][key]) | |||
// fallback | |||
|| '<'+key+'>' ); | |||
}; | |||
}; | |||
window.arkCreateI18nInterfaceEx = function ( module, strings ) { | |||
var lang = mw.config.get( 'wgPageContentLanguage' ); | |||
var localStrings = window.arkLocalI18n && window.arkLocalI18n[ module ]; | |||
return Object.assign( | |||
{}, | |||
strings[ 'en' ], | |||
strings[ lang ], | |||
localStrings | |||
); | |||
}; | |||
// #endregion | |||
// #region importArticles with transparent EN interwiki support | |||
// Strip "en:" prefix on EN wiki, or prepend "u:" on translations | |||
window.arkIsEnglishWiki = mw.config.get('wgContentLanguage') == 'en'; | |||
window.arkImportArticles = function ( articles ) { | |||
var mLocal = [], mGlobal = []; | |||
articles.forEach( function ( item ) { | |||
if ( item.startsWith( 'en:' ) ) { | |||
mGlobal.push( item.slice( 3 ) ); | |||
} else { | |||
mLocal.push( item ); | |||
} | |||
} ); | |||
if ( arkIsEnglishWiki ) { | |||
mLocal = mLocal.concat( mGlobal ); | |||
mGlobal.length = 0; | |||
} | |||
// Load global modules | |||
if ( mGlobal.length ) { | |||
mw.loader.load( '/load.php?lang=en&modules=' + encodeURIComponent( mGlobal.join( '|' ) ) | |||
+ '&skin=vector&version=ztntf' + ( mw.config.get( 'debug' ) ? '&debug=1' : '' ) ); | |||
} | |||
// Load local modules | |||
if ( mLocal.length ) { | |||
// Race warning: the ImportArticles extension script might be loaded after our script. Require it before executing the call. | |||
mw.loader.using( 'ext.importarticles', function () { | |||
importArticles( { type: 'script', articles: mLocal } ); | |||
} ); | |||
} | |||
}; |
Revisión del 11:32 25 abr 2024
/* Any JavaScript here will be loaded for all users on every page load. */
// #region I18n accessor factory
// This takes in a module name and a localised string table (map[language -> map[name -> string]]),
// and returns a function to look-up a string by its name.
// Translations should either be put into the script's string table, or provided locally via
// [[MediaWiki:Common.js]].
// To provide a string locally, provide window.arkLocalI18n (map[module -> map[name -> string]]).
window.arkCreateI18nInterface = function(module, strings) {
var lang = mw.config.get('wgPageContentLanguage');
var localStrings = window.arkLocalI18n && window.arkLocalI18n[module];
return function (key) {
return ( // try from local store
(localStrings && localStrings[key])
// try from script store
|| (strings[lang] && strings[lang][key] || strings['en'][key])
// fallback
|| '<'+key+'>' );
};
};
window.arkCreateI18nInterfaceEx = function ( module, strings ) {
var lang = mw.config.get( 'wgPageContentLanguage' );
var localStrings = window.arkLocalI18n && window.arkLocalI18n[ module ];
return Object.assign(
{},
strings[ 'en' ],
strings[ lang ],
localStrings
);
};
// #endregion
// #region importArticles with transparent EN interwiki support
// Strip "en:" prefix on EN wiki, or prepend "u:" on translations
window.arkIsEnglishWiki = mw.config.get('wgContentLanguage') == 'en';
window.arkImportArticles = function ( articles ) {
var mLocal = [], mGlobal = [];
articles.forEach( function ( item ) {
if ( item.startsWith( 'en:' ) ) {
mGlobal.push( item.slice( 3 ) );
} else {
mLocal.push( item );
}
} );
if ( arkIsEnglishWiki ) {
mLocal = mLocal.concat( mGlobal );
mGlobal.length = 0;
}
// Load global modules
if ( mGlobal.length ) {
mw.loader.load( '/load.php?lang=en&modules=' + encodeURIComponent( mGlobal.join( '|' ) )
+ '&skin=vector&version=ztntf' + ( mw.config.get( 'debug' ) ? '&debug=1' : '' ) );
}
// Load local modules
if ( mLocal.length ) {
// Race warning: the ImportArticles extension script might be loaded after our script. Require it before executing the call.
mw.loader.using( 'ext.importarticles', function () {
importArticles( { type: 'script', articles: mLocal } );
} );
}
};