Diferenças entre edições de "MediaWiki:Gadget-HistoryNumDiff.js"

Origem: Wikilivros, livros abertos por um mundo aberto.
Saltar para a navegação Saltar para a pesquisa
m (Migração para o MW 1.17; addOnloadHook$; wg*mw.config.get('wg*'); redução de erros com JSHint)
Linha 24: Linha 24:
 
var empty = "(empty)";
 
var empty = "(empty)";
 
 
if(wgUserLanguage == "fr")
+
if(mw.config.get( 'wgUserLanguage' ) == "fr")
 
{
 
{
 
regString = /\((.*) octets?\)/;
 
regString = /\((.*) octets?\)/;
Linha 30: Linha 30:
 
}
 
}
 
 
if(string==empty)
+
if(string==empty) {
 
string=0;
 
string=0;
else {
+
} else {
 
resultString= regString.exec(string);
 
resultString= regString.exec(string);
 
string = resultString[1].replace(separator,"");
 
string = resultString[1].replace(separator,"");
string = parseInt(string );
+
string = parseInt(string, 10);
 
}
 
}
 
return string;
 
return string;
Linha 50: Linha 50:
 
var length = eltsByTag.length;
 
var length = eltsByTag.length;
 
 
while(i<length && eltsByTag.item(i).className != "history-size")
+
while(i<length && eltsByTag.item(i).className != "history-size") {
 
i++;
 
i++;
  +
}
 
 
if(i<length) {
 
if(i<length) {
 
resultNextString = getNumFromString(i,eltsByTag);
 
resultNextString = getNumFromString(i,eltsByTag);
Linha 69: Linha 69:
 
string = "+" + string;
 
string = "+" + string;
 
}
 
}
else
+
else {
if (string<0)
+
if (string<0) {
 
className = "mw-plusminus-neg";
 
className = "mw-plusminus-neg";
else
+
} else {
 
className = "mw-plusminus-null";
 
className = "mw-plusminus-null";
  +
}
 
if (string<-500 || string>500)
+
}
  +
if (string<-500 || string>500) {
 
string = "<strong>" + "(" + string + ")" + "</strong>";
 
string = "<strong>" + "(" + string + ")" + "</strong>";
else
+
} else {
 
string = "(" + string + ")";
 
string = "(" + string + ")";
  +
}
 
 
eltsByTag.item(lastI).innerHTML = string ;
 
eltsByTag.item(lastI).innerHTML = string ;
 
eltsByTag.item(lastI).className = className;
 
eltsByTag.item(lastI).className = className;
Linha 90: Linha 91:
 
}
 
}
 
}
 
}
if(wgAction && wgAction == "history")
+
if(mw.config.get( 'wgAction' ) && mw.config.get( 'wgAction' ) == "history") {
addOnloadHook(makeNumDiff);
+
$(makeNumDiff);
  +
}

Revisão das 13h10min de 10 de maio de 2011

/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === WARNING: GLOBAL GADGET FILE ===                      |
 * |                  Changes to this page affect many users.                    |
 * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
 * |_____________________________________________________________________________|
 *
 * Imported from the January 17, 2011 version at [[fr:MediaWiki:Gadget-HistoryNumDiff.js]]
 *
 * Shows the number of characters added or removed, rather than the size of the revision.
 * This format is like the one used by the Watchlist and Recent Changes. 
 * 
 * See [[w:en:MediaWiki:Gadget-HistoryNumDiff]].
 *
 * Author: The RedBurn
 *
 */
 
function getNumFromString (i,eltsByTag) {
  var regString = /\((.*) bytes?\)/;
  var resultString;
  var string = eltsByTag.item(i).innerHTML;
  var separator = /[^0-9]/g;
  var empty = "(empty)";
 
  if(mw.config.get( 'wgUserLanguage' ) == "fr")
  {
    regString = /\((.*) octets?\)/;
    empty = "(vide)";
  }
 
  if(string==empty) {
    string=0;
  } else {
    resultString= regString.exec(string);
    string = resultString[1].replace(separator,"");
    string = parseInt(string, 10);
  }
  return string;
}
 
function makeNumDiff() {
  var string;
  var resultPrevString = 0; // précédent dans l'ordre chronologique
  var resultNextString = 0;
  var className;
  var lastI = 0;
  var i = 0;
  var eltsByTag = document.getElementsByTagName("span");
  var length = eltsByTag.length;
 
  while(i<length && eltsByTag.item(i).className != "history-size") {
    i++;
  }
  if(i<length) {
    resultNextString = getNumFromString(i,eltsByTag);
    lastI = i;
    i++;
 
    while (i<length) {
      if (eltsByTag.item(i).className == "history-size"){
 
        resultPrevString = getNumFromString(i,eltsByTag);
 
        string = resultNextString - resultPrevString;
 
        if (string>0) {
          className = "mw-plusminus-pos";
          string = "+" + string;
        }
        else {
          if (string<0) {
            className = "mw-plusminus-neg";
          } else {
            className = "mw-plusminus-null";
          }
        }
        if (string<-500 || string>500) {
          string = "<strong>" + "(" + string + ")" + "</strong>";
        } else {
          string = "(" + string + ")";
        }
        eltsByTag.item(lastI).innerHTML = string ;
        eltsByTag.item(lastI).className = className;
 
        resultNextString = resultPrevString;
        lastI = i;
      }
      i++;
    }
  }
}
if(mw.config.get( 'wgAction' ) && mw.config.get( 'wgAction' ) == "history") {
  $(makeNumDiff);
}