Jump to content

User:Minesweeper.007/extraeditbuttons.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>

document.write('<link rel="stylesheet" type="text/css" href="' +
               'http://en.wikipedia.org/w/index.php?title=User:MarkS/XEB/live.css' +
               '&action=raw&ctype=text/css&dontcountme=s">');

//fills the variable mwCustomEditButtons (s. function in /wikibits.js), with buttons for the Toolbar  
function addCustomButton(imageFile, speedTip, tagOpen, tagClose, sampleText){
mwCustomEditButtons.push({
  "imageFile": imageFile,
  "speedTip": speedTip,
  "tagOpen": tagOpen,
  "tagClose": tagClose,
  "sampleText": sampleText});
}

var Isrc='http://upload.wikimedia.org/wikipedia/commons/';

// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons
//  rather than mwEditButtons. However, there is no guarantee it will always be 11
//  so we count them here. 
var enExtraButtons=mwCustomEditButtons.length;

var BDict={
'A':['f/f0/Bouton_Vandale0.png','Vandal Warning 01','{{subst:uw-vandal1|','}} ~~~~','Article'],
'B':['1/1d/Bouton_Vandale1.png','Vandal Warning 02','{{subst:uw-vandal2|','}} ~~~~','Article'],
'C':['c/cc/Bouton_Vandale2.png','Vandal Warning 03','{{subst:uw-vandal3|','}} ~~~~','Article'],
'D':['e/e4/Bouton_Vandale3.png','Vandal Warning 04','{{subst:uw-vandal4|','}} ~~~~','Article'],
'E':['7/7e/Bouton_Vandale4.png','Only Warning','{{subst:uw-vandalism4im|','}} ~~~~','Article'],
'F':['b/bf/WP-icon.png','Welcome a New User to Wikipedia','{{subst:w-link','}}','|heading=true'],
};

var XEBOrder2=[];
if (typeof XEBOrder!='string') // can be modified
    XEBOrder2="A,B,C,D,E,F".split(",");
else if (XEBOrder.toLowerCase()=='all') 
    for (b in BDict) XEBOrder2.push(b);
else XEBOrder2=XEBOrder.toUpperCase().split(",");



addOnloadHook(initButtons);
if(!wgIsArticle)// only if edit
{ 

    if(XEBPopups)hookEvent("load", extendButtons);
}

function initButtons(){

    var bc,d;
    for (b in BDict) BDict[b][0] = Isrc+BDict[b][0]; // // Add the start of the URL (Isrc) to the XEB buttons
    // If the user has defined any buttons then add them into the available button lists 

    if (typeof myButtons=='object')
      for (b in myButtons) BDict[b] = myButtons[b];    // custom user buttons
    // Add the media wiki standard buttons into the available buttons 

    for (b in mwEditButtons) { // add standard buttons for full XEB order changing

    //    BDict[b]=[];
BDict[b]=[mwEditButtons[b].imageFile,mwEditButtons[b].speedTip,mwEditButtons[b].tagOpen,mwEditButtons[b].tagClose,mwEditButtons[b].sampleText];

//        for (d in mwEditButtons[b]) BDict[b].push(mwEditButtons[b][d]);
    }

    // Build the new buttons 

    for (i=0;i<XEBOrder2.length;i++) {
        bc = BDict[XEBOrder2[i]];

        //Check if bc is an object 
        // - protects if user specified a non-existant buttons
        // - IE causes a javascript error when viewing a page
        if(typeof bc=='object')
        {

            //Call addCustomButton in wikibits
            addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
        }
    }

    // Remove the default buttons (if requested by the user)
    eraseButtons();
}


/** en: Removes arbitrary standard buttons from the toolbar
* @author: [[:de:User:Olliminatore]]
* @version: 0.1 (01.10.2006) **/

function eraseButtons(){

    //Remove the buttons the user doesn't want

    if(typeof rmEditButtons!='object') return;

    if (typeof rmEditButtons[0] == 'string' && rmEditButtons[0].toLowerCase() == 'all') 
    {
        mwEditButtons=[];
        for(i=0;i<enExtraButtons;i++){mwCustomEditButtons.shift();}
    }
    //Sort the user's requests so we remove the button with the highest index first
    //- This ensures we remove the buttons the user expects whatever order he requested the buttons in
    rmEditButtons.sort(sortit);

    //Remove individual buttons the user doesn't want 

    for(i=0;i<rmEditButtons.length;i++){
        var n=rmEditButtons[i];
        //Standard Wikimedia buttons
        if(n>=0 && n<mwEditButtons.length){
            if(n<mwEditButtons.length){
                var x = -1;
                while((++x)<mwEditButtons.length)
                    if(x>=n)
                        mwEditButtons[x] = mwEditButtons[x+1];
            }
        mwEditButtons.pop();
        }
        //Extra buttons in English Wikipedia
        n=n-mwEditButtons.length;
        if(n>0 && n<mwCustomEditButtons.length){
        if(n<mwCustomEditButtons.length){
                var x = -1;
                while((++x)<mwCustomEditButtons.length)
                    if(x>=n)
                        mwCustomEditButtons[x] = mwCustomEditButtons[x+1];
            }
        mwCustomEditButtons.pop();
        }
    }
};

//Function:
//    sortit
//Purpose:
//    Used to sort the rmEditButtons array into descending order
function sortit(a,b){
    return(b-a)
}



// Adds extended onclick-function to some buttons 
function extendButtons(){

    if(!(allEditButtons = document.getElementById('toolbar'))) return false;
    if(typeof editform != 'undefined')
        if(!(window.editform = document.forms['editform'])) return false;

    //  table
extendAButton(Isrc+"0/04/Button_array.png",XEBPopupTable)
extendAButton(Isrc+"7/79/Button_reflink.png",XEBPopupRef)
extendAButton(Isrc+"b/b8/Button_Globe.png",XEBPopupGeoLink)
extendAButton(Isrc+"4/49/Button_talk.png",XEBPopupTalk)
extendAButton(Isrc+"1/1c/Button_advanced_image.png",XEBPopupImage)
//extendAButton(Isrc+"6/6a/Button_sup_letter.png",XEBPopupFormattedText)

    // redirect
    c=XEBOrder2.getIndex('V');
    if(c != -1)
        allEditButtons[bu_len+c].onclick=function(){
        var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
        document.editform.elements['wpTextbox1'].value=a;
        document.editform.elements['wpSummary'].value=a;
        document.editform.elements['wpWatchthis'].checked=false
  };
};

//</pre>