Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 04:15, 25 May 2026 by Bosco (talk | contribs) (online admins)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// === Language Detection ===
function detectLang() {
    var lang = mw.config.get('wgUserLanguage') || navigator.language || 'en';
    lang = lang.toLowerCase();

    var zhHantList = ['zh-hant','zh-hk','zh-mo','zh-tw'];
    var zhHansList = ['zh-hans','zh-cn','zh-sg','zh-my','zh'];

    if (zhHantList.indexOf(lang) !== -1) {
        return 'zh-hant';
    } else if (zhHansList.indexOf(lang) !== -1) {
        return 'zh-hans';
    } else {
        return 'en';
    }
}
var userLang = detectLang();

// === Labels & Messages ===
var labels = {
    admins: { 'en':'Admins','zh-hant':'管理員','zh-hans':'管理员' },
    bureaucrats: { 'en':'Bureaucrats','zh-hant':'行政員','zh-hans':'行政员' },
    stewards: { 'en':'Stewards','zh-hant':'監管員','zh-hans':'监管员' }
};
var helps = {
    admins: { 'en':'Seek help from admins.','zh-hant':'向管理員尋求協助','zh-hans':'向管理员寻求协助' },
    bureaucrats: { 'en':'Seek help from bureaucrats.','zh-hant':'向行政員尋求協助','zh-hans':'向行政员寻求协助' },
    stewards: { 'en':'Seek help from stewards.','zh-hant':'向監管員尋求協助','zh-hans':'向监管员寻求协助' }
};
var msgs = {
    noAdmins: { 'en':'Sorry! There are no Administrators online.','zh-hant':'抱歉!目前沒有管理員在線。','zh-hans':'抱歉!目前没有管理员在线。' },
    noBureaucrats: { 'en':'Sorry! There are no Bureaucrats online.','zh-hant':'抱歉!目前沒有行政員在線。','zh-hans':'抱歉!目前没有行政员在线。' },
    noStewards: { 'en':'Sorry! There are no Stewards online.','zh-hant':'抱歉!目前沒有監管員在線。','zh-hans':'抱歉!目前没有监管员在线。' },
    error404: { 'en':'Error 404','zh-hant':'錯誤 404','zh-hans':'错误 404' }
};
var onlineMsg = {
    admins: {
        'en':'There are currently {n} Administrators online.',
        'zh-hant':'目前有 {n} 位管理員在線。',
        'zh-hans':'目前有 {n} 位管理员在线。'
    },
    bureaucrats: {
        'en':'There are currently {n} Bureaucrats online.',
        'zh-hant':'目前有 {n} 位行政員在線。',
        'zh-hans':'目前有 {n} 位行政员在线。'
    },
    stewards: {
        'en':'There are currently {n} Stewards online.',
        'zh-hant':'目前有 {n} 位監管員在線。',
        'zh-hans':'目前有 {n} 位监管员在线。'
    }
};

// === Utility: Create User Link ===
function userLink(user) {
    return '<a href="/wiki/User:' + user + '" target="_blank">' + user +
           '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User_talk:' + user +
           '" target="_blank">Talk</a>)</small>';
}

// === Generic Handler ===
function setupPortlet(group, label, help, msgNo, onlineMsgGroup, groupName) {
    var portletLink = mw.util.addPortletLink(
        'p-personal','#',label[userLang],'t-online'+group,help[userLang],'','#pt-userpage'
    );
    $(portletLink).click(function(e) {
        e.preventDefault();
        var users = [], usersExt = [], found = [];
        var api = new mw.Api();
        var time = new Date();
        var rcstart = time.toISOString();
        time.setMinutes(time.getMinutes() - 30);
        var 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.push(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.push(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 && $.inArray(groupName,user.groups)!==-1){
                            found.push(user.name);
                        }
                    });
                };
                for(var i=0;i<users.length;i+=50){
                    promises.push(api.get({
                        format:'json',action:'query',list:'users',
                        ususers:users.slice(i,i+50).join('|'),usprop:'groups'
                    }).done(mark));
                }
                $.when.apply($,promises).done(function(){
                    if(found.length>0){
                        var out=['<center><b>'+label[userLang]+'</b></center>',
                                 '<p style="word-break:break-all;">'+
                                 onlineMsgGroup[userLang].replace('{n}',found.length)+'</p>'];
                        $.each(found,function(i,e){out.push(userLink(e));});
                        mw.notify($(out.join('')));
                    } else {
                        mw.notify(msgNo[userLang]);
                    }
                }).fail(function(){mw.notify(msgs.error404[userLang]);});
            });
        });
    });
}

// === Setup All Portlets ===
setupPortlet('admin',labels.admins,helps.admins,msgs.noAdmins,onlineMsg.admins,'sysop');
setupPortlet('bureaucrat',labels.bureaucrats,helps.bureaucrats,msgs.noBureaucrats,onlineMsg.bureaucrats,'bureaucrat');
setupPortlet('steward',labels.stewards,helps.stewards,msgs.noStewards,onlineMsg.stewards,'steward');
Cookies help us deliver our services. By using our services, you agree to our use of cookies.