Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
 
(15 intermediate revisions by the same user not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
local cfg = mw.loadData('Module:CareerList/config')
function p.makeTableTop()
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')
local function getSiteLink(site)
:css('width', '100%')
site = mw.ustring.lower(site)
:node(headerRow)
local url = cfg[site].url or ''
local id = cfg[site].id or '':done()
return url:gsub('$1', id)
end
 
-- Функция для создания ячейки таблицы
local function makeCell(args, bgcolor)
function p.makeCell(cellType, args)
local site = args.site or ''
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
end
 
local function getNotes(notes)
if not notes or notes == '' then
return 'N/A'
else
return notes
end
end
 
if not args.site then
return mw.html.create('tr')
:css('background-color', getColor(args.rowIndex))
: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, or mw.title.getCurrentTitle(site).text
local notes = getNotes(args.notes or 'N/A')
local linkbackground = string.formatgetBackground("[%s %s]", site, alias or pagename or "N/A")
 
local bg = (site == 'Website') and '#E7E7E7' or '#DADADA'
local rowbgcell = mw.html.create(bgcolor == '#FFFFFFtd') and '#F3F3F3' or '#FFFFFF'
:css('background-color', background)
return string.format([[
:css('padding', '8px')
<tr style="background-color: %s;">
:wikitext(p.getSiteLink(site))
<td style="background-color: %s;">%s</td>
:done()
<td style="background-color: %s;"><a href="%s">%s</a></td>
 
<td>%s</td>
local idCell = <td>%s</mw.html.create('td>')
:css('background-color', background)
</tr>
:css('padding', '8px')
]], bgcolor, bg, site, rowbg, link, alias, alias, notes)
: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.main(frame)
function p.processArgs(frame)
local args = frame.args
local args = require('Module:Arguments').getArgs(frame, {
local list = args.list or ''
wrappers = 'Template:CareerList'
local title = args.title or ''
})
local bgcolor = '#F2F2F2'
local site = args[1] or ''
local rows = ''
local id = args[2] or ''
for row in mw.ustring.gmatch(list, '{{CareerListCell(.-)}}') do
local alias = args[3] or ''
rows = rows .. makeCell(mw.text.split(row, '|'), bgcolor)
local notes = args[4] or ''
bgcolor = (bgcolor == '#FFFFFF') and '#F3F3F3' or '#FFFFFF'
 
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
return string.format([[
end
<table class="wikitable" style="width: 100%; margin: 1em 0; background-color: %s;">
 
<caption>%s</caption>
-- Главная функция модуля
<tr>
function p.main(frame)
<th style="width: 15%;">Type</th>
local tableTop = p.makeTableTop()
<th style="width: 35%;">Name</th>
local tableRows = ''
<th style="width: 35%;">Alias</th>
for i = 1, 999 do
<th style="width: 15%;">Notes</th>
local result = p.processArgs(frame:getParent())
</tr>
if type(result) == 'string' then
%s
return result
</table>
elseif not result then
]], bgcolor, title, rows)
break
else
tableRows = tableRows .. tostring(result)
end
end
return tostring(tableTop) .. tableRows .. '</table>'
end