Templates that use this module:
local p = {}
function getWorkByPageName( pageName )
local title = mw.title.new( pageName )
if title.isRedirect then
title = title.redirectTarget
end
local args = {
where = '_pageName = "' .. title.text .. '"',
join = '',
limit = 1
}
local results = mw.ext.cargo.query( 'works', '_pageName,type,title,authors,date,publisher,url,location,part_of', args )
if #results == 0 then
return nil
end
return results[1]
end
-- =p.cite({args={'ADB'}})
p.cite = function( frame )
if frame.args[1] == nil or frame.args[1] == '' then
return ''
end
local ident = mw.text.trim( frame.args[1] )
local work = getWorkByPageName( ident )
if work == nil then
local createUrl = mw.title.new( ident ):canonicalUrl( { action = 'edit', preload = 'Template:Work/preload' } )
return '<span class="error">[Work not found: "[' .. createUrl .. ' ' .. ident .. ']"]</span>'
end
local citation = ''
if work.authors ~= nil then
citation = work.authors .. ' '
end
citation = citation .. '[[' .. work._pageName .. '|' .. work.title .. ']] ' .. work.date
if work.publisher ~= nil then
citation = citation .. ' (' .. work.publisher
if work.location ~= nil then
citation = citation .. ', ' .. work.location
end
citation = citation .. ')'
end
if work.part_of ~= nil then
citation = citation .. ', part of [[' .. work.part_of .. ']]'
end
if frame.args.id ~= nil and frame.args.id ~= '' then
citation = citation .. ', Identifier: ' .. frame.args.id
end
return citation
end
function getSubpageContent( frame )
local title = ''
if frame.args.title then
title = frame.args.title
end
local currentTitleParts = mw.text.split( mw.title.getCurrentTitle().text, '/' )
local parentPage = currentTitleParts[1]
local workType = 'written work'
local args = {}
local work = getWorkByPageName( parentPage )
local link = parentPage
if work ~= nil then
workType = work.type
if work.title ~= title then
link = '[[' .. parentPage .. '|' .. work.title .. ']]'
end
end
local out = mw.html.create( 'div' )
:attr( 'class', 'mdl-work-subpage' )
:wikitext(
"This page is part of a " .. workType .. " relating to Fremantle that is documented on Freopedia."
.. " For more information, see " .. link .. "."
)
local styles = mw.getCurrentFrame():extensionTag( 'templatestyles', nil, { src = 'Module:Infobox/styles.css' } )
return styles .. tostring( out )
end
-- =p.main({args={tags="Lorem; Ipsum;"}})
p.main = function( frame )
local currentTitle = mw.title.getCurrentTitle()
if string.match( currentTitle.text, '/' ) then
return getSubpageContent( frame )
end
local type = 'written work'
if frame.args.type ~= nil and frame.args.type ~= '' then
type = frame.args.type
end
-- Image (without leading 'File:')
local image = ''
local imageDisplay = ''
if frame.args.image ~= nil and frame.args.image ~= '' then
image = frame.args.image
imageDisplay = '[[File:' .. image .. '|right|300px]]'
end
-- Title
local title = currentTitle.text
if frame.args.title ~= nil and frame.args.title ~= '' then
title = frame.args.title
end
-- Authors
local authors = ''
local authorsDisplay = ''
if frame.args.authors ~= nil and frame.args.authors ~= '' then
authors = frame.args.authors
authorsDisplay = '[[' .. table.concat( mw.text.split( frame.args.authors, '; ', true ), ']], [[' ) .. ']]'
end
local publisher = ''
local publisherDisplay = ''
if frame.args.publisher ~= nil and frame.args.publisher ~= '' then
publisher = frame.args.publisher
publisherDisplay = ' ' .. publisher
end
local location = ''
local locationDisplay = ''
if frame.args.location ~= nil and frame.args.location ~= '' then
location = frame.args.location
locationDisplay = ' (' .. location .. ')'
end
local partOf = ''
local partOfDisplay = ''
if frame.args.part_of ~= nil and frame.args.part_of ~= '' then
partOf = frame.args.part_of
partOfDisplay = ' [[' .. partOf .. ']]'
end
local date = ''
if frame.args.date ~= nil and frame.args.date ~= '' then
date = frame.args.date
end
local url = currentTitle:localUrl()
if frame.args.url ~= nil and frame.args.url ~= '' then
url = frame.args.url
end
-- Tags.
local tags = ''
local tagsDisplay = ''
if frame.args.tags ~= nil and frame.args.tags ~= '' then
local tagVals = {}
for i,t in pairs( mw.text.split( frame.args.tags, ';' ) ) do
if t ~= '' then
tagVals[ #tagVals + 1 ] = t
end
end
if #tagVals > 0 then
tags = table.concat( tagVals, '; ' )
tagsDisplay = '[[' .. table.concat( tagVals, ']]; [[' ) .. ']]';
end
end
-- Wikidata
local wikidata = ''
local wikidataDisplay = ''
if frame.args.wikidata ~= nil and frame.args.wikidata ~= '' then
local wikidataItem = mw.ext.UnlinkedWikibase.getEntity( frame.args.wikidata );
if wikidataItem ~= nil and wikidataItem ~= 'item-not-found' then
wikidata = wikidataItem.id
wikidataDisplay = 'Wikidata, [[wikidata:' .. wikidata .. '|' .. wikidata .. ']].'
end
end
-- Fremantle BRN
local fremantleBrn = ''
local fremantleBrnDisplay = ''
if frame.args.fremantle_brn ~= nil and frame.args.fremantle_brn ~= '' then
fremantleBrn = frame.args.fremantle_brn
fremantleBrnDisplay = 'Spydus, [https://fremantle.spydus.com/cgi-bin/spydus.exe/ENQ/WPAC/BIBENQ?SETLVL=&BRN=' .. fremantleBrn .. ' ' .. fremantleBrn .. '].'
end
-- Store data in Cargo (mainspace pages only)
if currentTitle.namespace == 0 then
mw.getCurrentFrame():callParserFunction( '#cargo_store', {
'_table=works',
wikidata = wikidata,
fremantle_brn = fremantle_brn,
image = image,
title = title,
authors = authors,
publisher = publisher,
location = location,
part_of = partOf,
tags = tags,
date = date,
url = url,
type = type
} )
end
local out = imageDisplay
.. "This page is a record of a [[works|" .. type .. "]] relating to Fremantle.\n"
.. "* '''Part of:''' " .. partOfDisplay .. "\n"
.. "* '''Title:''' " .. title .. "\n"
.. "* '''Authors:''' " .. authorsDisplay .. "\n"
.. "* '''Published:''' " .. date .. publisherDisplay .. locationDisplay .. "\n"
.. "* '''Reference URL:''' " .. url .. "\n"
.. "* '''Tags:''' " .. tagsDisplay .. "\n"
.. "* '''Authority control:''' " .. wikidataDisplay .. ' ' .. fremantleBrnDisplay .. "\n"
local styles = mw.getCurrentFrame():extensionTag( 'templatestyles', nil, { src = 'Module:Infobox/styles.css' } )
return styles .. out
end
return p