Aller au contenu

MediaWiki:Gadget-Adiutor-RPP.js

Une page de Wikipédia, l'encyclopédie libre.
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: Requests for page protection
 */
/* <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 adiutorUserOptions = JSON.parse(mw.user.options.get('userjs-adiutor-frwiki'));
var RPPText, RPPSummary, RPPData, RPPDuration;

function PageProtectionDialog(config) {
	PageProtectionDialog.super.call(this, config);
}
OO.inheritClass(PageProtectionDialog, OO.ui.ProcessDialog);
PageProtectionDialog.static.name = 'PageProtectionDialog';
PageProtectionDialog.static.title = new OO.ui.deferMsg('rpp-module-title');
PageProtectionDialog.static.actions = [{
	action: 'save',
	label: new OO.ui.deferMsg('create-request'),
	flags: ['primary', 'progressive']
}, {
	label: new OO.ui.deferMsg('cancel'),
	flags: 'safe'
}];
PageProtectionDialog.prototype.initialize = function() {
	PageProtectionDialog.super.prototype.initialize.apply(this, arguments);
	var headerTitle = new OO.ui.MessageWidget({
		type: 'notice',
		inline: true,
		label: new OO.ui.deferMsg('rpp-header-title')
	});
	var headerTitleDescription = new OO.ui.LabelWidget({
		label: new OO.ui.deferMsg('rpp-header-description')
	});
	TypeOfAction = new OO.ui.FieldsetLayout({
		label: new OO.ui.deferMsg('protection-type')
	});
	TypeOfAction.addItems([
		DurationOfProtection = new OO.ui.DropdownWidget({
			menu: {
				items: [
					new OO.ui.MenuOptionWidget({
						data: 'temporaire',
						label: new OO.ui.deferMsg('temporary')
					}),
					new OO.ui.MenuOptionWidget({
						data: 'indéfinie',
						label: new OO.ui.deferMsg('indefinite')
					}),
				]
			},
			label: new OO.ui.deferMsg('duration')
		}),
		TypeOfProtection = new OO.ui.DropdownWidget({
			menu: {
				items: [
					new OO.ui.MenuOptionWidget({
						data: "protection",
						label: mw.msg('full-protection')
					}),
					new OO.ui.MenuOptionWidget({
						data: "semi-protection",
						label: mw.msg('semi-protection')
					}),
					new OO.ui.MenuOptionWidget({
						data: "semi-protection étendue",
						label: mw.msg('extended-semi-protection')
					})
				]
			},
			label: new OO.ui.deferMsg('select-protection-type'),
			classes: ['adiutor-rpp-botton-select'],
		}),
		rationaleField = new OO.ui.FieldLayout(rationaleInput = new OO.ui.MultilineTextInputWidget({
			placeholder: new OO.ui.deferMsg('rpp-rationale-placeholder'),
			indicator: 'required',
			value: '',
		}), {
			label: new OO.ui.deferMsg('rationale'),
			align: 'inline',
		}),
	]);
	rationaleInput.on('change', function() {
		if(rationaleInput.value != "") {
			InputFilled = false;
		} else {
			InputFilled = true;
		}
	});
	TypeOfProtection.getMenu().on('choose', function(menuOption) {
		RPPData = menuOption.getData();
	});
	DurationOfProtection.getMenu().on('choose', function(duration) {
		RPPDuration = duration.getData();
	});
	this.content = new OO.ui.PanelLayout({
		padded: true,
		expanded: false
	});
	this.content.$element.append(headerTitle.$element, '<br>', headerTitleDescription.$element, '<br><hr><br>', TypeOfAction.$element);
	this.$body.append(this.content.$element);
};
PageProtectionDialog.prototype.getActionProcess = function(action) {
	var dialog = this;
	if(action) {
		return new OO.ui.Process(function() {
			RPPText = "\n\n== {{a\'|" + mwConfig.wgPageName.replace(/_/g, " ") + "}} ==" + "\n" + "{{DPP début|statut=|date=<!--~~~~~-->}}\n<!-- Ne pas modifier la ligne qui précède -->";
			if (RPPData) {
				if (RPPDuration) {
					RPPText += "\n* '''Type et durée : '''" + RPPData + ' ' + RPPDuration;
				} else {
					RPPText += "\n* '''Type : '''" + RPPData;
				}
			} else if (RPPDuration) {
				RPPText += "\n* '''Durée : '''" + RPPDuration;	
			}
			if (rationaleInput.value) {
				RPPText += "\n* '''Motif : '''" + rationaleInput.value;
			}
			RPPText += "\n* '''Demandée par''' : ~~~~\n<!-- Ne pas modifier la ligne qui suit -->\n{{DPP fin}}\n";
			RPPSummary = 'Demande de protection pour [[' + mwConfig.wgPageName.replace(/_/g, " ") + ']]';
			console.log(RPPText);
			addProtectionRequests(RPPText);
			dialog.close({
				action: action
			});
		});
	}
	return PageProtectionDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new PageProtectionDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);

function addProtectionRequests(RPPText) {
	api.postWithToken('csrf', {
		action: 'edit',
		title: 'Wikipédia:Demande de protection de page',
		appendtext: RPPText + "\n",
		summary: RPPSummary,
		tags: 'Adiutor',
		format: 'json'
	}).done(function() {
		window.location = '/wiki/Wikipédia:Demande_de_protection_de_page#' + mwConfig.wgPageName + "_(d_·_h_·_j_·_↵)";
	});
}
/* </nowiki> */