Support UI language change when global preferences are present
Notable changes: * First query global preferences to detect if global language setting is in use. If there is no global language setting, or if GlobalPreferences extension is not installed, it will fall back to changing the language as usual. If global language setting is found, it will add an override instead. * If a local override is added, the undo tooltip is different and links to the global preferences page. The task design shows mw.notify style popup located on a bottom right corner (LTR). I deviate from the design and re-use the old undo tooltip with a different message instead, for consistency. The message is chosen depending on whether local storage value `uls-gp` is set to '1' (set in mw.uls.changeLanguage). * I removed one use of deprecated mediawiki.api.options module. One other use still remains. * I changed tooltip text generation from html acrobatics to use mw.message.parseDom. Because of that I also had to move the click handler to avoid buildup of click handlers. * In message documentation fixed acronym -> autonym. Bug: T198206 Change-Id: Ie2ed792e222be919522bd1cdea98042515a0619d
This commit is contained in:
committed by
jenkins-bot
parent
2e5e57d92c
commit
fa9cea4627
@@ -50,23 +50,49 @@
|
||||
}
|
||||
|
||||
deferred.done( function () {
|
||||
var api;
|
||||
var api = new mw.Api();
|
||||
|
||||
if ( mw.user.isAnon() ) {
|
||||
changeLanguageAnon();
|
||||
return;
|
||||
}
|
||||
|
||||
api = new mw.Api();
|
||||
api.saveOption( 'language', language )
|
||||
.done( function () {
|
||||
location.reload();
|
||||
} )
|
||||
.fail( function () {
|
||||
// Set options failed. Maybe the user has logged off.
|
||||
// Continue like anonymous user and set cookie.
|
||||
changeLanguageAnon();
|
||||
// TODO We can avoid doing this query if we know global preferences are not enabled
|
||||
api.get( {
|
||||
action: 'query',
|
||||
meta: 'globalpreferences',
|
||||
gprprop: 'preferences'
|
||||
} ).then( function ( res ) {
|
||||
// Check whether global preferences are in use. If they are not, `res.query` is
|
||||
// an empty object. `res` will also contain warnings about unknown parameters.
|
||||
try {
|
||||
return !!res.query.globalpreferences.preferences.language;
|
||||
} catch ( e ) {
|
||||
return false;
|
||||
}
|
||||
} ).then( function ( hasGlobalPreference ) {
|
||||
var apiModule;
|
||||
|
||||
if ( hasGlobalPreference ) {
|
||||
apiModule = 'globalpreferenceoverrides';
|
||||
mw.storage.set( 'uls-gp', '1' );
|
||||
} else {
|
||||
apiModule = 'options';
|
||||
mw.storage.remove( 'uls-gp' );
|
||||
}
|
||||
|
||||
return api.postWithToken( 'csrf', {
|
||||
action: apiModule,
|
||||
optionname: 'language',
|
||||
optionvalue: language
|
||||
} );
|
||||
} ).done( function () {
|
||||
location.reload();
|
||||
} ).fail( function () {
|
||||
// Setting the option failed. Maybe the user has logged off.
|
||||
// Continue like anonymous user and set cookie.
|
||||
changeLanguageAnon();
|
||||
} );
|
||||
} );
|
||||
|
||||
mw.hook( 'mw.uls.interface.language.change' ).fire( language, deferred );
|
||||
|
||||
Reference in New Issue
Block a user