Content deleted Content added
Created page with "local p = {} function p.getConfig(siteName) local siteConfig = mw.loadData("Module:CareerList/config")[siteName] if not siteConfig then error(string.format("Site '%s' not found in configuration file", siteName)) end return siteConfig end function p.makeUrl(siteName, id) local siteConfig = p.getConfig(siteName) local url = siteConfig.url local variable = siteConfig.variable local idPlaceholder = string.find(url, variable) if i..."
 
No edit summary
 
(36 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
function p.getConfig(siteName)
function p.makeTableTop()
local siteConfig = mw.loadData("Module:CareerList/config")[siteName]
local headerRow = mw.html.create('tr')
if not siteConfig then
:node(mw.html.create('th'):wikitext('site'))
error(string.format("Site '%s' not found in configuration file", siteName))
: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')
:css('width', '100%')
:node(headerRow)
:done()
end
 
-- Функция для создания ячейки таблицы
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
end
return siteConfig
end
 
local function p.makeUrlgetNotes(siteName, idnotes)
if not notes or notes == '' then
local siteConfig = p.getConfig(siteName)
local url = siteConfig.url return 'N/A'
else
local variable = siteConfig.variable
return notes
local idPlaceholder = string.find(url, variable)
if idPlaceholder == nil then
error(string.format("No id placeholder found in URL for site '%s'", siteName))
end
return string.sub(url, 1, idPlaceholder - 1) .. id .. string.sub(url, idPlaceholder + string.len(variable))
end
 
if not args.site then
function p.makeTable(frame)
local data = return mw.html.create("table"'tr')
:css('background-color', getColor(args.rowIndex))
data
:node(mw.html.create('td'):attr('colspan', '4'):wikitext('Invalid arguments. Please see documentation for correct usage.'))
:addClass("wikitable")
:addClass("sortable")
:addClass("career-new")
:tag("tr")
:tag("th")
:wikitext(frame.args.title or "")
:done()
for _, row in ipairs(frame.args.list or {}) do
local siteName = row.site
local id = row.id
local alias = row.alias or ""
local notes = row.notes or ""
local url = p.makeUrl(siteName, id)
data
:tag("tr")
:tag("td")
:wikitext(row.site)
:done()
:tag("td")
:wikitext(row.id)
:done()
:tag("td")
:wikitext(row.alias)
:done()
:tag("td")
:wikitext(row.notes)
:done()
end
 
return tostring(data)
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