Module:Vital article/sandbox explained

local p =

-- Copy from local function normalizeTitle(title) title = mw.ustring.gsub(mw.ustring.gsub(title, "'", ""), '"', ) title = mw.ustring.gsub(title, "%b<>", "") return mw.title.new(title).prefixedTextend

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 page2 = tostring(tonumber(page))

page and tonumber(page) or page --convert to number if page is numerical, otherwise loadJsonData does not work local data = mw.loadJsonData(data_page)[page2] 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 link = link .. '#' .. data.section end return link, level end endend

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 '  ' .. level .. '' or )end

p.isVital = function(frame) local page = frame.args.page~= and frame.args.page or mw.title.getCurrentTitle.subjectPageTitle.text local _, level = getLink(page) return level or end

local top = function(container, frame) return (container and or frame:expandTemplate) .. frame:expandTemplate .. frame:expandTemplateend

p.header = function(frame) local pargs = frame:getParent.args local cat = pargs.category~= and pargs.category or mw.title.getCurrentTitle.subjectPageTitle.text local topic, class, level topic = cat:match('^Vital articles in ([%a ]+) by quality$') if topic then -- Category:Vital articles in TOPIC by quality return top(true, frame) .. '' .. '' end class = cat:match('^([%a-]+) vital articles by topic$') if class then -- Category:CLASS vital articles by topic return top(true, frame) .. '' .. '' end topic = cat:match('^Wikipedia vital articles in ([%a ]+) by level$') if topic then -- Category:Wikipedia vital articles in TOPIC by level return top(true, frame) .. '' .. '' end level = cat:match('^Wikipedia level%-(%w+) vital articles by topic$') if level then -- Category:Wikipedia level-LEVEL vital articles by topic return top(true, frame) .. '' .. '' end class = cat:match('^([%a-]+) vital articles by level$') if class then -- Category:CLASS vital articles by level return top(true, frame) .. '' .. '' end level = cat:match('^Level%-(%w+) vital articles by quality$') if level then -- Category:Level-LEVEL vital articles by quality return top(true, frame) .. '' .. '' end topic = cat:match('^Wikipedia vital articles in ([%a ]+)$') if topic then -- Category:Wikipedia vital articles in TOPIC return top(false, frame) .. '' end level = cat:match('^Wikipedia level%-(%w+) vital articles$') if level then -- Category:Wikipedia level-LEVEL vital articles return top(true, frame) .. '' end class, level = cat:match('^([%a%-]+) level%-(%w+) vital articles$') if class and level then -- Category:CLASS level-LEVEL vital articles return top(false, frame) .. '' .. '' end class = cat:match('^([%a-]+) vital articles$') if class then -- Category:CLASS vital articles class = class:match('(%a+)-Class') or class return top(true, frame) .. frame:expandTemplate end level, topic = cat:match('^Wikipedia level%-(%w+) vital articles in ([%a ]+)$') if level and topic then -- Category:Wikipedia level-LEVEL vital articles in TOPIC return top(false, frame) .. '' .. '' end class, topic = cat:match('^([%a-]+) vital articles in ([%a ]+)$') if class and topic then -- Category:CLASS vital articles in TOPIC return top(false, frame) .. '' .. '' endend

return p