User:BZPN/RfD.js: Difference between revisions
From Test Wiki
Content deleted Content added
Replaced content with "Nothing here" Tags: Replaced Mobile edit Mobile web edit |
No edit summary |
||
| Line 1: | Line 1: | ||
// <nowiki> |
|||
Nothing here |
|||
$(function () { |
|||
var QC = {}; |
|||
QC.summary = ' - with QuickClose'; |
|||
// Dodaj przycisk "Quick Close" obok tytułu strony |
|||
var $title = $('#firstHeading'); |
|||
if ($title.length) { |
|||
var $btn = $('<a>', { |
|||
text: '[Quick Close]', |
|||
href: 'javascript:void(0)', |
|||
id: 'quickclose-btn', |
|||
css: { marginLeft: '10px', cursor: 'pointer', color: '#0645AD', textDecoration: 'underline' } |
|||
}); |
|||
$title.append($btn); |
|||
$btn.click(function () { |
|||
openQuickCloseDialog(); |
|||
}); |
|||
} |
|||
function openQuickCloseDialog() { |
|||
// Definicja okna dialogowego z użyciem OO.ui |
|||
function QuickCloseDialog(config) { |
|||
QuickCloseDialog.super.call(this, config); |
|||
} |
|||
OO.inheritClass(QuickCloseDialog, OO.ui.ProcessDialog); |
|||
QuickCloseDialog.static.name = 'quickCloseDialog'; |
|||
QuickCloseDialog.static.title = 'Quick Close RfD'; |
|||
QuickCloseDialog.static.actions = [ |
|||
{ action: 'cancel', label: 'Anuluj', flags: 'safe' }, |
|||
{ action: 'submit', label: 'Zatwierdź', flags: ['primary', 'progressive'] } |
|||
]; |
|||
QuickCloseDialog.prototype.initialize = function () { |
|||
QuickCloseDialog.super.prototype.initialize.call(this); |
|||
// Pole tekstowe dla komentarza z wynikiem |
|||
this.commentInput = new OO.ui.MultilineTextInputWidget({ |
|||
rows: 5, |
|||
value: 'the outcome...' |
|||
}); |
|||
// Wybór szablonu – {{delete}} lub {{keep}} |
|||
this.outcomeSelect = new OO.ui.RadioSelectInputWidget({ |
|||
options: [ |
|||
{ data: 'delete', label: '{{delete}}' }, |
|||
{ data: 'keep', label: '{{keep}}' } |
|||
] |
|||
}); |
|||
this.outcomeSelect.selectItemByData('delete'); |
|||
// Jeśli użytkownik ma uprawnienia sysopa – dodatkowy checkbox |
|||
this.sysopCheckbox = null; |
|||
if (mw.config.get('wgUserGroups').indexOf('sysop') !== -1) { |
|||
this.sysopCheckbox = new OO.ui.CheckboxInputWidget(); |
|||
this.sysopCheckboxField = new OO.ui.FieldLayout(this.sysopCheckbox, { |
|||
label: 'Delete this page' |
|||
}); |
|||
} |
|||
// Komponowanie formularza |
|||
var $form = $('<div>'); |
|||
$form.append($('<div>').css('margin-bottom', '10px').append( |
|||
$('<label>').text('Wynik zamknięcia:'), |
|||
this.commentInput.$element |
|||
)); |
|||
$form.append($('<div>').css('margin-bottom', '10px').append( |
|||
$('<label>').text('Wybierz szablon: '), |
|||
this.outcomeSelect.$element |
|||
)); |
|||
if (this.sysopCheckboxField) { |
|||
$form.append($('<div>').css('margin-bottom', '10px').append( |
|||
this.sysopCheckboxField.$element |
|||
)); |
|||
} |
|||
this.content = new OO.ui.PanelLayout({ |
|||
padded: true, |
|||
expanded: false |
|||
}); |
|||
this.content.$element.append($form); |
|||
this.$body.append(this.content.$element); |
|||
}; |
|||
QuickCloseDialog.prototype.getActionProcess = function (action) { |
|||
var dialog = this; |
|||
if (action === 'submit') { |
|||
// Pobranie danych z formularza |
|||
var comment = this.commentInput.getValue().trim(); |
|||
var outcome = this.outcomeSelect.getSelectedItem().getData(); // 'delete' lub 'keep' |
|||
var templateText = (outcome === 'delete') ? '{{delete}}' : '{{keep}}'; |
|||
comment = templateText + ' ' + comment; |
|||
var pageTitle = mw.config.get('wgPageName'); |
|||
// Pobierz bieżący wikitext strony i usuń szablon z sekcji "Current deletion request discussions" |
|||
new mw.Api().get({ |
|||
action: 'parse', |
|||
page: pageTitle, |
|||
prop: 'wikitext' |
|||
}).done(function (result) { |
|||
var wikitext = result.parse.wikitext['*']; |
|||
// Zakładamy, że szablon ma postać: |
|||
// {{Wikipedia:Requests for deletion/Requests/2025/Sticker Mule}} |
|||
// Usuwamy go przy pomocy wyrażenia regularnego |
|||
var regex = /\{\{\s*Wikipedia:Requests for deletion\/Requests\/[^\}]+\}\}\s*\n?/g; |
|||
var newText = wikitext.replace(regex, ''); |
|||
new mw.Api().postWithEditToken({ |
|||
action: 'edit', |
|||
title: pageTitle, |
|||
text: newText, |
|||
summary: 'Quick close: ' + outcome + '. ' + comment + QC.summary, |
|||
minor: true |
|||
}).done(function () { |
|||
// Jeśli użytkownik sysop i checkbox "Delete this page" został zaznaczony – usuń stronę |
|||
if (dialog.sysopCheckbox && dialog.sysopCheckbox.isSelected()) { |
|||
new mw.Api().postWithEditToken({ |
|||
action: 'delete', |
|||
title: pageTitle, |
|||
reason: 'Quick close deletion: ' + outcome + '. ' + comment |
|||
}).done(function () { |
|||
location.reload(); |
|||
}); |
|||
} else { |
|||
location.reload(); |
|||
} |
|||
}); |
|||
}); |
|||
dialog.close(); |
|||
} |
|||
return QuickCloseDialog.super.prototype.getActionProcess.call(this, action); |
|||
}; |
|||
var quickDialog = new QuickCloseDialog({ size: 'large' }); |
|||
var windowManager = new OO.ui.WindowManager(); |
|||
$(document.body).append(windowManager.$element); |
|||
windowManager.addWindows([quickDialog]); |
|||
windowManager.openWindow(quickDialog); |
|||
} |
|||
}); |
|||
// </nowiki> |
|||