User:BZPN/RfD.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Created page with "// Simple English Wikipedia Deletion Gadget // This gadget helps users nominate pages for deletion according to Simple English Wikipedia's policy. (function() { if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return; // Check if page is already tagged for deletion if (document.getElementById('delete-tag')) { alert('This page is already nominated for deletion.'); return; } // Create deletion proc..." Tags: Mobile edit Mobile web edit |
No edit summary Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
// Simple English Wikipedia Deletion Gadget |
// Simple English Wikipedia Deletion Gadget with Popup |
||
// This gadget |
// This gadget adds a "Nominate for deletion" button to the toolbar, opening a popup for deletion nomination. |
||
(function() { |
(function() { |
||
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return; |
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return; |
||
// |
// Add "Nominate for deletion" button to the toolbar |
||
mw.util.addPortletLink( |
|||
if (document.getElementById('delete-tag')) { |
|||
'p-cactions', |
|||
alert('This page is already nominated for deletion.'); |
|||
'#', |
|||
'Nominate for deletion', |
|||
} |
|||
'ca-nominate-deletion', |
|||
'Nominate this page for deletion' |
|||
); |
|||
// Add click event for the deletion nomination button |
|||
// Create deletion process UI elements |
|||
$('#ca-nominate-deletion').on('click', function(e) { |
|||
const deletionBtn = document.createElement('button'); |
|||
e.preventDefault(); |
|||
deletionBtn.textContent = 'Nominate for deletion'; |
|||
openDeletionPopup(); |
|||
deletionBtn.style.margin = '10px'; |
|||
}); |
|||
deletionBtn.onclick = initiateDeletionProcess; |
|||
// Function to create and open the deletion popup |
|||
// Append button to page |
|||
function openDeletionPopup() { |
|||
document.getElementById('mw-content-text').prepend(deletionBtn); |
|||
// Create the popup overlay |
|||
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
|||
'position': 'fixed', |
|||
'top': '0', |
|||
'left': '0', |
|||
'width': '100%', |
|||
'height': '100%', |
|||
'background-color': 'rgba(0, 0, 0, 0.5)', |
|||
'z-index': '1000', |
|||
}).appendTo('body'); |
|||
// Create the popup container |
|||
// Function to initiate deletion process |
|||
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
|||
function initiateDeletionProcess() { |
|||
'width': '400px', |
|||
const reason = prompt('Please provide a reason for deletion:', 'Not a notable topic'); |
|||
'margin': '10% auto', |
|||
'padding': '20px', |
|||
'background-color': '#fff', |
|||
'border-radius': '8px', |
|||
'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)', |
|||
} |
|||
'text-align': 'left', |
|||
'position': 'relative' |
|||
}).appendTo(overlay); |
|||
// Close button |
|||
$('<span>').text('×').css({ |
|||
'position': 'absolute', |
|||
'top': '10px', |
|||
'right': '15px', |
|||
'cursor': 'pointer', |
|||
'font-size': '18px', |
|||
'font-weight': 'bold' |
|||
}).on('click', closeDeletionPopup).appendTo(popup); |
|||
// Title |
|||
$('<h3>').text('Nominate for deletion').appendTo(popup); |
|||
// Short reason input |
|||
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').appendTo(popup); |
|||
const shortReasonInput = $('<input>').attr({ |
|||
'type': 'text', |
|||
'id': 'deletion-short-reason', |
|||
'placeholder': 'Enter short reason...' |
|||
}).css({ |
|||
'width': '100%', |
|||
'padding': '8px', |
|||
'margin': '10px 0' |
|||
}).appendTo(popup); |
|||
// Detailed reason input |
|||
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').appendTo(popup); |
|||
const detailedReasonInput = $('<textarea>').attr({ |
|||
'id': 'deletion-detailed-reason', |
|||
'placeholder': 'Enter detailed reason...' |
|||
}).css({ |
|||
'width': '100%', |
|||
'padding': '8px', |
|||
'height': '80px', |
|||
'margin': '10px 0' |
|||
}).appendTo(popup); |
|||
// Submit button |
|||
$('<button>').text('Submit nomination').css({ |
|||
'width': '100%', |
|||
'padding': '10px', |
|||
'background-color': '#0073e6', |
|||
'color': '#fff', |
|||
'border': 'none', |
|||
'border-radius': '5px', |
|||
'cursor': 'pointer' |
|||
}).on('click', function() { |
|||
const shortReason = shortReasonInput.val().trim(); |
|||
const detailedReason = detailedReasonInput.val().trim(); |
|||
if (shortReason && detailedReason) { |
|||
initiateDeletionProcess(shortReason, detailedReason); |
|||
} else { |
|||
alert('Please provide both a short and detailed reason.'); |
|||
} |
|||
}).appendTo(popup); |
|||
} |
|||
// Function to close the deletion popup |
|||
function closeDeletionPopup() { |
|||
$('#deletion-popup-overlay').remove(); |
|||
} |
|||
// Function to initiate deletion process |
|||
function initiateDeletionProcess(shortReason, detailedReason) { |
|||
// Step 1: Tagging the article with deletion notice |
// Step 1: Tagging the article with deletion notice |
||
tagPageForDeletion( |
tagPageForDeletion(shortReason); |
||
// Step 2: Creating the deletion discussion page |
// Step 2: Creating the deletion discussion page |
||
createDiscussionPage( |
createDiscussionPage(detailedReason); |
||
// Step 3: Adding the discussion link to the deletion list |
// Step 3: Adding the discussion link to the deletion list |
||
addToDeletionList(); |
addToDeletionList(); |
||
// Close the popup |
|||
closeDeletionPopup(); |
|||
} |
} |
||
Revision as of 12:58, 1 November 2024
// Simple English Wikipedia Deletion Gadget with Popup
// This gadget adds a "Nominate for deletion" button to the toolbar, opening a popup for deletion nomination.
(function() {
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return;
// Add "Nominate for deletion" button to the toolbar
mw.util.addPortletLink(
'p-cactions',
'#',
'Nominate for deletion',
'ca-nominate-deletion',
'Nominate this page for deletion'
);
// Add click event for the deletion nomination button
$('#ca-nominate-deletion').on('click', function(e) {
e.preventDefault();
openDeletionPopup();
});
// Function to create and open the deletion popup
function openDeletionPopup() {
// Create the popup overlay
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
'position': 'fixed',
'top': '0',
'left': '0',
'width': '100%',
'height': '100%',
'background-color': 'rgba(0, 0, 0, 0.5)',
'z-index': '1000',
}).appendTo('body');
// Create the popup container
const popup = $('<div>').attr('id', 'deletion-popup').css({
'width': '400px',
'margin': '10% auto',
'padding': '20px',
'background-color': '#fff',
'border-radius': '8px',
'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)',
'text-align': 'left',
'position': 'relative'
}).appendTo(overlay);
// Close button
$('<span>').text('×').css({
'position': 'absolute',
'top': '10px',
'right': '15px',
'cursor': 'pointer',
'font-size': '18px',
'font-weight': 'bold'
}).on('click', closeDeletionPopup).appendTo(popup);
// Title
$('<h3>').text('Nominate for deletion').appendTo(popup);
// Short reason input
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').appendTo(popup);
const shortReasonInput = $('<input>').attr({
'type': 'text',
'id': 'deletion-short-reason',
'placeholder': 'Enter short reason...'
}).css({
'width': '100%',
'padding': '8px',
'margin': '10px 0'
}).appendTo(popup);
// Detailed reason input
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').appendTo(popup);
const detailedReasonInput = $('<textarea>').attr({
'id': 'deletion-detailed-reason',
'placeholder': 'Enter detailed reason...'
}).css({
'width': '100%',
'padding': '8px',
'height': '80px',
'margin': '10px 0'
}).appendTo(popup);
// Submit button
$('<button>').text('Submit nomination').css({
'width': '100%',
'padding': '10px',
'background-color': '#0073e6',
'color': '#fff',
'border': 'none',
'border-radius': '5px',
'cursor': 'pointer'
}).on('click', function() {
const shortReason = shortReasonInput.val().trim();
const detailedReason = detailedReasonInput.val().trim();
if (shortReason && detailedReason) {
initiateDeletionProcess(shortReason, detailedReason);
} else {
alert('Please provide both a short and detailed reason.');
}
}).appendTo(popup);
}
// Function to close the deletion popup
function closeDeletionPopup() {
$('#deletion-popup-overlay').remove();
}
// Function to initiate deletion process
function initiateDeletionProcess(shortReason, detailedReason) {
// Step 1: Tagging the article with deletion notice
tagPageForDeletion(shortReason);
// Step 2: Creating the deletion discussion page
createDiscussionPage(detailedReason);
// Step 3: Adding the discussion link to the deletion list
addToDeletionList();
// Close the popup
closeDeletionPopup();
}
// Function to tag page with deletion notice
function tagPageForDeletion(reason) {
const tag = `{{rfd|${reason}}}`;
const editSummary = 'Nominating for deletion';
new mw.Api().postWithToken('csrf', {
action: 'edit',
title: mw.config.get('wgPageName'),
prependtext: tag + '\n',
summary: editSummary,
watchlist: 'watch',
}).done(function() {
alert('Page tagged for deletion.');
}).fail(function() {
alert('Failed to tag the page for deletion. Please try again.');
});
}
// Function to create deletion discussion page
function createDiscussionPage(reason) {
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}`;
const discussionContent = `{{RfD/Preload/Template|reason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`;
new mw.Api().postWithToken('csrf', {
action: 'edit',
title: discussionPageTitle,
text: discussionContent,
summary: 'Starting deletion discussion',
watchlist: 'watch',
}).done(function() {
alert('Deletion discussion page created.');
}).fail(function() {
alert('Failed to create deletion discussion page. Please try again.');
});
}
// Function to add deletion discussion to the list
function addToDeletionList() {
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}}}`;
new mw.Api().edit(deletionListTitle, function(revision) {
return {
text: discussionLink + '\n' + revision.content,
summary: 'Adding new deletion discussion',
watchlist: 'watch',
};
}).done(function() {
alert('Deletion discussion added to the list.');
}).fail(function() {
alert('Failed to add the discussion to the deletion list. Please try again.');
});
}
})();