MediaWiki:Gadget-OnlineAdmins.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
final change |
||
(29 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
// Localized en version |
|||
// About this program: |
|||
// Create portlet link |
|||
// This program was done with implementation of codes, and combined codes of both Alexander Misel and Vjudge1 |
|||
// Program was used for English Wikipedia only. For Chinese Wikipedia, please check in the Chinese Box |
|||
// Version: 1.2 |
|||
// Create Portlet Link |
|||
var portletLinkOnline = mw.util.addPortletLink( |
var portletLinkOnline = mw.util.addPortletLink( |
||
'p-personal', |
'p-personal', |
||
'#', |
'#', |
||
' |
'Admins', |
||
't- |
't-onlineadmin', |
||
'Seek |
'Seek help from admins.', |
||
'', |
'', |
||
'#pt-userpage' |
'#pt-userpage' |
||
Line 15: | Line 12: | ||
var rcstart, rcend, time; |
var rcstart, rcend, time; |
||
var users = []; |
var users = []; |
||
var admins = [], |
var admins = [], bureaucrats = [], stewards = []; |
||
var api = new mw.Api(); |
var api = new mw.Api(); |
||
Line 21: | Line 18: | ||
$(portletLinkOnline).click(function(e) { |
$(portletLinkOnline).click(function(e) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
users = []; |
users = []; |
||
var usersExt = []; |
var usersExt = []; |
||
admins = []; |
admins = []; |
||
// Recent edits within 30 minutes |
|||
rollbackers = []; |
|||
patrollers = []; |
|||
// Recent Changes Detector |
|||
time = new Date(); |
time = new Date(); |
||
rcstart = time.toISOString(); |
rcstart = time.toISOString(); |
||
time.setMinutes(time.getMinutes() - |
time.setMinutes(time.getMinutes() - 30); |
||
rcend = time. |
rcend = time.toISOString(); |
||
//API:RecentChanges |
|||
//API:RecentChanges, Remove Bots and others |
|||
api.get({ |
api.get({ |
||
format: 'json', |
format: 'json', |
||
Line 63: | Line 55: | ||
Array.prototype.push.apply(users, usersExt); |
Array.prototype.push.apply(users, usersExt); |
||
// |
// Removing Duplicate Usernames |
||
users = $.unique(users.sort()); |
users = $.unique(users.sort()); |
||
Line 69: | Line 61: | ||
var mark = function(data) { |
var mark = function(data) { |
||
$.each(data.query.users, function(i, user) { |
$.each(data.query.users, function(i, user) { |
||
// 找到管理员,去除adminbot |
|||
if ($.inArray('bot', user.groups) === -1) { |
if ($.inArray('bot', user.groups) === -1) { |
||
if ($.inArray('sysop', user.groups) > -1) { |
if ($.inArray('sysop', user.groups) > -1) { |
||
admins[i] = user.name; |
admins[i] = user.name; |
||
} |
|||
if ($.inArray('rollbacker', user.groups) > -1) { |
|||
rollbackers[i] = user.name; |
|||
} |
|||
if ($.inArray('patroller', user.groups) > -1) { |
|||
patrollers[i] = user.name; |
|||
} |
|||
if ($.inArray('reviewer', user.groups) > -1) { |
|||
reviewers[i] = user.name; |
|||
} |
} |
||
} |
} |
||
Line 95: | Line 77: | ||
}).done(mark)); |
}).done(mark)); |
||
} |
} |
||
// Check User Group |
|||
$.when.apply($, promises).done(function () { |
$.when.apply($, promises).done(function () { |
||
// Remove Users without User Group |
|||
var filter = function(n) { |
var filter = function(n) { |
||
return n; |
return n; |
||
}; |
}; |
||
admins = admins.filter(filter); |
admins = admins.filter(filter); |
||
rollbackers = rollbackers.filter(filter); |
|||
patrollers = patrollers.filter(filter); |
|||
var userlink = function(user) { |
var userlink = function(user) { |
||
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<'); |
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"> |
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 Administrators:</b></p></center>']; |
|||
if (admins.length + rollbackers.length + patrollers.length > 0) { |
|||
var adminsstring = ['<p>Helpers Online</p>']; |
|||
if (admins.length > 0) { |
if (admins.length > 0) { |
||
adminsstring.push('<p style="word-break:break-all;">There are currently ' + admins.length + ' |
adminsstring.push('<p style="word-break:break-all;">There are currently ' + admins.length + ' Administrator(s) <br> online:'); |
||
$.each(admins, function(i, e) { |
$.each(admins, function(i, e) { |
||
adminsstring.push(userlink(e)); |
adminsstring.push(userlink(e)); |
||
Line 122: | Line 96: | ||
adminsstring.push('</p>'); |
adminsstring.push('</p>'); |
||
} |
} |
||
mw.notify($(adminsstring.join(''))); |
|||
} else { |
|||
mw.notify('Sorry! There are 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 = [], stewards = []; |
|||
var api = new mw.Api(); |
|||
// Bind click handler |
|||
if (patrollers.length > 0) { |
|||
$(portletLinkOnline).click(function(e) { |
|||
adminsstring.push('<p style="word-break:break-all;">There are currently' + patrollers.length + 'Patrollers Online:'); |
|||
e.preventDefault(); |
|||
$.each(patrollers, function(i, e) { |
|||
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>Online Bureaucrats:</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(userlink(e)); |
||
}); |
}); |
||
adminsstring.push('</p>'); |
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', |
|||
'#', |
|||
'Stewards', |
|||
't-onlinesteward', |
|||
'Seek help from stewards.', |
|||
'', |
|||
'#pt-userpage' |
|||
); |
|||
var rcstart, rcend, time; |
|||
var users = []; |
|||
var admins = [], bureaucrats = [], stewards = []; |
|||
var api = new mw.Api(); |
|||
// Bind click handler |
|||
if (rollbackers.length > 0) { |
|||
$(portletLinkOnline).click(function(e) { |
|||
adminsstring.push('<p style="word-break:break-all;">There are currently' + rollbackers.length + 'Rollbackers Online:'); |
|||
e.preventDefault(); |
|||
$.each(rollbackers, function(i, e) { |
|||
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>Online Stewards:</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(userlink(e)); |
||
}); |
}); |
||
adminsstring.push('</p>'); |
adminsstring.push('</p>'); |
||
} |
} |
||
mw.notify($(adminsstring.join(''))); |
mw.notify($(adminsstring.join(''))); |
||
} else { |
} else { |
||
mw.notify('There are |
mw.notify('Sorry! There are no Stewards online.'); |
||
} |
} |
||
}).fail(function () { |
}).fail(function () { |
||
mw.notify('Error |
mw.notify('Error 404'); |
||
}); |
}); |
||
}); |
}); |
Latest revision as of 06:41, 2 August 2024
// Localized en version
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Admins',
't-onlineadmin',
'Seek help from admins.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], 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 Administrators:</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 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 = [], 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>Online Bureaucrats:</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',
'#',
'Stewards',
't-onlinesteward',
'Seek help from stewards.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var admins = [], bureaucrats = [], 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>Online Stewards:</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');
});
});
});
});