User:Nobellion/global.js

////////////////////////////////////////////////////////////////////////// /************************************************************************/ /*************************** Modified Rollback **************************/ /*************************** Author — Ozuzanna **************************/ /*************** @http://dev.wikia.com/wiki/User:Ozank_Cx ***************/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// mw.loader.using('mediawiki.api', function { var main = {	init: function {		//check if user has rollback permission already		var userGroups = ["rollback","content-moderator","sysop","vstf","helper","staff"],		ownGroups = mw.config.get('wgUserGroups'),		hasPermissionAlready = false;		for (var i in ownGroups) {			if (userGroups.indexOf(ownGroups[i]) !== -1) {				hasPermissionAlready = true;				break;			}		}		if (hasPermissionAlready) return;		if (mw.config.get('wgAction') == "history" && $('#pagehistory li').length > 1) 			$('#pagehistory li:first .mw-history-undo a').before(' rollback | '); else if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") { $('#mw-content-text ul').find('li').each(function {				if ($(this).find('.mw-uctop').length)					$(this).append(' [rollback] ');			}); }		else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0) $('.mw-usertoollinks:last').after('   [rollback] '); $('.mw-custom-rollback-link a').click(function {			main.getRevisionIdAndContent($(this).attr('data-id'));			$(this).parent.remove;		}); },	getRevisionIdAndContent: function(title) { var API = new mw.Api; API.get({		action: 'query',		prop: 'revisions',		titles: title,		rvprop: 'user|ids',		rvlimit: 500,		cb: new Date.getTime		}) .done(function(d) {			if (!d.error) {				var revisions;				for (var i in d.query.pages) {					revisions = d.query.pages[i].revisions;				}				var currentUser = revisions[0].user, //current user rollbacking from				lastUser,				revId;				for (var i in revisions) {					if (revisions[i].user != currentUser) {						lastUser = revisions[i].user; //remember last author						revId = revisions[i].revid; //get revision to revert to						break;					}				}				if (lastUser) {					API.get({ action: 'query', prop: 'revisions', rvprop: 'content', revids: revId, cb: new Date.getTime })					.done(function(d) { if (!d.error) { var content = ""; //can be no content on page so initialise empty as failsafe for (var i in d.query.pages) { if (d.query.pages[i].revisions) content = d.query.pages[i].revisions[0]["*"]; }							main.performRollback(title,content,currentUser,lastUser); }						else new BannerNotification('Unable to rollback (failed to get page content): ' + d.error.code,'error').show; })					.fail(function { new BannerNotification('Unable to rollback: failed to get page content!','error').show; });				}				else					new BannerNotification('Unable to rollback: no different editor found!','error').show;			}			else				new BannerNotification('Unable to rollback (failed to get revisions): ' + d.error.code,'error').show;		}) .fail(function {			new BannerNotification('Unable to rollback: failed to get revisions!','error').show;		}); },	performRollback: function(page,text,user,user2) { var API = new mw.Api; API.post({		action: 'edit',		title: page,		text: text,		summary: 'Reverted edits by ' + user + ' (talk | block) to last version by ' + user2 + '',		token: mw.user.tokens.values.editToken		}) .done(function(d) {			if (!d.error) {				new BannerNotification('Rollback successful!','confirm').show;							}			else				new BannerNotification('Unable to rollback (failed to publish edit): ' + d.error.code,'error').show;		}) .fail(function {			new BannerNotification('Unable to rollback: failed to publish edit!','error').show;		}); } }; main.init; });//End MR*/ //////////////////////////////////////////////////////////////////////////// /**************************************************************************/ /************************* Import Configurations **************************/ /**************************************************************************/ //////////////////////////////////////////////////////////////////////////// /* Mass Rename */ massRenameDelay = 1000; massRenameSummary = 'automatic'; WHAMDelay = 1000; var MultiUploadoption = { max: 100 }; //End MR*/ //////////////////////////////////////////////////////////////////////////// /**************************************************************************/ /******************************** Imports *********************************/ /**************************************************************************/ ////////////////////////////////////////////////////////////////////////////

/* Universal Imports */ importArticles({   type: 'script',    articles: [        'u:dev:Wikimarks/code.js',                     /*Wikibarks*/        'u:dev:PortableCSSPad/code.js',                /*PortableCSSPad*/        'u:dev:AjaxDiff/code.js',                      /*ViewDiffPages at Wiki Activity*/        'w:dev:MediaWiki:WallGreetingButton/code.js',  /*Edit Wall greeting with ease*/        'u:dev:SkinSwitchButton/code.js',              /*Switch Skins Easily*/        'u:dev:Message/code.js',                       /*MultiUser Messaging*/        'u:dev:DisableCode/code.js',                   /*Disble Code dropdown menu on quick links bar*/        'u:dev:GlobalChatJS.js',                       /*Allows Chat.js to work globally*/        'u:dev:MediaWiki:UserCheck/code.js',           /*User Table (regdate, gender, groups)*/        'u:dev:UnsafeScripts/code.js',                 /*Allow scripts to work in code editor*/ 'u:dev:MediaWiki:TabKeyInserter/code.js',     /*TabKey for code editing*/ 'u:dev:WHAM/code.2.js',                       /*WHAM Popup*/ 'u:dev:ShowUserGroups.js',                    /*User Groups on User:Page*/ 'u:dev:QuickToolsv2/code.js',                 /*QuickTools Button*/ 'u:dev:NullEditButton/code.js',               /*Null Edits for Testing*/ 'u:dev:MarkBlocked.js',                       /*Strikethrough Blocked Peeps*/ 'u:dev:FindAndReplace/code.js',               /*Find and Replace for Source Mode*/ 'u:dev:AjaxUndo/code.js',                     /*Adds quickundo to edits*/ 'u:dev:AutoEditDropdown/code.js',             /*Hover menu dropdown*/ 'u:dev:Linksweeper/code.js',                  /*Backlink cleanup*/ 'u:dev:CleanWantedFiles/code.js',             /*Moar Cleanup*/ 'u:dev:MultiUpload/code.js',                  /*Multiupload.jsjsjsjsjs*/ 'u:cohdev:User:Count_of_Howard/MG.lenny',     /*Prevents gender assumption*/ 'u:dev:AllPagesHideRedirect/code.js',         /*BestNameThisGood*/ 'u:dev:BlogLink/code.js',                     /*Adds My Blogs and Contribs to dropdown*/ 'u:dev:RailWAM/code.js',                      /*WAM on right rail*/ 'u:dev:ReferencePopups/code.js',              /*Refer to ReferencePopups*/ 'u:dev:RevealAnonIP/usercode.js',             /*192.168.0.0000001*/ 'u:dev:Rollback/code.js',                     /*Rollback without permission*/ 'u:dev:SearchSuggest/code.js',                /*Can't find what your looking for?*/ 'u:dev:Thread Inspection/code.js',            /*Thread Admin Tools*/ 'u:dev:ToggleSideBar/code.js',                /*Rail off/on*/ 'u:dev:UnhideUserMasthead/code.js',           /*Checkuser*/ 'u:dev:Sine/code.js',                         /*Autosign*/ 'u:dev:ViewDeleted/code.js',                  /*View Deleted Images*/ 'u:dev:MediaWiki:ViewRemoved/code.js',        /*View Removed Posts*/ 'u:dev:HeaderLinks/code.js',                  /*Adds icon to Headings for easy linking*/ 'u:dev:CodeQuickLinks/code.js',               /*Code links rail*/ 'u:nobellion:MediaWiki:NewTab.js' ] });//End UI