MediaWiki:Gadget-OnlineAdmins.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
final change
 
(34 intermediate revisions by 5 users not shown)
Line 1: Line 1:
// Localized en version
/* Toggle VF */
// 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
// 05 Apr 16 0108
$(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);
function dotogg()
{
$( 'head' ).append( '<style type="text/css" media="screen">' + ' ul { list-style: none; }' + '</style>' );


// Removing Duplicate Usernames
$( 'head' ).append( '<style type="text/css" media="print">' + ' ul { list-style: none; }' + '</style>' );
users = $.unique(users.sort());


var promises = [];
$( ".mw-headline[id='References'] " ).toggle();
var mark = function(data) {
$( ".reference" ).toggle();
$.each(data.query.users, function(i, user) {
$( "ol.references" ).toggle();
if ($.inArray('bot', user.groups) === -1) {
$( ".toc" ).toggle();
if ($.inArray('sysop', user.groups) > -1) {
$( ".template" ).toggle();
admins[i] = user.name;
$( ".navbox" ).toggle();
}
$( ".navbar" ).toggle();
}
$( ".thumb" ).toggle();
});
$( ".wikitable" ).toggle();
};
$( ".toccolours" ).toggle();
for (var i=0; i<(users.length+50)/50; i++) {
$( ".hatnote" ).toggle();
promises.push(api.get({
$( ".hlist" ).toggle();
format: 'json',
$( ".mw-headline[id='External_Links'] " ).toggle();
action: 'query',
$( ".external" ).toggle();
list: 'users',
// $( ".external.text" ).show(); // showing only Ext Links
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:');
$( ".ambox" ).toggle();
$.each(admins, function(i, e) {
$( ".mbox" ).toggle();
adminsstring.push(userlink(e));
$( ".ombox" ).toggle();
});
$( ".dmbox" ).toggle();
adminsstring.push('</p>');
$( ".fmbox" ).toggle();
}
$( ".messagebox" ).toggle();
mw.notify($(adminsstring.join('')));
$( ".vertical-navbox" ).toggle();
} else {
$( ".infobox" ).toggle();
mw.notify('Sorry! There are no Administrators online.');
$( ".infobox.sisterproject" ).toggle();
}
$( ".infobox.subdivision" ).toggle();
}).fail(function () {
$( ".dablink" ).toggle();
mw.notify('Error 404');
$( ".metadata" ).toggle();
});
$( ".editlink" ).toggle();
});
$( ".navbar" ).toggle();
});
//
});
$( "#siteSub" ).toggle();
// Create portlet link
$( ".printfooter" ).toggle();
var portletLinkOnline = mw.util.addPortletLink(
$( "#catlinks, .catlinks" ).toggle();
'p-personal',
$( "#footer" ).toggle();
'#',
$( "#header" ).toggle();
'Bureaucrats',
$( ".image" ).toggle();
't-onlinebureaucrat',
$( ".metadata" ).toggle();
'Seek help from bureaucrats.',
$( ".protected" ).toggle();
'',
$( ".boilerplate" ).toggle();
'#pt-userpage'
$( ".mw-editsection-bracket" ).toggle();
);
$( ".mw-editsection" ).toggle();
var rcstart, rcend, time;
}
var users = [];
var admins = [], bureaucrats = [], stewards = [];
var api = new mw.Api();


// Bind click handler
var codeload;
$(portletLinkOnline).click(function(e) {
if (codeload!=9999) {
e.preventDefault();
dotogg();
firstHeading.style.textAlign = 'center';
$( ".Template-Fact" ).hide();
$("#coll-create_a_book").hide();
$("#coll-download-as-rdf2latex").hide();
// $("#t-print").replaceWith('<a href="/w/index.php?title=Nunatak&amp;printable=yes" title="Printable version of this page [p]" accesskey="p">Printable VF</a></li>');


users = [];
codeload=9999; }
var toggflag=0;
var usersExt = [];
admins = [];
mw.loader.using( 'mediawiki.util', function () {
bureaucrats = [];
$( document ).ready( function() {
stewards = [];
var ToggVF = mw.util.addPortletLink( "p-tb", "#", "Toggle VF", "t-Toggle VF","Convert to Voice-Friendly format",'4');


//Recent edit within 30 minutes
$( ToggVF ).click( function() {
time = new Date();
toggflag=toggflag+1;
rcstart = time.toISOString();
dotogg();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();


//API:RecentChanges
if (toggflag==1) {firstHeading.style.textAlign = 'left';
api.get({
$( ".Template-Fact" ).show(); }
format: 'json',
action: 'query',
if (toggflag==2) {firstHeading.style.textAlign = 'center';
list: 'recentchanges',
$( ".Template-Fact" ).hide();
rcprop: 'user',
toggflag=0 ; }
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');
});
});
});
});

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');
                });
            });
        });
    });