Module:Person/class
From Semantic MediaWiki - Sandbox
This module holds a lua class representing a person. It uses Module:SSC base for its functionality and gets its configuration from Module:Person/config.
Usage
local person = require( 'Module:Person/class' ):new()
-- for example, this call would be placed inside the main function called on the template:
return person:renderPage()
For available public methods see Module:SSC base.
local comicBooks = require( 'Module:Comic books/class' )
local config = mw.loadData( 'Module:Person/config' )
local class = require( 'Module:SSC base' )
local person = class:new( config )
function person:alterDataAfterStorage( data )
local data = data
if not data.profession then
data.profession = 'unknown'
end
if not data.firstname and not data.lastname then
data.firstname = 'John'
data.lastname = 'Doe'
data.name = data.firstname .. ' ' .. data.lastname
else
data.name = data.firstname or data.lastname
end
if data['date of birth'] and mw.ustring.find( data['date of birth'], '/', 1, true ) then
local date = mw.text.split( data['date of birth'], '/', true )
data['date of birth'] = date[2] .. '.' .. date[1] .. '.' .. date[3]
end
return data
end
function person:extractCollaborations( dataArray )
local collaborationData = {}
local dataArray = dataArray
for _, row in pairs( dataArray ) do
if row.artist then
for _, artist in pairs( row.artist ) do
if not collaborationData[artist] then
collaborationData[artist] = {}
end
table.insert( collaborationData[artist], row._mainlabel )
end
end
end
local collaborations = {}
for artist, works in pairs( collaborationData ) do
table.insert(
collaborations,
comicBooks:getPrintout( 'artist', artist ) .. ' (on [[' .. mw.text.listToText( works, ']], [[', ']] and [[' ) .. ']])'
)
end
table.sort( collaborations )
if #collaborations == 0 then
return 'none'
else
return '\n* ' .. table.concat( collaborations, '\n* ' ) .. '\n'
end
end
function person:extractWorks( dataArray )
local works = {}
local dataArray = dataArray
local comicBookData = self:buildArrayIndexedByField(dataArray, '_mainlabel')
for _, row in pairs( dataArray ) do
local work = '[[' .. row._mainlabel .. ']]'
if row.publisher then
work = work
.. ' (for ' .. comicBooks:getPrintout( 'publisher', row.publisher )
.. ( row['publication year'] and (' in ' .. row['publication year']) or '' ) .. ')'
end
if comicBookData[row._mainlabel] then
work = work .. ' ' .. mw.smw.info(comicBooks:formatToolTip(row))
end
table.insert( works, work )
end
table.sort( works )
if #works == 0 then
return 'none'
else
return '\n* ' .. table.concat( works, '\n* ' ) .. '\n'
end
end
function person:getPersonVitae()
local cbData, query = comicBooks:retrieveClassData( '[[Has comic book writer::' .. mw.title.getCurrentTitle().text .. ']]' )
cbData = cbData or {}
return '\n'
.. '=== Works ===\n' .. self:extractWorks( cbData ) .. '\n'
.. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n'
end
function person:renderPage()
return class.renderPage( self )
.. self:getPersonVitae()
end
return person