MediaWiki:MenuChanges.js

From WikiLectures

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* ============== MENU CHANGES ========================================
   author:        [[User:Slepi]]
   description:   personal menu and sidebar changes
   ====================================================================
*/

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

// FUNCTION ADDING SANDBOX
if (mw.config.get("wgUserName") != null)
    mw.util.addPortletLink('p-personal', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php?title=User:' + mw.config.get("wgUserName") + '/Sandbox', 'My sandbox', 'pt-piskoviste', 'Place, where I can experiment', 'a', document.getElementById('pt-preferences'));
/*
$(function() {
  if (mw.config.get("wgUserName") != null)
    mw.util.addPortletLink('p-personal', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php?title=User:' + mw.config.get("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($.inArray(mw.config.get("wgNamespaceNumber"), [2,3]) == -1) return;

  wgTitleAa = new Array();
  wgTitleAa = mw.config.get("wgTitle").split('/');
  urPath = mw.config.get("wgServer") + mw.config.get("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 (mw.config.get("wgUserName") != null && mw.config.get("wgCanonicalNamespace") == "Category" && mw.config.get("wgTitle")) {
    mw.util.addPortletLink('p-tb', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php/Special:CategoryHistory/'+mw.config.get("wgTitle"), 'Category history', 't-cathistory', 'History of changes of the articles in this category');
  }

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

});


// FUNCTION ADDING LIST OF RELATED PORTALS AND EXAM QUESTIONS
if (mw.config.get("wgNamespaceNumber") == 0 && mw.config.get("wgTitle") != mw.config.get("wgMainPageTitle") && mw.config.get("wgAction") != "markpatrolled") {
 
  jsonapi = mw.config.get("wgServer") + "/api.php?action=query&list=backlinks&bltitle=" + wgPageName + "&blnamespace=100&format=json";
 
  $.getJSON(jsonapi).done(function(data){
 
      // response
      var pocetOtazek = 0; // exam questins
      var pocetSkutPortalu = 0; // number of portals without exam questions
      pocetPortalu = data.query.backlinks.length;
 
      if(pocetPortalu == 0) return; // do not continue without portals
 
      for(i=0;i<pocetPortalu;i++) {
        // portal name
        aktPortal = data.query.backlinks[i].title;
        aktPortalNazev = aktPortal.replace("Portal:", "");
 
        // test to 
        var zjisteniOtazek = new RegExp("(exam|Exam|questions|Questions)");
 
        if(zjisteniOtazek.test(aktPortalNazev)) {
          idPortalu = "p-rel-exam";
          pocetOtazek++;
        } else {
          idPortalu = "p-rel-portals";
          pocetSkutPortalu++;
        }
 
        // intert portal to menu
        $(function(){
          mw.util.addPortletLink(idPortalu, wgServer + wgScript + '/' + aktPortal, aktPortalNazev , '', aktPortalNazev, '');
        });
      }
 
      // portal section
      if(pocetSkutPortalu > 0) {
        $j(document).ready(function() {
          $j("#p-rel-portals").slideDown();
        });
      }
 
      // unfold portal section
      $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 quiestions section
      if(pocetOtazek>0) {
        $j(document).ready(function() {
          $j("#p-rel-exam").slideDown();
        });
      }
 
    }
  );
}

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