User:GethN7/common.js

importScriptPage('MediaWiki:AjaxUndo/code.js', 'dev'); importArticles({   type: 'script',    articles: [        'u:dev:AjaxRC/code.js',    ] });

window.fdButtons = []; window.fdButtons.push(   {        summary: 'Housekeeping',        label: 'HK'    },    {        summary: 'Vandalism',        label: 'V'    },    {        summary: 'Spam',        label: 'S'    } );

importArticles({   type: 'script',    articles: [        'u:dev:FastDelete/code.js',    ] });

importArticles({   type: 'script',    articles: [        'u:dev:AjaxThreadDelete/code.js',    ] });

importArticles({   type: 'script',    articles: [        'u:dev:QuickToolsv2/code.js'    ] });

importArticles({   type: 'script',    articles: [        'u:dev:AjaxBatchDelete/code.js',    ] });

/** * AjaxDelete * * Allows to delete pages (through ?action=delete links) without leaving the current page. * Supports deleting revisions and restoring pages (does not support restoring individual revisions) * For personal use * @author Dorumin * @author KockaAdmiralac */ mw.loader.using(['mediawiki.api', 'mediawiki.Title']).then(function {   'use strict';    var config = mw.config.get([ 'wgArticlePath', 'wgContentLanguage', 'wgFormattedNamespaces', 'wgUserGroups' ]);   if ( window.AjaxDeleteLoaded || !/sysop|content-moderator|vstf|staff|helper/.test(config.wgUserGroups.join) ) {       return;    }    window.AjaxDeleteLoaded = true;    if (!window.dev || !window.dev.i18n) {        importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });   }    var AjaxDelete = {        config: window.AjaxDelete || {},        undelete: ['Undelete'],        init: function(i18n) {            this.i18n = i18n;            this.acw = typeof this.config.autoCheckWatch === 'undefined' ? true : this.config.autoCheckWatch;            this.api = new mw.Api;            this.buildDeleteReasons;            this.fetchUndeleteAliases;            $(document).click($.proxy(this.click, this));        },        buildDeleteReasons: function {            var dr = this.config.deleteReasons,                idr = this.config.imageDeleteReasons;            this.reasons = [, ];            if (!dr || !idr) {                this.fetchDeleteReasons;            }            if (dr) {                this.reasons[0] = this.makeReasonsHTML1(dr);            }            if (idr) {                this.reasons[1] = this.makeReasonsHTML1(idr);            } },       fetchUndeleteAliases: function { this.api.get({               action: 'query',                meta: 'siteinfo',                siprop: 'specialpagealiases'            }).done($.proxy(this.cbAliasFetch, this)); },       fetchDeleteReasons: function { this.api.get({               action: 'query',                meta: 'allmessages',                ammessages: 'deletereason-dropdown|filedelete-reason-dropdown',                amlang: config.wgContentLanguage            }).done($.proxy(this.cbFetch, this)); },       cbFetch: function(d) { if (d.error) { console.error(this.msg('errorfetch') + ': ' + d.error.code); return; }           var am = d.query.allmessages; this.makeReasonsHTML2(am, 0); this.makeReasonsHTML2(am, 1); },       cbAliasFetch: function(d) { var aliases = d.query.specialpagealiases; for (var i in aliases) { if (aliases[i].realname == 'Undelete') { this.undelete = aliases[i].aliases; }           }        },        makeReasonsHTML: function { return $(' ', {               id: 'AjaxDeleteReasonSelect'            }).append(                $(' ', { value: 'other', text: 'Other reason' })           );        },        makeReasonsHTML1: function(obj) { var $select = this.makeReasonsHTML; // Don't use $.each or $.map here because if the // user specifies a "length" parameter in the configuration // and some other stuff jQuery will interpret it           // as an array and bad things can happen for (var i in obj) { $select.append(                   $(' ', { value: i,                       text: obj[i] })               );            }            return $select; },       makeReasonsHTML2: function(obj, index) { if (this.reasons[index]) { return; }           var $select = this.makeReasonsHTML; obj[index]['*'].trim.split('\n').forEach(function(line) {               line = line.trim; // In case of \r or something dumb                if (line.charAt(1) === '*') {                    var text = line.substring(2).trim;                    $select.append( $(' ', {                           value: text,                            text: text                        }) );               } else if (line.charAt(0) === '*') {                    $select.append( $(' ', {                           label: line.substring(1).trim                        }) );               }            });            this.reasons[index] = $select; },       click: function(e) { var $target = $(e.target); if (               e.ctrlKey || e.shiftKey ||                !$target.is('a[href]') ||                $('[data-tab-body="about"]').html === ''            ) { return; }           var url = new mw.Uri($target.attr('href')); if (!$target.is('.ignoreAjDel') && !$('#AjaxUndeleteModal').exists) { if (url.query.action === 'delete') { e.preventDefault; this.doDelete(url, $target); } else if (this.isUndelete(url)) { e.preventDefault; this.doUndelete(url, $target); }           }        },        isUndelete: function(url) { return this.undelete.some(function(alias) {               return url.path.indexOf(mw.util.getUrl('Special:' + alias + '/')) === 0 ||                url.path === mw.util.getUrl('Special:' + alias) &&                url.query.target;            }) && !this.config.noUndelete && // URLs on undeletion history should not open the modal !url.query.timestamp; },       doDelete: function(url, $target) { this.action = 'delete'; var isImg = $target.is('a'), isRevImg = url.query.oldimage ? url.query.oldimage : false, page = decodeURIComponent(url.path).replace(config.wgArticlePath.replace('$1', ), ).replace(/_/g, ' '), text = isImg ? isRevImg ? this.i18n.msg('deleteimgrev', isRevImg.split('!')[0], page) : this.i18n.msg('deleteimg', page.replace('File:', '')) : this.i18n.msg('deletepage', page); this.page = page; this.rev = isRevImg; this.showModal([               $(' ', { id: 'AjaxDeleteText', text: text.plain }),               $(' ', {                    id: 'AjaxDeleteReasonLabel', 'for': 'AjaxDeleteReasonSelect', text: this.msg('reason') + ' ' }),               this.reasons[Number(isImg)],                $(' '),                $(' ', { id: 'AjaxDeleteCustomReason', type: 'text' }).attr('size', 50),               $(' '),                $(' ', { id: 'AjaxDeleteWatch', type: 'checkbox' }),               $(' ', {                    'for': 'AjaxDeleteWatch', id: 'AjaxDeleteWatchLabel', text: this.msg('watch') })           ]);            console.log(this.acw, $('#AjaxDeleteWatch').exists); $('#AjaxDeleteWatch').prop('checked', this.acw); },       capAction: function { return this.action.charAt(0).toUpperCase + this.action.substring(1); },       showModal: function(elements) { var cap = this.capAction; $.showCustomModal(               this.i18n.msg('title-' + this.action, this.page).escape,                $(' ').append(elements).html,                {                    id: 'Ajax' + cap + 'Modal',                    buttons: [                        {                            id: 'Ajax' + cap + 'Button',                            defaultButton: true,                            message: this.i18n.msg(this.action).escape,                            handler: $.proxy(this['handle' + cap], this)                        },                        {                            id: 'Ajax' + cap + 'CancelButton',                            defaultButton: true,                            message: this.i18n.msg('cancel').escape,                            handler: $.proxy(this.close, this)                        }                    ]                }            ); },       handleDelete: function { var customReason = $('#AjaxDeleteCustomReason').val, selectedReason = $('#AjaxDeleteReasonSelect').val; this.apiCall(               selectedReason === 'other' ?                    customReason :                    customReason ?                        selectedReason + ': ' + customReason :                        selectedReason,                $('#AjaxDeleteWatch').prop('checked')            ); this.close; },       apiCall: function(reason, watchlist) { var params = { action: this.action, bot: true, reason: reason, title: this.page, token: mw.user.tokens.get('editToken') };           if (this.rev) { params.oldimage = this.rev; }           if (watchlist) { params.watchlist = 'watch'; }           this.api.post(params).done($.proxy(this.cbDone, this)).fail($.proxy(this.cbFail, this)); },       cbDone: function(d) { if (d.error) { this.banner('error', d.error.code); } else { this.banner('confirm'); }       },        cbFail: function { this.banner('error', 'ajax'); },       banner: function(type, code) { var msg = this.action; if (this.rev) { msg += 'rev'; }           msg = this.i18n.msg(type + msg, this.page).parse + ' '; if (code === 'ajax') { msg += $('', {                   href: this.action === 'delete' ?                        mw.util.getUrl(this.page, { action: 'delete' }) :                       mw.util.getUrl('Special:Undelete/' + this.page),                    text: this.msg('retry')                }).prop('outerHTML'); } else if (code) { msg += ' (' + code + ')'; }           new BannerNotification(msg, type).show; },       close: function { $('#Ajax' + this.capAction + 'Modal').closeModal; },       doUndelete: function(url) { this.action = 'undelete'; if (url.query.target) { this.page = url.query.target .replace(/_/g, ' '); } else { this.page = decodeURIComponent(url.path) .replace(/_/g, ' '); this.undelete.forEach(function(alias) {                   this.page = this.page                        .replace(mw.util.getUrl('Special:' + alias + '/'), '');                }); }           this.showModal([                $(' ', { id: 'AjaxDeleteText', html: this.i18n.msg('undeletepage', this.page).parse }),               $(' ', {                    id: 'AjaxUndeleteReason', type: 'text' }).attr('size', 40)           ]); },       handleUndelete: function { this.apiCall($('#AjaxUndeleteReason').val.trim); this.close; },       msg: function(code) { return this.i18n.msg(code).plain; }   };    mw.hook('dev.i18n').add(function(i18no) {        i18no.loadMessages('AjaxDelete').then( $.proxy(AjaxDelete.init, AjaxDelete) );   }); });

importArticles({   type: 'script',    articles: [        'u:dev:AjaxCommentDelete/code.js',    ] });