Модул:File — разлика између измена

Извор: SI Wiki
Пређи на навигацију Пређи на претрагу
м (Ovako)
м (Šta)
Ред 4: Ред 4:
local data = mw.loadData('Module:File/data')
local data = mw.loadData('Module:File/data')


local function makeRow(html, title, content, ic)
local function makeRow(html, title, content, id)
     local tr = html:tag('tr')
     local tr = html:tag('tr')
     local th = tr:tag('th'):wikitext(title)
     local th = tr:tag('th'):wikitext(title)
     if ic ~= nil then
     if id ~= nil then
     th:attr('id', cls)
     th:attr('id', id)
     end
     end
     th:done()
     th:done()

Верзија на датум 27. фебруар 2021. у 01:27

Овај модул служи за генерисање табеле са описом датотека. За документацију о коришћењу видети Шаблон:File. Овај модул такође довлачи потребне податке за рад из модула са подацима.


local p = {}

local title = mw.title.getCurrentTitle()
local data = mw.loadData('Module:File/data')

local function makeRow(html, title, content, id)
    local tr = html:tag('tr')
    local th = tr:tag('th'):wikitext(title)
    if id ~= nil then
    	th:attr('id', id)
    end
    th:done()
    tr:tag('td')
			:wikitext(content)
			:done()
	  :done()
end

function p.category(category, subcategory)
	if category == nil then
		return '[[Категорија:Остале датотеке]]'
	elseif subcategory == nil then
		return table.concat({'[[Категорија:', category, ']]'})
	else
		return table.concat({'[[Категорија:', category, '/', data.subcategories[subcategory], ']]'})
	end
end

function p.main(frame)
	local args = frame:getParent().args
	if title.namespace ~= 6 then
		return
	end
	local subject = mw.text.split(title.text, ' ', true)[1]
	local category = data.categories[subject]
	local html = mw.html.create('table')
		:attr('class', 'wikitable file-description')
	if args.description ~= nil then
		makeRow(html, 'Опис датотеке', args.description, 'fileinfotpl_desc')
	end
	if category ~= nil then
		makeRow(html, 'Предмет', table.concat({'[[', category, ']]'}))
	end
	if args.author ~= nil then
		makeRow(html, 'Аутор', args.author, 'fileinfotpl_aut')
	end
	makeRow(html, 'Лиценца', args.license and data.licenses[args.license] or data.licenses.default)
	if args.source ~= nil then
		makeRow(html, 'Извор', args.source, 'fileinfotpl_src')
	end
	if args.notes ~= nil then
		makeRow(html, 'Напомене', args.notes)
	end
	return tostring(html) .. p.category(category, args.type)
end

return p