Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4051648
thanks.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
thanks.js
View Options
const
cacheKey
=
'dt-thanks'
;
/**
* Thank a comment item
*
* @param {CommentItem} commentItem Comment item
* @return {jQuery.Promise} Resolves when thanks successfully sent, rejects on error
*/
function
thankComment
(
commentItem
)
{
// TODO: Add recipient gender for messages
const
recipientGender
=
'unknown'
;
return
OO
.
ui
.
confirm
(
mw
.
msg
(
'thanks-confirmation2'
,
mw
.
user
),
{
actions
:
[
{
action
:
'accept'
,
label
:
mw
.
msg
(
'thanks-button-thank'
,
mw
.
user
,
recipientGender
),
flags
:
[
'primary'
,
'progressive'
]
},
{
action
:
'cancel'
,
label
:
mw
.
msg
(
'cancel'
),
flags
:
'safe'
}
]
}
).
then
(
(
confirmed
)
=>
{
if
(
!
confirmed
)
{
return
$
.
Deferred
().
reject
().
promise
();
}
const
api
=
require
(
'./controller.js'
).
getApi
();
return
api
.
postWithToken
(
'csrf'
,
{
action
:
'discussiontoolsthank'
,
// We don't need to store the correct transcluded comment page
// for a thank, any page the comment appears on will do.
page
:
mw
.
config
.
get
(
'wgRelevantPageName'
),
commentid
:
commentItem
.
id
}
).
then
(
()
=>
{
mw
.
notify
(
mw
.
msg
(
'thanks-thanked-notice'
,
commentItem
.
author
,
recipientGender
,
mw
.
user
),
{
type
:
'success'
}
);
cacheThanked
(
commentItem
);
},
(
code
,
data
)
=>
{
mw
.
notify
(
api
.
getErrorMessage
(
data
),
{
type
:
'error'
}
);
return
$
.
Deferred
().
reject
().
promise
();
}
);
}
);
}
function
isThanked
(
threadItem
)
{
const
cache
=
mw
.
storage
.
getObject
(
cacheKey
)
||
{};
return
cache
[
threadItem
.
id
];
}
function
cacheThanked
(
threadItem
)
{
const
cache
=
mw
.
storage
.
getObject
(
cacheKey
)
||
{};
cache
[
threadItem
.
id
]
=
true
;
mw
.
storage
.
setObject
(
cacheKey
,
cache
);
}
mw
.
hook
(
'discussionToolsOverflowMenuOnChoose'
).
add
(
(
id
,
menuItem
,
threadItem
)
=>
{
// TODO: Add recipient gender for messages
const
recipientGender
=
'unknown'
;
if
(
id
===
'thank'
)
{
thankComment
(
threadItem
).
then
(
()
=>
{
menuItem
.
setLabel
(
mw
.
msg
(
'thanks-button-thanked'
,
mw
.
user
,
recipientGender
)
);
menuItem
.
setDisabled
(
true
);
}
);
}
}
);
mw
.
hook
(
'discussionToolsOverflowMenuOnAddItem'
).
add
(
(
id
,
menuItem
,
threadItem
)
=>
{
// TODO: Add recipient gender for messages
const
recipientGender
=
'unknown'
;
if
(
id
===
'thank'
&&
isThanked
(
threadItem
)
)
{
menuItem
.
setLabel
(
mw
.
msg
(
'thanks-button-thanked'
,
mw
.
user
,
recipientGender
)
);
menuItem
.
setDisabled
(
true
);
}
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 15 2026, 18:19 (12 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1d/2b/4d3c6de3fae8b01356e15979c677
Default Alt Text
thanks.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment