Module:Vital article/sandbox
Appearance
| This is the module sandbox page for Module:Vital article (diff). See also the companion subpage for test cases (run). |
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.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 ' [[File:Círculos Concéntricos.svg|11px]] [[' .. link .. '|' .. level .. ']]' or '')
end
local top = function(container, frame)
return (container and '' or frame:expandTemplate{title = 'Possibly empty category'})
.. frame:expandTemplate{title = 'Wikipedia category', args = {container = container}}
.. frame:expandTemplate{title = 'CatAutoTOC'}
end
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('^Wikipedia vital articles in ([%a ]+) by class$')
if topic then -- Category:Wikipedia vital articles in TOPIC by class
return top(true, frame)
.. '[[Category:Wikipedia vital articles in ' .. topic .. '|Class]]'
.. '[[Category:Wikipedia vital articles by topic by class|' .. topic .. ']]'
end
class = cat:match('^([%a-]+) vital articles by topic$')
if class then -- Category:CLASS vital articles by topic
return top(true, frame)
.. '[[Category:' .. class .. ' vital articles|Topic]]'
.. '[[Category:Wikipedia vital articles by class by topic|' .. class .. ']]'
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)
.. '[[Category:Wikipedia vital articles in ' .. topic .. '|Level]]'
.. '[[Category:Wikipedia vital articles by topic by level|' .. topic .. ']]'
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)
.. '[[Category:Wikipedia level-' .. level .. ' vital articles|Topic]]'
.. '[[Category:Wikipedia vital articles by level by topic|' .. level .. ']]'
end
class = cat:match('Wikipedia ([%a-]+) vital articles by level')
if class then -- Category:Wikipedia CLASS vital articles by level
return top(true, frame)
.. '[[Category:' .. class .. ' vital articles|Level]]'
.. '[[Category:Wikipedia vital articles by class by level|' .. class .. ']]'
end
level = cat:match('Wikipedia level%-(%w+) vital articles by class')
if level then -- Category:Wikipedia level-LEVEL vital articles by class
return top(true, frame)
.. '[[Category:Wikipedia level-' .. level .. ' vital articles|Class]]'
.. '[[Category:Wikipedia vital articles by level by class|' .. level .. ']]'
end
topic = cat:match('^Wikipedia vital articles in ([%a ]+)$')
if topic then -- Category:Wikipedia vital articles in TOPIC
return top(true, frame)
.. '[[Category:Wikipedia vital articles by topic|' .. (topic=='an unknown topic' and 'Unknown' or topic) .. ']]'
end
level = cat:match('^Wikipedia level%-(%w+) vital articles$')
if level then -- Category:Wikipedia level-LEVEL vital articles
return top(true, frame)
.. '[[Category:Wikipedia vital articles by level|' .. level .. ']]'
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)
.. '[[Category:Wikipedia ' .. class .. ' vital articles by level|' .. level .. ']]'
.. '[[Category:Wikipedia level-' .. string.lower(level) .. ' vital articles by class|' ..class .. ']]'
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{title = 'cat class', args = {topic = 'vital', class = class}}
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)
.. '[[Category:Wikipedia vital articles in ' .. topic .. ' by level|' .. level .. ']]'
.. '[[Category:Wikipedia level-' .. level .. ' vital articles by topic|' .. topic .. ']]'
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)
.. '[[Category:Wikipedia vital articles in ' .. topic .. ' by class|' .. class .. ']]'
.. '[[Category:' .. class .. ' vital articles by topic|' .. (topic=='an unknown topic' and 'Unknown' or topic) .. ']]'
end
end
return p