MediaWiki:Monobook.js/UserWikiInfo.js

// / 	tmpl: ' {editavatar} ' + ' User:{U} &#124; Talk [+] &#124; Blog {email} &#124; Contributions {group}'+ ' ',	emailtmpl: ' &#124; Email ', contrtmpl: '{U} has {c} edits on the {fe}  <span class="psact pslvl{l}" style="width:{r}%;"> </a> ', datefm: '{d} de {m} de {y}', editavatar: 'Change avatar</a>', months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], groupseparator: ', ', groups: { bureaucrat: 'Bureaucrat</a>', sysop: 'Administratora>', rollback: 'Rollback</a>', },	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 == 'User_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'), '_'))), userinfo.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 != ) {			userinfo.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 (i) {					g += userinfor.groupseparator;				}				g += (userinfo.groups[groups[i]] || groups[i]);			}			grouptext = userinfo.grouptmpl.replace(new RegExp('\\{g\\}', 'g'), g);		}		$('#bodyContent').prepend(			userinfo.tmpl.replace('{email}', (emailable ? userinfo.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) ? userinfoeditavatar : )).replace( new RegExp('\\{group\\}'), grouptext)); // Avatar var img = new Image; userinfo.avatarImg = img; img.onload = userinfo.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+'/'+userinfo.avatarWidth.toString+'px-'+avatar; // Contribs userinfo.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', userinfo.contribsData); }	},	avatarLoaded: function { var img = userinfo.avatarImg; var h = img.height, w = img.width; if (h < 1) return; if (h > userinfo.avatarHeight) { img.style.height = userinfo.avatarHeight+'px'; }		$('#userinfo').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 = userinfo.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 = userinfo.datefm.replace('{d}', d.getDate).replace('{m}', userinfo.months[d.getMonth]).replace('{y}', d.getFullYear); $('#userinfo').children('.contribdetails').eq(0).append(			userinfo.contrtmpl.replace(new RegExp('\\{U\\}', 'g'), userinfo.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)); } };
 * 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
 * /var userinfo = {
 * /var userinfo = {

$(userinfo.init); //