Revert "Convert mediawiki.toc and mediawiki.user to using mw.cookie"
authorMaxSem <maxsem.wiki@gmail.com>
Thu, 28 May 2015 00:45:35 +0000 (00:45 +0000)
committerMaxSem <maxsem.wiki@gmail.com>
Thu, 28 May 2015 00:45:35 +0000 (00:45 +0000)
Caused a meltdown in production.

DO NOT MERGE COOKIE CHANGES WITHOUT AN OK FROM OPS

This reverts commit a4d3d3b4277137b765ceab8752f5562dd27928d3.

Change-Id: I40f0c2141e25ad37af0babfa95421915adce496b

resources/Resources.php
resources/src/mediawiki/mediawiki.cookie.js
resources/src/mediawiki/mediawiki.toc.js
resources/src/mediawiki/mediawiki.user.js
tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js

index 30ab739..ae5b3f9 100644 (file)
@@ -209,6 +209,7 @@ return array(
                'styles' => 'resources/src/jquery/jquery.confirmable.css',
                'dependencies' => 'mediawiki.jqueryMsg',
        ),
+       // Use mediawiki.cookie in new code, rather than jquery.cookie.
        'jquery.cookie' => array(
                'scripts' => 'resources/lib/jquery/jquery.cookie.js',
                'targets' => array( 'desktop', 'mobile' ),
@@ -1029,7 +1030,7 @@ return array(
        ),
        'mediawiki.toc' => array(
                'scripts' => 'resources/src/mediawiki/mediawiki.toc.js',
-               'dependencies' => 'mediawiki.cookie',
+               'dependencies' => 'jquery.cookie',
                'messages' => array( 'showtoc', 'hidetoc' ),
                'targets' => array( 'desktop', 'mobile' ),
        ),
@@ -1041,7 +1042,7 @@ return array(
        'mediawiki.user' => array(
                'scripts' => 'resources/src/mediawiki/mediawiki.user.js',
                'dependencies' => array(
-                       'mediawiki.cookie',
+                       'jquery.cookie',
                        'mediawiki.api',
                        'user.options',
                        'user.tokens',
index 0c0095c..8f091e4 100644 (file)
@@ -16,7 +16,7 @@
        mw.cookie = {
 
                /**
-                * Set or deletes a cookie.
+                * Sets or deletes a cookie.
                 *
                 * While this is natural in JavaScript, contrary to `WebResponse#setcookie` in PHP, the
                 * default values for the `options` properties only apply if that property isn't set
                },
 
                /**
-                * Get the value of a cookie.
+                * Gets the value of a cookie.
                 *
                 * @param {string} key
                 * @param {string} [prefix=wgCookiePrefix] The prefix of the key. If `prefix` is
                 *   `undefined` or `null`, then `wgCookiePrefix` is used
                 * @param {Mixed} [defaultValue=null]
-                * @return {string|null|Mixed} If the cookie exists, then the value of the
+                * @return {string} If the cookie exists, then the value of the
                 *   cookie, otherwise `defaultValue`
                 */
                get: function ( key, prefix, defaultValue ) {
index 78627fc..45338ea 100644 (file)
                                $tocList.slideDown( 'fast' );
                                $tocToggleLink.text( mw.msg( 'hidetoc' ) );
                                $toc.removeClass( 'tochidden' );
-                               mw.cookie.set( 'hidetoc', null );
+                               $.cookie( 'mw_hidetoc', null, {
+                                       expires: 30,
+                                       path: '/'
+                               } );
                        } else {
                                $tocList.slideUp( 'fast' );
                                $tocToggleLink.text( mw.msg( 'showtoc' ) );
                                $toc.addClass( 'tochidden' );
-                               mw.cookie.set( 'hidetoc', '1' );
+                               $.cookie( 'mw_hidetoc', '1', {
+                                       expires: 30,
+                                       path: '/'
+                               } );
                        }
                }
 
                // Only add it if there is a complete TOC and it doesn't
                // have a toggle added already
                if ( $toc.length && $tocTitle.length && $tocList.length && !$tocToggleLink.length ) {
-                       hideToc = mw.cookie.get( 'hidetoc' ) === '1';
+                       hideToc = $.cookie( 'mw_hidetoc' ) === '1';
 
                        $tocToggleLink = $( '<a href="#" id="togglelink"></a>' )
                                .text( hideToc ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) )
index c42eb9a..817c856 100644 (file)
                 * @return {string} Random session ID
                 */
                sessionId: function () {
-                       var sessionId = mw.cookie.get( 'mwuser-session' );
-                       if ( sessionId === null ) {
+                       var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
+                       if ( sessionId === undefined || sessionId === null ) {
                                sessionId = mw.user.generateRandomSessionId();
-                               mw.cookie.set( 'mwuser-session', sessionId, { expires: null } );
+                               $.cookie( 'mediaWiki.user.sessionId', sessionId, { expires: null, path: '/' } );
                        }
                        return sessionId;
                },
                                expires: 30
                        }, options || {} );
 
-                       cookie = mw.cookie.get( 'mwuser-bucket:' + key );
+                       cookie = $.cookie( 'mediaWiki.user.bucket:' + key );
 
                        // Bucket information is stored as 2 integers, together as version:bucket like: "1:2"
                        if ( typeof cookie === 'string' && cookie.length > 2 && cookie.indexOf( ':' ) !== -1 ) {
                                        }
                                }
 
-                               mw.cookie.set(
-                                       'mwuser-bucket:' + key,
+                               $.cookie(
+                                       'mediaWiki.user.bucket:' + key,
                                        version + ':' + bucket,
-                                       { expires: Number( options.expires ) * 86400 }
+                                       { path: '/', expires: Number( options.expires ) }
                                );
                        }
 
index 89eb45f..e43516b 100644 (file)
@@ -1,7 +1,7 @@
 ( function ( mw, $ ) {
        QUnit.module( 'mediawiki.toc', QUnit.newMwEnvironment( {
                setup: function () {
-                       // Prevent live cookies from interferring with the test
+                       // Prevent live cookies like mw_hidetoc=1 from interferring with the test
                        this.stub( $, 'cookie' ).returns( null );
                }
        } ) );