User:BZPN/RfD.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
Tags: Manual revert Reverted Mobile edit Mobile web edit
No edit summary
 
(20 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
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');

// Funkcja wywoływana po kliknięciu przycisku nominacji do usunięcia
if (ALLOWED_NAMESPACES.includes(wgPageName) ||
$('#ca-nominate-deletion').on('click', function(e) {
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) {
e.preventDefault();
openDeletionPopup();
$('span.mw-editsection-bracket:first-child').each(function() {
});
try {

// Pobieranie numeru sekcji
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia
var sectionNumber = this.parentElement.childNodes[1].href
function openDeletionPopup() {
.match(/action=edit&section=(\d+)/)[1];
// Tworzenie nakładki
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
// Dodawanie przycisku Quick Close
'position': 'fixed',
'top': '0',
$(this).after(' | ');
'left': '0',
$(this).after(
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' +
'width': '100%',
'height': '100%',
'data-section="' + sectionNumber + '">Quick Close</a>')
'background-color': 'rgba(0, 0, 0, 0.5)',
);
'z-index': '1000',
} catch(e) {}
}).appendTo('body');
});

// Tworzenie okna popup
// Obsługa kliknięcia przycisku
QuickCloseRfD.bindEvents();
const popup = $('<div>').attr('id', 'deletion-popup').css({
'width': '400px',
}
};
'margin': '10% auto',
'padding': '20px',
QuickCloseRfD.bindEvents = function() {
'background-color': '#fff',
$('.QuickCloseRfD-close').click(function(e) {
'border-radius': '8px',
'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)',
var sectionNumber = $(this).data('section');
QuickCloseRfD.showQuickCloseDialog(sectionNumber);
'text-align': 'left',
'position': 'relative'
}).appendTo(overlay);

// Przycisk zamknięcia popup
$('<span>').text('×').css({
'position': 'absolute',
'top': '10px',
'right': '15px',
'cursor': 'pointer',
'font-size': '18px',
'font-weight': 'bold'
}).on('click', closeDeletionPopup).appendTo(popup);

// Tytuł okna
$('<h3>').text('Nominate for deletion').appendTo(popup);

// Informacja o zasadach RfD i link do Wikipedia:Requests for deletion
$('<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': '15px'
}).appendTo(popup);

// CheckBox do potwierdzenia zapoznania się z polityką
const policyCheckbox = $('<input>').attr({
'type': 'checkbox',
'id': 'policy-confirmation'
}).css({
'margin-right': '5px'
});
});
};
$('<label>').attr('for', 'policy-confirmation').text('I have read and agree with the deletion policy').prepend(policyCheckbox).appendTo(popup);

QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) {
// Pole na krótki powód
// Prosty popup do zamykania dyskusji
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').css({
var $dialog = $('<div class="quick-close-dialog">' +
'display': 'block',
'margin-top': '15px'
'<h3>Close Deletion Request</h3>' +
}).appendTo(popup);
'<div>' +
const shortReasonInput = $('<input>').attr({
'<label>Outcome:</label>' +
'type': 'text',
'<select id="quick-close-outcome">' +
'<option value="{{delete}}">Delete</option>' +
'id': 'deletion-short-reason',
'<option value="{{keep}}">Keep</option>' +
'placeholder': 'Enter short reason...'
'<option value="{{merge}}">Merge</option>' +
}).css({
'width': '100%',
'<option value="{{redirect}}">Redirect</option>' +
'padding': '6px',
'</select>' +
'margin': '5px 0'
'</div>' +
}).appendTo(popup);
'<div>' +
'<label>Additional Comments (optional):</label>' +

'<textarea id="quick-close-comment" rows="3"></textarea>' +
// Pole na szczegółowy powód
'</div>' +
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').css({
'display': 'block',
(mw.config.get('wgUserGroups').includes('sysop') ?
'margin-top': '10px'
'<div>' +
'<label><input type="checkbox" id="quick-close-delete-page"> Delete this page</label>' +
}).appendTo(popup);
const detailedReasonInput = $('<textarea>').attr({
'</div>' : '') +
'id': 'deletion-detailed-reason',
'<div class="quick-close-buttons">' +
'<button id="quick-close-confirm">Close Discussion</button>' +
'placeholder': 'Enter detailed reason...'
'<button id="quick-close-cancel">Cancel</button>' +
}).css({
'width': '100%',
'</div>' +
'padding': '6px',
'</div>');
'height': '80px',
'margin': '5px 0'
// Dodanie arkusza stylów dla dialogu
}).appendTo(popup);
$('head').append(`
<style>

// Przycisk wyślij
.quick-close-dialog {
background: white;
$('<button>').text('Submit nomination').css({
'width': '100%',
border: 1px solid #a2a9b1;
'padding': '10px',
border-radius: 5px;
'background-color': '#0073e6',
padding: 15px;
'color': '#fff',
width: 400px;
'border': 'none',
margin: 0 auto;
'border-radius': '5px',
position: fixed;
'cursor': 'pointer',
top: 50%;
'margin-top': '10px'
left: 50%;
transform: translate(-50%, -50%);
}).on('click', function() {
if (!policyCheckbox.is(':checked')) {
z-index: 1000;
alert('Please confirm you have read the deletion policy.');
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
return;
}
}
.quick-close-dialog h3 {
const shortReason = shortReasonInput.val().trim();
margin-top: 0;
const detailedReason = detailedReasonInput.val().trim();
border-bottom: 1px solid #eaecf0;
if (shortReason && detailedReason) {
padding-bottom: 10px;
initiateDeletionProcess(shortReason, detailedReason);
}
} else {
.quick-close-dialog div {
alert('Please provide both a short and detailed reason.');
margin-bottom: 10px;
}
}
}).appendTo(popup);
.quick-close-dialog label {
display: block;
}
margin-bottom: 5px;

}
// Funkcja zamykająca popup
.quick-close-dialog select,
function closeDeletionPopup() {
$('#deletion-popup-overlay').remove();
.quick-close-dialog textarea {
width: 100%;
}
box-sizing: border-box;

}
// Funkcja inicjująca proces usunięcia
.quick-close-buttons {
function initiateDeletionProcess(shortReason, detailedReason) {
tagPageForDeletion(shortReason);
display: flex;
justify-content: space-between;
createDiscussionPage(detailedReason);
addToDeletionList();
}
.quick-close-buttons button {
notifyPageCreator();
closeDeletionPopup();
padding: 5px 10px;
}
}
</style>

`);
// Funkcja do oznaczania strony do usunięcia
function tagPageForDeletion(reason) {
$('body').append($dialog);
const tag = `{{rfd|${reason}}}`;
const editSummary = 'Nominating for deletion ([[User:BZPN/RfD.js|RfD]])';
// Zamykanie dialogu

new mw.Api().postWithToken('csrf', {
$('#quick-close-cancel').click(function() {
action: 'edit',
$dialog.remove();
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.');
});
});
}
// Potwierdzenie zamknięcia

$('#quick-close-confirm').click(function() {
// Funkcja do tworzenia strony dyskusji o usunięciu
var outcome = $('#quick-close-outcome').val();
function createDiscussionPage(reason) {
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: ';
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}`;
var deleteRequest = $('#quick-close-delete-page:checked').length > 0;
const discussionContent = `{{subst:RfD/Preload/Template|deletereason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`;

QuickCloseRfD.closeDiscussion(
new mw.Api().postWithToken('csrf', {
action: 'edit',
sectionNumber,
title: discussionPageTitle,
outcome,
text: discussionContent,
comment,
summary: 'Starting deletion discussion ([[User:BZPN/RfD.js|RfD]])',
deleteRequest
watchlist: 'watch',
);
}).done(function() {
alert('Deletion discussion page created.');
$dialog.remove();
}).fail(function() {
alert('Failed to create deletion discussion page. Please try again.');
});
});
}
};

QuickCloseRfD.closeDiscussion = function(sectionNumber, outcome, comment, deleteRequest) {
// Funkcja dodająca dyskusję do listy
var pageTitle = mw.config.get('wgPageName');
function addToDeletionList() {
var pageName = pageTitle.split('/').pop();
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}}}`;
new mw.Api().get({

action: 'parse',
new mw.Api().edit(deletionListTitle, function(revision) {
return {
page: pageTitle,
text: discussionLink + '\n' + revision.content,
prop: 'wikitext',
section: sectionNumber
summary: 'Adding new deletion discussion ([[User:BZPN/RfD.js|RfD]])',
}).done(function(result) {
watchlist: 'watch',
};
var wikitext = result.parse.wikitext['*'];
}).done(function() {
alert('Deletion discussion added to the list.');
// 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 add the discussion to the deletion list. 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 powiadamiająca autora strony
'</div>';
function notifyPageCreator() {
const creator = mw.config.get('wgPageContentModel') === 'wikitext' ? mw.config.get('wgPageCreator') : null;
wikitext += '\n' + closingText;
if (creator) {
const notification = `{{subst:RFDNote|${mw.config.get('wgPageName')}}} ~~"+"~~`;
new mw.Api().postWithToken('csrf', {
// Edycja strony
new mw.Api().postWithEditToken({
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();
}
});
});
}
});
}
};
})();
// Ł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>