User:BZPN/RfD.js: Difference between revisions

From Test Wiki
Content deleted Content added
BZPN (talk | contribs)
No edit summary
BZPN (talk | contribs)
No edit summary
Line 1: Line 1:
// <nowiki>
// <nowiki>
$(function () {
$(function () {
// Sprawdzamy, czy strona należy do przestrzeni nazw "Project:Requests for Deletion"
// Sprawdzamy, czy strona należy do przestrzeni "Project:Requests for Deletion"
var pageName = mw.config.get('wgPageName');
var pageName = mw.config.get('wgPageName');
if (!pageName.startsWith("Project:Requests for Deletion")) {
if (pageName.indexOf("Project:Requests for Deletion") !== 0) {
return;
return;
}
}
// Funkcja dodająca przycisk "Quick Close" w każdej podsekcji
// Dodajemy przycisk "Quick Close" do paska Toolbox (#p-tb)
var $toolboxList = $('#p-tb ul');
function addQuickCloseButtons() {
if (!$toolboxList.length) return;
$('span.mw-editsection-bracket').each(function () {
try {
var $this = $(this);
var sectionLink = $this.find('a').first();
if (!sectionLink.length) return;
// Wyciągnięcie numeru sekcji z URL
var href = sectionLink.attr('href');
var m = href.match(/action=edit&section=(\d+)/);
if (!m) return;
var sectionNumber = m[1];
// Dodajemy separator i przycisk "Quick Close"
$this.append(' | ');
var $btn = $('<a>', {
text: 'Quick Close',
href: 'javascript:void(0)',
'data-section': sectionNumber,
css: { cursor: 'pointer', color: '#0645AD', textDecoration: 'underline' }
});
$this.append($btn);
// Obsługa kliknięcia przycisku
$btn.click(function () {
openQuickCloseDialog(sectionNumber);
});
} catch (e) {
console.error(e);
}
});
}
var $li = $('<li>', { id: 't-quickclose' });
// Funkcja tworząca prosty popup dialogowy
var $link = $('<a>', { href: 'javascript:void(0)', text: 'Quick Close' });
function openQuickCloseDialog(sectionNumber) {
$link.click(function () {
openQuickCloseDialog();
});
$li.append($link);
$toolboxList.append($li);
// Funkcja otwierająca popup dialogowy
function openQuickCloseDialog() {
// Usuwamy ewentualny poprzedni dialog
// Usuwamy ewentualny poprzedni dialog
$('#quickclose-dialog').remove();
$('#quickclose-dialog').remove();
// Tworzymy element dialogu
var $dialog = $( '<div id="quickclose-dialog" style="position: fixed; top: 30%; left: 50%; transform: translate(-50%, -30%); background: #fff; border: 1px solid #aaa; padding: 20px; z-index: 10000; width: 400px; box-shadow: 0 0 10px rgba(0,0,0,0.5);"></div>' );
var $dialog = $('<div id="quickclose-dialog" style="position: fixed; top: 30%; left: 50%; transform: translate(-50%, -30%); background: #fff; border: 1px solid #aaa; padding: 20px; z-index: 10000; width: 400px; box-shadow: 0 0 10px rgba(0,0,0,0.5);"></div>');
// Pole komentarza
// Pole tekstowe na komentarz
var $commentLabel = $('<div style="margin-bottom:5px;">Wynik (komentarz):</div>');
var $commentLabel = $('<div style="margin-bottom:5px;">Wynik (komentarz):</div>');
var $commentInput = $('<textarea rows="4" style="width: 100%;">the outcome...</textarea>');
var $commentInput = $('<textarea rows="4" style="width: 100%;">the outcome...</textarea>');
// Wybór szablonu (radio)
// Wybór szablonu: {{delete}} lub {{keep}}
var $templateLabel = $('<div style="margin:10px 0 5px;">Wybierz szablon:</div>');
var $templateLabel = $('<div style="margin:10px 0 5px;">Wybierz szablon:</div>');
var $radioDelete = $('<label style="margin-right:10px;"><input type="radio" name="qc-template" value="delete" checked> {{delete}}</label>');
var $radioDelete = $('<label style="margin-right:10px;"><input type="radio" name="qc-template" value="delete" checked> {{delete}}</label>');
var $radioKeep = $('<label><input type="radio" name="qc-template" value="keep"> {{keep}}</label>');
var $radioKeep = $('<label><input type="radio" name="qc-template" value="keep"> {{keep}}</label>');
// Checkbox dla sysopa
// Checkbox dla sysopów – usunięcie strony docelowej
var isSysop = (mw.config.get('wgUserGroups').indexOf('sysop') !== -1);
var isSysop = (mw.config.get('wgUserGroups').indexOf('sysop') !== -1);
var $deleteCheckbox = '';
var $deleteCheckbox = '';
Line 57: Line 41:
$deleteCheckbox = $('<div style="margin-top:10px;"><label><input type="checkbox" id="qc-delete-page"> Delete this page</label></div>');
$deleteCheckbox = $('<div style="margin-top:10px;"><label><input type="checkbox" id="qc-delete-page"> Delete this page</label></div>');
}
}
// Przyciski akcji
// Przyciski akcji
var $btnContainer = $('<div style="margin-top:15px; text-align: right;"></div>');
var $btnContainer = $('<div style="margin-top:15px; text-align: right;"></div>');
var $btnCancel = $('<button style="margin-right:10px;">Anuluj</button>');
var $btnCancel = $('<button style="margin-right:10px;">Anuluj</button>');
var $btnSubmit = $('<button>Zatwierdź</button>');
var $btnSubmit = $('<button>Zatwierdź</button>');
$btnContainer.append($btnCancel, $btnSubmit);
$btnContainer.append($btnCancel, $btnSubmit);
// Składamy zawartość dialogu
$dialog.append($commentLabel, $commentInput, $templateLabel, $radioDelete, $radioKeep, $deleteCheckbox, $btnContainer);
$dialog.append($commentLabel, $commentInput, $templateLabel, $radioDelete, $radioKeep, $deleteCheckbox, $btnContainer);
$('body').append($dialog);
$('body').append($dialog);
// Obsługa przycisku "Anuluj"
// Obsługa przycisków
$btnCancel.click(function () {
$btnCancel.click(function () {
$dialog.remove();
$dialog.remove();
});
});
// Obsługa przycisku "Zatwierdź"
$btnSubmit.click(function () {
$btnSubmit.click(function () {
var comment = $commentInput.val().trim();
var comment = $commentInput.val().trim();
var outcome = $('input[name="qc-template"]:checked').val(); // "delete" lub "keep"
var outcome = $('input[name="qc-template"]:checked').val(); // "delete" lub "keep"
var templateText = (outcome === 'delete') ? '{{delete}}' : '{{keep}}';
var templateText = (outcome === 'delete') ? '{{delete}}' : '{{keep}}';
// Łączymy szablon z komentarzem
var fullComment = templateText + ' ' + comment;
var fullComment = templateText + ' ' + comment;
// Pobieramy tytuł strony RfD, a także wyciągamy tytuł docelowy (po ostatnim ukośniku)
// Tytuł strony RfD i wyznaczenie strony docelowej (tekst po ostatnim ukośniku)
var pageTitle = mw.config.get('wgPageName');
var pageTitle = mw.config.get('wgPageName');
var targetPage = pageTitle.split('/').pop().trim();
var targetPage = pageTitle.split('/').pop().trim();
// Pobieramy bieżący wikitext strony
// Pobieramy aktualny wikitext strony
new mw.Api().get({
new mw.Api().get({
action: 'parse',
action: 'parse',
Line 89: Line 74:
}).done(function (result) {
}).done(function (result) {
var wikitext = result.parse.wikitext['*'];
var wikitext = result.parse.wikitext['*'];
// Usuwamy szablon dyskusji z sekcji "Current deletion request discussions"
// Usuwamy szablon dyskusji, np. {{Wikipedia:Requests for deletion/Requests/2025/Sticker Mule}}
// Przykład: {{Wikipedia:Requests for deletion/Requests/2025/Sticker Mule}}
var regex = /\{\{\s*Wikipedia:Requests for deletion\/Requests\/[^\}]+\}\}\s*\n?/g;
var regex = /\{\{\s*Wikipedia:Requests for deletion\/Requests\/[^\}]+\}\}\s*\n?/g;
var newText = wikitext.replace(regex, '');
var newText = wikitext.replace(regex, '');
// Dodajemy komentarz na końcu sekcji
// Dodajemy komentarz na końcu
newText += '\n:' + fullComment;
newText += '\n:' + fullComment;
Line 104: Line 88:
minor: true
minor: true
}).done(function () {
}).done(function () {
// Jeśli użytkownik sysop i checkbox zaznaczony – usuwamy stronę docelową
// Jeśli sysop i checkbox zaznaczony – usuwamy stronę docelową
if (isSysop && $('#qc-delete-page').is(':checked')) {
if (isSysop && $('#qc-delete-page').is(':checked')) {
new mw.Api().postWithEditToken({
new mw.Api().postWithEditToken({
Line 121: Line 105:
});
});
}
}
// Inicjujemy przyciski po załadowaniu strony
addQuickCloseButtons();
});
});
// </nowiki>
// </nowiki>