Yu-Gi-Oh! Wiki
Yu-Gi-Oh! Wiki
(Revert.)
Tag: sourceedit
m (Reverted edits by IgorThunderMaster (talk) to last version by Becasita)
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
--[[
+
-- <pre>
Var list:
+
-- Module for {{Set list}},
  +
-- to be used like {{#invoke:Set list|main}}.
(so I can keep track of what to use)
 
-------
+
-- @@@ for ideas.
  +
-------------------
# Data:
 
  +
local SetList = {};
-> rg_list // Region code list;
 
-> region_list // Region list;
 
-> ln_list // Language code list;
 
-> language_list // Language list;
 
-> rarity_list // Rarity list;
 
----------
 
# General:
 
-> PAGENAME // {{PAGENAME}};
 
-> NAMESPACE // {{NAMESPACE}};
 
-> _rg // Region code;
 
-> _region // Region name;
 
-> _ln // Language code;
 
-> _language // Language name;
 
------
 
# Set:
 
-> nameSet_parts // Aux var containing the parts for the set name by «(»;
 
-> _nameSet // Set name;
 
-> _nameSet_localized // Localized set name;
 
-> _qty // Quantity value ({{{qty}}});
 
---------
 
# Design:
 
-> header // Page header (HTML);
 
-> category // Category;
 
--------------
 
# List (main):
 
-> cardList_input // List of cards passed;
 
-> cardList_array // Array of the above (by «\n»).
 
-> extra_column // If there's an extra column ({{{col}}});
 
--------
 
# Table:
 
-> _header // {{{header}}};
 
-> _rarity // {{{rarity}}};
 
-> out_t // Table to dsiplay (HTML);
 
-----------------
 
# List (entries):
 
## Section:
 
-> _headerSection // For sections («!:»), the header info («header::»);
 
-> _raritySection // For sections («!:»), the rarity info («rarity::»);
 
-> _qtySection // For sections («!:»), the quantity info («qty::»);
 
## Standard values (passed and parsed directly: <number>; <name>; <rarity>; <qty>;):
 
-> _nameCard // Card name (<name>);
 
-> nameCard_strip // Aux var; strip «#» from the above;
 
-> nameCard_noDab // Aux var; removes dab text from «_nameCard»;
 
-> _nameCard_localized // Localized card name;
 
-> _numberCard // Card number (<number>);
 
-> _rarityCard // Card rarity (<rarity>) OR more general rarity values;
 
-> _typeCard // Card type (or category);
 
-> _qtyCard // Card quantity (<qty>) OR more general qty values;
 
## Alternate values (literal, separated by «//»):
 
-> _nameCard_alt // «name::»;
 
-> _nameCard_localized_alt // «name-local::»;
 
-> _numberCard_alt // «number::»;
 
-> _rarityCard_alt // «rarity::»;
 
-> _typeCard_alt // «category::»;
 
-> _description // «description::»;
 
-> _extra // «<lowercased_column_name>::», where the column name is «extra_column»;
 
## Processing:
 
-> cardList_array_parts // Array of «cardList_array» divided by «//»;
 
-> cardList_array_std // Array of [1] of the above, divided by «;»;
 
-> rarity_array // Array of the card rarities;
 
## Display vars:
 
-> display_nameCard
 
-> display_nameCard_localized
 
-> display_numberCard
 
-> display_rarityCard
 
-> display_typeCard
 
-> display_qtyCard
 
--------
 
# Flags:
 
-> notEnglish // Boolean;
 
-> italics // Italicized name;
 
-> qty // Boolean: exists {{{qty}}};
 
-> noAbbr // Boolean: if {{{abbr}}} is set off;
 
->
 
-----------
 
# Counters:
 
-> colspan // Number of columns (colspan);
 
]]
 
----------
 
-- Start:
 
----------
 
local myInput = {};
 
-- Load outside data and modules:
 
local data = mw.loadData( 'Module:Set list/data' );
 
local LN = require( 'Module:Set list/name' ); -- For Localized Name.
 
   
  +
-----------------
function myInput.list( frame )
 
-- Get arguments:
+
-- Load modules:
  +
-----------------
-- { '1' or 'list', 'region', 'set', 'qty', 'abbr', 'col', 'header', 'rarity' }
 
  +
local getArgs = require( 'Dev:Arguments' ).getArgs;
local parameters = frame.args;
 
  +
local getCardType = require( 'Module:Card type' ).main;
 
  +
-- Load outside data:
 
  +
--------------
local rg_list = data.rg_list;
 
  +
-- Load data:
local region_list = data.region_list;
 
  +
--------------
local ln_list = data.ln_list;
 
  +
local _D = {};
local language_list = data.language_list;
 
  +
local data = mw.loadData( 'Module:Set list/data' );
local rarity_list = data.rarity_list;
 
  +
local rg_list = data.rg_list; -- Region code table.
-- {{PAGENAME}}
 
  +
local region_list = data.region_list; -- Region name table.
local PAGENAME = mw.title.getCurrentTitle().text;
 
  +
local ln_list = data.ln_list; -- Language code table.
-- {{NAMESPACE}}
 
  +
local language_list = data.language_list; -- Language name table.
local NAMESPACE = mw.title.getCurrentTitle().nsText;
 
  +
local rarity_list = data.rarity_list; -- Rarity name table.
 
  +
local abbr_list = data.abbr_list; -- Abbr disable codes table.
----------------------------------------
 
  +
-- Define vars related to the set info:
 
----------------------------------------
+
----------------------
  +
-- Utility functions:
 
  +
----------------------
-- Region and language:
 
  +
-- mw functions:
local _rg = parameters['region'] and parameters['region']:lower();
 
local _region = '';
+
local split = mw.text.split;
  +
local HTML = mw.html.create;
if _rg == nil or _rg == '' then
 
  +
--_region = string.match( PAGENAME, '%-(%a*)' ):lower(); -- a value is needed always!
 
  +
-- Trim function:
return '<strong class="error">Error: A «region» is always needed!</strong>';
 
  +
-- Trims white space from front and tail of string.
  +
-- If the input is only white space, returns nil.
  +
local function _trim( s )
  +
if s and not s:match( '^%s*$' ) then
  +
return mw.text.trim( s ); -- If not nil nor empty.
  +
end
  +
end
  +
  +
-- Link function:
  +
-- If a string is passed, links it;
  +
-- uses a label, when given.
  +
-- If a table is passed, links every instance of it;
  +
-- uses a table of labels, respectively for each entry, when given.
  +
local function _link( v, ... )
  +
local labels = type( ... or nil ) == 'table' and ... or { ... }; -- Make sure it's a table.
  +
local function __link( v, label )
  +
return ('[[%s|%s]]'):format( v:gsub( '#', '' ), _trim( label ) or split( v, '%s*%(' )[1] );
  +
end
  +
if type( v ) == 'string' then
  +
return __link( v, labels[1] );
  +
elseif type( v ) == 'table' then
  +
local t = {};
  +
for key, value in ipairs( v ) do
  +
table.insert( t, __link( value, labels[key] ));
  +
end
  +
return t;
 
else
 
else
  +
return v; -- @@@ error()
_region = region_list[_rg] or region_list['default'];
 
 
end
 
end
  +
end
local flag_notEnglish = true;
 
  +
local flag_italics = 'italic';
 
  +
-- Table count function:
local _ln = ln_list[_rg];
 
  +
-- Given a table, counts how many valuee it has.
local _language = language_list[_ln];
 
  +
local function _count( t ) -- @@@ error() for wrong type()
if _ln == 'en' then
 
flag_notEnglish = false;
+
local counter = 0;
  +
for key, value in pairs( t ) do
  +
counter = counter + 1;
 
end
 
end
  +
return counter;
if _ln == 'ja' or _ln == 'zh' or _ln == 'ko' then
 
  +
end
flag_italics = 'normal';
 
  +
  +
local function _error( message, default, category ) -- @@@ input list of categories.
  +
local err = HTML( 'div' ):css( 'padding-left', '1.6em' )
  +
:tag( 'strong' ):addClass( 'error' ):wikitext( ('Error: %s'):format( message ) ):done()
  +
:allDone();
  +
local cat = ('[[Category:%s]]'):format( category or '((Set list)) transclusion to be checked' );
  +
table.insert( _D.errors, table.concat( { tostring( err ), cat } ) );
  +
return default or '';
  +
end
  +
  +
-------------------------------
  +
-- Getter/generator functions:
  +
-------------------------------
  +
-- Info function:
  +
-- Handles region/language info and flags.
  +
local function getInfo()
  +
_D.rg = _D.args['region'] and _D.args['region']:lower() or _error( 'A «region» is always needed!', 'en' );
  +
_D.region = region_list[_D.rg];
  +
_D.ln = ln_list[_D.rg];
  +
_D.language = language_list[_D.ln];
  +
-- Flags:
  +
_D.flags = {};
  +
_D.flags.qty = _D.args['qty'] and true;
  +
_D.flags.noAbbr = _D.args['abbr'] and abbr_list[_D.args['abbr']:lower()] and true;
  +
_D.flags.column = _D.args['col'] and true;
  +
_D.flags.notEnglish = _D.ln ~= 'en';
  +
_D.flags.italics = ((_D.ln == 'ja') or (_D.ln == 'zh') or (_D.ln == 'ko')) and 'normal' or 'italic';
  +
end
  +
  +
-- Local name function:
  +
-- Returns the localized name.
  +
local function getNameLocal( name )
  +
if not mw.smw then
  +
return _error( 'mw.smw module not found' );
 
end
 
end
  +
local _page = name:gsub( '#', '' );
  +
local _query = { ('[[%s]]'):format( _page ), ('?%s name='):format( _D.language ), limit = 1, mainlabel = '-' };
  +
local query = mw.smw.ask( _query );
  +
if not query or _count( query ) == 0 or _count( query[1] ) == 0 then
  +
return;
  +
end
  +
return query[1][1];
  +
end
   
-- Set name:
+
-- Name function:
  +
-- Returns two values:
local _nameSet = parameters['set'];
 
  +
-- The English name; the localized name.
if _nameSet == nil or _nameSet == '' then
 
  +
local function getSetName( name )
local nameSet_parts = mw.text.split( PAGENAME, ' %(' );
 
  +
local t = split( name, '%s*%(' );
if nameSet_parts[3] == nil or nameSet_parts[3] == '' then
 
  +
local _name = _D.args['set'] or _trim( t[3] ) and table.concat( t, ' (', 1, 2 ) or t[1];
_nameSet = nameSet_parts[1]; -- Set name doesn't contain dab text.
 
  +
local _nameLocal = _D.flags['notEnglish'] and getNameLocal( _name );
else
 
  +
return _name, _nameLocal;
_nameSet = nameSet_parts[1] ..' ('.. nameSet_parts[2]; -- Set name contains dab text.
 
  +
end
  +
  +
-- Quotes function:
  +
-- Wraps a name with quotes.
  +
local function wrapQuotes( name, std )
  +
if not _trim( name ) then
  +
return ''; -- Return empty string.
  +
end
  +
return (std or (_D.ln ~= 'ja' and _D.ln ~= 'zh')) and table.concat( { '"', name, '"' } )
  +
or table.concat( { '「', name, '」' } );
  +
end
  +
  +
-- Rarity function:
  +
-- Receives a string of rarities.
  +
local function getRarity( s )
  +
local t = s and split( s, ',' ) or {};
  +
local rarities = {};
  +
for _, rarity in ipairs( t ) do
  +
_rarity = _trim( rarity:lower():gsub( ' rare$', '' ) );
  +
if _rarity and rarity_list[_rarity] then
  +
table.insert( rarities, _link( rarity_list[_rarity] ) );
 
end
 
end
 
end
 
end
  +
return table.concat( rarities, '<br />' );
local _nameSet_localized = LN.localized_name( _nameSet, _language );
 
  +
end
  +
  +
-- Page header function:
  +
-- Builds page header (HTML).
  +
local function getHeader( setName, setNameLocal )
  +
local CSS = {
  +
{ -- First «span» tag (set name).
  +
['font-size'] = '120%',
  +
['font-weight'] = 'bold',
  +
['font-style'] = 'italic'
  +
},
  +
{ -- Second «span» tag (local set name).
  +
['font-weight'] ='bold',
  +
['font-style'] = _D.flags['italics']
  +
  +
}
  +
};
 
 
  +
local header = HTML( 'div' ):css( 'text-align', 'center' )
-- Set abbreviation:
 
  +
:tag( 'span' ):css( CSS[1] )
local _abbr = parameters['abbr'] and parameters['abbr']:lower();
 
  +
:wikitext( _link( setName, (setName:match( '%(2011%)' ) or setName:match( '%(series%)' )) and setName ) )
local flag_noAbbr = false;
 
  +
:done();
if _abbr == 'no' or _abbr == 'none' or _abbr == 'off' or _abbr == 'false' or _abbr == '0' then
 
  +
if _trim( setNameLocal ) then
flag_noAbbr = true;
 
  +
header:tag( 'br' ):done()
  +
:tag( 'span' ):css( CSS[2] )
  +
:wikitext( setNameLocal )
  +
:done();
 
end
 
end
  +
header:tag( 'br' ):done()
  +
:wikitext( _D.region )
  +
:allDone();
 
 
  +
return tostring( header );
-- Quantity (main):
 
  +
end
local _qty = parameters['qty']; -- $qty-value
 
  +
local flag_qty = false;
 
  +
-- Categories function:
if not(_qty == nil or _qty == '') then
 
  +
-- Generates categories.
flag_qty = true;
 
  +
local function getCategory( ns )
_qty = tonumber(_qty) or 1;
 
  +
-- @@@ Make it similar to _link.
  +
return ('[[Category:%s %s]]'):format( _D.region, ns );
  +
end
  +
  +
local function tracking( frameArgs )
  +
local _parameters = {
  +
1,
  +
['region'] = 'region',
  +
['set'] = 'set',
  +
['abbr'] = 'abbr',
  +
['rarity'] = 'rarity',
  +
['qty'] = 'qty',
  +
['col'] = 'col'
  +
}
  +
for key, value in pairs( frameArgs ) do
  +
if not( _parameters[key] ) or not( _trim( value ) ) then
  +
-- There are parameters not being used or used empty.
  +
return _error( 'Instance of unsupported or empty parameters!' , nil, '((Set list)) transclusion with parameters to be checked' )
  +
end
 
end
 
end
  +
return '';
  +
end
  +
  +
-----------------------
  +
-- Set list functions:
  +
-----------------------
  +
-- Header entry function:
  +
-- Builds the section header.
  +
-- Fetches section info.
  +
local function getSetListHeader( entry )
  +
local _header = entry:match('header::(.-);')
  +
or entry:match('header::(.+)' );
  +
local _sectionNoAbbr = entry:match( 'abbr::(.-);')
  +
or entry:match( 'abbr::(.+)' );
  +
local _sectionRarityList = entry:match('rarity::(.-);')
  +
or entry:match('rarity::(.+)' );
  +
local _sectionQty = entry:match( 'qty::(.-);')
  +
or entry:match( 'qty::(.+)' );
  +
local _sectionColumn = entry:match( 'col::(.-);')
  +
or entry:match( 'col::(.+)' );
  +
local sectionNoAbbr = _trim( _sectionNoAbbr ) and abbr_list[_trim( _sectionNoAbbr )] and true;
  +
  +
return _trim( _header ), sectionNoAbbr, _sectionRarityList, _sectionQty, _trim( _sectionColumn );
  +
end
  +
  +
-- Card entry function:
  +
-- Builds the card row.
  +
local function getSetListCard( entry, sectionNoAbbr, sectionRarityList, sectionQty, sectionColumn )
  +
-- Intialize vars:
  +
local _number, _name, _rarityList, _qty;
  +
local _nameAlt, _nameLocalAlt, _rarityAlt, _typeAlt, _description, _column;
  +
-- General values (from args or section):
  +
local noAbbr = sectionNoAbbr or _D.flags['noAbbr'];
  +
local rarityList = sectionRarityList or _D.args['rarity'];
  +
local qty = (sectionQty or _D.flags['qty']) and (tonumber( sectionQty or _D.args['qty'] ) or 1);
  +
local column = sectionColumn or _D.args['col'];
 
 
-----------------------
+
-- Local values:
-- Design page header:
+
-- # Split info:
  +
local valuesStandard = split( split( entry, '//' )[1] , ';');
-----------------------
 
  +
local valuesAlternate = split( entry, '//' )[2];
-- Header:
 
local header = mw.html.create( 'div' ):css('text-align', 'center')
 
:tag('span'):css{
 
['font-size'] = '120%',
 
['font-weight'] = 'bold',
 
['font-style'] = 'italic'
 
}
 
:wikitext('[[' .._nameSet.. ']]')
 
:done()
 
if flag_notEnglish and _nameSet_localized ~= '' and _nameSet_localized then
 
header:tag('br'):done()
 
:tag('span'):css{
 
['font-weight'] ='bold',
 
['font-style'] = flag_italics
 
}
 
:wikitext(_nameSet_localized)
 
:done()
 
end
 
header:tag('br'):done()
 
:wikitext(_region)
 
:allDone()
 
-- Category:
 
local category = string.format('[['..'Category:%s %s]]', _region, NAMESPACE)
 
 
 
  +
-- # Deal with standard values:
---------------------------
 
  +
if noAbbr then
-- Process the list array:
 
  +
_name = _trim( valuesStandard[1] );
---------------------------
 
  +
_rarityList = _trim( valuesStandard[2] );
-- General:
 
  +
_qty = _trim( valuesStandard[3] );
local cardList_input = parameters['list'] or parameters['1'] or parameters[1]; -- @INPUT
 
  +
else
local cardList_array = mw.text.split( cardList_input, '\n' );
 
local extra_column = parameters['col'];
+
_number = _trim( valuesStandard[1] );
  +
_name = _trim( valuesStandard[2] );
local counter_colspan = 4;
 
  +
_rarityList = _trim( valuesStandard[3] );
if flag_notEnglish then counter_colspan = 5 end;
 
  +
_qty = _trim( valuesStandard[4] );
if flag_qty then counter_colspan = counter_colspan + 1 end;
 
  +
end
if flag_noAbbr then counter_colspan = counter_colspan - 1 end;
 
if extra_column and extra_column ~= '' then counter_colspan = counter_colspan + 1 end;
 
 
 
-- Build table:
+
-- # Deal with alternate values:
  +
if valuesAlternate then
local _header = parameters['header'];
 
  +
_nameAlt = valuesAlternate:match( 'name::(.-);')
local _rarity = parameters['rarity'];
 
  +
or valuesAlternate:match( 'name::(.+)' );
local out_t = mw.html.create( 'table' )
 
  +
_nameLocalAlt = valuesAlternate:match('name%-local::(.-);')
:addClass('wikitable'):addClass('sortable'):addClass('card-list')
 
if _header and _header ~= '' then -- If {{{header}}}.
+
or valuesAlternate:match('name%-local::(.+)' );
out_t:tag('caption'):wikitext(_header):done()
+
_rarityAlt = valuesAlternate:match( 'rarity::(.-);')
  +
or valuesAlternate:match( 'rarity::(.+)' );
end
 
  +
_typeAlt = valuesAlternate:match( 'category::(.-);')
out_t:tag('tr')
 
if not(flag_noAbbr) then
+
or valuesAlternate:match( 'category::(.+)' );
  +
_description = valuesAlternate:match('description::(.-);')
out_t:tag('th'):attr('scope','col'):wikitext('Card number'):done()
 
  +
or valuesAlternate:match('description::(.+)' );
end
 
if flag_notEnglish then
+
_column = column and
out_t:tag('th'):attr('scope','col'):wikitext('English name'):done()
+
(valuesAlternate:match(table.concat( { column:lower(), '::(.-);' } ))
:tag('th'):attr('scope','col'):wikitext(_language..' name'):done()
+
or valuesAlternate:match(table.concat( { column:lower(), '::(.+)' } )));
else
+
end
out_t:tag('th'):attr('scope','col'):wikitext('Name'):done()
 
end
 
out_t:tag('th'):attr('scope','col'):wikitext('Rarity'):done()
 
:tag('th'):attr('scope','col'):wikitext('Category'):done()
 
if flag_qty then
 
out_t:tag('th'):attr('scope','col'):wikitext('Qty'):done()
 
end
 
if extra_column and extra_column ~= '' then
 
out_t:tag('th'):attr('scope','col'):wikitext(extra_column):done()
 
end
 
out_t:done() -- Close <tr>
 
 
 
-- Process list results:
+
-- Build table row:
  +
-- # Initialize:
for index, value in ipairs(cardList_array) do
 
-- Redefine values:
+
local row = HTML( 'tr' );
  +
-- # Card number:
local _headerSection, _raritySection, _qtySection; -- Section info.
 
  +
if not noAbbr then
local _nameCard, _nameCard_localized, _numberCard, _rarityCard, _typeCard, _qtyCard; -- Standard info.
 
  +
row:tag( 'td' ):wikitext( _number and (_number:match( '?' ) and _number or _link( _number )) ):done();
local nameCard_strip, nameCard_noDab; -- Aux.
 
  +
end
local _nameCard_alt, _nameCard_localized_alt, _numberCard_alt, _rarityCard_alt, _typeCard_alt,
 
  +
-- # Card name:
_description, _extra; -- Alternate info.
 
  +
row:tag( 'td' )
local display_nameCard, display_nameCard_localized, display_numberCard,
 
  +
:wikitext( _trim( table.concat( { _nameAlt or wrapQuotes( _link( _name, (_name or ''):match( 'Token %(' ) and _name ), true ), _description or '' }, ' ' ) ) )
display_rarityCard, display_typeCard, display_qtyCard; -- Display info.
 
+
:done();
-- Parse:
+
-- # Card local name:
if value:match('^%s*!:') then
+
if _D.flags['notEnglish'] then
  +
row:tag( 'td' ):attr( 'lang', _D.ln ):wikitext( _nameLocalAlt or _name and wrapQuotes( getNameLocal( _name ) ) ):done();
-- It's a section; contains section info.
 
  +
end
_headerSection = cardList_array[index]:match('header::(.-);')
 
  +
-- # Card rarity:
or cardList_array[index]:match('header::(.+)' );
 
  +
row:tag( 'td' ):wikitext( _rarityAlt or getRarity( _rarityList or rarityList ) ):done();
_raritySection = cardList_array[index]:match('rarity::(.-);')
 
  +
-- # Card type:
or cardList_array[index]:match('rarity::(.+)' );
 
  +
row:tag( 'td' ):wikitext( _typeAlt or _name and getCardType( _name ) ):done();
_qtySection = cardList_array[index]:match( 'qty::(.-);')
 
  +
-- # Card qty:
or cardList_array[index]:match( 'qty::(.+)' );
 
+
if qty then
  +
row:tag( 'td' ):wikitext( tonumber( _qty ) or qty or 1 ):done();
if _headerSection then
 
  +
end
out_t:tag('tr')
 
  +
-- # Extra column:
:tag('th'):attr('scope','col'):attr('colspan',counter_colspan):wikitext(_headerSection):done()
 
  +
if column then
:done()
 
end
+
row:tag( 'td' ):wikitext( _column ):done();
  +
end
elseif cardList_array[index]:match('^(%s*)$') then
 
  +
row:allDone();
-- Nothing: empty line.
 
  +
  +
return tostring( row );
  +
end
  +
  +
-- Wrap function.
  +
-- Given HTML table rows,
  +
-- wraps it with «table» tags and builds the table header.
  +
local function wrapTable( header, t, noAbbr, qty, column )
  +
local noAbbr = noAbbr or _D.flags['noAbbr'];
  +
local qty = qty or _D.flags['qty'];
  +
local column = column or _D.flags['column'];
  +
  +
-- Build HTML table:
  +
-- # Initialize:
  +
local HTMLtableHeader = HTML( 'table' ):attr( 'id', header or 'Top_table' ):addClass( 'wikitable' ):addClass( 'sortable' ):addClass( 'card-list' );
  +
local HTMLtableCaption = header and HTML( 'caption' ):wikitext( header ):done();
  +
local HTMLtableRow = HTML( 'tr' );
  +
-- # Card number:
  +
if not noAbbr then
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Card number' ):done();
  +
end
  +
-- # Card name:
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( _D.flags['notEnglish'] and 'English name' or 'Name' ):done();
  +
-- # Card local name:
  +
if _D.flags['notEnglish'] then
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( table.concat( { _D.language, ' name' } ) ):done();
  +
end
  +
-- # Card rarity:
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Rarity' ):done();
  +
-- # Card type:
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Category' ):done();
  +
-- # Card qty:
  +
if qty then
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Qty' ):done();
  +
end
  +
-- # Extra column:
  +
if column then
  +
HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( _trim( _D.args['col'] ) ):done();
  +
end
  +
HTMLtableRow:done(); -- Close the </tr>.
  +
  +
-- Concat everything:
  +
local HTMLtable = (header and HTMLtableHeader:node( tostring( HTMLtableCaption ) ) or HTMLtableHeader)
  +
:node( tostring( HTMLtableRow ) )
  +
:node( table.concat( t ) ) -- Add the table content (all card rows).
  +
:allDone(); -- Close table (</table>).
  +
  +
return tostring( HTMLtable );
  +
end
  +
  +
-- Main set list function:
  +
-- Designs the card table.
  +
local function getSetList()
  +
local sections = _D.args[1] and split( _D.args[1], '!:' ) or _error( 'No list info given!', { ';' } );
  +
local SetListTable = {}; -- Contains list of processed sections.
  +
for _, section in ipairs( sections ) do
  +
local _section;
  +
local sectionSetListTable = {}; -- Contains list of processed card entries.
  +
local _header, _sectionNoAbbr, _sectionRarityList, _sectionQty; -- Store section info, applied to all section entries.
  +
if not _trim( section ) then
  +
-- Empty section; skip.
 
else
 
else
  +
-- It's a section.
local cardList_array_parts = mw.text.split( cardList_array[index], '//' );
 
--[[
+
local entries = split( section, '\n' );
  +
for index, entry in ipairs( entries ) do
cardList_array_parts[1] has the standard values ($values-standard);
 
cardList_array_parts[2] has the alternate values ($values-alternate);
+
if not _trim( entry ) then
]]
+
-- Emtpy entry; skip.
  +
elseif index == 1 and entry:match( 'header::' ) then
-- Deal with standard values:
 
  +
-- Contains header info.
local cardList_array_std = mw.text.split( cardList_array_parts[1], ';' );
 
  +
_header, _sectionNoAbbr, _sectionRarityList, _sectionQty, _sectionColumn = getSetListHeader( entry );
if flag_noAbbr then
 
_nameCard = mw.text.trim( cardList_array_std[1] or '' );
 
_rarityCard = mw.text.trim( cardList_array_std[2] or '' );
 
_qtyCard = mw.text.trim( cardList_array_std[3] or '' );
 
else
 
_numberCard = mw.text.trim( cardList_array_std[1] or '' );
 
_nameCard = mw.text.trim( cardList_array_std[2] or '' );
 
nameCard_strip = mw.ustring.gsub( _nameCard, '#', '' ); -- Remove «#» from card names.
 
nameCard_noDab = mw.text.split( _nameCard, ' %(' )[1]; -- Remove dab text
 
_rarityCard = mw.text.trim( cardList_array_std[3] or '' );
 
_qtyCard = mw.text.trim( cardList_array_std[4] or '' );
 
end
 
_nameCard_localized = LN.localized_name( nameCard_strip, _language );
 
_typeCard = frame:expandTemplate{ title = 'Card type', args = { nameCard_strip } };
 
 
-- Deal with alternate values:
 
if cardList_array_parts[2] then
 
_nameCard_alt = cardList_array_parts[2]:match('name::(.-);')
 
or cardList_array_parts[2]:match('name::(.+)' );
 
_nameCard_localized_alt = cardList_array_parts[2]:match('name%-local::(.-);')
 
or cardList_array_parts[2]:match('name%-local::(.+)' );
 
_numberCard_alt = cardList_array_parts[2]:match('number::(.-);')
 
or cardList_array_parts[2]:match('number::(.+)' );
 
_rarityCard_alt = cardList_array_parts[2]:match('rarity::(.-);')
 
or cardList_array_parts[2]:match('rarity::(.+)' );
 
_typeCard_alt = cardList_array_parts[2]:match('category::(.-);')
 
or cardList_array_parts[2]:match('category::(.+)' );
 
_description = cardList_array_parts[2]:match('decription::(.-);')
 
or cardList_array_parts[2]:match('decription::(.+)' );
 
if extra_column and extra_column ~= '' then
 
_extra = cardList_array_parts[2]:match(extra_column:lower()..'::(.-);')
 
or cardList_array_parts[2]:match(extra_column:lower()..'::(.+)' );
 
end
 
end
 
-- Display values:
 
-- # Card name:
 
if _nameCard_alt then
 
display_nameCard = _nameCard_alt;
 
elseif _nameCard and _nameCard ~= '' then
 
display_nameCard = '"[[' ..nameCard_strip.. '|' ..nameCard_noDab.. ']]"';
 
else
 
display_nameCard = '';
 
end
 
-- # Card localized name:
 
if _nameCard_localized_alt then
 
display_nameCard_localized = _nameCard_localized_alt;
 
else
 
if _nameCard_localized and _ln == "ja" or _ln == "zh" then
 
display_nameCard_localized = '「' .._nameCard_localized.. '」' or '';
 
elseif _nameCard_localized then
 
display_nameCard_localized = '"' .._nameCard_localized.. '"' or '';
 
end
 
end
 
-- # Card number:
 
if not(flag_noAbbr) then
 
if _numberCard_alt then
 
display_numberCard = _numberCard_alt;
 
 
else
 
else
if _numberCard:match('?') then
+
-- Card info.
  +
table.insert( sectionSetListTable, getSetListCard( entry, _sectionNoAbbr, _sectionRarityList, _sectionQty, _sectionColumn ) );
display_numberCard = _numberCard; -- Unknown; don't link.
 
else
 
display_numberCard = '[[' .._numberCard.. ']]'; -- Link.
 
end
 
 
end
 
end
 
end
 
end
-- # Card rarity:
+
-- Process table for each section.
  +
_section = wrapTable( _header, sectionSetListTable, _sectionNoAbbr, _sectionQty, _sectionColumn );
if _rarityCard_alt then
 
  +
end
display_rarityCard = _rarityCard_alt;
 
else
+
table.insert( SetListTable, _section );
  +
end
local rarity_array;
 
  +
return table.concat( SetListTable, '\n' );
if _rarityCard and _rarityCard ~= '' then
 
  +
end
rarity_array = mw.text.split( _rarityCard, ',' );
 
  +
elseif _raritySection and _raritySection ~= '' then
 
  +
-------------------
rarity_array = mw.text.split( _raritySection, ',' );
 
  +
-- Main functions:
elseif _rarity and _rarity ~= '' then
 
  +
-------------------
rarity_array = mw.text.split( _rarity, ',' );
 
  +
-- Main function:
end
 
  +
-- To be called through #invoke.
if rarity_array then
 
  +
function SetList.main( frame )
for _, rarity in ipairs(rarity_array) do
 
  +
_D.errors = {};
display_rarityCard = (display_rarityCard or '').. '[[' ..(rarity_list[mw.ustring.gsub(mw.text.trim(rarity):lower(), ' rare', '')] or rarity_list['default']).. ']]<br />';
 
end
+
_D.args = getArgs( frame, { trim = true, removeBlanks = true, parentOnly = true } );
  +
local PAGENAME = mw.title.getCurrentTitle().text; -- {{PAGENAME}}
else
 
  +
local NAMESPACE = mw.title.getCurrentTitle().nsText; -- {{NAMESPACE}}
display_rarityCard = ''; -- Display blank.
 
end
+
end
+
getInfo();
  +
local _setName, _setNameLocal = getSetName( PAGENAME );
-- # Card type:
 
  +
local header = getHeader( _setName, _setNameLocal );
display_typeCard = _typeCard_alt or _typeCard;
 
  +
local category = getCategory( NAMESPACE )
-- # Card qty:
 
  +
local setList = getSetList();
if _qtyCard_alt then
 
  +
local track = tracking( frame:getParent().args );
display_qtyCard = _qtyCard_alt;
 
  +
elseif _qtySection and _qtySection ~= '' then
 
  +
-- Return value:
display_qtyCard = tonumber(_qtySection) or 1;
 
  +
local ret = {};
elseif _qtyCard and _qtyCard ~= '' then
 
  +
if _trim( NAMESPACE ) then
display_qtyCard = tonumber(_qtyCard) or 1;
 
elseif _qty and _qty ~= '' then
+
if _count( _D.errors ) > 0 then
display_qtyCard = _qty;
+
for key, value in ipairs( _D.errors ) do
  +
table.insert( ret, value );
 
end
 
end
 
-- Add to table:
 
-- (rough draft!) TO DO
 
out_t:tag('tr')
 
:tag('td'):wikitext(display_numberCard):done()
 
:tag('td'):wikitext(display_nameCard):done()
 
:tag('td'):wikitext(display_nameCard_localized):done()
 
:tag('td'):wikitext(display_rarityCard):done()
 
:tag('td'):wikitext(display_typeCard):done()
 
:tag('td'):wikitext(display_qtyCard):done()
 
:done()
 
 
end
 
end
  +
table.insert( ret, header );
  +
table.insert( ret, category );
  +
table.insert( ret, setList );
  +
else
  +
-- When on the set page.
  +
return setList;
 
end
 
end
 
 
out_t:allDone() -- Close <table> (for testing)
+
return table.concat( ret );
-- For debug.
 
local debug = mw.html.create( 'ul' )
 
:tag('li'):tag('code'):wikitext('PAGENAME'):done():wikitext(': '..PAGENAME):done()
 
:tag('li'):tag('code'):wikitext('NAMESPACE'):done():wikitext(': '..NAMESPACE):done()
 
:tag('li'):tag('code'):wikitext('_rg'):done():wikitext(': '.._rg):done()
 
:tag('li'):tag('code'):wikitext('_region'):done():wikitext(': '.._region):done()
 
:tag('li'):tag('code'):wikitext('_ln'):done():wikitext(': '.._ln):done()
 
:tag('li'):tag('code'):wikitext('_language'):done():wikitext(': '.._language):done()
 
:tag('li'):tag('code'):wikitext('_nameSet'):done():wikitext(': '.._nameSet):done()
 
:tag('li'):tag('code'):wikitext('_nameSet_localized'):done():wikitext(': '.._nameSet_localized):done()
 
:tag('li'):tag('code'):wikitext('_qty'):done():wikitext(': '..tostring(_qty)):done()
 
:tag('li'):wikitext('<b>Flags</b>'):done()
 
:tag('li'):tag('code'):wikitext('flag_notEnglish'):done():wikitext(': '..tostring(flag_notEnglish)):done()
 
:tag('li'):tag('code'):wikitext('flag_italics'):done():wikitext(': '..flag_italics):done()
 
:tag('li'):tag('code'):wikitext('flag_qty'):done():wikitext(': '..tostring(flag_qty)):done()
 
:tag('li'):tag('code'):wikitext('flag_noAbbr'):done():wikitext(': '..tostring(flag_noAbbr)):done()
 
:tag('li'):wikitext('<b>List</b>'):done()
 
:tag('li'):tag('code'):wikitext('extra_column'):done():wikitext(': '..tostring(extra_column)):done()
 
:tag('li'):tag('code'):wikitext('counter_colspan'):done():wikitext(': '..counter_colspan):done()
 
:tag('li'):tag('code'):wikitext('cardList_input'):done():wikitext(': '..tostring(cardList_input)):done()
 
:done()
 
 
return tostring(debug)..tostring(header)..category..tostring(out_t); --the set list page;
 
 
end
 
end
   
  +
return myInput;
 
  +
return SetList;
  +
-- </pre>

Revision as of 21:42, 10 November 2019

Test Template Info-Icon - Version (2) Module documentation

The documentation for this module is missing. Click here to create it.

--  <pre>
--  Module for {{Set list}},
--  to be used like {{#invoke:Set list|main}}.
--  @@@ for ideas.
-------------------
local SetList = {};

-----------------
--  Load modules:
-----------------
local getArgs       = require( 'Dev:Arguments' ).getArgs;
local getCardType   = require( 'Module:Card type' ).main;

--------------
--  Load data:
--------------
local _D            = {};
local data          = mw.loadData( 'Module:Set list/data' );
local rg_list       = data.rg_list;         --  Region code table.
local region_list   = data.region_list;     --  Region name table.
local ln_list       = data.ln_list;         --  Language code table.
local language_list = data.language_list;   --  Language name table.
local rarity_list   = data.rarity_list;     --  Rarity name table.
local abbr_list     = data.abbr_list;       --  Abbr disable codes table.

----------------------
--  Utility functions:
----------------------
--  mw functions:
local split = mw.text.split;
local HTML  = mw.html.create;

--  Trim function:
--  Trims white space from front and tail of string.
--  If the input is only white space, returns nil.
local function _trim( s )
    if s and not s:match( '^%s*$' ) then
        return mw.text.trim( s ); -- If not nil nor empty.
    end
end

--  Link function:
--  If a string is passed, links it;
--  uses a label, when given.
--  If a table is passed, links every instance of it;
--  uses a table of labels, respectively for each entry, when given.
local function _link( v, ... )
    local labels = type( ... or nil ) == 'table' and ... or  { ... };  --  Make sure it's a table.
    local function __link( v, label )
        return ('[[%s|%s]]'):format( v:gsub( '#', '' ), _trim( label ) or split( v, '%s*%(' )[1] );
    end
    if type( v ) == 'string' then
        return __link( v, labels[1] );
    elseif type( v ) == 'table' then
        local t = {};
        for key, value in ipairs( v ) do
            table.insert( t, __link( value, labels[key] ));
        end
        return t;
    else
        return v; -- @@@ error()
    end
end

--  Table count function:
--  Given a table, counts how many valuee it has.
local function _count( t ) -- @@@ error() for wrong type()
    local counter = 0;
    for key, value in pairs( t ) do
        counter = counter + 1;
    end
    return counter;
end

local function _error( message, default, category ) -- @@@ input list of categories.
    local err   = HTML( 'div' ):css( 'padding-left', '1.6em' )
                    :tag( 'strong' ):addClass( 'error' ):wikitext( ('Error: %s'):format( message ) ):done()
                :allDone();
    local cat   = ('[[Category:%s]]'):format( category or '((Set list)) transclusion to be checked' );
    table.insert( _D.errors, table.concat( { tostring( err ), cat } ) );
    return default or '';
end

-------------------------------
--  Getter/generator functions:
-------------------------------
--  Info function:
--  Handles region/language info and flags.
local function getInfo()
    _D.rg       = _D.args['region'] and _D.args['region']:lower() or _error( 'A «region» is always needed!', 'en' );
    _D.region   = region_list[_D.rg];
    _D.ln       = ln_list[_D.rg];
    _D.language = language_list[_D.ln];
    --  Flags:
    _D.flags    = {};
    _D.flags.qty        = _D.args['qty'] and true;
    _D.flags.noAbbr     = _D.args['abbr'] and abbr_list[_D.args['abbr']:lower()] and true;
    _D.flags.column     = _D.args['col'] and true;
    _D.flags.notEnglish = _D.ln ~= 'en';
    _D.flags.italics    = ((_D.ln == 'ja') or (_D.ln == 'zh') or (_D.ln == 'ko')) and 'normal' or 'italic'; 
end

--  Local name function:
--  Returns the localized name.
local function getNameLocal( name )
    if not mw.smw then
        return _error( 'mw.smw module not found' );
    end
    local _page = name:gsub( '#', '' );
    local _query = { ('[[%s]]'):format( _page ), ('?%s name='):format( _D.language ), limit = 1, mainlabel = '-' };
    local query = mw.smw.ask( _query );
    if not query or _count( query ) == 0 or _count( query[1] ) == 0 then
        return;
    end
    return query[1][1];
end

--  Name function:
--  Returns two values:
--  The English name; the localized name.
local function getSetName( name )
    local t = split( name, '%s*%(' );
    local _name = _D.args['set'] or _trim( t[3] ) and table.concat( t, ' (', 1, 2 ) or t[1];
    local _nameLocal = _D.flags['notEnglish'] and getNameLocal( _name );
    return _name, _nameLocal;
end

--  Quotes function:
--  Wraps a name with quotes.
local function wrapQuotes( name, std )
    if not _trim( name ) then
        return '';  --  Return empty string.
    end
    return (std or (_D.ln ~= 'ja' and _D.ln ~= 'zh')) and table.concat( { '"', name, '"' } )
        or table.concat( { '「', name, '」' } );
end

--  Rarity function:
--  Receives a string of rarities.
local function getRarity( s )
    local t = s and split( s, ',' ) or {};
    local rarities = {};
    for _, rarity in ipairs( t ) do
        _rarity = _trim( rarity:lower():gsub( ' rare$', '' ) );
        if _rarity and rarity_list[_rarity] then
            table.insert( rarities, _link( rarity_list[_rarity] ) );
        end
    end
    return table.concat( rarities, '<br />' );
end

--  Page header function:
--  Builds page header (HTML).
local function getHeader( setName, setNameLocal )
    local CSS = {
                    {   --  First «span» tag (set name).
                        ['font-size']   = '120%',
                        ['font-weight'] = 'bold',
                        ['font-style']  = 'italic'
                    },
                    {   --  Second «span» tag (local set name).
                        ['font-weight'] ='bold',
                        ['font-style']  = _D.flags['italics']
                        
                    }
                };
    
    local header = HTML( 'div' ):css( 'text-align', 'center' )
        :tag( 'span' ):css( CSS[1] )
            :wikitext( _link( setName, (setName:match( '%(2011%)' ) or setName:match( '%(series%)' )) and setName ) )
        :done();
    if _trim( setNameLocal ) then
        header:tag( 'br' ):done()
        :tag( 'span' ):css( CSS[2] )
            :wikitext( setNameLocal )
        :done();
    end
    header:tag( 'br' ):done()
        :wikitext( _D.region )
    :allDone();
    
    return tostring( header );
end

--  Categories function:
--  Generates categories.
local function getCategory( ns )
    --  @@@ Make it similar to _link.
    return ('[[Category:%s %s]]'):format( _D.region, ns );
end

local function tracking( frameArgs )
    local _parameters = {
        1,
        ['region']  = 'region',
        ['set']     = 'set',
        ['abbr']    = 'abbr',
        ['rarity']  = 'rarity',
        ['qty']     = 'qty',
        ['col']     = 'col'
    }
    for key, value in pairs( frameArgs ) do
       if not( _parameters[key] ) or not( _trim( value ) ) then
           --  There are parameters not being used or used empty.
           return _error( 'Instance of unsupported or empty parameters!' , nil, '((Set list)) transclusion with parameters to be checked' )
        end
    end
    return '';
end

-----------------------
--  Set list functions:
-----------------------
--  Header entry function:
--  Builds the section header.
--  Fetches section info.
local function getSetListHeader( entry )
    local _header            = entry:match('header::(.-);')
                            or entry:match('header::(.+)' );
    local _sectionNoAbbr     = entry:match(  'abbr::(.-);')
                            or entry:match(  'abbr::(.+)' );
    local _sectionRarityList = entry:match('rarity::(.-);')
                            or entry:match('rarity::(.+)' );
    local _sectionQty        = entry:match(   'qty::(.-);')
                            or entry:match(   'qty::(.+)' );
    local _sectionColumn     = entry:match(   'col::(.-);')
                            or entry:match(   'col::(.+)' );
    local sectionNoAbbr = _trim( _sectionNoAbbr ) and abbr_list[_trim( _sectionNoAbbr )] and true;
        
    return _trim( _header ), sectionNoAbbr, _sectionRarityList, _sectionQty, _trim( _sectionColumn );
end

--  Card entry function:
--  Builds the card row.
local function getSetListCard( entry, sectionNoAbbr, sectionRarityList, sectionQty, sectionColumn )
    --  Intialize vars:
    local _number, _name, _rarityList, _qty;
    local _nameAlt, _nameLocalAlt, _rarityAlt, _typeAlt, _description, _column;
    --  General values (from args or section):
    local noAbbr     = sectionNoAbbr or _D.flags['noAbbr'];
    local rarityList = sectionRarityList or _D.args['rarity'];
    local qty        = (sectionQty or _D.flags['qty']) and (tonumber( sectionQty or _D.args['qty'] ) or 1);
    local column     = sectionColumn or _D.args['col'];
    
    --  Local values:
    --  # Split info:
    local valuesStandard    = split( split( entry, '//' )[1] , ';');
    local valuesAlternate   =        split( entry, '//' )[2];
    
    --  # Deal with standard values:
    if noAbbr then
        _name       = _trim( valuesStandard[1] );
        _rarityList = _trim( valuesStandard[2] );
        _qty        = _trim( valuesStandard[3] );
    else
        _number     = _trim( valuesStandard[1] );
        _name       = _trim( valuesStandard[2] );
        _rarityList = _trim( valuesStandard[3] );
        _qty        = _trim( valuesStandard[4] );
    end
    
    --  # Deal with alternate values:
    if valuesAlternate then
        _nameAlt      = valuesAlternate:match(       'name::(.-);')
                     or valuesAlternate:match(       'name::(.+)' );
        _nameLocalAlt = valuesAlternate:match('name%-local::(.-);')
                     or valuesAlternate:match('name%-local::(.+)' );
        _rarityAlt    = valuesAlternate:match(     'rarity::(.-);')
                     or valuesAlternate:match(     'rarity::(.+)' );
        _typeAlt      = valuesAlternate:match(   'category::(.-);')
                     or valuesAlternate:match(   'category::(.+)' );
        _description  = valuesAlternate:match('description::(.-);')
                     or valuesAlternate:match('description::(.+)' );
        _column       = column and
                        (valuesAlternate:match(table.concat( { column:lower(), '::(.-);' } )) 
                      or valuesAlternate:match(table.concat( { column:lower(), '::(.+)'  } )));
    end
    
    --  Build table row:
    --  # Initialize:
    local row = HTML( 'tr' );
    --  # Card number:
    if not noAbbr then
        row:tag( 'td' ):wikitext( _number and (_number:match( '?' ) and _number or _link( _number )) ):done();
    end
    --  # Card name:
    row:tag( 'td' )
        :wikitext( _trim( table.concat( { _nameAlt or wrapQuotes( _link( _name, (_name or ''):match( 'Token %(' ) and _name ), true ), _description or '' }, ' ' ) ) )
    :done();
    --  # Card local name:
    if _D.flags['notEnglish'] then
        row:tag( 'td' ):attr( 'lang', _D.ln ):wikitext( _nameLocalAlt or _name and wrapQuotes( getNameLocal( _name ) ) ):done();
    end
    --  # Card rarity:
    row:tag( 'td' ):wikitext( _rarityAlt or getRarity( _rarityList or rarityList ) ):done();
    --  # Card type:
    row:tag( 'td' ):wikitext( _typeAlt or _name and getCardType( _name ) ):done();
    --  # Card qty:
    if qty then
        row:tag( 'td' ):wikitext( tonumber( _qty ) or qty or 1 ):done();
    end
    --  # Extra column:
    if column then
        row:tag( 'td' ):wikitext( _column ):done();
    end
    row:allDone();
    
    return tostring( row );
end

--  Wrap function.
--  Given HTML table rows,
--  wraps it with «table» tags and builds the table header.
local function wrapTable( header, t, noAbbr, qty, column )
    local noAbbr    = noAbbr or _D.flags['noAbbr'];
    local qty       = qty or _D.flags['qty'];
    local column    = column or _D.flags['column'];
    
    --  Build HTML table:
    --  # Initialize:
    local HTMLtableHeader   = HTML( 'table' ):attr( 'id', header or 'Top_table' ):addClass( 'wikitable' ):addClass( 'sortable' ):addClass( 'card-list' );
    local HTMLtableCaption  = header and HTML( 'caption' ):wikitext( header ):done();
    local HTMLtableRow      = HTML( 'tr' );
    --  # Card number:
    if not noAbbr then
        HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Card number' ):done();
    end
    --  # Card name:
    HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( _D.flags['notEnglish'] and 'English name' or 'Name' ):done();
    --  # Card local name:
    if _D.flags['notEnglish'] then
        HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( table.concat( { _D.language, ' name' } ) ):done();
    end
    --  # Card rarity:
    HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Rarity' ):done();
    --  # Card type:
    HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Category' ):done();
    --  # Card qty:
    if qty then
        HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( 'Qty' ):done();
    end
    --  # Extra column:
    if column then
        HTMLtableRow:tag( 'th' ):attr( 'scope', 'col' ):wikitext( _trim( _D.args['col'] ) ):done();
    end
    HTMLtableRow:done();    --  Close the </tr>.
    
    --  Concat everything:
    local HTMLtable = (header and HTMLtableHeader:node( tostring( HTMLtableCaption ) ) or HTMLtableHeader)
        :node( tostring( HTMLtableRow ) )
        :node( table.concat( t ) )  --  Add the table content (all card rows).
        :allDone();    --  Close table (</table>).

    return tostring( HTMLtable );
end

--  Main set list function:
--  Designs the card table.
local function getSetList()
    local sections  = _D.args[1] and split( _D.args[1], '!:' ) or _error( 'No list info given!', { ';' } );
    local SetListTable = {};    --  Contains list of processed sections.
    for _, section in ipairs( sections ) do
        local _section;
        local sectionSetListTable = {}; --  Contains list of processed card entries.
        local _header, _sectionNoAbbr, _sectionRarityList, _sectionQty;  --  Store section info, applied to all section entries.
        if not _trim( section ) then
            --  Empty section; skip.
        else
            --  It's a section.
            local entries = split( section, '\n' );
            for index, entry in ipairs( entries ) do
                if not _trim( entry ) then
                    --  Emtpy entry; skip.
                elseif index == 1 and entry:match( 'header::' ) then
                    --  Contains header info.
                    _header, _sectionNoAbbr, _sectionRarityList, _sectionQty, _sectionColumn = getSetListHeader( entry );
                else
                    --  Card info.
                    table.insert( sectionSetListTable, getSetListCard( entry, _sectionNoAbbr, _sectionRarityList, _sectionQty, _sectionColumn ) );
                end
            end
            --  Process table for each section.
            _section = wrapTable( _header, sectionSetListTable, _sectionNoAbbr, _sectionQty, _sectionColumn );
        end
        table.insert( SetListTable, _section );
    end
    return table.concat( SetListTable, '\n' );
end

-------------------
--  Main functions:
-------------------
--  Main function:
--  To be called through #invoke.
function SetList.main( frame )
    _D.errors       = {};
    _D.args         = getArgs( frame, { trim = true, removeBlanks = true, parentOnly = true } );
    local PAGENAME  = mw.title.getCurrentTitle().text;     --  {{PAGENAME}}
    local NAMESPACE = mw.title.getCurrentTitle().nsText;   --  {{NAMESPACE}}
    
    getInfo();
    local _setName, _setNameLocal = getSetName( PAGENAME );
    local header    = getHeader( _setName, _setNameLocal );
    local category  = getCategory( NAMESPACE )
    local setList   = getSetList();
    local track     = tracking( frame:getParent().args );
    
    --  Return value:
    local ret = {};
    if _trim( NAMESPACE ) then
        if _count( _D.errors ) > 0 then 
            for key, value in ipairs( _D.errors ) do
                table.insert( ret, value );
            end
        end
        table.insert( ret, header );
        table.insert( ret, category );
        table.insert( ret, setList );
    else
        --  When on the set page.
        return setList;
    end
    
    return table.concat( ret );
end


return SetList;
--  </pre>