User:Slakr/Temp/sql

/** Dumps out all active protections made by a user in the article namespace. Does not include protected titles (salts). * Apologies if it's kludgeish. I need sleep. */

/* get all of it because I have no idea what you wanna do with it */ SELECT DISTINCT l.*, p.*, pr.*

/* find stuff in the logging table */ FROM logging AS l

/* ... and add in the page info ... */ LEFT JOIN page AS p ON (	l.log_namespace = p.page_namespace 	AND l.log_title = p.page_title )

/** find (actually, ideally don't find) protect log entires made by other dudes more recently than target dude. * Logically, this would indicate that the former dude's protect is no longer active; for, either a newer dudette unprotected or reprotected. * That's right, antiLog(tm)-- your fireplace's worst nightmare. */ LEFT JOIN logging AS antiLog ON (	antiLog.log_namespace = 0	AND antiLog.log_title = l.log_title

/* presumably you want any other dude's [un]protect to overwrite it. */	AND antiLog.log_type = 'protect'

/* magic number. another magic number is later */ AND antiLog.log_user != 603177 AND antiLog.log_id > l.log_id

) LEFT JOIN page_restrictions AS pr ON ( pr.pr_page = p.page_id

/** this will only return edit protects. * If you want moveprotects as well/instead, remove this/change it to move */

AND pr.pr_type = 'edit' AND antiLog.log_namespace IS NULL )

/** as promised, the where against the logging table. * replace the magic number below with the same magic number in antiLog to create more magic. */

WHERE l.log_user = 603177 AND l.log_namespace = 0 AND l.log_type = 'protect' AND antiLog.log_namespace IS NULL AND pr.pr_id IS NOT NULL