MediaWiki:BotManagement.js

/** * @Name           BotManagement * @Version        v1.0 * @Author         TheGoldenPatrik1 * @Description    Adds tools for users who can flag themselves as bots. */ (function {   // Get config    var config = mw.config.get([ 'wgUserGroups', 'wgUserName' ]);   // Load protection    if ( !/bot|vstf|bureaucrat|sysop|staff|helper/.test(config.wgUserGroups.join) || window.BotManagementLoaded ) {       return;    }    window.BotManagementLoaded = true;    // Main function    function init(i18n) {        // Variables        var Api = new mw.Api,            isBot = config.wgUserGroups.indexOf('bot') !== -1;        // Click function        function click {            // Confirm            if ( !confirm(                   i18n.msg('confirm').plain                ) ) {               return;            }            // Perform the action            // Based on WHAM            Api.get({ action: 'query', list: 'users', ustoken: 'userrights', ususers: config.wgUserName }).done(function(data) { var params = { action: 'userrights', user: config.wgUserName, reason: i18n .inContentLang .msg(                           isBot ?                            window.BotManagementRemove || 'removeReason' :                            window.BotManagementAdd || 'addReason'                            ) .plain, bot: true, token: data.query.users[0].userrightstoken };               params[isBot ? 'remove' : 'add'] = 'bot'; Api.post(params).done(function(d) {                   if (d.error) {                        new BannerNotification( i18n.msg('error').plain, 'error' ).show;                   } else {                        location.reload(true);                    }                }); });       }        // Tools link        $('#my-tools-menu').prepend( $('', {               'class': 'custom'            }).append(                $('', { href: '#', text: i18n.msg(isBot ? 'remove' : 'add').plain, click: click })           )        );        // Notification if the user is a bot        // Based on WikiaNotification        if (isBot) {            var $notificationArea = $('#WikiaNotifications'),                hasNotifications = $notificationArea.length ? 1 : 0,                notif =                $('', { 'class': 'custom-botmessage' }).append( $(' ').append(                       $(' ', { text: i18n.msg('notifText').plain }).append( $('', {                               href: '#',                                text: i18n.msg('notifLink').plain,                                click: click                            }) )                   )                );            if (hasNotifications) {                $notificationArea.append(notif);            } else {                $('body')                .addClass('notifications')                .append( $('', {                       id: 'WikiaNotifications',                        'class': 'WikiaNotifications'                    }).append(notif) );           }        }    }    // Load script	mw.hook('dev.i18n').add(function(i18n) { i18n.loadMessages('BotManagement').then(init); });	// Import	importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' }); });