Module:Sandbox/PhantomCaleb

local p = {} local h = {}

local Franchise = require("Module:Franchise") local utilsLayout = require("Module:UtilsLayout") local utilsMarkup = require("Module:UtilsMarkup") local utilsPage = require("Module:UtilsPage") local utilsTable = require("Module:UtilsTable")

function p.Main(frame) local categories = utilsPage.dpl({		uses = "Template:Gallery",		namespace = "Category",	})

local diffs = {} for i, category in ipairs(categories) do		local listing = utilsPage.stripNamespace(category, "Category") if utilsPage.exists(listing) then local subjectType, game = string.match(listing, "(.*) in (.*)") if subjectType and game then table.insert(diffs, {					listing = listing,					subjectType = subjectType,					game = game,					diffs = h.diffs(listing, subjectType),				}) end end end diffs = utilsTable.sortBy(diffs, "subjectType") local diffsByGame = utilsTable.groupBy(diffs, "game") local output = "" for i, game in ipairs(Franchise.enum) do		local shortName = Franchise.shortName(game) local diffs = diffsByGame[shortName] if diffs then output = output.."=="..Franchise.display(game).."==\n" for j, diffGroup in ipairs(diffs) do output = output.."==="..diffGroup.subjectType.." in "..Franchise.display(game).."===\n"..diffGroup.diffs.."\n" end end end return output end

function h.diffs(listing, subjectType) local categoryArticles = utilsPage.dpl({		category = listing,		namespace = "",	}) local listingArticles = utilsPage.dpl({		linksFrom = listing,		category = subjectType,		namespace = "",		nottitlematch= "Dungeon",	}) local absentFromListing = h.diffList(categoryArticles, listingArticles) local absentFromCategory = h.diffList(listingArticles, categoryArticles) if #absentFromListing == 0 and #absentFromCategory == 0 then return "" else local wikitable = utilsLayout.table({			headers = {				string.format("Absent from listing but present in category", listing, listing),				string.format("Absent from category but present in listing", listing, listing),			},			rows = 		}) return wikitable end end

function h.diffList(a, b)	local diff = utilsTable.difference(a, b)	-- if #diff == 0 then -- 	return "" -- end local links = utilsTable.map(diff, utilsMarkup.link) local list = utilsMarkup.bulletList(links) return list end

return p