MediaWiki:JSScripts/DeluxeHistory

Un article de Wikipèdia, l'enciclopèdia liura.
Salta a la navegació Salta a la cerca

//

  1 /**
  2 * Nom : DeluxeHistory
  3 * Autor : Dake
  4 * Basat sus de còde Ajax de GôTô
  5 * Darrièra mesa a jorn : 21 de novembre de 2007
  6 * Comentaris : 
  7 */
  8 var sysopsDeluxeHistory = null;
  9 var botsDeluxeHistory = null;
 10 
 11 function extractUsers(res) {
 12   pattern = /title\=\"Utilizaire:(.*?)\"/g;
 13   s = "";
 14   while((result = pattern.exec(res)) != null) {
 15     s += result[1] + "||";
 16   }
 17   return s;
 18 }
 19 
 20 function getBots() {
 21   try {
 22     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
 23   } catch (e) { /* menja l'excepcion */ }
 24 
 25   if (!cookies.get("botsDeluxeHistory")) {
 26     ajax.conn.onreadystatechange = function () {
 27     if (ajax.conn.readyState == 4) {
 28       botsDeluxeHistory = extractUsers(ajax.getResult())
 29       // conservat per una setmana
 30       cookies.setWithDelay("botsDeluxeHistory", botsDeluxeHistory, 1000*3600*24*7)
 31       getSysops();
 32     }
 33   }
 34   ajax.sendRequest("//oc.wikipedia.org/w/index.php?title=Special:Listusers&group=bot&limit=500&offset=0&action=raw", "GET", true)
 35   } else {
 36     botsDeluxeHistory = cookies.get("botsDeluxeHistory")
 37     getSysops();
 38   }
 39 }
 40 			
 41 function getSysops() {
 42   try {
 43     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
 44   } catch (e) { /* manja l'excepcion */ }
 45 
 46   if (!cookies.get("sysopsDeluxeHistory")) {
 47     ajax.conn.onreadystatechange = function () {
 48     if (ajax.conn.readyState == 4) {
 49       sysopsDeluxeHistory = extractUsers(ajax.getResult())
 50       // conservat per una setmana
 51       cookies.setWithDelay("sysopsDeluxeHistory", sysopsDeluxeHistory, 1000*3600*24*7)
 52       deluxeHistoryProcess();
 53     }
 54   }
 55   ajax.sendRequest("//oc.wikipedia.org/w/index.php?title=Special:Listusers&group=sysop&limit=500&offset=0&action=raw", "GET", true)
 56   } else {
 57     sysopsDeluxeHistory = cookies.get("sysopsDeluxeHistory")
 58     deluxeHistoryProcess();
 59   }
 60 }
 61 				
 62 // code by Martin Honnen
 63 function getOuterHTML (node) {
 64   if (node.nodeType == 3) {
 65     return node.nodeValue;
 66   } else if (node.nodeType == 1) {
 67     var html = '';
 68     html += '<' + node.nodeName;
 69     for (var a = 0; a < node.attributes.length; a++) html += ' ' + node.attributes[a].nodeName + '="' + node.attributes[a].nodeValue + '"';
 70     if (node.childNodes.length == 0) {
 71       html += ' \/>';
 72     } else {
 73       html += '>';
 74     }
 75     for (var c = 0; c < node.childNodes.length; c++) html += getOuterHTML(node.childNodes[c]);
 76     html += '<\/' + node.nodeName + '>';
 77   }
 78   return html;
 79 }
 80 		
 81 function deluxeHistoryProcess() {					
 82   sysopsList = sysopsDeluxeHistory.split("||")
 83   botsList = botsDeluxeHistory.split("||")		
 84 	
 85   var lis = document.getElementById("pagehistory").getElementsByTagName("li");
 86 
 87   for (i=0; i<lis.length; i++) {
 88     spanNode = lis[i].getElementsByTagName("span");
 89     username = spanNode[0].childNodes[0].childNodes[0].nodeValue;
 90 		
 91     // check l'estatut del contributor
 92     var className = "history-user-normal";
 93 		
 94     // bot ? 
 95     for (j=0;j<botsList.length;j++) {
 96       if (botsList[j] == username) {
 97         className = "history-user-bot";
 98         break;
 99       }
100     }  
101 		
102     // sysop ? 
103     for (j=0;j<sysopsList.length;j++) {
104       if (sysopsList[j] == username) {
105         className = "history-user-sysop";
106         break;
107       }
108     }
109 
110     // ip ? 
111     var ip = /\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}/;
112 		
113     if (ip.exec(username)) {
114       className = "history-user-ip"
115     }
116 
117     // ajust de las icònas
118     specialOp = "";
119     var comment = "";
120 					
121     for (h=0;h<spanNode.length;h++) {
122       if (spanNode[h].getAttribute("class") == "comment") { 
123         comment = getOuterHTML(spanNode[h])
124         break;
125       }
126     }
127 				
128     var regexExpEvents = new Array();
129     regexExpEvents[0] = /((r|R)evocacion|(r|R)v |(R|r)evert|(v|V)andalisme)/;
130     regexExpEvents[1] = /(a restabl(it|ida) (E|e)scafa(t|da)|(s|S)upression)/;
131     regexExpEvents[2] = /((R|r)enommage|a déplacé|a renommé)/;
132     regexExpEvents[3] = /((semi|Semi)proteccion|(P|p)roteccion|(A|a) protegi(t|da)/;
133 		
134     var iconsEvents = new Array();
135     iconsEvents[0] = "//upload.wikimedia.org/wikipedia/commons/thumb/7/77/Crystal_Clear_action_reload.png/20px-Crystal_Clear_action_reload.png"
136     iconsEvents[1] = "//upload.wikimedia.org/wikipedia/commons/thumb/0/0c/Crystal_Clear_action_exit.png/20px-Crystal_Clear_action_exit.png"
137     iconsEvents[2] = "//upload.wikimedia.org/wikipedia/commons/thumb/4/45/Crystal_Clear_action_2rightarrow.png/20px-Crystal_Clear_action_2rightarrow.png"
138     iconsEvents[3] = "//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Crystal_Clear_action_lock.png/20px-Crystal_Clear_action_lock.png"
139 
140     if (comment) {
141       for (k=0;k<regexExpEvents.length;k++) {
142         if (regexExpEvents[k].test(comment)) {
143           imgTag = "<img src=\"" + iconsEvents[k] + "\" />" 
144           specialOp = "<div class=\"" + className + "\" style=\"float: right; vertical-align:top;\">" + 
145           imgTag + "</div>"
146         }
147       }	
148     }
149 		
150     lis[i].innerHTML = "<div class=\"" + className + "\">" + specialOp  + lis[i].innerHTML + "</div>"
151 
152     inputNodes = lis[i].getElementsByTagName("input");
153     for (j=0;j<inputNodes.length;j++) {
154       inputNodes[j].style.visibility='visible';
155     }
156 
157     for (j=0;j<spanNode.length;j++) {
158       if(spanNode[j].getAttribute("class")=="history-user") {
159         spanNode[j].setAttribute("class", className);
160       }
161     }
162   }
163 }
164 
165 if (wgAction == "history") addOnloadHook(getBots);
166 //