Moduł:Czy wiesz/weryfikacja

Z Wikipedii, wolnej encyklopedii
 Dokumentacja modułu [zobacz] [edytuj] [historia] [odśwież]

Moduł służy jako pomocniczy komponent szablonu {{Wikiprojekt:Czy wiesz/weryfikacja}}. Optymalizuje zapytania do Wikidanych, dzięki czemu strona wczytuje się szybciej.

Moduł oferuje jedną funkcję, Nagłówek, która przyjmuje tylko jeden argument nazwany: strona. Należy w nim przekazać nazwę artykułu, którego dotyczy zgłoszenie.
function redText(t)
	return '<span style="color:red">' .. t .. '</span>'
end

function wikidataRow(entity)
	-- etykieta, opis, jest to
	local label = entity:getLabel() or redText('BRAK ETYTKIETY')
	local description = entity:getDescription() or redText('BRAK OPISU')
	local instanceOf = entity:formatStatements('P31')
	if instanceOf == nil then
		instanceOf = redText('BRAK P31')
	else
		instanceOf = instanceOf['value']
	end
	
	-- aliasy
	local aliasesList = (entity['aliases'] or {})['pl'] or {}
	local aliases = {}
	for i, aliasEntry in pairs(aliasesList) do
		table.insert(aliases, aliasEntry['value'])
	end
	if #aliases == 0 then
		table.insert(aliases, "''brak''")
	end
	
	return '| style="text-align:center;" | [[Plik:Wikidata-logo-v3.png|30px|link=]]' ..
		'\n| colspan="5" class="hlist hwrap" |' ..
		'\n; etykieta: ' .. label ..
		'\n; opis: ' .. description ..
		'\n; aliasy: ' .. table.concat(aliases, ', ') ..
		'\n; jest to: ' .. instanceOf
end

return {
	['Nagłówek'] = function(frame)
		local articleTitle = frame.args['strona']
		if articleTitle == nil then
			return '|-\n! colspan="6" | ' .. redText('Nie podano tytułu artykułu')
		end
		
		local anchor = frame:callParserFunction('anchorencode', articleTitle)
		local anchorTemplate = frame:expandTemplate{title = 'anchor', args = { anchor }}
		
		local output = {
			'|-\n! colspan="6" | ' .. anchorTemplate .. '[[' .. articleTitle .. ']] ('
		}
		
		local pageName = mw.title.getCurrentTitle().text
		if string.find(pageName, '/ekspozycje/') == nil then
			-- ukryj link do dyskusji artykułu na stronie /ekspozycje
			table.insert(output, '[[Dyskusja:' .. articleTitle .. '|dyskusja]], ')
		end
		
		local qid = mw.wikibase.getEntityIdForTitle(articleTitle)
		if qid ~= nil then
			-- pokaż link do elementu Wikidanych
			table.insert(output, '[[d:' .. qid .. '|' .. qid .. ']])')
			table.insert(output, '\n|- class="ll-script ll-script-dl-hlist"\n')
			
			local entity = mw.wikibase.getEntity(qid)
			table.insert(output, wikidataRow(entity))
		else
			table.insert(output, redText('BRAK WD') .. ')')
		end
		
		return table.concat(output, '')
	end,
}