Jump to content

Module:Vital article

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 10:49, 29 November 2023 (start link function). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

p.link = function(frame)
	local page = frame.args.page or mw.title.getCurrentTitle().subjectPageTitle.text
	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 '[[File:Círculos Concéntricos.svg|16px|link=|alt=]]&nbsp;This <b>[[' .. link .. '|level-' .. level .. ' vital article]]</b> '
		end
	end
end

return p