Merge "Do not load jquery.jStorage for logged in users"

This commit is contained in:
jenkins-bot
2013-11-12 10:43:57 +00:00
committed by Gerrit Code Review
3 changed files with 18 additions and 7 deletions

View File

@@ -117,6 +117,10 @@ $wgResourceModules['ext.uls.interface'] = array(
'position' => 'top',
) + $resourcePaths;
// Anonymous users need 'jquery.jStorage' module for client side preference persistence.
$wgResourceModules['ext.uls.interface.anon'] = $wgResourceModules['ext.uls.interface'];
$wgResourceModules['ext.uls.interface.anon']['dependencies'][] = 'jquery.jStorage';
$wgResourceModules['ext.uls.languagesettings'] = array(
'scripts' => 'resources/js/ext.uls.languagesettings.js',
'styles' => 'resources/css/ext.uls.languagesettings.css',
@@ -134,7 +138,10 @@ $wgResourceModules['ext.uls.preferences'] = array(
'dependencies' => array(
'mediawiki.user',
'mediawiki.api',
'jquery.jStorage',
'jquery.json',
// This is quite a big module and only needed for anons.
// Loaded conditionally in ext.uls.interface(.anon).
//'jquery.jStorage',
),
) + $resourcePaths;

View File

@@ -67,7 +67,11 @@ class UniversalLanguageSelectorHooks {
if ( self::isToolbarEnabled( $out->getUser() ) ) {
// Enable UI language selection for the user.
$out->addModules( 'ext.uls.interface' );
if ( $out->getUser()->isAnon() ) {
$out->addModules( 'ext.uls.interface.anon' );
} else {
$out->addModules( 'ext.uls.interface' );
}
}
return true;

View File

@@ -115,13 +115,14 @@
* Initialize
*/
init: function () {
var options;
if ( this.isAnon ) {
this.preferences = $.jStorage.get( this.preferenceName );
this.preferences = $.jStorage.get( this.preferenceName ) || {};
} else {
var options = mw.user.options.get( this.preferenceName );
this.preferences = $.parseJSON( options );
options = mw.user.options.get( this.preferenceName );
this.preferences = $.parseJSON( options ) || {};
}
this.preferences = this.preferences || {};
},
/**
@@ -157,7 +158,6 @@
$.jStorage.set( this.preferenceName, this.preferences );
callback.call( this, true );
} else {
// Logged in user. Use MW APIs to change preferences
saveOptionsWithToken( {
action: 'options',