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

From Test Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
     function addReportButton() {
     function addReportButton() {
         // Iterate through all diff links
         // Znajdź każdą edycję
         $('.mw-changeslist-links .mw-diff').each(function () {
         $('.mw-changeslist-diff').each(function () {
             var $diffLink = $(this);
             var diffUrl = $(this).attr('href');
            var diffHref = $diffLink.attr('href');
             var diffNumber = diffUrl.match(/diff=(\d+)/)[1];
             var diffNumber = diffHref.match(/oldid=(\d+)/)[1]; // Extracting the diff number


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


                // Add the button after the diff link
                 $(this).after($button);
                 $diffLink.after($button);


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


                     // Display popup for reason input
                     // Popup do wpisania uzasadnienia
                     var reason = prompt('Enter the reason for reporting:');
                     var reason = prompt('Podaj uzasadnienie zgłoszenia:');
                     if (!reason || reason.trim() === '') {
                     if (!reason || reason.trim() === '') {
                         alert('A reason is required.');
                         alert('Uzasadnienie jest wymagane.');
                         return;
                         return;
                     }
                     }


                     // Confirm the report
                     // Potwierdzenie zgłoszenia
                     var confirmReport = confirm('Are you sure you want to report this edit?');
                     var doThis = confirm('Czy na pewno chcesz zgłosić edycję?');
                     if (!confirmReport) {
                     if (doThis) {
                         return;
                         var api = new mw.Api();
 
                        // Stwórz nowy wątek na Wikipedia:Prośby do administratorów
                        api.postWithToken('csrf', {
                            action: 'edit',
                            title: 'Wikipedia:Prośby do administratorów',
                            section: 'new',
                            sectiontitle: 'Prośba o ukrycie',
                            text: '[[Specjalna:Diff/' + diffNumber + '|Edycja ' + diffNumber + ']] - ' + reason + '\n\nZgłasza: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:08, 4 October 2024 (UTC)',
                            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.');
                        });
                     }
                     }
                    // API call to post to the report page
                    var api = new mw.Api();
                    api.postWithToken('csrf', {
                        action: 'edit',
                        title: 'User talk:BZPN',
                        section: 'new',
                        sectiontitle: 'Request to hide',
                        text: '[[Special:Diff/' + diffNumber + '|Diff ' + diffNumber + ']] - ' + reason + '\nReported by: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:01, 4 October 2024 (UTC)',
                        summary: 'Request to hide edit no. ' + diffNumber
                    }).done(function () {
                        alert('The report has been submitted.');
                    }).fail(function (error) {
                        console.error('Error while submitting the report:', error);
                        alert('An error occurred while submitting the report.');
                    });
                 });
                 });
             }
             }
Line 57: Line 52:
     }
     }


    // Run the function after the page has loaded
     $(document).ready(function () {
     $(document).ready(function () {
         addReportButton();
         addReportButton();
     });
     });
});
});

Latest revision as of 20:08, 4 October 2024

mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
    function addReportButton() {
        // Znajdź każdą edycję
        $('.mw-changeslist-diff').each(function () {
            var diffUrl = $(this).attr('href');
            var diffNumber = diffUrl.match(/diff=(\d+)/)[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: 'Wikipedia:Prośby do administratorów',
                            section: 'new',
                            sectiontitle: 'Prośba o ukrycie',
                            text: '[[Specjalna:Diff/' + diffNumber + '|Edycja ' + diffNumber + ']] - ' + reason + '\n\nZgłasza: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:08, 4 October 2024 (UTC)',
                            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();
    });
});