User:BZPN/RfD.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
// <nowiki> |
|||
(function() { |
|||
(function($) { |
|||
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return; |
|||
// Główny obiekt skryptu |
|||
var QuickCloseRfD = {}; |
|||
// Dodaj przycisk "Nominate for deletion" do paska narzędzi |
|||
var nominateLink = mw.util.addPortletLink( |
|||
// Konfiguracja przestrzeni nazw |
|||
'p-tb', |
|||
const ALLOWED_NAMESPACES = ['Wikipedia:Requests for deletion']; |
|||
'#', |
|||
'Nominate for deletion', |
|||
QuickCloseRfD.setup = function() { |
|||
'ca-nominate-deletion', |
|||
// Sprawdzenie, czy jesteśmy na odpowiedniej stronie |
|||
'Nominate this page for deletion' |
|||
var wgPageName = mw.config.get('wgPageName'); |
|||
); |
|||
var wgNamespaceNumber = mw.config.get('wgNamespaceNumber'); |
|||
// Jeśli dodanie przycisku się powiodło, przypisz funkcję do obsługi kliknięcia |
|||
if (ALLOWED_NAMESPACES.includes(wgPageName) || |
|||
if (nominateLink) { |
|||
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) { |
|||
$('span.mw-editsection-bracket:first-child').each(function() { |
|||
openDeletionPopup(); |
|||
try { |
|||
// Pobieranie numeru sekcji |
|||
} |
|||
var sectionNumber = this.parentElement.childNodes[1].href |
|||
.match(/action=edit§ion=(\d+)/)[1]; |
|||
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia |
|||
function openDeletionPopup() { |
|||
// Dodawanie przycisku Quick Close |
|||
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
|||
$(this).after(' | '); |
|||
$(this).after( |
|||
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' + |
|||
'left': '0', |
|||
' |
'data-section="' + sectionNumber + '">Quick Close</a>') |
||
); |
|||
} catch(e) {} |
|||
}); |
|||
// Obsługa kliknięcia przycisku |
|||
QuickCloseRfD.bindEvents(); |
|||
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
|||
} |
|||
}; |
|||
'max-width': '400px', |
|||
'margin': '10% auto', |
|||
QuickCloseRfD.bindEvents = function() { |
|||
'padding': '15px', |
|||
$('.QuickCloseRfD-close').click(function(e) { |
|||
'background-color': '#fff', |
|||
var sectionNumber = $(this).data('section'); |
|||
QuickCloseRfD.showQuickCloseDialog(sectionNumber); |
|||
'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)', |
|||
'text-align': 'left', |
|||
'position': 'relative' |
|||
}).appendTo(overlay); |
|||
$('<span>').text('×').css({ |
|||
'position': 'absolute', |
|||
'top': '10px', |
|||
'right': '15px', |
|||
'cursor': 'pointer', |
|||
'font-size': '18px', |
|||
'font-weight': 'bold' |
|||
}).on('click', closeDeletionPopup).appendTo(popup); |
|||
$('<h3>').text('Nominate for deletion').css({ |
|||
'font-size': '18px', |
|||
'margin-bottom': '10px' |
|||
}).appendTo(popup); |
|||
$('<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' |
|||
}).appendTo(popup); |
|||
$('<a>').attr('href', '/wiki/Wikipedia:Requests_for_deletion').text('Go to Wikipedia:Requests for deletion').css({ |
|||
'font-size': '14px', |
|||
'color': '#0073e6', |
|||
'text-decoration': 'underline', |
|||
'display': 'block', |
|||
'margin-bottom': '10px' |
|||
}).appendTo(popup); |
|||
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').css({ |
|||
'display': 'block', |
|||
'margin-top': '10px', |
|||
'font-size': '14px' |
|||
}).appendTo(popup); |
|||
const shortReasonInput = $('<input>').attr({ |
|||
'type': 'text', |
|||
'id': 'deletion-short-reason', |
|||
'placeholder': 'Enter short reason...' |
|||
}).css({ |
|||
'width': '100%', |
|||
'padding': '6px', |
|||
'margin': '5px 0', |
|||
'font-size': '14px', |
|||
'box-sizing': 'border-box' |
|||
}).appendTo(popup); |
|||
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').css({ |
|||
'display': 'block', |
|||
'margin-top': '10px' |
|||
}).appendTo(popup); |
|||
const detailedReasonInput = $('<textarea>').attr({ |
|||
'id': 'deletion-detailed-reason', |
|||
'placeholder': 'Detailed reason...' |
|||
}).css({ |
|||
'width': '100%', |
|||
'padding': '6px', |
|||
'font-size': '14px', |
|||
'height': '80px', |
|||
'margin-bottom': '10px' |
|||
}).appendTo(popup); |
|||
// Checkbox i lista rozwijana Quick Delete |
|||
const quickDeleteCheckbox = $('<input>').attr({ |
|||
'type': 'checkbox', |
|||
'id': 'quick-delete' |
|||
}).css({ |
|||
'margin-right': '5px' |
|||
}); |
}); |
||
}; |
|||
$('<label>').attr('for', 'quick-delete').text('Quick Delete').css({ |
|||
'font-size': '14px' |
|||
QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) { |
|||
}).prepend(quickDeleteCheckbox).appendTo(popup); |
|||
// Prosty popup do zamykania dyskusji |
|||
$('< |
var $dialog = $('<div class="quick-close-dialog">' + |
||
' |
'<h3>Close Deletion Request</h3>' + |
||
' |
'<div>' + |
||
' |
'<label>Outcome:</label>' + |
||
'<select id="quick-close-outcome">' + |
|||
}).appendTo(popup); |
|||
'<option value="{{delete}}">Delete</option>' + |
|||
'<option value="{{keep}}">Keep</option>' + |
|||
const quickDeleteReasonSelect = $('<select>').attr('id', 'quick-delete-reason').css({ |
|||
' |
'<option value="{{merge}}">Merge</option>' + |
||
'<option value="{{redirect}}">Redirect</option>' + |
|||
'padding': '6px', |
|||
'</select>' + |
|||
' |
'</div>' + |
||
'<div>' + |
|||
'<label>Additional Comments (optional):</label>' + |
|||
'<textarea id="quick-close-comment" rows="3"></textarea>' + |
|||
const reasons = { |
|||
' |
'</div>' + |
||
' |
(mw.config.get('wgUserGroups').includes('sysop') ? |
||
'<div>' + |
|||
'<label><input type="checkbox" id="quick-close-delete-page"> Delete this page</label>' + |
|||
'A4': 'Not notable', |
|||
' |
'</div>' : '') + |
||
' |
'<div class="quick-close-buttons">' + |
||
'<button id="quick-close-confirm">Close Discussion</button>' + |
|||
'G2': 'Test page', |
|||
'<button id="quick-close-cancel">Cancel</button>' + |
|||
'G3': 'Vandalism', |
|||
' |
'</div>' + |
||
'</div>'); |
|||
'G12': 'Copyright infringement' |
|||
// Dodanie arkusza stylów dla dialogu |
|||
}; |
|||
$('head').append(` |
|||
<style> |
|||
.quick-close-dialog { |
|||
$('<option>').attr('value', key).text(key + ' - ' + value).appendTo(quickDeleteReasonSelect); |
|||
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 |
|||
$('<button>').text('Submit nomination').css({ |
|||
$('#quick-close-confirm').click(function() { |
|||
'width': '100%', |
|||
var outcome = $('#quick-close-outcome').val(); |
|||
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: '; |
|||
'background-color': '#0073e6', |
|||
var deleteRequest = $('#quick-close-delete-page:checked').length > 0; |
|||
'color': '#fff', |
|||
QuickCloseRfD.closeDiscussion( |
|||
sectionNumber, |
|||
outcome, |
|||
comment, |
|||
deleteRequest |
|||
); |
|||
const quickDelete = quickDeleteCheckbox.is(':checked'); |
|||
$dialog.remove(); |
|||
}); |
|||
}; |
|||
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({ |
|||
tagPageForQuickDeletion(quickDeleteReason); |
|||
action: 'edit', |
|||
title: pageTitle, |
|||
section: sectionNumber, |
|||
text: wikitext, |
|||
summary: 'Closing deletion discussion for ' + pageName |
|||
} |
|||
}).done(function() { |
|||
// Opcjonalne usunięcie strony dla administratorów |
|||
function closeDeletionPopup() { |
|||
if (deleteRequest) { |
|||
$('#deletion-popup-overlay').remove(); |
|||
new mw.Api().postWithEditToken({ |
|||
} |
|||
action: 'delete', |
|||
title: 'Wikipedia:Requests for deletion/Requests/2025/' + pageName, |
|||
function tagPageForQuickDeletion(reason) { |
|||
reason: 'Deletion discussion completed' |
|||
}).done(function() { |
|||
location.reload(); |
|||
}); |
|||
} else { |
|||
location.reload(); |
|||
} |
|||
}) |
}); |
||
alert('Quick Delete tag added.'); |
|||
}).fail(function() { |
|||
alert('Failed to add Quick Delete tag.'); |
|||
}); |
}); |
||
} |
}; |
||
// Ładowanie skryptu |
|||
function initiateDeletionProcess(shortReason, detailedReason) { |
|||
mw.loader.using('mediawiki.api', function() { |
|||
tagPageForDeletion(shortReason); |
|||
$(document).ready(function() { |
|||
createDiscussionPage(detailedReason); |
|||
QuickCloseRfD.setup(); |
|||
notifyPageCreator(); |
|||
closeDeletionPopup(); |
|||
} |
|||
function tagPageForDeletion(reason) { |
|||
const tag = `{{rfd|${reason}}}`; |
|||
const editSummary = 'Nominating for deletion (RfD)'; |
|||
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.'); |
|||
}); |
}); |
||
} |
}); |
||
})(jQuery); |
|||
// </nowiki> |
|||
function createDiscussionPage(detailedReason) { |
|||
// Pseudokod funkcji tworzącej stronę dyskusji |
|||
console.log('Creating discussion page with reason:', detailedReason); |
|||
} |
|||
function addToDeletionList() { |
|||
// Pseudokod funkcji dodającej stronę do listy usunięć |
|||
console.log('Adding to deletion list'); |
|||
} |
|||
function notifyPageCreator() { |
|||
// Pseudokod funkcji powiadamiającej twórcę strony |
|||
console.log('Notifying page creator'); |
|||
} |
|||
})(); |
Latest revision as of 20:25, 25 March 2025
// <nowiki>
(function($) {
// Główny obiekt skryptu
var QuickCloseRfD = {};
// Konfiguracja przestrzeni nazw
const ALLOWED_NAMESPACES = ['Wikipedia:Requests for deletion'];
QuickCloseRfD.setup = function() {
// Sprawdzenie, czy jesteśmy na odpowiedniej stronie
var wgPageName = mw.config.get('wgPageName');
var wgNamespaceNumber = mw.config.get('wgNamespaceNumber');
if (ALLOWED_NAMESPACES.includes(wgPageName) ||
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) {
$('span.mw-editsection-bracket:first-child').each(function() {
try {
// Pobieranie numeru sekcji
var sectionNumber = this.parentElement.childNodes[1].href
.match(/action=edit§ion=(\d+)/)[1];
// Dodawanie przycisku Quick Close
$(this).after(' | ');
$(this).after(
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' +
'data-section="' + sectionNumber + '">Quick Close</a>')
);
} catch(e) {}
});
// Obsługa kliknięcia przycisku
QuickCloseRfD.bindEvents();
}
};
QuickCloseRfD.bindEvents = function() {
$('.QuickCloseRfD-close').click(function(e) {
var sectionNumber = $(this).data('section');
QuickCloseRfD.showQuickCloseDialog(sectionNumber);
});
};
QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) {
// Prosty popup do zamykania dyskusji
var $dialog = $('<div class="quick-close-dialog">' +
'<h3>Close Deletion Request</h3>' +
'<div>' +
'<label>Outcome:</label>' +
'<select id="quick-close-outcome">' +
'<option value="{{delete}}">Delete</option>' +
'<option value="{{keep}}">Keep</option>' +
'<option value="{{merge}}">Merge</option>' +
'<option value="{{redirect}}">Redirect</option>' +
'</select>' +
'</div>' +
'<div>' +
'<label>Additional Comments (optional):</label>' +
'<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() {
var outcome = $('#quick-close-outcome').val();
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: ';
var deleteRequest = $('#quick-close-delete-page:checked').length > 0;
QuickCloseRfD.closeDiscussion(
sectionNumber,
outcome,
comment,
deleteRequest
);
$dialog.remove();
});
};
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>