mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-15 02:54:23 +00:00
bc369fdf85
See https://www.mediawiki.org/wiki/Extension:Thanks Change-Id: Ic037f1fcde0f7fa10848c2ed8e31291ad022027d
37 lines
903 B
JavaScript
37 lines
903 B
JavaScript
( function ( $, mw ) {
|
|
'use strict';
|
|
|
|
$( 'a.mw-thanks-thank-link' ).click( function( e ) {
|
|
var source, $thankLink = $( this );
|
|
e.preventDefault();
|
|
if ( mw.config.get( 'wgAction' ) === 'history' ) {
|
|
source = 'history';
|
|
} else {
|
|
source = 'diff';
|
|
}
|
|
( new mw.Api ).get( {
|
|
'action' : 'thank',
|
|
'rev' : $thankLink.attr( 'data-revision-id' ),
|
|
'source' : source,
|
|
'token' : mw.user.tokens.values.editToken
|
|
} )
|
|
.done( function( data ) {
|
|
$thankLink.before( mw.msg( 'thanks-thanked' ) );
|
|
$thankLink.remove();
|
|
} )
|
|
.fail( function( errorCode, details ) {
|
|
switch( errorCode ) {
|
|
case 'invalidrevision':
|
|
alert( mw.msg( 'thanks-error-invalidrevision' ) );
|
|
break;
|
|
case 'ratelimited':
|
|
alert( mw.msg( 'thanks-error-ratelimited' ) );
|
|
break;
|
|
default:
|
|
alert( mw.msg( 'thanks-error-undefined' ) );
|
|
}
|
|
} );
|
|
} );
|
|
|
|
} )( jQuery, mediaWiki );
|