MediaWiki:MenuChanges.js

/* */

/* ============== MENU CHANGES =============================== author:       Petr Kajzar User:Slepi date:         10/2009, last update 03/2012 documentation: -- description:  menu changes ==========================================================

/* ============================== Personal menu ========================================= */

// FUNCTION ADDING SANDBOX $(function { // not logged in  if(wgUserName==null) {    // login vs anonlogin    if(document.getElementById("pt-anonlogin")) piskovisteId = "pt-anonlogin";    if(document.getElementById("pt-login")) piskovisteId = "pt-login";    if(!piskovisteId) return;

mw.util.addPortletLink('p-personal', wgServer + wgScriptPath + '/index.php?title=WikiLectures:Sandbox', 'My sandbox', 'pt-piskoviste', 'Place, where I can experiment', 'a', document.getElementById(piskovisteId));

} else { // personal sandbox mw.util.addPortletLink('p-personal', wgServer + wgScriptPath + '/index.php?title=User:' + wgUserName + '/Sandbox', 'My sandbox', 'pt-piskoviste', 'Place, where I can experiment', 'a', document.getElementById('pt-preferences')); } });

/* ============================== Sidebar ====================================== */ // add links "User rights", "Check IP address" and "Patrol rights" to toolbox menu // only for head editors and administrators on user pages and discussion pages $(function { if(wgNamespaceNumber != 2 && wgNamespaceNumber != 3) return;

wgTitleAa = new Array; wgTitleAa = wgTitle.split('/'); urPath = wgServer + wgScript + '/';

if(mwGetUserRight("sysop")) { mw.util.addPortletLink('p-tb', urPath + "Special:Userrights/" + wgTitleAa[0], 'User rights', 't-userrights', 'Set user rights for this user'); }

if(mwGetUserRight("bureaucrat")) { mw.util.addPortletLink('p-tb', urPath + "Special:CheckUser?user=" + wgTitle, 'Check IP address', 't-ipcheckuser', 'Check IP address of this user'); }

});

// FUNCTION ADDING LINKS TO SIDEBAR $(function { // Category History  if (wgUserName!=null && wgCanonicalNamespace == "Category" && wgTitle) {    mw.util.addPortletLink('p-tb', wgServer + wgScriptPath + '/index.php/Special:CategoryHistory/'+wgTitle, 'Category history', 't-cathistory', 'History of changes of the articles in this category');  }

// Upload to Commons if (wgUserName!=null) { mw.util.addPortletLink('p-tb', 'http://commons.wikimedia.org/wiki/Special:UploadWizard', 'Upload to Commons', 't-commonsfile', 'Upload a file to Wikimedia Commons', 'c', document.getElementById('t-specialpages')); }

// recent changes mw.util.addPortletLink('p-tb', wgServer + wgScriptPath + '/index.php?title=Special:RecentChanges', 'Recent changes', 'pt-recent', 'The list of recent changes at WikiLectures', '', document.getElementById("t-specialpages"));

// check sources if (wgNamespaceNumber == 0 || wgNamespaceNumber == 1) { mw.util.addPortletLink('p-editorial-links', wgServer + wgScriptPath + '/index.php?title=Special:PlagiatorChecker/' + wgTitle, 'Check sources', 'pt-check', 'Check sources of this article', '', document.getElementById("n-Article-processing")); }

// Print as PDF $("#p-coll-print_export").css("display", "none"); if(document.getElementById("coll-download-as-rl")) mw.util.addPortletLink('p-navigation', document.getElementById("coll-download-as-rl").getElementsByTagName("a")[0].href, 'Download as PDF', 't-printPDF', 'Download this article as PDF file'); });

// FUNCTION ADDING LIST OF RELATED PORTALS AND EXAM QUESTIONS function odkazujiciPortaly {

// wait until data available if(xmlPortaly.readyState != 4 || xmlPortaly.status != 200) return;

var jsonRes = xmlPortaly.responseText;

// process server response var pocetOtazek = 0; // exam questions var pocetSkutPortalu = 0; // number of portals (without exam questions) var jsonObj = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(jsonRes.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + jsonRes + ')');

// portals to output pocetPortalu = jsonObj.query.backlinks.length; if(pocetPortalu == 0) return; // do not continue without portals

for(i=0;i<pocetPortalu;i++) { // name of portal aktPortal = jsonObj.query.backlinks[i].title; aktPortalNazev = aktPortal.replace("Portal:", "");

// test of exam questions var zjisteniOtazek = new RegExp("(exam|Exam|questions|Questions)");

if(zjisteniOtazek.test(aktPortalNazev)) { idPortalu = "p-rel-exam"; pocetOtazek++; } else { idPortalu = "p-rel-portals"; pocetSkutPortalu++; }

// add portal to menu $(function{     mw.util.addPortletLink(idPortalu, wgServer + wgScript + '/' + aktPortal, aktPortalNazev, , aktPortalNazev, );    }); }

// portals if(pocetSkutPortalu > 0) { $j(document).ready(function {     $j("#p-rel-portals").slideDown;    }); }

// unfold portals $j(document).ready(function {   if(document.getElementById("p-rel-portals").className.indexOf("collapsed") != -1) {      $j('#mw-panel > div#p-rel-portals').toggleClass('collapsed').toggleClass('expanded').find('div.body').slideToggle('fast');    }  });

// exam questions if(pocetOtazek>0) { $j(document).ready(function {     $j("#p-rel-exam").slideDown;    }); }

// delete variables delete jsonRes; delete xmlPortaly; }

$(function{ if(mwGetUserRight("editor")) $("#p-editorial-links").css("display", "block"); });

// FUNCTION FIXES THE SIDEBAR WHEN SCROLLING $j(function { // some variables  var $wind = $j(window),        $element = $j('#mw-panel'),        timer,        highEnough,  // if the window is high enough to show whole sidebar        topPosition = $element.position.top,        headMargin = 0;

// when scrolling, start this $wind.scroll(function {   if (timer) {      clearTimeout(timer);    }

timer = setTimeout(function {     timer = null;      highEnough = (($wind.height - headMargin) > $element.height); // if the window is high enough to show whole sidebar

// when scrolling up and down, fix the sidebar if (($wind.scrollTop >= topPosition) && highEnough && ($wind.scrollLeft == 0)) { $element.css({          position: 'fixed',           top: headMargin        });

// when scrolling left and right, keep the position on the left } else if(($wind.scrollTop >= topPosition) && highEnough && ($wind.scrollLeft != 0)) { $element.css({         position: 'absolute',          top: $wind.scrollTop,          left: 0        });

// normal position under logo } else { $element.css({          position: ,           top:          }); }    }, 10);  }); });

/* ============================== Footer ============================================== */

// FUNCTION ADDING "Share Button" FROM FACEBOOK // to the end of an article // and links to stimulate editors $(function {

// check NS // only main NS, portal or studium guide if (wgNamespaceNumber != 0 && wgNamespaceNumber != 100 && wgTitle.indexOf("guide") == -1) return false;

// check main page if (wgTitle == wgMainPageTitle) return false;

// check action if (wgAction != "view") return false;

// create button fbShareButton = document.createElement("div"); fbShareButton.className = "fb_sharebutton"; fbShareButton.id = "fb_likebutton"; document.getElementById("content").appendChild(fbShareButton);

if (document.getElementById("catlinks")) { fbShareButton.parentNode.insertBefore(document.getElementById("catlinks"), fbShareButton.nextSibling); }

fbShareButton.innerHTML = " ";

// link to fb and others (AddThis.com) fbShareButton.innerHTML += '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + ' \n' + '';

// script for addthis.com importScriptURI("http://s7.addthis.com/js/300/addthis_widget.js#pubid=xa-4f3a743e135889bd");

// link to editations if(wgNamespaceNumber == 0) { fbShareButton.innerHTML += ' Join us! If you find this article incomplete, inaccurate or false, correct it! Or tell us about the shortcomings. '; } });

// FOOTER $(function { links = document.createElement("div");  links.id = "myLfFooter";  document.getElementById("footer").appendChild(links);  links.innerHTML = 'WikiLectures, project of the medical faculties network MEFANET</a> • ISSN 1804-9885 • e-mail: info&#64;wikilectures.eu</a>'; });

/* ============================== Start fucntions ===================================== */

// START if (wgNamespaceNumber == 0 && wgTitle != wgMainPageTitle && wgAction != "markpatrolled") { var xmlPortaly; $(function{   getXMLHttpRequest("xmlPortaly", wgServer + "/api.php?action=query&list=backlinks&bltitle=" + wgPageName + "&blnamespace=100&format=json", "odkazujiciPortaly")  }); }

/* */