2018-11-12 19:22:46 +00:00
|
|
|
( function () {
|
2014-02-26 02:12:47 +00:00
|
|
|
mw.thanks = {
|
|
|
|
// Keep track of which revisions and comments the user has already thanked for
|
|
|
|
thanked: {
|
|
|
|
maxHistory: 100,
|
|
|
|
cookieName: 'thanks-thanked',
|
2013-04-25 20:43:00 +00:00
|
|
|
|
2022-01-10 12:54:51 +00:00
|
|
|
/**
|
|
|
|
* Load thanked IDs from cookies
|
|
|
|
*
|
|
|
|
* @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
|
|
|
|
* @return {string[]} Thanks IDs
|
|
|
|
*/
|
|
|
|
load: function ( cookieName ) {
|
2024-04-19 08:37:25 +00:00
|
|
|
const cookie = mw.cookie.get( cookieName || this.cookieName );
|
2014-02-26 02:12:47 +00:00
|
|
|
if ( cookie === null ) {
|
|
|
|
return [];
|
2013-06-08 05:06:46 +00:00
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
return unescape( cookie ).split( ',' );
|
|
|
|
},
|
2013-06-08 05:06:46 +00:00
|
|
|
|
2022-01-10 12:54:51 +00:00
|
|
|
/**
|
|
|
|
* Record as ID as having been thanked
|
|
|
|
*
|
|
|
|
* @param {string} id Thanked ID
|
|
|
|
* @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
|
|
|
|
*/
|
|
|
|
push: function ( id, cookieName ) {
|
2024-04-19 08:37:25 +00:00
|
|
|
let saved = this.load();
|
2022-01-10 12:54:51 +00:00
|
|
|
saved.push( id );
|
2014-02-26 02:12:47 +00:00
|
|
|
if ( saved.length > this.maxHistory ) { // prevent forever growing
|
|
|
|
saved = saved.slice( saved.length - this.maxHistory );
|
|
|
|
}
|
2022-01-10 12:54:51 +00:00
|
|
|
mw.cookie.set( cookieName || this.cookieName, escape( saved.join( ',' ) ) );
|
2014-02-26 02:12:47 +00:00
|
|
|
},
|
2013-06-08 05:06:46 +00:00
|
|
|
|
2022-01-10 12:54:51 +00:00
|
|
|
/**
|
|
|
|
* Check if an ID has already been thanked, according to the cookie
|
|
|
|
*
|
|
|
|
* @param {string} id Thanks ID
|
|
|
|
* @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
|
|
|
|
* @return {boolean} ID has been thanked
|
|
|
|
*/
|
|
|
|
contains: function ( id, cookieName ) {
|
|
|
|
return this.load( cookieName ).indexOf( id ) !== -1;
|
2014-02-26 02:12:47 +00:00
|
|
|
}
|
2015-04-22 23:21:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve user gender
|
2016-04-22 19:47:08 +00:00
|
|
|
*
|
2015-04-22 23:21:27 +00:00
|
|
|
* @param {string} username Requested username
|
|
|
|
* @return {jQuery.Promise} A promise that resolves with the gender string, 'female', 'male', or 'unknown'
|
|
|
|
*/
|
|
|
|
getUserGender: function ( username ) {
|
|
|
|
return new mw.Api().get( {
|
|
|
|
action: 'query',
|
|
|
|
list: 'users',
|
|
|
|
ususers: username,
|
|
|
|
usprop: 'gender'
|
|
|
|
} )
|
|
|
|
.then(
|
|
|
|
function ( result ) {
|
|
|
|
return (
|
2016-04-22 19:47:08 +00:00
|
|
|
result.query.users[ 0 ] &&
|
|
|
|
result.query.users[ 0 ].gender
|
2015-04-22 23:21:27 +00:00
|
|
|
) || 'unknown';
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
return 'unknown';
|
|
|
|
}
|
|
|
|
);
|
2013-06-08 05:06:46 +00:00
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
};
|
2013-03-18 19:56:12 +00:00
|
|
|
|
2018-11-12 19:22:46 +00:00
|
|
|
}() );
|