Difference between pages "Module:Card table sets" and "Module:Card table sets/sandbox"

(Difference between pages)
Jump to: navigation, search
Page 1
Page 2
(Fix for cases where it makes sense to show the dab text on set names (such as reprint sets of Legendary Collection: 25th Anniversary Edition).)
 
(Distinguish th elements using CSS classes.)
 
Line 12: Line 12:
 
local Reporter = require( 'Module:Reporter' )
 
local Reporter = require( 'Module:Reporter' )
 
local StringBuffer = require( 'Module:StringBuffer' )
 
local StringBuffer = require( 'Module:StringBuffer' )
 
local DATA_REGIONS = DATA( 'region' )
 
local DATA_LANGUAGES = DATA( 'language' )
 
  
 
local LANGUAGE_ENGLISH = DATA.getLanguage( 'English' )
 
local LANGUAGE_ENGLISH = DATA.getLanguage( 'English' )
Line 22: Line 19:
  
 
local reporter;
 
local reporter;
 
local KEY_DATE = 'SET_DATE'
 
local KEY_NAME = 'SET_NAME'
 
 
local CONTROL_PROP = 'Modification date'
 
  
 
local function formatCardNumber( cardNumber )
 
local function formatCardNumber( cardNumber )
Line 34: Line 26:
 
end
 
end
  
local function linkRarities( rarities, lineno )
+
local function validateRarities( rarities, lineno )
local linked = {}
+
local validated = {}
 
 
local duplicated = {}
 
  
 
local position = 0
 
local position = 0
 
local nonEmptyposition = 0
 
  
 
for _, r in ipairs( rarities ) do
 
for _, r in ipairs( rarities ) do
position = position + 1
 
 
 
if UTIL.trim( r ) then
 
if UTIL.trim( r ) then
nonEmptyposition = nonEmptyposition + 1
+
position = position + 1
  
 
local rarity = DATA.getRarity( r )
 
local rarity = DATA.getRarity( r )
  
 
if rarity then
 
if rarity then
if duplicated[ rarity.full ] then
+
table.insert( validated, rarity.full )
local message = ( 'Duplicate rarity `%s` (same as `%s`, at non-empty position `%d`), at non-empty input line %d, at non-empty position %d.' )
 
:format(
 
r,
 
duplicated[ rarity.full ].input,
 
duplicated[ rarity.full ].nonEmptyposition,
 
lineno,
 
nonEmptyposition
 
)
 
 
 
local category = 'transclusions with duplicate rarities'
 
 
 
reporter
 
:addError( message )
 
:addCategory( category )
 
else
 
duplicated[ rarity.full ] = {
 
input = r,
 
nonEmptyposition = nonEmptyposition,
 
}
 
 
 
table.insert( linked, UTIL.link( rarity.full, rarity.full ) )
 
end
 
 
else
 
else
local message = ( 'No such rarity for `%s`, at non-empty input line %d, at non-empty position %d.' )
+
local message = ('No such rarity for `%s`, at non-empty input line %d, at non-empty position %d.')
:format( r, lineno, nonEmptyposition )
+
:format( r, lineno, position )
  
local category = 'transclusions with invalid rarities'
+
reporter:addError( message )
 
 
reporter
 
:addError( message )
 
:addCategory( category )
 
 
end
 
end
else
 
local message = ( 'Empty rarity input, at non-empty input line %d, at position %d.' )
 
:format( lineno, position )
 
 
local category = 'transclusions with empty rarities'
 
 
reporter
 
:addError( message )
 
:addCategory( category )
 
 
end
 
end
 
end
 
end
  
return linked
+
return validated
 
end
 
end
  
local function getWikitextVarValue( frame, varName )
+
local function printRarities( rarities )
return UTIL.trim(
+
local linked = {}
frame:callParserFunction{
 
name = '#var',
 
args = {
 
varName
 
}
 
}
 
)
 
end
 
  
local function setWikitextVarValue( frame, varName, value )
+
for _, rarity in ipairs( rarities ) do
frame:callParserFunction{
+
table.insert( linked, UTIL.link( rarity ) )
name = '#vardefine',
+
end
args = {
 
varName, value or ''
 
}
 
}
 
  
return value
+
return table.concat( linked, '<br />' )
 
end
 
end
  
local function makeWikitextVarName( ... )
+
local function setSMWProps( cardNumber, setName, rarities, regionFull )
return table.concat( {
+
if not mw.smw then
'$$', ...,
+
reporter:addError( 'SMW is not available!' )
}, '-' )
 
end
 
  
local function getSetSmwInfo( frame, setName )
+
return
local info = {
 
[ KEY_DATE ] = {},
 
[ KEY_NAME ] = {},
 
}
 
 
 
if not setName then
 
return info
 
 
end
 
end
  
local isCachedVarName = makeWikitextVarName( setName, 'setSmwInfoIsCached' )
+
local setInfoProp = ('--- %s --- %s --- %s --- %s ---')
 +
:format(
 +
cardNumber,
 +
setName,
 +
table.concat( rarities, ',' ),
 +
regionFull
 +
)
  
local missingSetPageVarName = makeWikitextVarName( setName, 'pageIsMissing' )
+
local jsonRarities = {}
  
if getWikitextVarValue( frame, isCachedVarName ) then
+
for _, rarity in ipairs( rarities ) do
if getWikitextVarValue( frame, missingSetPageVarName ) then
+
table.insert( jsonRarities, '"' .. rarity .. '"' )
return info
 
end
 
 
 
for _, region in pairs( DATA_REGIONS ) do
 
local varName = makeWikitextVarName( setName, KEY_DATE, region.index )
 
 
 
info[ KEY_DATE ][ region.index ] = getWikitextVarValue( frame, varName )
 
end
 
 
 
for _, language in pairs( DATA_LANGUAGES ) do
 
local varName = makeWikitextVarName( setName, KEY_NAME, language.index )
 
 
 
info[ KEY_NAME ][ language.index ] = getWikitextVarValue( frame, varName )
 
end
 
 
 
return info
 
end
 
 
 
setWikitextVarValue( frame, isCachedVarName, 1 )
 
 
 
local smwResult = ( mw.smw.ask{ -- TODO: the props to query should be generated automatically from DATA region and language
 
table.concat{ '[[', setName, ']]' },
 
table.concat{ '?', CONTROL_PROP },
 
 
 
'?Worldwide English release date#ISO',
 
'?English release date#ISO',
 
'?North American English release date#ISO',
 
'?European English release date#ISO',
 
'?Oceanic English release date#ISO',
 
'?French release date#ISO',
 
'?French-Canadian release date#ISO',
 
'?German release date#ISO',
 
'?Italian release date#ISO',
 
'?Portuguese release date#ISO',
 
'?Spanish release date#ISO',
 
'?Latin American Spanish release date#ISO',
 
'?Japanese release date#ISO',
 
'?Japanese-Asian release date#ISO',
 
'?Asian-English release date#ISO',
 
'?Simplified Chinese release date#ISO',
 
'?Traditional Chinese release date#ISO',
 
'?Korean release date#ISO',
 
 
 
'?English name',
 
'?French name',
 
'?German name',
 
'?Italian name',
 
'?Portuguese name',
 
'?Spanish name',
 
'?Japanese name',
 
'?Simplified Chinese name',
 
'?Traditional Chinese name',
 
'?Korean name',
 
 
 
mainlabel = '-',
 
} or {} )[ 1 ] or {}
 
 
 
if not smwResult[ CONTROL_PROP ] then
 
setWikitextVarValue( frame, missingSetPageVarName, 1 )
 
 
 
local category = 'transclusions with set names without a page'
 
 
 
reporter:addCategory( category )
 
 
 
return info
 
 
end
 
end
  
for _, region in pairs( DATA_REGIONS ) do
+
local setInfoJSONProp = ('{ "number": "%s", "name": "%s", "rarity": [%s], "region": "%s" }')
local varName = makeWikitextVarName( setName, KEY_DATE, region.index )
+
:format(
 
+
cardNumber,
local dateForRegion = smwResult[ table.concat{ region.full, ' release date' } ]
+
setName,
 
+
table.concat( jsonRarities, ',' ),
info[ KEY_DATE ][ region.index ] = setWikitextVarValue( frame, varName, dateForRegion
+
regionFull
and dateForRegion[ 1 ]
 
or dateForRegion
 
 
)
 
)
end
 
  
for _, language in pairs( DATA_LANGUAGES ) do
+
local setRes = mw.smw.set{
local varName = makeWikitextVarName( setName, KEY_NAME, language.index )
+
['Set information'] = setInfoProp,
 +
['Set information (JSON)'] = setInfoJSONProp,
 +
}
  
local localizedName = smwResult[ table.concat{ language.full, ' name' } ]
+
if not setRes then
 
+
reporter:addError( "Failed to set SMW properties for set information!" )
info[ KEY_NAME ][ language.index ] = setWikitextVarValue( frame, varName, localizedName )
 
end
 
 
 
-- Special cases:
 
do
 
-- Fallback to `English release date`
 
local varName = makeWikitextVarName( setName, KEY_DATE, 'EN' )
 
 
 
info[ KEY_DATE ][ 'EN' ] = info[ KEY_DATE ][ 'EN' ] or setWikitextVarValue( frame, varName, smwResult[ 'English release date' ] )
 
 
end
 
end
 
return info
 
 
end
 
end
  
Line 275: Line 134:
 
end
 
end
  
local function checkIsSetNameSpecialCase( setName )
+
local function createDataRow( region, language, line, lineno )
return UTIL.getDab( setName ) == '25th Anniversary Edition'
 
end
 
 
 
local function computeSetNameCellContent( setName )
 
if not setName then
 
return nil
 
end
 
 
 
local isSetNameSpecialCase = checkIsSetNameSpecialCase( setName )
 
 
 
return isSetNameSpecialCase
 
and UTIL.link( setName, UTIL.italicNoDab( setName ) )
 
or UTIL.italicLink( setName )
 
end
 
 
 
 
 
local function createDataRow( frame, region, language, line, lineno )
 
 
local parts = mwText.split( line, '%s*;%s*' )
 
local parts = mwText.split( line, '%s*;%s*' )
  
Line 298: Line 140:
 
local setName = UTIL.trim( parts[ 2 ] )
 
local setName = UTIL.trim( parts[ 2 ] )
 
local rarities = UTIL.trim( parts[ 3 ] )
 
local rarities = UTIL.trim( parts[ 3 ] )
and linkRarities(
+
and validateRarities(
 
mwText.split( parts[ 3 ], '%s*,%s*' ),
 
mwText.split( parts[ 3 ], '%s*,%s*' ),
 
lineno
 
lineno
 
)
 
)
 +
or {}
  
 
if not setName then
 
if not setName then
local message = ( 'No set name provided at non-empty input line %d.' )
+
local message = ('No set name given at non-empty input line %d.')
 
:format( lineno )
 
:format( lineno )
  
local category = 'transclusions with missing set name'
+
reporter:addWarning( message )
 
 
reporter
 
:addWarning( message )
 
:addCategory( category )
 
end
 
 
 
if not rarities then
 
local message = ( 'No rarities provided at non-empty input line %d.' )
 
:format( lineno )
 
 
 
local category = 'transclusions with missing rarities'
 
 
 
reporter
 
-- :addWarning( message )
 
:addCategory( category )
 
 
end
 
end
 
 
local setSmwInfo = getSetSmwInfo( frame, setName )
 
 
local releaseDate = setSmwInfo[ KEY_DATE ][ region.index ]
 
 
if not releaseDate then
 
local category = 'transclusions with missing release dates'
 
 
reporter:addCategory( category )
 
end
 
 
local setNameCellContent = computeSetNameCellContent( setName )
 
  
 
local tr = mwHtmlCreate( 'tr' )
 
local tr = mwHtmlCreate( 'tr' )
:node( createCell( 'release', releaseDate ) )
+
:node( createCell( 'release', setName and DATA.getReleaseDate( setName, region ) ) )
 
:node( createCell( 'number', cardNumber and formatCardNumber( cardNumber ) ) )
 
:node( createCell( 'number', cardNumber and formatCardNumber( cardNumber ) ) )
:node( createCell( 'set', setNameCellContent ) )
+
:node( createCell( 'set', setName and UTIL.italicLink( setName ) ) )
  
 
if language.full ~= LANGUAGE_ENGLISH.full then
 
if language.full ~= LANGUAGE_ENGLISH.full then
Line 347: Line 162:
 
createCell(
 
createCell(
 
'set-localized',
 
'set-localized',
setSmwInfo[ KEY_NAME ][ language.index ]
+
DATA.getName( setName, language )
 
)
 
)
 
)
 
)
 
end
 
end
  
tr:node( createCell( 'rarity', rarities and table.concat( rarities, '<br />' ) ) )
+
tr:node( createCell( 'rarity', printRarities( rarities ) ) )
 +
 
 +
setSMWProps( cardNumber or '', setName or '', rarities, region.full )
  
 
return tostring( tr )
 
return tostring( tr )
end
 
 
function printOtherCategories( categories )
 
return mw.title.getCurrentTitle().namespace == 0
 
and table.concat( categories )
 
or ''
 
 
end
 
end
  
  
local function main( frame, regionInput, setsInput )
+
local function main( regionInput, setsInput )
 
reporter = Reporter( 'Card table sets' )
 
reporter = Reporter( 'Card table sets' )
  
Line 370: Line 181:
  
 
local language = DATA.getLanguage( regionInput )
 
local language = DATA.getLanguage( regionInput )
 
local otherCategories = {}
 
  
 
local setsTable = mwHtmlCreate( 'table' )
 
local setsTable = mwHtmlCreate( 'table' )
:attr( 'id', 'cts--' .. region.index )
 
 
:addClass( 'wikitable' )
 
:addClass( 'wikitable' )
 
:addClass( 'sortable' )
 
:addClass( 'sortable' )
Line 388: Line 196:
 
lineno = lineno + 1
 
lineno = lineno + 1
  
setsTable:node( createDataRow( frame, region, language, line, lineno ) )
+
setsTable:node( createDataRow( region, language, line, lineno ) )
 
end
 
end
end
 
 
if lineno == 1 then
 
table.insert( otherCategories, ( '[[Category:%s cards that have not been reprinted]]' ):format( region.full ) )
 
 
end
 
end
 
else
 
else
local message = 'No input provided for the sets.'
+
local message = 'No input given for the sets.'
  
local category = 'transclusions with no input (((1)))'
+
local category = '((Card table sets)) transclusions with no input (((1)))'
  
 
reporter
 
reporter
Line 407: Line 211:
 
return StringBuffer()
 
return StringBuffer()
 
:add( reporter:dump() )
 
:add( reporter:dump() )
:add( printOtherCategories( otherCategories ) )
 
 
:add( tostring( setsTable ) )
 
:add( tostring( setsTable ) )
 
:toString()
 
:toString()
Line 416: Line 219:
 
local arguments = frame:getParent().args
 
local arguments = frame:getParent().args
  
return main( frame, arguments[ 'region' ], arguments[ 1 ] )
+
return main( arguments[ 'region' ], arguments[ 1 ] )
 
end
 
end
 
}, {
 
}, {
__call = function( t, rg, list )
+
__call = function( t, ... )
local testRg = 'EN'
+
return main( ... )
 
 
local testList = [[
 
TLM-KR012; The Lost Millennium; Super Rare, Ultimate Rare
 
MVP1-ENSV4; Yu-Gi-Oh! The Dark Side of Dimensions Movie Pack Secret Edition; Ultra Rare
 
MVP1-ENS55; Yu-Gi-Oh! The Dark Side of Dimensions Movie Pack Secret Edition; Secret Rare
 
 
 
SRL-DE082; Spell Ruler (25th Anniversary Edition); Common
 
SDMA-EN001; Structure Deck: Marik (TCG); Common
 
 
 
MVP1-ENS55; ; Secret Rare
 
MVP1-ENS55; PAGE THAT DOESN'T EXIST; Secret Rare
 
 
 
MVP1-ENS55; LOB; Invalid Rare
 
 
 
MVP1-ENS55; LOB; Rare, R, r
 
 
 
MVP1-ENS55; LOB;
 
; LOB; SR, , R
 
 
 
]]
 
return main( mw.getCurrentFrame(), rg or testRg, list or testList )
 
 
end,
 
end,
 
} )
 
} )
 
-- </pre>
 
-- </pre>