Use jquery.jStorage for saving preferences of anonymous users
Change-Id: I36f9f13a3468a11e05d1e1bb59b1841aa3464a24
This commit is contained in:
committed by
Gerrit Code Review
parent
bfcb50f86a
commit
b845045070
@@ -83,7 +83,7 @@ $wgResourceModules['ext.uls.preferences'] = array(
|
|||||||
'remoteExtPath' => 'UniversalLanguageSelector',
|
'remoteExtPath' => 'UniversalLanguageSelector',
|
||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
'mediawiki.user',
|
'mediawiki.user',
|
||||||
'jquery.json',
|
'jquery.jStorage',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* ULS preferences system for MediaWiki.
|
* ULS preferences system for MediaWiki.
|
||||||
* Cookies for anonymous users, preferences for logged in users.
|
* Local storage for anonymous users, preferences for logged in users.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
|
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
|
||||||
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
|
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ULSPreferences = function ( group ) {
|
var ULSPreferences = function ( group ) {
|
||||||
this.cookieName = this.preferenceName = 'uls-preferences';
|
this.preferenceName = 'uls-preferences';
|
||||||
this.username = mw.user.getName();
|
this.username = mw.user.getName();
|
||||||
this.isAnon = mw.user.isAnon();
|
this.isAnon = mw.user.isAnon();
|
||||||
this.preferences = null;
|
this.preferences = null;
|
||||||
@@ -36,8 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
init: function () {
|
init: function () {
|
||||||
if ( this.isAnon ) {
|
if ( this.isAnon ) {
|
||||||
this.cookie = $.cookie( this.cookieName );
|
this.preferences = $.jStorage.get( this.preferenceName );
|
||||||
this.preferences = $.parseJSON( this.cookie );
|
|
||||||
} else {
|
} else {
|
||||||
var options = mw.user.options.get( this.preferenceName );
|
var options = mw.user.options.get( this.preferenceName );
|
||||||
this.preferences = $.parseJSON( options );
|
this.preferences = $.parseJSON( options );
|
||||||
@@ -75,12 +74,8 @@
|
|||||||
var that = this;
|
var that = this;
|
||||||
callback = callback || $.noop();
|
callback = callback || $.noop();
|
||||||
if ( this.isAnon ) {
|
if ( this.isAnon ) {
|
||||||
// Anonymous user- Save preferences in cookie
|
// Anonymous user- Save preferences in local storage
|
||||||
$.cookie( this.cookieName, $.toJSON( this.preferences ), {
|
$.jStorage.set( this.preferenceName, this.preferences );
|
||||||
expires: 30,
|
|
||||||
HttpOnly: true,
|
|
||||||
path: '/'
|
|
||||||
} );
|
|
||||||
callback.call( this, true );
|
callback.call( this, true );
|
||||||
} else {
|
} else {
|
||||||
// Logged in user. Use MW apis to change preferences
|
// Logged in user. Use MW apis to change preferences
|
||||||
|
|||||||
Reference in New Issue
Block a user