Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* Article average generator (median and mean), version [0.0.1]Originally from: http://en.wikipedia.org/wiki/User:Splarka/genaverage.jsIf you go to: http://en.wikipedia.org/wiki/MediaWiki:Generatestats (generic placeholder for page to generate input)A textarea is generated where you can enter page names and submit for median/mean stats. Each usage appends a <pre> to the page.Test version using API.*/(function(){mw.log.warn('User:Splarka/genaverage.js script disabled due to [[phab:T72470]]. Please fix!');if(wgPageName=='MediaWiki:Generatestats'&&wgAction=='view')addOnloadHook(genstatsInit)functiongenstatsInit(){vargen=(document.getElementById('bodyContent'))?document.getElementById('bodyContent'):document.getElementById('content')if(!gen)return;varinfo=document.createElement('pre');info.style.padding='.5em';info.style.backgroundColor='#ddffdd';info.style.border='1px solid black';info.appendChild(document.createTextNode('Enter a list of pages you wish to take the arithmatic mean and median of.\nPlease have only one page title per newline.\nNOTES:\n * The following characters are stripped and ignored: # < > [ ] | { }\n * Pages unedited in several years have no size information available, so are skipped.'));gen.appendChild(info);varta=document.createElement('textarea');ta.setAttribute('id','genstatbox');ta.style.height='30em';ta.style.width='100%';gen.appendChild(ta);varbt=document.createElement('input');bt.setAttribute('type','button');bt.setAttribute('value','Generate');bt.setAttribute('id','genstatsbutton');addClickHandler(bt,genstatsStart);gen.appendChild(bt);}functiongenstatsStart(){varbt=document.getElementById('genstatsbutton');bt.setAttribute('disabled','disabled');bt.setAttribute('value','fetching...');varta=document.getElementById('genstatbox');ta.value=ta.value.replace(/(\#|\<|\>|\[|\]|\||\{|\})/g,'');ta.value=ta.value.replace(/[ ]{2,}/g,' ');tav=ta.value.split('\n');vartitles='';for(vari=0;i<tav.length;i++){varttl=tav[i].replace(/[ ]/g,'_');if(ttl!='_'&&ttl!='')titles+=encodeURIComponent(ttl)+'|'}titles=titles.replace(/\|$/g,'')varurl=wgScriptPath+'/api.php?action=query&prop=revisions&rvprop=size&format=json&callback=genstats&titles='+titles;if(url.length>4000){alert('Too many pages entered');}else{varscriptElem=document.createElement('script');scriptElem.setAttribute('src',url);scriptElem.setAttribute('type','text/javascript');document.getElementsByTagName('head')[0].appendChild(scriptElem);}}functiongenstats(obj){varbt=document.getElementById('genstatsbutton');bt.removeAttribute('disabled');bt.setAttribute('value','Generate');if(!obj['query']||!obj['query']['pages'])returnvarpages=obj['query']['pages'];varnum=0;vartsize=0;varmed=[];vartxt='';vargoodtitles='';varbadtitles='';for(variinpages){if(pages[i].missing==undefined){varsz=pages[i].revisions[0].size;if(sz!=undefined){num++;tsize+=parseInt(sz);med[med.length]=sz;goodtitles+=' * [['+pages[i].title+']] ('+sz+' bytes)\n';}else{badtitles+=' * [['+pages[i].title+']] (too old)\n';}}else{badtitles+=' * [['+pages[i].title+']] (no such page)\n';}}if(num>0){varmean=Math.round(tsize/num*100)/100;txt+='Number of counted pages: '+num+'\n';txt+=' mean = '+mean+' bytes\n';med=med.sort(sortbynum);if(num%2==1){varmedian=med[num/2-.5];}else{varmedian=(med[num/2-1]+med[num/2])/2;}txt+=' median = '+median+' bytes\n\n';txt+='Counted pages: \n'+goodtitles+'\n';txt+='Uncounted pages: \n'+badtitles+'\n';}else{txt+='No valid page titles found\n';}varpre=document.createElement('pre');pre.appendChild(document.createTextNode(txt));bt.parentNode.appendChild(pre);}functionsortbynum(a,b){x=parseInt(a);y=parseInt(b);return((x<y)?-1:((x>y)?1:0));}});