Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/103065


Change subject: Hygiene: Cleanup cookie usage in MobileFrontend
......................................................................

Hygiene: Cleanup cookie usage in MobileFrontend

use jquery.cookie
Kill test which is not useful.

Change-Id: I7e385ad0fa6e12e8c5653f1e9e4b5634ea07ab77
---
M includes/Resources.php
M javascripts/common/settings.js
M tests/javascripts/common/test_settings.js
3 files changed, 5 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/65/103065/1

diff --git a/includes/Resources.php b/includes/Resources.php
index 80a7de6..aecf8d1 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -177,6 +177,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..0c63327 100644
--- a/javascripts/common/settings.js
+++ b/javascripts/common/settings.js
@@ -1,4 +1,4 @@
-( function( M ) {
+( function( M, $ ) {
 
 M.settings = ( function() {
        var supportsLocalStorage;
@@ -11,46 +11,11 @@
        }
 
        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 } );
        }
 
        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 +32,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..12e91e2 100644
--- a/tests/javascripts/common/test_settings.js
+++ b/tests/javascripts/common/test_settings.js
@@ -9,15 +9,6 @@
                "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() {
        var cookie_name = 'test_cookies_module', cookieVal;
        MFEB.writeCookie( cookie_name, "", -1 );

-- 
To view, visit https://gerrit.wikimedia.org/r/103065
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e385ad0fa6e12e8c5653f1e9e4b5634ea07ab77
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to