* Remove redundant 'path' parameter (handled by mw.cookie)
* Remove redundant 'expires' parameter (handled by mw.cookie)
* Return value for absent cookie is now reliably 'null'.
This changes the cookie name due to mw.cookie adding the standard
cookie prefix. This will cause existing values to be lost. Make
use of this oppertunity to rename some cookie names.
* mw_hidetoc -> {wikiprefix} hidetoc
* mediaWiki.user.sessionId -> {wikiprefix} mwuser-sessionId
* mediaWiki.user.bucket -> {wikiprefix} mwuser-bucket
This is a re-submission of
a4d3d3b427713, which was reverted due
to T101857. Commit amended to use "sessionId" instead of "session".
Bug: T67384
Change-Id: Ibe88778cf3b6db90b3875c89305ffba53ac84104
'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' ),
),
'mediawiki.toc' => array(
'scripts' => 'resources/src/mediawiki/mediawiki.toc.js',
- 'dependencies' => 'jquery.cookie',
+ 'dependencies' => 'mediawiki.cookie',
'messages' => array( 'showtoc', 'hidetoc' ),
'targets' => array( 'desktop', 'mobile' ),
),
'mediawiki.user' => array(
'scripts' => 'resources/src/mediawiki/mediawiki.user.js',
'dependencies' => array(
- 'jquery.cookie',
+ 'mediawiki.cookie',
'mediawiki.api',
'user.options',
'user.tokens',
mw.cookie = {
/**
- * Sets or deletes a cookie.
+ * Set or delete 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
},
/**
- * Gets the value of a cookie.
+ * Get 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} If the cookie exists, then the value of the
+ * @return {string|null|Mixed} If the cookie exists, then the value of the
* cookie, otherwise `defaultValue`
*/
get: function ( key, prefix, defaultValue ) {
$tocList.slideDown( 'fast' );
$tocToggleLink.text( mw.msg( 'hidetoc' ) );
$toc.removeClass( 'tochidden' );
- $.cookie( 'mw_hidetoc', null, {
- expires: 30,
- path: '/'
- } );
+ mw.cookie.set( 'hidetoc', null );
} else {
$tocList.slideUp( 'fast' );
$tocToggleLink.text( mw.msg( 'showtoc' ) );
$toc.addClass( 'tochidden' );
- $.cookie( 'mw_hidetoc', '1', {
- expires: 30,
- path: '/'
- } );
+ mw.cookie.set( 'hidetoc', '1' );
}
}
// 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 = $.cookie( 'mw_hidetoc' ) === '1';
+ hideToc = mw.cookie.get( 'hidetoc' ) === '1';
$tocToggleLink = $( '<a href="#" id="togglelink"></a>' )
.text( hideToc ? mw.msg( 'showtoc' ) : mw.msg( 'hidetoc' ) )
* @return {string} Random session ID
*/
sessionId: function () {
- var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
- if ( sessionId === undefined || sessionId === null ) {
+ var sessionId = mw.cookie.get( 'mwuser-sessionId' );
+ if ( sessionId === null ) {
sessionId = mw.user.generateRandomSessionId();
- $.cookie( 'mediaWiki.user.sessionId', sessionId, { expires: null, path: '/' } );
+ mw.cookie.set( 'mwuser-sessionId', sessionId, { expires: null } );
}
return sessionId;
},
expires: 30
}, options || {} );
- cookie = $.cookie( 'mediaWiki.user.bucket:' + key );
+ cookie = mw.cookie.get( 'mwuser-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 ) {
}
}
- $.cookie(
- 'mediaWiki.user.bucket:' + key,
+ mw.cookie.set(
+ 'mwuser-bucket:' + key,
version + ':' + bucket,
- { path: '/', expires: Number( options.expires ) }
+ { expires: Number( options.expires ) * 86400 }
);
}
( function ( mw, $ ) {
QUnit.module( 'mediawiki.toc', QUnit.newMwEnvironment( {
setup: function () {
- // Prevent live cookies like mw_hidetoc=1 from interferring with the test
+ // Prevent live cookies from interferring with the test
this.stub( $, 'cookie' ).returns( null );
}
} ) );