User:Iceblock/Scripts/Seeking-help.js

/* To use the script, add the following line to Special:MyPage/common.js importScript('User:Iceblock/Scripts/Seeking-help.js'); // Linkback: [[User:Ice

/*

To use the script, add the following line to Special:MyPage/common.js
importScript('User:Iceblock/Scripts/Seeking-help.js'); // Linkback: [[User:Iceblock/Scripts/Seeking-help.js]]


 * Documentation: This script adds a tab with information on how
 * many Wikipedians currently are looking for help.
 * Clicking the tab will open Category:Wikipedians_looking_for_help 
 *
 *
 * This script is based on the two scripts
 *
 * http://no.wikipedia.org/wiki/MediaWiki:Gadget-HurtigSlett.js
 * http://en.wikipedia.org/wiki/MediaWiki:Gadget-dropdown-menus.js
 *
 * The function createTab2 is taken from 
 * MediaWiki:Gadget-dropdown-menus.js (called createTab there).
 * It is modified not to include 'mid' and to include 'link'.
 * It is also modified to check the page name and set the class
 * name to 'selected' if the page name matches the category name.
 * The rest of this script is based on MediaWiki:Gadget-HurtigSlett.js
 * and modified to check Category:Wikipedians_looking_for_help
 * Under the Vector skin, it places the tab to the left (!) to ensure it is
 * being displayed on special pages.
 *
 * In the function names, 'qd' is replaced with 'seekinghelp'.
 *
 * An unused function (function displayQuickDelete()) is removed from this script.
 * 
 */



// Create cactions LI tab
    function createTab2(cid,ltxt,link) {
        var elements = {
            li: document.createElement('li'),
            a: document.createElement('a'),
            span: document.createElement('span'),
            txt: document.createTextNode(ltxt)
        };
        with (elements) {
            if ( wgPageName == 'Category:Wikipedians_looking_for_help' ) {
                li.className='selected';
            }
            li.id = cid;
            a.href = link;
            span.appendChild(txt); a.appendChild(span); li.appendChild(a);
        }
        return elements.li;
    }



/* Memo to self, den som skal sjekkes mot er denne */
/* http://no.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Kategori:Sider%20som%20er%20foresl%E5tt%20raskt%20slettet&format=xml */
 
/* Vi har to mulige valg å legge denne på: */
/* <div id="p-cactions" class="portlet"> <-- Brukerside, diskusjon, overvåk, etc. */
/* <div class="portlet" id="p-personal"> <-- Brukernavn, min diskusjonsside, innstillinger, etc. */


/* (function displayQuickDelete() removed) */




 
/* init ajax */
function seekinghelp_create_request() {

  try {
    seekinghelp_http = new XMLHttpRequest();
 
  } catch (e) {
    try {
      seekinghelp_http = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        seekinghelp_http = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
 
  seekinghelp_http.onreadystatechange = function() {
    if(seekinghelp_http.readyState == 4) seekinghelp_ajax_response();
  }
 
  return true;
}
 

/* make a request */
function seekinghelp_ajax_request() {

  var api_link = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&list=categorymembers&cmtitle=Category:Wikipedians%20looking%20for%20help&format=xml&cmlimit=25';

  if (seekinghelp_create_request () == false) {
     return;
  }
 
  // Then make the request
  seekinghelp_http.open("GET", api_link, true);
  seekinghelp_http.send(null);
}



/* we have received a response */
function seekinghelp_ajax_response() {


  var refresh_time = 60;
  var link = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Category:Wikipedians_looking_for_help&action=purge';
  var items = seekinghelp_http.responseXML.getElementsByTagName('cm');
  //items.length;


  document.getElementById((skin=='vector')?'left-navigation':'p-cactions').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(createTab2('ca-seekinghelp', items.length + ' seeking help', link));

 
  /* Repeat */
  /* Actually, I think we should not repeat, check if it is updated on page refresh, and if that is enough */
//  setTimeout("seekinghelp_ajax_request()", refresh_time * 1000);
}
 

addOnloadHook(seekinghelp_ajax_request);

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.