MediaWiki:FixAdminKick/code.js

/* if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat') return; var main = { init: function { var chatUniqueString = mw.config.get('wgCityId') + "9586094684058490483905805934850986098709568790580980938059835098306968069870796890809870348730573057035370583708"; //chat-specific long string // Send the kick message to everyone in chat mainRoom.model.chats.bind('afteradd', function (child) {           if (main.oldUsers.findByName(child.attributes.name) && main.oldUsers.findByName(child.attributes.name).attributes.canPromoteModerator && child.attributes.text.slice(0, chatUniqueString.length) == chatUniqueString) {                main.oldUsers.findByName(child.attributes.name).attributes.canPromoteModerator = false; // prevent double kicking                var kicked = child.attributes.text.split(' ')[1];                var kicker = child.attributes.name;                var inline = main.kickMessage.replace(/\$1/g, kicked).replace(/\$2/g, kicker);                var chatUL = mainRoom.viewDiscussion.chatUL;                $('#entry-' + child.cid).remove;                chatUL.children('.inline-alert').last.html(inline);            }        }); // Exit if you're not an admin if (mw.config.get('wgUserGroups').indexOf('sysop') === -1) return; //Add CSS mw.util.addCSS('.UserStatsMenu .actions ul li.admin-kick .icon {background-position: -428px 0px;}'); // Attach the admin kick over the existing one mainRoom.viewUsers.bind('mainListClick', function(e) {           var interval = setInterval(function { if (mainRoom.model.users.findByName(e.name) && !mainRoom.model.users.findByName(e.name).attributes.canPromoteModerator) clearInterval(interval); if ($('.admin-actions').children.length == 2) { //when the actions against another admin is present the number of child elements is 2 clearInterval(interval); $('.admin-actions .kick').removeClass('kick').addClass('admin-kick').click(function {                       main.oldUsers = mainRoom.model.users;                        $('.UserStatsMenu[style*="display: block;"]').remove;                        main.kickAdmin(e.name);                        main.sendKickMessage(chatUniqueString + ' ' + e.name);                    }); }           }, 1);            setTimeout(function { clearInterval(interval); }, 3000);       });    },    kickAdmin: function(userToKick) { mainRoom.socket.socket.send(new models.BanCommand({ userToBan: userToKick, reason: 'Kicking out of chat' }).xport); },   sendKickMessage: function(msg) { mainRoom.socket.send(new models.ChatEntry({ roomId: this.roomId, name: mw.config.get('wgUserName'), text: msg }).xport); },   kickMessage: '', oldUsers: mainRoom.model.users }; setTimeout(function {   $.getJSON('/api.php?action=query&prop=revisions&rvprop=content&titles=MediaWiki:Chat-user-was-kicked&format=json', function(data) { var page = data.query.pages[Object.keys(data.query.pages)[0]]; if (page.missing == '') main.kickMessage = '$1 has been kicked by $2.'; else main.kickMessage = page.revisions[0]['*']; main.init; }); }, 5000); }) (this.jQuery, this.mediaWiki);
 * FixAdminKick
 * Allows admins to kick other admins in chat
 * @author Ozank Cx
 * Thanks to Dorumin for contributing
 * (function($, mw) {