User:BZPN/RfD.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
 
(4 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', // Pasek narzędzi
const ALLOWED_NAMESPACES = ['Wikipedia:Requests for deletion'];
'#', // link docelowy
'Nominate for deletion', // Tekst przycisku
QuickCloseRfD.setup = function() {
'ca-nominate-deletion', // ID linku
// Sprawdzenie, czy jesteśmy na odpowiedniej stronie
'Nominate this page for deletion' // Podpowiedź tekstowa
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) {
nominateLink.onclick = function(event) {
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) {
event.preventDefault();
$('span.mw-editsection-bracket:first-child').each(function() {
openDeletionPopup();
};
try {
// Pobieranie numeru sekcji
}
var sectionNumber = this.parentElement.childNodes[1].href

.match(/action=edit&section=(\d+)/)[1];
// Dodanie zakładki Quick Delete do popupu
function addQuickDeleteTab(popup) {
// Dodawanie przycisku Quick Close
const quickDeleteTab = $('<div>').attr('id', 'quick-delete-tab').css({
'display': 'none' // Domyślnie ukryty
$(this).after(' | ');
}).appendTo(popup);
$(this).after(
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' +

$('<h3>').text('Quick Delete').css({
'data-section="' + sectionNumber + '">Quick Close</a>')
'font-size': '18px',
);
'margin-bottom': '10px'
} catch(e) {}
}).appendTo(quickDeleteTab);
});

// Obsługa kliknięcia przycisku
$('<p>').html('Before proceeding with Quick Deletion, please read the <a href="/wiki/Template:QD" target="_blank">Template:QD</a> documentation and the <a href="/wiki/Wikipedia:Deletion_policy" target="_blank">Wikipedia Deletion Policy</a>.')
.css({
QuickCloseRfD.bindEvents();
'font-size': '14px',
}
};
'margin-bottom': '10px'
}).appendTo(quickDeleteTab);
QuickCloseRfD.bindEvents = function() {

$('.QuickCloseRfD-close').click(function(e) {
const consentCheckbox = $('<input>').attr('type', 'checkbox').attr('id', 'consent-checkbox').css('margin-right', '10px');
var sectionNumber = $(this).data('section');
const consentLabel = $('<label>').attr('for', 'consent-checkbox').text('I have read and understand the deletion policy.');
QuickCloseRfD.showQuickCloseDialog(sectionNumber);
$('<div>').append(consentCheckbox).append(consentLabel).appendTo(quickDeleteTab);

$('<p>').text('Choose a reason for quick deletion from the list below:').css({
'font-size': '14px',
'margin-bottom': '10px'
}).appendTo(quickDeleteTab);

const quickDeleteSelect = $('<select>').attr('id', 'quick-delete-reason').css({
'width': '100%',
'padding': '6px',
'font-size': '14px',
'margin-bottom': '10px'
}).appendTo(quickDeleteTab);

const reasons = [
{ value: 'A1', text: 'Little or no meaning' },
{ value: 'A2', text: 'No content' },
{ value: 'A3', text: 'Article is transwikied' },
{ value: 'A4', text: 'Does not say why it is notable' },
{ value: 'A5', text: 'Not in English' },
{ value: 'A6', text: 'Hoax' }
];

$.each(reasons, function(index, reason) {
quickDeleteSelect.append($('<option>').attr('value', reason.value).text(reason.text));
});
});
};

// Przycisk do szybkiego usunięcia
QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) {
$('<button>').text('Quick Delete').css({
'width': '100%',
// Prosty popup do zamykania dyskusji
var $dialog = $('<div class="quick-close-dialog">' +
'padding': '10px',
'background-color': '#d9534f',
'<h3>Close Deletion Request</h3>' +
'color': '#fff',
'<div>' +
'border': 'none',
'<label>Outcome:</label>' +
'border-radius': '5px',
'<select id="quick-close-outcome">' +
'cursor': 'pointer',
'<option value="{{delete}}">Delete</option>' +
'font-size': '16px'
'<option value="{{keep}}">Keep</option>' +
'<option value="{{merge}}">Merge</option>' +
}).on('click', function() {
'<option value="{{redirect}}">Redirect</option>' +
const reason = quickDeleteSelect.val();
const consent = consentCheckbox.is(':checked');
'</select>' +
if (reason && consent) {
'</div>' +
tagPageForQuickDeletion(reason);
'<div>' +
} else if (!consent) {
'<label>Additional Comments (optional):</label>' +
'<textarea id="quick-close-comment" rows="3"></textarea>' +
alert('Please confirm you have read the deletion policy.');
} else {
'</div>' +
(mw.config.get('wgUserGroups').includes('sysop') ?
alert('Please choose a reason for quick deletion.');
}
'<div>' +
'<label><input type="checkbox" id="quick-close-delete-page"> Delete this page</label>' +
}).appendTo(quickDeleteTab);
'</div>' : '') +
}
'<div class="quick-close-buttons">' +

'<button id="quick-close-confirm">Close Discussion</button>' +
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia
'<button id="quick-close-cancel">Cancel</button>' +
function openDeletionPopup() {
// Tworzenie nakładki
'</div>' +
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
'</div>');
'position': 'fixed',
'top': '0',
// Dodanie arkusza stylów dla dialogu
'left': '0',
$('head').append(`
'width': '100%',
<style>
'height': '100%',
.quick-close-dialog {
'background-color': 'rgba(0, 0, 0, 0.5)',
background: white;
'z-index': '1000'
border: 1px solid #a2a9b1;
}).appendTo('body');
border-radius: 5px;
padding: 15px;

// Tworzenie okna popup
width: 400px;
margin: 0 auto;
const popup = $('<div>').attr('id', 'deletion-popup').css({
'position': 'fixed',
position: fixed;
'top': '50%',
top: 50%;
'left': '50%',
left: 50%;
'transform': 'translate(-50%, -50%)',
transform: translate(-50%, -50%);
'background-color': '#fff',
z-index: 1000;
'padding': '20px',
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
'border': '1px solid #ddd',
}
'border-radius': '5px',
.quick-close-dialog h3 {
'box-shadow': '0 0 10px rgba(0, 0, 0, 0.5)',
margin-top: 0;
'z-index': '1001'
border-bottom: 1px solid #eaecf0;
}).appendTo('body');
padding-bottom: 10px;
}

.quick-close-dialog div {
// Dodanie zakładki Request for Deletion
margin-bottom: 10px;
const requestDeletionTab = $('<div>').attr('id', 'request-deletion-tab').appendTo(popup);
}

.quick-close-dialog label {
$('<h3>').text('Request for Deletion').css({
'font-size': '18px',
display: block;
'margin-bottom': '10px'
margin-bottom: 5px;
}
}).appendTo(requestDeletionTab);
.quick-close-dialog select,

.quick-close-dialog textarea {
$('<p>').html('Before proceeding with Request for Deletion, please read the <a href="/wiki/Wikipedia:Deletion_policy" target="_blank">Wikipedia Deletion Policy</a>.')
.css({
width: 100%;
'font-size': '14px',
box-sizing: border-box;
'margin-bottom': '10px'
}
}).appendTo(requestDeletionTab);
.quick-close-buttons {
display: flex;

justify-content: space-between;
const reasonInput = $('<textarea>').attr('id', 'deletion-reason').css({
'width': '100%',
}
'height': '100px',
.quick-close-buttons button {
'padding': '10px',
padding: 5px 10px;
'font-size': '14px',
}
'margin-bottom': '10px'
</style>
}).appendTo(requestDeletionTab);
`);

$('body').append($dialog);
// Przycisk do nominacji do usunięcia
$('<button>').text('Nominate for Deletion').css({
'width': '100%',
// Zamykanie dialogu
$('#quick-close-cancel').click(function() {
'padding': '10px',
'background-color': '#337ab7',
$dialog.remove();
'color': '#fff',
'border': 'none',
'border-radius': '5px',
'cursor': 'pointer',
'font-size': '16px'
}).on('click', function() {
const reason = reasonInput.val();
if (reason) {
tagPageForDeletion(reason);
} else {
alert('Please enter a reason for deletion.');
}
}).appendTo(requestDeletionTab);

// Dodanie zakładki Quick Delete
addQuickDeleteTab(popup);

// Zamknięcie okna popup po kliknięciu poza nim
overlay.on('click', function() {
overlay.remove();
popup.remove();
});
});
}
// Potwierdzenie zamknięcia

$('#quick-close-confirm').click(function() {
// Funkcja oznaczająca stronę do usunięcia
var outcome = $('#quick-close-outcome').val();
function tagPageForDeletion(reason) {
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: ';
const tag = `{{db|${reason}}}`;
var deleteRequest = $('#quick-close-delete-page:checked').length > 0;
const editSummary = 'Nominating for deletion ([[User :BZPN/RfD.js|RfD]])';

QuickCloseRfD.closeDiscussion(
new mw.Api().postWithToken('csrf', {
action: 'edit',
sectionNumber,
title: mw.config.get('wgPageName'),
outcome,
prependtext: tag + '\n',
comment,
summary: editSummary,
deleteRequest
watchlist: 'watch',
);
}).done(function() {
alert('Page tagged for deletion.');
$dialog.remove();
}).fail(function() {
alert('Failed to tag the page for deletion. Please try again.');
});
});
}
};

QuickCloseRfD.closeDiscussion = function(sectionNumber, outcome, comment, deleteRequest) {
// Funkcja tworząca stronę dyskusji o usunięciu
var pageTitle = mw.config.get('wgPageName');
function createDiscussionPage(reason) {
var pageName = pageTitle.split('/').pop();
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}`;
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().get({

new mw.Api().postWithToken('csrf', {
action: 'parse',
action: 'edit',
page: pageTitle,
title: discussionPageTitle,
prop: 'wikitext',
text: discussionContent,
section: sectionNumber
}).done(function(result) {
summary: 'Starting deletion discussion ([[User :BZPN/RfD.js|RfD]])',
watchlist: 'watch',
var wikitext = result.parse.wikitext['*'];
}).done(function() {
alert('Deletion discussion page created.');
// Dodanie zamknięcia dyskusji
var closingText =
}).fail(function() {
'<div class="boilerplate" style="background-color: #EDEAFF; padding: 0px 10px 0px 10px; border: 1px solid #8779DD;">\n' +
alert('Failed to create deletion discussion page. Please try again.');
':\'\'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' +
// Funkcja dodająca dyskusję do listy
'</div>';
function addToDeletionList() {
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
wikitext += '\n' + closingText;
const discussionLink = `{{subst:Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}}}`;

// Edycja strony
new mw.Api().edit(deletionListTitle, function(revision) {
return {
new mw.Api().postWithEditToken({
text: discussionLink + '\n' + revision.content,
summary: 'Adding new deletion discussion ([[User :BZPN/RfD.js|RfD]])',
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.');
});
}

// 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',
action: 'edit',
title: `User talk:${creator}`,
title: pageTitle,
appendtext: '\n' + notification,
section: sectionNumber,
text: wikitext,
summary: 'Notifying page creator about deletion nomination ([[User :BZPN/RfD.js|RfD]])',
watchlist: 'watch',
summary: 'Closing deletion discussion for ' + pageName
}).done(function() {
}).done(function() {
alert('Page creator notified.');
// Opcjonalne usunięcie strony dla administratorów
}).fail(function() {
if (deleteRequest) {
alert('Failed to notify the page creator. Please try again.');
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();
}
});
});
}
}

// Funkcja oznaczająca stronę do szybkiego usunięcia
function tagPageForQuickDeletion(reason) {
const tag = `{{qd|${reason}}}`;
const editSummary = 'Nominating for quick deletion ([[User :BZPN/RfD.js|QD]])';

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 quick deletion.');
}).fail(function() {
alert('Failed to tag the page for quick deletion. Please try again.');
});
});
}
};
})();
// Ładowanie skryptu
mw.loader.using('mediawiki.api', function() {
$(document).ready(function() {
QuickCloseRfD.setup();
});
});
})(jQuery);
// </nowiki>

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&section=(\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>