Debian Codegraph @

extensions/Thanks/modules/ext.thanks.thank.js

raw symbols SCIP
1 ( function () {
2 mw.thanks = {
3 // Keep track of which revisions and comments the user has already thanked for
4 thanked: {
5 maxHistory: 100,
6 cookieName: 'thanks-thanked',
7
8 /**
9 * Load thanked IDs from cookies
10 *
11 * @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
12 * @return {string[]} Thanks IDs
13 */
14 load: function ( cookieName ) {
15 const cookie = mw.cookie.get( cookieName || this.cookieName );
16 if ( cookie === null ) {
17 return [];
18 }
19 return unescape( cookie ).split( ',' );
20 },
21
22 /**
23 * Record as ID as having been thanked
24 *
25 * @param {string} id Thanked ID
26 * @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
27 */
28 push: function ( id, cookieName ) {
29 let saved = this.load();
30 saved.push( id );
31 if ( saved.length > this.maxHistory ) { // prevent forever growing
32 saved = saved.slice( saved.length - this.maxHistory );
33 }
34 mw.cookie.set( cookieName || this.cookieName, escape( saved.join( ',' ) ) );
35 },
36
37 /**
38 * Check if an ID has already been thanked, according to the cookie
39 *
40 * @param {string} id Thanks ID
41 * @param {string} [cookieName] Cookie name to use, defaults to this.cookieName
42 * @return {boolean} ID has been thanked
43 */
44 contains: function ( id, cookieName ) {
45 return this.load( cookieName ).indexOf( id ) !== -1;
46 }
47 },
48
49 /**
50 * Retrieve user gender
51 *
52 * @param {string} username Requested username
53 * @return {jQuery.Promise} A promise that resolves with the gender string, 'female', 'male', or 'unknown'
54 */
55 getUserGender: function ( username ) {
56 return new mw.Api().get( {
57 action: 'query',
58 list: 'users',
59 ususers: username,
60 usprop: 'gender'
61 } )
62 .then(
63 ( result ) => (
64 result.query.users[ 0 ] &&
65 result.query.users[ 0 ].gender
66 ) || 'unknown',
67 () => 'unknown'
68 );
69 }
70 };
71
72 }() );