MediaWiki:Gadget-Adiutor-AIV.js

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.
/*
 * Adiutor: Adiutor enables versatile editing options and modules to assist a variety of user actions to enhance the Wikipedia editing experience.
 * Author: Vikipolimer
 * Learn more at: https://meta.wikimedia.org/wiki/Adiutor
 * Licensing and Attribution: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
 * Module: Administrator intervention against vandalism
 */
/* <nowiki> */
// Get essential configuration from MediaWiki
var mwConfig = mw.config.get(["skin", "wgAction", "wgArticleId", "wgPageName", "wgNamespaceNumber", "wgTitle", "wgUserGroups", "wgUserName", "wgUserEditCount", "wgUserRegistration", "wgCanonicalNamespace"]);
var api = new mw.Api();
var wikiId = mw.config.get('wgWikiID');
var adiutorUserOptions = JSON.parse(mw.user.options.get('userjs-adiutor-'+wikiId));
var RDRRationale, VandalizedPageInput, revId;
var VandalizedPage = {};
var RequestRationale = false;
VandalizedPage.value = null;
var revisionID = {};
revisionID.value = null;

function RevisionDeleteRequestDialog(config) {
	RevisionDeleteRequestDialog.super.call(this, config);
}
OO.inheritClass(RevisionDeleteRequestDialog, OO.ui.ProcessDialog);
RevisionDeleteRequestDialog.static.name = 'RevisionDeleteRequestDialog';
RevisionDeleteRequestDialog.static.title = new OO.ui.deferMsg('aiv-module-title');
RevisionDeleteRequestDialog.static.actions = [{
	action: 'save',
	label: new OO.ui.deferMsg('report'),
	flags: ['primary', 'progressive']
}, {
	label: new OO.ui.deferMsg('cancel'),
	flags: 'safe'
}];
RevisionDeleteRequestDialog.prototype.initialize = function() {
	RevisionDeleteRequestDialog.super.prototype.initialize.apply(this, arguments);
	var headerTitle = new OO.ui.MessageWidget({
		type: 'notice',
		inline: true,
		label: new OO.ui.deferMsg('aiv-header-title')
	});

	var headerTitleDescription = new OO.ui.LabelWidget({
		label: new OO.ui.deferMsg('aiv-header-description')
	});
	// Add margin-top to headerTitleDescription
	headerTitleDescription.$element.css({
		'margin-top': '20px',
		'font-weight': '300'
	});
	var RationaleSelector = new OO.ui.DropdownWidget({
		menu: {
			items: [
				new OO.ui.MenuOptionWidget({
					data: 1,
					label: new OO.ui.deferMsg('vandalism')
				}),
				new OO.ui.MenuOptionWidget({
					data: 2,
					label: new OO.ui.deferMsg('username-violation')
				}),
			]
		},
		label: new OO.ui.deferMsg('report-type'),
	});
	// Add margin-top to RationaleSelector
	RationaleSelector.$element.css('margin-top', '20px');
	
	this.content = new OO.ui.PanelLayout({
		padded: true,
		expanded: false
	});
	var RequestRationaleContainer = new OO.ui.FieldsetLayout({
		classes: ['adiutor-report-window-rationale-window']
	});
	RequestRationaleContainer.$element.css('margin-top', '20px');
	RationaleSelector.getMenu().on('choose', function(menuOption) {
		switch(menuOption.getData()) {
			case 1:
				RequestRationale = new OO.ui.FieldsetLayout({
					label: new OO.ui.deferMsg('rationale'),
				});
				RequestRationale.addItems([
					new OO.ui.FieldLayout(VandalizedPage = new OO.ui.TextInputWidget({
						value: ''
					}), {
						label: new OO.ui.deferMsg('related-page'),
						help: new OO.ui.deferMsg('related-page-description'),
					}),
					new OO.ui.FieldLayout(revisionID = new OO.ui.TextInputWidget({
						value: ''
					}), {
						label: new OO.ui.deferMsg('revision-id'),
						help: new OO.ui.deferMsg('revision-id-description'),
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-1').text(),
					}), {
						label: mw.message('aiv-rationale-1').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-2').text(),
					}), {
						label: mw.message('aiv-rationale-2').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-3').text(),
					}), {
						label: mw.message('aiv-rationale-3').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-4').text(),
					}), {
						label: mw.message('aiv-rationale-4').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-5').text(),
					}), {
						label: mw.message('aiv-rationale-5').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-6').text(),
					}), {
						label: mw.message('aiv-rationale-6').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-7').text(),
					}), {
						label: mw.message('aiv-rationale-7').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-8').text(),
					}), {
						label: mw.message('aiv-rationale-8').text(),
						align: 'inline'
					}),
				]);
				break;
			case 2:
				RequestRationale = new OO.ui.FieldsetLayout({
					label: new OO.ui.deferMsg('rationale'),
				});
				RequestRationale.addItems([
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-9').text(),
					}), {
						label: mw.message('aiv-rationale-9').text(),
						align: 'inline'
					}),
					new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
						selected: false,
						data: mw.message('aiv-rationale-10').text(),
					}), {
						label: mw.message('aiv-rationale-10').text(),
						align: 'inline'
					}),
				]);
				break;
		}
		RequestRationaleContainer.$element.html(RequestRationale.$element);
	});
	this.content.$element.append(headerTitle.$element, headerTitleDescription.$element, RationaleSelector.$element, RequestRationaleContainer.$element);
	RevisionDeleteRequestDialog.prototype.getBodyHeight = function() {
		return Math.max(this.content.$element.outerHeight(false), 515);
	};
	this.$body.append(this.content.$element);
};
RevisionDeleteRequestDialog.prototype.getActionProcess = function(action) {
	var dialog = this;
	if(action) {
		if(RequestRationale) {
			RequestRationale.items.forEach(function(Rationale) {
				if(Rationale.fieldWidget.selected) {
					RDRRationale = Rationale.fieldWidget.data;
				}
			});
		}
		if(RDRRationale) {
			return new OO.ui.Process(function() {
				if(VandalizedPage.value) {
					VandalizedPageInput = 'page: [[' + VandalizedPage.value + ']] ';
				} else {
					VandalizedPageInput = '';
				}
				if(revisionID.value) {
					revId = '([[Spécial:Diff/' + revisionID.value + '|diff]]) ';
				} else {
					revId = '';
				}
				AccountName = mwConfig.wgPageName.replace(/_/g, " ").replace('Utilisateur:', '').replace('Utilisatrice:', '').replace('Discussion utilisateur:', '').replace('Discussion utilisatrice:', '').replace('Spécial:Contributions\/', '').replace(/\/.+/, ''); // nom de l'utilisateur à bloquer
				PreparedText = '\n\== Demande de blocage de ' + AccountName + ' ==' + '\n\n' + '* Auteur du vandalisme : {{u+|'+ AccountName +'}} \n\n* Type de dégâts : '+ VandalizedPageInput +  revId + RDRRationale+'\n\nMessage déposé par --~~~~';
				addReport(PreparedText, AccountName);
				dialog.close({
					action: action
				});
			});
		} else {
			OO.ui.alert(new OO.ui.deferMsg('select-rationale')).done(function() {});
		}
	}
	return RevisionDeleteRequestDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new RevisionDeleteRequestDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);

function addReport(PreparedText, AccountName) {
	api.postWithToken('csrf', {
		action: 'edit',
		title: 'Wikipédia:Vandalisme en cours',
		appendtext: "\n" + PreparedText + "\n",
		summary: '[[Utilisateur:' + AccountName + ']] a été signalé.',
		tags: 'Adiutor',
		format: 'json'
	}).done(function() {
		adiutorUserOptions.stats.blockRequests++;
		api.postWithEditToken({
			action: 'globalpreferences',
			format: 'json',
			optionname: 'userjs-adiutor',
			optionvalue: JSON.stringify(adiutorUserOptions),
			formatversion: 2,
		}).done(function() {});
		window.location = '/wiki/Wikipédia:Vandalisme_en_cours#Demande_de_blocage_de_' + AccountName;
	});
}
/* </nowiki> */