User:BZPN/RfD.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Undo revision 52874 by BZPN (talk)
Tags: Undo Mobile edit Mobile web edit
Line 18: Line 18:
};
};
}
}
// === Wstaw ten fragment PRZED openDeletionPopup ===


// Dodanie zakładki Quick Delete do popupu
function addQuickDeleteTab(popup) {
// Tworzenie zakładki QD i formularza
const quickDeleteTab = $('<div>').attr('id', 'quick-delete-tab').css({
'display': 'none' // Domyślnie ukryty, widoczny po przełączeniu na zakładkę QD
}).appendTo(popup);

$('<h3>').text('Quick Delete').css({
'font-size': '18px',
'margin-bottom': '10px'
}).appendTo(quickDeleteTab);

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

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

// Dodanie opcji do listy
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' },
// Dodaj inne powody według potrzeb
];

reasons.forEach(reason => {
$('<option>').attr('value', reason.value).text(`${reason.value} - ${reason.text}`).appendTo(quickDeleteSelect);
});

// Przycisk zatwierdzenia QD
$('<button>').text('Submit Quick Delete').css({
'width': '100%',
'padding': '10px',
'background-color': '#d9534f',
'color': '#fff',
'border': 'none',
'border-radius': '5px',
'cursor': 'pointer',
'font-size': '16px',
'margin-top': '10px'
}).on('click', function() {
const selectedReason = quickDeleteSelect.val();
if (selectedReason) {
insertQuickDeleteTag(selectedReason);
} else {
alert('Please select a reason for quick deletion.');
}
}).appendTo(quickDeleteTab);
}

// Funkcja wstawiająca tag QD na górę strony
function insertQuickDeleteTag(reason) {
const tag = `{{QD|${reason}}}`;
const editSummary = `Tagging page for quick deletion (Reason: ${reason})`;

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.');
});
}

// === Koniec fragmentu PRZED openDeletionPopup ===
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia
function openDeletionPopup() {
function openDeletionPopup() {
Line 112: Line 31:
'z-index': '1000',
'z-index': '1000',
}).appendTo('body');
}).appendTo('body');
// === Wstaw ten fragment NA POCZĄTKU openDeletionPopup ===

// Dodaj przyciski do przełączania między zakładkami RfD i QD
$('<div>').css({
'display': 'flex',
'justify-content': 'space-around',
'margin-bottom': '10px'
}).append(
$('<button>').text('Request for Deletion').css({
'flex': '1',
'padding': '6px',
'font-size': '14px',
'border': 'none',
'background-color': '#0073e6',
'color': '#fff',
'cursor': 'pointer'
}).on('click', function() {
$('#request-deletion-tab').show();
$('#quick-delete-tab').hide();
}),
$('<button>').text('Quick Delete').css({
'flex': '1',
'padding': '6px',
'font-size': '14px',
'border': 'none',
'background-color': '#d9534f',
'color': '#fff',
'cursor': 'pointer'
}).on('click', function() {
$('#quick-delete-tab').show();
$('#request-deletion-tab').hide();
})
).prependTo(popup);

// Dodaj zakładkę Quick Delete do popupu
addQuickDeleteTab(popup);


// === Koniec fragmentu NA POCZĄTKU openDeletionPopup ===
// Tworzenie okna popup
// Tworzenie okna popup
const popup = $('<div>').attr('id', 'deletion-popup').css({
const popup = $('<div>').attr('id', 'deletion-popup').css({

Revision as of 18:50, 1 November 2024

(function() {
    if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return;

    // Dodaj przycisk "Nominate for deletion" do paska narzędzi
    var nominateLink = mw.util.addPortletLink(
        'p-tb', // Pasek narzędzi
        '#', // link docelowy
        'Nominate for deletion', // Tekst przycisku
        'ca-nominate-deletion', // ID linku
        'Nominate this page for deletion' // Podpowiedź tekstowa
    );

    // Jeśli dodanie przycisku się powiodło, przypisz funkcję do obsługi kliknięcia
    if (nominateLink) {
        nominateLink.onclick = function(event) {
            event.preventDefault();
            openDeletionPopup();
        };
    }

    // Tworzenie i otwarcie okna popup dla nominacji do usunięcia
    function openDeletionPopup() {
        // Tworzenie nakładki
        const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
            'position': 'fixed',
            'top': '0',
            'left': '0',
            'width': '100%',
            'height': '100%',
            'background-color': 'rgba(0, 0, 0, 0.5)',
            'z-index': '1000',
        }).appendTo('body');

        // Tworzenie okna popup
        const popup = $('<div>').attr('id', 'deletion-popup').css({
            'width': '90%',
            'max-width': '400px',
            'margin': '10% auto',
            'padding': '15px',
            'background-color': '#fff',
            'border-radius': '8px',
            'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)',
            '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').css({
            'font-size': '18px',
            'margin-bottom': '10px'
        }).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'
        }).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);

        // Pole na krótki powód - poprawka do krawędzi dolnej
        $('<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',
            'line-height': '1.5', // poprawka dla dolnej krawędzi
        }).appendTo(popup);

        // Pole na szczegółowy powód
        $('<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 potwierdzenia zapoznania się z polityką
        const policyCheckbox = $('<input>').attr({
            'type': 'checkbox',
            'id': 'policy-confirmation'
        }).css({
            'margin-right': '5px'
        });
        const policyLabel = $('<label>').attr('for', 'policy-confirmation').text('I have read and understand the deletion policy.');
        $('<div>').append(policyCheckbox, policyLabel).css({
            'margin-bottom': '15px'
        }).appendTo(popup);



        // Przycisk wyślij
        $('<button>').text('Submit nomination').css({
            'width': '100%',
            'padding': '10px',
            'background-color': '#0073e6',
            'color': '#fff',
            'border': 'none',
            'border-radius': '5px',
            'cursor': 'pointer',
            'font-size': '16px'
        }).on('click', function() {
            const shortReason = shortReasonInput.val().trim();
            const detailedReason = detailedReasonInput.val().trim();
            const policyConfirmed = policyCheckbox.is(':checked');
            if (shortReason && detailedReason && policyConfirmed) {
                initiateDeletionProcess(shortReason, detailedReason);
            } else if (!policyConfirmed) {
                alert('Please confirm you have read the deletion policy.');
            } else {
                alert('Please provide both a short and detailed reason.');
            }
        }).appendTo(popup);
    }

    // Funkcja zamykająca popup
    function closeDeletionPopup() {
        $('#deletion-popup-overlay').remove();
    }

    // Funkcja inicjująca proces usunięcia
    function initiateDeletionProcess(shortReason, detailedReason) {
        tagPageForDeletion(shortReason);
        createDiscussionPage(detailedReason);
        addToDeletionList();
        notifyPageCreator();
        closeDeletionPopup();
    }

    // Funkcja do oznaczania strony do usunięcia
    function tagPageForDeletion(reason) {
        const tag = `{{rfd|${reason}}}`;
        const editSummary = 'Nominating for deletion ([[User:BZPN/RfD.js|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. Please try again.');
        });
    }

    // Funkcja do tworzenia strony dyskusji o usunięciu
    function createDiscussionPage(reason) {
        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().postWithToken('csrf', {
            action: 'edit',
            title: discussionPageTitle,
            text: discussionContent,
            summary: 'Starting deletion discussion ([[User:BZPN/RfD.js|RfD]])',
            watchlist: 'watch',
        }).done(function() {
            alert('Deletion discussion page created.');
        }).fail(function() {
            alert('Failed to create deletion discussion page. Please try again.');
        });
    }

    // Funkcja dodająca dyskusję do listy
    function addToDeletionList() {
        const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
        const discussionLink = `{{Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}}}`;

        new mw.Api().edit(deletionListTitle, function(revision) {
            return {
                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',
                title: `User talk:${creator}`, appendtext: '\n' + notification,
                summary: 'Notifying page creator about deletion nomination ([[User:BZPN/RfD.js|RfD]])',
                watchlist: 'watch',
            }).done(function() {
                alert('Page creator notified.');
            }).fail(function() {
                alert('Failed to notify these page creator. Please try again.');
            });
        }
    }
})();