MediaWiki:Gadget-BlockMessage.js
Apparence
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./*
** BlockMessage
** (C) 2012 Arkanosis, under the MIT license
** Offre la possibilité de laisser un message sur la page de discussion d'un utilisateur lors d'un blocage
*/
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 = '\\{\\{(Bloqué\\|[^\\|]*\\|[^\\}]*|Vandale banni)\\}\\}';
var reason = '(\\s*Avec le motif suivant\\s*: «[^»]*»\\.)?~~' + '~~';
var hardBlock = $('#mw-input-wpHardBlock').parents('tr');
hardBlock.clone()
.find('label')
.attr('for', checkId)
.end().find('input')
.attr('id', checkId)
.attr('value', 0)
.next()
.text('Laisser un message sur la page de discussion de cet utilisateur')
.end()
.click(function() {
$('#' + textId + '-tr').toggle();
})
.end()
.appendTo(hardBlock.parent())
.clone()
.attr('id', textId + '-tr')
.find('label')
.attr('for', textId)
.end().find('input')
.next()
.remove()
.end()
.replaceWith($('<textarea id="' + textId + '" rows="10">{{Bloqué||}} — [[Utilisateur:Arkanosis|Arkanosis]] <sup>[[Discussion Utilisateur:Arkanosis|✉]]</sup> 25 mars 2012 à 21:06 (CEST)</textarea>'))
.end()
.appendTo(hardBlock.parent())
.hide();
hardBlock.parents('form').submit(function () {
if (typeof($('#' + checkId).attr('checked')) != 'undefined') {
var talkPage = 'User_talk:' + $('#mw-bi-target').val();
$.getJSON(api + '?action=query&prop=info|revisions&intoken=edit&format=json&titles=' + talkPage, function (response) {
$.each(response.query.pages, function (_, page) {
$.post(api, {
action: 'edit',
title: talkPage,
section: 'new',
sectiontitle: 'Avis de blocage',
text: $('#' + textId).val(),
basetimestamp: page.starttimestamp,
token: page.edittoken,
format: 'json'
}, function (response) {
// TODO do something if there was a problem
});
});
});
}
});
$('#mw-input-wpExpiry').change(function () {
var duration = $(this).find('option:selected').text();
var template = '{{Vandale banni}}';
if (duration != 'indéfiniment') {
template = '{{Bloqué|' + 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 + ' ». — [[Utilisateur:Arkanosis|Arkanosis]] <sup>[[Discussion Utilisateur:Arkanosis|✉]]</sup> 25 mars 2012 à 21:06 (CEST)')
);
}
$('#mw-input-wpReason').change(changeReason);
$('#mw-input-wpReason-other').change(changeReason);
$('#mw-input-wpReason-other').keyup(changeReason);
});
}