Zum Inhalt springen

„Benutzer:Euku/Mentorenprogramm.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
kein Protokollwechsel; relative Links
Zeile 3: Zeile 3:
// kleine Erweiterung von [[Benutzer:Euku]]
// kleine Erweiterung von [[Benutzer:Euku]]
//<nowiki>
//<nowiki>
addOnloadHook(function() { // put onload in wikibits.js
$(function() {
function newRequest() {
function newRequest() {
Zeile 19: Zeile 19:
var req;
var req;
if (req = newRequest()) {
if (req = newRequest()) {
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Mentor gesucht";
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Mentor gesucht";
req.open("GET", text, false);
req.open("GET", text, false);
req.send("");
req.send("");
var menteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
var menteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
}
}
var req;
var req;
if (req = newRequest()) {
if (req = newRequest()) {
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Wunschmentor gesucht";
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Wunschmentor gesucht";
req.open("GET", text, false);
req.open("GET", text, false);
req.send("");
req.send("");
var wmenteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
var wmenteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
}
}
Zeile 163: Zeile 163:
/* replaceMenteeTemplate aufrufen */
/* replaceMenteeTemplate aufrufen */
if(UrlParameters['irmentee'])
if(UrlParameters['irmentee'])
addOnloadHook(replaceMenteeTemplate);
$(replaceMenteeTemplate);


addOnloadHook(addMenteeButton);
$(addMenteeButton);
//</nowiki>
//</nowiki>

Version vom 28. März 2016, 11:16 Uhr

////// Fügt neben dem eigenen Benutzernamen eine Zahl mit den wartenden Neulingen ein. Gesuchte Wunschmentoren werden gesondert angezeigt.
// Idee: [[Benutzer:Stefan]], Ur-Skript: [[Benutzer:DerHexer]]
// kleine Erweiterung von [[Benutzer:Euku]]
//<nowiki>
 $(function() {
 
  function newRequest() {
   try {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else {
        return new ActiveXObject("MSXML2.XMLHTTP");
      }
   } catch (e) {
      return false;
   }
  }
 
  var req;
    if (req = newRequest()) {
     var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Mentor gesucht";
     req.open("GET", text, false);
     req.send("");
     var menteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
  }
  var req;
    if (req = newRequest()) {
     var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Wunschmentor gesucht";
     req.open("GET", text, false);
     req.send("");
     var wmenteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
  }
 
 // From [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link]]
        function aswcAddliOrSpanLink(tabs, url, name, id, title, key) {
         var ta = new Array();
         var na = document.createElement('a');
         na.href = url;
         na.appendChild(document.createTextNode(name));
         ta_hi = document.getElementById('pt-userpage'); // to versions tab
         var liOrSpan = document.createElement(ta_hi.localName); // get the node type from the sibling
         if (id) liOrSpan.id = id;
         if (mw.config.get('skin') == 'vector') {
             // damit Nutzer-Icon und die Mentee-Anzeige nicht ineinander hängen
             liOrSpan.style.margin = "0 0.75em";
         }
         liOrSpan.appendChild(na);
         if (ta_hi) tabs.insertBefore(liOrSpan, ta_hi);
         if (id) {
                 if (key && title) ta_hi[id] = [key, title];
                 else if (key) ta_hi[id] = [key, ''];
                 else if (title) ta_hi[id] = ['', title];
         }
         return liOrSpan;
        };
        aswcAddliOrSpanLink(document.getElementById('pt-userpage').parentNode, "/wiki/Kategorie:Benutzer:Mentor_gesucht", menteecount , "ca-mentee", "Wartende Neulinge", "");
        if (wmenteecount > 0)
            aswcAddliOrSpanLink(document.getElementById('pt-userpage').parentNode, "/wiki/Kategorie:Benutzer:Wunschmentor_gesucht", "WM: " + wmenteecount, "ca-wmentee", "Wartende Neulinge mit Wunschmentor", "");
 });
//</nowiki>
////// Der folge Teil fügt ein Tab zur Benutzerseite eines "wartenden Neulings" ein, mit dem man ihn sofort übernehmen kann.
////// von [[Benutzer:Ireas/mentorenscript.js]] (17:31, 30. August 2009), Autor ist [[Benutzer:Ireas]], kleine Änderung von [[Benutzer:DerHexer]]
//<nowiki>

/* Voraussetzungen */
/* isUserpage und isUserMainpage */
var isUserMainpageI = false;
if (wgCanonicalNamespace == "User")
    if (wgTitle == wgTitle.split("/")[0])
        isUserMainpageI = true;

/* UrlParameters, von PDD */
var UrlParameters = new Array ();
readparams();

function readparams() {
    var asReadInUrlParameters;
    var asReadInUrlParameter;

    asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
    for (i = 0; i < asReadInUrlParameters.length; i++) {
        asReadInUrlParameter = asReadInUrlParameters[i].split("=");
        UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
    }
}
/* Ende der Voraussetzungen */

/* Optionale Variablen */
if(typeof mentorenbuttonplatz == 'undefined')
    mentorenbuttonplatz = "";
if(typeof mentorenbuttontext == 'undefined')
    mentorenbuttontext = "Als Mentee übernehmen";
/* Ende optionale Variablen */

/* Mentee übernehmen */
function addMentee() {
    var editl = wgServer + wgScript + '?title=' +wgPageName + '&action=edit&irmentee=1';
    if(wgUserName == wgTitle)
        alert('Du willst Dich selbst für Dich als Mentor? Jaja... verarschen kann ich mich selbst...');
    location.href = editl;
}

/* Mentor-Gesucht- o. Wunschmentor-Gesucht-Baustein ersetzen */
function replaceMenteeTemplate() {
    document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/{{Mentor gesucht[^}]*}}/g, '{{Benutzer:' + wgUserName + '/Vorlage Mentor}}');
    document.editform.wpSummary.value = 'Mentorenprogramm';
    document.editform.wpSave.click();
    return;
}

/* Button in die Buttonleiste einfügen */
function addMenteeButton() {
    mentorgesucht = false;
    links = document.getElementById('mw-normal-catlinks');
    if(!links)
        return;
    links = links.getElementsByTagName('a');
    if(!links)
        return;
    for(var i in links) {
        if(!links[i].title)
            continue;
        var regmatch = links[i].title.match(/^Kategorie:Benutzer:(Wunschm|M)entor gesucht/);
        if(regmatch) {
            mentorgesucht = true;
            break;
        }
     }
    if(isUserMainpageI && mentorgesucht) {
        switch(mentorenbuttonplatz) {
            case "portlet":
                var a   = document.createElement("a");
                a.textContent   = mentorenbuttontext;
                a.onclick       = function() { addMentee(); };
                a.style.cursor  = "default";
                var li  = document.createElement("li");
                li.appendChild(a);
                var up = document.getElementById('pt-userpage');
                if (up)
                    up.parentNode.insertBefore(li, up);
            break;
            case "none": // ausblenden
                  // nichts zu tun
            break;
            default:
                var a   = document.createElement("a");
                a.onclick       = function() { addMentee(); };
                a.style.cursor  = "default";
                var span = document.createElement("span");
                span.textContent   = mentorenbuttontext;
                a.appendChild(span);
                var li  = document.createElement("li");
                li.appendChild(a);
                var watch = document.getElementById('ca-watch') ||
                            document.getElementById('ca-unwatch');
                if (watch)
                    watch.parentNode.insertBefore(li, watch);
            break;
        }
    }
}

/* replaceMenteeTemplate aufrufen */
if(UrlParameters['irmentee'])
    $(replaceMenteeTemplate);

$(addMenteeButton);
//</nowiki>