User:Pintor Kagamine/global.js

var ajaxPages = ["Special:WikiActivity", "Special:Log", "Special:RecentChanges", "Especial:WikiActivity", "Especial:Registro", "Especial:CambiosRecientes"]; var qtUserPageTemplate = ''; var qtEnableUserPageOverwrite = true;

importArticles({	type: 'script',	articles: [		'u:dev:AjaxRC/code.js',		'u:dev:NoImageLightbox/code.js',		'u:dev:PortableCSSPad/code.js',       'u:dev:QuickCreateUserPage/code.js',		'u:dev:RelatedDiscussionsModule/code.js',		'u:dev:ReferencePopups/code.js'	] });

(function (window, $, mw) {   "use strict";    //Global Variables    var page_name = mw.config.get("wgPageName"),        server = mw.config.get("wgServer"),        skin = mw.config.get("skin"),        token = mw.user.tokens.values.editToken,        page_id = mw.config.get("wgArticleId"),        namespace = mw.config.get("wgNamespaceNumber"),        signature = "" + "",        modal_title,        modal_html,        modal_id,        modal_button_name,        modal_function_to_call;    //Adds buttons    if ( skin === 'oasis' || skin === 'wikia' ) {        var node = document.createElement('a');            node.textContent = "Advanced Tools";            node.id = "advanced_tools";            node.addEventListener('click', function  { mainMenu; });       $('.wds-global-navigation .wds-button span').html($(node));        $('.wds-global-navigation .wds-button span').parent.removeAttr("href");    } else {        $('Advanced Tools').appendTo( '#p-cactions > .pBody > ul' );        $('#at-open').click(function  { mainMenu; });        mw.loader.load( $.getSassCommonURL( 'skins/oasis/css/core/modal.scss' ), 'text/css' );        mw.loader.load( $.getSassCommonURL( 'skins/oasis/css/core/buttons.scss' ), 'text/css' );     }    mw.util.addCSS('#advanced_tools{color: inherit;}');    //Un-urlencoding pagename    page_name = page_name.replace(/_/g, ' ');    //Main menu modal    function mainMenu {        $.showCustomModal("Advanced Tools", ' Block user Delete page Move page (Un)Protect page Purge page  Redirect page</a> <a class="wikia-button" id="at-redlinks">Remove redlinks</a> <a class="wikia-button" id="at-switch">Switch skin</a> <a class="wikia-button" id="at-template">Add template</a> <a class="wikia-button" id="at-unsigned">Add unsigned</a> <a class="wikia-button" id="at-batch">Batch delete</a>  ', { id: "advancedtools", width: 650, buttons: [{ id: "close-menu", defaultButton: true, message: "Close form", handler: function { $("#advancedtools").closeModal; } }]       });        //Stupid Hack        $("#at-block").click(function  { modal("block"); });       $("#at-delete").click(function  { modal("delete"); });       $("#at-move").click(function  { modal("move"); });       $("#at-protect").click(function  { modal("protect"); });       $("#at-purge").click(function  { $.get('/index.php?title='+encodeURIComponent(page_name)+'&action=purge',function{location.reload(true);}); });       $("#at-redirect").click(function  { modal("redirect"); });       $("#at-redlinks").click(function  { $.getJSON('/api.php?action=query&prop=revisions&titles='+encodeURIComponent(page_name)+'&rvprop=content&indexpageids=1&format=json',function(result){var text=result.query.pages[result.query.pageids[0]].revisions[0]['*'];var redlinks=$('a.new');var ref=0;while(text.indexOf(,ref)!=-1){if(text.indexOf(,text.indexOf(,open);var close=text.indexOf(,open);if(text.indexOf(' ',open)!=-1&&text.indexOf(' ',open)<close){ref=open+1;continue;}if(pipe!=-1&&pipe<close){if(pipe==close-1){var title=text.substring(open+2,pipe);var display=title.substring(title.indexOf(':')+1);}else{var title=text.substring(open+2,pipe);var display=text.substring(pipe+1,close);}}else{var title=text.substring(open+2,close);var display=title;}if(!title){ref=open+1;continue;}for(var i=0;i<redlinks.length;i++){var utitle=title[0].toUpperCase+title.substring(1);if(redlinks[i].title.indexOf(' (page does not exist)')){var redlink=redlinks[i].title.substring(0,redlinks[i].title.length-22);}else{var redlink=redlinks[i];}if(utitle==redlink||utitle==':'+redlink){if(pipe==close-1){var show=title;}else{var show=display;}text=text.substring(0,open)+show+text.substring(close+2);break;}}ref=open+2;}else{break;}}$.getJSON('/api.php?action=query&prop=info&titles='+encodeURIComponent(page_name)+'&intoken=edit&indexpageids=1&format=json',function(result){$.post('/api.php',{action:'edit',title:page_name,text:text,summary:'Fixing redlinks',token:token},function{window.location.reload;});});}); });       $("#at-switch").click(function { if(!document.getElementById("ca-skins")){if(skin==="oasis"||skin==="wikia"){window.location=server+"/wiki/"+encodeURIComponent(page_name)+"?useskin=monobook";}else{window.location=server+"/wiki/"+encodeURIComponent(page_name)+"?useskin=wikia";}} });       $("#at-template").click(function  { modal("template"); });       $("#at-unsigned").click(function  { if(-1<[1,3,4,5,7,9,11,13,15,110].indexOf(namespace)){$.getJSON("/api.php",{action:"query",prop:"revisions",titles:page_name,rvprop:"user",format:"json",indexpageids:1},function(json){var user=json.query.pages[page_id].revisions[0].user,addText=;var summary="Adding Unsigned template for ";url=server+'/api.php?action=edit&title='+encodeURIComponent(page_name)+'&appendtext='+encodeURIComponent(addText)+'&summary='+encodeURIComponent(summary)++encodeURIComponent(user)+'&token='+encodeURIComponent(token);$.post(url,function{alert('Unsigned template has been added!');});});} });       $("#at-batch").click(function  { modal("batch"); });   }    function modal(mode) {        //Close main modal        $("#advancedtools").closeModal;        //Switch function (more compact?)        switch (mode) {        case "block":            modal_title = "Block user";            modal_html = ' Username/IP to block: <input type="text" id="block-username" placeholder="Username/IP" style="width: 500px">  Duration of the block: <input type="text" id="block-duration" placeholder="2 Weeks" style="width: 500px">  Reason for blocking: <input type="text" id="block-reason" placeholder="Vandalism" style="width: 500px"> ';            modal_id = "block";            modal_button_name = "Block";            modal_function_to_call = function  { var user = document.getElementById('block-username').value, expiry = document.getElementById('block-duration').value, reason = document.getElementById('block-reason').value; ajaxBlock(user, expiry, reason); }; break; case "delete": modal_title =