Utilisateur:Dr Brains/LiveRC/MostModifiedPagesExtension.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./*
--------------------------------------------------------------------------------------
---------LLLL---------III--------------------------RRRRRRRRRR--------CCCCC------------
---------LLLL---------III--------------------------RRRRRRRRRRRR----CCCCCCCCC----------
---------LLLL--------------------------------------RRR------RRR---CCC-----CCC---------
---------LLLL---------III--VV-----VV--EEEEEEEEE----RRR------RRR--CCC------------------
---------LLLL---------III---VV---VV---EEE----------RRRRRRRRRRR---CCC------------------
---------LLLL---------III---VV---VV---EEEEEE-------RRRRRRRRRR----CCC------------------
---------LLLL---------III----VV-VV----EEEEEE-------RRR-----RRR----CCC-----CCC---------
---------LLLLLLLLLLL--III----VVVVV----EEE----------RRR------RRR----CCCCCCCCC----------
---------LLLLLLLLLLL--III-----VVV-----EEEEEEEEE----RRR-------RRR-----CCCCC------------
--------------------------------------------------------------------------------------
'''Extension de LiveRC'''
Ajoute une icône à côté des articles modifiés par plus de 5 personnes différentes durant la dernière heure
* Licence : ...?
* Documentation :
* Auteur : [[:fr:User:Dr Brains]]
* Développement et maintenance :
{{Catégorisation JS|LiveRC}}
<source lang=javascript> */
if (typeof(lrcHooks)!="undefined") { // DÉBUT IF
// Paramètres
try{
lrcParams["MostModifiedPagesRun"] = true;
lrcParams["MostModifiedPagesDelay"] = 1;
lrcParams["MostModifiedPagesUserLimit"] = 4;
lrcParams["MostModifiedPagesRevertLimit"] = 2;
}catch(e){ }
// Textes
try{
lrcTexts["MostModifiedIcon_Title"] = "$1 éditeurs $2 : $3";
lrcTexts["MostRevertedIcon_Title"] = "$1 reverts $2 : $3";
lrcTexts["MostModifiedHours"] = "durant les $1 dernières heures";
lrcTexts["MostModifiedHour"] = "durant la dernière heure";
}catch(e){ }
// Icônes
try{
lrcIcons["MostModifiedIcon"] = {"type":0,
"src":"thumb/1/16/Co-op_activism4.svg/12px-Co-op_activism4.svg.png",
"width":12,
"height":12
}
lrcIcons["MostRevertedIcon"] = {"type":0,
"src":"thumb/9/98/Tango-grenade.svg/12px-Tango-grenade.svg.png",
"width":12,
"height":12
}
}catch(e){ }
// Descriptions
try{
lrcParamDesc["DescMostModifiedPagesRun"] = "[MostModified] Charger l’historique des pages (coûteux)";
lrcParamDesc["DescMostModifiedPagesDelay"] = "[MostModified] Nombre d’heures d’historique à charger";
lrcParamDesc["DescMostModifiedPagesUserLimit"] = "[MostModified] Limite d’utilisateurs pour les pages très modifiées";
lrcParamDesc["DescMostModifiedPagesRevertLimit"] = "[MostModified] Limite de reverts pour les pages très revertées";
lrcParamDesc["DescMostModifiedIcon"] = "[MostModified] Page très modifiée";
lrcParamDesc["DescMostRevertedIcon"] = "[MostModified] Possible guerre d’édition";
lrcParamDesc["DescMostModifiedIcon_Title"] = "[MostModified] Infobulle de l’icône pour pages très modifiées";
lrcParamDesc["DescMostRevertedIcon_Title"] = "[MostModified] Infobulle de l’icône pour pages en guerre d’édition";
lrcParamDesc["DescMostModifiedHours"] = '[MostModified] Texte "durant les X dernières heures" (pluriel)';
lrcParamDesc["DescMostModifiedHour"] = '[MostModified] Texte "durant la dernière heure" (singulier)';
}catch(e){ }
function MostModifiedPagesExtension_GetTimestamp(TS){
var Year = parseInt(TS.substring(0, 4));
var Month = parseInt(TS.substring(5, 7).replace(/^0/, ""));
var Day = parseInt(TS.substring(8, 10).replace(/^0/, ""));
var Hour = parseInt(TS.substring(11, 13).replace(/^0/, ""));
var Minut = parseInt(TS.substring(14, 16).replace(/^0/, ""));
var DaysinMonth = {"1" :31,
"2" :28,
"3" :31,
"4" :30,
"5" :31,
"6" :30,
"7" :31,
"8" :31,
"9" :30,
"10":31,
"11":30,
"12":31
}
if(Year%4==0 && (Year%100!=0 || Year%400==0) ) DaysinMonth[2]=29;
Hour = Hour-lrcMakeParam("MostModifiedPagesDelay");
if(Hour==-1){
Hour = Hour + 24;
Day = Day-1;
if(Day == 0){
Month = Month-1;
if(Month==0){
Month = 12;
Year = Year-1;
}
Day = DaysinMonth[Month];
}
}
var ThisTimestamp = "" + Year
+ (Month<10 ? "0"+Month : Month)
+ (Day <10 ? "0"+Day : Day )
+ (Hour <10 ? "0"+Hour : Hour )
+ (Minut<10 ? "0"+Minut : Minut)
+ "00";
return ThisTimestamp;
}
function MostModifiedPagesExtension_GetInfos(Args){
if(!lrcMakeParam("MostModifiedPagesRun")) return;
var tr1 = document.getElementById(Args.id);
if (!tr1) return;
var rc = Args.rc;
var article = rc.title;
var continuevalue = Args.mustcontinue;
if(!continuevalue) continuevalue = '';
var TS = MostModifiedPagesExtension_GetTimestamp(rc.timestamp);
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query'
+ '&prop=revisions&titles='+encodeURIComponent(article)
+ '&rvlimit='+LiveRC_Config["UserInfos"].APIlimit
+ '&rvend='+TS
+ '&rvprop=user|comment'
+ continuevalue;
if(!Args.users) Args.users = new Array();
if(!Args.reverts) Args.reverts = new Array();
lrcDisplayDebug("Get page revisions : " + article + " " + continuevalue);
wpajax.http({ url: URL,
onSuccess: MostModifiedPagesExtension_AddIcon,
page: article,
Args: Args
});
}
LiveRC_AddHook("AfterRC", MostModifiedPagesExtension_GetInfos);
function MostModifiedPagesExtension_AddIcon(Req, data){
var Args = data.Args
var rc = Args.rc;
var TR = document.getElementById(Args.id);
if (!TR) return;
var ObjetXML = Req.responseXML;
if(!ObjetXML) return;
var Modifs = ObjetXML.getElementsByTagName('rev');
for(var a=0,l=Modifs.length;a<l;a++){
var User = Modifs[a].getAttribute('user');
if(Args.users.indexOf(User)==-1) Args.users.push(User);
var Comment = Modifs[a].getAttribute("comment");
var rc = new Object();
rc.state = new Array();
if (typeof(Comment) != "undefined") {
var CommentTests = Custom_commenttests;
if(CommentTests.length===0) CommentTests = commenttests;
for(var j=0,lenj = CommentTests.length; j<lenj; j++)
if(new RegExp(CommentTests[j].regex).test(Comment))
rc.state = lrcAddState(rc.state, CommentTests[j].state);
}
if(lrcHasState(rc.state, "REVERT")) Args.reverts.push(User);
}
var ContinueTag = ObjetXML.getElementsByTagName('query-continue')[0];
if(ContinueTag){
Args.mustcontinue = "&rvcontinue=" + encodeURIComponent(ContinueTag.firstChild.getAttribute('rvcontinue'));
MostModifiedPagesExtension_GetInfos(Args);
}else{
MostModifiedPagesExtension_AddIcons(Args);
}
}
function MostModifiedPagesExtension_AddIcons(Args){
var Users = Args.users;
var Reverts = Args.reverts;
var IconsToAdd = new Array();
var HourParam = lrcMakeParam("MostModifiedPagesDelay");
var HourParamText = lrcMakeText("MostModifiedHour"+(HourParam>1 ? "s" : "")).split("$1").join(HourParam);
if(Users.length>lrcMakeParam("MostModifiedPagesUserLimit")){
var UbuttonIcon = lrcMakeIcon("MostModifiedIcon");
UbuttonIcon = UbuttonIcon.split("$1").join(Users.length);
UbuttonIcon = UbuttonIcon.split("$2").join(HourParamText);
UbuttonIcon = UbuttonIcon.split("$3").join(Users.join(" - "));
IconsToAdd.push(UbuttonIcon);
}
if(Reverts.length>lrcMakeParam("MostModifiedPagesRevertLimit")){
var RbuttonIcon = lrcMakeIcon("MostRevertedIcon");
RbuttonIcon = RbuttonIcon.split("$1").join(Reverts.length);
RbuttonIcon = RbuttonIcon.split("$2").join(HourParamText);
RbuttonIcon = RbuttonIcon.split("$3").join(Reverts.join(" - "));
IconsToAdd.push(RbuttonIcon);
}
if(IconsToAdd.length>0) LiveRC_AddIconBeforeArticleLink(Args, IconsToAdd);
}
function LiveRC_AddIconBeforeArticleLink(Args, IconsToAdd){
var TR = document.getElementById(Args.id);
if (!TR || typeof(IconsToAdd)!= "object") return;
var ArticleLink = TR.querySelector('a.lrc_ArticleLink');
if(!ArticleLink) return;
var Icons = document.createElement('span');
Icons.innerHTML = IconsToAdd.join(" ") + " ";
ArticleLink.parentNode.insertBefore(Icons, ArticleLink);
}
function MostModifiedPagesExtension_TransformOptions(){
var InputsToTransform = new Array();
var Options = new Array();
for(var a=1,l=25;a<l;a++) Options.push({value:a,text:a});
InputsToTransform["MostModifiedPagesDelay"] = Options;
LiveRC_ManageParams_CheckInputsToTransform(InputsToTransform);
}
LiveRC_AddHook("AfterCreateParamPanel", MostModifiedPagesExtension_TransformOptions);
} // FIN IF
//</source>