Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:MasterGunner

From Wikipedia, the free encyclopedia

require('strict')
local p = {}
local data = mw.loadData('Module:MasterGunner/data')
local getArgs = require('Module:Arguments').getArgs
-- South African Master Gunner Data
-- Data Fields
--      Code: This is just a duplicate of the lookup code, but expressed as a number instead of a string
--      Rank: Person's rank. Not wikilinked
---     FirstName: Initials or first name(s)
--      Surname: Person's Surname
--      Year:   Year appointed Master Gunner
--      WikiPage: If the person has a Wiki article, name of the article here
--      PostNoms: list of Post Nominal Titles. Stored in Lua table format ie Curly braces with values seperated by commas
--      Post: The name of the post that they held when awarded. Commas will be turned into line breaks
--      Note: Any additional info about this Gunner.
--      RecipCat: Category for recipients. "List of Master Gunners (South Africa)"

function p.Gunner(frame)
	local output = ''
	local templateArgs = getArgs(frame)
	local gunnercode = templateArgs["code"] or nil
	-- local pagename=templateArgs["pagename"] or nil
	if not gunnercode then
		output = '<span style="color:#d33">Error: No code specified</span>'
		return output
	end
	if data[gunnercode] then
		output = output .. gunnercode .. ": "
		output = output ..  data[gunnercode].Code .. " Master Gunner" .. "<br />"
		output = output .. data[gunnercode].FirstName .. " " .. data[gunnercode].Surname .. " Year: " .. data[gunnercode].Year .. "<br />"
		return output
	else
		output = '<span style="color:#d33">Error: code '.. gunnercode .. ' not found</span>'
	end
	return output
end

function p.GunnerBox(frame)
	local output = ''
	local templateArgs = getArgs(frame)
	local gunnercode = templateArgs["code"] or nil
	local imagesize = templateArgs["imagesize"] or '150px'
		if not gunnercode then
			output = '<span style="color:#d33">Error: No "code" specified. Use the Gunner number preceded by an A for example, code=A100</span>[[Category:Master Gunner Error]]'
		return output
		end

	if data[gunnercode] then
		-- Send Info
		-- Generate wiki table code for the Master Gunner

		local float = templateArgs.float or 'none'
    	if float == "left" then 
        	float = "floatleft"
    	elseif float == "right" then
            float = "floatright"
    	elseif float == "none" then 
    		float = '' 
    	end

		local tableCode = '{| class="wikitable ' .. float .. '" style="text-align:center" \n'
--		tableCode = tableCode .. "|+ Master Gunner \n" -- Caption
		tableCode = tableCode .. "|-\n"
		tableCode = tableCode .. '!colspan=2 style="background:red; color:white;"| Master Gunner: ' .. data[gunnercode].Code .. '\n'
		tableCode = tableCode .. "|-\n"
		tableCode = tableCode .. "|colspan=2|[[file:SANDF Arty Master Gunner badge embossed.png|border|" .. imagesize .. "|link=List of badges of the South African Army#Proficiency: Master Gunner|Master Gunner]]\n"
		tableCode = tableCode .. "|-\n"
		tableCode = tableCode .. "|colspan=2|" .. p.GetGunner("A" .. data[gunnercode].Code)
		if string.len(data[gunnercode].Post) > 1 then
			tableCode = tableCode .. mw.getCurrentFrame():expandTemplate{ title = 'Efn', args = {"Post occupied when award was made: " .. data[gunnercode].Post} }
		end
		if string.len(data[gunnercode].Note) > 1 then
			tableCode = tableCode .. mw.getCurrentFrame():expandTemplate{ title = 'Efn', args = {data[gunnercode].Note} }
		end
		tableCode = tableCode .. "\n"
		tableCode = tableCode .. "|-\n "
		tableCode = tableCode .. "|colspan=2|[[Master Gunners of the South African Army|Year]]: '''".. data[gunnercode].Year .. "'''\n"
		tableCode = tableCode .. "|-\n"
		local prevgunner="A" .. data[gunnercode].Code -1 .. ""
		tableCode = tableCode .. "| ←" .. data[gunnercode].Code -1 .. ": " .. p.GetGunner(prevgunner) .. "\n"
		local nextgunner="A" .. data[gunnercode].Code +1 ..""
		tableCode = tableCode .. "| " .. p.GetGunner(nextgunner) .. " :".. data[gunnercode].Code +1 .. "→\n"
		tableCode = tableCode .. "|}"
		return tableCode
	end
	return output
end
function p.GetGunner(gunnercode)
	local output = ''
	if not data[gunnercode] then
		output = "Unknown"
	else
		if string.len(data[gunnercode].WikiPage) < 1 then
			output =  data[gunnercode].Rank .. "<br />".. data[gunnercode].FirstName .. " " .. data[gunnercode].Surname
		else
			output = data[gunnercode].Rank .. "<br />" .. "[[" .. data[gunnercode].WikiPage .. "|" ..  data[gunnercode].FirstName .. " " .. data[gunnercode].Surname .. "]]"
		end
	end
	return output -- Should never get here, but belts-and -braces... just to be sure
end

function p.GunnerTable(frame)
	-- Data Fields
--      Code: This is just a duplicate of the lookup code, but expressed as a number instead of a string
--      Rank: Person's rank. Not wikilinked
---     FirstName: Initials or first name(s)
--      Surname: Person's Surname
--      Year:   Year appointed Master Gunner
--      WikiPage: If the person has a Wiki article, name of the article here
--      PostNoms: list of Post Nominal Titles. Stored in Lua table format ie Curly braces with values seperated by commas
--      Post: The name of the post that they held when awarded. Commas will be turned into line breaks
--      Note: Any additional info about this Gunner.
--      RecipCat: Category for recipients. "List of Master Gunners (South Africa)"
	local output = ''
	local templateArgs = getArgs(frame)
	local localfloat = templateArgs["float"] or ''
	if not localfloat then
		localfloat = "left"  -- NOTE TODO: Make the table float according to the value of locafloat ;-)
	end
	local tableCode = '{| class="wikitable sortable" \n'
	tableCode = tableCode .. "|+ List of Master Gunners \n" -- Caption
	tableCode = tableCode .. "|-\n"
	tableCode = tableCode .. "! Code !!Number !! Rank !! Surname !! First Names !! Post !! Year !! Note \n"
	-- Iterate through the data in the table "GunnerData"
	for code, record in pairs(data) do
		-- Generate wiki table code for the Master Gunner
		-- TODO: If record.Surname == "Unknown" make the row distinctive somehow.
		tableCode = tableCode .. "|-\n"
		tableCode = tableCode .. "|" ..code .. "\n"
		tableCode = tableCode .. "| " .. record.Code .. "\n"
		tableCode = tableCode .. "| " .. record.Rank .. "\n"
		if string.len(record.WikiPage) < 1 then
			tableCode = tableCode .. "| " .. record.Surname 
		else
			tableCode = tableCode .. "| " .. "[[" .. record.WikiPage .. "|" .. record.Surname .. "]]"
		end
	--	if string.len(record.Post)>1 then
	--		tableCode = tableCode .. mw.getCurrentFrame():expandTemplate{ title = 'Efn', args = {"Post occupied when award was made: " .. record.Post} }
	--	end
		tableCode = tableCode .. "\n"
		tableCode = tableCode .. "| " .. record.FirstName .. "\n"
		tableCode = tableCode .. "| " .. string.gsub(record.Post, ",", " - <br />") .. "\n"
		tableCode = tableCode .. "| " .. record.Year .. "\n"
		tableCode = tableCode .. "| <small>" .. record.Note .. "</small>\n"
		
	end
	tableCode = tableCode .. "|}" -- End the table
	return tableCode
end

return p
-- Initial Code by John Dovey (13 April 2023) [[User:BoonDock]]