User:TheNozomi/global.js

WHAMDelay = 100; importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:PortableCSSPad/code.js',        'u:dev:MediaWiki:WHAM/code.2.js',        'u:dev:MediaWiki:AjaxRedirect/code.js',        'u:dev:MediaWiki:FindAndReplace/code.js',        'u:dev:ListFiles/code.js',        'u:dev:Thread Inspection/code.js',        'u:dev:Nuke/code.js'    ] }); require(['jquery', 'mw', 'wikia.ui.factory', 'wikia.window'], function ($, mw, uiFactory, context) {   'use strict';    if (context.DiffModalLoaded) {        return;    }    context.DiffModalLoaded = true;    var lang = mw.config.get('wgUserLanguage');    var msg = {        en: {            error: 'Something went wrong while getting the page at “%url”.',            loading: 'Loading…',            title: 'Changes: %pagename'        },        be: {            error: 'Што-то пайшло не так падчас загрузкі старонкі «%url».',            loading: 'Загрузка…',            title: 'Змены: %pagename'        },        es: {            error: 'Un error ha occurido mientras se extraia la página en “%url”.',            loading: 'Cargando…',            title: 'Diferencia entre revisiones: %pagename'        },        it: {            error: 'Qualcosa è andato storto mentre si caricava la pagina da “%url”.', loading: 'Caricamento…', title: 'Modifiche: %pagename' },       nl: { error: 'Er ging iets verkeerd bij het ophalen van de pagina op “%url”.', loading: 'Laden…', title: 'Wijzigingen: %pagename' },       pl: { error: 'Coś się zepsuło podczas ładowania strony „%url”.', loading: 'Ładowanie…', title: 'Zmiany: %pagename' },       ru: { error: 'Что-то пошло не так во время загрузки страницы «%url».', loading: 'Загрузка…', title: 'Изменения: %pagename' },       uk: { error: 'Щось пішло не так під час завантаження сторінки «%url».', loading: 'Завантаження…', title: 'Зміни: %pagename' },       vi: { error: 'Đã có sự cố xảy ra khi tải trang tại đường dẫn “%url”.', loading: 'Đang tải…', title: 'Thay đổi: %pagename' }   };    msg = msg[lang] || msg[lang.split('-')['0']] || msg.en; var specialDiff = { en: 'Diff' };   specialDiff = mw.config.get('wgFormattedNamespaces')['-1'] + ':' + (specialDiff[mw.config.get('wgContentLanguage')] || specialDiff.en); var currentModal = null; var pendingModal = null; var uiModalFactory = null; function updateModal(modal) { if (!currentModal) { currentModal = modal; modal.$buttons = modal.$element.find('> footer > .buttons'); modal.$content.addClass('WikiaArticle'); pendingModal['1'] = pendingModal['1'] || msg.loading; }       var shouldFire = pendingModal['2']; if (pendingModal['1']) { modal.setTitle(msg.title.replace('%pagename', pendingModal['1'])); }       modal.setContent(pendingModal['0']); pendingModal = null; modal.$buttons.empty; if (shouldFire) { mw.hook('DiffModal.ready').fire(modal); }       modal.show; }   function loadModal { if (uiModalFactory) { uiModalFactory.createComponent({               vars: {                    content: '',                    id: 'diff-modal',                    size: 'large'                },                confirmCloseModal: function  {                    currentModal = null;                    return true;                }            }, updateModal); } else { uiFactory.init(['modal']).then(function (uiModal) {               uiModalFactory = uiModal;                loadModal;            }); }   }    function showModal(content, title, shouldFire) { if (pendingModal) { pendingModal = [content, title, shouldFire]; return; }       pendingModal = [content, title, shouldFire]; if (currentModal) { updateModal(currentModal); } else { loadModal; }   }    function loadDiff(url) { showModal(''); url.extend({           action: 'render',            diffonly: '1'        }); var urlString = url.toString; $.get(urlString).always(function (content) {           var $content = null;            var valid = false;            if (typeof content === 'string') {                $content = $(content);            }            if ($content && $content.hasClass('diff')) {                valid = true;            }            if (!valid && $content) {                var $contentDiff = $content.find('table.diff');                if ($contentDiff.length) {                    $content = $contentDiff;                    content = $contentDiff.prop('outerHTML');                    valid = true;                }            }            if (valid) {                var title = $content.find('#mw-diff-ntitle1 > strong > a').attr('title');                mw.loader.using('mediawiki.action.history.diff', function  { showModal(content, title, true); });           } else {                showModal(msg.error.replace('%url', urlString));            }        }); }   function init { mw.util.addCSS(           '#diff-modal > section {' +                'box-sizing: border-box;' +                'font-size: 13px;' +                'line-height: 21px;' +                'overflow: auto;' +                'position: relative;' +            '}' +            '#blackout_diff-modal ~ .modalWrapper {' +                'position: fixed;' +            '}'        ); $(document.body).on('click.DiffModal', 'a', function (event) {           var url = new mw.Uri(event.currentTarget.href);            if (url.host !== location.hostname) {                return;            }            var hasDiffParam = url.query.diff && !url.fragment;            var isSpecialDiffLink = event.currentTarget.title.indexOf(specialDiff + '/') === 0;            if (hasDiffParam || isSpecialDiffLink) {                event.preventDefault;                loadDiff(url);            }        }); }   $(init); mw.hook('DiffModal.ready').add(function (modal) {       var $buttons = modal.$content.find('.diff-ntitle')            .find('.mw-rev-head-action, .mw-rollback-link, .patrollink').clone;        $buttons.contents.filter(function (ignore, element) { return element.nodeType === 3; }).remove;       $buttons.find('a').addClass('button');        modal.$buttons.append($buttons);    }); }); window.UseCSS = {	skin: ,	init: function {		if (window.location.href.indexOf('usesitecss=') == -1) return;		var url = UseCSS.parseURL(window.location.href);		if (url.query.usesitecss) {			UseCSS.skin = (url.query.usewikicss || url.query.usesitecss);		}		if (UseCSS.skin != ) {			$(document.body).bind('click.usecss', UseCSS.clicEvent);			$('form').bind('submit.usecss', UseCSS.submitEvent);		}	},	parseURL: function(url) {		var ret = {base:,qs:,query:{},hash:''};		var loc = url.indexOf('#');		if (loc != -1) {			ret.hash = url.substr(loc+1);			url = url.substr(0,loc);		}		loc = url.indexOf('?');		if (loc != -1) {			ret.qs = url.substr(loc+1);			url = url.substr(0,loc);			var paras = ret.qs.split('&');			for (var i = 0; i < paras.length; i++) {				var p = paras[i].split('=');				if (p.length == 2) {					ret.query[p[0]] = p[1];				}			}		}		ret.base = url;		return ret;	},	getURL: function(url) { var nurl = url.base + '?'; for (var p in url.query) { nurl += p + '=' + url.query[p] + '&'; }		nurl = nurl.substr(0,nurl.length-1); if (url.hash != '') { nurl += '#'+ url.hash; }		return nurl; },	clicEvent: function(e) { if (e.target.tagName.toLowerCase != 'a') return; if (e.target.href.indexOf(window.wgServer) != 0) return; var url = UseCSS.parseURL(e.target.href); var thisloc = UseCSS.parseURL(window.location.href); if (url.base == thisloc.base && url.qs == thisloc.qs && url.hash != '') { return; }		if (url.query.usesitecss && url.query.usesitecss != UseCSS.skin) { url.query.usewikicss = UseCSS.skin; } else { url.query.usesitecss = UseCSS.skin; }		e.target.href = UseCSS.getURL(url); },	submitEvent: function(e) { if (this.action.indexOf(window.wgServer) != 0) return; if (this.method == 'post') { var url = UseCSS.parseURL(this.action); url.query.usesitecss = UseCSS.skin; this.action = UseCSS.getURL(url); } else { $(this).append(''); }	},	stop: function { $(document.body).unbind('click.usecss'); $('form').unbind('submit.usecss'); } }; $(UseCSS.init);

var main = { init: function { 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(' revertir | '); else if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") { $('#mw-content-text ul').find('li').each(function {				if ($(this).find('.mw-uctop').length)					$(this).append(' [revertir] ');			}); }		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'));		}); },	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,				lastUser,				revId;				for (var i in revisions) {					if (revisions[i].user != currentUser) {						lastUser = revisions[i].user;						revId = revisions[i].revid;						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 = ""; 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: 'Revertidos los cambios de ' + user + ' (disc | bloquear) a la última edición de ' + 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;		}); } };
 * (function($, mw) {

main.init; }) (this.jQuery, this.mediaWiki);

/* * Ajax batch delete thingy, version [0.0.3] by Grunny * Based on: http://en.wikipedia.org/wiki/User:Splarka/ajaxbatchdelete.js * Converted to use jQuery */ ( function ( mw, $, window, document ) {	"use strict";	// Prevent double runs	if ($('#t-ajaxbd').length)		return;	var skin = mw.config.get( 'skin' ),		wgServer = mw.config.get( 'wgServer' ),		wgScriptPath = mw.config.get( 'wgScriptPath' );	function createAjaxDeleteForm {		var	pageHeading = ( skin === 'oasis' ) ? ( $( '.AdminDashboardArticleHeader' ).length ? '.AdminDashboardArticleHeader > h1' : '.WikiaPageHeader > h1' ) : 'h1.firstHeading',			$bodyId = $( '#mw-content-text > p' ),			bdelFormHtml = ''				+ ' Delete reason: '				+ '   ';		$( pageHeading ).text( 'Ajax Batch Delete' );		$bodyId.text( 'List of pages to delete:' );		$bodyId.after( bdelFormHtml );		$( '#abd-startbutton' ).click( ajaxDeleteStart );	}	function ajaxDeleteStart {		document.getElementById( 'abd-startbutton' ).setAttribute( 'disabled', 'disabled' );		var	txt = document.getElementById( 'abd-textarea' ),			deletes = txt.value.split( '\n' ),			page = deletes[0],			reason = document.getElementById( 'abd-reason' ).value, badchars = /(\#|<|>|\[|\]|\{|\}|\|)/; if( page === '' ) { $( '#abd-output' ).append( '* Done! Nothing left to do, or next line is blank.\n' ); document.getElementById( 'abd-startbutton' ).removeAttribute( 'disabled' ); } else { if( badchars.test( page ) ) { $( '#abd-output' ).append( '! Illegal characters detected, skipping:' + page + '\n' ); setTimeout( ajaxDeleteStart, 1000 ); } else { $( '#abd-output' ).append( '> Attempting to delete ' + page + '\n' ); ajaxBatchDeleteAPage( page, reason ); }		}		deletes = deletes.slice( 1, deletes.length ); txt.value = deletes.join( '\n' ); }	function ajaxBatchDeleteAPage( title, deleteReason ) { var token = mw.user.tokens.get( 'editToken' ), url = wgServer + wgScriptPath + '/api.php?action=delete&title=' + window.encodeURIComponent( title ) + '&reason=' + window.encodeURIComponent( deleteReason ) + '&format=json&token=' + window.encodeURIComponent( token ); $.post( url, function( data ) {			if( data.error ) {				$( '#abd-output' ).append( '  > Error: ' + data.error.info + '\n' );			} else {				$( '#abd-output' ).append( '  > Deleted\n' );			}			setTimeout( ajaxDeleteStart, 1000 );		} ); }	$( function {		// add link to toolbar/toolbox		if( skin === 'monobook' ) {			mw.util.addPortletLink( 'p-tb', wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd', 'Batch Delete', 't-ajaxbd' );		} else {			$( '#my-tools-menu' ).prepend( 'Batch Delete</a></li>' );		}		// create ajax delete form, but only on Special:Blankpage?blankspecial=ajaxjqbd		if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Blankpage' || ('wgCanonicalSpecialPageName' ) === 'BlanquearPágina' && $.getUrlVar( 'blankspecial' ) === 'ajaxjqbd' ) {			document.title = 'Ajax Batch Delete';			createAjaxDeleteForm;		}	} ); } ( mediaWiki, jQuery, window, document ) );