User:BZPN/RfD.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
// <nowiki> |
// <nowiki> |
||
(function($) { |
|||
// Główny obiekt skryptu |
|||
var QuickCloseRfD = {}; |
|||
QC.summary = ' - with QuickClose'; |
|||
// Konfiguracja przestrzeni nazw |
|||
// Dodaj przycisk "Quick Close" obok tytułu strony |
|||
const ALLOWED_NAMESPACES = ['Wikipedia:Requests for deletion']; |
|||
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(); |
|||
}); |
|||
} |
|||
QuickCloseRfD.setup = function() { |
|||
function openQuickCloseDialog() { |
|||
// |
// Sprawdzenie, czy jesteśmy na odpowiedniej stronie |
||
var wgPageName = mw.config.get('wgPageName'); |
|||
var wgNamespaceNumber = mw.config.get('wgNamespaceNumber'); |
|||
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'] } |
|||
]; |
|||
if (ALLOWED_NAMESPACES.includes(wgPageName) || |
|||
QuickCloseDialog.prototype.initialize = function () { |
|||
ALLOWED_NAMESPACES.some(ns => wgPageName.startsWith(ns + '/'))) { |
|||
QuickCloseDialog.super.prototype.initialize.call(this); |
|||
$('span.mw-editsection-bracket:first-child').each(function() { |
|||
// Pole tekstowe dla komentarza z wynikiem |
|||
try { |
|||
// Pobieranie numeru sekcji |
|||
var sectionNumber = this.parentElement.childNodes[1].href |
|||
.match(/action=edit§ion=(\d+)/)[1]; |
|||
// Dodawanie przycisku Quick Close |
|||
$(this).after(' | '); |
|||
$(this).after( |
|||
$('<a href="javascript:void(0)" class="QuickCloseRfD-close" ' + |
|||
'data-section="' + sectionNumber + '">Quick Close</a>') |
|||
); |
|||
} catch(e) {} |
|||
}); |
}); |
||
// |
// Obsługa kliknięcia przycisku |
||
QuickCloseRfD.bindEvents(); |
|||
this.outcomeSelect = new OO.ui.RadioSelectInputWidget({ |
|||
} |
|||
}; |
|||
{ data: 'delete', label: '{{delete}}' }, |
|||
{ data: 'keep', label: '{{keep}}' } |
|||
QuickCloseRfD.bindEvents = function() { |
|||
] |
|||
$('.QuickCloseRfD-close').click(function(e) { |
|||
}); |
|||
this. |
var sectionNumber = $(this).data('section'); |
||
QuickCloseRfD.showQuickCloseDialog(sectionNumber); |
|||
}); |
|||
}; |
|||
QuickCloseRfD.showQuickCloseDialog = function(sectionNumber) { |
|||
// Prosty popup do zamykania dyskusji |
|||
var $dialog = $('<div class="quick-close-dialog">' + |
|||
'<h3>Close Deletion Request</h3>' + |
|||
'<div>' + |
|||
'<label>Outcome:</label>' + |
|||
'<select id="quick-close-outcome">' + |
|||
'<option value="{{delete}}">Delete</option>' + |
|||
'<option value="{{keep}}">Keep</option>' + |
|||
'<option value="{{merge}}">Merge</option>' + |
|||
'<option value="{{redirect}}">Redirect</option>' + |
|||
'</select>' + |
|||
'</div>' + |
|||
'<div>' + |
|||
'<label>Additional Comments (optional):</label>' + |
|||
'<textarea id="quick-close-comment" rows="3"></textarea>' + |
|||
'</div>' + |
|||
(mw.config.get('wgUserGroups').includes('sysop') ? |
|||
'<div>' + |
|||
'<label><input type="checkbox" id="quick-close-delete-page"> Delete this page</label>' + |
|||
'</div>' : '') + |
|||
'<div class="quick-close-buttons">' + |
|||
'<button id="quick-close-confirm">Close Discussion</button>' + |
|||
'<button id="quick-close-cancel">Cancel</button>' + |
|||
'</div>' + |
|||
'</div>'); |
|||
// Dodanie arkusza stylów dla dialogu |
|||
$('head').append(` |
|||
<style> |
|||
.quick-close-dialog { |
|||
background: white; |
|||
border: 1px solid #a2a9b1; |
|||
border-radius: 5px; |
|||
padding: 15px; |
|||
width: 400px; |
|||
margin: 0 auto; |
|||
position: fixed; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translate(-50%, -50%); |
|||
z-index: 1000; |
|||
box-shadow: 0 4px 6px rgba(0,0,0,0.1); |
|||
} |
|||
.quick-close-dialog h3 { |
|||
margin-top: 0; |
|||
border-bottom: 1px solid #eaecf0; |
|||
padding-bottom: 10px; |
|||
} |
|||
.quick-close-dialog div { |
|||
margin-bottom: 10px; |
|||
} |
|||
.quick-close-dialog label { |
|||
display: block; |
|||
margin-bottom: 5px; |
|||
} |
|||
.quick-close-dialog select, |
|||
.quick-close-dialog textarea { |
|||
width: 100%; |
|||
box-sizing: border-box; |
|||
} |
|||
.quick-close-buttons { |
|||
display: flex; |
|||
justify-content: space-between; |
|||
} |
|||
.quick-close-buttons button { |
|||
padding: 5px 10px; |
|||
} |
|||
</style> |
|||
`); |
|||
$('body').append($dialog); |
|||
// Zamykanie dialogu |
|||
$('#quick-close-cancel').click(function() { |
|||
$dialog.remove(); |
|||
}); |
|||
// Potwierdzenie zamknięcia |
|||
$('#quick-close-confirm').click(function() { |
|||
var outcome = $('#quick-close-outcome').val(); |
|||
var comment = $('#quick-close-comment').val() || 'The outcome of this discussion is: '; |
|||
var deleteRequest = $('#quick-close-delete-page:checked').length > 0; |
|||
QuickCloseRfD.closeDiscussion( |
|||
// Jeśli użytkownik ma uprawnienia sysopa – dodatkowy checkbox |
|||
sectionNumber, |
|||
outcome, |
|||
if (mw.config.get('wgUserGroups').indexOf('sysop') !== -1) { |
|||
comment, |
|||
deleteRequest |
|||
this.sysopCheckboxField = new OO.ui.FieldLayout(this.sysopCheckbox, { |
|||
); |
|||
}); |
|||
} |
|||
$dialog.remove(); |
|||
}); |
|||
}; |
|||
$form.append($('<div>').css('margin-bottom', '10px').append( |
|||
$('<label>').text('Wynik zamknięcia:'), |
|||
QuickCloseRfD.closeDiscussion = function(sectionNumber, outcome, comment, deleteRequest) { |
|||
this.commentInput.$element |
|||
var pageTitle = mw.config.get('wgPageName'); |
|||
var pageName = pageTitle.split('/').pop(); |
|||
$('<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); |
|||
}; |
|||
new mw.Api().get({ |
|||
QuickCloseDialog.prototype.getActionProcess = function (action) { |
|||
action: 'parse', |
|||
page: pageTitle, |
|||
prop: 'wikitext', |
|||
section: sectionNumber |
|||
var comment = this.commentInput.getValue().trim(); |
|||
}).done(function(result) { |
|||
var outcome = this.outcomeSelect.getSelectedItem().getData(); // 'delete' lub 'keep' |
|||
var wikitext = result.parse.wikitext['*']; |
|||
// Dodanie zamknięcia dyskusji |
|||
var closingText = |
|||
'<div class="boilerplate" style="background-color: #EDEAFF; padding: 0px 10px 0px 10px; border: 1px solid #8779DD;">\n' + |
|||
':\'\'The following discussion is closed. <span style="color:red">\'\'\'Please do not modify it.\'\'\'\</span> Subsequent comments should be made on the appropriate discussion page. No further changes should be made to this discussion.\'\'\n' + |
|||
// Pobierz bieżący wikitext strony i usuń szablon z sekcji "Current deletion request discussions" |
|||
'----\n' + |
|||
outcome + ' - ~~~~\n\n' + |
|||
comment + ' ~~~~\n' + |
|||
'</div>'; |
|||
wikitext += '\n' + closingText; |
|||
// Edycja strony |
|||
// {{Wikipedia:Requests for deletion/Requests/2025/Sticker Mule}} |
|||
new mw.Api().postWithEditToken({ |
|||
// Usuwamy go przy pomocy wyrażenia regularnego |
|||
action: 'edit', |
|||
var regex = /\{\{\s*Wikipedia:Requests for deletion\/Requests\/[^\}]+\}\}\s*\n?/g; |
|||
title: pageTitle, |
|||
section: sectionNumber, |
|||
text: wikitext, |
|||
summary: 'Closing deletion discussion for ' + pageName |
|||
}).done(function() { |
|||
// Opcjonalne usunięcie strony dla administratorów |
|||
if (deleteRequest) { |
|||
new mw.Api().postWithEditToken({ |
new mw.Api().postWithEditToken({ |
||
action: ' |
action: 'delete', |
||
title: |
title: 'Wikipedia:Requests for deletion/Requests/2025/' + pageName, |
||
reason: 'Deletion discussion completed' |
|||
}).done(function() { |
|||
location.reload(); |
|||
}).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(); |
|||
} |
|||
}); |
}); |
||
} |
} else { |
||
location.reload(); |
|||
} |
} |
||
}); |
|||
return QuickCloseDialog.super.prototype.getActionProcess.call(this, action); |
|||
}; |
}); |
||
}; |
|||
var quickDialog = new QuickCloseDialog({ size: 'large' }); |
|||
// Ładowanie skryptu |
|||
var windowManager = new OO.ui.WindowManager(); |
|||
mw.loader.using('mediawiki.api', function() { |
|||
$(document.body).append(windowManager.$element); |
|||
$(document).ready(function() { |
|||
QuickCloseRfD.setup(); |
|||
} |
}); |
||
}); |
}); |
||
})(jQuery); |
|||
// </nowiki> |
// </nowiki> |
||