MediaWiki:Gadget-OnlineAdmins.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
m 23 revisions imported
final change
 
(12 intermediate revisions by 3 users not shown)
Line 4: Line 4:
'p-personal',
'p-personal',
'#',
'#',
'Find Admins',
'Admins',
't-onlineadmin',
't-onlineadmin',
'Seek help from admins.',
'Seek help from admins.',
Line 12: Line 12:
var rcstart, rcend, time;
var rcstart, rcend, time;
var users = [];
var users = [];
var admins = [], rollbackers = [], patrollers = [];
var admins = [], bureaucrats = [], stewards = [];
var api = new mw.Api();
var api = new mw.Api();


Line 21: Line 21:
var usersExt = [];
var usersExt = [];
admins = [];
admins = [];
// Recent edits within 15 minutes
// Recent edits within 30 minutes
time = new Date();
time = new Date();
rcstart = time.toISOString();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 15);
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
rcend = time.toISOString();
//API:RecentChanges
//API:RecentChanges
Line 87: Line 87:
};
};
if (admins.length > 0) {
if (admins.length > 0) {
var adminsstring = ['<center><p><b>Online Admins</b></p></center>'];
var adminsstring = ['<center><p><b>Online Administrators:</b></p></center>'];


if (admins.length > 0) {
if (admins.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + admins.length + ' administrators <br> online:');
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 98: Line 98:
mw.notify($(adminsstring.join('')));
mw.notify($(adminsstring.join('')));
} else {
} else {
mw.notify('Sorry! There are currently no administrators online');
mw.notify('Sorry! There are no Administrators online.');
}
}
}).fail(function () {
}).fail(function () {
Line 110: Line 110:
'p-personal',
'p-personal',
'#',
'#',
'Patrollers',
'Bureaucrats',
't-onlinepatrol',
't-onlinebureaucrat',
'Seek help from patrollers.',
'Seek help from bureaucrats.',
'',
'',
'#pt-userpage'
'#pt-userpage'
Line 118: Line 118:
var rcstart, rcend, time;
var rcstart, rcend, time;
var users = [];
var users = [];
var admins = [], rollbackers = [], patrollers = [];
var admins = [], bureaucrats = [], stewards = [];
var api = new mw.Api();
var api = new mw.Api();


Line 128: Line 128:
var usersExt = [];
var usersExt = [];
admins = [];
admins = [];
rollbackers = [];
bureaucrats = [];
patrollers = [];
stewards = [];


//Recent edit within 15 minutes
//Recent edit within 30 minutes
time = new Date();
time = new Date();
rcstart = time.toISOString();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 15);
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
rcend = time.toISOString();


Line 169: Line 169:
$.each(data.query.users, function(i, user) {
$.each(data.query.users, function(i, user) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('patroller', user.groups) > -1) {
if ($.inArray('bureaucrat', user.groups) > -1) {
patrollers[i] = user.name;
bureaucrats[i] = user.name;
}
}
}
}
Line 189: Line 189:
};
};
admins = admins.filter(filter);
admins = admins.filter(filter);
rollbackers = rollbackers.filter(filter);
bureaucrats = bureaucrats.filter(filter);
patrollers = patrollers.filter(filter);
stewards = stewards.filter(filter);
var userlink = function(user) {
var userlink = function(user) {
var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
};
if (patrollers.length > 0) {
if (bureaucrats.length > 0) {
var adminsstring = ['<center><p><b>Patrollers Online:</b></p></center>'];
var adminsstring = ['<center><p><b>Online Bureaucrats:</b></p></center>'];
if (patrollers.length > 0) {
if (bureaucrats.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + patrollers.length + ' patrollers <br>online:');
adminsstring.push('<p style="word-break:break-all;">There are currently ' + bureaucrats.length + ' Bureaucrat(s) <br>online:');
$.each(patrollers, function(i, e) {
$.each(bureaucrats, function(i, e) {
adminsstring.push(userlink(e));
adminsstring.push(userlink(e));
});
});
Line 206: Line 206:
mw.notify($(adminsstring.join('')));
mw.notify($(adminsstring.join('')));
} else {
} else {
mw.notify('Sorry! There are no patrollers online');
mw.notify('Sorry! There are no Bureaucrats online.');
}
}
}).fail(function () {
}).fail(function () {
mw.notify('Error 404');
mw.notify('Error 404');
});
});
});
});
var portletLinkOnline = mw.util.addPortletLink(
'p-personal',
'#',
'Rollbackers',
't-onlinerollbacks',
'Seek help from rollbackers.',
'',
'#pt-userpage'
);
var rcstart, rcend, time;
var users = [];
var rollbackers = [];
var api = new mw.Api();
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
rollbackers = [];
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 15);
rcend = time.toISOString();
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('rollbacker', user.groups) > -1) {
rollbackers[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);
rollbackers = rollbackers.filter(filter);
patrollers = patrollers.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
if (rollbackers.length > 0) {
var adminsstring = ['<center><p><b>Current online rollbackers</b></p></center>'];
if (rollbackers.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + rollbackers.length + ' rollbackers <br>online');
$.each(rollbackers, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify('Sorry! There are currently no rollbackers.');
}
}).fail(function () {
mw.notify('Error 404 - Please check internet connection');
});
});
});
});
Line 316: Line 218:
'p-personal',
'p-personal',
'#',
'#',
'Reviewers',
'Stewards',
't-onlinereviews',
't-onlinesteward',
'Seek help from reviewers.',
'Seek help from stewards.',
'',
'',
'#pt-userpage'
'#pt-userpage'
Line 324: Line 226:
var rcstart, rcend, time;
var rcstart, rcend, time;
var users = [];
var users = [];
var reviewers = [];
var admins = [], bureaucrats = [], stewards = [];
var api = new mw.Api();
var api = new mw.Api();


Line 333: Line 235:
users = [];
users = [];
var usersExt = [];
var usersExt = [];
reviewers = [];
admins = [];
bureaucrats = [];
stewards = [];


// Edits made within 15 minutes
//Recent edit within 30 minutes
time = new Date();
time = new Date();
rcstart = time.toISOString();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 15);
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
rcend = time.toISOString();


Line 372: Line 276:
var mark = function(data) {
var mark = function(data) {
$.each(data.query.users, function(i, user) {
$.each(data.query.users, function(i, user) {
// Removing reviewers which are bots
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('reviewer', user.groups) > -1) {
if ($.inArray('steward', user.groups) > -1) {
reviewers[i] = user.name;
stewards[i] = user.name;
}
}
}
}
Line 389: Line 292:
}).done(mark));
}).done(mark));
}
}

// Query for user rights
$.when.apply($, promises).done(function () {
$.when.apply($, promises).done(function () {
var filter = function(n) {
var filter = function(n) {
return n;
return n;
};
};
reviewers = reviewers.filter(filter);
admins = admins.filter(filter);
bureaucrats = bureaucrats.filter(filter);
stewards = stewards.filter(filter);
var userlink = function(user) {
var userlink = function(user) {
var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
};
};
if (rollbackers.length > 0) {
if (stewards.length > 0) {
var adminsstring = ['<center><p><b>Current online reviewers</b></p></center>'];
var adminsstring = ['<center><p><b>Online Stewards:</b></p></center>'];
if (rollbackers.length > 0) {
if (stewards.length > 0) {
adminsstring.push('<p style="word-break:break-all;">There are currently ' + reviewers.length + ' reviewers <br>online');
adminsstring.push('<p style="word-break:break-all;">There are currently ' + steward(s).length + ' Steward(s) <br>online:');
$.each(rollbackers, function(i, e) {
$.each(bureaucrats, function(i, e) {
adminsstring.push(userlink(e));
adminsstring.push(userlink(e));
});
});
Line 411: Line 314:
mw.notify($(adminsstring.join('')));
mw.notify($(adminsstring.join('')));
} else {
} else {
mw.notify('Sorry! There are currently no reviewers online.');
mw.notify('Sorry! There are no Stewards online.');
}
}
}).fail(function () {
}).fail(function () {
mw.notify('Error 404 - Connection not found');
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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
                        return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
                        return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
                        return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<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');
                });
            });
        });
    });