MediaWiki:AjaxBlock/code.js

// STILL ON TESTING PHASE $(window).load(function {   if (mw.config.get("wgUserGroups").indexOf('sysop') + mw.config.get("wgUserGroups").indexOf('bureaucrat') === -2) return;    var obj = window.ajaxBlock || {};    obj.ajaxBlockExpiryTimes = obj.ajaxBlockExpiryTimes || {        '2 hours': '2 hours',        '1 day': '1 day',        '3 days': '3 days',        '1 week': '1 week',        '2 weeks': '2 weeks',        '1 month': '1 month',        '3 months': '3 months',        '6 months': '6 months',        '1 year': '1 year'    };    obj.ajaxBlockReasons = obj.ajaxBlockReasons || {        'Vandalism': 'Vandalism',        'Spam': 'Spam',        'Sockpuppetry/Ban Evasion': 'Sockpuppetry',        'Removing content/blanking pages': 'Page blanking',        'Inserting false information or nonsense': 'Nonsense',        'Intimidating behaviour/harassment/trolling': 'Troll/Harassment',        'Unacceptable username, avatar, or global masthead': 'Name/avatar', 'Under the legal age': 'COPPA' };   obj.checkCreation = obj.checkCreation || true; obj.checkUserTalk = obj.checkUserTalk || false; obj.checkAutoBlock = obj.checkAutoBlock || true; obj.checkOverride = obj.checkOverride || false; $('a[href^="/wiki/Special:Block/"]').click(function(event) {       if (event.ctrlKey || event.shiftKey) return;        event.preventDefault;        var usr = $(this).attr('href').split('Special:Block/')[1],        token = mw.user.tokens.get('editToken'),        Api = new mw.Api;        $.showCustomModal('Ajax Block: ' + usr, 'Expiry: Other  Reason: Other   Prevent account creation  Prevent from posting on message wall  Block all IPs from this user (AutoBlock)  Override any blocks already in effect ', { id: "ajaxBlockModal", callback: function { if (obj.checkCreation) $('#accountCreation').attr('checked', true); if (obj.checkUserTalk) $('#disableWall').attr('checked', true); if (obj.checkAutoBlock) $('#autoBlock').attr('checked', true); if (obj.checkOverride) $('#overrideBlock').attr('checked', true); var $expirySelect = $('#AjaxBlockExpirySelect'); var $reasonSelect = $('AjaxBlockReasonSelect'); $.each(obj.ajaxBlockExpiryTimes, function(key, value) {                       $expirySelect                        .append($("  ") .attr("value", key) .text(value));                }); $.each(obj.ajaxBlockReasons, function(key, value) {                       $reasonSelect                        .append($("  ") .attr("value", key) .text(value));                }); },           buttons: [{ id: "ajaxBlockBlock", defaultButton: true, message: "Block this user", handler: function{ var blockDuration = ($('#AjaxBlockExpirySelect').val == 'other') ? $('#AjaxBlockCustomExpiry').val : $('#AjaxBlockExpirySelect').val; var blockReason = ($('#AjaxBlockReasonSelect').val == 'other') ? $('#AjaxBlockCustomReason').val : $('#AjaxBlockReasonSelect').val; Api.post({                       action: 'block',                        user: usr,                        expiry: blockDuration,                        nocreate: ($('#accountCreation').is(':checked')) ? true : false,                        autoblock: ($('#autoBlock').is(':checked')) ? true : false,                        reason: blockReason,                        allowusertalk: ($('#disableWall').is(':checked')) ? true : false,                        reblock: ($('#overrideBlock').is(':checked')) ? true : false,                        bot: true,                        token: token                    }); }           },            {                id: "ajaxBlockCancel", defaultButton: true, message: "Cancel", handler: function{ $("#ajaxBlockModal").closeModal; } }]       });    }); });