Module:Publisher
From Eli's Software Encyclopedia
Documentation for this module may be created at Module:Publisher/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 bodyclass = args['bodyclass'] or 'vevent'
local titleclass = args['titleclass'] or 'fn summary'
local class1 = args['class1'] or 'organiser'
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['name'] or args['Name'] or args['title'] or titleObj.text
local address = args['address'] or args['Address'] or ''
local country = args['country'] or args['Country'] or ''
local founded = args['founded'] or args['Founded'] or ''
local defunct = args['defunct'] or args['Defunct'] or ''
local acquiredBy = args['acquiredby'] or args['Acquired by'] or ''
local labelOf = args['labelof'] or args['Label of'] or ''
local phone = args['phone'] or args['Phone'] or ''
local fax = args['fax'] or args['Fax'] or ''
local website = args['website'] or args['Website'] or ''
local websiteUrl = utils.getUrlFromLink(website) or ''
local renamed = args['renamed'] or args['Renamed'] or ''
local formerly = args['formerly'] or args['Formerly'] or ''
-- Get and process a logo
local logo = args['logo'] or args['Logo'] or ''
local logoFilename = ''
if logo ~= '' then
logoFilename = frame:preprocess('{{PAGENAME:' .. logo .. '}}')
end
-- Get and process an image
local image = args['image'] or args['photo'] or args['Photo'] or ''
local imageFilename, imageAlt, imageCaption = '', '', ''
if image ~= '' then
local fn, alt = utils.parseFileLink(image)
if fn then
imageFilename = fn
imageAlt = alt or args['caption'] or args['Caption'] or ''
else
imageFilename = frame:preprocess('{{PAGENAME:' .. image .. '}}')
end
imageCaption = args['caption'] or args['Caption'] or ''
end
-- Set properties
local data = {
'Has Title=' .. title,
'Has Logo=' .. logoFilename,
'Has Image=' .. imageFilename,
'Has Image Caption=' .. imageCaption,
'Address=' .. address,
'Country=' .. country,
'Foundation Date=' .. founded,
'Defunct Info=' .. defunct,
'Acquired By=' .. utils.unwrapList(utils.unwrapLink(acquiredBy)),
'+sep=;',
'Label=' .. labelOf,
'Phone=' .. phone,
'Fax=' .. fax,
'Website URL=' .. websiteUrl,
'Renaming Info=' .. renamed,
'Formerly Known As=' .. formerly
}
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
-- Assign category
local category = string.format('[[Category:%s]]', 'Software Publisher') or ''
-- 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(category .. 'Publisher '):done()
infobox:node(headerTr)
-- Logo
if logo ~= '' then
local logoTr = mw.html.create('tr')
logoTr:tag('td'):attr('colspan', '2'):addClass('text-center px-0')
:wikitext(string.format('[[File:%s|class=img-fluid|%s]]',
logoFilename, 'Logo of ' .. title
))
infobox:node(logoTr)
end
-- 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, link, splitsep, class)
local tr = utils.addLabelValue(label, value, link, splitsep, class)
if tr then infobox:node(tr) end
end
appendIfExists('Name', title, 'none', ';', 'font-weight-bold')
appendIfExists('Address', address, 'none', ';')
appendIfExists('Country', country)
appendIfExists('Founded', founded)
appendIfExists('Defunct', defunct)
appendIfExists('Acquired by', utils.unwrapList(utils.unwrapLink(acquiredBy)), 'link', ';')
appendIfExists('Label of', labelOf, 'link')
appendIfExists('Phone', phone)
appendIfExists('Fax', fax)
appendIfExists('Website', utils.printExternalLink(websiteUrl, title), 'none', ';')
appendIfExists('Renamed', renamed, 'none', ';')
appendIfExists('Formerly', formerly, 'link', ';')
return html
end
return p
