User:BZPN/RfD.js: Difference between revisions
From Test Wiki
Content deleted Content added
Tags: Undo Mobile edit Mobile web edit |
No edit summary Tags: Mobile edit Mobile web edit |
||
| Line 1: | Line 1: | ||
// 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() { |
(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; |
||
// |
// Dodaj przycisk "Nominate for deletion" do paska narzędzi |
||
mw.util.addPortletLink( |
mw.util.addPortletLink( |
||
'p-cactions', |
'p-cactions', |
||
| Line 14: | Line 11: | ||
); |
); |
||
// Funkcja wywoływana po kliknięciu przycisku nominacji do usunięcia |
|||
// Add click event for the deletion nomination button |
|||
$('#ca-nominate-deletion').on('click', function(e) { |
$('#ca-nominate-deletion').on('click', function(e) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
| Line 20: | Line 17: | ||
}); |
}); |
||
// |
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia |
||
function openDeletionPopup() { |
function openDeletionPopup() { |
||
// |
// Tworzenie nakładki |
||
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
||
'position': 'fixed', |
'position': 'fixed', |
||
| Line 33: | Line 30: | ||
}).appendTo('body'); |
}).appendTo('body'); |
||
// |
// Tworzenie okna popup |
||
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
||
'width': '400px', |
'width': '400px', |
||
| Line 45: | Line 42: | ||
}).appendTo(overlay); |
}).appendTo(overlay); |
||
// |
// Przycisk zamknięcia popup |
||
$('<span>').text('×').css({ |
$('<span>').text('×').css({ |
||
'position': 'absolute', |
'position': 'absolute', |
||
| Line 55: | Line 52: | ||
}).on('click', closeDeletionPopup).appendTo(popup); |
}).on('click', closeDeletionPopup).appendTo(popup); |
||
// |
// Tytuł okna |
||
$('<h3>').text('Nominate for deletion').appendTo(popup); |
$('<h3>').text('Nominate for deletion').appendTo(popup); |
||
// |
// Informacja o zasadach RfD |
||
$('<p>').text('Before nominating, please read the deletion policy and guidelines on the Wikipedia:Requests for deletion page.').css({ |
|||
'font-size': '14px', |
|||
'margin-bottom': '10px' |
|||
| ⚫ | |||
$('<a>').attr('href', '/wiki/Wikipedia:Requests_for_deletion').text('Go to Wikipedia:Requests for deletion').css({ |
|||
'font-size': '14px', |
|||
'color': '#0073e6', |
|||
'text-decoration': 'underline' |
|||
}).appendTo(popup); |
|||
// Pole na krótki powód |
|||
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').appendTo(popup); |
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').appendTo(popup); |
||
const shortReasonInput = $('<input>').attr({ |
const shortReasonInput = $('<input>').attr({ |
||
| Line 70: | Line 78: | ||
}).appendTo(popup); |
}).appendTo(popup); |
||
// |
// Pole na szczegółowy powód |
||
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').appendTo(popup); |
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').appendTo(popup); |
||
const detailedReasonInput = $('<textarea>').attr({ |
const detailedReasonInput = $('<textarea>').attr({ |
||
| Line 78: | Line 86: | ||
'width': '100%', |
'width': '100%', |
||
'padding': '8px', |
'padding': '8px', |
||
'height': ' |
'height': '100px', |
||
'margin': '10px 0' |
'margin': '10px 0' |
||
}).appendTo(popup); |
}).appendTo(popup); |
||
// |
// Przycisk wyślij |
||
$('<button>').text('Submit nomination').css({ |
$('<button>').text('Submit nomination').css({ |
||
'width': '100%', |
'width': '100%', |
||
| Line 102: | Line 110: | ||
} |
} |
||
// |
// Funkcja zamykająca popup |
||
function closeDeletionPopup() { |
function closeDeletionPopup() { |
||
$('#deletion-popup-overlay').remove(); |
$('#deletion-popup-overlay').remove(); |
||
} |
} |
||
// Funkcja inicjująca proces usunięcia |
|||
// Function to initiate deletion process |
|||
function initiateDeletionProcess(shortReason, detailedReason) { |
function initiateDeletionProcess(shortReason, detailedReason) { |
||
// Step 1: Tagging the article with deletion notice |
|||
tagPageForDeletion(shortReason); |
tagPageForDeletion(shortReason); |
||
// Step 2: Creating the deletion discussion page |
|||
createDiscussionPage(detailedReason); |
createDiscussionPage(detailedReason); |
||
// Step 3: Adding the discussion link to the deletion list |
|||
addToDeletionList(); |
addToDeletionList(); |
||
notifyPageCreator(); |
|||
| ⚫ | |||
closeDeletionPopup(); |
closeDeletionPopup(); |
||
} |
} |
||
// |
// Funkcja do oznaczania strony do usunięcia |
||
function tagPageForDeletion(reason) { |
function tagPageForDeletion(reason) { |
||
const tag = `{{rfd|${reason}}}`; |
const tag = `{{rfd|${reason}}}`; |
||
| Line 140: | Line 142: | ||
} |
} |
||
// Funkcja do tworzenia strony dyskusji o usunięciu |
|||
// Function to create deletion discussion page |
|||
function createDiscussionPage(reason) { |
function createDiscussionPage(reason) { |
||
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}`; |
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}`; |
||
const discussionContent = `{{RfD/Preload/Template| |
const discussionContent = `{{subst:RfD/Preload/Template|deletereason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`; |
||
new mw.Api().postWithToken('csrf', { |
new mw.Api().postWithToken('csrf', { |
||
| Line 158: | Line 160: | ||
} |
} |
||
// Funkcja dodająca dyskusję do listy |
|||
// Function to add deletion discussion to the list |
|||
function addToDeletionList() { |
function addToDeletionList() { |
||
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions'; |
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions'; |
||
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}}}`; |
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}}}`; |
||
new mw.Api().edit(deletionListTitle, function(revision) { |
new mw.Api().edit(deletionListTitle, function(revision) { |
||
| Line 174: | Line 176: | ||
alert('Failed to add the discussion to the deletion list. Please try again.'); |
alert('Failed to add the discussion to the deletion list. Please try again.'); |
||
}); |
}); |
||
} |
|||
// Funkcja powiadamiająca autora strony |
|||
function notifyPageCreator() { |
|||
const creator = mw.config.get('wgPageContentModel') === 'wikitext' ? mw.config.get('wgPageCreator') : null; |
|||
if (creator) { |
|||
const notification = `{{subst:RFDNote|${mw.config.get('wgPageName')}}} ~~"+"~~`; |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: `User talk:${creator}`, |
|||
appendtext: '\n' + notification, |
|||
summary: 'Notifying page creator about deletion nomination', |
|||
watchlist: 'watch', |
|||
}).done(function() { |
|||
alert('Page creator notified.'); |
|||
}).fail(function() { |
|||
alert('Failed to notify the page creator. Please try again.'); |
|||
}); |
|||
} |
|||
} |
} |
||
})(); |
})(); |
||