mediawiki-extensions-Thanks/modules/ext.thanks.thank.js
Kaldari bc369fdf85 Initial version of Thanks extension
See https://www.mediawiki.org/wiki/Extension:Thanks

Change-Id: Ic037f1fcde0f7fa10848c2ed8e31291ad022027d
2013-03-21 11:33:50 -07:00

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 );