From b8450450706a50ca1c080aa950e8538c7aee9202 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 29 Aug 2012 14:35:54 +0530 Subject: [PATCH] Use jquery.jStorage for saving preferences of anonymous users Change-Id: I36f9f13a3468a11e05d1e1bb59b1841aa3464a24 --- UniversalLanguageSelector.php | 2 +- resources/js/ext.uls.preferences.js | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index 79904891..0a009175 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -83,7 +83,7 @@ $wgResourceModules['ext.uls.preferences'] = array( 'remoteExtPath' => 'UniversalLanguageSelector', 'dependencies' => array( 'mediawiki.user', - 'jquery.json', + 'jquery.jStorage', ), ); diff --git a/resources/js/ext.uls.preferences.js b/resources/js/ext.uls.preferences.js index 2dbf1af7..6c886fea 100644 --- a/resources/js/ext.uls.preferences.js +++ b/resources/js/ext.uls.preferences.js @@ -1,6 +1,6 @@ /** * 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, * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other @@ -22,7 +22,7 @@ "use strict"; var ULSPreferences = function ( group ) { - this.cookieName = this.preferenceName = 'uls-preferences'; + this.preferenceName = 'uls-preferences'; this.username = mw.user.getName(); this.isAnon = mw.user.isAnon(); this.preferences = null; @@ -36,8 +36,7 @@ */ init: function () { if ( this.isAnon ) { - this.cookie = $.cookie( this.cookieName ); - this.preferences = $.parseJSON( this.cookie ); + this.preferences = $.jStorage.get( this.preferenceName ); } else { var options = mw.user.options.get( this.preferenceName ); this.preferences = $.parseJSON( options ); @@ -75,12 +74,8 @@ var that = this; callback = callback || $.noop(); if ( this.isAnon ) { - // Anonymous user- Save preferences in cookie - $.cookie( this.cookieName, $.toJSON( this.preferences ), { - expires: 30, - HttpOnly: true, - path: '/' - } ); + // Anonymous user- Save preferences in local storage + $.jStorage.set( this.preferenceName, this.preferences ); callback.call( this, true ); } else { // Logged in user. Use MW apis to change preferences