jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Cleanup cookie usage in MobileFrontend
......................................................................
Hygiene: Cleanup cookie usage in MobileFrontend
use jquery.cookie
Kill test which is not useful.
Also remove unused removeCookie method.
Add deprecation FIXME to remove these in future
Change-Id: I7e385ad0fa6e12e8c5653f1e9e4b5634ea07ab77
---
M includes/Resources.php
M javascripts/common/settings.js
M tests/javascripts/common/test_settings.js
3 files changed, 8 insertions(+), 49 deletions(-)
Approvals:
JGonera: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Resources.php b/includes/Resources.php
index 9cebe5c..a53b94a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -184,6 +184,7 @@
'mobile.head',
'mobile.templates',
'mobile.user',
+ 'jquery.cookie',
),
'scripts' => array(
'javascripts/common/Router.js',
diff --git a/javascripts/common/settings.js b/javascripts/common/settings.js
index b058cfb..29cca26 100644
--- a/javascripts/common/settings.js
+++ b/javascripts/common/settings.js
@@ -1,4 +1,4 @@
-( function( M ) {
+( function( M, $ ) {
M.settings = ( function() {
var supportsLocalStorage;
@@ -10,47 +10,14 @@
supportsLocalStorage = false;
}
+ // FIXME: Deprecate - use $.cookie instead
function writeCookie( name, value, days, path, domain ) {
- var date, expires, cookie;
- if ( days ) {
- date = new Date();
- date.setTime( date.getTime() + ( days * 24 * 60 * 60
*1000 ) );
- expires = '; expires=' + date.toGMTString();
- } else {
- expires = '';
- }
-
- if ( typeof path === 'undefined' ) {
- path = '/';
- }
-
- cookie = name + '=' + value + expires + '; path=' + path;
-
- if ( typeof domain !== 'undefined' ) {
- cookie = cookie + '; domain=' + domain;
- }
- document.cookie = cookie;
+ $.cookie( name, value, { path: path, expires: days, domain:
domain } );
}
+ // FIXME: Deprecate - use $.cookie instead
function readCookie( name ) {
- var nameVA = name + '=',
- ca = document.cookie.split( ';' ),
- c, i;
- for( i=0; i < ca.length; i++ ) {
- c = ca[i];
- while ( c.charAt(0) === ' ' ) {
- c = c.substring( 1, c.length );
- }
- if ( c.indexOf( nameVA ) === 0 ) {
- return c.substring( nameVA.length, c.length );
- }
- }
- return null;
- }
-
- function removeCookie( name ) {
- writeCookie( name, '', -1 );
- return null;
+ return $.cookie( name );
}
function saveUserSetting( name, value, useCookieFallback ) {
@@ -67,11 +34,10 @@
return {
getUserSetting: getUserSetting,
readCookie: readCookie,
- removeCookie: removeCookie,
saveUserSetting: saveUserSetting,
supportsLocalStorage: supportsLocalStorage,
writeCookie: writeCookie
};
}());
-}( mw.mobileFrontend ));
+}( mw.mobileFrontend, jQuery ) );
diff --git a/tests/javascripts/common/test_settings.js
b/tests/javascripts/common/test_settings.js
index a34495f..740516e 100644
--- a/tests/javascripts/common/test_settings.js
+++ b/tests/javascripts/common/test_settings.js
@@ -1,4 +1,5 @@
( function ( MFEB ) {
+// FIXME: Deprecate writeCookie and readCookie removing need for these tests
QUnit.module( 'MobileFrontend settings.js: cookies' );
QUnit.test( 'read and write cookies', 1, function() {
@@ -7,15 +8,6 @@
cookieVal = MFEB.readCookie( cookie_name );
strictEqual(cookieVal, "yes",
"Are you running off localhost?");
-});
-
-QUnit.test( 'read and write cookies with spaces', 1, function() {
- var cookie_name = 'test_cookies_module', cookieVal;
- MFEB.writeCookie( cookie_name, ' yes this has spaces ', 40000 );
- MFEB.writeCookie( cookie_name + '2', ' yes this has spaces ',
40000 );
- cookieVal = MFEB.readCookie( cookie_name );
- strictEqual(cookieVal, "yes this has spaces",
- "spaces are kept and trailing whitespace is removed");
});
QUnit.test( 'remove cookie via write', 1, function() {
--
To view, visit https://gerrit.wikimedia.org/r/103065
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7e385ad0fa6e12e8c5653f1e9e4b5634ea07ab77
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits