User:Grandiosarceus/UserWikiInfo.js

// /* A JavaScript implementation of the SHA family of hashes, as defined in FIPS * PUB 180-2 as well as the corresponding HMAC implementation as defined in * FIPS PUB 198a * * Version 1.3 Copyright Brian Turek 2008-2010 * Distributed under the BSD License * See http://jssha.sourceforge.net/ for more information * * Several functions taken from Paul Johnson */ (function{var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotl=function(x,n){return(x<>>(32-n))},parity=function(x,y,z){return x^y^z},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA1=function(f,g){var W=[],a,b,c,d,e,T,i,t,appendedMessageLength,H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];f[g>>5]|=0x80<<(24-(g%32));f[(((g+65)>>9)<<4)+15]=g;appendedMessageLength=f.length;for(i=0;i(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA1(keyWithIPad.concat(this.strToHash),512+this.strBinLen);retVal=coreSHA1(keyWithOPad.concat(retVal),672);return(d(retVal))}};window.jsSHA=jsSHA});

/* var UserWikiInfo = { tmpl: ' {editavatar} ' + ' Usuario:{U} &#124; Discusión [+] &#124; Blog {email} &#124; Contribuciones</a> {group}'+ ' ',	emailtmpl: ' &#124; Enviar correo</a> ', contrtmpl: '{U} ha realizado {c} ediciones desde el {fe}  <span class="psact pslvl{l}" style="width:{r}%;"> </a> ', grouptmpl: ' &#124; Grupos: {g} ', datefm: '{d} de {m} de {y}', editavatar: 'Cambiar avatar</a>', months: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'], groupseparator: ', ', groups: { bureaucrat: 'burócrata</a>', sysop: 'administrador</a>', rollback: 'reversor</a>', 'fb-user': false },	avatarWidth: 100, // Initial width avatarHeight: 75, // Max height avatarImg: null, username: null, firstEdit: null, init: function { var u = null, infoURL = wgServer+wgScriptPath+'/api.php?action=query&list=users|usercontribs|allusers&ususers={u}&usprop=groups|editcount|registration|emailable&ucuser={u}&uclimit=1&ucdir=newer&ucprop=timestamp&aufrom={u}&auprop=&aulimit=1&smaxage=3600&maxage=3600&format=json'; if (window.wgNamespaceNumber == -1 && window.wgCanonicalSpecialPageName == 'Contributions') { var cbu = $('#user'); if (cbu.exists && cbu.get(0).checked) { u = cbu.parent.children('input[name=target]').eq(0).val; }		} else if (window.wgCanonicalNamespace == 'User' || window.wgCanonicalNamespace == 'User_talk' || window.wgCanonicalNamespace == 'Usuario_Blog') { u = window.wgTitle; var sl = u.indexOf('/'); if (sl != -1) { u = u.substr(0, sl); }		}		if (!u) return; if (u.search(new RegExp('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$')) != -1) return; // IP		$.getJSON(infoURL.replace(new RegExp('\\{u\\}','g'), encodeURIComponent(u.replace(new RegExp(' ','g'), '_'))), UserWikiInfo.dataRecv); },	dataRecv: function(data) { var q = data.query; if (q.users.length == 0 || typeof q.users[0].missing != 'undefined') return; var u = q.users[0].name, editcount = (q.users[0].editcount||0), groups = q.users[0].groups, emailable = (typeof q.users[0].emailable == 'string'), firstedit = (q.usercontribs.length == 0 ?  : q.usercontribs[0].timestamp), userid = q.allusers[0].id, grouptext = ; u.replace(new RegExp('\<', 'g'), '&lt;').replace(new RegExp('\>', 'g'), '&gt;').replace(new RegExp('"', 'g'), '&quot;');		if (firstedit != ) {			UserWikiInfo.firstEditDate = new Date(Date.UTC(firstedit.substr(0,4), parseInt(firstedit.substr(5,2),10)-1, firstedit.substr(8,2)));		}		if (groups && groups.length > 0) {			var g = ;			for (var i = 0; i < groups.length; i++) {				if (UserWikiInfo.groups[groups[i]] === false) {					continue;				}				if (g.length) {					g += UserWikiInfo.groupseparator;				}				g += (UserWikiInfo.groups[groups[i]] || groups[i]);			}			if (g.length) {				grouptext = UserWikiInfo.grouptmpl.replace(new RegExp('\\{g\\}', 'g'), g);			}		}		$('#bodyContent').prepend(			UserWikiInfo.tmpl.replace('{email}', (emailable ? UserWikiInfo.emailtmpl : '')).replace(				new RegExp('\\{U\\}', 'g'), u).replace(				new RegExp('\\{u\\}', 'g'), encodeURIComponent(u.replace(new RegExp(' ', 'g'), '_'))).replace( new RegExp('\\{editavatar\\}'), ((window.wgUserName && window.wgUserName == u) ? UserWikiInfo.editavatar : '')).replace( new RegExp('\\{group\\}'), grouptext)); // Avatar var img = new Image; UserWikiInfo.avatarImg = img; img.onload = UserWikiInfo.avatarLoaded; var avatar = userid.toString+'.png'; var shaObj = new jsSHA(userid.toString, 'ASCII'); var hash = shaObj.getHash('HEX'); img.alt = 'avatar'; img.src = 'http://images1.wikia.nocookie.net/common/avatars/thumb/'+hash.substr(0,1)+'/'+hash.substr(0,2)+'/'+avatar+'/'+UserWikiInfo.avatarWidth.toString+'px-'+avatar; // Contribs UserWikiInfo.username = u;		if (editcount > 0) { $.getJSON(wgServer+wgScriptPath+'/api.php?action=parse&text=&title=User:'+encodeURIComponent(u)+'&prop=text&smaxage=3600&maxage=3600&format=json', UserWikiInfo.contribsData); }	},	avatarLoaded: function { var img = UserWikiInfo.avatarImg; var h = img.height, w = img.width; if (h < 1) return; if (h > UserWikiInfo.avatarHeight) { img.style.height = UserWikiInfo.avatarHeight+'px'; }		$('#UserWikiInfo').children('.useravatar').eq(0).find('img').eq(0).replaceWith(img); },	contribsData: function(data) { var text = data.parse.text['*'], c = 0, cu = 0, acontr = [], rate = 0, lvl = 0, d = UserWikiInfo.firstEditDate, fe = ''; if (text.indexOf('class="new"') != -1 || text.indexOf(' ') == -1) return; // Template does not exist/sanity check text = text.substring(3, text.indexOf(' ')).replace(new RegExp('[\.,]', 'g'), ''); acontr = text.split('|'); for (var i = 0; i < acontr.length; i++) { var n = parseInt(acontr[i], 10); if (isNaN(n)) return; if (i == 0) { c = n;			} else { cu += n;			} }		if (c == 0) return; rate = parseInt((cu*10000/c), 10)/100; lvl = parseInt((cu/c*4), 10); fe = UserWikiInfo.datefm.replace('{d}', d.getDate).replace('{m}', UserWikiInfo.months[d.getMonth]).replace('{y}', d.getFullYear); $('#UserWikiInfo').children('.contribdetails').eq(0).append(			UserWikiInfo.contrtmpl.replace(new RegExp('\\{U\\}', 'g'), UserWikiInfo.username).replace( new RegExp('\\{c\\}', 'g'), c).replace( new RegExp('\\{cu\\}', 'g'), cu).replace( new RegExp('\\{l\\}', 'g'), lvl).replace( new RegExp('\\{r\\}', 'g'), rate).replace( new RegExp('\\{fe\\}', 'g'), fe)); } };
 * UserWikiInfo v1.5: Una colección de enlaces útiles relacionados con el usuario que aparece en contribuciones, página de usuario y discusión, con recuento de ediciones y avatar, para Monobook
 * Copyright (C) 2010 Jesús Martínez Novo (User:Ciencia Al Poder)
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version

$(UserWikiInfo.init); //