ATTENTION: This wiki is fully discontinued. Please access the new wiki at animalcrossing.indyamos.com. You can import some pages from here, but no stubs. No page can be edited expect for sysops. For more information, An Animal Crossing Wiki from Miraheze will be at a new website at animalcrossing.indyamos.com. This will be an enhanced version of this wiki. Please view Special:Diff/57616 for more information.
MediaWiki:Common.js/Classes/UserWikiInfo.js
From Animal Crossing Wiki
Jump to navigationJump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// <pre>
/*
* UserWikiInfo v4.2: A collection of useful user-related links that appears in contributions, user page and discussion, with edit count and avatar, for Monobook
*
* Copyright (C) 2010-2018 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
*
* @requires: mediawiki.api, jquery.ui.dialog, jquery.form
*/
(function($, mw) {
'use strict';
var _tmpl = '<div class="useravatar"><a title="Avatar of {U}"><img src="http://images4.wikia.nocookie.net/__cb20081128203240/messaging/images/thumb/1 /19/Avatar.jpg/50px-Avatar.jpg" width="100" height="100" alt="Avatar" /></a></div>' +
'<span class="userlink"><a title="User Page">User:{U}</a></span> | <span class="talklink"><a title="Discussion Page">Discussion</a> <a href="/index.php? title=User_Discussion:{u}&action=edit&section=new" title ="Leave a new message on the discussion page">[+]</a></span>{email} | <span class="contribslink"><a title="User Contributions">Contributions</a></span>{group}'+
'<div class="contribdetails"></div>',
_emailtmpl = ' | <span class="emaillink"><a href="/wiki/Special:SendEmailUser/{u}" title="Send email to user">Send email</a></span>',
_contrtmpl = '{U} has made {c} edits from {fe}<br /><span class="contenteditcount"><a href="/wiki/Special:Editcount/{U}" title="{cu} edits (the {r}% of the total) have been made in articles, categories, images and templates. See advanced statistics."><span class="psmax"><span class="psact pslvl{l}" style= "width:{r}%;"></span></span></a></span>',
_grouptmpl = ' | <span class="usergroups" title="Groups to which the user belongs">Groups: {g}</span>',
_nosuchuser = 'The user does not exist',
_edit avatar = 'Change avatar',
_editavatardescription = 'Select an image from your PC to use as your avatar. It should have a square shape (same height as width). If the image is elongated, it will be cropped, so it may be deformed. It is recommended that you edit it first in an image editing program so that it has these dimensions. The optimal size is 150x150px.',
_previewsaveavatar = 'This is the image you have uploaded and that will be used as an avatar. If you agree, confirm the change. Keep in mind that the previous one could continue to be displayed for a while because your browser has saved the old version. If when you accept you see the image you just uploaded, it's that everything went well.',
_saveavatar = 'Apply the new avatar',
_datefm = '{d} of {m} of {y}',
_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
_groupseparator = ', ',
_groups = {
bureaucrat: '<a href="/wiki/WikiDex:Administrators">bureaucrat</a>',
sysop: '<a href="/wiki/WikiDex:Administrators">administrator</a>',
rollback: '<a href="/wiki/WikiDex:Reversors">reversors</a>',
assistant: '<a href="/wiki/WikiDex:Assistants">assistant</a>',
bot: '<a href="/wiki/WikiDex:Bots">bot</a>',
'fb-user': false,
'*': false,
user: false,
autoconfirmed: false,
emailconfirmed: false,
poweruser: false
},
//_avatarWidth = 100, // Initial width
_avatarHeight = 100, // Max height
_avatarImg = null,
_isIP = false,
_userid = null,
_username = null,
_firstEditDate = null,
_dlg = null,
_fetchinginfo = false,
_formdata = null,
_init = function() {
var u = null, qParams, api, cbu, sl;
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') {
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', '') === 'Blog_User') {
u = mw.config.get('wgTitle', '');
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('<div id="UserWikiInfo"></div>');
api.get(qParams).done(_dataRecv);
},
_dataRecv = function(data) {
var q = data.query, exists = true, $uwi = $('#UserWikiInfo'), u, groups, emailable, firstedit, userid, g, grouptext, api, params;
if (typeof q.users[0].missing ! == 'undefined') {
exists = false;
}
u = q.users[0].name;
groups = q.users[0].groups;
emailable = (typeof q.users[0].emailable === 'string');
firstedit = (q.usercontribs.length === 0 ? '' : q.usercontribs[0].timestamp);
userid = -1;
grouptext = '';
api = new mw.Api();
if (! _isIP && exists) {
//userid = q.allusers[0].id.toString();
userid = q.users[0].userid.toString();
}
u.replace(new RegExp('\<', 'g'), '<').replace(new RegExp('\>', 'g'), '>').replace(new RegExp(' "', 'g'), '"');
if (firstedit ! == '') {
_firstEditDate = new Date(firstedit);
} else {
_firstEditDate = new Date();
}
if (groups && groups.length > 0) {
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 > a').eq(0).attr('href', mw.util.getUrl(((_isIP ? (mw.config.get('wgFormattedNamespaces')['-1' ] + ':Contributions/') : (mw.config.get('wgFormattedNamespaces')['2'] + ':')) + u)));
if (! _isIP) {
$uwi.find('.userlink > a').eq(0).attr('href', mw.util.getUrl(mw.config.get('wgFormattedNamespaces')['2'] + ':' + or));
}
$uwi.find('.talklink > a').eq(0).attr('href', mw.util.getUrl(mw.config.get('wgFormattedNamespaces')['3'] + ':' + or));
$uwi.find('.contribslink > a').eq(0).attr('href', mw.util.getUrl(mw.config.get('wgFormattedNamespaces')['-1'] + ':Contributions /' + u));
if (! exists) {
$uwi.children('.contribdetails').eq(0).text(_nosuchuser);
}
// Contribs
_username = u;
_userid = userid;
//Avatar
//if (! _isIP) {
// $.getJSON('/api/v1/User/Details/', { ids: userid }).success(_wikiaMetadata);
//}
//if ((q.users[0].editcount||0) > 0) -- In wikia you can exit editcount to 0 even if you have edited
params = {
action: 'parse',
text: '{{:MediaWiki:UserWikiInfoContribs}}',
title: 'User:'+u,
prop: 'text',
disablepp: '',
smaxage: '3600',
maxage: '3600'
};
api.get(params).done(_contribsData);
},
_wikiaMetadata = function(data) {
var img;
if (mw.config.get('wgUserName', '') === _username) {
$('<a class="editavatar" href="#">').text(_editavatar).appendTo($('#UserWikiInfo').find('.useravatar').eq(0)).on( 'click', function() {
mw.loader.using(['jquery.ui.dialog', 'jquery.form', 'jquery.json'], _changeAvatar);
return false;
});
}
if (data.items && data.items.length > 0) {
img = new Image();
_avatarImg = img;
img.onload = _avatarLoaded;
img.alt = 'avatar';
img.src = data.items[0].avatar;
}
},
_avatarLoaded = function() {
var img = _avatarImg, h = img.height;
if (h < 1) return;
if (h > _avatarHeight) {
img.style.height = _avatarHeight+'px';
}
$('#UserWikiInfo > .useravatar 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 = '', n;
if (text.indexOf('class="new"') ! == -1 || text.indexOf('<p>') === -1) return; // Template does not exist/sanity check
text = text.substring(3, text.indexOf('</p>')).replace(new RegExp('[\.,]', 'g'), '');
// Sum of each number, separated by pipes
acontr = text.split('|');
for (var i = 0; i < acontr.length; i++) {
n = parseInt(acontr[i], 10);
if (isNaN(n)) return;
if (i === 0) {
c = n;
} else {
cu += n;
}
}
if (c ! == 0) {
// Multiply by 100, convert to int and divide by 100 to round to 2 decimal positions. Multiply by 100 again because it's a %
rate = parseInt((cu*10000/c), 10)/100;
// Level: an integer between 0 and 4 proportional to rate, to allow specific styles applied
lvl = parseInt((cu/c*4), 10);
// Sometimes the sum is greater than 100 (wrong cached data?). Correct it
if (rate > 100) {
rate = 100;
lvl = 4;
}
}
fe = _datefm.replace('{d}', d.getDate()).replace('{m}', _months[d.getMonth()]).replace('{y}', d.getFullYear() );
$('#UserWikiInfo > .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));
},
// Method to show the avatar change form. If the argument is string, it's due to some error
_changeAvatar = function(o) {
var bFirstDialog = false;
if (! _dlg) {
bFirstDialog = true;
_dlg = $('<div id="UserWikiInfoUploadAvatar">');
} else {
_dlg.find('input').off().end().html('');
}
if (typeof or === 'string') {
$('<div class="error">').text(o).appendTo(_dlg);
}
$('<p>').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"/></form>').find('input[type="file"]').on('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('<span class="mw-small-spinner"></span >').end().ajaxSubmit({
dataType: 'json',
success: function(data) {
try {
if(data.result.success === true) {
_dlg.find('input').off().end().html(
'<div style="float:left; margin-right: 10px;"><img class="useravatar" src="'+data.result.avatar+'" /></div>').append(
$('<p>').text(_previewsaveavatar)).append(
'<p><input type="button" name="save" /></p>').find(
'input[name="save"]').val(_saveavatar).on('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').off().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 ),
token: mw.user.tokens.get('editToken')
}
}).done(_submitComplete).fail(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.off('load').get(0).onload = null;
img.attr('src', src);
_dlg.dialog('close');
}
};
$(_init);
})(jQuery, mw);
// </pre>
This content comes from wikidex.net, and attribution must be given to its authors, as specified in the license.
PlagioDex (the FANDOM wiki) is prohibited from using it for repeatedly copying without attribution.