Add log-thanks support to corethank module

This adds support for thanking for log entries. It gets the log
ID from and attribute on the thank link (which does not yet have
this; that will come in T187485), and sets the source to be 'log'
if it's being called from Special:Log (this can be extended in
the future if we want to thank for log entries from elsewhere).

Bug: T186921
Change-Id: Ifdb458b873ed4f1e6e64760658d2293aba1e02b3
This commit is contained in:
Sam Wilson 2018-03-29 10:36:40 +08:00
parent e238b4e50f
commit 3973a11e8d

View file

@ -14,7 +14,7 @@
// $thankLink is the element with the data-revision-id attribute
// $thankElement is the element to be removed on success
function sendThanks( $thankLink, $thankElement ) {
var source;
var source, apiParams;
if ( $thankLink.data( 'clickDisabled' ) ) {
// Prevent double clicks while we haven't received a response from API request
@ -22,17 +22,28 @@
}
$thankLink.data( 'clickDisabled', true );
// Determine the thank source (history, diff, or log).
if ( mw.config.get( 'wgAction' ) === 'history' ) {
source = 'history';
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Log' ) {
source = 'log';
} else {
source = 'diff';
}
( new mw.Api() ).postWithToken( 'csrf', {
// Construct the API parameters.
apiParams = {
action: 'thank',
rev: $thankLink.attr( 'data-revision-id' ),
source: source
} )
};
if ( $thankLink.data( 'log-id' ) ) {
apiParams.log = $thankLink.data( 'log-id' );
} else {
apiParams.rev = $thankLink.data( 'revision-id' );
}
// Send the API request.
( new mw.Api() ).postWithToken( 'csrf', apiParams )
.then(
// Success
function () {