Content deleted Content added
No edit summary
No edit summary
 
(32 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
-- Load the configuration file
function p.makeTableTop()
local cfg = mw.loadData('Module:CareerList/config')
local headerRow = mw.html.create('tr')
:node(mw.html.create('th'):wikitext('site'))
:node(mw.html.create('th'):wikitext('id'))
:node(mw.html.create('th'):wikitext('alias'))
:node(mw.html.create('th'):wikitext('notes'))
:done()
 
return mw.html.create('table')
-- Function to build a row of the table
:css('width', '100%')
function buildRow(site, id, alias, notes, index)
:node(headerRow)
-- Determine the row color
local color :done()
end
if site == 'Website' then
 
color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
-- Функция для создания ячейки таблицы
function p.makeCell(cellType, args)
local function getColor(index)
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
end
 
local function getBackground(site)
local config = mw.loadData('Module:CareerList/config')
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7'
return config[site] and color or '#FFFFFF'
end
 
local function getAlias(alias, title)
if not alias or alias == '' then
return 'N/A'
else
return alias
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
-- Build the row
local row = string.format(
cfg.rowTemplate,
color,
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
site,
cfg.siteUrls[site][1],
cfg.siteUrls[site][2]:gsub('$1', id),
alias == '' and mw.title.getCurrentTitle().text or alias,
notes == '' and 'N/A' or notes
)
return row
end
 
-- Main local function getNotes(notes)
if not notes or notes == '' then
function p.main(frame)
-- Get the template parametersreturn 'N/A'
else
local args = frame.args
return notes
-- Get the list parameter
local list = args.list or error('List not specified')
-- Split the list into rows
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
-- Build the table
local index = 1
local tableContent = ''
for _, row in ipairs(rows) do
local params = mw.text.split(row, '%s*|%s*')
if #params >= 3 then
local site = params[1]
local id = params[2]
local alias = params[3]
local notes = params[4] or ''
tableContent = tableContent .. buildRow(site, id, alias, notes, index)
index = index + 1
end
end
end
 
-- Build the table
if not args.site then
local tableHtml = string.format(cfg.tableTemplate, tableContent)
return mw.html.create('tr')
:css('background-color', getColor(args.rowIndex))
return tableHtml
:node(mw.html.create('td'):attr('colspan', '4'):wikitext('Invalid arguments. Please see documentation for correct usage.'))
:done()
end
 
local site = args.site or mw.title.getCurrentTitle().text
local id = args.id or ''
local alias = getAlias(args.alias, site)
local notes = getNotes(args.notes)
local background = getBackground(site)
 
local cell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(p.getSiteLink(site))
:done()
 
local idCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(id)
:done()
 
local aliasCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(aliasCell)
:done()
 
local notesCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(notesCell)
:done()
 
return mw.html.create('tr')
:css('background-color', getColor(args.rowIndex))
:node(cell)
:node(idCell)
:node(aliasCell)
:node(notesCell)
:done()
end
-- Функция для определения ссылки на сайт
function p.getSiteLink(site)
local config = mw.loadData('Module:CareerList/config')
site = site:lower()
if config[site] then
local url = config[site].url
local id = mw.text.encode(site.id)
return string.format('[%s %s]', url:gsub('$1', id), site)
else
return site
end
end
 
-- Функция для обработки аргументов
function p.processArgs(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:CareerList'
})
local site = args[1] or ''
local id = args[2] or ''
local alias = args[3] or ''
local notes = args[4] or ''
 
if site == '' then
return '<strong class="error">Error: </strong>Site parameter is required'
else
site = site:lower()
if not mw.loadData('Module:CareerList/config')[site] then
return '<strong class="error">Error: </strong>Invalid site specified'
else
return p.makeCell(site, id, alias, notes)
end
end
end
 
-- Главная функция модуля
function p.main(frame)
local tableTop = p.makeTableTop()
local tableRows = ''
for i = 1, 999 do
local result = p.processArgs(frame:getParent())
if type(result) == 'string' then
return result
elseif not result then
break
else
tableRows = tableRows .. tostring(result)
end
end
return tostring(tableTop) .. tableRows .. '</table>'
end