User:BZPN/Zgłaszarka.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 41: Line 41:
                                 section: 'new',
                                 section: 'new',
                                 sectiontitle: 'Prośba o ukrycie',
                                 sectiontitle: 'Prośba o ukrycie',
                                 text: '[[Special:Diff/' + diffNumber + '|Diff' + diffNumber + ']] - ' + reason + '\n\nZgłasza:'+'~~'+'~~',
                                 text: '[[Specjalna:Diff/' + diffNumber + '|Edycja' + diffNumber + ']] - ' + reason + '\n\nZgłasza:'+'~~'+'~~',
                                 summary: 'Zgłoszono edycję do ukrycia: ' + diffNumber
                                 summary: 'Zgłoszono edycję do ukrycia: ' + diffNumber
                             }).done(function () {
                             }).done(function () {

Revision as of 19:22, 6 October 2024

mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
    function addReportButton() {
        // Znajdź każdą edycję w historii zmian strony
        $('.mw-changeslist-history .mw-changeslist-links a').each(function () {
            var diffUrl = $(this).attr('href');
            var diffNumberMatch = diffUrl.match(/diff=(\d+)/);
            
            if (diffNumberMatch) {
                var diffNumber = diffNumberMatch[1];

                // Dodaj przycisk, jeśli go jeszcze nie ma
                if ($(this).siblings('.pt-report').length === 0) {
                    var $button = $('<a>')
                        .attr('href', '#')
                        .text('(zgłoś)')
                        .addClass('pt-report')
                        .css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' });

                    $(this).after($button);

                    // Obsługa kliknięcia w przycisk
                    $button.click(function (e) {
                        e.preventDefault();

                        // Popup do wpisania uzasadnienia
                        var reason = prompt('Podaj uzasadnienie zgłoszenia:');
                        if (!reason || reason.trim() === '') {
                            alert('Uzasadnienie jest wymagane.');
                            return;
                        }

                        // Potwierdzenie zgłoszenia
                        var doThis = confirm('Czy na pewno chcesz zgłosić edycję?');
                        if (doThis) {
                            var api = new mw.Api();

                            // Stwórz nowy wątek na Wikipedia:Prośby do administratorów
                            api.postWithToken('csrf', {
                                action: 'edit',
                                title: 'User:BZPN/Wikipedia:Prośby do administratorów',
                                section: 'new',
                                sectiontitle: 'Prośba o ukrycie',
                                text: '[[Specjalna:Diff/' + diffNumber + '|Edycja' + diffNumber + ']] - ' + reason + '\n\nZgłasza:'+'~~'+'~~',
                                summary: 'Zgłoszono edycję do ukrycia: ' + diffNumber
                            }).done(function () {
                                alert('Edycja została zgłoszona.');
                            }).fail(function (error) {
                                console.error('Błąd podczas zgłaszania:', error);
                                alert('Wystąpił błąd podczas zgłaszania edycji.');
                            });
                        }
                    });
                }
            }
        });
    }

    $(document).ready(function () {
        addReportButton();
    });
});