Toggle navigation
Home
New Query
Recent Queries
Discuss
Database tables
Database names
MediaWiki
Wikibase
Replicas browser and optimizer
Login
History
Fork
This query is marked as a draft
This query has been published
by
DannyS712
.
Toggle Highlighting
SQL
/** * Admin name * Timestamp of their 10th most recent edit * Timestamp of their 10th most recent **log entry** that requires admin rights, does not account for other admin actions * DOES NOT ACCOUNT FOR STEWARD ACTIONS BEING LOGGED AS ADMIN ACTIONS * * Log entries that count: * - abusefilter/* * - block/* * - delete/delete, /revision, /restore, /event * - import/* * - rights/rights * - protect/protect, /modify * * Not sure about * - massmessage * - pagetranslation * - pagelang * - patrol */ /* USE metawiki_p; set @start = '20200401000000'; set @end = '20201001000000'; SELECT a.*, ug.*, editCounts.* FROM actor_user a JOIN user_groups ug ON ug.ug_user = a.actor_user AND ug.ug_group = 'sysop' LEFT JOIN ( SELECT editor.ug_user, editorActor.*, COUNT(rev.rev_id) FROM user_groups editor LEFT JOIN actor editorActor ON editorActor.actor_user = editor.ug_user JOIN revision_userindex rev ON rev.rev_actor = editorActor.actor_id WHERE editor.ug_group = 'sysop' AND rev.rev_timestamp > @start AND rev.rev_timestamp < @end GROUP BY rev.rev_actor ) as editCounts ON editCounts.actor_id = a.actor_id LIMIT 100; */ USE metawiki_p; -- Modify startdate and enddate to change dates SET @startdate = '20191001000000'; SET @enddate = '20200401000000'; -- regex for exempt users SET @exempt_username_pattern = ' \\(WMF\\)$|-WMF$|WMFOffice'; -- Define for what is a sysop action SET @sysoplogtype = CAST( "( 'abusefilter', 'block', 'contentmodel', 'delete', 'import', 'lock', 'managetags', 'massmessage', 'merge', 'protect', 'rights', 'tag', 'timedmediahandler' )" AS CHAR ); -- misc SET @logwhere = CONCAT( "ug_group = 'sysop' ", "AND log_type IN ",@sysoplogtype," ", "AND actor_name NOT REGEXP @exempt_username_pattern ", "AND log_timestamp BETWEEN @startdate AND @enddate " ); SET @zeroaction = CONCAT( "SELECT ug_user as userid, user_name as username, 0 ", "FROM user_groups JOIN user ON ug_user = user_id ", "WHERE ug_group = 'sysop' ", "AND user_name NOT REGEXP @exempt_username_pattern " ); -- show count of sysop actions in the term SET @logcountsql = CONCAT( "SELECT userid, username, SUM(sysoplogs) as SysopActionCount ", "FROM (", "SELECT ug_user as userid, actor_name as username, count(*) as sysoplogs FROM user_groups LEFT JOIN actor ON ug_user=actor_user JOIN logging ON actor_id = log_actor ", "WHERE ",@logwhere, "GROUP BY ug_user ", "UNION ", @zeroaction, ") as t GROUP BY userid ", "ORDER BY SysopActionCount asc " ); PREPARE stmt FROM @logcountsql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -- show count of edits in the term SELECT userid, username, SUM(edit) as edits FROM ( SELECT ug_user as userid, actor_name as username, count(*) as edit FROM user_groups LEFT JOIN actor ON ug_user=actor_user JOIN revision ON actor_id = rev_actor WHERE ug_group = 'sysop' AND actor_name NOT REGEXP @exempt_username_pattern AND rev_timestamp BETWEEN @startdate AND @enddate GROUP BY ug_user UNION SELECT ug_user as userid, user_name as username, 0 as edit FROM user_groups JOIN user ON ug_user = user_id WHERE ug_group = 'sysop' AND user_name NOT REGEXP @exempt_username_pattern ) as t GROUP BY userid ORDER BY edits asc; -- show all edits in the term SELECT CONCAT('[[Special:Redirect/user/',actor_user,'|',actor_user,']]') as userid, actor_name as username, CONCAT('[[Special:Diff/',rev_id,'|',rev_id,']]') as diff, CONCAT('[[Special:Redirect/page/',rev_page,'|',rev_page,']]') AS pageid, rev_timestamp FROM user_groups LEFT JOIN actor ON ug_user=actor_user JOIN revision ON actor_id = rev_actor WHERE ug_group = 'sysop' AND actor_name NOT REGEXP @exempt_username_pattern AND rev_timestamp BETWEEN @startdate AND @enddate ORDER BY actor_user asc, rev_timestamp asc; -- show all sysop actions in the term SET @logsql = CONCAT( "SELECT CONCAT('[[Special:Redirect/logid/',log_id,'|',log_id,']]') as logid, ", "log_type, ", "log_timestamp, ", "CONCAT('[[Special:Redirect/user/',actor_user,'|',actor_user,']]') as loguserid, ", "actor_name ", "FROM user_groups LEFT JOIN actor ON ug_user=actor_user LEFT JOIN logging ON actor_id=log_actor ", "WHERE ",@logwhere ); PREPARE stmt FROM @logsql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
By running queries you agree to the
Cloud Services Terms of Use
and you irrevocably agree to release your SQL under
CC0 License
.
Submit Query
Stop Query
All SQL code is licensed under
CC0 License
.
Checking query status...