Module:Format work
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module depends on the following other modules: |
This module is invoked by {{format work}} |
Usage
This module returns details supplied about a creative work, formatted inline with MOS:DISCOGRAPHY or MOS:FILMOGRAPHY of MOS:WORKS, and suitable for display in an article list.
{{#invoke:Format work|main
| act = <!-- required; "Pink Floyd" or "[[Pink Floyd (band)|Pink Floyd]]" -->
| title = <!-- required; "The Dark Side of the Moon" or "[[The Dark Side of the Moon (album)|The Dark Side of the Moon]]" -->
| type = <!-- "minor" to override the default "major" -->
| label = <!-- for a musical release; "Harvest Records" or "[[Harvest Records|Harvest]]" -->
| distributor = <!-- for a film release; "Lionsgate Studios" or "[[Lionsgate Studios|Lionsgate]]" -->
| year = <!-- "1973" -->
| month = <!-- "3" -->
| day = <!-- "1" -->
| page = <!-- only if |day= is provided; "Pink Floyd discography" -->
| notes = <!-- "There is no dark side in the moon, really. Matter of fact, it's all dark." -->
}}
act and title
Required
|act=should be an artist, group, ensemble, actor etc.|title=should be the title of the creative work
Both values may be plain text or wikilinks; plain text will be automatically linked if a suitable matching article exists.
For example:{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
{{#invoke:Format work|main
| act = [[Pink Floyd (band)|Pink Floyd]]
| title = [[The Dark Side of the Moon (album)|The Dark Side of the Moon]]
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
type
By default, the |type= of the work is treated as "major"; use |type=minor to override this. See MOS:NAT for guidance.
{{#invoke:Format work|main
| act = Pink Floyd
| title = [[Eclipse (Pink Floyd song)|Eclipse]]
| type = minor
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
label or distributor
For musical works, |label= may be used, and |distributor= may be used for films, if suitable.
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| label = [[Harvest Records|Harvest]]
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
year and month
Providing a date must include a |year=; if no year is provided, |month= and |day= will be ignored.
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| year = 1973
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| year = 1973
| month = 3
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
day and page
If the |day= is provided, the date format will be automatically established via Module:Get article date format, which will return its default (day month year) unless an article |page= is provided. The article will be probed for explicit date formatting requirements established by use of {{use dmy dates}} or {{use mdy dates}}, or for implicit expectations due to an established English variant. The practical upshot should be for formatting lists of works on articles with established date formats, just provide the {{FULLPAGENAME}}.
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| year = 1973
| month = 3
| day = 1
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
{{#invoke:Format work|main
| act = Captain Beefheart
| title = Trout Mask Replica
| year = 1969
| month = 6
| day = 16
| page = Captain Beefheart
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
notes
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| notes = There is no dark side in the moon, really. Matter of fact, it's all dark.
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
Complete examples
{{#invoke:Format work|main
| act = Pink Floyd
| title = The Dark Side of the Moon
| label = [[Harvest Records|Harvest]]
| year = 1973
| month = 3
| day = 1
| page = Pink Floyd
| notes = There is no dark side in the moon, really. Matter of fact, it's all dark.
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
{{#invoke:Format work|main
| act = Captain Beefheart
| title = Trout Mask Replica
| label = [[Straight Records|Straight]]
| year = 1969
| month = 6
| day = 16
| page = Captain Beefheart
| notes = produced by [[Frank Zappa]]
}}
Returns: ERROR with invocation of Module:User:Fred Gandt: a page name (including namespace) MUST be provided
Alarming messages
Alarming messages will be returned if values for the required |act= and |title= are not provided.
local p = {}
local function errorMessage( message )
return '<strong class="error">ERROR with invocation of [[Module:User:Fred Gandt]]: ' .. message .. '</strong>'
end
local function getWikidataDescription( name, lang )
local wikidata_id = mw.wikibase.getEntityIdForTitle( name )
if not wikidata_id then
return nil
end
local wikidata_description, wikidata_description_lang = mw.wikibase.getDescriptionWithLang( wikidata_id )
if not wikidata_description then
return nil
end
if lang.no or wikidata_description_lang == 'en' then
return wikidata_description
end
if not wikidata_description_lang then
return nil
end
local current_frame = mw.getCurrentFrame()
if not current_frame then
return errorMessage( 'could not getCurrentFrame' )
end
local non_english_wikidata_description = current_frame:expandTemplate {
title = 'lang',
args = {
wikidata_description_lang,
wikidata_description,
italic = lang.italic or '',
nocat = lang.nocat or '',
size = lang.size or '',
cat = lang.cat or '',
rtl = lang.rtl or ''
}
}
if not non_english_wikidata_description then
return errorMessage( 'could not expandTemplate lang' )
end
return non_english_wikidata_description
end
local function getImplicitDescription()
--[[
for m in string.gmatch( 'string', 'pattern' ) do
mw.log( m )
end
--]]
--[[
local current_title = mw.title.getCurrentTitle()
if not current_title then
return errorMessage( 'could not getCurrentTitle' )
end
--]]
-- let's assume that implicit descriptions will generally be set by infoboxes, but could be from anywhere
-- it would therefore makes sense to cycle through any infoboxes first
--[[ get the lead infoboxes (there might be none or many) first, since they're the most likely to place any implicit description ]]
--[[ since we will be preprocessing them, strip a bunch of stuff we definitely don't need or want ]]
--[[ being infoboxes; there SHOULD be no references, but since when did that stop anyone? -_- ]]
--local lead_infoboxes = getTransclusion( 'The Partisan#', { only = 'templates', categories = 0, references = 0, files = 0, templates = '[Ii]nfobox' } )
--mw.log( lead_infoboxes )
--[[ split the results, and loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if we didn't get a hit...
--[[ get any remaining infoboxes; multiple infoboxes is unusual, but this will unfortunately get the lead infobox again if there is one ]]
--[[ why not just do this first? because it's much more expensive and a lot less likely to be useful ]]
--[[ again; strip the stuff we don't need or want ]]
--local all_infoboxes = getTransclusion( 'The Partisan', { only = 'templates', categories = 0, references = 0, files = 0, templates = '[Ii]nfobox' } )
--mw.log( all_infoboxes )
--[[ split the results ]]
--[[ obviously, we don't want to preprocess the same infobox again, so ignore it ]]
--[[ if there are any more, loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if they weren't helpful, it's probably a good idea to stop doing this, but if you insist...
--[[ get all templates that aren't {{cite*}}s; it would be nice to not get infoboxes too, but that doesn't seem possible ]]
--[[ again; strip the stuff we don't need or want ]]
--local all_other_templates = getTransclusion( 'The Partisan', { only = 'templates', categories = 0, references = 0, files = 0, templates = '-[Cc]ite' } )
--mw.log( all_other_templates )
--[[ split the results ]]
--[[ obviously, we don't want to preprocess the infoboxes again, so ignore them ]]
--[[ if there are any more, loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if they didn't spit one out, we consider ourselves lucky to have survived
-- NOTE: if there are multiple implicit descriptions being set, it's theoretically possible we could find one that's redundant
-- I have zero intention to address this possibility
--[[
local current_title_lead_infobox = getTransclusion( tostring( current_title ), { only = 'templates' } )
if not current_title_lead_infobox then
return nil
end
current_title_lead_infobox = mw.text.trim( current_title_lead_infobox )
if not current_title_lead_infobox or current_title_lead_infobox == '' then
return nil
end
local current_frame = mw.getCurrentFrame()
if not current_frame then
return errorMessage( 'could not getCurrentFrame' )
end
local preprocessed_current_title_lead_infobox = current_frame:preprocess( current_title_lead_infobox )
if not preprocessed_current_title_lead_infobox then
return errorMessage( 'could not preprocess current_title_lead_infobox' )
end
-- <div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">19th episode of the 7th season of Star Trek: Voyager</div>
-- right at the start too :)
return mw.text.nowiki( preprocessed_current_title_lead_infobox )
--]]
end
local function getExplicitDescription( name )
local page_content = mw.title.new( name ):getContent()
if not page_content then
return errorMessage( 'could not getContent' )
end
local short_description_template = string.match( page_content, '{{%s*[Ss]hort description%s*|.-}}' )
if not short_description_template then
return nil
end
local current_frame = mw.getCurrentFrame()
if not current_frame then
return errorMessage( 'could not getCurrentFrame' )
end
local preprocessed_short_description_template = current_frame:preprocess( short_description_template )
if not preprocessed_short_description_template then
return errorMessage( 'could not preprocess short_description_template' )
end
return string.match( preprocessed_short_description_template, '>%s*(.-)%s*<' )
end
local function getShortDescription( args )
local name = args.name
if not name then
return errorMessage( 'a page name (including namespace) MUST be provided' )
end
local result
local only = args.only
local prefer = args.prefer or 'explicit'
local lang = {}
lang.italic = args.lang_italic
lang.nocat = args.lang_nocat
lang.size = args.lang_size
lang.cat = args.lang_cat
lang.rtl = args.lang_rtl
lang.no = args.lang_no
if only == 'explicit' then
result = getExplicitDescription( name )
elseif only == 'wikidata' then
result = getWikidataDescription( name, lang )
elseif prefer == 'explicit' then
result = getExplicitDescription( name ) or getWikidataDescription( name, lang )
elseif prefer == 'wikidata' then
result = getWikidataDescription( name, lang ) or getExplicitDescription( name )
end
return result or args.fallback
end
function p.main( frame )
local args = frame.args
local result = getShortDescription( args ) or ''
mw.log( result )
return result
end
return p