Utilisateur:Dr Brains/WatchNewUsers.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.if(mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgTitle') == "WatchNewUsers"){
// mw.config.get('wgCanonicalSpecialPageName') = "WatchNewUsers";
mw.loader.load('//bits.wikimedia.org/skins-1.5/common/edit.js?283-16&action=raw&ctype=text/javascript');
mw.loader.load('//bits.wikimedia.org/skins-1.5/common/diff.js?283-17&action=raw&ctype=text/javascript');
mw.loader.load('//fr.wikipedia.org/w/index.php?title=Utilisateur:Dr Brains/BotFramework.js&action=raw&ctype=text/javascript');
importStylesheetURI('http://fr.wikipedia.org/w/index.php?title=User:Dr Brains/WatchNewUsers.css&action=raw&ctype=text/css');
importStylesheetURI('http://bits.wikimedia.org/skins-1.5/common/diff.css?283-17&action=raw&ctype=text/css');
addOnloadHook(WatchNewUsers_InitPage);
}else{
addOnloadHook(WatchNewUsers_AddLink);
}
var WatchNewUsers_ContentId;
var WatchNewUsers_Text_Title = "Suivi des nouveaux inscrits";
function WatchNewUsers_AddLink(){
var ToolBox = document.getElementById("p-tb");
if(!ToolBox) return;
var UlBox = ToolBox.getElementsByTagName('ul')[0];
var NewLi = document.createElement('li');
NewLi.id = "t-watchnewusers";
var NewA = document.createElement('a');
NewA.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join("Special:WatchNewUsers");
NewA.innerHTML = WatchNewUsers_Text_Title;
NewLi.appendChild(NewA);
UlBox.appendChild(NewLi);
}
function WatchNewUsers_InitPage(){
var Title = document.getElementsByTagName('title')[0];
Title.innerHTML = WatchNewUsers_Text_Title;
var Content = document.getElementById("bodyContent");
if(!Content) Content = document.getElementById("mw_contentheader");
if(!Content) Content = document.getElementById("article");
if(!Content) return;
WatchNewUsers_ContentId = Content.id;
while(Content.firstChild){ Content.removeChild(Content.firstChild); }
var Titre = document.getElementsByTagName('h1')[0]
Titre.innerHTML = WatchNewUsers_Text_Title;
var WaitingCenter = document.createElement('center');
WaitingCenter.id = "WNU_Running";
var WaitingImage = document.createElement('img');
WaitingImage.src = "http://upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif";
WaitingImage.width = 150;
WaitingImage.height = 150;
var WaitingSpan = document.createElement('span');
WaitingSpan.id = "WNU_RunningWait";
WaitingSpan.innerHTML = "Veuillez patienter";
var WaitingSpanInfo = document.createElement('span');
WaitingSpanInfo.id = "WNU_RunningSpan";
WaitingCenter.appendChild(WaitingImage);
WaitingCenter.appendChild(document.createElement('br'));
WaitingCenter.appendChild(WaitingSpan);
WaitingCenter.appendChild(document.createElement('br'));
WaitingCenter.appendChild(WaitingSpanInfo);
Content.appendChild(WaitingCenter);
WatchNewUsers_GetLog();
}
var WatchNewUsers_UserArray = new Array();
var WatchNewUsers_UserTimestampArray = new Array();
function WatchNewUsers_GetLog(UserContinue){
if(!UserContinue) UserContinue = "";
var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&list=logevents&letype=newusers&lelimit='+BotFramework_APILimit+UserContinue;
BotFrameworkRequestGET(url, WatchNewUsers_ShowLog, true);
}
var WatchNewUsers_Text_RunningSpanText = "$1 utilisateurs récupérés ; Timestamp = $2";
function WatchNewUsers_ShowLog(Req, FuncParams){
var ResultXML = Req.responseXML;
if(!ResultXML) return;
var FourDaysUpdateOK = false;
var Items = ResultXML.getElementsByTagName('item');
for(var a=0,l=Items.length;(a<l&&!FourDaysUpdateOK);a++){
var ThisItem = Items[a];
var User = ThisItem.getAttribute('user');
var Timestamp = ThisItem.getAttribute('timestamp');
var Time = BotFramework_compareDates(Timestamp);
if(Time>(1000*60*60*24*4)){
FourDaysUpdateOK = true;
}else{
WatchNewUsers_UserArray.push(User);
WatchNewUsers_UserTimestampArray.push(Timestamp);
}
}
var RunningSpan = document.getElementById("WNU_RunningSpan");
if(RunningSpan){
var LastTimestamp = BotFramework_ManageAPITimestamp(WatchNewUsers_UserTimestampArray[(WatchNewUsers_UserTimestampArray.length-1)]);
var LastDate = BotFramework_AddZero(LastTimestamp[2])+"-"+BotFramework_AddZero(LastTimestamp[1])+"-"+LastTimestamp[0]+" "+BotFramework_AddZero(LastTimestamp[3])+":"+BotFramework_AddZero(LastTimestamp[4])+":"+BotFramework_AddZero(LastTimestamp[5]);
var NumberOfNewUsers = WatchNewUsers_UserArray.length;
RunningSpan.innerHTML = WatchNewUsers_Text_RunningSpanText.split('$1').join(NumberOfNewUsers).split('$2').join(LastDate);
}
var CanContinue = ResultXML.getElementsByTagName('query-continue')[0];
if(CanContinue && !FourDaysUpdateOK){
var ContinueID = "lestart=" + CanContinue.firstChild.getAttribute('lestart');
WatchNewUsers_GetLog(ContinueID);
}else{
WatchNewUsers_CreateForm();
}
}
var WatchNewUsers_Text_Legend = "Nouveaux utilisateurs ayant moins de quatre jours d'ancienneté";
var WatchNewUsers_Text_UserTitle = "Voir les contributions de l'utilisateur « $1 »";
var WatchNewUsers_AutoShowContribs = true;
function WatchNewUsers_CreateForm(){
var Content = document.getElementById(WatchNewUsers_ContentId);
if(!Content) return;
var Running = document.getElementById("WNU_Running");
if(Running&& !WatchNewUsers_AutoShowContribs) Running.parentNode.removeChild(Running);
var Fieldset = document.createElement('fieldset');
var Legend = document.createElement('legend');
Legend.innerHTML = WatchNewUsers_Text_Legend;
var Ol = document.createElement('ol');
Ol.id = "WNU_Ol";
for(var a=0,l=WatchNewUsers_UserArray.length;a<l;a++){
if(!WatchNewUsers_UserArray[a] || !WatchNewUsers_UserTimestampArray[a]) continue;
var Li = document.createElement('li');
Li.id = "WNU_Li"+a;
Li.className = "WNU_Li";
var TimestampSpan = document.createElement('span');
TimestampSpan.className = "TimestampSpan";
TimestampSpan.id = "WNU_TS"+a;
var Timestamp = BotFramework_ManageAPITimestamp(WatchNewUsers_UserTimestampArray[a]);
var Time = BotFramework_AddZero(Timestamp[2])+"-"+BotFramework_AddZero(Timestamp[1])+"-"+Timestamp[0]+" "+BotFramework_AddZero(Timestamp[3])+":"+BotFramework_AddZero(Timestamp[4])+":"+BotFramework_AddZero(Timestamp[5])
TimestampSpan.innerHTML = Time;
var UserLink = document.createElement('a');
UserLink.id = "WNU_User"+a;
UserLink.innerHTML = WatchNewUsers_UserArray[a];
UserLink.title = WatchNewUsers_Text_UserTitle.split('$1').join(WatchNewUsers_UserArray[a]);
UserLink.href = "javascript:WatchNewUsers_GetUserContribs(\'" + WatchNewUsers_UserArray[a].replace(/'/g, "ZAPPOSTROPHE") + "\', "+a+");";
Li.appendChild(document.createTextNode(" "));
Li.appendChild(TimestampSpan);
Li.appendChild(document.createTextNode(" — "));
Li.appendChild(UserLink);
Ol.appendChild(Li);
}
Fieldset.appendChild(Legend);
Fieldset.appendChild(Ol);
Content.appendChild(Fieldset);
if(WatchNewUsers_AutoShowContribs){ WatchNewUsers_GetAllContribs()}
}
function WatchNewUsers_GetAllContribs(){
var Content = document.getElementById(WatchNewUsers_ContentId);
var AllLis = document.getElementsByTagName('li');
for(var a=0,l=AllLis.length;a<l;a++){
if(!$(AllLis[a]).hasClass("WNU_Li")) continue;
var Li = AllLis[a];
var Index = WatchNewUsers_getIndex(Li);
var UserName = Li.getElementsByTagName('a')[0].innerHTML;
WatchNewUsers_GetUserContribs(UserName, Index);
}
}
function WatchNewUsers_GetUserContribs(UserName, LiIndex, ContribsArray, ContribContinue){
var OldContribs = document.getElementById("WNU_UserContribs"+LiIndex);
if(OldContribs){
if(OldContribs.style.display=="none"){
OldContribs.style.display = "block";
}else{
OldContribs.style.display = "none";
}
return;
}
if(!ContribsArray) ContribsArray = new Array();
if(!ContribContinue) ContribContinue = "";
var Param = new Array();
Param["Index"] = LiIndex;
Param["Contribs"] = ContribsArray;
Param["User"] = UserName;
UserName = UserName.replace(/'/g, "ZAPPOSTROPHE").replace(/&/g, "%26")
var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&list=usercontribs&uclimit='+BotFramework_APILimit+'&ucprop=ids|title|timestamp|comment|parsedcomment|size|flags|tags&ucuser=' + UserName + ContribContinue;
BotFrameworkRequestGET(url, WatchNewUsers_UserContribs, Param);
}
var WatchNewUsers_FormatUserContribs = "$TIME — $PAGE ($DIFF|$HIST) ($SIZE octets) – $NEW$BOT$MINOR « $COMMENT » + $LAST";
function WatchNewUsers_UserContribs(Req, Param){
var Contribs = Param["Contribs"];
var Index = Param["Index"];
var UserName = Param["User"];
var ResultXML = Req.responseXML;
if(!ResultXML) return;
var RunningSpan = document.getElementById("WNU_RunningSpan");
if(RunningSpan){
var ThisInformation = "User : "+ UserName + " - " +(Index+1) + "/" + WatchNewUsers_UserArray.length;
var RunningSpanContribs = document.getElementById("WNU_RunningSpanContribs");
if(RunningSpanContribs){
RunningSpanContribs.innerHTML = ThisInformation;
}else{
RunningSpan.innerHTML += '<br /><span id="WNU_RunningSpanContribs">'+ThisInformation+'</span>';
}
}
var Items = ResultXML.getElementsByTagName('item');
for(var a=0,l=Items.length;a<l;a++){
var ThisLiIndex = Index + "_" + Contribs.length;
var ThisItem = Items[a];
var Page = ThisItem.getAttribute('title');
var Last = ( ThisItem.getAttribute("top")=="" ? "<b>Dernière</b>" : "" );
var New = ( ThisItem.getAttribute("new")=="" ? "<b>N</b>" : "" );
var Minor = ( ThisItem.getAttribute("minor")=="" ? "<b>m</b>" : "" );
var Bot = ( ThisItem.getAttribute("bot")=="" ? "<b>b</b>" : "" );
var ParsedComment = ( ThisItem.getAttribute("parsedcomment") ? BotFramework_Parse(ThisItem.getAttribute("parsedcomment"), true, false) : "" );
var Size = parseInt(ThisItem.getAttribute('size'));
var Timestamp = BotFramework_ManageAPITimestamp(ThisItem.getAttribute('timestamp'));
var Oldid = ThisItem.getAttribute('revid');
var ThisRevision = WatchNewUsers_FormatUserContribs;
ThisRevision = ThisRevision.split('$TIME').join(BotFramework_AddZero(Timestamp[2])+"-"+BotFramework_AddZero(Timestamp[1])+"-"+Timestamp[0]+" "+BotFramework_AddZero(Timestamp[3])+":"+BotFramework_AddZero(Timestamp[4])+":"+BotFramework_AddZero(Timestamp[5]));
ThisRevision = ThisRevision.split('$PAGE').join(WatchNewUsers_ManagePageLink(Page));
ThisRevision = ThisRevision.split('$DIFF').join(WatchNewUsers_ManageHistoryLink(Page, "hist"));
ThisRevision = ThisRevision.split('$HIST').join(WatchNewUsers_ManagePageDiffLink(Page, Oldid, "prev", "diff"));
ThisRevision = ThisRevision.split('$NEW').join(New);
ThisRevision = ThisRevision.split('$MINOR').join(Minor);
ThisRevision = ThisRevision.split('$BOT').join(Bot);
ThisRevision = ThisRevision.split('$SIZE').join(Size);
ThisRevision = ThisRevision.split('$COMMENT').join(ParsedComment);
ThisRevision = ThisRevision.split('$LAST').join(Last);
Contribs.push(ThisRevision);
}
var CanContinue = ResultXML.getElementsByTagName('query-continue')[0];
if(CanContinue){
var ContinueID = "ucstart=" + CanContinue.firstChild.getAttribute('ucstart');
WatchNewUsers_GetUserContribs(UserName, Index, Contribs, ContinueID);
}else{
var Li = document.getElementById("WNU_Li"+Index);
if(Li){
if(!Contribs[0]){
Li.parentNode.removeChild(Li);
}else{
var Ul = document.createElement('ul');
Ul.id = "WNU_UserContribs"+Index
for(var a=0,l=Contribs.length;a<l;a++){
var NewLi = document.createElement('li');
NewLi.id = "WNU_UserContrib_"+Index + "_"+a;
NewLi.innerHTML = Contribs[a];
Ul.appendChild(NewLi);
}
Li.appendChild(Ul);
}
}
var Running = document.getElementById("WNU_Running");
if(Running&& Index==(WatchNewUsers_UserArray.length-1)) Running.parentNode.removeChild(Running);
}
}
function WatchNewUsers_ManagePageLink(Page, Text, Title){
Page = Page.replace(/_/g, " ");
if(!Text) Text = Page;
if(!Title) Title = Page;
var EncodedPage = encodeURIComponent(Page);
var PageLink = '<a class="WNU_PageLink" href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(EncodedPage) + '" title="' + Title + '">' + Text + '</a>';
return PageLink;
}
function WatchNewUsers_ManageHistoryLink(Page, Text, Title){
Page = Page.replace(/_/g, " ");
if(!Text) Text = Page;
if(!Title) Title = Page;
var EncodedPage = encodeURIComponent(Page);
var PageLink = '<a class="WNU_PageLink" href="' + mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + EncodedPage + '&action=history" title="' + Title + '">' + Text + '</a>';
return PageLink;
}
function WatchNewUsers_ManagePageDiffLink(Page, Oldid, Diff, Text, Title){
Page = Page.replace(/_/g, " ");
if(!Diff) Diff = "prev";
if(!Text) Text = Page;
if(!Title) Title = Page;
var EncodedPage = encodeURIComponent(Page);
var PageLink = '<a class="WNU_DiffLink" href="' + mw.config.get('wgServer') + mw.config.get('wgScript')+ '?title=' + EncodedPage + '&oldid=' + Oldid + '&diff=' + Diff +'" title="' + Title + '">' + Text + '</a>';
return PageLink;
}
function WatchNewUsers_getIndex( Element ){
return parseInt(Element.id.replace(/[^0-9]/g, ""));
}