Module:Magazine: Difference between revisions
From Eli's Software Encyclopedia
Created page with "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 founders local function addIfNotEmpty(tbl, val) if val and val ~= '' then table.insert(tbl,..." |
mNo edit summary |
||
| Line 47: | Line 47: | ||
local country = args['country'] or '' | local country = args['country'] or '' | ||
local language = args['language'] or '' | local language = args['language'] or '' | ||
local image = args['image'] or '' | |||
local infoboxImage = '' | local infoboxImage, infoboxCaption = '', '' | ||
if image ~= '' then | if image ~= '' then | ||
infoboxImage = frame:preprocess('{{PAGENAME:' .. image .. '}}') | infoboxImage = frame:preprocess('{{PAGENAME:' .. image .. '}}') | ||
infoboxCaption = args['caption'] or '' | |||
end | end | ||
Revision as of 15:11, August 19, 2025
Documentation for this module may be created at Module:Magazine/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 founders
local function addIfNotEmpty(tbl, val)
if val and val ~= '' then
table.insert(tbl, val)
end
end
local foundersTable = {}
local magfounder1 = args['magfounder1'] or ''
local magfounder2 = args['magfounder2'] or ''
local magfounder3 = args['magfounder3'] or ''
local magfounder4 = args['magfounder4'] or ''
addIfNotEmpty(foundersTable, magfounder1)
addIfNotEmpty(foundersTable, magfounder2)
addIfNotEmpty(foundersTable, magfounder3)
addIfNotEmpty(foundersTable, magfounder4)
-- Get other properties
local title = args['magtitle'] or titleObj.text
local publisher = args['publisher'] or ''
local location = args['maglocation'] or ''
local magazineCategory = args['magcategory']
local magazineFrequency = args['magfrequency']
local magazineFormat = args['magformat']
local circulation = args['magcirculation'] or ''
local firstIssueDate = args['magfirstissue'] or ''
local finalIssueDate = args['magfinalissue'] or ''
local issn = args['issn'] or ''
local eissn = args['eissn'] or ''
local oclc = args['oclc'] or ''
local website = args['magwebsite'] or ''
local country = args['country'] or ''
local language = args['language'] or ''
local image = args['image'] or ''
local infoboxImage, infoboxCaption = '', ''
if image ~= '' then
infoboxImage = frame:preprocess('{{PAGENAME:' .. image .. '}}')
infoboxCaption = args['caption'] or ''
end
-- Set properties
local data = {
'Magazine Title=' .. title,
'Location=' .. location,
'Founded By=' .. table.concat(foundersTable, ', '),
'+sep=,',
'Publisher=' .. publisher,
'Magazine Category=' .. magazineCategory,
'Magazine Frequency=' .. magazineFrequency,
'Magazine Format= ' .. magazineFormat,
'Has Circulation=' .. circulation,
'First Issue Date=' .. firstIssueDate,
'Final Issue Date=' .. finalIssueDate,
'ISSN=' .. issn,
'EISSN=' .. eissn,
'OCLC=' .. oclc,
'Website URL=' .. website,
'Country=' .. country,
'Language=' .. language,
'Has Image=' .. infoboxImage,
'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 ~= '' and showImage == 'yes' 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]]',
infoboxImage, 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('Based In', location)
appendIfExists('Publisher', publisher)
if founders ~= '' then
infobox:node(utils.authorRow(utils.buildAuthorOutput(founders)))
end
appendIfExists('Category', magazineCategory)
appendIfExists('Frequency', magazineFrequency)
appendIfExists('Format', magazineFormat)
appendIfExists('Circulation', circulation)
appendIfExists('First Issue Date', firstIssueDate)
appendIfExists('Final Issue Date', finalIssueDate)
appendIfExists('ISSN', isbn)
appendIfExists('EISSN', eissn)
appendIfExists('OCLC', oclc)
appendIfExists('Website', website)
appendIfExists('Country', country)
appendIfExists('Language', language)
return html
end
return p
