User:OldBee/LiveRC.js/Extensions/UserWarningsExtension.js
Appearance
< User:OldBee | LiveRC.js
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)
- Edge: Hold Ctrl while clicking Refresh, or press 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'''
Permet de marquer les utilisateurs ayant reçu un avertissement sur leur page de discussion.
* Licence : CC0
* Documentation :
* Auteur : [[:fr:User:Orlodrim]]
* Développement et maintenance :
** [[:fr:User:Dr Brains]]
{{Catégorisation JS|LiveRC}}
<source lang=javascript> */
if (typeof(LiveRC_AddHook)==="function") { // DÉBUT IF
LiveRC_Config["InstalledLiveRCExtensions"].push("UserWarningsExtension");
/* ************************************************************************************************************************************************ */
// Paramètres
try{
lrcParams["lrcXUWShowEditcount"] = true;
lrcParams["lrcXUWShowWarnings"] = true;
lrcParams["lrcXUWDelayIP"] = 24;
lrcParams["lrcXUWDelay"] = 24;
lrcParams["lrcXUWColorNoTalk"] = "";
lrcParams["lrcXUWColorRecentTalk"] = "";
lrcParams["lrcXUWColorRecentWarning"] = "";
}catch(e){ }
// Icônes
try{
lrcIcons["EditCount0"] = {"type":0,
"src":"thumb/1/1b/Emblem-person-red.svg/16px-Emblem-person-red.svg.png",
"width":14,
"height":14
}
lrcIcons["EditCount1"] = {"type":0,
"src":"thumb/2/23/Emblem-person-orange.svg/16px-Emblem-person-orange.svg.png",
"width":14,
"height":14
}
lrcIcons["EditCount2"] = {"type":0,
"src":"thumb/f/f4/Emblem-person-yellow.svg/16px-Emblem-person-yellow.svg.png",
"width":14,
"height":14
}
lrcIcons["EditCount3"] = {"type":0,
"src":"thumb/0/06/Emblem-person-green.svg/16px-Emblem-person-green.svg.png",
"width":14,
"height":14
}
lrcIcons["SpamIcon"] = {"type":0,
"src":"9/92/LiveRC_Spam.png",
"width":14,
"height":14
}
lrcIcons["Test0Icon"] = {"type":0,
"src":"3/3b/LiveRC_Test0.png",
"width":14,
"height":14
}
lrcIcons["Test1Icon"] = {"type":0,
"src":"5/5d/LiveRC_Test1.png",
"width":14,
"height":14
}
lrcIcons["Test2Icon"] = {"type":0,
"src":"7/78/LiveRC_Test2.png",
"width":14,
"height":14
}
lrcIcons["Test3Icon"] = {"type":0,
"src":"7/7b/LiveRC_Test3.png",
"width":14,
"height":14
}
lrcIcons["SalebotIcon"] = {"type":0,
"src":"3/31/Salebot_small_icon.png",
"width":14,
"height":14
}
}catch(e){ }
// Textes
try{
lrcTexts["EditCount0_Title"] = "Editcount : $1";
lrcTexts["EditCount1_Title"] = "Editcount : $1";
lrcTexts["EditCount2_Title"] = "Editcount : $1";
lrcTexts["EditCount3_Title"] = "Editcount : $1";
lrcTexts["SpamIcon_Title"] = "Averti : spam";
lrcTexts["Test0Icon_Title"] = "Averti : test 0";
lrcTexts["Test1Icon_Title"] = "Averti : test 1";
lrcTexts["Test2Icon_Title"] = "Averti : test 2";
lrcTexts["Test3Icon_Title"] = "Averti : test 3";
lrcTexts["SalebotIcon_Title"] = "Révoqué par Salebot";
lrcTexts['lrcXUWRAZ_Title'] = 'Remettre le compteur d’avertissements à zéro';
lrcTexts['lrcXUWRAZ_Text'] = 'raz';
}catch(e){ }
// Descriptions
try{
lrcParamDesc['DesclrcUserWarningsMessages'] = 'Paramètres de l’extension UserWarnings';
lrcParamDesc['DesclrcUserWarningsMessages_short'] = 'UserWarnings';
lrcParamDesc["DesclrcXUWShowEditcount"] = "[UserWarnings] Afficher le compteur d’éditions (couteux)";
lrcParamDesc["DesclrcXUWShowWarnings"] = "[UserWarnings] Afficher les avertissements (couteux)";
lrcParamDesc['DesclrcXUWColorNoTalk'] = '[UserWarnings] Couleur du nom des utilisateurs sans page de discussion';
lrcParamDesc['DesclrcXUWColorRecentTalk'] = '[UserWarnings] Couleur du nom des utilisateurs avec message récent mais pas d’avertissement';
lrcParamDesc['DesclrcXUWColorRecentWarning'] = '[UserWarnings] Couleur du nom des utilisateurs avertis';
lrcParamDesc['DesclrcXUWDelayIP'] = '[UserWarnings] Délai en heures avant que les avertissements ne soient caducs (IP)';
lrcParamDesc['DesclrcXUWDelay'] = '[UserWarnings] Délai en heures avant que les avertissements ne soient caducs (utilisateur enregistré)';
lrcParamDesc['DesclrcXUWRAZ_Title'] = '[UserWarnings] Infobulle du lien de mise à zéro du compteur du nombre d’avertissements';
lrcParamDesc['DesclrcXUWRAZ_Text'] = '[UserWarnings] Texte du lien de mise à zéro du compteur du nombre d’avertissements';
lrcParamDesc['DescEditCount0'] = '[UserWarnings] Compteur d’éditions, niveau 0';
lrcParamDesc['DescEditCount1'] = '[UserWarnings] Compteur d’éditions, niveau 1';
lrcParamDesc['DescEditCount2'] = '[UserWarnings] Compteur d’éditions, niveau 2';
lrcParamDesc['DescEditCount3'] = '[UserWarnings] Compteur d’éditions, niveau 3';
lrcParamDesc['DescSpamIcon'] = '[UserWarnings] Averti : spam';
lrcParamDesc['DescTest0Icon'] = '[UserWarnings] Averti : test 0';
lrcParamDesc['DescTest1Icon'] = '[UserWarnings] Averti : test 1';
lrcParamDesc['DescTest2Icon'] = '[UserWarnings] Averti : test 2';
lrcParamDesc['DescTest3Icon'] = '[UserWarnings] Averti : test 3';
lrcParamDesc['DescSalebotIcon'] = '[UserWarnings] Révoqué par Salebot';
lrcParamDesc['DescEditCount0_Title'] = '[UserWarnings] Tooltip de l’icône Compteur d’éditions, niveau 0';
lrcParamDesc['DescEditCount1_Title'] = '[UserWarnings] Tooltip de l’icône Compteur d’éditions, niveau 1';
lrcParamDesc['DescEditCount2_Title'] = '[UserWarnings] Tooltip de l’icône Compteur d’éditions, niveau 2';
lrcParamDesc['DescEditCount3_Title'] = '[UserWarnings] Tooltip de l’icône Compteur d’éditions, niveau 3';
lrcParamDesc['DescSpamIcon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : spam';
lrcParamDesc['DescTest0Icon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : test 0';
lrcParamDesc['DescTest1Icon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : test 1';
lrcParamDesc['DescTest2Icon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : test 2';
lrcParamDesc['DescTest3Icon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : test 3';
lrcParamDesc['DescSalebotIcon_Title'] = '[UserWarnings] Infobulle de l’icône d’avertissement : Salebot';
}catch(e){ }
// Tests de commentaire
window.lrcUserWarningsMessages = [
{ image: "SpamIcon" , class: "RcUWSpam" , regex: /(S|s)pammeur/ },
{ image: "Test0Icon" , class: "RcUWTest0" , regex: /(T|t)est ?0/ },
{ image: "Test1Icon" , class: "RcUWTest1" , regex: /(T|t)est ?1/ },
{ image: "Test2Icon" , class: "RcUWTest2" , regex: /(T|t)est ?2/ },
{ image: "Test3Icon" , class: "RcUWTest3" , regex: /(T|t)est ?3/ },
{ image: "SalebotIcon" , class: "RcUWSalebot" , regex: /^bot : annonce de révocation/ }
];
window.lrcUserWarningsMessages_Custom = [];
window.Custom_lrcUserWarningsMessages = [];
// ============================ FIN DE LA PARTIE PERSONNALISABLE
LiveRC_Config["UserWarnings_rvend"] = {};
window.lrcXUWTwoDigits = function(i) {
return (i < 10 ? '0' : '') + i;
}
window.lrcXUWGetWikiDate = function(localDate) {
var d = new Date(localDate.getTime() + localDate.getTimezoneOffset() * 60 * 1000);
return '' + d.getFullYear() + lrcXUWTwoDigits(d.getMonth() + 1)
+ lrcXUWTwoDigits(d.getDate()) + lrcXUWTwoDigits(d.getHours())
+ lrcXUWTwoDigits(d.getMinutes()) + lrcXUWTwoDigits(d.getSeconds());
}
window.lrcXUWGetUserLink = function(tr1) {
var links = tr1.getElementsByTagName("td")[0].getElementsByTagName("a");
for (var i = links.length - 1; i >= 0; i--) {
if(lrcHasClass(links[i], "lrc_EditorLink")) return links[i];
}
return null;
}
window.lrcXUWHook = function(Args) {
var id = Args.id;
var tr1 = document.getElementById(id);
if (!tr1) return;
var rc = Args.rc;
var user = rc.user;
// talkpage comments request
if(lrcMakeParam("lrcXUWShowWarnings")){
var talkPage = lrcGetNamespaceName(3) + ':' + user;
lrcDisplayDebug("Get user talk page infos : " + talkPage);
var requestTalkPage = lrcGetAPIURL({format:'xml',action:'query',prop:'info',titles:talkPage,continue:''});
wpajax.http({url: requestTalkPage,
onSuccess: lrcTalkPageInfos,
user: user,
tr1id: id,
talkPage: talkPage
});
}
// user infos request
if(lrcMakeParam("lrcXUWShowEditcount")){
lrcDisplayDebug("Get user groups & editcount : " + user);
if(UserIsIP(user)){
var requestIPContribs = lrcGetAPIURL({format:'xml',action:'query',list:'usercontribs',ucuserprefix:user,uclimit:LiveRC_Config["UserInfos"].APIlimit,continue:''});
wpajax.http({url: requestIPContribs,
onSuccess: lrcIPContribsCallback,
user: user,
tr1id: id,
contribs: 0
});
}else{
var requestUserInfos = lrcGetAPIURL({format:'xml',action:'query',list:'allusers',auprefix:user,aulimit:'1',auprop:'editcount|registration|groups',continue:''});
wpajax.http({url: requestUserInfos,
onSuccess: lrcUserInfosCallback,
user: user,
tr1id: id
});
}
}
}
window.lrcTalkPageInfos = function(xmlreq, data) {
var user = data.user;
var ObjetXML = xmlreq.responseXML;
var Page = ObjetXML.getElementsByTagName("page")[0];
var ContentType = Page.getAttribute("contentmodel");
if(ContentType === "flow-board"){
var requestTalkPage = lrcGetAPIURL({format:'xml',action:'flow',submodule:'view-topiclist',vtlsortby:'newest',vtlformat:'wikitext',page:data.talkPage,continue:''});
// TODO : timestamp de départ pour la requête
wpajax.http({url: requestTalkPage,
onSuccess: lrcFlowTalkPageCallback,
user: user,
tr1id: data.tr1id
});
}else{
var Delay = (UserIsIP(user) ? lrcMakeParam("lrcXUWDelayIP") : lrcMakeParam("lrcXUWDelay") );
var rvend = (LiveRC_Config["UserWarnings_rvend"][user] ? LiveRC_Config["UserWarnings_rvend"][user] : lrcXUWGetWikiDate(new Date(new Date() - (Delay * 3600000))));
var requestTalkPage = lrcGetAPIURL({format:'xml',action:'query',prop:'revisions',rvlimit:LiveRC_Config["UserInfos"].APIlimit,rvend:rvend,rvprop:'comment|timestamp',titles:data.talkPage,continue:''});
wpajax.http({url: requestTalkPage,
onSuccess: lrcTalkPageCallback,
user: user,
tr1id: data.tr1id
});
}
};
window.lrcFlowTalkPageCallback = function(xmlreq, data) {
var tr1 = document.getElementById(data.tr1id);
if (!tr1) return;
var lastLink = lrcXUWGetUserLink(tr1);
if(!lastLink) return;
var revisions = xmlreq.responseXML.getElementsByTagName('revisions')[0];
if(!revisions) return;
lrcAddClass(tr1, "FlowUser");
var firstrevtimestamp = "";
var warning = [];
var classes = [];
var XUWMessages = lrcUserWarningsMessages_Custom;
if(XUWMessages.length===0) XUWMessages = Custom_lrcUserWarningsMessages;
if(XUWMessages.length===0) XUWMessages = lrcUserWarningsMessages;
var FS = revisions.firstChild
while(FS){
if(FS.getAttribute("changeType") == "new-post"){
var topictitle = FS.getElementsByTagName("topic-of-post-text-from-html")[0];
if(topictitle){
topictitle = topictitle.getAttribute("plaintext");
for (var j = 0; j < XUWMessages.length; j++) {
if((XUWMessages[j].regex).test(topictitle.unhtmlize())){
warning.push(lrcMakeIcon(XUWMessages[j].image, {before:' '}));
classes.push(XUWMessages[j].class);
}
}
}
if(firstrevtimestamp === "") firstrevtimestamp = FS.getAttribute("timestamp");
}
FS = FS.nextSibling;
if(!FS) break;
}
if(warning.length>0) {
var iconcontainer = document.createElement('span');
iconcontainer.className = "UserWarningsIcons";
lastLink.parentNode.insertBefore(iconcontainer, lastLink.nextSibling);
for(var a=0,l=warning.length;a<l;a++){
var icon = document.createElement('span');
icon.innerHTML = warning[a];
if(classes[a]) lrcAddClass(tr1, classes[a]);
iconcontainer.appendChild(icon);
}
iconcontainer.appendChild(lrcXUWrazwarningslink(data.user, firstrevtimestamp, iconcontainer));
if(lrcMakeParam("lrcXUWColorRecentWarning")) {
lastLink.style.color = lrcMakeParam("lrcXUWColorRecentWarning");
}
} else if(revisions.length > 0 && lrcMakeParam("lrcXUWColorRecentTalk")) {
lastLink.style.color = lrcMakeParam("lrcXUWColorRecentTalk");
}
};
window.lrcTalkPageCallback = function(xmlreq, data) {
var tr1 = document.getElementById(data.tr1id);
if (!tr1) return;
var lastLink = lrcXUWGetUserLink(tr1);
if(!lastLink) return;
var page = xmlreq.responseXML.getElementsByTagName('page')[0];
if (!page.getAttribute('pageid')) {
if (lrcMakeParam("lrcXUWColorNoTalk")) lastLink.style.color = lrcMakeParam("lrcXUWColorNoTalk");
return;
}
var revisions = xmlreq.responseXML.getElementsByTagName('rev');
if (revisions.length == 0) return;
var firstrevtimestamp = revisions[0].getAttribute("timestamp");
var warning = [];
var classes = [];
var XUWMessages = lrcUserWarningsMessages_Custom;
if(XUWMessages.length===0) XUWMessages = Custom_lrcUserWarningsMessages;
if(XUWMessages.length===0) XUWMessages = lrcUserWarningsMessages;
for(var i = 0, l=revisions.length; i < l; i++) {
var comment = revisions[i].getAttribute('comment');
if (!comment) continue;
for (var j = 0; j < XUWMessages.length; j++) {
if((XUWMessages[j].regex).test(comment.unhtmlize())){
warning.push(lrcMakeIcon(XUWMessages[j].image, {before:' '}));
classes.push(XUWMessages[j].class);
}
}
}
if(warning.length>0) {
var iconcontainer = document.createElement('span');
iconcontainer.className = "UserWarningsIcons";
lastLink.parentNode.insertBefore(iconcontainer, lastLink.nextSibling);
for(var a=0,l=warning.length;a<l;a++){
var icon = document.createElement('span');
icon.innerHTML = warning[a];
if(classes[a]) lrcAddClass(tr1, classes[a]);
iconcontainer.appendChild(icon);
}
iconcontainer.appendChild(lrcXUWrazwarningslink(data.user, firstrevtimestamp, iconcontainer));
if(lrcMakeParam("lrcXUWColorRecentWarning")) {
lastLink.style.color = lrcMakeParam("lrcXUWColorRecentWarning");
}
} else if(revisions.length > 0 && lrcMakeParam("lrcXUWColorRecentTalk")) {
lastLink.style.color = lrcMakeParam("lrcXUWColorRecentTalk");
}
}
window.lrcXUWrazwarningslink = function(user, firstrevtimestamp, iconcontainer){
var linksup = document.createElement('sup');
var link = document.createElement('a');
link.innerHTML = lrcMakeText('lrcXUWRAZ_Text');
link.title = lrcMakeText('lrcXUWRAZ_Title').split("$1").join(firstrevtimestamp);
link.href = "javascript:;";
link.onclick = function(){ lrcXUWrazwarnings(user, firstrevtimestamp, iconcontainer); }
linksup.appendChild(document.createTextNode(" "));
linksup.appendChild(link);
return linksup;
}
window.lrcXUWrazwarnings = function(user, firstrevtimestamp, iconcontainer){
LiveRC_Config["UserWarnings_rvend"][user] = (parseInt(firstrevtimestamp.replace(/\D/g, ""))+1);
iconcontainer.parentNode.removeChild(iconcontainer);
}
window.lrcUserInfosCallback = function(xmlreq, data){
var tr1 = document.getElementById(data.tr1id);
if (!tr1) return;
var td2 = tr1.getElementsByTagName("td")[0];
if(!td2) return;
var U = xmlreq.responseXML.getElementsByTagName('u')[0];
if(!U) return;
var username = U.getAttribute("name");
if(username != data.user) return;
var OldEditCount = document.getElementById(data.tr1id+"editcount");
if(OldEditCount) return;
var usereditcount = U.getAttribute("editcount");
var userregistration = U.getAttribute("registration");
var G = U.getElementsByTagName("g");
var usergroups = [];
for(var a=0,l=G.length;a<l;a++){
usergroups.push(G[a].firstChild.nodeValue);
}
var editcounticon = lrcMakeIcon("EditCount3", {after:' – '});
var usereditcount = parseInt(usereditcount, {after:' – '});
if(usereditcount<10){
editcounticon = lrcMakeIcon("EditCount0", {after:' – '});
}else if(usereditcount<50){
editcounticon = lrcMakeIcon("EditCount1", {after:' – '});
}else if(usereditcount<500){
editcounticon = lrcMakeIcon("EditCount2", {after:' – '});
}
editcounticon = editcounticon.split("$1").join(usereditcount);
var SpanEditcount = document.createElement('span');
SpanEditcount.id = data.tr1id+"editcount";
SpanEditcount.innerHTML = editcounticon;
td2.insertBefore(SpanEditcount, td2.firstChild);
UpdateGroups(usergroups, tr1, username);
}
window.UpdateGroups = function(usergroups, tr1, username){
for(var group in LiveRC_Config["UserGroupList"]){
if(usergroups.indexOf(group)!=-1 && typeof(LiveRC_Config["UserGroupList"][group])==="object" && typeof(LiveRC_Config["UserGroupList"][group].list)==="object" && LiveRC_Config["UserGroupList"][group].list.indexOf(username) == -1){
LiveRC_Config["UserGroupList"][group].list.push(username);
lrcAddClass(tr1, lrcGetGroupClass(tr1, lrcGetGroupState(username, [])));
}
}
}
window.lrcIPContribsCallback = function(xmlreq, data){
var tr1 = document.getElementById(data.tr1id);
if (!tr1) return;
var lastLink = lrcXUWGetUserLink(tr1);
var td2 = tr1.getElementsByTagName("td")[0];
if(!lastLink || !td2) return;
var UContribs = xmlreq.responseXML.getElementsByTagName('usercontribs')[0];
if(!UContribs) return;
var Items = UContribs.getElementsByTagName('item');
var contribs = data.contribs + Items.length;
var othercontribs = UContribs.getElementsByTagName('continue')[0];
if(othercontribs){
var continueparam = othercontribs.getAttribute('uccontinue');
var requestIPContribs = lrcGetAPIURL({format:'xml',action:'query',list:'usercontribs',ucuserprefix:data.user,uclimit:LiveRC_Config["UserInfos"].APIlimit,uccontinue:continueparam,continue:''});
wpajax.http({url: requestIPContribs,
onSuccess: lrcIPContribsCallback,
user: data.user,
tr1id: data.id,
contribs: contribs
});
}else{
var editcounticon = lrcMakeIcon("EditCount3", {after:' – '});
if(contribs<10){
editcounticon = lrcMakeIcon("EditCount0", {after:' – '});
}else if(contribs<50){
editcounticon = lrcMakeIcon("EditCount1", {after:' – '});
}else if(contribs<500){
editcounticon = lrcMakeIcon("EditCount2", {after:' – '});
}
editcounticon = editcounticon.split("$1").join(contribs);
var SpanEditcount = document.createElement('span');
SpanEditcount.innerHTML = editcounticon;
td2.insertBefore(SpanEditcount, td2.firstChild);
}
}
LiveRC_AddHook("AfterRC", lrcXUWHook);
// Personnalisation auto
window.defineCustomUserWarningsMessages = function(UserWarningsMessages){
Custom_lrcUserWarningsMessages = UserWarningsMessages;
}
LiveRC_AddHook("AfterFillParamPanel", function(){
LiveRC_ManageParams_Fill(lrcUserWarningsMessages, "lrcUserWarningsMessages", "defineCustomUserWarningsMessages", true);
});
/* ************************************************************************************************************************************************ */
} // FIN IF
//</source>