User:Ruincrez/adminonline.js

// Create portlet link // Look the number of admins online // By:zh:User:Alexander Misel var portletLinkOnline = mw.util.addPortletLink(	'p-personal',	'#',	'Admins Online',//'在线管理员',	't-onlineadmin',	'Look Admins Online',	'',	'#pt-userpage' );

var rcstart, rcend, time; var users =[]; var admins =[]; var uniqueuser, userTotal; var api = new mw.Api;

// Bind click handler $( "li#t-onlineadmin a" ).click( function {	users = [];	users_ext = [];	admins = [];	userTotal = 0;	//最近更改5分钟内的编辑用户	//Find users who edited in 10 minutes	time= new Date;	rcstart=time.toISOString;	time.setMinutes(time.getMinutes-5);	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',				lepstart: rcstart,				leend: rcend,				lelimit: 500					}).done( function ( data ) {						$.each( data.query.logevents, function( i, item ) { users_ext[i] = item.user; });			Array.prototype.push.apply(users, users_ext); 			//用户去重			//get unique			users.sort;			uniqueuser=$.unique(users).join('|');			//查询用户权限			//Query user rights			api.get( { format: 'json', action: 'query', list: 'users', ususers: uniqueuser, usprop: 'groups' } ).done( function ( data ) { $.each( data.query.users, function( i, user ) {						//找到管理员，去除adminbot						//found the admin,remove adminbot						if ($.inArray('sysop', user.groups) > -1 && $.inArray('bot', user.groups) === -1) {			 				admins[i]=user.name;						}					}); //消除空值 admins = admins.filter(function(n){return n}); //console.log( admins ); //管理员数 userTotal=admins.length; //	mw.notify( '上线'+userTotal+'名管理员' ); //显示管理员数 $("li#t-onlineadmin a").html(wgUVS( '在线管理员', '線上管理員' ) + '：('+userTotal+')'); if (userTotal>0) { var adminsstring = ''; //online.preventDefault; mw.loader.using( 'oojs-ui' ).done( function {                        var popup = new OO.ui.PopupWidget( { $content: $( ' ' ), padded: true, head: true, //label: wgUVS( '当前在线的管理员有：', '目前線上管理員有：' ), label: 'The number of current online admins:', $container: $("#t-onlineadmin"), align: 'right', width: '', autoClose: true //popup只出现一个 } );                       $( '#t-onlineadmin' ).append( popup.$element );                            popup.toggle( true );                            //var uri = mw.config.get('wgServer')+mw.config.get('wgScript');                            $("div.oo-ui-popupWidget").css("left","200px"); //popup偏移修正                            $.each( admins, function( i, adminuser ) { adminsstring=adminsstring+' '+adminuser+' (留言)'; });                           //console.log( adminsstring );                            $('div#popupadmin').append(adminsstring);                    }); }                   else { //mw.notify( wgUVS( '当前没有管理员在线. ', '管理員無人在線上. ' ) ); // Send a plaintext notification mw.notify('There is no admin online.'); }			  });		  });	 });	});