User:BZPN/RfD.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
Tags: Undo Mobile edit Mobile web edit |
||
| Line 4: | Line 4: | ||
// Dodaj przycisk "Nominate for deletion" do paska narzędzi |
// Dodaj przycisk "Nominate for deletion" do paska narzędzi |
||
var nominateLink = mw.util.addPortletLink( |
var nominateLink = mw.util.addPortletLink( |
||
'p-tb', |
'p-tb', // Pasek narzędzi |
||
'#', |
'#', // link docelowy |
||
'Nominate for deletion', |
'Nominate for deletion', // Tekst przycisku |
||
'ca-nominate-deletion', |
'ca-nominate-deletion', // ID linku |
||
'Nominate this page for deletion' |
'Nominate this page for deletion' // Podpowiedź tekstowa |
||
); |
); |
||
| Line 21: | Line 21: | ||
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia |
// Tworzenie i otwarcie okna popup dla nominacji do usunięcia |
||
function openDeletionPopup() { |
function openDeletionPopup() { |
||
// Tworzenie nakładki |
|||
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({ |
||
'position': 'fixed', |
'position': 'fixed', |
||
| Line 31: | Line 32: | ||
}).appendTo('body'); |
}).appendTo('body'); |
||
// Tworzenie okna popup |
|||
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
const popup = $('<div>').attr('id', 'deletion-popup').css({ |
||
'width': '90%', |
'width': '90%', |
||
| Line 43: | Line 45: | ||
}).appendTo(overlay); |
}).appendTo(overlay); |
||
// Przycisk zamknięcia popup |
|||
$('<span>').text('×').css({ |
$('<span>').text('×').css({ |
||
'position': 'absolute', |
'position': 'absolute', |
||
| Line 52: | Line 55: | ||
}).on('click', closeDeletionPopup).appendTo(popup); |
}).on('click', closeDeletionPopup).appendTo(popup); |
||
// Tytuł okna |
|||
$('<h3>').text('Nominate for deletion').css({ |
$('<h3>').text('Nominate for deletion').css({ |
||
'font-size': '18px', |
'font-size': '18px', |
||
| Line 57: | Line 61: | ||
}).appendTo(popup); |
}).appendTo(popup); |
||
// Informacja o zasadach RfD |
|||
$('<p>').text('Before nominating, please read the deletion policy and guidelines on the Wikipedia:Requests for deletion page.').css({ |
$('<p>').text('Before nominating, please read the deletion policy and guidelines on the Wikipedia:Requests for deletion page.').css({ |
||
'font-size': '14px', |
'font-size': '14px', |
||
| Line 69: | Line 74: | ||
}).appendTo(popup); |
}).appendTo(popup); |
||
// Pole na krótki powód - poprawka do krawędzi dolnej |
|||
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').css({ |
$('<label>').attr('for', 'deletion-short-reason').text('Short reason:').css({ |
||
'display': 'block', |
'display': 'block', |
||
| Line 83: | Line 89: | ||
'margin': '5px 0', |
'margin': '5px 0', |
||
'font-size': '14px', |
'font-size': '14px', |
||
'box-sizing': 'border-box' |
'box-sizing': 'border-box', |
||
'line-height': '1.5', // poprawka dla dolnej krawędzi |
|||
}).appendTo(popup); |
}).appendTo(popup); |
||
// Pole na szczegółowy powód |
|||
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').css({ |
$('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').css({ |
||
'display': 'block', |
'display': 'block', |
||
| Line 101: | Line 109: | ||
}).appendTo(popup); |
}).appendTo(popup); |
||
// Checkbox |
// Checkbox potwierdzenia zapoznania się z polityką |
||
const |
const policyCheckbox = $('<input>').attr({ |
||
'type': 'checkbox', |
'type': 'checkbox', |
||
'id': ' |
'id': 'policy-confirmation' |
||
}).css({ |
}).css({ |
||
'margin-right': '5px' |
'margin-right': '5px' |
||
}); |
}); |
||
$('<label>').attr('for', ' |
const policyLabel = $('<label>').attr('for', 'policy-confirmation').text('I have read and understand the deletion policy.'); |
||
$('<div>').append(policyCheckbox, policyLabel).css({ |
|||
'font-size': '14px' |
|||
'margin-bottom': '15px' |
|||
}).prepend(quickDeleteCheckbox).appendTo(popup); |
|||
$('<label>').attr('for', 'quick-delete-reason').text('Select reason:').css({ |
|||
'display': 'block', |
|||
'margin-top': '10px', |
|||
'font-size': '14px' |
|||
}).appendTo(popup); |
}).appendTo(popup); |
||
const quickDeleteReasonSelect = $('<select>').attr('id', 'quick-delete-reason').css({ |
|||
'width': '100%', |
|||
'padding': '6px', |
|||
'font-size': '14px', |
|||
'box-sizing': 'border-box' |
|||
}).appendTo(popup); |
|||
const reasons = { |
|||
'A1': 'Little/no meaning', |
|||
'A2': 'No content', |
|||
'A3': 'Transwikied', |
|||
'A4': 'Not notable', |
|||
'A5': 'Not in English', |
|||
'G1': 'Nonsense', |
|||
'G2': 'Test page', |
|||
'G3': 'Vandalism', |
|||
'G10': 'Attack page', |
|||
'G11': 'Advertising', |
|||
'G12': 'Copyright infringement' |
|||
}; |
|||
$.each(reasons, function(key, value) { |
|||
$('<option>').attr('value', key).text(key + ' - ' + value).appendTo(quickDeleteReasonSelect); |
|||
}); |
|||
// Przycisk wyślij |
|||
$('<button>').text('Submit nomination').css({ |
$('<button>').text('Submit nomination').css({ |
||
'width': '100%', |
'width': '100%', |
||
| Line 155: | Line 136: | ||
const shortReason = shortReasonInput.val().trim(); |
const shortReason = shortReasonInput.val().trim(); |
||
const detailedReason = detailedReasonInput.val().trim(); |
const detailedReason = detailedReasonInput.val().trim(); |
||
const |
const policyConfirmed = policyCheckbox.is(':checked'); |
||
if (shortReason && detailedReason && policyConfirmed) { |
|||
if (quickDelete) { |
|||
tagPageForQuickDeletion(quickDeleteReason); |
|||
} else { |
|||
initiateDeletionProcess(shortReason, detailedReason); |
initiateDeletionProcess(shortReason, detailedReason); |
||
} else if (!policyConfirmed) { |
|||
alert('Please confirm you have read the deletion policy.'); |
|||
} else { |
|||
alert('Please provide both a short and detailed reason.'); |
|||
} |
} |
||
}).appendTo(popup); |
}).appendTo(popup); |
||
} |
} |
||
// Funkcja zamykająca popup |
|||
function closeDeletionPopup() { |
function closeDeletionPopup() { |
||
$('#deletion-popup-overlay').remove(); |
$('#deletion-popup-overlay').remove(); |
||
} |
} |
||
// Funkcja inicjująca proces usunięcia |
|||
function tagPageForQuickDeletion(reason) { |
|||
const tag = `{{QD|${reason}}}`; |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: mw.config.get('wgPageName'), |
|||
prependtext: tag + '\n', |
|||
summary: `Quick Delete tag added: ${reason}`, |
|||
watchlist: 'watch', |
|||
}).done(function() { |
|||
alert('Quick Delete tag added.'); |
|||
}).fail(function() { |
|||
alert('Failed to add Quick Delete tag.'); |
|||
}); |
|||
} |
|||
function initiateDeletionProcess(shortReason, detailedReason) { |
function initiateDeletionProcess(shortReason, detailedReason) { |
||
tagPageForDeletion(shortReason); |
tagPageForDeletion(shortReason); |
||
| Line 193: | Line 161: | ||
} |
} |
||
// Funkcja do oznaczania strony do usunięcia |
|||
function tagPageForDeletion(reason) { |
function tagPageForDeletion(reason) { |
||
const tag = `{{rfd|${reason}}}`; |
const tag = `{{rfd|${reason}}}`; |
||
const editSummary = 'Nominating for deletion (RfD)'; |
const editSummary = 'Nominating for deletion ([[User:BZPN/RfD.js|RfD]])'; |
||
new mw.Api().postWithToken('csrf', { |
new mw.Api().postWithToken('csrf', { |
||
action: 'edit', |
action: 'edit', |
||
| Line 205: | Line 175: | ||
alert('Page tagged for deletion.'); |
alert('Page tagged for deletion.'); |
||
}).fail(function() { |
}).fail(function() { |
||
alert('Failed to tag the page for deletion.'); |
alert('Failed to tag the page for deletion. Please try again.'); |
||
}); |
}); |
||
} |
} |
||
// Funkcja do tworzenia strony dyskusji o usunięciu |
|||
function createDiscussionPage(detailedReason) { |
|||
function createDiscussionPage(reason) { |
|||
// Pseudokod funkcji tworzącej stronę dyskusji |
|||
const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}`; |
|||
console.log('Creating discussion page with reason:', detailedReason); |
|||
const discussionContent = `{{subst:RfD/Preload/Template|deletereason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`; |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: discussionPageTitle, |
|||
text: discussionContent, |
|||
summary: 'Starting deletion discussion ([[User:BZPN/RfD.js|RfD]])', |
|||
watchlist: 'watch', |
|||
}).done(function() { |
|||
alert('Deletion discussion page created.'); |
|||
}).fail(function() { |
|||
alert('Failed to create deletion discussion page. Please try again.'); |
|||
}); |
|||
} |
} |
||
// Funkcja dodająca dyskusję do listy |
|||
function addToDeletionList() { |
function addToDeletionList() { |
||
const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions'; |
|||
// Pseudokod funkcji dodającej stronę do listy usunięć |
|||
const discussionLink = `{{Wikipedia:Requests for deletion/Requests/2024/${mw.config.get('wgPageName')}}}`; |
|||
console.log('Adding to deletion list'); |
|||
new mw.Api().edit(deletionListTitle, function(revision) { |
|||
return { |
|||
text: discussionLink + '\n' + revision.content, |
|||
summary: 'Adding new deletion discussion ([[User:BZPN/RfD.js|RfD]])', |
|||
watchlist: 'watch', |
|||
}; |
|||
}).done(function() { |
|||
alert('Deletion discussion added to the list.'); |
|||
}).fail(function() { |
|||
alert('Failed to add the discussion to the deletion list. Please try again.'); |
|||
}); |
|||
} |
} |
||
// Funkcja powiadamiająca autora strony |
|||
function notifyPageCreator() { |
function notifyPageCreator() { |
||
const creator = mw.config.get('wgPageContentModel') === 'wikitext' ? mw.config.get('wgPageCreator') : null; |
|||
// Pseudokod funkcji powiadamiającej twórcę strony |
|||
if (creator) { |
|||
const notification = `{{subst:RFDNote|${mw.config.get('wgPageName')}}} ~~"+"~~`; |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: `User talk:${creator}`, appendtext: '\n' + notification, |
|||
summary: 'Notifying page creator about deletion nomination ([[User:BZPN/RfD.js|RfD]])', |
|||
watchlist: 'watch', |
|||
}).done(function() { |
|||
alert('Page creator notified.'); |
|||
}).fail(function() { |
|||
alert('Failed to notify these page creator. Please try again.'); |
|||
}); |
|||
} |
|||
} |
} |
||
})(); |
})(); |
||