User:BZPN/MassRollback2.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 537: | Line 537: | ||
mw.notify('Successfully rolled back 1 edit.', { type: 'success' }); |
mw.notify('Successfully rolled back 1 edit.', { type: 'success' }); |
||
if (confirmResult.leaveWarning) { |
if (confirmResult.leaveWarning) { |
||
await self.leaveUserWarning(confirmResult.warningType); |
await self.leaveUserWarning(confirmResult.warningType, edit.user || null); |
||
} |
} |
||
if (confirmResult.reportVIP) { |
if (confirmResult.reportVIP) { |
||
| Line 560: | Line 560: | ||
title = ($plink.attr('title') || '').trim(); |
title = ($plink.attr('title') || '').trim(); |
||
} |
} |
||
// Try to get username from the RC line |
// Try to get username (author of the edit) from the RC line |
||
let user = |
let user = ''; |
||
// Prefer the direct user page link, not talk/contribs |
|||
const $userAnchor = $line.find('a.mw-userlink[href*="/wiki/User:"]:not([href*="User_talk"]):not([href*="Special:Contributions"])').first(); |
|||
if ($userAnchor.length) { |
|||
user = ($userAnchor.find('bdi').text() || $userAnchor.text() || '').trim(); |
|||
} |
|||
// Fallback: from talk link href |
|||
if (!user) { |
if (!user) { |
||
const $ |
const $talk = $line.find('a[href*="/wiki/User_talk:"]').first(); |
||
if ($talk.length) { |
|||
const href = $talk.attr('href'); |
|||
const m = href && href.match(/User_talk:([^?#]+)/); |
|||
if (m) user = decodeURIComponent(m[1]); |
|||
} |
|||
} |
|||
// Fallback: from Special:Contributions link href |
|||
if (!user) { |
|||
const $contribs = $line.find('a[href*="Special:Contributions/"]').first(); |
|||
if ($contribs.length) { |
|||
const href = $contribs.attr('href'); |
|||
const m = href && href.match(/Special:Contributions\/([^?#]+)/); |
|||
if (m) user = decodeURIComponent(m[1]); |
|||
} |
|||
} |
} |
||
user = user || null; |
|||
if (revid && parentid && title) { |
if (revid && parentid && title) { |
||
return { title: title, revid: revid, parentid: parentid, timestamp: new Date().toISOString(), user: user || null }; |
return { title: title, revid: revid, parentid: parentid, timestamp: new Date().toISOString(), user: user || null }; |
||
| Line 1,012: | Line 1,032: | ||
mw.notify(`Successfully rolled back ${selected.length} edits.`, { type: 'success' }); |
mw.notify(`Successfully rolled back ${selected.length} edits.`, { type: 'success' }); |
||
if (confirmResult.leaveWarning) { |
if (confirmResult.leaveWarning) { |
||
const targetUser = (selected[0] && selected[0].user) ? selected[0].user : null; |
|||
await this.leaveUserWarning(confirmResult.warningType); |
await this.leaveUserWarning(confirmResult.warningType, targetUser); |
||
} |
} |
||
if (confirmResult.reportVIP) { |
if (confirmResult.reportVIP) { |
||
| Line 1,044: | Line 1,065: | ||
mw.notify(`Successfully rolled back ${selected.length} filtered edits.`, { type: 'success' }); |
mw.notify(`Successfully rolled back ${selected.length} filtered edits.`, { type: 'success' }); |
||
if (confirmResult.leaveWarning) { |
if (confirmResult.leaveWarning) { |
||
const targetUser = (selected[0] && selected[0].user) ? selected[0].user : null; |
|||
await this.leaveUserWarning(confirmResult.warningType); |
await this.leaveUserWarning(confirmResult.warningType, targetUser); |
||
} |
} |
||
if (confirmResult.reportVIP) { |
if (confirmResult.reportVIP) { |
||
| Line 1,078: | Line 1,100: | ||
mw.notify(`Successfully rolled back all ${contributions.length} edits.`, { type: 'success' }); |
mw.notify(`Successfully rolled back all ${contributions.length} edits.`, { type: 'success' }); |
||
if (confirmResult.leaveWarning) { |
if (confirmResult.leaveWarning) { |
||
const targetUser = (contributions[0] && contributions[0].user) ? contributions[0].user : null; |
|||
await this.leaveUserWarning(confirmResult.warningType); |
await this.leaveUserWarning(confirmResult.warningType, targetUser); |
||
} |
} |
||
if (confirmResult.reportVIP) { |
if (confirmResult.reportVIP) { |
||
| Line 1,153: | Line 1,176: | ||
// Leave a talk page warning using a chosen template (subst) under current month section |
// Leave a talk page warning using a chosen template (subst) under current month section |
||
leaveUserWarning: async function(templateName) { |
leaveUserWarning: async function(templateName, targetUser) { |
||
const api = new mw.Api(); |
const api = new mw.Api(); |
||
const userName = mw.config.get('wgRelevantUserName'); |
const userName = targetUser || mw.config.get('wgRelevantUserName'); |
||
if (!userName) { |
|||
mw.notify('Could not determine user name for talk page warning.', { type: 'error' }); |
|||
return; |
|||
} |
|||
const title = `User talk:${userName}`; |
const title = `User talk:${userName}`; |
||