Module:Software: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
Line 15: Line 15:
-- Get other properties
-- Get other properties
local title      = args['title'] or titleObj.text  
local title      = args['title'] or titleObj.text  
local publisher   = utils.unwrapLink(args['publisher']) or ''
local publisher   = args['publisher'] or ''
local publabel    = args['publabel'] or ''
local publabel    = args['publabel'] or ''
local manpartnum  = args['manpartnum'] or ''
local manpartnum  = args['manpartnum'] or ''
Line 22: Line 22:
local ean        = args['EAN'] or ''
local ean        = args['EAN'] or ''
local isbn        = args['ISBN'] or ''
local isbn        = args['ISBN'] or ''
     local platform    = utils.unwrapLink(args['platform']) or utils.unwrapLink(args['platforms']) or ''
     local platform    = args['platform'] or args['platforms'] or ''
     local videostandard = args['videostandard'] or ''  
     local videostandard = args['videostandard'] or ''  
     local packaging  = args['packaging'] or ''  
     local packaging  = args['packaging'] or ''  
Line 28: Line 28:
local copyrighted = args['copyrighted'] or args['copyright'] or ''
local copyrighted = args['copyrighted'] or args['copyright'] or ''
local released    = args['released'] or ''  
local released    = args['released'] or ''  
local distributor = utils.unwrapLink(args['distributor']) or ''  
local distributor = args['distributor'] or ''  
local developer  = utils.unwrapLink(args['developer']) or ''  
local developer  = args['developer'] or ''  
local series      = args['series'] or ''  
local series      = args['series'] or ''  
local genre      = utils.unwrapLink(args['genre']) or ''
local genre      = args['genre'] or ''
local engine      = utils.unwrapLink(args['engine']) or ''
local engine      = args['engine'] or ''
local age        = args['age'] or ''
local age        = args['age'] or ''
local ratings    = args['ratings'] or ''
local ratings    = args['ratings'] or ''
local country    = utils.unwrapLink(args['country']) or ''
local country    = args['country'] or ''
local language   = args['language'] or ''
local language   = args['language'] or ''
local image      = args['image'] or ''
local image      = args['image'] or ''
Line 58: Line 58:
'Product EAN=' .. ean,
'Product EAN=' .. ean,
'Product ISBN=' .. isbn,
'Product ISBN=' .. isbn,
'Platform=' .. platform,
'Platform=' .. utils.unwrapList(platform),
'+sep=,',
'Video Standard=' .. videostandard,
'Video Standard=' .. videostandard,
'Software Packaging=' .. packaging,
'Software Packaging=' .. packaging,
Line 66: Line 67:
     'Publisher=' .. publisher,
     'Publisher=' .. publisher,
     'Publisher Label=' .. publabel,
     'Publisher Label=' .. publabel,
     'Distributor=' .. distributor,
     'Distributor=' .. utils.unwrapList(distributor),
     'Developer=' .. developer,
    '+sep=,',
     'Developer=' .. utils.unwrapList(developer),
    '+sep=,',
     'Series=' .. series,
     'Series=' .. series,
     'Genre=' .. genre,
     'Genre=' .. utils.unwrapList(genre),
     '+sep=,',
     '+sep=,',
     'Game Engine=' .. engine,
     'Game Engine=' .. engine,

Revision as of 10:41, August 20, 2025

Documentation for this module may be created at Module:Software/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['publisher'] or ''
	local publabel    = args['publabel'] or ''
	local manpartnum  = args['manpartnum'] or ''
	local productid   = args['productid'] or ''
	local upc         = args['UPC'] or ''
	local ean         = args['EAN'] or ''
	local isbn        = args['ISBN'] or ''
    local platform    = args['platform'] or args['platforms'] or ''
    local videostandard = args['videostandard'] or '' 
    local packaging   = args['packaging'] or '' 
	local media       = args['media'] or '' 
	local copyrighted = args['copyrighted'] or args['copyright'] or ''
	local released    = args['released'] or '' 
	local distributor = args['distributor'] or '' 
	local developer   = args['developer'] or '' 
	local series      = args['series'] or '' 
	local genre       = args['genre'] or ''
	local engine      = args['engine'] or ''
	local age         = args['age'] or ''
	local ratings     = args['ratings'] or ''
	local country     = args['country'] or ''
	local language	  = args['language'] 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,
    	'Manufacturer Code=' .. manpartnum,
    	'Product ID=' .. productid,
		'Product UPC=' .. upc,
		'Product EAN=' .. ean,
		'Product ISBN=' .. isbn,
		'Platform=' .. utils.unwrapList(platform),
		'+sep=,',
		'Video Standard=' .. videostandard,
		'Software Packaging=' .. packaging,
		'Digital Media=' .. media,
		'Copyright Date=' .. copyrighted,
		'Released Date=' .. released,
    	'Publisher=' .. publisher,
    	'Publisher Label=' .. publabel,
    	'Distributor=' .. utils.unwrapList(distributor),
    	'+sep=,',
    	'Developer=' .. utils.unwrapList(developer),
    	'+sep=,',
    	'Series=' .. series,
    	'Genre=' .. utils.unwrapList(genre),
    	'+sep=,',
    	'Game Engine=' .. engine,
    	'Recommended Age=' .. age,
	  	'Software Content Rating System=' .. ratings,
    	'Country Of Origin=' .. country,
    	'Language=' .. language,
    	'+sep=,',
    	'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('Manufacturer #', manpartnum)
	appendIfExists('Product ID', productid)
	appendIfExists('Product UPC', upc)
	appendIfExists('Product EAN', ean)
	appendIfExists('Product ISBN', isbm)
	appendIfExists('[[:Category:Hardware|Platform(s)]]', platform)
	appendIfExists('[[Video Standard]]', videostandard)
	appendIfExists('[[Software Packaging|Packaging]]', packaging)
	appendIfExists('[[Digital Media|Media]]', media)
	appendIfExists('Copyright date(s)', copyrightDate)
	appendIfExists('Release date(s)', releaseDate)
	appendIfExists('[[:Category:Software Publisher|Publisher(s)]]', publisher)
	appendIfExists('Publisher label', publabel)
	appendIfExists('Distributor(s)', distributor)
	appendIfExists('[[:Category:Software Developer|Developer(s)]]', developer)
	appendIfExists('Series', series)
	appendIfExists('[[:Category:Software|Category(s)]]', genre)
	appendIfExists('[[Game engine|Engine]]', engine)
	appendIfExists('Recommended age(s)', age)
	appendIfExists('[[Software content rating system|Rating(s)]]', ratings)
	appendIfExists('Language(s)', language)
	appendIfExists('Country of Origin', country)
	
	return html
end

return p