User:Superwatery/common.js

$('head').append('');

/** * A variant of WHAM with a different modal * Includes functionality to delete forum/message wall threads and selective * deleting of pages, which the original lacks * Original "WHAM" - https://dev.wikia.com/wiki/MediaWiki:WHAM/code.js * @author Ozank Cx */ mw.loader.using('mediawiki.api').then(function {   'use strict';    var config = mw.config.get([ 'wgCanonicalSpecialPageName', 'wgFormattedNamespaces', 'wgPageName', 'wgUserGroups', 'wgUserName' ]);   if ( config.wgCanonicalSpecialPageName !== 'Contributions' || !/rollback|content-moderator|threadmoderator|sysop|vstf|staff|helper|global-discussions-moderator|wiki-manager|autoconfirmed/.test(config.wgUserGroups.join) || window.WHAMLoaded ) {       return;    }    window.WHAMLoaded = true;    if (!window.dev || !window.dev.i18n) {           importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });   }    importArticle({ type: 'style', article: 'u:dev:MediaWiki:WHAM.css' });   var username = config.wgPageName.split('/')[1],        token = mw.user.tokens.get('editToken'),        delay = window.WHAMDelay || 100,        deleteReason,        duration,        blockReason,        Api = new mw.Api,        i18n,        progress = 'https://images.wikia.nocookie.net/common/skins/common/progress-wheel.gif',        $button;    function apiDelete(page, reason) {        Api.post({ action: 'delete', title: page, reason: reason, bot: true, token: token }).done(function(d) { if (d.error) { console.log(                   i18n.msg('do-delete-fail', page, d.error.code).plain                ); } else { console.log(i18n.msg('do-delete-success', page).plain); }       }).fail(function { console.log(               i18n.msg( 'do-delete-fail', page, i18n.msg('ajax-error').plain ).plain           ); });   }    function doRollback {        var $links = $('.mw-rollback-link a'),            len = $links.length;        if (len === 0) {            $('#status-wham').text(i18n.msg('do-rollback-done').plain);        }        $links.each(function(i) { var href = new mw.Uri($(this).attr('href')).extend({               bot: 1            }).toString; setTimeout(function {               $.get(href);                $('#status-wham').html( i18n.msg('do-rollback-status').escape + $(' ', {                       src: progress                    }).prop('outerHTML') );               if (i === len - 1) {                    $('#status-wham').text( i18n.msg('do-rollback-done').plain );               }            }, i * delay); });   }    function doDelete {        deleteReason = prompt( i18n.msg('do-delete-reason').plain, window.WHAMDeleteReason || i18n .inContentLang .msg('default-delete-reason') .plain );       if (!deleteReason) {            return;        }        var deleteArray = [];        $('#mw-content-text ul li').each(function { var $children = $(this).children('a'), title = $children.first.attr('title'), uri = new mw.Uri($children.eq(1).attr('href')); if (               // If it's not a thread...                !title.match(/\/@comment-/) ||                ( // ...or if it's a thread edit... title.match(/\/@comment-/) && uri.query.diff === 'prev' )           ) {                // ...don't process it. return; }           deleteArray.push(title); });       $('li .newpage ~ a').each(function { var title = new mw.Title($(this).attr('title')); if (               title.namespace === 1200 ||                title.namespace === 1201 &&                title.getNamespacePrefix < 9            ) { return; }           deleteArray.push(title.getPrefixedText); });       $.each(deleteArray, function(i, v) { setTimeout(function {               $('#status-wham').html( i18n.msg('do-delete-status').escape + $(' ', {                       src: progress                    }).prop('outerHTML') );               apiDelete(v, deleteReason);                if (i === deleteArray.length - 1) {                    $('#status-wham').text(i18n.msg('do-delete-done').plain);                }            }, i * delay); });   }    function doBlock {        duration = prompt( i18n.msg('do-block-duration').plain, window.WHAMBlockDuration || '2 weeks' );       if (!duration) {            return;        }        blockReason = prompt( i18n.msg('do-block-reason').plain, window.WHAMBlockReason || i18n .inContentLang .msg('default-block-reason') .plain );       if (!blockReason) {            return;        }        Api.post({ action: 'block', user: username, expiry: duration, nocreate: 0, autoblock: 0, reason: blockReason, bot: true, token: token }).done(function(d) { if (d.error) { alert(                   i18n.msg('do-block-fail', username, d.error.code).plain                ); } else { console.log(i18n.msg('do-block-success', username).plain); }       }).fail(function { alert(               i18n.msg( 'do-block-fail', username, i18n.msg('ajax-error').plain ).plain           ); });   }    function doBot {        Api.get({ action: 'query', list: 'users', ustoken: 'userrights', ususers: config.wgUserName }).done(function(data) { var params = { action: 'userrights', user: config.wgUserName, reason: window.WHAMBotReason || i18n .inContentLang .msg('default-delete-reason') .plain, bot: true, token: data.query.users[0].userrightstoken };           params[ config.wgUserGroups.indexOf('bot') === -1 ? 'add' : 'remove' ] = 'bot'; Api.post(params).done(function(d) {               if (d.error) {                    console.log(i18n.msg('bot-me-fail', d.error.code).plain);                } else {                    console.log(i18n.msg('bot-me-done').plain);                }            }); });   }    function doSelectiveDelete {        deleteReason = prompt( i18n.msg('do-delete-reason').plain, window.WHAMDeleteReason || i18n .inContentLang .msg('default-delete-reason') .plain );       if (!deleteReason) {            return;        }        $('.selectiveDel').each(function { var $this = $(this), title = new mw.Title($('.mw-revdelundel-link').exists ?                   $this.parent.children('a').eq(0).attr('title') :                    $this.parent.find('a').first.attr('title')); if ($this.prop('checked') && title.namespace !== 1200) { apiDelete(title.getPrefixedText, deleteReason); $this .parent .addClass('wham-resolved') .children .removeAttr('href') .addClass('wham-resolved'); }       });        setTimeout(function { location.reload; }, 5000);   }    function checkSelectiveDelete {        var $this = $(this),        uncheck = $this.text === i18n.msg('selective-delete-uncheck').plain;        $('.selectiveDel').each(function { var chkObj = $(this); if (uncheck) { chkObj.removeAttr('checked'); } else { chkObj.attr('checked', 'checked'); }       });        $this.text( i18n.msg(               uncheck ?                    'selective-delete-check' :                    'selective-delete-uncheck'            ).plain );   }    function startSelectiveDelete {        $('#form-main').closeModal;        if ($('#btn-wham-del').exists && $('#btn-wham-check').exists) {            return;        }        var $chk = $(' ', { 'class': 'selectiveDel', 'type': 'checkbox' });       $('#mw-content-text')            .find('ul')            .last            .before( $('', {                   'class': 'button',                    'id': 'btn-wham-del',                    'text': i18n.msg('start-selective-delete').plain                }), ' ',               $('', {                    'class': 'button',                    'id': 'btn-wham-check',                    'text': i18n.msg('selective-delete-check').plain                }) );       $('li .newpage ~ a').each(function { if (!$(this).parent.find('input').length) { $(this).parent.prepend($chk.clone); }       });        $('#mw-content-text ul li').each(function { var $children = $(this).children('a'), title = $children.first.attr('title'), uri = new mw.Uri($children.eq(1).attr('href')); if (               // If it's a thread...                title.match(/\/@comment-/) &&                // ...and not a thread edit...                uri.query.diff !== 'prev' &&                // ...and there's no checkbox currently...                !$this.find('input').length            ) { // ...append it. $this.prepend($chk.clone); }       });        $('#btn-wham-del').click(doSelectiveDelete);        $('#btn-wham-check').click(checkSelectiveDelete);    }    function doAll {        doBlock;        if (duration || blockReason) {            doDelete;            if ($('.tabs li:first-child a:not(.new)').exists) {                if (confirm(i18n.msg('userpage-delete-confirm').plain)) {                    apiDelete(config.wgFormattedNamespaces[2] + ':' + username, window.WHAMDeleteReason || i18n.inContentLang.msg('default-delete-reason').plain);                }            }            if (deleteReason) {                doRollback;            }        }    }    function click {        $.showCustomModal(i18n.msg('title').escape, '', { id: 'form-main', width: 260, height: 190, buttons: [{ message: i18n.msg('do-delete').escape, defaultButton: true, handler: doDelete }, {               message: i18n.msg('start-selective-delete').escape, defaultButton: true, handler: startSelectiveDelete }, {               message: i18n.msg('do-rollback').escape, defaultButton: true, handler: doRollback }, {               message: i18n.msg('do-block').escape, defaultButton: true, handler: doBlock }, {               message: i18n.msg('do-all').escape, defaultButton: true, handler: doAll }, {               message: i18n.msg('close-wham').escape, id: 'close-wham' }]       });        $('#close-wham').after($(' ', {            id: 'status-wham'        }));        $('#close-wham,.close').click(function { $('#form-main').closeModal; location.reload; });       // Bot button        if ( window.WHAMBotMe === true || /vstf|staff|helper|wiki-manager/.test(config.wgUserGroups.join) ) {           $('#form-main .modalToolbar .wikia-button:nth-child(5)').after( $('', {                   'id': 'wham-bot',                    'class': 'wikia-button',                    'text': i18n.msg( config.wgUserGroups.indexOf('bot') === -1 ? 'bot-me' : 'unbot-me' ).plain               }).click(doBot) );       }    }    function qlIntegration(QuickLogs) {        $button.remove;        QuickLogs.addLink('wham', { click: click, message: i18n.msg('contribs-wham').plain });   }    function init(i18no) {        i18n = i18no;        $button = $('', { id: 'contribs-wham', click: click, title: i18n.msg('contribs-wham-title').plain, text: i18n.msg('contribs-wham').plain });       $('#contentSub').append(' ', $button);        mw.hook('QuickLogs.loaded').add(qlIntegration);    }    function preload(i18no) {        i18no.loadMessages('WHAM').then(init);    }    mw.hook('dev.i18n').add(preload); });

require(['wikia.ui.factory'], function(ui) {   'use strict';    importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' }, {       type: 'style', article: 'u:dev:MediaWiki:LastEdited.css' });

/**    * Main object * @class lastEdited */   var lastEdited = { // Cached mw.config values config: mw.config.get([           'stylepath',            'skin',            'wgAction',            'wgArticleId',            'wgFormattedNamespaces',            'wgIsMainPage',            'wgNamespaceNumber',            'wgPageName',            'wgUserGroups',            'wgUserName'        ]), // Configuration options options: $.extend({           avatar: true,            avatarsize: 15,            size: true,            diff: true,            diffModal: true,            comment: true,            newpage: true,            time: 'timeago',            position: {                 element: ,                 method:             },            namespaces: {                exclude: [-1, 1201, 2001]            },            pages: []        }, window.lastEdited), // If the user can rollback edits canRollback: /(bureaucrat|sysop|helper|vstf|staff|content-moderator|rollback|autoconfirmed)/.test(mw.config.get('wgUserGroups').join(' ')), /**        * Initializes everything */       init: function { if (lastEdited.shouldRun) { window.lastEditedLoaded = true; lastEdited.insert; mw.hook('dev.i18n').add(function(i18no) {                   $.when( lastEdited.fetch, i18no.loadMessages('LastEdited'), ui.init(['modal']), mw.loader.using('mediawiki.action.history.diff') ).then(lastEdited.render);               }); }       },        /**         * Checks whether the script should run further or not * @return {Boolean} If the script should run further */       shouldRun: function { var allowed = Object.keys(lastEdited.config.wgFormattedNamespaces).map(Number), ns = lastEdited.options.namespaces; if (ns && ns.exclude instanceof Array) { allowed = allowed.filter(function(elem) {                   return ns.exclude.indexOf(elem) < 0;                }); }           return !$.getUrlVar('diff') && !$.getUrlVar('oldid') && allowed.indexOf(lastEdited.config.wgNamespaceNumber) !== -1 && lastEdited.options.pages.indexOf(lastEdited.config.wgPageName) === -1 && !lastEdited.config.wgIsMainPage && lastEdited.config.wgAction === 'view' && !window.lastEditedLoaded && lastEdited.config.wgArticleId !== 0; },       /**         * Inserts the placeholder for last edit information */       insert: function { var $loader = $(' ', {               id: 'lastEdited',                'class': 'lastEdited'            }).append(                $(' ', { id: 'lastEdited-loading', src: lastEdited.config.stylepath + '/common/images/ajax.gif' })           );            if (lastEdited.config.skin === 'oasis') { var pos = lastEdited.options.position; if (pos.element && pos.method) { var $el = $(pos.element), m = pos.method; if ($el.length && (m === 'append' || m === 'prepend')) { $el[m]($loader); }               } else { $loader.insertAfter('#PageHeader .page-header__title, .UserProfileActionButton'); }           } else { $loader.insertBefore('#bodyContent'); }           lastEdited.$content = $loader; mw.hook('LastEdited.inserted').fire($loader); },       /**         * Fetches last edit information from the API * @returns {jQuery.Deferred} A Promise-like object */       fetch: function { var query = { action: 'query', titles: lastEdited.config.wgPageName, prop: 'revisions', rvprop: 'timestamp|user|userid|size|parsedcomment|flags', rvlimit: 2, rvdiffto: 'prev', format: 'json' };           if (lastEdited.canRollback) { query.rvtoken = 'rollback'; }           return $.get(mw.util.wikiScript('api'), query); },       /**         * Renders last edited information * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @param {Object} modal Modal generator obtained from UI factory */       render: function(data, i18n, modal) { if (lastEdited.options.lang) { i18n.useLang(lastEdited.options.lang); } else { i18n.useUserLang; }           data = data[0].query.pages[lastEdited.config.wgArticleId].revisions; if (!data[1] && !lastEdited.options.newpage) { lastEdited.$content.remove; return; }           var prev = data[1]; data = data[0]; lastEdited.$content.html(''); ['UserTime', 'Diff', 'Minor', 'Comment', 'Size'].forEach(function(el) {               lastEdited.$content.append.apply(lastEdited.$content, lastEdited['render' + el](data, i18n, prev));            }); // In case the user doesn't have an avatar $('#lastEdited img').error(function {               $(this).attr('src', 'https://images.wikia.nocookie.net/messaging/images/1/19/Avatar.jpg');            }); lastEdited._i18n = i18n; lastEdited._data = data; lastEdited._modal = modal; mw.hook('LastEdited.render').fire(lastEdited.$content); },       /**         * Returns HTML for a link to a page * containing a user's username * Utility function for renderUserTime * @returns {String} HTML for an  tag */       userLink: function(prefix, user, text) { return mw.html.element('a', { href: mw.util.getUrl(prefix + user) }, text); },       /**         * Renders user and time links * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @returns {Array} Parts to append to last edited information */       renderUserTime: function(data, i18n) { // Build user links var user = data.user, links = lastEdited.userLink('User:', user, user) + ' (' +                   lastEdited.userLink('User talk:', user, i18n.msg('talk').plain) +                    ' | ' +                    lastEdited.userLink('Special:Contributions/', user, i18n.msg('contribs').plain);            if (/(bureaucrat|sysop|helper|vstf|staff|custodian)/.test(lastEdited.config.wgUserGroups.join(' '))) {                links += ' | ' + lastEdited.userLink('Special:Block/', user, i18n.msg('block').plain);            }            if (lastEdited.options.avatar) {                links = mw.html.element('img', { src: 'https://services.fandom.com/user-avatar/user/' + data.userid + '/avatar', width: lastEdited.options.avatarsize, height: lastEdited.options.avatarsize }) + ' ' + links;           }            links += ') '; // Build time var $time = $(' ', {               'class': 'lastEdited-timeago',                title: data.timestamp            }); if (lastEdited.options.time === 'timestamp') { var date = new Date(data.timestamp).toString; if (lastEdited.options.timezone && lastEdited.options.timezone === 'UTC') { date = new Date(data.timestamp).toUTCString; }               if (lastEdited.options.timezone && lastEdited.options.timezone === 'locale') { date = new Date(data.timestamp).toLocaleString; $time.text(date); }               else { $time.text(date.slice(0, 3) + ', ' + date.slice(4, 16) + ', ' + date.slice(17, 26)); }           } else { $time.timeago; }           return [ i18n.msg('lastEdited').escape .replace('$1', links) .replace('$2', $time.prop('outerHTML')) ];       },        /**         * Renders the diff link * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @returns {Array} Parts to append to last edited information */       renderDiff: function(data, i18n) { if (lastEdited.options.diff && data.diff.from) { var link = $('', {                   id: 'lastEdited-diff-link',                    href: '?diff=' + data.diff.to,                    text: i18n.msg('diff').plain,                    title: 'Special:Diff/' + data.diff.to                }); if (lastEdited.options.diffModal) { link.attr('data-disable-quickdiff', ''); link.click(function(e) {                       e.preventDefault;                        lastEdited.generateModal(lastEdited._i18n, lastEdited._data, lastEdited._modal);                    }); }               return [ ' (',                   link,                    ')' ];           }            return []; },       /**         * Renders the "m" sign next to minor edits * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @returns {Array} Parts to append to last edited information */       renderMinor: function(data, i18n) { if (data.minor === '') { return [ ' ',                   $(' ', {                        id: 'lastEdited-minor',                        text: '[' + i18n.msg('minor').plain + ']'                    }) ];           }            return []; },       /**         * Renders the last edit summary used * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @returns {Array} Parts to append to last edited information */       renderComment: function(data, i18n) { var comment = data.parsedcomment; if (lastEdited.options.comment && comment) { return [ ' ',                   i18n.msg('comment').escape, ': ',                   comment.indexOf('Created page with') === -1 ? comment : i18n.msg('created').escape ];           }            return []; },       /**         * Renders the size of the last diff * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @param {Object} prev Information about the previous edit from the API * @returns {Array} Parts to append to last edited information */       renderSize: function(data, i18n, prev) { if (!lastEdited.options.size) { return []; }           var arr = [ ' ',               i18n.msg('size').escape, ': ',               data.size, ' ',               i18n.msg('bytes').escape ];           if (prev) { var bytes = data.size - prev.size, classes = 'mw-plusminus-' + (bytes > 0 ?                       'pos' :                        bytes < 0 ?                            'neg' :                            'null'); if (Math.abs(bytes) > 500) { classes += ' lastEdited-diff-major'; }               arr.push(                    ' ',                    $(' ', { text: '(' + (bytes > 0 ? '+' : '') + bytes.toString.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ')', 'class': classes })               );            }            return arr; },       /**         * (Re)generates the diff modal * @param {Object} data Edit information obtained from the API * @param {Object} i18n I18N object generated by I18n-js * @param {Object} modal Modal generator obtained from UI factory */       generateModal: function(i18n, data, modal) { var config = { vars: { id: 'lastEdited-diff', size: 'large', title: i18n.msg('changes').escape + ': ' + lastEdited.config.wgPageName.replace(/_/g, ' '), content: ' ' + ' ' +                            ' ',                    buttons: [ {                           vars: { value: i18n.msg('cancel').plain, data: [{ key: 'event', value: 'close' }]                           }                        },                        {                            vars: { value: i18n.msg('link').plain, classes: ['normal', 'primary'], data: [{ key: 'event', value: 'link' }]                           }                        },                        {                            vars: { value: i18n.msg('undo').plain, classes: ['normal', 'primary'], data: [{ key: 'event', value: 'undo' }]                           }                        }                    ]                },                confirmCloseModal: function { lastEdited.modal = null; return true; }           };            if (lastEdited.canRollback && lastEdited.config.wgUserName !== data.user) { config.vars.buttons.push({                   vars: {                        value: i18n.msg('rollback').plain,                        classes: ['normal', 'primary'],                        data: [{                            key: 'event',                            value: 'rollback'                        }]                    }                }); }           modal.createComponent(config, function(diffModal) {                diffModal.bind('link', function { diffModal.trigger('close'); window.open(mw.util.getUrl('', { diff: data.diff.to                   }), '_blank'); });               diffModal.bind('undo', function { diffModal.trigger('close'); window.open(mw.util.getUrl(lastEdited.config.wgPageName, { action: 'edit', undoafter: data.diff.from, undo: data.diff.to                   }),                    '_blank'); });               diffModal.bind('rollback', function { $.post(mw.util.wikiScript('api'), {                       action: 'rollback',                        title: lastEdited.config.wgPageName,                        user: data.user,                        token: data.rollbacktoken,                        format: 'json'                    }).done(function(d) {                        if (!d.error) {                            window.location.reload;                        }                    }); });               lastEdited.modal = diffModal;                lastEdited.modal.show;            }); }   };    lastEdited.init; });

// /* jshint browser:true jquery:true laxbreak:true smarttabs:true */ /* global mediaWiki */ (function(window, $, mw) {   'use strict';    var config = mw.config.get([ 'wgAction', 'wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'wgUserName' ]), groups = config.wgUserGroups.join(' ');   if (config.wgNamespaceNumber === 1202) {        $('#ca-talk').remove;        return;    } else if ( config.wgTitle.indexOf('/') !== -1 || config.wgNamespaceNumber !== 1200 || !(           config.wgUserName === config.wgTitle ||            /sysop|threadmoderator|vstf|helper|staff/.test(groups)        ) || config.wgAction !== 'edit' || window.WallGreetingButtonLoaded ) {       return;    }    window.WallGreetingButtonLoaded = true;    function init(i18n) {        i18n.useUserLang;        var params = {            url: new mw.Title(config.wgTitle, 1202).getUrl,            wallUrl: new mw.Title(config.wgTitle, 1200).getUrl        };        ['editGreeting', 'history', 'wallHistory', 'delete', 'protect', 'raw'].forEach(function(el) { params[el] = i18n.msg(el).plain; });       $('#WikiaMainContentContainer').prepend(window.Mustache.render(            ' ' +                ' ' +                    ' ' +                        '' +                            '' +                                ' ' +                            ' ' +                            '  ' +                        '' +                        ' ' +                            '' +                                '' + ' ' + ' ' +                           ' ' +                            '' + '' + '<li></a></li>' + '<li></a></li>' + (                                       /sysop|content-moderator|vstf|helper|staff/.test(groups) ?                                            '<li></a></li>' +                                             (window.WallGreetingButtonProtect ? '<li></a></li>' : ) :                                                                               ) +                                     (                                        window.WallGreetingButtonRaw ?                                            '<li></a></li>' :                                        ''                                    ) + '</ul>' + ' ' +                       ' ' +                    ' ' +                ' ' +            ' ',            params ));   }    importArticle({        type: 'script',        article: 'u:dev:MediaWiki:I18n-js/code.js'    }); mw.hook('dev.i18n').add(function(i18no) {       $.when( i18no.loadMessages('WallGreetingButton'), mw.loader.using(['mediawiki.Title', 'wikia.mustache']) ).then(init);   }); })(window, jQuery, mediaWiki);

/* mw.loader.using('mediawiki.api', function {	//Exit if normal rollback links are present	if ($('.mw-rollback-link').length) return;	var conf = mw.config.get([ 'wgAction', 'wgCanonicalSpecialPageName', 'wgContentLanguage', 'wgPageName', 'wgUserLanguage', 'skin' ]),	i18n = {		en: {			rollback: "rollback",			description: "&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click",			summary: "Reverted edits by $1 (talk | block) to last version by $2 (script)",			summaryShort: "Reverted edits by $1 (talk) to last version by $2 (script)",			editConflict: "Unable to rollback (edit conflict)",			contentFail: "Unable to rollback (failed to get page content)",			singleEditor: "Unable to rollback (no different editor found)",			revisionFail: "Unable to rollback (failed to get revisions)",			editFail: "Unable to rollback (failed to publish edit)",			success: "Rollback successful"		}	};	i18n = i18n[conf.wgUserLanguage] || i18n[conf.wgUserLanguage.split('-')[0]] || i18n[conf.wgContentLanguage] || i18n[conf.wgContentLanguage.split('-')[0]] || i18n.en; conf.API = new mw.Api; conf.token = mw.user.tokens.values.editToken; //History if (conf.wgAction == "history" && $('#pagehistory li').length > 1) $('#pagehistory li:first .mw-history-undo a').before(' ' + i18n.rollback + '</a> | '); //Contributions else if (conf.wgCanonicalSpecialPageName == "Contributions") { $('#mw-content-text ul').find('li').each(function {			if ($(this).find('.mw-uctop').length)				$(this).append(' [' + i18n.rollback + '</a>] ');		}); }	//Diffs else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0) $('.mw-usertoollinks:last').after('   [' + i18n.rollback + '</a>] '); else return; mw.util.addCSS('.mw-custom-rollback-link a { cursor: pointer; }'); $('.mw-custom-rollback-link a').click(function {		getRevisionIdAndContent($(this).data('id'),$(this).data('user').replace(/_/g, " "));		$(this).parent.remove;	}); window.AjaxBlock = { blockReasons: { 'Vandalism': 'Vandalism', 'Spam': 'Spam', 'Repeated policy violations': 'Repeated violations', 'Sockpuppetry/Ban Evasion': 'Sockpuppetry', 'Moved to a new account': 'Moved account', 'Removing content/blanking pages': 'Page blanking', 'Inserting false information or nonsense': 'Gibberish', 'Intimidating behaviour/harassment/trolling': 'Troll/Harassment', 'Unacceptable username, avatar, or global masthead': 'Name/avatar', 'Under the legal age': 'COPPA', 'Failing to comply with the File Policy': 'File Policy', 'Posting/Discussing leaked content': 'Leaks' },   check: { creation: true, talk: true, autoBlock: true, override: true } };	function getRevisionIdAndContent(title,target) { conf.API.get({		action: 'query',		prop: 'revisions',		titles: title,		rvprop: 'user|ids',		rvlimit: 500000,		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 lastUser,				revId;				for (var j in revisions) {					if (revisions[j].user != target) {						lastUser = revisions[j].user; //remember last author						revId = revisions[j].revid; //get revision to revert to						break;					}				}				if (lastUser) {					conf.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 for (var i in d.query.pages) { if (d.query.pages[i].revisions) content = d.query.pages[i].revisions[0]["*"]; }							performRollback(title,content,target,lastUser); }						else outputError(i18n.contentFail + ': ' + d.error.code); })					.fail(function { outputError(i18n.contentFail); });				}				else					outputError(i18n.singleEditor);			}			else				outputError(i18n.revisionFail + ': ' + d.error.code);		}) .fail(function {			outputError(i18n.revisionFail);		}); }	function performRollback(page,text,user,user2) { var summary = i18n.summary.replace(/\$1/g,user).replace(/\$2/g,user2); conf.API.post({		action: 'edit',		title: page,		text: text,		summary: summary,		minor: true,		token: conf.token		}) .done(function(d) {			if (!d.error) {				new BannerNotification(i18n.success,'confirm').show;							}			else				outputError(i18n.editFail + ': ' + d.error.code);		}) .fail(function {			outputError(i18n.editFail);		}); }	function outputError(text) { switch (conf.skin) { case 'oasis': case 'wikia': new BannerNotification(text,'error').show; break; default: alert(text); break; }		} });
 * Rollback
 * @description Perform rollbacks without needing to be in the usergroup
 * @author Ozank

// Talk page button // Created by Lil' Miss Rarity // MIT OS License mw.loader.using(['mediawiki.api', 'mediawiki.Title']).then(function {   var config = mw.config.get([ 'wgArticleId', 'wgNamespaceNumber', 'wgPageName' ]);   if ( (window.TalkButtonNamespaces || [0]).indexOf(config.wgNamespaceNumber) === -1 || config.wgArticleId === 0 || window.TalkButtonLoaded ) {       return;    }    window.TalkButtonLoaded = true;    var title = new mw.Title(config.wgPageName);    title.namespace += 1;    var titleText = title.getPrefixedText;    new mw.Api.get({ action: 'query', titles: titleText, prop: 'info', meta: 'allmessages', inprop: 'revcount', ammessages: 'oasis-page-header-talk' }).done(function(d) { if (d.error) { return; }       var text = d.query.allmessages[0]['*'], pages = d.query.pages; if (!pages[-1]) { text += ' (' + pages[Object.keys(pages)[0]].revcount + ')'; }       $('<li>').append(            $('', { 'class': 'TalkButtonBubble', href: mw.util.getUrl(titleText), id: 'ca-talk', text: text })       ).appendTo('.page-header__contribution-buttons .wds-list'); }); });

users = []; $('.edited-by a:not(.subtle)').each(function(i,el) {	name = $(this).text;	users.push({nickname: name, el:el});	$.getJSON('/api.php?action=query&list=users&ususers=' + name + '&format=json',function(res) { id = res.query.users[0].userid; _.where(users,{nickname: res.query.users[0].name}).forEach(function(u) {			u.id = id;		}); $.get('https://services.wikia.com/user-attribute/user/' + id + '/attr/name', function(attr) {			userItems = _.where(users,{id: id});			userItems.forEach(function(u) { u.name = attr.value; if(!$(u.el).siblings('.user_nickname').length) { $(u.el).text(u.name).after(                       '&emsp;',                        $(' ',{class: 'user_nickname'}).css({color:'grey', 'font-weight':'normal'}).text('@' + u.nickname)                    ); }			});		});	}); });

/** * Standard edit summaries * * see https://dev.wikia.com/wiki/Standard_Edit_Summary * for documentation and examples * * Originally written by User:Sikon for Wookiepedia * Rewritten by User:Quarenon for RuneScape Wiki * Updated by User:Eladkse for Casualty Wiki * Updated to handle comments and tabindexes by User:452 * Updated to handle wide-screen mode and slightly optimized by User:Pecoes */ /*jshint jquery:true, browser:true, es5:true, devel:true, camelcase:true, curly:false, undef:true, bitwise:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, unused:true, regexp:true, strict:true, trailing:false*/ /*global mw, importArticle */ $(function {   'use strict';    var $textarea = $('#wpSummary');    if (!$textarea.length || document.getElementById('stdSummaries')) return;    var presets = (window.dev && window.dev.editSummaries) || {},        select = presets.select || 'Template:Stdsummaries';    $textarea.attr('tabindex', '3'); //set tabindex for summaries text area    $('#wpMinoredit').attr('tabindex', '4'); //set tabindex for minor edit checkbox    $('#wpSave').attr('tabindex', '5'); //set tabindex for publish button    var $summary = $('#wpSummaryEnhanced');    if (!$summary.length) $summary = $textarea;    if ('css' in presets) {        mw.util.addCSS(presets.css);    } else {        importArticle({ type: 'style', article: 'u:dev:MediaWiki:Standard_Edit_Summary.css' });   }    var $combo = $('<select id="stdSummaries" tabindex="2"> ')    .insertAfter($textarea)    .change(function { //var val = $summary.val; //$summary.val(val + (val.length ? '; ' : '') + $(this).val); $summary.val($(this).val); });   function flatten (options, indent) {        var flattened = [];        indent = indent || ;        for (var i = 0; i < options.length; i++) {            if ($.isArray(options[i])) {                flattened = flattened.concat(flatten(options[i], '-- '));            } else {                flattened.push(indent + options[i]);            }        }        return flattened;    }    function render (lines) {        var options = , selected = ' selected',            ignore = { ':': 1, '*': 1,  '<': 1 };        for (var i = 0; i < lines.length; i++, selected = '') {            if (!lines[i].length || ignore[lines[i][0]]) {                continue; // lines beginning with these characters: : * < are ignored            }            if (lines[i].substring(0, 3) === '-- ') {                var contents = mw.html.escape( lines[i].substring(3) );                options += '<option value="' + contents + '"' + selected + '> ' + contents + ' '; } else { options += '<option value="" disabled' + selected + '>' + mw.html.escape( lines[i] ) + ' '; }       }        $combo.append(options); }   if (typeof select === 'string') { $.get(mw.util.getUrl(select, {action: 'raw'})) .done(function (data) {           render(data.split(/\r\n|\n|\r/));        }); } else if (Array.isArray(select)) { render(flatten(select)); } });

/* Clock */ window.DisplayClockJS = '%X %x [%{Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday}w] (UTC)'; /* Last edit header */ window.lastEdited = { avatar: true, size: false, diff: true, comment: true, time: 'timeago', namespaces: { include: [], exclude: [] },   pages: [] };

/** * Ajax Page Rename * Allows the user to quickly rename a page without having to load Special:MovePage * https://community.wikia.com/wiki/User:Cörey */ (function($, mw) {   var config = mw.config.get([ 'wgPageName' ]),   $list = $('.page-header__contribution-buttons .wds-list');    if(!$list.find('#ca-move').exists || window.AjaxRenameLoaded) {        return;    }    window.AjaxRenameLoaded = true;    importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });   var token = mw.user.tokens.get('editToken'), i18n, api;    function init(res) {        i18n = res;        $list.append( $('<li>').append(               $('', { href: '#', id: 'ajax-rename' })               .text(i18n.msg('button').plain)                .click(renamePage)            ) );   }    function renamePage {        i18n.useContentLang;        var defaultReason = i18n.msg('default-reason').plain;        i18n.useUserLang;        var newName = prompt(i18n.msg('target-prompt').plain, '');        if (newName === null) {            return;        }        var moveReason = prompt(i18n.msg('reason-prompt').plain, defaultReason);        if (moveReason === null) {            return;        }        api.post({ action: 'move', from: config.wgPageName, to: newName, movesubpages: '', movetalk: '', reason: moveReason, token: token }).done(function(d) { if (d.error) { alert(i18n.msg('error', d.error.code).plain); } else { alert(i18n.msg('success', config.wgPageName, newName).plain); location.reload(true); }       }).fail(function { alert(i18n.msg('error', i18n.msg('ajax-error').plain).plain); });   }    mw.loader.using('mediawiki.api').then(function { api = new mw.Api; mw.hook('dev.i18n').add(function (i18no) {           i18no.loadMessages('AjaxRename').done(init);        }); }); })(this.jQuery, this.mediaWiki);