2018-11-12 19:22:46 +00:00
|
|
|
( function () {
|
2013-03-18 19:56:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
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',
|
|
|
|
attrName: 'data-revision-id',
|
2013-04-25 20:43:00 +00:00
|
|
|
|
2015-05-04 19:13:43 +00:00
|
|
|
load: function () {
|
2014-02-26 02:12:47 +00:00
|
|
|
var cookie = $.cookie( this.cookieName );
|
|
|
|
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
|
|
|
|
2015-05-04 19:13:43 +00:00
|
|
|
push: function ( $thankLink ) {
|
2014-02-26 02:12:47 +00:00
|
|
|
var saved = this.load();
|
|
|
|
saved.push( $thankLink.attr( this.attrName ) );
|
|
|
|
if ( saved.length > this.maxHistory ) { // prevent forever growing
|
|
|
|
saved = saved.slice( saved.length - this.maxHistory );
|
|
|
|
}
|
|
|
|
$.cookie( this.cookieName, escape( saved.join( ',' ) ) );
|
|
|
|
},
|
2013-06-08 05:06:46 +00:00
|
|
|
|
2015-05-04 19:13:43 +00:00
|
|
|
contains: function ( $thankLink ) {
|
2019-12-12 11:36:24 +00:00
|
|
|
return this.load().indexOf( $thankLink.attr( this.attrName ) ) !== -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
|
|
|
}() );
|