User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
mw.notify |
fix |
||
| Line 82: | Line 82: | ||
if (!link.length) { |
if (!link.length) { |
||
mw.notify('Cannot find target article link!', {title: 'VfDcloser', type: 'error'}); |
mw.notify('Cannot find target article link!', {title: 'VfDcloser', type: 'error'}); |
||
| ⚫ | |||
return; |
return; |
||
} |
} |
||
const targetPage = link.attr('title'); |
const targetPage = link.attr('title') || link.text().trim(); |
||
if (!targetPage) { |
|||
| ⚫ | |||
return; |
|||
} |
|||
if (actionObj.name === 'delete') { |
if (actionObj.name === 'delete') { |
||
// Delete target article |
// Delete target article |
||
api.postWithToken('csrf', {action: 'delete', title: targetPage, reason: '[[' + mw.config.get('wgPageName') + ']]'}) |
api.postWithToken('csrf', {action: 'delete', title: targetPage, reason: '[[' + mw.config.get('wgPageName') + ']]'}) |
||
.done(() => { |
.done(() => { |
||
const talkPage = 'Talk:' + targetPage; |
const talkPage = 'Talk:' + targetPage; |
||
| ⚫ | |||
// Check if talk page exists before deletion |
|||
api.get({action: 'query', titles: talkPage, format: 'json'}).done(data => { |
|||
const talkPages = data.query.pages; |
|||
const talkId = Object.keys(talkPages)[0]; |
|||
| ⚫ | |||
if (talkId !== "-1") { |
|||
| ⚫ | |||
.done(() => { |
|||
mw.notify('Discussion closed. Article and talk page deleted.', {title: 'VfDcloser', type: 'success'}); |
|||
location.reload(); |
|||
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
|||
} else { |
|||
mw.notify('Discussion closed. Article deleted. No talk page found.', {title: 'VfDcloser', type: 'success'}); |
|||
| ⚫ | |||
} |
|||
}); |
|||
}).fail(err => mw.notify('Error deleting article: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
|||
} else { |
} else { |
||
// Keep / No consensus: update target and talk page |
// Keep / No consensus: update target and talk page |
||
| Line 111: | Line 126: | ||
const articleId = Object.keys(articlePages)[0]; |
const articleId = Object.keys(articlePages)[0]; |
||
let articleContent = articlePages[articleId].revisions[0].slots.main['*']; |
let articleContent = articlePages[articleId].revisions[0].slots.main['*']; |
||
articleContent = articleContent.replace(/\{\{vfd-new\}\}/gi, '').trim(); |
articleContent = articleContent.replace(/\{\{vfd-new\}\}/gi, '').trim(); |
||
| Line 147: | Line 161: | ||
minor: true |
minor: true |
||
}).done(() => { |
}).done(() => { |
||
mw.notify('Discussion closed and |
mw.notify('Discussion closed. Article and talk page updated.', {title: 'VfDcloser', type: 'success'}); |
||
location.reload(); |
location.reload(); |
||
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'})); |
||