'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' => 'mediawiki.cookie',
+ 'dependencies' => 'jquery.cookie',
'messages' => array( 'showtoc', 'hidetoc' ),
'targets' => array( 'desktop', 'mobile' ),
),
'mediawiki.user' => array(
'scripts' => 'resources/src/mediawiki/mediawiki.user.js',
'dependencies' => array(
- 'mediawiki.cookie',
+ 'jquery.cookie',
'mediawiki.api',
'user.options',
'user.tokens',
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 ) {
$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' ) )
* @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 ) }
);
}
( 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 );
}
} ) );