Utente:Salvatore Ingala/Orfanizza
Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione
Vai alla ricerca
Se hai installato il Monobook standard e la Commandline, questa pagina contiene una procedura semiautomatica per orfanizzare i redirect.
/*
*/ cmnParseXML = function(xml){ if (window.ActiveXObject){ //IE var d = new ActiveXObject("Microsoft.XMLDOM"); d.async = "false"; d.loadXML(xml); } else { //Non-IE var p = new DOMParser(); var d = p.parseFromString(xml,"text/xml"); } return d.documentElement; }; //Preleva un parametro dall'url cmnGetParam = function(name){ var h = window.location.href; var qmarkpos = h.indexOf('?'); if (qmarkpos == -1) return ''; var a = h.substring(qmarkpos+1).split('&'); for(var i = 0; i < a.length; i++){ var eq = a[i].indexOf('='); if (eq == -1) continue; if(a[i].substring(0, eq) == name) return a[i].substring(eq + 1); } return ''; }; /*** Abstract Data Types ***/ /* Queue */ cmnQueue = function() { this._array = new Array(); } cmnQueue.prototype.push = function(elem){ this._array.push(elem); }; cmnQueue.prototype.pop = function(){ return this._array.shift(); }; cmnQueue.prototype.empty = function(){ return this._array.length == 0; }; cmnQueue.prototype.size = function(){ return this._array.length; }; cmnQueue.prototype.size = function(){ return this._array.length; }; cmnQueue.prototype.front = function(){ return this._array[0]; }; cmnQueue.prototype.back = function(){ return this._array[this._array.length - 1]; }; /**/ /*
*/ // Grazie a [[:en:User:Topaz]] netXMLHttpRequest = function(){ var xmlhttpobj; if (window.XMLHttpRequest) xmlhttpobj = new XMLHttpRequest(); else{ try{ xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ xmlhttpobj = null; } } } return xmlhttpobj; }; // Scarica il contenuto di una pagina e passa il risultato alla callback function netGetPage = function(callback, url){ var http_request = netXMLHttpRequest(); http_request.open("GET", url, true); http_request.onreadystatechange = function (){ if (http_request.readyState == 4){ if (http_request.status == 200){ callback(http_request.responseText); } } }; http_request.send(null); }; //Get a random page (via Special:Randompage) netGetRandomPage = function(callback){ netGetPage(function(res){ var start = res.indexOf("<title>") + "<title>".length; var end = res.indexOf(" - Wikipedia</title>"); callback(res.substring(start, end)); }, mw.config.get('wgServer')+mw.config.get('wgScriptPath')+"/index.php?title=Special:Randompage"); }; //Get the list of the newpages (via Special:Newpages) netGetNewpages = function(callback, limit){ function decodeHTMLEntities(str) { var tmp = document.createElement("textarea"); tmp.innerHTML = str.replace(/</g,"<").replace(/>/g,">"); return tmp.value; } netGetPage(function(res){ var re = /title="([^"]+)">cron<\/a>/g; var match; var result = new Array(); while(match = re.exec(res)) result.push(decodeHTMLEntities(match[1])); callback(result); }, mw.config.get('wgServer')+mw.config.get('wgScriptPath')+"/index.php?title=Special:Newpages" + (limit ? "&limit=" + limit : "")); }; /**/ /*
*/ //Try to get the XMLHttpRequest object, depending on the browser //returns: the XMLHttpRequest object, or null if something went wrong qrXMLHttpRequest = function(){ var xmlhttpobj; if (window.XMLHttpRequest) xmlhttpobj = new XMLHttpRequest(); else{ try{ xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ xmlhttpobj = null; } } } return xmlhttpobj; }; //Interface for the query API //mandatory params: //*callback: the callback function to receive the result //*query: the string portion of the URL with the query (that is, after the '?') qrSendQuery = function(callback, query){ var q = mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/query.php?' + query; var http_request = qrXMLHttpRequest(); http_request.open("GET", query, true); http_request.onreadystatechange = function (){ if (http_request.readyState == 4){ if (http_request.status == 200){ res = eval("(" + http_request.responseText + ")"); callback(res); } http_request = null; } }; http_request.send(null); }; //Get the contributions of an user //mandatory params: //*callback: the callback function to receive the result //*user: the username //optional params: //*limit: the number of contributions to get //*comments: boolean, true to get the summaries of the contributions //*start: timestamp of the earliest entry //*end: timestamp of the latest entry qrGetUserContribs = function(callback, user, limit, comments, top, start, end){ if (!user) return; var q = mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/query.php?what=usercontribs&titles=User:' + encodeURIComponent(user); if (limit) q += "&uclimit=" + limit; if (comments) q += "&ucomments"; if (top) q += "&uctop=" + top; if (start) q += "&ucstart=" + start; if (end) q += "&ucend=" + end; q += "&format=json"; var cb = function(result){ var contribs; for(var x in result.pages){ contribs = result.pages[x].contributions; break; //ci interessa solo il primo } callback(contribs, result); }; qrSendQuery(cb, q); }; //Get the backlinks of a page //mandatory params: //*callback: the callback function to receive the result //*title: the title of the page //optional params: //*filter: 'redirects', 'nonredirects', 'existing' or 'all' //*namespace: namespace id //*limit: how many entries will return //*contfrom: from which point to continue qrGetBacklinks = function(callback, title, limit, filter, namespace, contfrom){ if (!title) return; var q = mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/query.php?what=backlinks&titles=' + encodeURIComponent(title); if (filter) q += "&blfilter=" + filter; if (typeof namespace != 'undefined') q += "&blnamespace=" + namespace; if (limit) q += "&bllimit=" + limit; if (contfrom) q += "&blcontfrom=" + contfrom; q += "&format=json"; var cb = function(result){ var contribs; for(var x in result.pages){ var backlinks = result.pages[x].backlinks; break; } callback(backlinks, result); }; qrSendQuery(cb, q); }; /**/ /*
*/ window.rfWait = function(){ var allclosed = true; for(var i = 0; i < 10; i++) if (rfWnd[i]) if (rfWnd[i].closed == false) allclosed = false; if (allclosed) rfApplyCommand(); else setTimeout('rfWait();', 200); }; window.rfApplyCommand = function(){ if (rfPagelist.length == 0){ alert("Operazione completata!"); return; } document.getElementById('rfStartButton').disabled = true; var limit = document.getElementById('rfMultipleCheckbox').checked ? 10 : 1; rfWnd = new Array(); var command = rfCreateCommand(); for(var i = 0; i < limit; i++){ if (rfPagelist.length == 0) break; var current_bl = rfPagelist.shift(); rfWnd[i] = window.open(wgServer + wgScriptPath + "/index.php?title=" + encodeURIComponent(current_bl) + "&action=edit" + "&fakeaction=runcommand&command=" + encodeURIComponent(command)); } setTimeout('rfWait();', 100); }; window.rfMakeLink = function(article){ return "<a href='/wiki/" + article + "'>" + article + "</a>"; }; window.rfCreateGui = function(){ var ihtml = '<h3>Orfanizzazione redirect</h3>' + '<br>' + 'Questa pagina consente di orfanizzare in maniera semi-automatica un ' + 'redirect, correggendo i link entranti con la destinazione.<br>' + '<br>' + 'Link errato: ' + rfMakeLink(rfWrong) +'<br>' + 'Link corretto: ' + rfMakeLink(rfCorrect) + '<br>' + '<br>' + 'Elenco delle pagine da correggere nel namespace principale:<br>' + '<br>' + '<div id="rfPageList">' + '<ol start="1">'; for(var i in rfPagelist) ihtml += '<li>' + rfMakeLink(rfPagelist[i]) + '</li>'; ihtml += '</div>'; ihtml += '</ol><br><br>'; ihtml += '<div id="rfInputObjects">'; ihtml += '<input type="checkbox" id="rfMultipleCheckbox" value="0">10 alla volta</input><br><br>'; ihtml += '<input type="checkbox" id="rfProperNoun" value="0">Nome proprio (iniziale sempre maiuscola)</input><br>'; ihtml += '<input type="checkbox" id="rfAvoidPipedLinks" value="0">Evita i piped link<br><br>'; ihtml += '<input type="button" id="rfStartButton" value="Inizia" onclick="rfStart()"/><br>'; ihtml += '</div>'; document.getElementById('bodyContent').innerHTML = ihtml; }; window.rfCreateCommand = function(){ var properNoun = document.getElementById('rfProperNoun').checked; var avoidPipes = document.getElementById('rfAvoidPipedLinks').checked; var rfWrongL = rfWrong.charAt(0).toLowerCase() + rfWrong.substring(1); var rfWrongU = rfWrong.charAt(0).toUpperCase() + rfWrong.substring(1); var rfCorrectL = rfCorrect.charAt(0).toLowerCase() + rfCorrect.substring(1); var rfCorrectU = rfCorrect.charAt(0).toUpperCase() + rfCorrect.substring(1); if (properNoun) rfCorrectL = rfCorrectU; //usa sempre la correzione in maiuscolo if (avoidPipes){ var fixUnpiped = "replace#\\[\\[[ ]*" + rfWrongL + "[ ]*\\]\\]" + "#" + "[[" + rfCorrectL + "]]" + "#" + "replace#\\[\\[[ ]*" + rfWrongU + "[ ]*\\]\\]" + "#" + "[[" + rfCorrectU + "]]" ; } else { var fixUnpiped = "replace#\\[\\[[ ]*(" + rfWrongL + ")[ ]*\\]\\]" + "#" + "[[" + rfCorrectL + "|$1]]" + "#" + "replace#\\[\\[[ ]*(" + rfWrongU + ")[ ]*\\]\\]" + "#" + "[[" + rfCorrectU + "|$1]]" ; } var fixPiped = "replace#\\[\\[[ ]*" + rfWrongL + "[ ]*\\|(.+)\\]\\]" + "#" + "[[" + rfCorrectL + "|$1]]" + "#" + "replace#\\[\\[[ ]*" + rfWrongU + "[ ]*\\|(.+)\\]\\]" + "#" + "[[" + rfCorrectU + "|$1]]"; //TODO: distinguere quelli Anchored e Piped? var fixAnchored = "replace#\\[\\[[ ]*" + rfWrongL + "(\\x23)" + "#" + "[[" + rfCorrectL + "$1#" + "replace#\\[\\[[ ]*" + rfWrongU + "(\\x23)" + "#" + "[[" + rfCorrectU + "$1"; var t = rfCorrectL + "|" + rfCorrectU; var fixTautologies = "replace#\\[\\[(" + t + ")\\|(" + t + ")\\]\\]#[[$2]]"; return fixUnpiped + "#" + fixPiped + "#" + fixAnchored + "#" + fixTautologies + "#" + "setsummary#orfanizzazione redirect#setminor#1#" + "diff"; }; window.rfStart = function(){ if (rfPagelist.length == 0){ alert("Nessuna correzione da effettuare"); return; } rfApplyCommand(); }; window.rfInit = function(){ rfWrong = decodeURIComponent(cmnGetParam('wrong')); rfCorrect = decodeURIComponent(cmnGetParam('correct')); if(!rfWrong || !rfCorrect) return; //GLOBALI rfPagelist = new Array(); qrGetBacklinks(function(res){ for(var x in res) rfPagelist.push(res[x]['*']); rfCreateGui(); }, rfWrong, 100, 'all', 0); }; if(__COMMANDLINE_LOADED) rfInit(); else alert("Questo strumento necessita della Commandline, che attualmente non risulta installata."); /**/