_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

MediaWiki:Gadget-RecentChangesBox.js

Dans cet article, nous allons aborder le sujet de MediaWiki:Gadget-RecentChangesBox.js, qui suscite aujourd’hui un grand intérêt. MediaWiki:Gadget-RecentChangesBox.js est un sujet qui touche des personnes de tous âges et de tous horizons, car sa pertinence transcende les barrières culturelles et géographiques. Il est important de comprendre l'importance de MediaWiki:Gadget-RecentChangesBox.js dans notre société actuelle et comment il peut influencer divers aspects de nos vies. Tout au long de cet article, nous explorerons les différents aspects et perspectives liés à MediaWiki:Gadget-RecentChangesBox.js, dans le but de proposer une analyse complète et objective de ce sujet très pertinent.
/* New changes box */

mw.loader.using(, function () {
  var isVectorSkin = mw.config.get('skin') === 'vector' || mw.config.get('skin') === 'vector-2022';
  // allow user settings through
  var rcp_enabled = window.rcp_enabled;
  var rcp_num_pages = window.rcp_num_pages;
  var rcp_refresh = window.rcp_refresh;

  if (rcp_enabled === undefined) {
    rcp_enabled = false;
  }
  if (rcp_num_pages === undefined) {
    rcp_num_pages = 10;
  }
  if (rcp_refresh === undefined) {
    rcp_refresh = 10;
  }

  // a few limits to be nice to the servers
  if (rcp_num_pages > 50) {
    rcp_num_pages = 50;
  }
  if (rcp_num_pages < 1) {
    rcp_num_pages = 1;
  }
  if (rcp_refresh < 2) {
    rcp_refresh = 2;
  }

  $( rcp_init );

  /* initalise */
  function rcp_init() {
    if( !document.getElementById('p-logo') ) return;

    // get our cookie
    if (mw.cookie.get('rcp_show_box') === 'yes') {
      rcp_enabled = true;
    } else {
      rcp_enabled = false;
    }

    // Either make a request or show nothing
    if (rcp_enabled == true) {
      rcp_ajax_request();
    } else {
      rcp_draw_disabled_box();
    }
  }

  /* make a request */
  function rcp_ajax_request() {
    // check we are enabled
    if (rcp_enabled == false) return;

    // firstly, inform the user
    var cur_box = document.getElementById('p-recentchanges');
    if (cur_box != null) {
      cur_box.firstChild.firstChild.data = 'Recent Changes (updating)';
    }

    new mw.Api()
      .get({
        action: 'query',
        list: 'recentchanges',
        rcnamespace: 0,
        rcshow: '!bot',
        rcprop: 'title',
        rclimit: rcp_num_pages,
      })
      .done(rcp_ajax_response);
  }

  /* we have received a response */
  function rcp_ajax_response(data) {

    var items = data.query.recentchanges;

    // create the div that holds all the recentchanges links
    var link_div = document.createElement('div');
    link_div.className = 'body pBody';
    var list = document.createElement('ul');
    link_div.appendChild(list);

    // populate the list with 10 links.
    for (var i = 0; i < items.length; i++) {
      var item_name = items.title;
      var item_url = mw.util.getUrl(item_name, {diff: 'cur', oldid: 'prev'});

      var a = document.createElement('a');
      a.setAttribute('href', item_url);
      a.appendChild(document.createTextNode(item_name));

      var li = document.createElement('li');
      li.appendChild(a);
      list.appendChild(li);
    }

    // Container div
    var div = document.createElement('div');
    div.setAttribute('id', 'p-recentchanges');
    div.className = 'portal portlet';
    div.setAttribute('role', 'navigation');
    var heading = document.createElement('h3');
    if( isVectorSkin ) heading.setAttribute('style', 'display: block');
    heading.appendChild(document.createTextNode('Modifications récentes'));
    div.appendChild(heading);
    div.appendChild(link_div);

    // disable link
    var p = document.createElement('p');
    p.style.fontSize = 'x-small';
    p.style.margin = '0px';
    p.style.textAlign = 'right';
    var a = document.createElement('a');
    a.setAttribute('style', 'cursor: pointer');
    a.appendChild(document.createTextNode('désactiver cette boite'));
    a.onclick = rcp_disable_box;
    p.appendChild(a);
    link_div.appendChild(p);

    // now replace the div
    var old_div = document.getElementById('p-recentchanges');
    if (old_div != null) {
      old_div.parentNode.replaceChild(div, old_div);
    } else {
      var node = document.getElementById('p-logo');
      node.parentNode.insertBefore(div, node.nextSibling);
    }

    // and do it again in some seconds
    setTimeout(rcp_ajax_request, rcp_refresh * 1000);
  }

  function rcp_disable_box() {
    rcp_enabled = false;
    rcp_draw_disabled_box();
    mw.cookie.set('rcp_show_box', 'no', 86400 * 365);
  }

  function rcp_enable_box() {
    rcp_enabled = true;
    rcp_ajax_request();
    mw.cookie.set('rcp_show_box', 'yes', 86400 * 365);
  }

  function rcp_draw_disabled_box() {
    // Container div
    var link_div = document.createElement('div');
    link_div.className = 'body pBody';
    var div = document.createElement('div');
    div.setAttribute('id', 'p-recentchanges');
    div.className = 'portal portlet';
    div.setAttribute('role', 'navigation');
    var heading = document.createElement('h3');
    if( isVectorSkin ) heading.setAttribute('style', 'display: block');
    heading.appendChild(document.createTextNode('Modifications récentes'));
    div.appendChild(heading);
    div.appendChild(link_div);

    // enable link
    var p = document.createElement('p');
    p.style.fontSize = 'x-small';
    p.style.margin = '0px';
    var a = document.createElement('a');
    a.setAttribute('style', 'cursor: pointer');
    a.appendChild(document.createTextNode('Activer cette boite'));
    a.onclick = rcp_enable_box;
    p.appendChild(a);
    link_div.appendChild(p);

    // now replace the div
    var old_div = document.getElementById('p-recentchanges');
    if (old_div != null) {
      old_div.parentNode.replaceChild(div, old_div);
    } else {
      var node = document.getElementById('p-logo');
      node.parentNode.insertBefore(div, node.nextSibling);
    }
  }

});