User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
Tooltip added |
mw.notify |
||
| Line 3: | Line 3: | ||
const pagePrefix = 'User:Euphoria/TestVfD'; |
const pagePrefix = 'User:Euphoria/TestVfD'; |
||
// Only run on relevant pages in view mode |
|||
if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') return; |
if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') return; |
||
| Line 9: | Line 10: | ||
const heading = this; |
const heading = this; |
||
// Skip |
// Skip headings already inside a .vfd container |
||
if ($(heading).closest('.vfd').length) return; |
if ($(heading).closest('.vfd').length) return; |
||
// Skip |
// Skip headings without links |
||
if (!$(heading).find('a').length) return; |
if (!$(heading).find('a').length) return; |
||
| Line 27: | Line 28: | ||
const btn = document.createElement('button'); |
const btn = document.createElement('button'); |
||
btn.textContent = actionObj.name.charAt(0).toUpperCase(); // D/K/N |
btn.textContent = actionObj.name.charAt(0).toUpperCase(); // D/K/N |
||
btn.title = 'Close as ' + actionObj.name; |
|||
// |
// Small inline button styling |
||
btn.style.width = '16px'; |
btn.style.width = '16px'; |
||
btn.style.height = '16px'; |
btn.style.height = '16px'; |
||
| Line 50: | Line 51: | ||
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return; |
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return; |
||
btn.disabled = true; // prevent double-clicks |
|||
btn.disabled = true; |
|||
const api = new mw.Api(); |
const api = new mw.Api(); |
||
// |
// Fetch discussion page content |
||
api.get({ |
api.get({ |
||
action: 'query', |
action: 'query', |
||
| Line 72: | Line 71: | ||
const discussionNewContent = topText + content.trim() + bottomText; |
const discussionNewContent = topText + content.trim() + bottomText; |
||
// |
// Edit discussion page |
||
api.postWithToken('csrf', { |
api.postWithToken('csrf', { |
||
action: 'edit', |
action: 'edit', |
||
| Line 82: | Line 81: | ||
const link = $(heading).find('a').first(); |
const link = $(heading).find('a').first(); |
||
if (!link.length) { |
if (!link.length) { |
||
mw.notify('Cannot find target article link!', {title: 'VfDcloser', type: 'error'}); |
|||
location.reload(); |
location.reload(); |
||
return; |
return; |
||
| Line 89: | Line 88: | ||
if (actionObj.name === 'delete') { |
if (actionObj.name === 'delete') { |
||
// Delete target article |
// Delete target article and talk page |
||
api.postWithToken('csrf', { |
api.postWithToken('csrf', {action: 'delete', title: targetPage, reason: '[[' + mw.config.get('wgPageName') + ']]'}) |
||
.done(() => { |
|||
const talkPage = 'Talk:' + targetPage; |
|||
api.postWithToken('csrf', {action: 'delete', title: talkPage, reason: 'Parent page deleted via VfD'}) |
|||
.done(() => { |
|||
mw.notify('Discussion closed and "' + targetPage + '" deleted with talk page.', {title: 'VfDcloser', type: 'success'}); |
|||
location.reload(); |
|||
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
|||
title: |
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
||
reason: 'Parent page deleted via VfD' |
|||
}).done(() => { |
|||
alert('Discussion closed and "' + targetPage + '" along with its talk page deleted.'); |
|||
location.reload(); |
|||
}).fail(err => alert('Error deleting talk page: ' + err)); |
|||
}).fail(err => alert('Error deleting page: ' + err)); |
|||
} else { |
} else { |
||
// Keep / No consensus |
// Keep / No consensus: update target and talk page |
||
api.get({ |
api.get({ |
||
action: 'query', |
action: 'query', |
||
| Line 154: | Line 147: | ||
minor: true |
minor: true |
||
}).done(() => { |
}).done(() => { |
||
mw.notify('Discussion closed and "' + targetPage + '" updated. Talk page updated.', {title: 'VfDcloser', type: 'success'}); |
|||
location.reload(); |
location.reload(); |
||
}).fail(err => |
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
||
}); |
}); |
||
}).fail(err => |
}).fail(err => mw.notify('Error editing article: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
||
}); |
}); |
||
} |
} |
||
}).fail(err => |
}).fail(err => mw.notify('Error editing discussion page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
||
}); |
}); |
||
}); |
}); |
||