User:Tim H/global.js

/* --- Disables InfoboxBuilder, defaults instead to source editor --- */ if( $('.template-classification-type-text').data('type') == 'infobox' ) { $('#ca-edit').attr('href', function(a) {          return this.href + '&useeditor=source';         }); }   if(window.location.pathname.indexOf('InfoboxBuilder') != -1) { var template = window.location.pathname.split('InfoboxBuilder/')[1]; location.replace(document.URL.replace(window.location.href.split('/wiki/')[1], 'Template:' + template + '?action=edit&useeditor=source')); }

/** * Ajax Batch Delete * @description Delete listed multiple pages * Does not need to go to Special:BlankPage to use * Includes the option to protect after deleting * Includes the option to grab a whole category's contents * @author Ozank Cx */ mw.loader.using(['mediawiki.api','mediawiki.util'], function {   'use strict';    if ( window.AjaxBatchDeleteLoaded || !/sysop|vstf|staff|helper|content-volunteer|content-moderator/.test(mw.config.get('wgUserGroups').join) ) {       return;    }    window.AjaxBatchDeleteLoaded = true;    var api = new mw.Api, i18n, formHtml;    function click {        $.showCustomModal(i18n.msg('modalTitle').escape, formHtml, { id: 'form-mass-delete', width: 500, buttons: [{ message: i18n.msg('close').escape, handler: function { $('#form-mass-delete').closeModal; }           }, {                message: i18n.msg('addCategoryContents').escape, defaultButton: true, handler: addCategoryContents }, {               id: 'startButton', message: i18n.msg('initiate').escape, defaultButton: true, handler: init }]       });    }    function init {        var txt = document.getElementById('text-mass-delete'),            deleteReason = document.getElementById('delete-reason').value,            pages = txt.value.split('\n'),            currentPage = pages[0];        if (!deleteReason) {            alert(i18n.msg('stateReason').plain);            return;        }        document.getElementById('startButton').setAttribute('disabled', 'disabled');        if (!currentPage) {            document.getElementById('startButton').removeAttribute('disabled');            $.showCustomModal(i18n.msg('endTitle').escape, i18n.msg('endMsg').escape, { id: 'mass-delete-complete', width: 200, buttons: [{ message: i18n.msg('close').escape, defaultButton: true, handler: function { $('#mass-delete-complete').closeModal; }               }]            });        } else {            process(currentPage, deleteReason);        }        pages = pages.slice(1,pages.length);        txt.value = pages.join('\n');    }    function addCategoryContents {        var category = prompt(i18n.msg('enterCategory').plain + ':');        api.get({ action: 'query', list: 'categorymembers', cmtitle: 'Category:' + category, cmlimit: 5000 }).done(function(d) { if (!d.error) { var data = d.query; for (var i in data.categorymembers) { $('#text-mass-delete').append(data.categorymembers[i].title + '\n'); }           } else { outputError('GetContents', category, d.error.code); }       }).fail(function { outputError('GetContents', category, i18n.msg('ajaxError').plain); });   }    function outputError(error, param1, param2) {        $('#text-error-output').append(i18n.msg('error' + error, param1, param2).escape, ' ');   }    function process(page,reason) {        var token = mw.user.tokens.get('editToken');        api.post({ action: 'delete', watchlist: 'nochange', title: page, reason: reason, token: token, bot: true }).done(function(d) { if (!d.error) { console.log(i18n.msg('deleteSuccess', page).plain); if (document.getElementById('protect-check').checked) { api.post({                       action: 'protect',                        expiry: 'infinite',                        protections: 'create=sysop',                        watchlist: 'nochange',                        title: page,                        reason: reason,                        token: token                    }).done(function(d) {                        if (!d.error) {                            console.log(i18n.msg('protectSuccess', page).plain);                        } else {                            console.log(i18n.msg('errorProtect', page, d.error.code).plain);                            outputError('Protect', page, d.error.code);                        }                    }).fail(function {                        console.log(i18n.msg('errorProtect', page, i18n.ajaxError).plain);                        outputError('Protect', page, i18n.msg('ajaxError').plain); });               }            } else {                console.log(i18n.msg('errorDelete', page, d.error.code).plain);                outputError('Delete', page, d.error.code);            }        }).fail(function {            console.log(i18n.msg('errorDelete', page, i18n.msg('ajaxError').plain).plain);            outputError('Delete', page, i18n.msg('ajaxError').plain);        }); setTimeout(init, window.batchDeleteDelay || 10); }   mw.hook('dev.i18n').add(function(i18no) {        i18no.loadMessages('AjaxBatchDelete').done(function(i18nData) { i18n = i18nData; formHtml = $(' ', {                   'class': 'WikiaForm'                }).append(                    $(' ').append( $(' ').append(                           $(' ', { 'for': 'delete-reason', text: i18n.msg('inputReason').plain }),                           $(' ', {                                type: 'text', name: 'delete-reason', id: 'delete-reason' }),                           $(' '),                            $(' ', {                                'for': 'protect-check', text: i18n.msg('inputProtect').plain }),                           $(' ', {                                type: 'checkbox', id: 'protect-check', name: 'protect-check' })                       ),                        $(' ', {                            text: i18n.msg('inputPages').plain + ':'                        }), $(' ', {                           id: 'text-mass-delete'                        }), $(' ', {                           text: i18n.msg('errorsForm').plain + ':'                        }), $(' ', {                           id: 'text-error-output'                        }) )               ).prop('outerHTML'); // Add link $('#my-tools-menu').prepend(                   $('').append( $('', {                           id: 't-bd',                            text: i18n.msg('toolsTitle').plain                        }) )               );            $('#t-bd').click(click); });   });    importArticles(        {            type: 'script',            articles: [ 'u:dev:MediaWiki:I18n-js/code.js' ]        },        {            type: 'style',            articles: [ 'u:dev:MediaWiki:AjaxBatchDelete.css' ]        }    ); });