User:BZPN/RfD.js: Difference between revisions

From Test Wiki
Content deleted Content added
BZPN (talk | contribs)
Nominating for deletion
Tags: Reverted Mobile edit Mobile web edit
BZPN (talk | contribs)
No edit summary
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
// <nowiki>
{{rfd|Test}}
(function($) {
// Simple English Wikipedia Deletion Gadget with Popup
// Główny obiekt skryptu
// This gadget adds a "Nominate for deletion" button to the toolbar, opening a popup for deletion nomination.
var QuickCloseRfD = {};

(function() {
// Konfiguracja przestrzeni nazw
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return;
const ALLOWED_NAMESPACES = ['Wikipedia:Requests for deletion'];

// Add "Nominate for deletion" button to the toolbar
QuickCloseRfD.setup = function() {
mw.util.addPortletLink(
// Sprawdzenie, czy jesteśmy na odpowiedniej stronie
'p-cactions',
var wgPageName = mw.config.get('wgPageName');
'#',
var wgNamespaceNumber = mw.config.get('wgNamespaceNumber');
'Nominate for deletion',
'ca-nominate-deletion',
if (ALLOWED_NAMESPACES.includes(wgPageName) ||
'Nominate this page for deletion'
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) {
);

$('span.mw-editsection-bracket:first-child').each(function() {
// Add click event for the deletion nomination button
try {
$('#ca-nominate-deletion').on('click', function(e) {
// Pobieranie numeru sekcji
e.preventDefault();
var sectionNumber = this.parentElement.childNodes[1].href
openDeletionPopup();
.match(/action=edit&section=(\d+)/)[1];
});

// Dodawanie przycisku Quick Close
// Function to create and open the deletion popup
$(this).after(' | ');
function openDeletionPopup() {
// Create the popup overlay
$(this).after(
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' +
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
'position': 'fixed',
'data-section="' + sectionNumber + '">Quick Close</a>')
'top': '0',
);
'left': '0',
} catch(e) {}
'width': '100%',
});
'height': '100%',
'background-color': 'rgba(0, 0, 0, 0.5)',
// Obsługa kliknięcia przycisku
'z-index': '1000',
QuickCloseRfD.bindEvents();
}).appendTo('body');
}
};

// Create the popup container
QuickCloseRfD.bindEvents = function() {
const popup = $('<div>').attr('id', 'deletion-popup').css({
$('.QuickCloseRfD-close').click(function(e) {
'width': '400px',
'margin': '10% auto',
var sectionNumber = $(this).data('section');
QuickCloseRfD.showQuickCloseDialog(sectionNumber);
'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.');
});
});
}
};

QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) {
// Function to create deletion discussion page
// Prosty popup do zamykania dyskusji
function createDiscussionPage(reason) {
var $dialog = $('<div class="quick-close-dialog">' +
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}`;
'<h3>Close Deletion Request</h3>' +
const discussionContent = `{{RfD/Preload/Template|reason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`;
'<div>' +

'<label>Outcome:</label>' +
new mw.Api().postWithToken('csrf', {
action: 'edit',
'<select id="quick-close-outcome">' +
'<option value="{{delete}}">Delete</option>' +
title: discussionPageTitle,
'<option value="{{keep}}">Keep</option>' +
text: discussionContent,
'<option value="{{merge}}">Merge</option>' +
summary: 'Starting deletion discussion',
watchlist: 'watch',
'<option value="{{redirect}}">Redirect</option>' +
'</select>' +
}).done(function() {
alert('Deletion discussion page created.');
'</div>' +
}).fail(function() {
'<div>' +
'<label>Additional Comments (optional):</label>' +
alert('Failed to create deletion discussion page. Please try again.');
'<textarea id="quick-close-comment" rows="3"></textarea>' +
'</div>' +
(mw.config.get('wgUserGroups').includes('sysop') ?
'<div>' +
'<label><input type="checkbox" id="quick-close-delete-page"> Delete this page</label>' +
'</div>' : '') +
'<div class="quick-close-buttons">' +
'<button id="quick-close-confirm">Close Discussion</button>' +
'<button id="quick-close-cancel">Cancel</button>' +
'</div>' +
'</div>');
// Dodanie arkusza stylów dla dialogu
$('head').append(`
<style>
.quick-close-dialog {
background: white;
border: 1px solid #a2a9b1;
border-radius: 5px;
padding: 15px;
width: 400px;
margin: 0 auto;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.quick-close-dialog h3 {
margin-top: 0;
border-bottom: 1px solid #eaecf0;
padding-bottom: 10px;
}
.quick-close-dialog div {
margin-bottom: 10px;
}
.quick-close-dialog label {
display: block;
margin-bottom: 5px;
}
.quick-close-dialog select,
.quick-close-dialog textarea {
width: 100%;
box-sizing: border-box;
}
.quick-close-buttons {
display: flex;
justify-content: space-between;
}
.quick-close-buttons button {
padding: 5px 10px;
}
</style>
`);
$('body').append($dialog);
// Zamykanie dialogu
$('#quick-close-cancel').click(function() {
$dialog.remove();
});
});
}
// Potwierdzenie zamknięcia

$('#quick-close-confirm').click(function() {
// Function to add deletion discussion to the list
var outcome = $('#quick-close-outcome').val();
function addToDeletionList() {
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: ';
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
var deleteRequest = $('#quick-close-delete-page:checked').length > 0;
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}}}`;

QuickCloseRfD.closeDiscussion(
new mw.Api().edit(deletionListTitle, function(revision) {
return {
sectionNumber,
text: discussionLink + '\n' + revision.content,
outcome,
summary: 'Adding new deletion discussion',
comment,
watchlist: 'watch',
deleteRequest
};
);
}).done(function() {
alert('Deletion discussion added to the list.');
$dialog.remove();
}).fail(function() {
alert('Failed to add the discussion to the deletion list. Please try again.');
});
});
}
};
})();
QuickCloseRfD.closeDiscussion = function(sectionNumber, outcome, comment, deleteRequest) {
var pageTitle = mw.config.get('wgPageName');
var pageName = pageTitle.split('/').pop();
new mw.Api().get({
action: 'parse',
page: pageTitle,
prop: 'wikitext',
section: sectionNumber
}).done(function(result) {
var wikitext = result.parse.wikitext['*'];
// Dodanie zamknięcia dyskusji
var closingText =
'<div class="boilerplate" style="background-color: #EDEAFF; padding: 0px 10px 0px 10px; border: 1px solid #8779DD;">\n' +
':\'\'The following discussion is closed. <span style="color:red">\'\'\'Please do not modify it.\'\'\'\</span> Subsequent comments should be made on the appropriate discussion page. No further changes should be made to this discussion.\'\'\n' +
'----\n' +
outcome + ' - ~~~~\n\n' +
comment + ' ~~~~\n' +
'</div>';
wikitext += '\n' + closingText;
// Edycja strony
new mw.Api().postWithEditToken({
action: 'edit',
title: pageTitle,
section: sectionNumber,
text: wikitext,
summary: 'Closing deletion discussion for ' + pageName
}).done(function() {
// Opcjonalne usunięcie strony dla administratorów
if (deleteRequest) {
new mw.Api().postWithEditToken({
action: 'delete',
title: 'Wikipedia:Requests for deletion/Requests/2025/' + pageName,
reason: 'Deletion discussion completed'
}).done(function() {
location.reload();
});
} else {
location.reload();
}
});
});
};
// Ładowanie skryptu
mw.loader.using('mediawiki.api', function() {
$(document).ready(function() {
QuickCloseRfD.setup();
});
});
})(jQuery);
// </nowiki>