User:DodoMan/blockanddiscuss.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Created page with "if (mw.config.get('wgCanonicalNamespace') == 'Special' && mw.config.get('wgCanonicalSpecialPageName') == 'Block') { $(function() { var api = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php'; var checkId = 'mw-input-wpBlockMessage'; var textId = 'mw-input-wpBlockMessageText'; var blockTemplate = '\\{\\{(Averto-3\\|[^\\|]*\\|[^\\}]*|Vandale banni)\\}\\}'; var reason = '(\\s*Avec le motif suivant\\s*: «[^»]*»\\.)?..." |
m FuzzyBot moved page User:DodoMan~usurped/blockanddiscuss.js to User:DodoMan/blockanddiscuss.js: Part of translatable page "User:DodoMan~usurped" |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
var checkId = 'mw-input-wpBlockMessage'; |
var checkId = 'mw-input-wpBlockMessage'; |
||
var textId = 'mw-input-wpBlockMessageText'; |
var textId = 'mw-input-wpBlockMessageText'; |
||
var blockTemplate = '\\{\\{( |
var blockTemplate = '\\{\\{(Blocked user\\|[^\\|]*\\|[^\\}]*)\\}\\}'; |
||
var reason = '(\\s*Avec le motif suivant\\s*: «[^»]*»\\.)?~~' + '~~'; |
var reason = '(\\s*Avec le motif suivant\\s*: «[^»]*»\\.)?~~' + '~~'; |
||
var $watchBlock = $('#mw-input-wpWatch').closest('.oo-ui-fieldLayout'); |
var $watchBlock = $('#mw-input-wpWatch').closest('.oo-ui-fieldLayout'); |
||
Line 27: | Line 27: | ||
.end() |
.end() |
||
.find('.oo-ui-fieldLayout-field') |
.find('.oo-ui-fieldLayout-field') |
||
.replaceWith($('<textarea id="' + textId + '" rows="10">{{ |
.replaceWith($('<textarea id="' + textId + '" rows="10">{{Blocked user}}~~' + '~~</textarea>')) |
||
.end() |
.end() |
||
.appendTo($watchBlock.parent()) |
.appendTo($watchBlock.parent()) |
||
Line 62: | Line 62: | ||
var template = '{{Vandale banni}}'; |
var template = '{{Vandale banni}}'; |
||
if (duration != 'indéfiniment') { |
if (duration != 'indéfiniment') { |
||
template = '{{ |
template = '{{Blocked user|' + duration.replace(' ', '|') + '}}'; |
||
} |
} |
||
$('#' + textId).val( |
$('#' + textId).val( |
Latest revision as of 12:56, 2 April 2024
if (mw.config.get('wgCanonicalNamespace') == 'Special' &&
mw.config.get('wgCanonicalSpecialPageName') == 'Block') {
$(function() {
var api = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php';
var checkId = 'mw-input-wpBlockMessage';
var textId = 'mw-input-wpBlockMessageText';
var blockTemplate = '\\{\\{(Blocked user\\|[^\\|]*\\|[^\\}]*)\\}\\}';
var reason = '(\\s*Avec le motif suivant\\s*: «[^»]*»\\.)?~~' + '~~';
var $watchBlock = $('#mw-input-wpWatch').closest('.oo-ui-fieldLayout');
$watchBlock.clone()
.find('label')
.attr('for', checkId)
.text('Laisser un message sur la page de discussion de cet utilisateur')
.end().find('input')
.attr('id', checkId)
.attr('value', 0)
.click(function() {
$('#' + textId + '-tr').toggle();
})
.end()
.appendTo($watchBlock.parent())
.clone()
.attr('id', textId + '-tr')
.find('label')
.remove()
.end()
.find('.oo-ui-fieldLayout-field')
.replaceWith($('<textarea id="' + textId + '" rows="10">{{Blocked user}}~~' + '~~</textarea>'))
.end()
.appendTo($watchBlock.parent())
.hide();
$watchBlock.closest('form').submit(function (event) {
var form = this;
if ($('#' + checkId).prop('checked')) {
event.preventDefault();
var talkPage = 'User_talk:' + $('#mw-bi-target input').val();
$.getJSON(api + '?action=query&meta=tokens&type=csrf&prop=revisions&format=json&curtimestamp=true&titles=' + talkPage, function (response) {
$.each(response.query.pages, function (_, page) {
$.post(api, {
action: 'edit',
title: talkPage,
section: 'new',
sectiontitle: 'Blocage',
text: $('#' + textId).val(),
basetimestamp: page.revisions[0].timestamp,
starttimestamp: response.curtimestamp,
token: response.query.tokens.csrftoken,
format: 'json'
}, function (response) {
// TODO do something if there was a problem
form.submit();
});
});
});
}
});
$('#mw-input-wpExpiry').change(function () {
var duration = $(this).find('option:selected').text();
var template = '{{Vandale banni}}';
if (duration != 'indéfiniment') {
template = '{{Blocked user|' + duration.replace(' ', '|') + '}}';
}
$('#' + textId).val(
$('#' + textId).val().replace(new RegExp(blockTemplate), template)
);
});
function changeReason() {
var defaultText = $('#mw-input-wpReason option:selected').text();
if (defaultText == 'Autre') {
defaultText = '';
}
var customText = $('#mw-input-wpReason-other').val();
if (defaultText && customText) {
defaultText += ' ';
}
$('#' + textId).val(
// TODO if the user removed the reason from the message, don't add it again
$('#' + textId).val().replace(new RegExp(reason), '\n\nAvec le motif suivant : « ' + defaultText + customText + ' ».~~' + '~~')
);
}
$('#mw-input-wpReason').change(changeReason);
$('#mw-input-wpReason-other').change(changeReason);
$('#mw-input-wpReason-other').keyup(changeReason);
});
}