Changes

Jump to: navigation, search

Module:Set page header

2,178 bytes added, 7 months ago
Making the region and edition matching more dynamic, less dependent on the "CG" in the page name
medium = {},
edition = nil,
releaseDate = nil, isParentSet = nil,
}
local function getRegion( pagename )
-- Get content after the first hyphen after the last `(` in the page name -- up until the next `-` or `)` -- More specifically match -- `(` -- Any amount of non-`(` non-`-` -- `-` -- Any amount of non-`(` non-`-` (Capture the text in this group) -- An optional `-` -- An optional amout of non-`(` non-`-` -- A `)` -- the end of the string local index = pagename:match( 'CG%([^%(-]*-([^%a+(-]*)-?[^%(-?]*%)$' )
local region = DATA.getRegion( index ) -- TODO: handle erroneous region (nil)?
local function getEdition( pagename )
-- Get content after the second hyphen after the last `(` in the page name. local index = pagename:match( 'CG%([^%(-]*-[^%a+(-]*-([^%-(]*)%w+)$' )
local edition = DATA.getEdition( index ) -- TODO: handle erroneous edition (nil)?
:wikitext( releaseData.region.full )
:wikitext( releaseData.edition and ( ' - %s' ):format( releaseData.edition.full ) )
 
-- If there is a release date, show it in the header
if ( releaseData.releaseDate ) then
header:tag( 'div' ):wikitext( '(Release date: ' .. releaseData.releaseDate .. ')' )
end
return tostring( header )
local function makeCategories( ns )
return table.concatlocal categories = { ( '[[Category:%s %s]]' ):format( releaseData.region.full, ns ), releaseData.edition and ( '[[Category:%s %s]]' ):format( releaseData.edition.full, ns ),
}
if ( releaseData.edition ) then
table.insert( categories, ( '[[Category:%s %s]]' ):format( releaseData.edition.full, ns ) )
end
 
if ( ns == 'Set Card Lists' and releaseData.isParentSet ) then
table.insert( categories, '[[Category:Set Card Lists for parent sets]]' )
end
 
-- Set lists with no release dates
-- Excludes lists for parent sets, whose children each have individual release dates
if ( ns == 'Set Card Lists' and not releaseData.releaseDate and not releaseData.isParentSet ) then
table.insert( categories, '[[Category:Set Card Lists with no release date]]' )
end
 
return table.concat(categories)
end
['Release'] = releaseData.medium and releaseData.medium.full,
['Language'] = releaseData.language.full,
['RegionLocality'] = releaseData.region and releaseData.region.full,
['Edition'] = releaseData.edition and releaseData.edition.full,
['Release date'] = releaseData.releaseDate
-- @return table name, localName, releaseDate
local function querySetData()
return local results = mw.smw.ask{
'[[' .. releaseData.set .. ']]',
'?English name = name' ,
'?' .. releaseData.language.full .. ' name = localName',
'?' .. releaseData.region.full .. ' release date = releaseDate',
-- Bit sloppy, but we need to fallback to this if "Worldwide English release date" is empty
'?English release date = englishReleaseDate',
'?-Parent set = isParentSet',
mainlabel = '-'
-- Reurn the first result, if there is one return results and results[1]
end
-- Set data for the `releaseData` table based on the page name and parameters
local function setReleaseData( ns, currentPageName, args )
-- Set the set page equal to the supplied set
-- or defaul to to the one that can be inferred from the page name
-- Query the set page to find more information
local queriedData = querySetData()
 
-- Exit early if no results were found
if ( not queriedData ) then
-- todo: Tracking category
return
end
-- Update the `releaseData` object based on the results of the query
releaseData.name = queriedData.name
releaseData.localName = args.name or queriedData.localName
releaseData.isParentSet = queriedData.isParentSet and true or false  -- For now, only do the release date for list pages -- Don't add it to parent set lists e.g. the overall "Shonen Jump promotional cards" list -- which have multiple releases, each with their own set list. if ( ns == 'Set Card Lists' and not queriedData.isParentSet ) then releaseData.releaseDate = args.releaseDate or queriedData.releaseDate  -- If 'Worldwide English' and the `releaseDate` is empty, check the `englishReleaseDate` if ( not releaseData.releaseDate and releaseData.region.full == 'Worldwide English' ) then releaseData.releaseDate = queriedData.englishReleaseDate end end
end
-- Update the `releaseData` object based on information from the page name
-- and the supplied arguments.
setReleaseData( ns, currentTitle.text, args )
-- Get the header wikitext

Navigation menu