Module:Print ref/Info

-- These functions require an exact match to printCode (and issueNumber). Matcher will need to handle variations -- italics display by default for titles and linked titles, hence noItalics -- printEntry and issueEntry cannot be accessed outside of this module

local p = {}

p.work = function(frame) local printCode = frame.args[1] local issueNumber = frame.args[2] or nil local title = frame.args['title'] or nil local noItalics = frame.args['noitalics'] or nil local pagename = frame.args['pagename'] or nil local printDisplay = frame.args['printdisplay'] or nil local workType = frame.args['worktype'] or nil local issuePage = frame.args['issuepage'] or nil local issueTitle = frame.args['issuetitle'] or nil local issueDisplay = frame.args['issuedisplay'] or nil

if not isempty(title) then data = p.title(printCode, noItalics) elseif not isempty(pagename) then data = p.pagename(printCode) elseif not isempty(printDisplay) then data = p.printDisplay(printCode) elseif not isempty(workType) then data = p.workType(printCode) elseif not isempty(issuePage) then data = p.issuePage(printCode, issueNumber) elseif not isempty(issueTitle) then data = p.issueTitle(printCode, issueNumber) elseif not isempty(issueDisplay) then data = p.issueDisplay(printCode, issueNumber) else data = printCode end return data end

-- retrieves the matching top-level entry in Print ref/Array printEntry = function(printCode) local pra = mw.loadData('Module:Print ref/Array') local printEntry if not isempty(pra[printCode]) then printEntry = pra[printCode] else printEntry = { ['title'] = 'Unknown printed work', }   end return printEntry end

-- the issue-level entry in Print ref/Array issueEntry = function(printCode, issueNumber) local issueEntry local printEntry = printEntry(printCode) if not isempty(printEntry['issues']) then issueEntry = printEntry['issues'][issueNumber] else issueEntry = { ['page'] = 'Unknown issue', }   end return issueEntry end

p.title = function(printCode, noItalics) if noItalics ~= nil and noItalics ~= false then noItalics = true else noItalics = false end local printEntry = printEntry(printCode) local title = printEntry['title'] if noItalics == false then title = "''" .. title .. "''"   end return title end

p.pagename = function(printCode) local pagename local printEntry = printEntry(printCode) if printEntry['pagename'] then pagename = printEntry['pagename'] else pagename = printEntry['title'] end return pagename end

p.workType = function(printCode) local printEntry = printEntry(printCode) local workType = printEntry['workType'] return workType end

-- linked and italicized output for a printed work p.printDisplay = function(printCode) local printDisplay local pagename = p.pagename(printCode) local title = p.title(printCode, false) if pagename ~= title then printDisplay = pagename .. '|' .. title else printDisplay = pagename end printDisplay = "''" ..  .. printDisplay ..  .."''" return printDisplay end

p.issuePage = function(printCode, issueNumber) local issuePage local pagename = p.pagename(printCode) local issueEntry = issueEntry(printCode, issueNumber) if not isempty(issueEntry['page']) then issuePage = issueEntry['page'] else issuePage = pagename .. ' ' .. issueNumber end return issuePage end

p.issueTitle = function(printCode, issueNumber) local issueEntry = issueEntry(printCode, issueNumber) local title = p.title(printCode) local issueTitle if not isempty(issueEntry['displayTitle']) then issueTitle = issueEntry['displayTitle'] else issueTitle = title .. ' #' .. issueNumber end return issueTitle end

-- linked and italicized output for a comic by issue number p.issueDisplay = function(printCode, issueNumber) local issuePage = p.issuePage(printCode, issueNumber) local issueTitle = p.issueTitle(printCode, issueNumber) local issueDisplay =  .. issueTitle ..  return issueDisplay end

return p