2013-09-26 01:16:56 +00:00
|
|
|
( function( M, $ ) {
|
|
|
|
var api = M.require( 'api' ),
|
2014-01-15 01:27:47 +00:00
|
|
|
popup = M.require( 'toast' ),
|
2013-09-26 01:16:56 +00:00
|
|
|
schema = M.require( 'loggingSchemas/MobileWebClickTracking' );
|
|
|
|
|
|
|
|
function thankUser( name, revision, gender ) {
|
|
|
|
var d = $.Deferred();
|
|
|
|
api.getToken( 'edit' ).done( function( token ) {
|
2014-09-07 03:44:27 +00:00
|
|
|
api.post( {
|
2013-09-26 01:16:56 +00:00
|
|
|
'action' : 'thank',
|
|
|
|
'rev' : revision,
|
|
|
|
'source' : 'mobilediff',
|
|
|
|
'token' : token
|
|
|
|
} )
|
|
|
|
.done( function() {
|
|
|
|
popup.show( mw.msg( 'thanks-thanked-notice', name, gender ) );
|
|
|
|
d.resolve();
|
|
|
|
} )
|
|
|
|
.fail( function( errorCode ) {
|
|
|
|
switch( errorCode ) {
|
|
|
|
case 'invalidrevision':
|
|
|
|
popup.show( mw.msg( 'thanks-error-invalidrevision' ) );
|
|
|
|
break;
|
|
|
|
case 'ratelimited':
|
2013-10-07 15:17:18 +00:00
|
|
|
popup.show( mw.msg( 'thanks-error-ratelimited', gender ) );
|
2013-09-26 01:16:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
popup.show( mw.msg( 'thanks-error-undefined' ) );
|
|
|
|
}
|
|
|
|
d.reject();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a thank button for a given edit
|
|
|
|
*
|
|
|
|
* @param name String The username of the user who made the edit
|
|
|
|
* @param rev String The revision the user created
|
|
|
|
* @param gender String The gender of the user who made the edit
|
|
|
|
*/
|
|
|
|
function createThankLink( name, rev, gender ) {
|
2014-01-15 20:07:17 +00:00
|
|
|
var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png',
|
|
|
|
thankImgTag = '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>',
|
|
|
|
$thankBtn;
|
2013-09-26 01:16:56 +00:00
|
|
|
// Don't make thank button for self
|
|
|
|
if ( name !== mw.config.get( 'wgUserName' ) ) {
|
2014-01-15 20:07:17 +00:00
|
|
|
// See if user has already been thanked for this edit
|
|
|
|
if ( mw.config.get( 'wgThanksAlreadySent' ) ) {
|
2014-03-04 00:39:13 +00:00
|
|
|
$thankBtn = $( '<button class="mw-mf-action-button mw-ui-button mw-ui-constructive thanked">' )
|
2014-01-15 20:07:17 +00:00
|
|
|
.attr( 'disabled', true )
|
|
|
|
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
|
|
|
|
} else {
|
2014-03-04 00:39:13 +00:00
|
|
|
$thankBtn = $( '<button class="mw-mf-action-button mw-ui-button mw-ui-constructive">' )
|
2014-01-15 20:07:17 +00:00
|
|
|
.html( thankImgTag + mw.message( 'thanks-button-thank', mw.user ).escaped()
|
|
|
|
)
|
|
|
|
.on( 'click', function() {
|
|
|
|
var $this = $( this );
|
|
|
|
schema.log( 'diff-thank', name );
|
|
|
|
if ( !$this.hasClass( 'thanked' ) ) {
|
|
|
|
thankUser( name, rev, gender ).done( function() {
|
|
|
|
$this.addClass( 'thanked' ).attr( 'disabled', true )
|
|
|
|
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
return $thankBtn;
|
2013-09-26 01:16:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$( function() {
|
|
|
|
var $user = $( '.mw-mf-user' ),
|
|
|
|
username = $user.data( 'user-name' ),
|
|
|
|
rev = $user.data( 'revision-id' ),
|
|
|
|
gender = $user.data( 'user-gender' ),
|
|
|
|
$thankBtn;
|
|
|
|
|
|
|
|
if ( !$user.hasClass( 'mw-mf-anon' ) ) {
|
|
|
|
$thankBtn = createThankLink( username, rev, gender );
|
|
|
|
if ( $thankBtn ) {
|
|
|
|
$thankBtn.prependTo( '#mw-mf-userinfo' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} )( mw.mobileFrontend, jQuery );
|