Changes

Jump to: navigation, search

Module:Limitation status list

5,503 bytes added, 1 month ago
Changing order to match the F/L list header in each article
local inArray = require('Module:TableTools').inArray
 
-- Shell object for the list itself
local List = {
locality = nil,
startDate = nil,
endDate = nil,
prev = nil,
next = nil,
prevStatus = nil,
prevStatusNote = nil
}
 
local statusDescriptions = {
['Forbidden'] = 'These cards cannot be used in the [[Main Deck]], [[Extra Deck]], or [[Side Deck]].',
['Limited'] = 'A maximum of one copy of each of these cards can be included in the [[Main Deck]], [[Extra Deck]], and [[Side Deck]] combined.',
['Semi-Limited'] = 'A maximum of two copies of each of these cards can be included in the [[Main Deck]], [[Extra Deck]], and [[Side Deck]] combined.',
['Limited 1'] = 'A maximum of one out of all of the following cards can be included in the [[Main Deck]], [[Extra Deck]], [[Side Deck]], and choice of [[Skill Card]] combined.',
['Limited 2'] = 'A maximum of two out of all of the following cards can be included in the [[Main Deck]], [[Extra Deck]], [[Side Deck]], and choice of [[Skill Card]] combined. This may be two copies of the same card or one copy one card and one copy of another.',
['Limited 3'] = 'A maximum of three out of all of the following cards can be included in the [[Main Deck]], [[Extra Deck]], [[Side Deck]], and choice of [[Skill Card]] combined. This can include multiple copies of the same card, as long as the combined total from this list is three or fewer.',
['Unlimited'] = 'Limitations have been removed from the following cards since the last list.'
}
 
-- Mediums that have only been released in Japanese
-- @todo: Come up with solution that doesn't involve hardcoding games in the module
local jaOnlyMediums = {
'Yu-Gi-Oh! Duel Monsters (video game)',
'Yu-Gi-Oh! Rush Duel',
}
l:setData(args or {})
 
l:validateAfterParsing()
return l
self.locality = args.locality
self.startDate = args.start_date
self.endDate = args.end_date
self.prev = args.prev
self.next = args.next
self:addItems('Limited', args.limited)
self:addItems('Semi-Limited', args.semi_limited)
self:addItems('Limited 1', args.limited_1)
self:addItems('Limited 2', args.limited_2)
self:addItems('Limited 3', args.limited_3)
self:addItems('Unlimited', args.no_longer_on_list)
self.locality == 'Korean'
) then
self.localColumnHeading = self.locality.. ' name'
self.localColumnProperty = self.locality .. ' name'
return
end
local isOcg = self.medium == 'OCG' or self.medium == 'Yu-Gi-Oh! Official Card Game';
local isJaOnly = inArray(jaOnlyMediums, self.medium) local isOcg = self.medium == 'OCG' or self.medium == 'Yu-Gi-Oh! Official Card Game'  if (isJaOnly or (isOcg and self.locality ~= 'Asian-English' )) then self.localColumnHeading = 'Japanesename'
self.localColumnProperty = 'Japanese name'
return
local cardData = self:lookupCardData(itemText)
if (not listItem.cardFound = cardData) then table.insert(self.errors, 'Failed to look up details for card: "' .. itemText .. '"')and true or false end-- The original name that was supplied
listItem.card = itemText
-- The name that SMW found
listItem.pageName = cardData and cardData.pageName or nil
listItem.cardName = cardData and cardData.name or itemText
listItem.localCardName = cardData and cardData.localName or ''
function List:setSmwData()
mw.smw.set({
['Effective date'] = self.startDate, -- deprecated ['Start date'] = self.startDate, ['End date'] = self.endDate,
['Medium'] = self.medium,
['Release'] = self.medium,
['Format'] = self.formator self.locality or self.medium,
['Locality'] = self.locality,
['Page type'] = 'Status list'
local queryParams = {
'[[' .. pageName .. ']]',
'? = pageName#',
'?English name = name',
'?Card type# = cardType',
}
-- If there is a column for another language
-- also query for the card's name in that language
if (self.localColumnProperty) then
table.insert(queryParams, '?' .. self.localColumnProperty .. ' = localName')
return cardData and cardData[1] or nil
end
 
-- Validate the data after it has been parsed
-- Checks for errors and adds them to the `errors` attribute
function List:validateAfterParsing()
for i, item in pairs(self.items) do
-- If not a card, go to the next iteration of the loop.
-- (Any validation after this line is only applicable to cards.)
if (not item.card) then break end
 
-- Check if card data was found for the looked up name.
if (item.cardFound == false) then
table.insert(self.errors, 'Failed to look up details for card: <code>' .. item.card .. '</code>.')
 
-- If the card wasn't found, move on to the next list item.
-- No need to perform the next few checks.
break
end
 
-- Check if a card is listed more than once
for i2, item2 in pairs(self.items) do
-- `i < i2`: Only look at records that come after this one,
-- so the same error isn't reported again for the duplicate(s)
if (i < i2 and item.pageName == item2.pageName) then
table.insert(self.errors, '<code>' .. item.pageName .. '</code> is listed more than once.')
-- Duplicate found, so no need to keep looking.
break
end
end
 
-- Check if the supplied name doesn't match the found page name
if (item.card ~= item.pageName) then
table.insert(self.errors, 'The supplied page name, <code>' .. item.card .. '</code>, does not match the looked-up page name, <code>' .. item.pageName .. '</code>.')
end
 
if (item.status == 'Unlimited' and not item.prevStatus) then
table.insert(self.errors, '<code>' .. item.card .. '</code> has been removed from the list, but does not specify its previous status.')
end
end
end
output = output .. self:renderStatusList('Limited')
output = output .. self:renderStatusList('Semi-Limited')
output = output .. self:renderStatusList('Limited 1')
output = output .. self:renderStatusList('Limited 2')
output = output .. self:renderStatusList('Limited 3')
output = output .. self:renderStatusList('Unlimited', 'No longer on list')
output = output .. self:renderCategories()
-- Format the page name, if necessary
function List:renderDisplayTitle()
local italicTitle = nil local pageName = mw.title.getCurrentTitle().text -- Medium without the word "Yu-Gi-Oh!" local mediumShort = mw.text.trim(replacePlain(self.medium, 'Yu-Gi-Oh!', ''), '%s')
-- If the medium or a shortened version of it is not mentioned in the page name, leave italicize it alone. if not string.pageName:find(pageName, self.medium) then return end  -- Italicize the medium in the page name local italicTitle = replacePlain(pageName:gsub(, self.medium, '<i>' .. self.medium .. '</i>') elseif pageName:find(mediumShort) then italicTitle = replacePlain(pageName, mediumShort, '<i>' .. mediumShort .. '</i>') end
-- Use the italicized name as the page name
if italicTitle then mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', italicTitle) end
end
-- @return string
function List:renderNavigation()
-- Strip disambiguation text from the medium's page name local mediumName = mw.text.split(self.medium, ' %(')[1]  local currText = (self.locality or '') .. '<i>' ..self.medium mediumName .. '</i> ' .. (self.format or '') .. 'Forbidden & Limited Lists'
local prevText = isFilled(self.prev) and ('← [[' .. self.prev .. '|' .. self:pageNameToShortName(self.prev) .. ']]') or '&nbsp;'
local nextText = isFilled(self.next) and ('[[' .. self.next .. '|' .. self:pageNameToShortName(self.next) .. ']] →') or '&nbsp;'
output = output .. '<div style="flex: 1; text-align: right;">' .. nextText .. '</div>'
output = output .. '</div>'
 
if isFilled(self.startDate) and isFilled(self.endDate) then
output = output .. '<p style="font-size: .9em; text-align: center;"><b>Effective</b>: '
output = output .. self.startDate .. ' – ' .. self.endDate
output = output .. '</p>'
end
return output
-- Convert a page name to a short name
-- e.g. "March 2020 Lists (Duel Links)" -> "March 2020 Lists"-- e.g. "OCG April 2014 Lists" -> "April 2014 Lists"
-- @param pageName string
-- @return string
-- Remove mention of the medium
shortName = replacePlain(shortName:gsub(, self.medium, '')  -- Remove the word 'Lists' shortName = replacePlain(shortName, ' Lists', '')
-- Clear any leading/trailing spaces
if (isFilled(mw.title.getCurrentTitle().nsText)) then return '' end
local output = '[[Category:' .. (self.locality or '') .. ' ' .. (self.medium or '') .. ' ' .. (self.format or '') .. ' Forbidden & Limited Lists]]'
if (#self.errors > 0) then
local headingRow = list:tag('tr')
headingRow:tag('th'):attr('scope', 'col'):wikitext('Card')
if self.localColumnHeading then
headingRow:tag('th'):attr('scope', 'col'):wikitext(self.localColumnHeading)
end
headingRow:tag('th'):attr('scope', 'col'):wikitext('Card type') headingRow:tag('th'):attr('scope', 'col'):wikitext('Status') headingRow:tag('th'):attr('scope', 'col'):wikitext('Changes')
for _, item in pairs(items) do
local cardTypeLink = item.cardType
and ('[[' .. item.cardType .. '|' .. string.gsubreplacePlain(item.cardType, ' Card', '') .. ']]')
or ''
-- Form the CSS class that styles the cells in the status column
local statusClass = 'status-' .. (item.status:gsub(' ', '-')):lower()
local statusText = '[[' .. item.status .. ']]'
end
local description = statusDescriptions[status] or ''  return tostring(heading) .. description .. tostring(list)
end
function isFilled(value)
return value ~= nil and value ~= ''
end
 
-- Replace all occurances of a string with another
-- Unlike `string.gsub`, do not treat the searched term as a pattern.
--
-- @param source str - The text to perform the replacement in
-- @param search str - The text to search for
-- @param replace str - The text to replace the searched text with
-- @return str
function replacePlain(source, search, replace)
-- Escape any patterns in the search term
search = mw.ustring.gsub(search, '([%(%)%.%%%+%-%*%?%[%^%$%]])', '%%%1')
 
-- Replace all instances of the search term, with the replace term
return mw.ustring.gsub(source, search, replace)
end
return List

Navigation menu