User:Ivancillo/global.js

/* VDA 1.1.1 beta Compatibility: FF 3.5+, IE 7 If you notice that this tool is breaking in a disruptive manner, add ?vda_disable=1 (if the URL does not contain a question mark) or &vda_disable=1 (if it does) to your URL to disable VDA and contact us at vda.wikia.com immediately. Also remember: VDA may not be accepted on all wikis. If the community on a particular wiki decides that VDA should not be used, by all means disable it. If you're unsure, ask another user. importStylesheetPage("MediaWiki:VDA.css", "vda"); importScriptURI("http://trentrichardson.com/Impromptu/scripts/jquery-impromptu.3.0.min.js"); importScriptURI("http://stilbuero.de/jquery/cookie/jquery.cookie.js"); var $_GET = (function {    var vars = {};    location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { vars[decodeURIComponent(key)] = decodeURIComponent(value); });   return vars; }); var VDA = { util: { // Trim string as in PHP trim: function (str) { return str.replace(/^\s+|\s+$/g, ""); },       // Convert CSV to array csv: function (input) { if ((typeof input) === "string") { input = input.split(","); for (var i = 0; i < input.length; i++) { input[i] = VDA.util.trim(input[i]); }           } else if ((typeof input) !== "array") { input = [input]; }           return input; },       // A quick wikilinking function for usernames userLink: function (name) { return "" + name + ""; },       // Prevent IE caching results randomString: function { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var rstring = ''; // We can increase the 10, but at a cost of performance for (var i = 0; i < 10; i++) { var rnum = Math.floor(Math.random * chars.length); rstring += chars.charAt(rnum); }           return rstring; },       // Make an array of users from the history page; useful for revert scripts hist2array: function { if (wgAction !== "history") { return VDA.error("VDA.util.hist2array called on non-history page"); }           var arr = []; $("ul#pagehistory li").each(function {                var oldid = $(this).find("input + a").attr("href");                oldid = oldid.substring(oldid.lastIndexOf("=") + 1);                var username = $(this).find("span.history-user > a").html;                arr.push({ username: username, oldid: oldid });           });            return arr; },       // Get some info necessary for performing a rollback rollback_info: function (histarr) { var username = ""; for (var i = 0; i < histarr.length; i++) { if (i === 0) { username = histarr[i].username; } else if (histarr[i].username !== username) { return {old: histarr[i], username: username}; }           }            return false; // This will only be reached when all the edits were made by the same user }   },    // Logging function entries: [], log: function (str) { if (!!str) { var d = new Date; VDA.entries.push(d + " Log entry: " + str); }       return VDA; },   warn: function (str) { if (!!str) { var d = new Date; VDA.entries.push(d + " Warning: " + str); }       return VDA; },   error: function (str) { if (!!str) { var d = new Date; VDA.entries.push(d + " Error: " + str); }       return VDA; },   show_entries: function  { $.prompt('' + VDA.entries.join("\n") + ' '); },   // Functions to enable/disable VDA enabled: true, enable: function { VDA.enabled = true; return VDA.log("VDA enabled"); },   disable: function  { VDA.enabled = false; return VDA.log("VDA disabled"); },   // Libraries libraries: { // VDA RV ///////////////////////////////////////////////////////////////// RV: { getRVType: function (callback) { $.prompt({                   state0: {                        html: "What best describes the edits which you are reverting?",                        buttons: {                            "Vandalism": "v",                            "Good faith": "gf",                            "Other": "g"                        },                        submit: function (v, m, f) {                            switch (v) {                                case "v":                                    callback({type: "v", message: null});                                    $.prompt.close;                                    break;                                case "gf":                                    $.prompt.goToState("state1");                                    break;                                case "g":                                    $.prompt.goToState("state2");                                    break; }                           return false; }                   },                    state1: { html: 'You are reverting good faith edits. Briefly summarize why you reverted the edits in the box below. Your entry will be used in the VDA edit summary. ', buttons: { Done: true },                       submit: function (v, m, f) { if (f.message_goodfaith) { callback({type: "gf", message: f.message_goodfaith}); $.prompt.close; }                           return false; }                   },                    state2: { html: 'You are reverting edits. Briefly summarize why you reverted the edits in the box below. Your entry will be used in the VDA edit summary. ', buttons: { Done: true },                       submit: function (v, m, f) { if (f.message) { callback({type: "g", message: f.message}); $.prompt.close; }                           return false; }                   }                });            },            rollback: function  {                var histarr = VDA.util.hist2array;                var rv = VDA.util.rollback_info(histarr);                VDA.RV.getRVType(function (r) { switch (r.type) { case "v": VDA.RV.revert(rv.old.oldid, "Reverted vandalism by " + VDA.util.userLink(rv.username) + " back to revision " + rv.old.oldid + " by " + VDA.util.userLink(rv.old.username) + ") (VDA", rv.username); break; case "gf": VDA.RV.revert(rv.old.oldid, "Reverted good faith edits by " + VDA.util.userLink(rv.username) + " back to revision " + rv.old.oldid + " by " + VDA.util.userLink(rv.old.username) + ": " + r.message + ") (VDA", rv.username); break; case "g": VDA.RV.revert(rv.old.oldid, "Reverted edits by " + VDA.util.userLink(rv.username) + " back to revision " + rv.old.oldid + " by " + VDA.util.userLink(rv.old.username) + ": " + r.message + ") (VDA", rv.username); break; }               });            },            histRevert: function (i) {                var histarr = VDA.util.hist2array;                var rv = histarr[i];                VDA.RV.getRVType(function (r) { switch (r.type) { case "v": VDA.RV.revert(rv.oldid, "Reverted vandalism back to revision " + rv.oldid + " by " + VDA.util.userLink(rv.username) + ") (VDA"); break; case "gf": VDA.RV.revert(rv.oldid, "Reverted good faith edits back to revision " + rv.oldid + " by " + VDA.util.userLink(rv.username) + ": " + r.message + ") (VDA"); break; case "g": VDA.RV.revert(rv.oldid, "Reverted edits back to revision " + rv.oldid + " by " + VDA.util.userLink(rv.username) + ": " + r.message + ") (VDA"); break; }               });            },            diffRevert: function  {                var oldid = $_GET.oldid;                var username = $("#mw-diff-otitle2 .mw-userlink").html;                VDA.RV.getRVType(function (r) { switch (r.type) { case "v": VDA.RV.revert(oldid, "Reverted vandalism back to revision " + oldid + " by " + VDA.util.userLink(username) + ") (VDA"); break; case "gf": VDA.RV.revert(oldid, "Reverted good faith edits back to revision " + oldid + " by " + VDA.util.userLink(username) + ": " + r.message + ") (VDA"); break; case "g": VDA.RV.revert(oldid, "Reverted edits back to revision " + oldid + " by " + VDA.util.userLink(username) + ": " + r.message + ") (VDA"); break; }               });            },            revert: function (oldid, msg, user) {                $("body").append($(' Loading, please wait... '));                $.cookie("VDA_RV_status", "reverting", { path: "/" });                if (user) {                    $.cookie("VDA_RV_user", user, { path: "/" });                }                location.href = wgScript + "?title=" + encodeURIComponent(wgTitle) + "&action=edit&oldid=" + oldid + "&useeditor=mediawiki&vda_rv=1&vda_rv_msg=" + encodeURIComponent(msg);            },            init: function  {                if ($.cookie("VDA_RV_status") === "reverted") {                    $.cookie("VDA_RV_status", null, { path: "/" });                    if (VDA.VW) {                        $.prompt("VDA Revert has completed the reversion.", { buttons: ($.cookie("VDA_RV_user")? { OK: true, "Warn vandal": "w" } : { OK: true }), submit: function (v, m, f) { if (v === "w") { VDA.VW.warn($.cookie("VDA_RV_user")); }                               $.cookie("VDA_RV_user", null, { path: "/" }); }                       });                    } else {                        $.prompt("VDA Revert has completed the reversion.");                    }                }                if (wgAction === "history") {                    var content = ' Hover over a revision below and press Revert to revert back to that revision.';                    if (!$_GET.offset) {                        content += '

Rollback'; }                   content += " "; $(content).insertAfter("#mw-history-searchform"); $("ul#pagehistory > li").each(function (i) {                       var content = ' (none) ';                        if (i !== 0) {                            content = 'Revert';                        }                        $(this).append($(' ' + content + ' '));                    }); } else if ($_GET.diff) { $(' Revert back to old revision ').insertBefore("table.diff"); } else if ($_GET.vda_rv) { if (!($(".permissions-errors").length)) { $("body").append($(' Loading, please wait... '));                       $("#new_edit_page_old_revision_notice").hide; $.cookie("VDA_RV_status", "reverted", { path: "/" }); $("input[name=wpSummary]").val(decodeURIComponent($_GET.vda_rv_msg)); $("#editform").submit; } else { $.cookie("VDA_RV_status", null, { path: "/" }); $.prompt("A permissions error has occurred. Make sure you have access to edit this page and you have not been blocked."); }               }            }        },        // END VDA RV ///////////////////////////////////////////////////////////////// // VDA JFF ///////////////////////////////////////////////////////////////// JFF: { tips: [ // Developers: Go ahead, have some fun, add some stuffs "This is the first tip.", "Listen up, everyone! I am a very shy and introverted person.", "ROTFLOLCOPTERS BANNING IT TEH COOLIES.", "I'm so humble, I'm the humblest person in the world.", "I never make misteaks.", "Ajraddatz is a noob. There, I said it!", "I am very proud to have lost the habit of the use of unnecessary words in my speech.", "The cool thing about this sentence is that you never really know that it's useless until it's already too late.", "My grammer and splelling is impeckable!", "I lost the game.", "100% of the population thinks that this sentence is useless.", 'Read the following sentence out loud: "This for is as how do you off keep were an as idiot has busy that for the twenty good five not seconds how." Now read every other word, starting at "this."', "CATS: All your base are belong to us. You have no chance to survive make your time.", "The lack of money is the root of all evil. -- Mark Twain", "Camping is nature's way of promoting the motel business. -- Dave Barry", "We believe that electricity exists, because the electric company keeps sending us bills for it, but we cannot figure out how it travels inside wires. -- Dave Barry", "Don't take life too seriously. You won't come out of it alive.", "This is the last tip." ],           tip: 0, counter: 0, init: function { VDA.JFF.tip = Math.floor(Math.random * (VDA.JFF.tips.length + 1)); $(document).click(function {                    if (++VDA.JFF.counter === 10) {                        $.prompt("Tip of the day: " + VDA.JFF.tips[VDA.JFF.tip]);                        VDA.log("VDA JFF has just revealed a pearl of wisdom (!)");                    } else if (VDA.JFF.counter === 20) {                        $("body").append(' LOLWUT ');                        $("#vda-jff-lolwut").css({ "font-size": "24pt", position: "fixed", top: "0%", left: "50%" }).animate({ top: "100%" }, {                           duration: 5000, easing: "linear", complete: function { $("#vda-jff-lolwut").remove; }                       });                        VDA.log("VDA JFF has released its patent-pending LOLWUT banner");                    }                }); if ($_GET.vda_jff) { $("body").addClass("vda-jff"); }           }        },        // END VDA JFF ///////////////////////////////////////////////////////////////// // VDA AA ///////////////////////////////////////////////////////////////// AA: { admins: [], setList: function (arr) { VDA.AA.admins = arr; },           VSTF: ["Charitwo", "Eulalia459678", "Grunny", "Joeyaa", "Misiek95", "Ose", "Vegadark"], alert: function (name, title, msg) { $("body").append($(' Loading, please wait... '));               location.href = "/index.php?title=User talk:" + name + "&action=edit&section=new&useeditor=mediawiki&vda_aa=1&vda_aa_title=" + encodeURIComponent(title) + "&vda_aa_msg=" + encodeURIComponent(msg); },           displayAdminForm: function  { if (VDA.AA.admins.length === 0) { $.prompt("You do not have any administrators on your list."); } else { $.prompt('Select an admininstrator: ' + VDA.AA.admins.join("  ") + '

Type the title of your message: 

Type your message:

VDA will automatically append your signature.', { buttons: { Done: true, Cancel: false }, submit: function (v, m, f) { if (v) { VDA.AA.alert(f.admin, f.title, f.message); }                       }                    });                }            },            displayVSTFForm: function  {                $.prompt('Select a VSTF member: ' + VDA.AA.VSTF.join(" ") + '

Type the title of your message: 

Type your message:

VDA will automatically append your signature.', { buttons: { Done: true, Cancel: false }, submit: function (v, m, f) { if (v) { VDA.AA.alert(f.member, f.title, f.message); }                   }                });            },            init: function  {                var html = ' Alert an admin &bull; Alert a VSTF member ';                if (skin === "monaco") {                    $("#userData").prepend(html);                } else if (skin === "monobook") {                    $("#p-personal ul").prepend("" + html + "</li>");                }                if ($_GET.vda_aa) {                    if (!($(".permissions-errors").length)) {                        $("body").append($(' Loading, please wait... '));                        $("input[name=wpSummary]").val(decodeURIComponent($_GET.vda_aa_title));                        $("#wpTextbox1").val(decodeURIComponent($_GET.vda_aa_msg) + " " + "");                        $("#editform").submit; } else { $.prompt("A permissions error has occurred. Make sure you have access to edit this page and you have not been blocked."); }               }            }        },        // END VDA AA ///////////////////////////////////////////////////////////////// // VDA RC ///////////////////////////////////////////////////////////////// RC: { showRC: function { $.prompt('Visit the Recent Changes</a> One moment, please...', { buttons: { Close: true } }); $(".jqimessage").load("/wiki/Special:RecentChanges #bodyContent", function (res, status, xhr) {                   if (status === "error") {                        $(".jqimessage").html("Oh dear. The following error has occurred while attempting to load Special:RecentChanges:

Visit the Recent Changes</a>');                   } else {                        $(".jqimessage").prepend('View full page</a>');                    }                }); },           init: function  { if (wgPageName !== "Special:RecentChanges") { // cheap and dirty way of bypassing JSLint's "Script URL" error *smirk* $('a[href="/wiki/Special:RecentChanges"]').attr("href", (function (s) { return s + ":"; })("javascript") + "VDA.RC.showRC;"); }           }        },        // END VDA RC ///////////////////////////////////////////////////////////////// // VDA VW ///////////////////////////////////////////////////////////////// VW: { generateMessage: function (o) { var msg = ""; switch (o.level) { case "1": msg += "Hi there" + (o.welcome? " and welcome to " + wgSitename : "") + "! "; switch (o.edittype) { case "edit": msg += "Your recent edits to " + o.page + " have been identified as " + o.type + " and have been reverted. "; break; case "create": msg += "The page you created, " + o.page + ", has been identified as " + o.type + " and has been marked for deletion. "; break; }                       msg += "If you think that this warning is a mistake, please let me know by leaving a message below. Thanks!"; break; case "2": msg += "Hi there. "; switch (o.edittype) { case "edit": msg += "We ask that you do not make " + o.type + " edits, as you apparently did in your edits to " + o.page + ". "; break; case "create": msg += "We ask that you do not create " + o.type + " pages, as you apparently did when you created " + o.page + ". "; break; }                       msg += "Once again, if you think that this warning is a mistake, let me know by posting below. Thanks."; break; case "3": switch (o.edittype) { case "edit": msg += "Please refrain from making " + o.type + " edits, as you apparently did in your edits to " + o.page + ", or you will be blocked. This is your final warning."; break; case "create": msg += "Please refrain from making " + o.type + " pages, as you apparently did when you created " + o.page + ", or you will be blocked. This is your final warning."; break; }                       break; case "4": switch (o.edittype) { case "edit": msg += "You have been blocked for " + o.period + " for repeated " + o.type + " edits. "; break; case "create": msg += "You have been blocked for " + o.period + " for repeated creation of " + o.type + " pages. "; break; }                       msg += o.canEditTalk? "You can still edit your talk page. If you think this block is not justified, let me know by posting below." : "";                       break; }               return msg + (o.comment? "

" + o.comment : "") + " " + "";           },            warn: function (user) {                $.prompt('Username: <input type="text" name="username" value="' + (user? user : "") + '" />

First warning Second warning  Final warning  Blocked

What type of edit has the user made? Editing an existing page Creating a new page

<input type="checkbox" name="welcome" /> This user is new to ' + wgSitename + ' Type: <input type="text" name="type1" value="unconstructive" /> Page: <input type="text" name="page1" value="' + wgCanonicalNamespace.replace(/_/g, " ") + ':' + wgTitle + '" /> Type: <input type="text" name="type2" value="unconstructive" /> Page: <input type="text" name="page2" value="' + wgCanonicalNamespace.replace(/_/g, " ") + ':' + wgTitle + '" /> Type: <input type="text" name="type3" value="unconstructive" /> Page: <input type="text" name="page3" value="' + wgCanonicalNamespace.replace(/_/g, " ") + ':' + wgTitle + '" /> Type: <input type="text" name="type4" value="unconstructive" /> <input type="checkbox" name="canEditTalk" /> Can edit own talk page Block period: <input type="text" name="period" value="24 hours" /> Additional comment: <input type="text" name="comment" value="" />

', {                   buttons: { Preview: "p", Done: true }, loaded: function { $(".level-options:not(#level1)").hide; $('select[name="level"] > option').click(function {                            $(".level-options").hide("slow");                            var index = $(this).attr("value");                            $("#level" + index).show("slow");                        }); },                   submit: function (v, m, f) { if (v === "p") { f.type = f["type" + f.level]; f.page = f["page" + f.level]; var msg = VDA.VW.generateMessage(f); $("#preview").hide.css({ border: "thin solid black", padding: "10px", margin: "10px" }).html(msg).show("slow"); return false; } else if (v) { f.type = f["type" + f.level]; f.page = f["page" + f.level]; var msg = VDA.VW.generateMessage(f); $("body").append($(' Loading, please wait... '));                           location.href = "/index.php?title=User talk:" + f.username + "&action=edit&section=new&useeditor=mediawiki&vda_vw=1&vda_vw_msg=" + encodeURIComponent(msg); }                   }                });            },            init: function  {                if ((wgCanonicalNamespace === "User")||(wgCanonicalNamespace === "User_talk")) {                    var user = (wgTitle.indexOf("/") === -1)? wgTitle : wgTitle.substring(0, wgTitle.indexOf("/"));                    VDA.log("Viewing user/talk page belonging to " + user);                    if (user !== wgUserName) {                        $("#user_masthead_head h2").append(' warn</a> ');                    }                }                if ($_GET.vda_vw) {                    if (!($(".permissions-errors").length)) {                        $("body").append($(' Loading, please wait... '));                        $("input[name=wpSummary]").val("Warning");                        $("#wpTextbox1").val(decodeURIComponent($_GET.vda_vw_msg)); $("#editform").submit; } else { $.prompt("A permissions error has occurred. Make sure you have access to edit this page and you have not been blocked."); }               }            }        },        // END VDA VW ///////////////////////////////////////////////////////////////// // VDA CRED ///////////////////////////////////////////////////////////////// CRED: { pplz: [ "Ajraddatz", "Andres bonilla 196", "FB100Z", "FreddyderHamster", "Ivancillo", "Manyman", "Quarenon", "The last username left", "VegaDark", "Wikia" ],           init: function  { if ($_GET.vda_credits) { $.prompt('A great big "thank you" to all of you who helped in this project:

' + VDA.CRED.pplz.join(", ") + '

Meet us at vda.wikia.com</a> '); // I promise you, this will be the only link to us. I promise.               }            }        }        // END VDA CRED /////////////////////////////////////////////////////////////////    },    loaded_libs: [],    load: function (str) {        if (VDA.libraries[str]) {            VDA[str] = VDA.libraries[str];            VDA.loaded_libs.push(str);            return VDA.log("VDA library '" + str + "' loaded successfully");        } else {            return VDA.warn("Unknown library '" + str + "' not loaded");        }    },    // Run VDA    init: function  {        for (var i = 0; i < VDA.loaded_libs.length; i++) {            if (typeof VDA[VDA.loaded_libs[i]].init === "function") {                VDA[VDA.loaded_libs[i]].init;            } else {                VDA.warn("No init function found for library '" + VDA.loaded_libs[i] + "'."); }       }        // These variables aren't needed any more; they only make sense before the initializing call delete VDA.libraries; delete VDA.loaded_libs; delete VDA.load; return VDA.log("VDA.init called"); } }; // This uses jQuery's $(document).ready function; if jQuery is not installed, use addOnloadHook $(function {    $.prompt.setDefaults({ buttons: { OK: true } });   if (VDA.enabled && (!$_GET.vda_disable)) {        VDA.init;    } else {        VDA.log("VDA.init not called (VDA has been manually disabled)");    } }); /* */