« Module:Person/class » : différence entre les versions
De Semantic MediaWiki - Sandbox
Aucun résumé des modifications |
Aucun résumé des modifications |
||
(26 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 1 : | Ligne 1 : | ||
local comicBooks = require( 'Module:Comic books/class' ) | |||
local config = mw.loadData( 'Module:Person/config' ) | local config = mw.loadData( 'Module:Person/config' ) | ||
local class = require( 'Module:SSC base' ) | local class = require( 'Module:SSC base' ) | ||
local person = class:new( config ) | local person = class:new( config ) | ||
Ligne 28 : | Ligne 28 : | ||
function person:extractCollaborations( dataArray ) | function person:extractCollaborations( dataArray ) | ||
local collaborationData = {} | local collaborationData = {} | ||
local dataArray = dataArray | |||
for _, row in pairs( dataArray ) do | for _, row in pairs( dataArray ) do | ||
if row.artist then | if row.artist then | ||
Ligne 38 : | Ligne 39 : | ||
end | end | ||
end | end | ||
local collaborations = {} | local collaborations = {} | ||
for artist, works in pairs( collaborationData ) do | for artist, works in pairs( collaborationData ) do | ||
table.insert( | table.insert( | ||
collaborations, | collaborations, | ||
comicBooks:getPrintout( 'artist', artist ) .. '(on [[' .. mw.text.listToText( works, ']], [[', ']] and [[' ) .. ']])' | comicBooks:getPrintout( 'artist', artist ) .. ' (on [[' .. mw.text.listToText( works, ']], [[', ']] and [[' ) .. ']])' | ||
) | ) | ||
end | end | ||
Ligne 56 : | Ligne 58 : | ||
function person:extractWorks( dataArray ) | function person:extractWorks( dataArray ) | ||
local works = {} | local works = {} | ||
local dataArray = dataArray | |||
local comicBookData = self:buildArrayIndexedByField(dataArray, '_mainlabel') | |||
for _, row in pairs( dataArray ) do | for _, row in pairs( dataArray ) do | ||
local work = '[[' .. row._mainlabel .. ']]' | local work = '[[' .. row._mainlabel .. ']]' | ||
Ligne 62 : | Ligne 66 : | ||
.. ' (for ' .. comicBooks:getPrintout( 'publisher', row.publisher ) | .. ' (for ' .. comicBooks:getPrintout( 'publisher', row.publisher ) | ||
.. ( row['publication year'] and (' in ' .. row['publication year']) or '' ) .. ')' | .. ( row['publication year'] and (' in ' .. row['publication year']) or '' ) .. ')' | ||
end | |||
if comicBookData[row._mainlabel] then | |||
work = work .. ' ' .. mw.smw.info(comicBooks:formatToolTip(row)) | |||
end | end | ||
table.insert( works, work ) | table.insert( works, work ) | ||
Ligne 75 : | Ligne 82 : | ||
function person:getPersonVitae() | function person:getPersonVitae() | ||
local cbData = comicBooks | local cbData, query = comicBooks:retrieveClassData( '[[Has comic book writer::' .. mw.title.getCurrentTitle().text .. ']]' ) | ||
cbData = cbData or {} | cbData = cbData or {} | ||
return '\n=== Works ===\n' .. self:extractWorks( cbData ) .. '\n' | return '\n' | ||
.. '=== Works ===\n' .. self:extractWorks( cbData ) .. '\n' | |||
.. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n' | .. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n' | ||
end | end | ||
function person:renderPage() | function person:renderPage() | ||
return class.renderPage( self ) | |||
.. self:getPersonVitae() | |||
return class.renderPage( self ) | |||
end | end | ||
return person | return person |
Dernière version du 19 janvier 2017 à 08:20
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