MediaWiki:Gadget-Adiutor-WRN.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*
 * 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: User warning
 */
/* <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 RequestRationale, warningTemplate;

function UserWarningDialog(config) {
	UserWarningDialog.super.call(this, config);
}
OO.inheritClass(UserWarningDialog, OO.ui.ProcessDialog);
UserWarningDialog.static.name = 'UserWarningDialog';
UserWarningDialog.static.title = new OO.ui.deferMsg('wrn-module-title');
UserWarningDialog.static.actions = [{
	action: 'save',
	label: new OO.ui.deferMsg('warn'),
	flags: ['primary', 'progressive']
}, {
	label: new OO.ui.deferMsg('cancel'),
	flags: 'safe'
}];
UserWarningDialog.prototype.initialize = function() {
	UserWarningDialog.super.prototype.initialize.apply(this, arguments);
	var headerTitle = new OO.ui.MessageWidget({
		type: 'notice',
		inline: true,
		label: new OO.ui.deferMsg('wrn-dialog-description')
	});
	headerTitle.$element.css('margin-top', '20px');
	var RationaleSelector = new OO.ui.DropdownWidget({
		menu: {
			items: [
				new OO.ui.MenuOptionWidget({
					data: ['Please link images', 'Please link images through categories or galleries.'],
					label: 'Please link images'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Copyvionote', 'Informing you about the speedy deletion of uploaded media.'],
					label: 'Copyvionote'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Derivativenote', 'Informing you about the speedy deletion of uploaded derivative media.'],
					label: 'Derivativenote'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No fair use', 'Commons does not accept fair use media. Please stop uploading those.'],
					label: 'No fair use'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please name images', 'Requesting you to please name your images correctly.'],
					label: 'Please name images'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please tag images', 'Requesting you to please tag your images properly.'],
					label: 'Please tag images'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please describe images', 'Requesting you to please provide detailed descriptions for your images.'],
					label: 'Please describe images'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Project scope', 'Informing you about the project scope after deleting out-of-scope contributions.'],
					label: 'Project scope'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No comments', 'Informing you to use talk pages for comments.'],
					label: 'No comments'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Welcome', 'Welcoming a new user to Wikimedia Commons.'],
					label: 'Welcome'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['End of copyvios', 'Giving you a final warning due to previous copyright violations.'],
					label: 'End of copyvios'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Fcs', 'Giving you a polite warning due to copyright violations.'],
					label: 'Fcs'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Off topic', 'Requesting you to stay on topic in Commons.'],
					label: 'Off topic'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No re-uploading', 'Requesting you to not re-upload deleted content.'],
					label: 'No re-uploading'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Test', 'Referring you to the sandbox for conducting experiments.'],
					label: 'Test'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Test2', 'Warning for vandalism and request to cease.'],
					label: 'Test2'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Test3', 'Second warning for vandalism and announcement of block if it continues.'],
					label: 'Test3'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Test4', 'Last warning for vandalism and announcement of block on the next violation.'],
					label: 'Test4'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Inappropriate imagenotes', 'Requesting you not to add inappropriate imagenotes.'],
					label: 'Inappropriate imagenotes'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont remove delete', 'Requesting you not to remove deletion templates from pages nominated for deletion.'],
					label: 'Dont remove delete'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont remove nsd or nld', 'Requesting you not to remove valid warning tags from file-description pages.'],
					label: 'Dont remove nsd or nld'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont remove speedy', 'Requesting you not to remove speedy-deletion tags.'],
					label: 'Dont remove speedy'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont remove warnings', 'Requesting you not to remove valid warning templates from your talk page, except while archiving.'],
					label: 'Dont remove warnings'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Be civil', 'Requesting you to remain civil, even if your contributions are being attacked.'],
					label: 'Be civil'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Be civil final', 'Reminding you to remain civil and warning of potential block next time.'],
					label: 'Be civil final'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Blocked user with header', 'Informing you that your account has been blocked.'],
					label: 'Blocked user with header'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Inappropriate username', 'Informing you that your username is considered inappropriate, and your account has been blocked.'],
					label: 'Inappropriate username'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Copyviouploadindefblock', 'Informing you that you have been blocked indefinitely for not stopping copyright violations after warnings.'],
					label: 'Copyviouploadindefblock'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Indefblockeduser', 'Informing you that your account has been blocked indefinitely.'],
					label: 'Indefblockeduser'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Imposter', 'Marking your account as blocked for impersonation or attack.'],
					label: 'Imposter'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please register', 'Requesting you to create an account due to numerous and good contributions.'],
					label: 'Please register'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Provide better quality', 'Asking if you have a better version of the media.'],
					label: 'Provide better quality'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please use SVG', 'Informing you about the advantages of using SVG (Scalable Vector Graphics).'],
					label: 'Please use SVG'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No scaled down dupes', 'Requesting you not to upload scaled down duplicates and explaining that MediaWiki can change the size for you.'],
					label: 'No scaled down dupes'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Unfree', 'Notifying you about the deletion of an image.'],
					label: 'Unfree'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Attackimage', 'Requesting you not to upload attack images.'],
					label: 'Attackimage'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Attackpage', 'Requesting you not to create attack pages.'],
					label: 'Attackpage'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont overwrite', 'Requesting you not to overwrite images.'],
					label: 'Dont overwrite'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont recreate', 'Requesting you not to recreate deleted images.'],
					label: 'Dont recreate'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Speedywhat', 'Informing you that one of your uploads has been speedy-deleted.'],
					label: 'Speedywhat'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No advertising', 'Requesting you not to advertise on Commons and explaining the goal of an educational image collection.'],
					label: 'No advertising'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Sign', 'Requesting you to sign your postings with four tildes (~~~~).'],
					label: 'Sign'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Blocked', 'Informing you that your account has been blocked.'],
					label: 'Blocked'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Anonblock', 'Informing you that anonymous editing is not allowed from your IP address and suggesting creating an account to contribute.'],
					label: 'Anonblock'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Blocked proxy subst', 'Informing you that your IP address has been blocked due to being believed to be an open proxy or zombie computer.'],
					label: 'Blocked proxy subst'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['IPsock', 'Informing you that there are concerns about this IP address being used by a registered user.'],
					label: 'IPsock'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Geocoding', 'Suggesting considering adding coordinates to some of your images (Geo-Coding).'],
					label: 'Geocoding'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Sourcefield', 'Requesting you to properly use the source field.'],
					label: 'Sourcefield'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dateformat', 'Requesting you to use the correct date format.'],
					label: 'Dateformat'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Do not upload thumbnails', 'Requesting you to always upload the biggest resolution image you can obtain.'],
					label: 'Do not upload thumbnails'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Flickrvionote', 'Requesting you not to upload questionable Flickr-Files to Commons.'],
					label: 'Flickrvionote'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Speedynote', 'Informing you that some of your contributed contents may be speedy-deleted.'],
					label: 'Speedynote'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Talkback', 'Requesting a talkback response.'],
					label: 'Talkback'
				}),
				new OO.ui.MenuOptionWidget({
					data: ["You've got mail", 'Notifying that an e-mail has been sent using the e-Mail-this-user feature.'],
					label: "You've got mail"
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Commons is not for articles', 'Reminding that Wikimedia Commons is for media files, while Wikipedia is for articles.'],
					label: 'Commons is not for articles'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Nopenis', 'Requesting you to consider reading COM:Project scope and COM:Nudity.'],
					label: 'Nopenis'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Please use TeX', 'Informing you about the advantages of using TeX markup.'],
					label: 'Please use TeX'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Wrong license note', 'Requesting you to be careful in selecting the correct license and to pay attention to copyright.'],
					label: 'Wrong license note'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['How to transfer', 'Informing you about the error when transferring and suggesting using CommonsHelper.'],
					label: 'How to transfer'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Unfreeflickrnote', 'Requesting you not to upload unfree files from Flickr.'],
					label: 'Unfree flickr note'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['Dont upload Wikipedia thumbnails', 'Requesting you to always upload the biggest resolution image you can obtain (Wikipedia specific).'],
					label: 'Dont upload Wikipedia thumbnails'
				}),
				new OO.ui.MenuOptionWidget({
					data: ['No selfies', 'Informing you that pictures of self and family/friends are often out of scope.'],
					label: 'No selfies'
				}),
				new OO.ui.MenuOptionWidget({
					data: ["Don't edit war", 'Asking you to refrain from edit warring.'],
					label: "Don't edit war"
				}),
				new OO.ui.MenuOptionWidget({
					data: ['', 'Select a message! Empty option.'],
					label: 'A new message for you!'
				}),
			]
		},
		label: new OO.ui.deferMsg('warning-type'),
	});
	RationaleSelector.getMenu().on('choose', function(menuOption) {
		var data = menuOption.getData();
		warningTemplate = data[0];
		talkSummary = data[1];
	});
	RationaleSelector.$element.css('margin-top', '20px');
	relatedPageField = new OO.ui.FieldLayout(relatedPage = new OO.ui.TextInputWidget({
			value: ''
		}), {
			label: new OO.ui.deferMsg('related-page'),
			help: new OO.ui.deferMsg('wrn-related-page-help')
		}),
		this.content = new OO.ui.PanelLayout({
			padded: true,
			expanded: false
		});
	warningLevel = new OO.ui.RadioSelectInputWidget({
		options: [{
			data: 1,
			label: new OO.ui.deferMsg('wrn-user-mildly'),
		}, {
			data: 2,
			label: new OO.ui.deferMsg('wrn-user-seriously'),
		}, {
			data: 3,
			label: new OO.ui.deferMsg('wrn-user-sternly'),
		}, ]
	});
	relatedPageField.$element.css({
		'margin-top': '20px',
		'margin-bottom': '20px'
	});
	this.content.$element.append(headerTitle.$element, RationaleSelector.$element, relatedPageField.$element, warningLevel.$element);
	this.$body.append(this.content.$element);
};
UserWarningDialog.prototype.getActionProcess = function(action) {
	var dialog = this;
	if(action) {
		return new OO.ui.Process(function() {
			warnUser(warningTemplate);
			dialog.close({
				action: action
			});
		});
	}
	return UserWarningDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new UserWarningDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);

function warnUser(warningTemplate) {
	api.postWithEditToken({
		action: 'edit',
		title: 'User_talk:' + mwConfig.wgPageName.replace(/_/g, " ").replace('User:', '').replace('Special:Contributions/', '').replace('User talk:', ''),
		appendtext: '\n{{subst:' + warningTemplate + '|' + relatedPage.value + '}} ~~~~\n',
		summary: 'User has been warned',
		tags: 'Adiutor',
		watchlist: 'unwatch',
		format: 'json'
	}).done(function() {
		window.location = '/wiki/' + 'User talk:' + mwConfig.wgPageName.replace(/_/g, " ").replace('User:', '').replace('Special:Contributions/', '').replace('User talk:', '');
		adiutorUserOptions.stats.userWarnings++;
		api.postWithEditToken({
			action: 'globalpreferences',
			format: 'json',
			optionname: 'userjs-adiutor',
			optionvalue: JSON.stringify(adiutorUserOptions),
			formatversion: 2,
		}).done(function() {});
	});
}
/* </nowiki> */