Module:Delete

From Zelda Wiki, the Zelda encyclopedia
Revision as of 23:25, 1 April 2024 by PhantomCaleb (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Delete/Documentation

local p = {}

local utilsPage = require("Module:UtilsPage")

function p.Categories(frame)
	local categories = ""
	local title = mw.title.getCurrentTitle()
	local namespace = title.nsText
	
	if frame:getParent().args[3] == "nocat" then
		return ""
	end
	
	-- While this could be refactored, it's best that the prefixed category title 
	-- remain whole so that it can be more easily found in source searches
	if namespace == "File" then
		categories = categories .. "[[Category:Files needing deletion]]"
		if p.isReady(title) then
			categories = categories .. "[[Category:Files ready for deletion]]"
		end
	elseif namespace == "Template" then
		categories = categories .. "[[Category:Templates needing deletion]]"
	else
		categories = categories .. "[[Category:Articles needing deletion]]"
	end
	
	return categories
end

-- If modifying the logic of this function, be sure to update the description of 
-- [[Category:Files ready for deletion]] which describes the logic
function p.isReady(title)
	local pagesUsingFile = utilsPage.dpl({
		imageused = title.text
	})
	local file = title.file
	return #pagesUsingFile == 0 and (false
		or file.exists == false -- indicates the file was moved
		or file.mimeType ~= "image/png" -- if a non-PNG file was marked with Delete it's probably because a PNG replacement was uploaded
	)
end

return p