User:BZPN/RfD.js

From Test Wiki
Revision as of 19:43, 1 November 2024 by BZPN (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
(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();
        };
    }

    // Dodanie zakładki Quick Delete do popupu
    function addQuickDeleteTab(popup) {
        const quickDeleteTab = $('<div>').attr('id', 'quick-delete-tab').css({
            'display': 'none' // Domyślnie ukryty
        }).appendTo(popup);

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

        $('<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({
                'font-size': '14px',
                'margin-bottom': '10px'
            }).appendTo(quickDeleteTab);

        const consentCheckbox = $('<input>').attr('type', 'checkbox').attr('id', 'consent-checkbox').css('margin-right', '10px');
        const consentLabel = $('<label>').attr('for', 'consent-checkbox').text('I have read and understand the deletion policy.');
        $('<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
        $('<button>').text('Quick Delete').css({
            'width': '100%',
            'padding': '10px',
            'background-color': '#d9534f',
            'color': '#fff',
            'border': 'none',
            'border-radius': '5px',
            'cursor': 'pointer',
            'font-size': '16px'
        }).on('click', function() {
            const reason = quickDeleteSelect.val();
            const consent = consentCheckbox.is(':checked');
            if (reason && consent) {
                tagPageForQuickDeletion(reason);
            } else if (!consent) {
                alert('Please confirm you have read the deletion policy.');
            } else {
                alert('Please choose a reason for quick deletion.');
            }
        }).appendTo(quickDeleteTab);
    }

    // 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({
            'position': 'fixed',
            'top': '50%',
            'left': '50%',
            'transform': 'translate(-50%, -50%)',
            'background-color': '#fff',
            'padding': '20px',
            'border': '1px solid #ddd',
            'border-radius': '5px',
            'box-shadow': '0 0 10px rgba(0, 0, 0, 0.5)',
            'z-index': '1001'
        }).appendTo('body');

        // Dodanie zakładki Request for Deletion
        const requestDeletionTab = $('<div>').attr('id', 'request-deletion-tab').appendTo(popup);

        $('<h3>').text('Request for Deletion').css({
            'font-size': '18px',
            'margin-bottom': '10px'
        }).appendTo(requestDeletionTab);

        $('<p>').html('Before proceeding with Request for Deletion, please read the <a href="/wiki/Wikipedia:Deletion_policy" target="_blank">Wikipedia Deletion Policy</a>.')
            .css({
                'font-size': '14px',
                'margin-bottom': '10px'
            }).appendTo(requestDeletionTab);

        const reasonInput = $('<textarea>').attr('id', 'deletion-reason').css({
            'width': '100%',
            'height': '100px',
            'padding': '10px',
            'font-size': '14px',
            'margin-bottom': '10px'
        }).appendTo(requestDeletionTab);

        // Przycisk do nominacji do usunięcia
        $('<button>').text('Nominate for Deletion').css({
            'width': '100%',
            'padding': '10px',
            'background-color': '#337ab7',
            '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();
        });
    }

    // Funkcja oznaczająca stronę do usunięcia
    function tagPageForDeletion(reason) {
        const tag = `{{db|${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 tworząca stronę 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 = `{{subst: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 the page creator. Please try again.');
            });
        }
    }

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