Module:Vital article

This is an old revision of this page, as edited by Kammerer55 (talk | contribs) at 00:03, 30 November 2023 (it's better to always return the proper link to the article itself (in all exceptional cases), because otherwise it will look very bad when it was used in the previous discussions and then the page gets removed from the vital list). 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 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
			if not mw.title.new(link).exists then -- add tracking category if link does not exist
				link = link .. '[[Category:Wikipedia vital articles with an incorrect link]]'
			end
			return link, level
		end
	end
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|link=|alt=]]&nbsp;[[' .. link .. '|' .. level .. ']]' or '')
end

return p