Jump to content

Module:Vital article/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Kammerer55 (talk | contribs) at 07:37, 9 December 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local getLink = function(page)
	local subpage = mw.ustring.upper(mw.ustring.sub(page, 1, 1)) -- get first letter of article name
	local codepoint = mw.ustring.codepoint(page, 1, 1)
	if codepoint<65 or codepoint>90 then --first letter is not between A-Z
		subpage = 'others'
	end
	local data_page = 'Wikipedia:Vital articles/data/' .. subpage .. '.json'
	local data = mw.loadJsonData(data_page)[page]
	if data then
		local level = tostring(data.level)
		if level then
			local trimmed_link = data.trimmed_link
			local link
			if trimmed_link then
				link = 'Wikipedia:Vital articles' .. trimmed_link
			else
				link = 'Wikipedia:Vital articles/Level/' .. level
				if (level=='4' or level=='5') and data.topic then
					link = link .. '/' .. data.topic
				end
				if data.sublist then
					link = link .. '/' .. data.sublist
				end
				--if data.section then -- not used until we have stable section anchors to link to
				--	link = link .. '#' .. data.section
				--end
			end
			return link, level
		end
	end
end

p.getLink = getLink

local getLevel = function(page)
	local result = getLink(page)
	return result and result[2] or nil
end

p.link = function(frame)
	local page = frame.args.page~='' and frame.args.page or mw.title.getCurrentTitle().subjectPageTitle.text
	local link, level = getLink(page)
	return '[[' .. page .. ']]' .. (link and '&nbsp;[[File:Círculos Concéntricos.svg|11px]]&nbsp;[[' .. link .. '|' .. level .. ']]' or '')
end

return p