Module:Titles

From Eli's Software Encyclopedia
Revision as of 11:23, August 20, 2025 by WikiVisor (talk | contribs)

Documentation for this module may be created at Module:Titles/doc

local utils = require('Module:Utils')

local p = {}

function p.semanticStore(frame)

	local titleObj    = mw.title.getCurrentTitle()
	local args        = frame:getParent().args or {}
	
	-- Get infobox helper params
	local collapsible = args['collapsible'] or 'no'
	local state       = args['state'] or 'autocollapse'
	local showImage   = args['show image'] or 'no'

	-- Get other properties	
	local title       = args['title'] or titleObj.text 
	local publisher	  = args['origpub'] or ''
	local released    = args['release'] or '' 
    local platform    = args['origplat'] or ''
	local developer   = args['developer'] or '' 
	local genre       = args['genre'] or ''
	local country     = args['country'] or ''
	local image       = args['image'] or ''
	
	local imageFilename, imageAlt, imageCaption = '', '', ''
	if image ~= '' then
		local fn, alt = utils.parseFileLink(image)
		if fn then
    		imageFilename = fn
        	imageAlt  = alt or imageCaption or ''
        else
        	imageFilename = frame:preprocess('{{PAGENAME:' .. image .. '}}')
    	end
	end
	
	-- Set properties
    local data = {
    	'Has Title=' .. title,
    	'Original Publisher=' .. utils.unwrapList(publisher),
    	'+sep=,',
		'Original Platform=' .. utils.unwrapList(platform),
		'+sep=,',
		'Released Date=' .. released,
    	'Developer=' .. utils.unwrapList(developer),
    	'+sep=,',
    	'Genre=' .. utils.unwrapList(genre),
    	'+sep=,',
    	'Country Of Origin=' .. country,
    	'Has Image=' .. imageFilename,
    	'Has Image Caption=' .. imageCaption
	}
	mw.smw.set( data )
	
	-- Infobox variables
	local infoboxClass = 'chameleon-infobox smwtable-clean d-table w-100 w-md-30 d-md-flex float-none float-md-right border shadow-sm ml-md-4 mb-4 text-left'
	local pad = ''
	if collapsible == 'yes' then
		infoboxClass = infoboxClass .. ' collapsible ' .. state
		pad = frame:preprocess('{{pad|5em}}')
	end
	-- Build infobox
	local html   = mw.html.create()
	local infobox = html:tag('table'):addClass(infoboxClass)
    	:css('font-size', '90%')
		:attr('cellpadding', '0')
		:attr('cellspacing', '0')
		
	-- Header row (title + optional image)
	local headerTr = mw.html.create('tr')
	headerTr:tag('td'):attr('colspan', '2')
       	:tag('div'):addClass('summary text-center font-italic font-weight-bold')
			:css('font-size', '110%')
			:wikitext(pad .. title):done()
		infobox:node(headerTr)
		
	-- Image and caption
	if image ~= '' then
		local imgTr = mw.html.create('tr')
    	imgTr:tag('td'):attr('colspan', '2'):addClass('text-center px-0')
			:wikitext(string.format('[[File:%s|class=img-fluid|%s]]',
				imageFilename, imageCaption
			))
    	infobox:node(imgTr)

		if imageCaption ~= '' then
			local capTr = mw.html.create('tr')
			capTr:tag('td'):attr('colspan', '2'):addClass('text-center px-0')
				:wikitext(imageCaption)
			infobox:node(capTr)
    	end
	end
	
	-- Print data rows
	local function appendIfExists(label, value)
    	local tr = utils.addLabelValue(label, value)
    	if tr then infobox:node(tr) end
	end
	
	appendIfExists('Title', title)
	appendIfExists('Release date(s)', releaseDate)
	appendIfExists('[[:Category:Hardware|Original Platform(s)]]', platform)
	appendIfExists('[[:Category:Software Publisher|Original Publisher(s)]]', publisher)
	appendIfExists('[[:Category:Software Developer|Developer(s)]]', developer)
	appendIfExists('[[:Category:Software|Category(s)]]', genre)
	appendIfExists('Country of Origin', country)
	
	return html
end

return p