MediaWiki:Gadget-OnlineAdmins.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary Tags: Mobile edit Mobile web edit |
mNo edit summary Tag: Reverted |
||
Line 12: | Line 12: | ||
var rcstart, rcend, time; |
var rcstart, rcend, time; |
||
var users = []; |
var users = []; |
||
var admins = [], bureaucrats = [], stewards = []; |
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = []; |
||
var api = new mw.Api(); |
var api = new mw.Api(); |
||
Line 118: | Line 118: | ||
var rcstart, rcend, time; |
var rcstart, rcend, time; |
||
var users = []; |
var users = []; |
||
var admins = [], bureaucrats = [], stewards = []; |
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = []; |
||
var api = new mw.Api(); |
var api = new mw.Api(); |
||
Line 214: | Line 214: | ||
}); |
}); |
||
}); |
}); |
||
// Create portlet link |
|||
var portletLinkOnline = mw.util.addPortletLink( |
|||
'p-personal', |
|||
'#', |
|||
'Non-steward suppressors', |
|||
't-non_steward_suppressor', |
|||
'Seek help from non-steward suppressors.', |
|||
'', |
|||
'#pt-userpage' |
|||
); |
|||
var rcstart, rcend, time; |
|||
var users = []; |
|||
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = []; |
|||
var api = new mw.Api(); |
|||
// Bind click handler |
|||
$(portletLinkOnline).click(function(e) { |
|||
e.preventDefault(); |
|||
users = []; |
|||
var usersExt = []; |
|||
admins = []; |
|||
bureaucrats = []; |
|||
non_steward_suppressors = []; |
|||
stewards = []; |
|||
//Recent edit within 30 minutes |
|||
time = new Date(); |
|||
rcstart = time.toISOString(); |
|||
time.setMinutes(time.getMinutes() - 30); |
|||
rcend = time.toISOString(); |
|||
//API:RecentChanges |
|||
api.get({ |
|||
format: 'json', |
|||
action: 'query', |
|||
list: 'recentchanges', |
|||
rcprop: 'user', |
|||
rcstart: rcstart, |
|||
rcend: rcend, |
|||
rcshow: '!bot|!anon', |
|||
rclimit: 500 |
|||
}).done(function(data) { |
|||
$.each(data.query.recentchanges, function(i, item) { |
|||
users[i] = item.user; |
|||
}); |
|||
api.get({ |
|||
format: 'json', |
|||
action: 'query', |
|||
list: 'logevents', |
|||
leprop: 'user', |
|||
lestart: rcstart, |
|||
leend: rcend, |
|||
lelimit: 500 |
|||
}).done(function(data) { |
|||
$.each(data.query.logevents, function(i, item) { |
|||
usersExt[i] = item.user; |
|||
}); |
|||
Array.prototype.push.apply(users, usersExt); |
|||
users = $.unique(users.sort()); |
|||
var promises = []; |
|||
var mark = function(data) { |
|||
$.each(data.query.users, function(i, user) { |
|||
if ($.inArray('bot', user.groups) === -1) { |
|||
if ($.inArray('non-stewardsuppress', user.groups) > -1) { |
|||
non_steward_suppresors[i] = user.name; |
|||
} |
|||
} |
|||
}); |
|||
}; |
|||
for (var i=0; i<(users.length+50)/50; i++) { |
|||
promises.push(api.get({ |
|||
format: 'json', |
|||
action: 'query', |
|||
list: 'users', |
|||
ususers: users.slice(i*50, (i+1)*50).join('|'), |
|||
usprop: 'groups' |
|||
}).done(mark)); |
|||
} |
|||
$.when.apply($, promises).done(function () { |
|||
var filter = function(n) { |
|||
return n; |
|||
}; |
|||
admins = admins.filter(filter); |
|||
bureaucrats = bureaucrats.filter(filter); |
|||
non_steward_suppressors = non_steward_suppressors.filter(filter); |
|||
stewards = stewards.filter(filter); |
|||
var userlink = function(user) { |
|||
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<'); |
|||
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> '; |
|||
}; |
|||
if (non_steward_suppessors.length > 0) { |
|||
var adminsstring = ['<center><p><b>Non-steward suppressor(s) Online:</b></p></center>']; |
|||
if (non_steward_suppessors.length > 0) { |
|||
adminsstring.push('<p style="word-break:break-all;">There are currently ' + steward(s).length + ' non-steward-suppressor(s) <br>online:'); |
|||
$.each(bureaucrats, function(i, e) { |
|||
adminsstring.push(userlink(e)); |
|||
}); |
|||
adminsstring.push('</p>'); |
|||
} |
|||
mw.notify($(adminsstring.join(''))); |
|||
} else { |
|||
mw.notify('Sorry! There are no non-steward-suppressors online'); |
|||
} |
|||
}).fail(function () { |
|||
mw.notify('Error 404'); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
// Create portlet link |
// Create portlet link |
||
var portletLinkOnline = mw.util.addPortletLink( |
var portletLinkOnline = mw.util.addPortletLink( |
||
Line 226: | Line 337: | ||
var rcstart, rcend, time; |
var rcstart, rcend, time; |
||
var users = []; |
var users = []; |
||
var admins = [], bureaucrats = [], stewards = []; |
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = []; |
||
var api = new mw.Api(); |
var api = new mw.Api(); |
||
Revision as of 00:57, 19 February 2024
// Localized en version
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Find Admins',
't-onlineadmin',
'Seek help from admins.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = [];
var api = new mw.Api();
// Bind click handler
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
admins = [];
// Recent edits within 30 minutes
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
api.get({
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.logevents, function(i, item) {
usersExt[i] = item.user;
});
Array.prototype.push.apply(users, usersExt);
// Removing Duplicate Usernames
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('sysop', user.groups) > -1) {
admins[i] = user.name;
}
}
});
};
for (var i=0; i<(users.length+50)/50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i*50, (i+1)*50).join('|'),
usprop: 'groups'
}).done(mark));
}
$.when.apply($, promises).done(function () {
var filter = function(n) {
return n;
};
admins = admins.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
if (admins.length > 0) {
var adminsstring = ['<center><p><b>Online Admin(s)</b></p></center>'];
if (admins.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + admins.length + ' administrator(s) <br> online:');
$.each(admins, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify('Sorry! There are currently no administrators online');
}
}).fail(function () {
mw.notify('Error 404');
});
});
});
});
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Bureaucrats',
't-onlinebureaucrat',
'Seek help from bureaucrats.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = [];
var api = new mw.Api();
// Bind click handler
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
admins = [];
bureaucrats = [];
stewards = [];
//Recent edit within 30 minutes
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
api.get({
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.logevents, function(i, item) {
usersExt[i] = item.user;
});
Array.prototype.push.apply(users, usersExt);
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('bureaucrat', user.groups) > -1) {
bureaucrats[i] = user.name;
}
}
});
};
for (var i=0; i<(users.length+50)/50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i*50, (i+1)*50).join('|'),
usprop: 'groups'
}).done(mark));
}
$.when.apply($, promises).done(function () {
var filter = function(n) {
return n;
};
admins = admins.filter(filter);
bureaucrats = bureaucrats.filter(filter);
stewards = stewards.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
if (bureaucrats.length > 0) {
var adminsstring = ['<center><p><b>Bureaucrat(s) Online:</b></p></center>'];
if (bureaucrats.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + bureaucrats.length + ' bureaucrat(s) <br>online:');
$.each(bureaucrats, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify('Sorry! There are no bureaucrats online');
}
}).fail(function () {
mw.notify('Error 404');
});
});
});
});
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Non-steward suppressors',
't-non_steward_suppressor',
'Seek help from non-steward suppressors.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = [];
var api = new mw.Api();
// Bind click handler
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
admins = [];
bureaucrats = [];
non_steward_suppressors = [];
stewards = [];
//Recent edit within 30 minutes
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
api.get({
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.logevents, function(i, item) {
usersExt[i] = item.user;
});
Array.prototype.push.apply(users, usersExt);
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('non-stewardsuppress', user.groups) > -1) {
non_steward_suppresors[i] = user.name;
}
}
});
};
for (var i=0; i<(users.length+50)/50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i*50, (i+1)*50).join('|'),
usprop: 'groups'
}).done(mark));
}
$.when.apply($, promises).done(function () {
var filter = function(n) {
return n;
};
admins = admins.filter(filter);
bureaucrats = bureaucrats.filter(filter);
non_steward_suppressors = non_steward_suppressors.filter(filter);
stewards = stewards.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
if (non_steward_suppessors.length > 0) {
var adminsstring = ['<center><p><b>Non-steward suppressor(s) Online:</b></p></center>'];
if (non_steward_suppessors.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + steward(s).length + ' non-steward-suppressor(s) <br>online:');
$.each(bureaucrats, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify('Sorry! There are no non-steward-suppressors online');
}
}).fail(function () {
mw.notify('Error 404');
});
});
});
});
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Stewards',
't-onlinesteward',
'Seek help from stewards.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], non_steward_suppressors = [], stewards = [];
var api = new mw.Api();
// Bind click handler
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
admins = [];
bureaucrats = [];
stewards = [];
//Recent edit within 30 minutes
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
api.get({
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.logevents, function(i, item) {
usersExt[i] = item.user;
});
Array.prototype.push.apply(users, usersExt);
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('steward', user.groups) > -1) {
stewards[i] = user.name;
}
}
});
};
for (var i=0; i<(users.length+50)/50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i*50, (i+1)*50).join('|'),
usprop: 'groups'
}).done(mark));
}
$.when.apply($, promises).done(function () {
var filter = function(n) {
return n;
};
admins = admins.filter(filter);
bureaucrats = bureaucrats.filter(filter);
stewards = stewards.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
if (stewards.length > 0) {
var adminsstring = ['<center><p><b>Steward(s) Online:</b></p></center>'];
if (stewards.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + steward(s).length + ' steward(s) <br>online:');
$.each(bureaucrats, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify('Sorry! There are no stewards online');
}
}).fail(function () {
mw.notify('Error 404');
});
});
});
});