User:0kkur/global.js

/** * Name:       MultiUploadJS * Author:     Fujimaru-kun * Based on:   MultiUpload (by Gguigui1 and KhangND), Gadget-multiupload.js (by Pcj) * Description: Allows upload of multiple files at the same time */ mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function {    'use strict';    var config = mw.config.get([ 'wgCanonicalSpecialPageName', 'wgUserLanguage', 'wgUserGroups', 'wgVersion' ]);

if (           window.MultiUploadJSLoaded ||            config.wgCanonicalSpecialPageName !== "Upload" ||            $("#wpForReUpload").val || //Disabling for Reupload            !/autoconfirmed/.test(config.wgUserGroups.join)        ) { return; }       window.MultiUploadJSLoaded = true;

var api = new mw.Api, i18n, preloads = 1, token = mw.user.tokens.get('editToken'), files = [], stdmsgs = ['filedesc', 'license-header', 'fileexists-no-change', 'fileexists-duplicate-version', 'verification-error', 'fileexists-shared-forbidden', 'permissiondenied', 'watchthisupload', 'ignorewarnings'].join('|'), limit, curFile = 0;

function preload { if (--preloads === 0) { window.dev.i18n.loadMessages('MultiUpload').then(init); }       }

function init(i18nData) { i18n = i18nData; setLimit;

getMessages; $("#wpUploadFile").parent.parent.addClass("regularFileSelect"); $("tr.regularFileSelect").after('&nbsp  '); $("#mw-htmlform-source > tbody > tr.mw-htmlform-field-UploadSourceField.regularFileSelect").remove; $("#mw-upload-form > fieldset:nth-child(3)").remove; $("#mw-upload-form > span > input.mw-htmlform-submit").remove; $("#mw-upload-form > fieldset:nth-child(2)").hide; $("span.mw-htmlform-submit-buttons").append(''); $("span.mw-htmlform-submit-buttons").append(''); $("#multiupload").change(addFields); $("#multiFileSubmit").click(uploadFiles); $("#multiFileReset").click(reset); }       /*        * Set Maximum number of file the user can import at one time (can be overriden by a config var but its value is capped at 100) */       function setLimit { if (window.MultiUploadoption && window.MultiUploadoption.max) { limit = window.MultiUploadoption.max; } else { limit = -1; }           if (limit < 0 ||                limit > 101 ||                typeof limit !== 'number') { if (/staff|helper|util|bot-global|wiki-manager/.test(config.wgUserGroups.join)) { limit = 200; } else if (/bureaucrat|bot/.test(config.wgUserGroups.join)) { limit = 70; } else if (/sysop/.test(config.wgUserGroups.join)) { limit = 50; } else if (/rollback|content-moderator/.test(config.wgUserGroups.join)) { limit = 30; } else { limit = 20; }           }        }

/*       * Add Fields to change the filename, description and license of each file to DOM */       function addFields { reset; files = $("#multiupload")[0].files; if (files.length <= limit) { for (var index = 0; index < files.length; index++) { var element = files[index]; var filedesc = $("#mw-upload-form > fieldset:nth-child(2)").clone; filedesc.attr("id", "file-" + index); filedesc.children("legend").text(i18n.msg('imagename').escape + index); filedesc.find("#mw-htmlform-description > tbody > tr.mw-htmlform-field-HTMLTextField > td.mw-label > label").attr("for", "wpDestFile" + index); filedesc.find("#mw-htmlform-description > tbody > tr.mw-htmlform-field-HTMLTextAreaField > td.mw-label > label").attr("for", "wpUploadDescription" + index); filedesc.find("#wpDestFile").attr("name", "wpDestFile" + index).attr("id", "wpDestFile" + index).val(element.name); filedesc.find("#wpUploadDescription").attr("name", "wpUploadDescription" + index).attr("id", "wpUploadDescription" + index); filedesc.find("#wpLicense").attr("name", "wpLicense" + index).attr("id", "wpLicense" + index); filedesc.append(" "); filedesc.append(" " + i18n.msg('watchthisupload').escape + " "); filedesc.append(" " + i18n.msg('ignorewarnings').escape + " "); $("#mw-upload-form > span").before(filedesc.show); }           } else { alert(i18n.msg('limit').plain); $("#multiupload").val(""); reset; }       }

/*       * Reset form to its initial state */       function reset { files = []; $("#mw-upload-form > fieldset:nth-child(2) ~ fieldset").remove; }

/*       * Get standard messages for supported errors */       function getMessages { api.get({               action: 'query',                meta: 'allmessages',                amlang: config.wgUserLanguage,                ammessages: stdmsgs            }).then(function (data) {                var msg = data.query.allmessages;                msg.forEach(function (message) { i18n['_messages'][config.wgUserLanguage][message.name] = message['*']; });           });        }

/*        * Initiate uploading process */       function uploadFiles {

if (files.length === 0) { alert(i18n.msg('nofile').plain); return false; } else if (files.length > limit) { alert(i18n.msg('limit').plain); return false; }

$("#firstHeading").text(i18n.msg('uploading').escape); $("#mw-content-text").hide; $(" " + i18n.msg('successful').escape + "  " + i18n.msg('failed').escape + "  ").prependTo("#content"); apiUpload; }       /*        * Make API Requests to upload files */       function apiUpload { if (curFile > files.length) { $(" " + i18n.msg('done').escape + " ").appendTo("#content"); return; }           if (files[curFile] === undefined) { curFile++; apiUpload; return; }           var filename = $("#wpDestFile" + curFile).val || files[curFile].name; var license = $("#wpLicense" + curFile + " option:selected").prop("title") !== " – " ? "== " + i18n.msg('license-header').plain + " ==\n" + $("#wpLicense" + curFile + " option:selected").prop("title") : ""; var description = $("#wpUploadDescription" + curFile).val ? "== " + i18n.msg('filedesc').plain + " ==\n" + $("#wpUploadDescription" + curFile).val : ""; var watch = $("#wpWatchthis" + curFile).is(":checked") ? 'watch' : 'nochange'; var warning = $("#wpIgnoreWarning" + curFile).is(":checked"); var params = { token: token, filename: filename, text: description + "\n" + license, watchlist: watch, ignorewarnings: '1', format: 'json' }           if (!warning) { delete params.ignorewarnings; }

api.upload(files[curFile], params).done(function (d) {               console.log(d);                $("#multiUploadDone").append('<li><a href="' + d.upload.imageinfo.descriptionurl + '" target="_blank">' + d.upload.filename + '</a></li>');                curFile++;                apiUpload;            }).fail(function (d) {                if (!warning || stdmsgs.includes(d)) {                    $("#multiUploadFailed ul").append('<li>' + filename + ': ' + i18n.msg(d,"File:"+filename).parse + '</li>');                    $("#multiUploadFailed").show;                } else {                    $("#multiUploadDone").append('<li>' + filename + ': ' + i18n.msg(d).escape + '</li>');                }                curFile++;                apiUpload;            }); }       mw.hook('dev.i18n').add(preload); importArticles({           type: 'script',            articles: [                'u:dev:MediaWiki:I18n-js/code.js',            ]        }); });

/** * A variant of WHAM with a different modal * Includes functionality to delete forum/message wall threads and selective * deleting of pages, which the original lacks * Original "WHAM" - https://dev.fandom.com/wiki/MediaWiki:WHAM/code.js * @author Ozank Cx */

'use strict';
 * (function($, mw, window) {

mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function {       const config = mw.config.get([ 'wgCanonicalSpecialPageName', 'wgFormattedNamespaces', 'wgPageName', 'wgUserGroups', 'wgUserName', 'wgVersion' ]);       if ( config.wgCanonicalSpecialPageName !== 'Contributions' || !/rollback|content-moderator|threadmoderator|sysop|soap|staff|helper|global-discussions-moderator|wiki-manager|content-team-member/.test(config.wgUserGroups.join) || window.WHAMLoaded ) {           return;        }        window.WHAMLoaded = true;        const isUCP = config.wgVersion !== '1.19.24';

if (!window.dev || !window.dev.i18n) { if (isUCP) { mw.loader.load('https://dev.fandom.com/load.php?mode=articles&only=scripts&articles=MediaWiki:I18n-js/code.js'); }           else { importArticle({                   type: 'script',                    article: 'u:dev:MediaWiki:I18n-js/code.js'                }); }       }        if (isUCP) { mw.loader.load('https://dev.fandom.com/load.php?mode=articles&only=styles&articles=MediaWiki:WHAM.css', 'text/css'); } else { importArticle({               type: 'style',                article: 'u:dev:MediaWiki:WHAM.css'            }); }

const username = config.wgPageName.split('/')[1], token = mw.user.tokens.get(isUCP ? 'csrfToken' : 'editToken'), delay = window.WHAMDelay || 100, progress = '//images.wikia.nocookie.net/common/skins/common/progress-wheel.gif', Api = new mw.Api;

var deleteReason, duration, blockReason, i18n, $button, windowManager, dialog;

function apiDelete(page, reason) { Api.post({               action: 'delete',                title: page,                reason: reason,                bot: true,                token: token            }).done(function(d) {                if (d.error) {                    console.log( i18n.msg('do-delete-fail', page, d.error.code).plain );               } else {                    console.log(i18n.msg('do-delete-success', page).plain);                }            }).fail(function {                console.log( i18n.msg(                       'do-delete-fail',                        page,                        i18n.msg('ajax-error').plain                    ).plain );           });        }

function doRollback { const $links = $('.mw-rollback-link a'), len = $links.length; if (len === 0) { $('#status-wham').text(i18n.msg('do-rollback-done').plain); if (isUCP) dialog.updateSize; }           $links.each(function(i) {                const href = new mw.Uri($(this).attr('href')).extend({ bot: 1 }).toString;               setTimeout(function { $.get(href); $('#status-wham').html(                       i18n.msg('do-rollback-status').escape +                        $(' ', { src: progress }).prop('outerHTML')                   ); if (i === len - 1) { $('#status-wham').text(                           i18n.msg('do-rollback-done').plain                            ); if (isUCP) dialog.updateSize; }               }, i * delay);            }); }

function doDelete { deleteReason = prompt(               i18n.msg('do-delete-reason').plain,                window.WHAMDeleteReason || i18n                    .inContentLang                    .msg('default-delete-reason')                    .plain            ); if (!deleteReason) { return; }           var deleteArray = [];

$('#mw-content-text ul li').each(function {               const $children = $(this).children('a'),                    title = $children.first.attr('title'),                    uri = new mw.Uri($children.eq(1).attr('href'));                if ( // If it's not a thread... !title.match(/\/@comment-/) || (                       // ...or if it's a thread edit...                        title.match(/\/@comment-/) &&                        uri.query.diff === 'prev'                    ) ) {                   // ...don't process it.                    return;                }                deleteArray.push(title);            });

$('li .newpage ~ a').each(function {               const title = new mw.Title($(this).attr('title'));                if ( title.namespace === 1200 || title.namespace === 1201 && title.getNamespacePrefix < 9 ) {                   return;                }                deleteArray.push(title.getPrefixedText);            });

$.each(deleteArray, function(i, v) {               setTimeout(function { $('#status-wham').html(                       i18n.msg('do-delete-status').escape +                        $(' ', { src: progress }).prop('outerHTML')                   ); apiDelete(v, deleteReason); if (i === deleteArray.length - 1) { $('#status-wham').text(i18n.msg('do-delete-done').plain); if (isUCP) dialog.updateSize; }               }, i * delay);            }); }

function doBlock { duration = prompt(               i18n.msg('do-block-duration').plain,                window.WHAMBlockDuration || '2 weeks'            ); if (!duration) { return; }           blockReason = prompt(                i18n.msg('do-block-reason').plain,                window.WHAMBlockReason || i18n                    .inContentLang                    .msg('default-block-reason')                    .plain            ); if (!blockReason) { return; }           Api.post({                action: 'block',                user: username,                expiry: duration,                nocreate: 0,                autoblock: 0,                reason: blockReason,                bot: true,                token: token            }).done(function(d) {                if (d.error) {                    alert( i18n.msg('do-block-fail', username, d.error.code).plain );               } else {                    alert(i18n.msg('do-block-success', username).plain);                }            }).fail(function {                alert( i18n.msg(                       'do-block-fail',                        username,                        i18n.msg('ajax-error').plain                    ).plain );           });        }

function doBot { Api.get({               action: 'query',                list: 'users',                ustoken: 'userrights',                ususers: config.wgUserName,                usprop: 'groups'            }).done(function(data) {                const resp = data.query.users[0];

var params = { action: 'userrights', user: config.wgUserName, reason: window.WHAMBotReason || i18n .inContentLang .msg('default-delete-reason') .plain, bot: true, token: resp.userrightstoken };               params[ resp.groups.indexOf('bot') === -1 ? 'add' : 'remove' ] = 'bot'; Api.post(params).done(function(d) {                   if (d.error) {                        alert(i18n.msg('bot-me-fail', d.error.code).plain);                    } else {                        alert(i18n.msg('bot-me-done').plain);

// Change button label if (params.hasOwnProperty('add')) { $('#wham-bot').text(                               i18n.msg('unbot-me').plain                            ); } else { $('#wham-bot').text(                               i18n.msg('bot-me').plain                            ); }                   }                });            });        }

function doSelectiveDelete { deleteReason = prompt(               i18n.msg('do-delete-reason').plain,                window.WHAMDeleteReason || i18n                    .inContentLang                    .msg('default-delete-reason')                    .plain            ); if (!deleteReason) { return; }           $('.selectiveDel').each(function {                var $this = $(this),                    title = new mw.Title($('.mw-revdelundel-link').length ? $this.parent.children('a').eq(0).attr('title') : $this.parent.find('a').first.attr('title'));               if ($this.prop('checked') && title.namespace !== 1200) {                    apiDelete(title.getPrefixedText, deleteReason);                    $this                        .parent                        .addClass('wham-resolved')                        .children                        .removeAttr('href')                        .addClass('wham-resolved');                }            }); setTimeout(function {               window.location.reload;            }, 5000); }

function checkSelectiveDelete { var $this = $(this), uncheck = $this.text === i18n.msg('selective-delete-uncheck').plain; $('.selectiveDel').each(function {               const chkObj = $(this);                if (uncheck) {                    chkObj.removeAttr('checked');                } else {                    chkObj.attr('checked', 'checked');                }            }); $this.text(               i18n.msg( uncheck ? 'selective-delete-check' : 'selective-delete-uncheck' ).plain           ); }

function startSelectiveDelete { if (isUCP) { dialog.close; }           else { $('#form-main').closeModal; }           if ($('#btn-wham-del').length && $('#btn-wham-check').length) { return; }           const $chk = $(' ', {                'class': 'selectiveDel',                'type': 'checkbox'            }); $('#mw-content-text') .find('ul') .last .before(                   $(isUCP ? ' ' : '<a>', { 'class': 'button', 'id': 'btn-wham-del', 'text': i18n.msg('start-selective-delete').plain }),                   ' ',                    $(isUCP ? ' ' : '<a>', { 'class': 'button', 'id': 'btn-wham-check', 'text': i18n.msg('selective-delete-check').plain })               );

$('li .newpage ~ a').each(function {               if (!$(this).parent.find('input').length) {                    $(this).parent.prepend($chk.clone);                }            });

$('#mw-content-text ul li').each(function {               const $children = $(this).children('a'),                    title = $children.first.attr('title'),                    uri = new mw.Uri($children.eq(1).attr('href'));                if ( // If it's a thread... title.match(/\/@comment-/) && // ...and not a thread edit... uri.query.diff !== 'prev' && // ...and there's no checkbox currently... !$(this).find('input').length ) {                   // ...append it.                    $(this).prepend($chk.clone);                }            }); $('#btn-wham-del').click(doSelectiveDelete); $('#btn-wham-check').click(checkSelectiveDelete); }

function doAll { doBlock; if (duration || blockReason) { doDelete; if ($('.tabs li:first-child a:not(.new), .mw-contributions-user-tools > a:not(.new)').length) { if (confirm(i18n.msg('userpage-delete-confirm').plain)) { apiDelete(config.wgFormattedNamespaces[2] + ':' + username, window.WHAMDeleteReason || i18n.inContentLang.msg('default-delete-reason').plain); }               }                if (deleteReason) { doRollback; }           }        }

function canFlagBot { return /soap|staff|helper|wiki-manager/.test(config.wgUserGroups.join); }

function click { const self = ((username === config.wgUserName) ? true : false), $self_warn_html = $(' ', {                   html: i18n.msg('self-use-warn').parse,                    id: 'wham-self-use-warn',                    class: 'error'                  });

if (isUCP && !windowManager) { function WHAMDialog(config) { WHAMDialog.super.call(this, config); }               OO.inheritClass(WHAMDialog, OO.ui.ProcessDialog); WHAMDialog.static.name = 'WHAM'; WHAMDialog.static.title = i18n.msg('title').escape; WHAMDialog.static.actions = [ { label: i18n.msg('do-delete').escape, flags: ['secondary'], action: 'doDelete' }, { label: i18n.msg('start-selective-delete').escape, flags: ['secondary'], action: 'startSelectiveDelete' }, { label: i18n.msg('do-rollback').escape, flags: ['secondary'], action: 'doRollback' }, { label: i18n.msg('do-block').escape, flags: ['secondary'], action: 'doBlock' }, { label: i18n.msg('do-all').escape, flags: ['secondary'], action: 'doAll' }, { label: i18n.msg('close-wham').escape, flags: ['safe', 'close'] } ];

if (window.WHAMBotMe === true || canFlagBot) { WHAMDialog.static.actions.push({                           label: i18n.msg( config.wgUserGroups.indexOf('bot') === -1 ? 'bot-me' : 'unbot-me' ).plain,                           flags: ['secondary'],                            action: 'doBot'                        }); }

// initialise dialog, append content WHAMDialog.prototype.initialize = function { WHAMDialog.super.prototype.initialize.apply(this, arguments); this.content = new OO.ui.PanelLayout({                       padded: true                    }); this.content.$element.append((self ? $self_warn_html : '')); this.$foot.append(                       $(' ', { id: 'status-wham' }));                   this.$content.addClass('wham-Dialog'); this.$body.append(this.content.$element); };

// Handle actions WHAMDialog.prototype.getActionProcess = function (action) { switch (action) { case 'doDelete': doDelete; break; case 'startSelectiveDelete': startSelectiveDelete; break; case 'doRollback': doRollback; break; case 'doBlock': doBlock; break; case 'doAll': doAll; break; case 'doBot': doBot; break; }                   return WHAMDialog.super.prototype.getActionProcess.call(this, action); };

// Create the Dialog and add the window manager. windowManager = new OO.ui.WindowManager({                   classes: ['wham']                }); $(document.body).append(windowManager.$element); // Create a new dialog window. dialog = new WHAMDialog({                   size: 'medium'                });

// Add window and open windowManager.addWindows([dialog]); windowManager.openWindow(dialog);

// Close dialog when clicked outside the dialog dialog.$frame.parent.on('click', function(e) {                   if (!$(e.target).closest('.wham-Dialog').length) {                        dialog.close;                    }                }); if (self) $(dialog.$content.find('.oo-ui-window-body').show); }           else if (windowManager) { windowManager.openWindow(dialog); }           else { $.showCustomModal(i18n.msg('title').escape, (self ? $self_warn_html : ''), {                   id: 'form-main',                    width: 285,                    height: (self ? 280 : 190),                   buttons: [{                        message: i18n.msg('do-delete').escape,                        defaultButton: true,                        handler: doDelete,                        id: 'wham-delete-all'                    }, {                        message: i18n.msg('start-selective-delete').escape,                        defaultButton: true,                        handler: startSelectiveDelete,                        id: 'wham-selective-delete'                    }, {                        message: i18n.msg('do-rollback').escape,                        defaultButton: true,                        handler: doRollback,                        id: 'wham-rollback'                    }, {                        message: i18n.msg('do-block').escape,                        defaultButton: true,                        handler: doBlock,                        id: 'wham-block' }, {                       message: i18n.msg('do-all').escape, defaultButton: true, handler: doAll, id: 'wham-all' }, {                       message: i18n.msg('close-wham').escape, id: 'close-wham' }]               });                $('#close-wham').after($(' ', {                    id: 'status-wham'                }));                $('#close-wham,.close').click(function { $('#form-main').closeModal; window.location.reload; });           }

// Bot button if (window.WHAMBotMe === true || canFlagBot) { const form = $('#form-main .modalToolbar .wikia-button:nth-child(5)'); $('#form-main .modalToolbar .wikia-button:nth-child(5)').after(                   $('<a>', { 'id': 'wham-bot', 'class': 'wikia-button', 'text': i18n.msg(                           config.wgUserGroups.indexOf('bot') === -1 ?                                'bot-me' :                                'unbot-me'                        ).plain }).click(doBot)               ); }

// Fire the hook to allow customization mw.hook('dev.wham').fire; }

function qlIntegration(QuickLogs) { $button.remove; QuickLogs.addLink('wham', {               click: click,                message: i18n.msg('contribs-wham').plain            }); }

function init(i18no) { i18n = i18no; $button = $('<a>', {               id: 'contribs-wham',                click: click,                title: i18n.msg('contribs-wham-title').plain,                text: i18n.msg('contribs-wham').plain            }); if (isUCP) { $('.mw-contributions-user-tools .mw-changeslist-links').append($(' ').append($button)); } else { $('#contentSub').append(' ', $button); }           mw.hook('QuickLogs.loaded').add(qlIntegration); }

function preload(i18no) { if (isUCP) { $.when(i18no.loadMessages('WHAM'), mw.loader.using(['oojs-ui-windows'])).then(init); } else { i18no.loadMessages('WHAM').then(init); }       }

mw.hook('dev.i18n').add(preload); }); })(jQuery, mediaWiki, window);

dev:AjaxPoll.js