2013-03-18 19:56:12 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
'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 ) {
|
2014-02-26 02:12:47 +00:00
|
|
|
// $.inArray returns the index position or -1 if non-existant
|
|
|
|
if ( $.inArray( $thankLink.attr( this.attrName ), this.load() ) !== -1 ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 23:21:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve user gender
|
|
|
|
* @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 (
|
|
|
|
result.query.users[0] &&
|
|
|
|
result.query.users[0].gender
|
|
|
|
) || '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
|
|
|
|
|
|
|
} )( jQuery, mediaWiki );
|