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:Thread Inspection/code.js'    ] }); 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); 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);    }); });