User:Jezhotwells/vector.js

// //This function adds a link to the toolbox which, when clicked, displays the size of the page //and the size of the prose. See the talk page for more details. // //To use this function add User:Dr pda/prosesize.js to your monobook.js // function loadXMLDocPassingTemplate(url,handler, page) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { var req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req) { req.onreadystatechange = function {handler(req, page)}; req.open("GET", url, true); req.send(""); } } function getWikiText(req, page) { // only if req shows "loaded"

importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... response = req.responseXML.documentElement; var rev = response.getElementsByTagName('rev'); if(rev.length > 0){ result = rev[0].getAttribute('size'); if(result > 10240){ result = (result/1024).toFixed(0)+' kB'; } else{ result = result+' B'; } wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: '+result; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); }	 else{ //alert("There was a problem using the Wikipedia Search to find the wiki text size\nEither the search is not working or the correct article did not appear on the first page of results"); wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: Problem getting wiki text size'; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); } } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } } function getFileSize(req, page) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... var fsize = req.responseText.length; window.status = fsize; var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+(fsize/1024).toFixed(0)+' kB'; var output = document.getElementById("document-size-stats"); var prose_html_value = document.getElementById("prose-size-html"); output.insertBefore(total_value,prose_html_value); } else { alert("There was a problem retrieving the XML data:\n" + req.statusText + "\n(" + url + ")"); } } } function getLength(id){ var textLength = 0; for(var i=0;i<id.childNodes.length; i++){ if(id.childNodes[i].nodeName == '#text'){ textLength += id.childNodes[i].nodeValue.length; } else if(id.childNodes[i].id == 'coordinates'){ //special case for °N, °W template } else{ textLength += getLength(id.childNodes[i]); } } return textLength; } function getRefMarkLength(id,html){ var textLength = 0; for(var i=0;i<id.childNodes.length; i++){ if(id.childNodes[i].className == 'reference'){ textLength += (html)? id.childNodes[i].innerHTML.length : getLength(id.childNodes[i]); } } return textLength; } function getDocumentSize{ contentDivName = ''; if(skin == 'monobook' || skin == 'chick' || skin == 'myskin' || skin == 'simple'){ contentDivName = 'bodyContent'; } else if (skin == 'modern'){ contentDivName = 'mw_contentholder'; } else if (skin == 'standard' || skin == 'cologneblue' || skin == 'nostalgia'){ contentDivName = 'article'; } else{ //fallback case; the above covers all currently existing skins contentDivName = 'bodyContent'; } //Same for all skins if previewing page if(wgAction == 'submit') contentDivName = 'wikiPreview'; var bodyContent = document.getElementById(contentDivName); if(document.getElementById("document-size-stats")){ //if statistics already exist, turn them off and remove highlighting var output = document.getElementById("document-size-stats"); var oldStyle = output.className; var pList = bodyContent.getElementsByTagName("p"); for(var i=0;i<pList.length; i++){ if(pList[i].parentNode.id == contentDivName) pList[i].style.cssText = oldStyle; } output.parentNode.removeChild(output); var header = document.getElementById("document-size-header"); header.parentNode.removeChild(header); } else{ var output = document.createElement("ul"); output.id = "document-size-stats"; var prose_html_value = document.createElement("li"); prose_html_value.id = "prose-size-html"; output.appendChild(prose_html_value); var ref_html_value = document.createElement("li"); ref_html_value.id = "ref-size-html"; output.appendChild(ref_html_value); var prose_value = document.createElement("li"); prose_value.id = "prose-size"; output.appendChild(prose_value); output.className = bodyContent.getElementsByTagName("p").item(0).style.cssText; var ref_value = document.createElement("li"); ref_value.id = "ref-size"; output.appendChild(ref_value); var dummy = document.getElementById("siteSub"); dummy.parentNode.insertBefore(output, dummy.nextSibling); var header = document.createElement("span"); header.id = "document-size-header"; header.innerHTML = ' Document statistics: (See here for details.) '; dummy.parentNode.insertBefore(header,output); //File size not well defined for preview mode or section edit if(wgAction != 'submit'){ //If browser supports document.fileSize property (IE) if(document.fileSize){ var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+(document.fileSize/1024).toFixed(0)+' kB'; output.insertBefore(total_value,prose_html_value); } else{ loadXMLDocPassingTemplate(location.pathname,getFileSize,'') } } //Get size of images only if browser supports filesize property (IE) var iList = bodyContent.getElementsByTagName("img"); if(iList.length >0 && iList[0].fileSize){ //Get size of images included in document var image_size = 0; var first_magnify = true; for (var i=0;i<iList.length; i++){ var im = iList[i]; if(im.getAttribute("src").indexOf("magnify-clip.png") != -1){ if(first_magnify){ image_size += im.fileSize*1; first_magnify = false; } } else{ image_size += im.fileSize*1; } } var image_value = document.createElement("li"); image_value.id = "image-size"; image_value.innerHTML='Images: '+(image_size/1024).toFixed(0)+' kB'; output.appendChild(image_value); } //Calculate prose size and size of reference markers ([1] etc) var pList = bodyContent.getElementsByTagName("p"); prose_size = 0; prose_size_html = 0; refmark_size = 0; refmark_size_html = 0; word_count = 0; for(var i=0;i]+)>)/ig,"").split(' ').length para.style.cssText = "background-color:yellow"; } } if((prose_size-refmark_size)>10240){ prose_value.innerHTML='Prose size (text only): '+((prose_size-refmark_size)/1024).toFixed(0)+' kB ('+word_count+' words) "readable prose size"'; } else{ prose_value.innerHTML='Prose size (text only): '+(prose_size-refmark_size)+' B ('+word_count+' words) "readable prose size"'; } if((prose_size_html-refmark_size_html)>10240){ prose_html_value.innerHTML='Prose size (including all HTML code): '+((prose_size_html-refmark_size_html)/1024).toFixed(0)+' kB'; } else{ prose_html_value.innerHTML='Prose size (including all HTML code): '+(prose_size_html-refmark_size_html)+' B'; } //Calculate size of references (i.e. output of ) var rList = bodyContent.getElementsByTagName("ol"); var ref_size = 0; var ref_size_html = 0; for (var i=0; i10240){ ref_value.innerHTML='References (text only): '+((ref_size+refmark_size)/1024).toFixed(0)+' kB'; } else{ ref_value.innerHTML='References (text only): '+(ref_size+refmark_size)+' B'; } if((ref_size_html+refmark_size_html)>10240){ ref_html_value.innerHTML='References (including all HTML code): '+((ref_size_html+refmark_size_html)/1024).toFixed(0)+' kB'; } else{ ref_html_value.innerHTML='References (including all HTML code): '+(ref_size_html+refmark_size_html)+' B'; } //get correct name of article from wikipedia-defined global variables var pageNameUnderscores = wgPageName; var pageNameSpaces = pageNameUnderscores.replace(/_/g,' ') //if page is a permalink, diff, etc don't try to search if(!location.pathname.match('/w/index.php')){ //Get revision size from API var searchURL = wgScriptPath + '/api.php?action=query&prop=revisions&rvprop=size&format=xml&revids=' + wgCurRevisionId; loadXMLDocPassingTemplate(searchURL,getWikiText,pageNameSpaces); } else if(wgAction == 'submit'){ //Get size of text in edit box result = document.getElementById('wpTextbox1').value.length; if(result > 10240){ result = (result/1024).toFixed(0)+' kB'; } else{ result = result+' B'; } wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: '+result; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); } } } $(function { if(wgAction == 'edit' || (wgAction == 'submit' && document.getElementById('wikiDiff')) ){ mw.util.addPortletLink('p-tb', 'javascript:alert("You need to preview the text for the prose size script to work in edit mode.")', 'Page size', 't-page-size', 'Calculate page and prose size', , ); document.getElementById("t-page-size").firstChild.style.cssText = "color:black;" } else if(wgAction == 'view' || wgAction == 'submit' || wgAction == 'purge'){ mw.util.addPortletLink('p-tb', 'javascript:getDocumentSize', 'Page size', 't-page-size', 'Calculate page and prose size', , ); } }); // // User:Lupin/popups.js importScript('User:Lupin/popups.js'); /* Note: After saving, you have to bypass your browser's cache to see the changes. To do this in Firefox/Mozilla/Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R). If you use Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

AzaToth's reversion tools
*/ // importScript('User:AzaToth/twinkle.js'); /*

WikEd, replaces Firefox's text edit window
*/ // install User:Cacycle/wikEd in-browser text editor document.write(' '); /*

Lupin's anti-vandal tools
*/ // Script from User:Lupin/recent2.js document.write(''); /*

Popups
*/ /* User:Lupin/popups.js */ document.write(' '); /**/ /*

Watchlist sorter
Sorts your watchlist by namespace, and also adds spaces for readability. $(function { if (location.href.indexOf('Special:Watchlist') == -1) return; //Are we on a watchlist? //days = document.getElementById('bodyContent').getElementsByTagName('ul'); days = document.evaluate( //Hell knows how it works - found in "Dive into Greasemonkey" "//ul[@class='special']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (d = 0; d < days.snapshotLength; d++) { //For each day day = days.snapshotItem(d); newday = document.createElement('ul'); //This will replace the old listing while ((diffs = day.getElementsByTagName('li')).length > 0) { //Are there any diffs left? //Try to extract the namespace As = diffs[0].getElementsByTagName('a'); if (As[0].innerHTML == 'diff') pagename = As[2].innerHTML; else pagename = As[1].innerHTML; if (pagename.indexOf(':') == -1) namespace = 'Main'; else namespace = pagename.split(':')[0]; //This will fail for articles which contain ":" in name hdrs = newday.getElementsByTagName('h5'); //Get the list of namespace headers hdr = null; for (j=0; j<hdrs.length; j++) //Find the header if (hdrs[j].innerHTML==namespace) { hdr = hdrs[j]; break; } if (hdr==null) { //Not found? Make a new one! hdr = document.createElement('h5'); hdr.innerHTML = namespace; newday.appendChild(hdr); namespacesub = document.createElement('ul'); newday.appendChild(namespacesub); } hdr.nextSibling.appendChild(diffs[0]); //Move the diff } newday.appendChild(document.createElement('hr')); //For readablility day.parentNode.replaceChild(newday,day); importScript('User:Smith609/toolbox.js'); } }); /* Disambiguation lookup script, version [0.2.7b] Originally from: http://en.wikipedia.org/wiki/User:Splarka/dabfinder.js Notes: Operation: This is a bit messy but at the time was the easiest and most thorough way to do it I could think of. Of course, a bot might be much more efficient, but this is handy for quick on-the-fly live checking. To do: var dabnames = new Array; var dabfound = 0; if(wgNamespaceNumber != -1) addOnloadHook(findDABsButton) function findDABsButton { if(!queryString('oldid') && !queryString('diff') && (wgAction == 'view' || wgAction == 'purge')) { mw.util.addPortletLink('p-tb','javascript:findDABs','Find disambiguations','t-dab'); if(queryString('finddab')=='true') findDABs; } mw.util.addPortletLink('p-tb','javascript:findRDRs','Find redirects','t-rdr'); if(queryString('findrdr')=='true') findRDRs; } function findRDRs { appendCSS('.mw-redirect { background-color: #ffff00;}\n#t-rdr:after {content:" (redirects hilighted)"; background-color:#ffff00; }'); } function findDABs { var dab = document.getElementById('t-dab'); if(dab) injectSpinner(dab,'dab'); var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?maxage=86400&smaxage=86400&action=query&prop=links&pllimit=500&tlnamespace=10&indexpageids&format=json&callback=findDABsCB&titles=MediaWiki:Disambiguationspage'; mw.loader.load(url); } function findDABsCB(obj) { if(!obj['query'] || !obj['query']['pages'] || !obj['query']['pageids']) return var links = obj['query']['pages'][obj['query']['pageids'][0]]['links'] if(!links) return for(var i=0;i<links.length;i++) { dabnames.push(links[i]['title']); } findDABsQuery; } function findDABsQuery(qcont) { var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?maxage=300&smaxage=300&action=query&redirects&generator=links&gpllimit=500&prop=templates&tllimit=500&indexpageids&format=json&callback=findDABlinksCB&titles=' + encodeURIComponent(mw.config.get('wgPageName')); if(qcont) url += '&tlcontinue=' + encodeURIComponent(qcont) mw.loader.load(url); } function findDABlinksCB(obj) { var dablinks = new Array; if(!obj['query'] || !obj['query']['pages'] || !obj['query']['pageids']) return appendCSS('.dablink-found {border: 2px solid #00ff00}\n .dablink .dablink-found {border:2px dashed #00ff00}'); var ids = obj['query']['pageids']; var links = new Array for(var i=0;i<ids.length;i++) { var templates = obj['query']['pages'][ids[i]]['templates']; if(!templates) continue for(var j=0;j<templates.length;j++) { var tpl = templates[j]['title']; for(var k=0;k<dabnames.length;k++) { if(tpl == dabnames[k]) { dablinks.push(obj['query']['pages'][ids[i]]['title']); continue; } } } } if(obj['query']['redirects']) { var dablen = dablinks.length;  //don't iterate over additions. var redirects = obj['query']['redirects']; if(redirects) { for(var i=0;i<redirects.length;i++) { for(var j=0;j<dablen;j++) { if(obj['query']['redirects'][i]['to'] == dablinks[j]) { dablinks.push(obj['query']['redirects'][i]['from']); continue; } } } } } var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.body var links = docobj.getElementsByTagName('a') for(var i=0;i<links.length;i++) { for(var j=0;j<dablinks.length;j++) { //to match API: "Foo (bar)" with href: "/wiki/Foo_%28bar%29", have to do some hacky string manipulation //should now work with parenthesis, unicode? var dablink = dablinks[j].replace(/ /g,'_'); var chklink = (links[i].hasAttribute('href')) ? links[i].getAttribute('href', 2).replace(/\#.*/,) :  chklink = chklink.replace(wgArticlePath.replace(/\$1/,),); chklink = decodeURIComponent(chklink); if(chklink == dablink && links[i].className.indexOf('dablink-found') == -1) { links[i].className += ' dablink-found'; dabfound++; } } } var dab = document.getElementById('t-dab'); if(obj['query-continue'] && obj['query-continue']['templates']) { if(dab) { dab.appendChild(document.createElement('br')); dab.appendChild(document.createTextNode('more...')); } findDABsQuery(obj['query-continue']['templates']['tlcontinue']); } else { if(dab) { removeSpinner('dab'); dab.appendChild(document.createElement('br')); if(dabfound > 0) { var span = document.createElement('span'); span.appendChild(document.createTextNode(dabfound + ' links to disambiguation pages found.')); span.className = 'dablink-found'; dab.appendChild(span); } else { dab.appendChild(document.createTextNode('No disambiguation links found.')); } } else { alert(dabfound + ' links to disambiguation pages found.'); } } } function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } } return null; } importScript('User:TheJosh/Scripts/NewPagePatrol.js'); /** Checklinks toolbox item *************************************************** function checklinks{ mw.util.addPortletLink('p-tb', 'http://toolserver.org/~dispenser/cgi-bin/webchecklinks.py?page=' + wgContentLanguage + ':' + wgPageName, 'Check external links', 't-checklinks'); } if(wgIsArticle){ $(checklinks); } importScript('User:Quarl/util.js'); importScript('User:Quarl/wikipage.js'); importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css'); importScript('User:AzaToth/twinkle.js'); importScript('User:Lupin/popups.js'); // see Wikipedia:Tools/Navigation popups importScript('Wikipedia:WikiProject Deletion sorting/delsort.js'); importScript('User:Quarl/wikipage.js');function addToToolbox { if (wgCanonicalNamespace != "Special") { var pTb = document.getElementById("p-tb"); var pRef = pTb.cloneNode(true); var pStats = pTb.cloneNode(true); pRef.id="p-refs"; pRef.innerHTML = " Reference formatting  "; pStats.id="p-stats"; pStats.innerHTML = " Statistics  "; pTb.parentNode.insertBefore(pRef, pTb.nextSibling); pTb.parentNode.insertBefore(pStats, pRef); var escPageName = escape(wgPageName).replace(/\+/g, '%2B').replace(/&/g, '%26').replace(/%u2013/g, '%96'); mw.util.addPortletLink("p-refs", "http://tools.wikimedia.de/~verisimilus/Bot/DOI_bot/doibot.php?edit=toolbar&turbo=1&user="+wgUserName+"&page="+escPageName, 'Automatic (fast)', '', "Add DOIs to citations and fix common formatting errors. Turbo mode!"); mw.util.addPortletLink("p-refs", "http://tools.wikimedia.de/~verisimilus/Bot/DOI_bot/doibot.php?edit=toolbar&slow=1&user="+wgUserName+"&page="+escPageName, 'Automatic (thorough)', '', "Add DOIs to citations and fix common formatting errors"); //mw.util.addPortletLink("p-refs", "http://tools.wikimedia.de/~verisimilus/Scholar/RefTool.php?user="+wgUserName+"&wgPageName="+escPageName, 'Semi-automatic (experimental)', '', "Improve formatting of references – manually approve automatic improvements"); now = new Date; var month = now.getMonth; var thisMonth = (now.getDay > 6); if (thisMonth) month++; if (month == 0) var month=12; else var month = ((month <10)?'0':'') + month; mw.util.addPortletLink("p-stats", "http://stats.grok.se/en/" + now.getFullYear + month + "/"+wgPageName, 'Traffic stats', '', "Traffic to this page " + (thisMonth?'this':'last') + " month"); mw.util.addPortletLink("p-stats", "http://wikidashboard.parc.com/wiki/"+wgPageName, 'Edit history stats', '', "Statistics about the edit history of this page"); } } $(addToToolbox);
 * Uses the API using head/appendchild(script) and callback to avoid ajax.
 * Alt command finds and hilights redirects with simple CSS append (class="mw-redirect").
 * Per http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=37270 we are limited to 500 subtemplates
 * The query-continue seems to work fine even as a generator. Built a re-query system to do this automatically.
 * Adds portlet button (or works with URI parameter &finddab=true)
 * Makes call to MediaWiki:Disambiguationspage links, generates array of these.
 * Makes call to generator=links / prop=templates on page title.
 * Builds array of registered links that link to disambiguation pages (that contain a disambiguation template).
 * Iterates over all  link objects on page, matching any that link to disambiguation, and applies green border.
 * .dablink descendant links are given a dashed border, all other found links are given a solid border.
 * Repeats call with tlcontinue if more than 500 templates have been returned in previous query.
 * test it
 * centralized link list in contentSub?
 * test unicode support
 * Description: Adds an item in toolbox portlet that runs the checklinks tool
 * on the viewed page.
 * Maintainers: User:Dispenser
 * Installation: Copy and paste following code into you /monobook.js
 * User:Dispenser/Link checker/toolbox.js
 * User:Dispenser/Link checker/toolbox.js

importScript('User:Kaldari/wikilove.js');

importScript('User:Smith609/toolbox.js');

importScript('User:Quarl/util.js'); importScript('User:Quarl/wikipage.js'); importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css'); importScript('User:AzaToth/twinkle.js'); importScript('Wikipedia:WikiProject Deletion sorting/delsort.js'); importScript('User:Lupin/popups.js'); // see Wikipedia:Tools/Navigation popups

importScript('User:Shubinator/DYKcheck.js');