User:Amortias/common.js

importScript('User:Lourdes/PageCuration.js'); // Linkback: User:Lourdes/PageCuration.js importScript('User:Jackmcbarn/editProtectedHelper.js'); // Linkback: User:Jackmcbarn/editProtectedHelper.js importScript('User:Mr. Stradivarius/gadgets/SpamUserPage.js'); // Linkback: User:Mr. Stradivarius/gadgets/SpamUserPage.js importScript( 'User:MusikAnimal/responseHelper.js' ); // Backlink: User:MusikAnimal/responseHelper.js importScript('User:GoldenRing/wordcount.js'); // Backlink: User:GoldenRing/wordcount.js importScript('User:Writ Keeper/Scripts/massRevdel.js'); // Backlink: User:Writ Keeper/Scripts/massRevdel.js] importScript('User:Enterprisey/url-select-revdel.js'); //Linkback:[[User:Enterprisey/url-select-revdel.js

/** PermissionOTRS.js // Adds OTRS permission template via the API. Other templates such as {OTRS pending} will be removed. * @revision 22:04, 29 July 2015 (UTC) * @license: under the terms of the MIT license * @authors: *	Maintainer: User:Rillke *	Created by Bryan Tong Minh *	Amended by de:User:DerHexer, User:Guandalug, DieBuche, User:Steinsplitter *	Partially rewritten by Perhelion * @required modules: mediawiki.util, jquery.ui // /*global mediaWiki, jQuery*/ /*jshint curly:false, scripturl:true*/ (function ($, mw) { 'use strict'; var user = mw.config.get('wgUserName'); if ( mw.config.get('wgNamespaceNumber') !== 6 || !user )	return;

var sLink = '(Script) OTRS ', url = mw.config.get('wgScriptPath') + '/api.php', page = mw.config.get('wgPageName'), ticket = null, edittoken = null, content = null, timestamp = null;

function _prompt(text, OTRS) { var type = 'errorbox', title = 'OTRS', $ticket = $(' ').attr({			type : 'text',			id : 'OTRSdialog',			maxlength : 16,			size : 16,			'class' : 'numbersOnly'		}); if (!text) { title = 'INVALID ID'; text = 'You must enter a valid 16-digit ticket number.'; } else if (text === 'FAIL') { title = text; text = 'No suitable place found to insert template! Please add the template by hand.'; $ticket = ''; } else type = ''; text = $(' ').attr({'for': 'OTRSdialog','class': type}).text(text); $(' ').append([text, $ticket]).dialog({		width : 400,		dialogClass : "wikiEditor-toolbar-dialog",		resizable : false,		modal : true,		title : title,		close : function {				$(this).dialog("destroy");				$(this).remove;		},		buttons : [{			text : "OK",			click : function {				ticket = ($ticket)? $.trim($ticket.val) : ;				$(this).dialog("close");				if (ticket) {					// Check if ticket is valid					if (!ticket.match(/^\d{16}$/)) return _prompt(, OTRS);					_getPage(OTRS);				}			}		}]	}); }

function _addPermission(template, summary) { var text = content, permTester = /\|\s*[Pp]ermission\s*\=/; if (!permTester.test(text)) return _prompt('FAIL'); text = _cleanUp(text); var replLicence = text.match(/\|\s*[Pp]ermission\s*\=\s*([^\n]*)\s*\n/); if (replLicence && replLicence[1]) template += "\n" + replLicence[1]; text = text.replace(/\|\s*[Pp]ermission(\s*)\=\s*[^\n]*/, "|Permission$1= " + template); content = text; _savePage(sLink + summary); }

window.PermissionOTRS = function PermissionOTRS { _addPermission('",	'permission added'); };

window.OTRSreceived = function OTRSreceived { _addPermission('',	'email received but permission not yet confirmed'); };

function _getPage(OTRS) { $.getJSON(url, {		action : "query",		format : "json",		prop : "info|revisions",		intoken : "edit",		rvprop : "content|timestamp",		titles : page	}, function (r) {		var pages = r.query.pages;		for (var id in pages) {			if (pages.hasOwnProperty(id)) {				pages = pages[id];				edittoken = pages.edittoken;				content = pages.revisions[0]['*'];				timestamp = pages.revisions[0].timestamp;				return OTRS;			}		}	}); }

function _cleanUp(text) { return text .replace(/\=\= ?Summary ?\=\=/, '====') .replace(/\=\= ?Licensing ?\=\=/, '====') .replace(/\{\{otrs[ _\-]pending[^\}\n]*\}\}/ig, '') .replace(/\{\{[Nn]o[ _]permission[^\}\n]*\}\}/g, '') .replace(/\{\{[Nn]o[ _]OTRS[ _]permission[^\}\n]*\}\}/g, '') .replace(/\{\{otrs[ _]received[^\}\n]*\}\}/ig, '') .replace(/\{\{[Dd]elete[^\n]*\(CES?T\)\s*/g, '') .replace(/\{\{[Dd]elete[^\}\n]*\}\}\b/g, ''); }

function _savePage(summary) { var params = { action : 'edit', summary : summary, watchlist : 'preferences', title : page, token : edittoken, text : content, format : 'json' };	$.ajax({		url : url,		cache : false,		dataType : 'json',		data : params,		basetimestamp : timestamp,		type : 'POST',		success : function {			window.location.reload;		}	}); }

window.dialogOTRS = function dialogOTRS(OTRS) { _prompt('Ticket ID (16 digit number):', OTRS); };

mw.loader.using(['mediawiki.util', 'jquery.ui'], function {	mw.util.addPortletLink('p-tb', 'javascript:{dialogOTRS(PermissionOTRS);void(0)}', 'Permission OTRS');	mw.util.addPortletLink('p-tb', 'javascript:{dialogOTRS(OTRSreceived);void(0)}', 'OTRS received'); }); }(jQuery, mediaWiki));

//Mass rollback function //Written by John254 and modified/rewritten by Writ Keeper with modifications by TheDJ; original is at https://en.wikipedia.org/wiki/User:John254/mass_rollback.js //Adapted from User:Mr.Z-man/rollbackSummary.js //Instructions: Selecting the "rollback all" tab when viewing a user's contributions history //will open all rollback links displayed there. (Use with caution) function rollbackEverythingWKMR(editSummary) {	if(editSummary === null) {		return false; }	var userName = mw.config.get("wgRelevantUserName"); var titleRegex = /title=([^&]+)/; mw.loader.using( 'mediawiki.api' ).done( function	{		var api = new mw.Api;		$("a[href*='action=rollback']").each(function(ind, el) {			var params = {}; if( editSummary != '' ) {				params.summary = editSummary; }			api.rollback( titleRegex.exec(el.href)[1], userName, params).done( function			{				$(el).after("reverted");				$(el).remove;			} ); } );	} );	return false; } $(document).ready(function {	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions" && $("span.mw-rollback-link").length > 0)	{		mw.loader.using("mediawiki.util").done( function {			mw.util.addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here"); $("#ca-rollbackeverything").click( function(event)			{				event.preventDefault;				mw.loader.load( [ 'mediawiki.api' ] ); //start loading, while the user is in the prompt				return rollbackEverythingWKMR(prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));			}); });	} }); //