MediaWiki:Monobook.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 = '  ' +		' User:{U} &#124; Talk Page [+] {email} &#124; Contributions {group}'+		' ',	_emailtmpl = ' &#124; Send Email</a> ',	_contrtmpl = '{U} has made {c} edits since {fe}  <span class="psact pslvl{l}" style="width:{r}%;"> </a> ',	_grouptmpl = ' &#124; {g} ', _nosuchuser = 'User does not exist', _editavatar = 'Change avatar', _editavatardescription = 'Select an image from your PC to use as your avatar. Should be square (same height as width). If the image is elongated cut, so it can be deformed. It is recommended that you edit first in an image editing program to have these dimensions. The optimal size is 150x150px.', _previewsaveavatar = 'This is the image you uploaded and will be used as an avatar. If you agree, confirm the change. Note that the above may still appear for a while because your browser has saved the old version. If you see the image in accepting you just uploaded is that everything went well.', _saveavatar = 'Apply the new avatar', _datefm = '{d} de {m} de {y}', _months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], _groupseparator = ', ', _groups = { bureaucrat: 'Bureaucrat</a>', sysop: 'Administrator</a>', rollback: 'Rollback</a>', chatmoderator: 'Keeper of the Nightosphere</a>•', 'fb-user': false, '*': false, user: false, autoconfirmed: false, emailconfirmed: false },	_avatarWidth = 100, // Initial width _avatarHeight = 100, // Max height _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' || mw.config.get('wgCanonicalNamespace', '') == 'Usuario_Blog') { 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.allusers[0].id.toString; 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); }		// Avatar if (!_isIP) { if (mw.config.get('wgUserName', '') == u) { $('</a>').text(_editavatar).appendTo($('#UserWikiInfo').find('.useravatar').eq(0)).bind('click', function {					//$.loadJQueryAIM(_changeAvatar);					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; }		// Contribs _username = u;		_userid = userid; //if (editcount > 0) -- En wikia puede salir editcount a 0 aun habiendo editado 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; // 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 = _datefm.replace('{d}', d.getDate).replace('{m}', _months[d.getMonth]).replace('{y}', d.getFullYear); $('#UserWikiInfo').children('.contribdetails').eq(0).append(			_contrtmpl.replace(new RegExp('\\{U\\}', 'g'), _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)); },	// Método para mostrar el form de cambio de avatar. Si el argumento es string es por algun error _changeAvatar = function(o) { var bFirstDialog = false; if (!_dlg) { bFirstDialog = true; _dlg = $(' '); } else { _dlg.find('input').unbind.end.html(''); }		if (typeof o == 'string') { $(' ').text(o).appendTo(_dlg); }		$(' ').text(_editavatardescription).appendTo(_dlg); _dlg.append(			'<form action="/wikia.php?controller=UserProfilePage&method=onSubmitUsersAvatar&format=json&userId='+_userid+'" method="post" enctype="multipart/form-data">' +			'<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'); }		// Fetch the rest of user data 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); //