FANDOM


local iconData = {
	reb = {
		image = "Clapper_icon.png",
		tooltip = "The subject of this article is a crew worker or actor.",
		link = "Category:Cast and Crew",
		category = "Cast and Crew"
	},
	old = {
		image = "Air_emblem.png",
		tooltip = "The subject of this article represents the air element.",
		link = "Air Element",
		category = "Air"
	},
	imp = {
		image = "Fire_emblem.png",
		tooltip = "The subject of this article represents the fire element.",
		link = "Fire Element",
		category = "Fire"
	},
	njo = {
		image = "Earth_emblem.png",
		tooltip = "The subject of this article represents the earth element.",
		link = "Earth Element",
		category = "Earth"
	},
	new = {
		image = "Spirit_emblem.png",
		tooltip = "The subject of this article represents the spirit element.",
		link = "Spirit Element",
		category = "Spirit"
	},
	inf = {
		image = "Water_emblem.png",
		tooltip = "The subject of this article represents the water element.",
		link = "Water Element",
		category = "Water"
	},
	real = {
		image = "Real-world.png",
		tooltip = "The subject of this article exists in or is relevant to the real world.",
		link = "Category:Real-world articles",
		category = "Real-world articles"
	},
	fprot = {
		protectionAction = "edit",
		protectionLevel = "sysop",
		image = "512px-Padlock.svg.png",
		category = "Protected"
	},
	sprot = {
		protectionAction = "edit",
		protectionLevel = "autoconfirmed",
		image = "128px-Padlock-red.svg.png",
		tooltip = "This article is semi-protected.",
		category = "Semi-protected articles"
	},
	ssprot = {
		image = "128px-Padlock-silver.svg.png",
		tooltip = "This article is super-semi-protected.",
		category = "Super-semi-protected articles"
	},
	mprot = {
		protectionAction = "move",
		protectionLevel = "sysop",
		image = "128px-Padlock-olive.svg.png",
		tooltip = "This article is move protected.",
		category = "Move protected articles"
	},
}
-------------------------------------------------------------------------------
-- Helper functions
-------------------------------------------------------------------------------
 
-- Find whether the specified page exists. We use pcall to catch errors if we
-- are over the expensive parser function count limit, or a number of other
-- juicy errors. This function increases the expensive parser function count
-- for every new page called.
local function exists(page)
	local success, title = pcall(mw.title.new, page)
	return success and title and title.exists or false
end
 
-------------------------------------------------------------------------------
-- Eras class
-------------------------------------------------------------------------------
 
-- The eras class does all of the heavy lifting in the module. We use a class
-- rather than normal functions so that we can avoid passing lots of different
-- values around for each different function.
 
local Eras = {}
Eras.__index = Eras -- Set up inheritance for tables that use Eras as a metatable.
 
-- Add a category, to be rendered at the very end of the template output.
function Eras:addCategory(cat, sort)
	table.insert(self.categories, {category = cat, sortKey = sort})
end
 
-- Shortcut method for getting an icon data subtable.
function Eras:getIconData(code)
	return self.icons[code]
end
 
-- Renders an eras icon from the given icon data. It deals with the image,
-- tooltip, link, and the category, but not the protection fields.
function Eras:renderIcon(data)
	-- Render the category at the end if it exists.
	if data.category then
		self:addCategory(data.category)
	end
	-- Render the icon and return it.
	local ret = {}
	ret[#ret + 1] = '[[File:'
	ret[#ret + 1] = data.image
	if data.tooltip then
		ret[#ret + 1] = '|'
		ret[#ret + 1] = data.tooltip
	end
	if data.link then
		ret[#ret + 1] = '|link='
		ret[#ret + 1] = data.link
	end
	ret[#ret + 1] = ']]'
	return table.concat(ret)
end
 
-- Renders a protection eras icon from the given data. If the page doesn't have
-- the specified protection level, returns nil and adds a flag to add a
-- tracking category later on in processing.
function Eras:renderProtectionIcon(data)
	if not data.protectionAction then
		return self:renderIcon(data)
	end
	local protectionLevel = self.title.protectionLevels[data.protectionAction]
	protectionLevel = protectionLevel and protectionLevel[1]
	if protectionLevel and protectionLevel == data.protectionLevel then
		return self:renderIcon(data)
	else
		self.hasIncorrectProtectionIcon = true
	end
end
 
-- Renders the icons that respond to a publishing era.
function Eras:renderPublishingIcons()
		local ret = {}
		local codes = {'pre', 'btr', 'old', 'imp', 'reb', 'new', 'njo', 'leg', 'inf'}
		for _, code in ipairs(codes) do
			local data = self:getIconData(code)
			if data then
				ret[#ret + 1] = self:renderIcon(data)
			end
		end
		return table.concat(ret)
end
 
-- Renders other icons, e.g. featured article status and protection status.
function Eras:renderNonPublishingIcons()
	local ret = {}
	local codes = {'real', 'featured', 'former', 'good', 'fga', 'comp', 'fca'}
	for _, code in ipairs(codes) do
		local data = self:getIconData(code)
		if data then
			ret[#ret + 1] = self:renderIcon(data)
		end
	end
	local protectionCodes = {'fprot', 'sprot', 'ssprot', 'mprot', 'uprot'}
	for _, code in ipairs(protectionCodes) do
		local data = self:getIconData(code)
		if data then
			ret[#ret + 1] = self:renderProtectionIcon(data)
		end
	end
	return table.concat(ret)
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.