Module:Magazine: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 45: Line 45:
local oclc        = args['oclc'] or ''
local oclc        = args['oclc'] or ''
local website    = args['magwebsite'] or ''
local website    = args['magwebsite'] or ''
local websiteUrl  = utils.getUrlFromLink(website) or ''
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 image      = args['image'] or ''
local infoboxImage, infoboxCaption = '', ''
local imageFilename, imageAlt, imageCaption = '', '', ''
if image ~= '' then
if image ~= '' then
infoboxImage = frame:preprocess('{{PAGENAME:' .. image .. '}}')
local fn, alt = utils.parseFileLink(image)
infoboxCaption = args['caption'] or ''
if fn then
    imageFilename = fn
        imageAlt  = alt or imageCaption or ''
        else
        imageFilename = frame:preprocess('{{PAGENAME:' .. image .. '}}')
    end
end
end
-- Set properties
-- Set properties
Line 61: Line 68:
     'Founded By=' .. table.concat(foundersTable, ', '),
     'Founded By=' .. table.concat(foundersTable, ', '),
     '+sep=,',
     '+sep=,',
     'Publisher=' .. publisher,
     'Publisher name=' .. publisher,
'Magazine Category=' .. magazineCategory,
'Magazine Category=' .. magazineCategory,
'Magazine Frequency=' .. magazineFrequency,
'Magazine Frequency=' .. magazineFrequency,
Line 71: Line 78:
     'EISSN=' .. eissn,
     'EISSN=' .. eissn,
     'OCLC=' .. oclc,
     'OCLC=' .. oclc,
     'Website URL=' .. website,
     'Website URL=' .. websiteUrl,
     'Country=' .. country,
     'Country=' .. country,
     'Language=' .. language,
     'Language=' .. language,
     'Has Image=' .. infoboxImage,
     'Has Image=' .. imageFilename,
     'Has Image Caption=' .. imageCaption
     'Has Image Caption=' .. imageCaption
}
}
Line 106: Line 113:
     imgTr:tag('td'):attr('colspan', '2'):addClass('text-center px-0')
     imgTr:tag('td'):attr('colspan', '2'):addClass('text-center px-0')
:wikitext(string.format('[[File:%s|class=img-fluid|%s]]',
:wikitext(string.format('[[File:%s|class=img-fluid|%s]]',
infoboxImage, imageCaption
imageFilename, imageCaption
))
))
     infobox:node(imgTr)
     infobox:node(imgTr)
Line 119: Line 126:
-- Print data rows
-- Print data rows
local function appendIfExists(label, value)
local function appendIfExists(label, value, link)
     local tr = utils.addLabelValue(label, value)
     local tr = utils.addLabelValue(label, value, link)
     if tr then infobox:node(tr) end
     if tr then infobox:node(tr) end
end
end
Line 127: Line 134:
appendIfExists('Based In', location)
appendIfExists('Based In', location)
appendIfExists('Publisher', publisher)
appendIfExists('Publisher', publisher)
if founders ~= '' then
if #foundersTable > 0 then
infobox:node(utils.authorRow(utils.buildAuthorOutput(founders)))
infobox:node(utils.authorRow(utils.buildAuthorOutput(table.concat(foundersTable, ','), 'Founder', 'Founders')))
end
end
appendIfExists('Category', magazineCategory)
appendIfExists('Category', magazineCategory)

Latest revision as of 20:54, December 10, 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 websiteUrl  = utils.getUrlFromLink(website) 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 = {
    	'Magazine Title=' .. title,
    	'Location=' .. location,
    	'Founded By=' .. table.concat(foundersTable, ', '),
    	'+sep=,',
    	'Publisher name=' .. 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=' .. websiteUrl,
    	'Country=' .. country,
    	'Language=' .. language,
    	'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 ~= '' 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]]',
				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)
    	local tr = utils.addLabelValue(label, value, link)
    	if tr then infobox:node(tr) end
	end
	
	appendIfExists('Title', title)
	appendIfExists('Based In', location)
	appendIfExists('Publisher', publisher)
	if #foundersTable > 0 then
		infobox:node(utils.authorRow(utils.buildAuthorOutput(table.concat(foundersTable, ','), 'Founder', '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