User:Hairr/userheader.js

//Modified from http://es.pokemon.wikia.com/wiki/MediaWiki:Common.js/Clases/UserWikiInfo.js (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});(function($){var _tmpl='  '+' Usuario:{U} &#124; Discusión [+] {email} &#124; Contribuciones {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} ',_nosuchuser='El usuario no existe',_editavatar='Cambiar avatar',_editavatardescription='Selecciona una imagen desde tu PC para utilizar como tu avatar. Debería tener forma cuadrada (misma altura que anchura). Si la imagen es alargada se recortará, por lo que puede quedar deformada. Es recomendable que la edites primero en un programa de edición de imágenes para que tenga estas dimensiones. El tamaño óptimo es 150x150px.',_previewsaveavatar='Esta es la imagen que has subido y que se usará como avatar. Si estás de acuerdo, confirma el cambio. Ten en cuenta que podría seguir mostrándose el anterior por un tiempo debido a que tu navegador ha guardado la versión antigua. Si al aceptar ves la imagen que acabas de subir es que todo ha ido bien.',_saveavatar='Aplicar el nuevo avatar',_datefm='{d} de {m} de {y}',_months=['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre'],_groupseparator=', ',_groups={bureaucrat:'bureaucrat</a>',sysop:'administrator</a>',rollback:'rollback</a>',custodian:'custodian</a>','fb-user':false,'*':false,user:false,autoconfirmed:false,emailconfirmed:false},_avatarWidth=100,_avatarHeight=100,_avatarImg=null,_isIP=false,_userid=null,_username=null,_firstEdit=null,_dlg=null,_fetchinginfo=false,_formdata=null,_init=function{var u=null,qParams={action:'query',list:'users|usercontribs',usprop:'groups|editcount|registration|emailable',uclimit:'1',ucdir:'newer',ucprop:'timestamp',smaxage:'3600',maxage:'3600'},api=new mw.Api;if(mw.config.get('wgNamespaceNumber',0)==-1&&mw.config.get('wgCanonicalSpecialPageName',)=='Contributions'){var cbu=$('#user');if(cbu.length==1&&cbu.get(0).checked){u=cbu.parent.children('input[name=target]').eq(0).val;}}else if(mw.config.get('wgCanonicalNamespace',)=='User'||mw.config.get('wgCanonicalNamespace',)=='User_talk'){u=mw.config.get('wgTitle',);var sl=u.indexOf('/');if(sl!=-1){u=u.substr(0,sl);}}if(!u)return;qParams.ususers=qParams.ucuser=u;if(u.search(new RegExp('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$'))!=-1){_isIP=true;}$('#bodyContent').prepend(' ');api.get(qParams,{ok:_dataRecv});},_dataRecv=function(data){var q=data.query,exists=true,uwi=$('#UserWikiInfo');if(typeof q.users[0].missing!='undefined')exists=false;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=-1,grouptext=,userlinktext=,api=new mw.Api;if(!_isIP&&exists){userid=q.users[0].userid.toString;}u.replace(new RegExp('\<','g'),'&lt;').replace(new RegExp('\>','g'),'&gt;').replace(new RegExp('"','g'),'&quot;');if(firstedit!=){_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(_groups[groups[i]]===false){continue;}if(g.length){g+=_groupseparator;}g+=(_groups[groups[i]]||groups[i]);}if(g.length){grouptext=_grouptmpl.replace(new RegExp('\\{g\\}','g'),g);}}uwi.append(_tmpl.replace('{email}',(emailable?_emailtmpl:)).replace(new RegExp('\\{U\\}','g'),u).replace(new RegExp('\\{u\\}','g'),mw.util.wikiUrlencode(u)).replace('{group}',grouptext));uwi.find('.useravatar').children('a').eq(0).attr('href',mw.util.wikiGetlink(((_isIP?(mw.config.get('wgFormattedNamespaces')['-1']+':Contributions/'):(mw.config.get('wgFormattedNamespaces')['2']+':'))+u)));if(!_isIP){uwi.find('.userlink').children('a').eq(0).attr('href',mw.util.wikiGetlink(mw.config.get('wgFormattedNamespaces')['2']+':'+u));}uwi.find('.talklink').children('a').eq(0).attr('href',mw.util.wikiGetlink(mw.config.get('wgFormattedNamespaces')['3']+':'+u));uwi.find('.contribslink').children('a').eq(0).attr('href',mw.util.wikiGetlink(mw.config.get('wgFormattedNamespaces')['-1']+':Contributions/'+u));if(!exists){uwi.children('.contribdetails').eq(0).text(_nosuchuser);}if(!_isIP){if(mw.config.get('wgUserName',)==u){$('</a>').text(_editavatar).appendTo($('#UserWikiInfo').find('.useravatar').eq(0)).bind('click',function{mw.loader.using(['jquery.ui.dialog','jquery.form','jquery.json'],_changeAvatar);return false;});}var img=new Image;_avatarImg=img;img.onload=_avatarLoaded;var avatar=userid+'.png';var hash=(new jsSHA(userid,'ASCII')).getHash('HEX');img.alt='avatar';img.src='http://images1.wikia.nocookie.net/common/avatars/thumb/'+hash.substr(0,1)+'/'+hash.substr(0,2)+'/'+avatar+'/'+_avatarWidth.toString+'px-'+avatar;}_username=u;_userid=userid;var params={action:'parse',text:,title:'User:'+u,prop:'text',disablepp:,smaxage:'3600',maxage:'3600'};api.get(params,{ok:_contribsData});},_avatarLoaded=function{var img=_avatarImg;var h=img.height,w=img.width;if(h<1)return;if(h>_avatarHeight){img.style.height=_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=_firstEditDate,fe=;if(text.indexOf('class="new"')!=-1||text.indexOf(' ')==-1)return;text=text.substring(3,text.indexOf(' ')).replace(new RegExp('[\.,]','g'),);acontr=text.split('|');for(var i=0;i'+'<input type="file" name="UPPLightboxAvatar"/> ').find('input[type="file"]').bind('change',_uploadAvatar);if(bFirstDialog){_dlg.dialog({modal:true,title:_editavatar,width:500});}else{_dlg.dialog('option',{height:'auto'}).dialog('open');}if(!_fetchinginfo&&_formdata===null){$.post('/wikia.php?controller=UserProfilePage&format=json',{method:'getLightboxData',tab:'about',userId:_userid,rand:Math.floor(Math.random*100001)},_fetchResult,'json');}},_fetchResult=function(data){if(data.body){_formdata={};$(data.body).find('#userData').find('input,select').each(function{_formdata[this.name]=this.value;});}_fetchinginfo=false;},_uploadAvatar=function{_dlg.find('form').eq(0).find('input').css('visibility','hidden').after(' ').end.ajaxSubmit({dataType:'json',success:function(data){try{if(data.result.success===true){_dlg.find('input').unbind.end.html(' <img class="useravatar" src="'+data.result.avatar+'" /> ').append($('  ').text(_previewsaveavatar)).append(' <input type="button" name="save" /> ').find('input[name="save"]').val(_saveavatar).bind('click',_submitChanges);_dlg.dialog('option',{height:'auto'}).dialog('open');}else{_changeAvatar(data.result.error);}}catch(e){_changeAvatar(e.message);}},error:function(xhr,status,errMsg){var msg=(status||'');if(msg.length){msg+=': '+errMsg;}else{msg=errMsg;}}})},_submitChanges=function{_dlg.find('input').unbind.attr('disabled','disabled');if(_formdata===null){_changeAvatar('Error: formdata null');}_formdata.avatarData={'file':_dlg.find('img.useravatar').attr('src'),'source':'uploaded','userId':_userid};$.ajax({type:'POST',url:'/wikia.php?controller=UserProfilePage&format=json&method=saveUserData',dataType:'json',data:'userId='+_userid+'&data='+$.toJSON(_formdata),success:_submitComplete,error:function(xhr,t,e){if(t===null&&e!==undefined){t=e.toString+e.stack;}_changeAvatar(t);}});},_submitComplete=function(data){if(data.status=='error'){_changeAvatar(data.errorMsg);}else{var img=$('#UserWikiInfo').find('.useravatar').find('img');var src=img.attr('src');if(src.indexOf('?')==-1){src+='?';}src+=(new Date).getMilliseconds.toString;img.unbind('load').get(0).onload=null;img.attr('src',src);_dlg.dialog('close');}};$(_init);})(jQuery);