Editing Module:Limitation status list
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | |||
− | |||
-- Shell object for the list itself | -- Shell object for the list itself | ||
local List = { | local List = { | ||
name = nil, | name = nil, | ||
medium = nil, | medium = nil, | ||
− | |||
locality = nil, | locality = nil, | ||
startDate = nil, | startDate = nil, | ||
− | |||
prev = nil, | prev = nil, | ||
next = nil, | next = nil, | ||
Line 33: | Line 29: | ||
cardType = nil, | cardType = nil, | ||
status = nil, | status = nil, | ||
− | |||
− | |||
− | |||
prevStatus = nil, | prevStatus = nil, | ||
prevStatusNote = nil | prevStatusNote = nil | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 74: | Line 50: | ||
l:setData(args or {}) | l:setData(args or {}) | ||
− | |||
− | |||
return l | return l | ||
Line 85: | Line 59: | ||
self.name = args.name or mw.title.getCurrentTitle().text | self.name = args.name or mw.title.getCurrentTitle().text | ||
self.medium = args.medium | self.medium = args.medium | ||
− | |||
self.locality = args.locality | self.locality = args.locality | ||
self.startDate = args.start_date | self.startDate = args.start_date | ||
− | |||
self.prev = args.prev | self.prev = args.prev | ||
self.next = args.next | self.next = args.next | ||
Line 97: | Line 69: | ||
self:addItems('Limited', args.limited) | self:addItems('Limited', args.limited) | ||
self:addItems('Semi-Limited', args.semi_limited) | self:addItems('Semi-Limited', args.semi_limited) | ||
− | |||
− | |||
− | |||
self:addItems('Unlimited', args.no_longer_on_list) | self:addItems('Unlimited', args.no_longer_on_list) | ||
Line 112: | Line 81: | ||
self.locality == 'Korean' | self.locality == 'Korean' | ||
) then | ) then | ||
− | self.localColumnHeading = self.locality | + | self.localColumnHeading = self.locality |
self.localColumnProperty = self.locality .. ' name' | self.localColumnProperty = self.locality .. ' name' | ||
− | |||
− | |||
− | + | elseif self.medium == 'OCG' or self.medium == 'Yu-Gi-Oh! Official Card Game' then | |
− | + | self.localColumnHeading = 'Japanese' | |
+ | self.localColumnProperty = 'Japanese name' | ||
− | + | else | |
− | self.localColumnHeading = | + | self.localColumnHeading = nil |
− | self.localColumnProperty = | + | self.localColumnProperty = nil |
− | |||
end | end | ||
− | |||
− | |||
− | |||
end | end | ||
Line 147: | Line 111: | ||
-- Extract data from content after the `//` | -- Extract data from content after the `//` | ||
− | |||
− | |||
local prevStatus = options and options:match('prev::([^;]*)') | local prevStatus = options and options:match('prev::([^;]*)') | ||
local prevStatusNote = options and options:match('prev%-note::([^;]*)') | local prevStatusNote = options and options:match('prev%-note::([^;]*)') | ||
Line 156: | Line 118: | ||
listItem.status = status | listItem.status = status | ||
− | |||
− | |||
listItem.prevStatus = prevStatus | listItem.prevStatus = prevStatus | ||
listItem.prevStatusNote = prevStatusNote | listItem.prevStatusNote = prevStatusNote | ||
Line 169: | Line 129: | ||
local cardData = self:lookupCardData(itemText) | local cardData = self:lookupCardData(itemText) | ||
− | + | if (not cardData) then | |
− | + | table.insert(self.errors, 'Failed to look up details for card: "' .. itemText .. '"') | |
+ | end | ||
+ | |||
listItem.card = itemText | listItem.card = itemText | ||
− | |||
− | |||
listItem.cardName = cardData and cardData.name or itemText | listItem.cardName = cardData and cardData.name or itemText | ||
listItem.localCardName = cardData and cardData.localName or '' | listItem.localCardName = cardData and cardData.localName or '' | ||
Line 187: | Line 147: | ||
function List:setSmwData() | function List:setSmwData() | ||
mw.smw.set({ | mw.smw.set({ | ||
− | ['Effective date'] = self.startDate | + | ['Effective date'] = self.startDate, |
− | |||
− | |||
['Medium'] = self.medium, | ['Medium'] = self.medium, | ||
['Release'] = self.medium, | ['Release'] = self.medium, | ||
− | |||
['Locality'] = self.locality, | ['Locality'] = self.locality, | ||
['Page type'] = 'Status list' | ['Page type'] = 'Status list' | ||
Line 213: | Line 170: | ||
local queryParams = { | local queryParams = { | ||
'[[' .. pageName .. ']]', | '[[' .. pageName .. ']]', | ||
− | |||
'?English name = name', | '?English name = name', | ||
− | '?Card type# = cardType' | + | '?Card type# = cardType', |
} | } | ||
− | |||
− | |||
if (self.localColumnProperty) then | if (self.localColumnProperty) then | ||
table.insert(queryParams, '?' .. self.localColumnProperty .. ' = localName') | table.insert(queryParams, '?' .. self.localColumnProperty .. ' = localName') | ||
Line 227: | Line 181: | ||
return cardData and cardData[1] or nil | return cardData and cardData[1] or nil | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 289: | Line 203: | ||
-- @return string | -- @return string | ||
function List:render() | function List:render() | ||
− | |||
− | |||
local output = '' | local output = '' | ||
output = output .. self:renderErrors() | output = output .. self:renderErrors() | ||
Line 297: | Line 209: | ||
output = output .. self:renderStatusList('Limited') | output = output .. self:renderStatusList('Limited') | ||
output = output .. self:renderStatusList('Semi-Limited') | output = output .. self:renderStatusList('Semi-Limited') | ||
− | |||
− | |||
− | |||
output = output .. self:renderStatusList('Unlimited', 'No longer on list') | output = output .. self:renderStatusList('Unlimited', 'No longer on list') | ||
output = output .. self:renderCategories() | output = output .. self:renderCategories() | ||
return output | return output | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 345: | Line 234: | ||
-- @return string | -- @return string | ||
function List:renderNavigation() | function List:renderNavigation() | ||
− | -- | + | -- If prev and next are both empty, don't show a navigation menu |
− | + | if (not isFilled(self.prev) and not isFilled(self.next)) then | |
+ | return '' | ||
+ | end | ||
− | local currText = | + | local currText = self:pageNameToShortName(self.name) |
local prevText = isFilled(self.prev) and ('← [[' .. self.prev .. '|' .. self:pageNameToShortName(self.prev) .. ']]') or ' ' | local prevText = isFilled(self.prev) and ('← [[' .. self.prev .. '|' .. self:pageNameToShortName(self.prev) .. ']]') or ' ' | ||
local nextText = isFilled(self.next) and ('[[' .. self.next .. '|' .. self:pageNameToShortName(self.next) .. ']] →') or ' ' | local nextText = isFilled(self.next) and ('[[' .. self.next .. '|' .. self:pageNameToShortName(self.next) .. ']] →') or ' ' | ||
Line 357: | Line 248: | ||
output = output .. '<div style="flex: 1; text-align: right;">' .. nextText .. '</div>' | output = output .. '<div style="flex: 1; text-align: right;">' .. nextText .. '</div>' | ||
output = output .. '</div>' | output = output .. '</div>' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
return output | return output | ||
Line 368: | Line 253: | ||
-- Convert a page name to a short name | -- Convert a page name to a short name | ||
− | -- e.g. "March 2020 Lists (Duel Links)" -> "March 2020" | + | -- e.g. "March 2020 Lists (Duel Links)" -> "March 2020 Lists" |
− | -- e.g. "OCG April 2014 Lists" -> "April 2014" | + | -- e.g. "OCG April 2014 Lists" -> "April 2014 Lists" |
-- @param pageName string | -- @param pageName string | ||
-- @return string | -- @return string | ||
Line 377: | Line 262: | ||
-- Remove mention of the medium | -- Remove mention of the medium | ||
− | shortName = | + | shortName = shortName:gsub(self.medium, '') |
− | |||
− | |||
− | |||
-- Clear any leading/trailing spaces | -- Clear any leading/trailing spaces | ||
Line 390: | Line 272: | ||
if (isFilled(mw.title.getCurrentTitle().nsText)) then return '' end | if (isFilled(mw.title.getCurrentTitle().nsText)) then return '' end | ||
− | local output = '[[Category:' .. (self. | + | local output = '[[Category:' .. (self.region or '') .. ' ' .. (self.medium or '') .. ' Forbidden & Limited Lists]]' |
if (#self.errors > 0) then | if (#self.errors > 0) then | ||
Line 414: | Line 296: | ||
local headingRow = list:tag('tr') | local headingRow = list:tag('tr') | ||
− | headingRow:tag('th | + | headingRow:tag('th'):wikitext('Card') |
if self.localColumnHeading then | if self.localColumnHeading then | ||
− | headingRow:tag('th | + | headingRow:tag('th'):wikitext(self.localColumnHeading) |
end | end | ||
− | headingRow:tag('th | + | headingRow:tag('th'):wikitext('Card type') |
− | headingRow:tag('th | + | headingRow:tag('th'):wikitext('Status') |
− | headingRow:tag('th | + | headingRow:tag('th'):wikitext('Changes') |
for _, item in pairs(items) do | for _, item in pairs(items) do | ||
local cardTypeLink = item.cardType | local cardTypeLink = item.cardType | ||
− | and ('[[' .. item.cardType .. '|' .. | + | and ('[[' .. item.cardType .. '|' .. string.gsub(item.cardType, ' Card', '') .. ']]') |
or '' | or '' | ||
-- Form the CSS class that styles the cells in the status column | -- Form the CSS class that styles the cells in the status column | ||
− | local statusClass = 'status-' .. (item.status | + | local statusClass = 'status-' .. (item.status):lower() |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local row = list:tag('tr') | local row = list:tag('tr') | ||
Line 448: | Line 318: | ||
end | end | ||
row:tag('td'):wikitext(cardTypeLink) | row:tag('td'):wikitext(cardTypeLink) | ||
− | row:tag('td'):addClass(statusClass):wikitext( | + | row:tag('td'):addClass(statusClass):wikitext('[[' .. item.status .. ']]') |
row:tag('td'):wikitext( | row:tag('td'):wikitext( | ||
(item.prevStatus and 'was [[' .. item.prevStatus .. ']]' or '') .. | (item.prevStatus and 'was [[' .. item.prevStatus .. ']]' or '') .. | ||
Line 455: | Line 325: | ||
end | end | ||
− | + | return tostring(heading) .. tostring(list) | |
− | |||
− | return tostring(heading) | ||
end | end | ||
Line 466: | Line 334: | ||
function isFilled(value) | function isFilled(value) | ||
return value ~= nil and value ~= '' | return value ~= nil and value ~= '' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
return List | return List |