User:Veralann/common.js

if ( wgPageName === "User:HyperFlash Studios", "Message Wall:HyperFlash Studios", "User blog:HyperFlash Studios", "Special:Contributions/HyperFlash Studios") { importStylesheet('User:HyperFlash Studios/Test.css'); } importArticles({   type: 'script',    articles: [        'u:dev:PageRenameAuto-update/code.js',    ] });

/** * Name:           AjaxThreadDelete * Version:        v1.1 * Author(s):      KockaAdmiralac <1405223@gmail.com> * Description:    Allows deleting threads without leaving the page. */ $(function {   var n = mw.config.get('wgNamespaceNumber'), ids = mw.config.get('wgNamespaceIds');    if(n !== ids.thread && n !== ids.board_thread) return;    $.get("/load.php", { mode: "articles", articles: "u:kocka:MediaWiki:Custom-plugin-i18n/AjaxThreadDelete.json", only: "styles" }, function(d) {       var i18n = JSON.parse(d.replace(/\/\*.*\*\//g, "")), AjaxThreadDeleteApiInterval = setInterval(function       {            if(typeof mw !== 'undefined' && typeof mw.Api !== 'undefined')            {                clearInterval(AjaxThreadDeleteApiInterval);                var lang = mw.config.get('wgUserLanguage'),                    langConfig = i18n[i18n[lang] ? lang : "en"];                if(typeof langConfig === 'string') langConfig = i18n[langConfig];                doStuff(langConfig);            }        }, 100); });   function doStuff(i18n)    {        /**         * Main object         */        var AjaxThreadDelete = {            // MediaWiki API object            api: new mw.Api,            // Configuration            config: $.extend({ // Deletion reason reason: "Cleanup" }, window.AjaxThreadDeleteConfig),           // Internationalization data            i18n: $.extend(i18n, window.AjaxThreadDeleteVocab),            /**             * The initializing function             * Inserts the "Delete" buttons into appropriate places             */            init: function            {                var el = "" + this.i18n.deleteText + "",                    oasis = (skin === "oasis"),                    selector = ".message-main ." + (oasis ? "WikiaMenuElement" : "tools");               if(oasis) el = $("").append(el).prop("outerHTML");                $(selector).append(el);                $(selector + " .AjaxThreadDeleteButton").click(function(e) {                   var id = $(e.currentTarget).closest(".SpeechBubble").data.id; if(this.config.fastDelete) this.deleteThread(id); else this.showModal(id); }.bind(this));           },            /**             * Deletes a thread, if it's an original post, every child post of it, too.             * @param [Number] id - The iD of the thread to delete             */            deleteThread: function(id)            {                if($(".SpeechBubble[data-id='" + id + "']").hasClass("message-main"))                    $(".SpeechBubble.message-main").find(".SpeechBubble").each(function(a, b)                    { var cid = $(b).data.id; if(cid) this.deleteThreadBase(cid); }.bind(this));               this.deleteThreadBase(id);            },            /**             * Method for deleting a thread with specified iD             * @param [Number] id - The iD of the thread to delete             */            deleteThreadBase: function(id)            {                this.api.post({ action: 'delete', pageid: id, reason: this.config.reason, bot: true, token: mw.user.tokens.get('editToken') }).done(function(d) {                   if(d.error) new BannerNotification(this.i18n.fail + ": " + d.error.code, 'error').show; else $("[data-id=" + id + "]").slideToggle; }.bind(this)).fail(function(d) { new BannerNotification(this.i18n.fail, 'error').show; }.bind(this));           },            /**             * Shows a confirmation modal before deleting a thread             * @param [Number] id - The iD of the thread to delete             */            showModal: function(id)            {                $.showCustomModal(this.i18n.modalTitle, " " + this.i18n.helpText + " ", { id: "AjaxThreadDeleteModal", buttons: [{ id: "AjaxThreadDeleteDeleteButton", defaultButton: true, message: this.i18n.deleteText, handler: function {                           this.deleteThread(id); $("#AjaxThreadDeleteModal").closeModal; }.bind(this) },                   {                        id: "AjaxThreadDeleteCloseButton", defaultButton: true, message: this.i18n.close, handler: function { $("#AjaxThreadDeleteModal").closeModal; } }]               });            }        };        // Initialize        AjaxThreadDelete.init;    } });

/* mw.loader.using('mediawiki.api', function { var ug = mw.config.get("wgUserGroups");  if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions" && (ug.indexOf('rollback') + ug.indexOf('content-moderator') + ug.indexOf('threadmoderator') + ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') > -7)) { /*     var walls = [         "Message Wall",         // en        "Nachrichtenseite",     // de		"Muro",                 // es        "Viestiseinä",          // fi        "Mur",                  // fr        "Üzenőfal",             // hu        "Bacheca",              // it        "メッセージ ウォール",  // ja        "메시지_담벼락",        // ko        "Prikbord",             // nl        "Tablica wiadomości",   // pl        "Mural de mensagens",   // pt, pt-br        "Стіна обговорення",    // uk        "Стена обсуждения",     // ru        "Tường tin nhắn",       // vi        "留言墙"                // zh    ], username = mw.config.get("wgPageName").split("/")[1], token = mw.user.tokens.get("editToken"), delay = window.WHAMDelay || 100, deleteReason, duration, blockReason, deleteArray, Api = new mw.Api, revDel = 0; if ($('.mw-revdelundel-link').length) revDel = 1; $("#contentSub").append(' Quick Tools'); $('#contribs-wham').click(function {     $.showCustomModal('WHAM!', '', { id: 'form-main', width: 660, buttons: [{ message: 'Delete all pages', defaultButton: true, handler: function { doDelete; }	       },{		           message: 'Delete selected', defaultButton: true, handler: function { startSelectiveDelete; }       },{		           message: 'Rollback all edits', defaultButton: true, handler: function { doRollback; }       },{		           message: 'Quick block', defaultButton: true, handler: function { doBlock; }       },{		           message: 'All of the options', defaultButton: true, handler: function { doBlock; if (!duration || !blockReason) return; doDelete; if (!deleteReason) return; doRollback; }       },{          message: 'Cancel', id: 'close-wham' }]     });      mw.util.addCSS('.modalWrapper .modalContent .modalToolbar {text-align:left;}');      $('#close-wham').after(' ');      $('#close-wham,.close').click(function { $('#form-main').closeModal; location.reload; });     //Bot button      if (window.WHAMBotMe == true || ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') + indexOf('content-moderator') > -4) {        $('#form-main .modalContent div .modalToolbar .wikia-button:nth-child(5)').after('Bot me');        $('#form-main').css('width','800px');        if (ug.indexOf('bot') != -1)          $('#wham-bot').text('Unbot me');        $('#wham-bot').click(function { var user = mw.config.get('wgUserName'); $.getJSON("/api.php?action=query&list=users&ustoken=userrights&ususers=" + user + "&format=json", function(token) {           var config = {                action: 'userrights',                user: user,                add: 'bot',		reason: window.WHAMBotReason || 'Cleanup',		bot: true,	        token: token.query.users[0].userrightstoken            };            if ($('#wham-bot').text == "Bot me") {	      $('#wham-bot').text('Unbot me');	    } else {	      config.remove = config.add;	      delete config.add;	      $('#wham-bot').text('Bot me');		              }	    Api.post(config)            .done(function(d) { if (!d.error) { console.log('Bot status changed!'); } else { console.log('Failed to change bot status: '+ d.error.code); }           })            .fail(function { console.log('Failed to change bot status!'); });         });	});      }    });    function apiDelete(page,reason) { Api.post({     action: 'delete',      title: page,      reason: reason,      bot: true,      token: token      }) .done(function(d) {        if (!d.error) {          console.log('Deletion of '+page+' successful!');        } else {          console.log('Failed to delete '+page+': '+ d.error.code);        }      }) .fail(function {       console.log('Failed to delete '+page+'!');      }); }   function doRollback { $('.mw-rollback-link a').each(function(i) {       var href = $(this).attr('href') + "&bot=1";        setTimeout(function { $.get(href); if ($('.mw-rollback-link a').length > 0) $('#status-wham').html('Rollbacking... please wait '); if (i === $('.mw-rollback-link a').length - 1) $('#status-wham').html('Rollbacks complete!'); }, i*delay);     }); }   function doDelete { deleteReason = prompt('Please enter the delete reason','cleanup'); if (!deleteReason) return; deleteArray = []; $('#mw-content-text ul li').each(function {       var title = $(this).children('a').first.attr('title');	if (title.split('-').length == 1 || title.split('/@comment').length == 1) return;           deleteArray.push(title);      }); $('li .newpage ~ a').each(function {       var title = $(this).attr('title');        if (walls.indexOf(title.split(':')[0]) !== -1 || (title.split(':')[0] === "Thread" && title.split(':')[1].length < 8)) return;          deleteArray.push(title);      }); if (deleteArray) { $.each(deleteArray, function(i,v) {         setTimeout(function { $('#status-wham').html('Deleting... please wait '); apiDelete(v,deleteReason); if (i === deleteArray.length - 1) $('#status-wham').html('Deletions complete!'); }, i*delay);       }); }   }    function doBlock { duration = prompt('Please state the block duration','2 weeks'); if (!duration) return; blockReason = prompt('Please state the block reason','Vandalism'); 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) {          console.log(username+' has been blocked successfully!');        }         else {          alert('Failed to block '+username+': '+ d.error.code);        }      }) .fail(function {       alert('Failed to block '+username+'!');      }); }   function startSelectiveDelete { var chk = ' '; $('#form-main').closeModal; if ($('#btn-wham-del').length && $('#btn-wham-check').length) return; $('#mw-content-text').find('ul').last.before('Delete Selected Check All'); $('li .newpage ~ a').each(function {       if (!$(this).parent.find('input').length)          $(this).parent.prepend(chk);      }); $('#mw-content-text ul li').each(function {       var title = $(this).children('a').first.attr('title');	if (title.split('-').length != 1 && title.split('/@comment').length != 1 && !$(this).find('input').length && title.split(username) != -1)          $(this).prepend(chk);	      }); $('#btn-wham-del').click(function {       var deleteReason = prompt('Please enter the delete reason','cleanup');        if (!deleteReason) return;        $('.selectiveDel').each(function { var chkObj = $(this); if (revDel == 0) { var title = $(this).parent.find('a').first.attr('title'); }         else { var title = $(this).parent.children('a').eq(0).attr('title'); }         if (chkObj.attr('Checked') && walls.indexOf(title.split(':')[0]) == -1) { apiDelete(title,deleteReason); $(this).parent.css({'color':'grey','text-decoration':'line-through'}).children.removeAttr('href').css({'color':'grey','text-decoration':'line-through'}); }       });        setTimeout((function{          location.reload;        }), 5000);      }); $('#btn-wham-check').click(function {       var btn = $(this);        if (btn.text == 'Uncheck All') {          $('.selectiveDel').each(function { var chkObj = $(this); if (chkObj.attr('checked')) chkObj.removeAttr('checked'); });         btn.text('Check All');        }        else {          $('.selectiveDel').each(function { var chkObj = $(this); if (!chkObj.attr('checked')) chkObj.attr('checked','checked'); });         btn.text('Uncheck All');         }      }); } } });
 * 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" - http://dev.wikia.com/wiki/WHAM/code.js
 * @author Ozank Cx
 * @TODO i18n
 * Message wall equivalents list, used to prevent deletion of message walls (causes glitches and not necessary)
 * Acquired from https://github.com/Wikia/app/blob/a0c00a44254d958fcd06514b12cb6b75c88da9c0/extensions/wikia/Wall/Wall.namespaces.php