Module:Vital article: Difference between revisions

Content deleted Content added
No edit summary
no cat class
 
(47 intermediate revisions by 4 users not shown)
Line 1:
local p = {}
 
-- Copy from [[Module:Section link]]
local function normalizeTitle(title)
title = mw.ustring.gsub(mw.ustring.gsub(title, "'", ""), '"', '')
title = mw.ustring.gsub(title, "%b<>", "")
return mw.title.new(title).prefixedText
end
 
local getLink = function(page)
Line 8 ⟶ 15:
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)[page]
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
local trimmed_link = data.trimmed_link
if (level=='4' or level=='5') and data.topic then
local link
link = link .. '/' .. data.topic
if trimmed_link then
end
link = 'Wikipedia:Vital articles' .. trimmed_link
if data.sublist then
else
link = 'Wikipedia:Vitallink articles/Level.. '/' .. leveldata.sublist
end
if (level=='4' or level=='5') and data.topic then
if data.section then
link = link .. '/' .. data.topic
link = link .. '#' .. data.section
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
Line 37 ⟶ 39:
local link, level = getLink(page)
return '[[' .. page .. ']]' .. (link and '&nbsp;[[File:Círculos Concéntricos.svg|11px]]&nbsp;[[' .. link .. '|' .. 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{title = 'Possibly empty category'})
.. frame:expandTemplate{title = 'Wikipedia category', args = {container = container}}
.. frame:expandTemplate{title = 'CatAutoTOC'}
Line 46 ⟶ 54:
 
p.header = function(frame)
local catpargs = frame:getParent().args
local cat = pargs.category~='' and frame.argspargs.category or mw.title.getCurrentTitle().subjectPageTitle.text
local topic, class, level
local class, topic = cat:match('^([%a-]+) vital articles in ([%a ]+)$')
topic = cat:match('^Vital articles in ([%a ]+) by quality$')
if class and topic then
if topic then -- Category:Vital articles in TOPIC by quality
class = class:match('(%a+)-Class') or 'Unassessed'
return top(true, frame)
.. '[[Category:Wikipedia vital articles in ' .. topic .. '|Quality]]'
.. '[[Category:Vital articles by topic by quality|' .. (topic=='an unknown topic' and 'Unknown' or 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:Vital articles by quality 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=='an unknown topic' and 'Unknown' or 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('^([%a-]+) vital articles by level$')
if class then -- Category:CLASS vital articles by level
return top(true, frame)
.. '[[Category:' .. class .. ' vital articles|Level]]'
.. '[[Category:Vital articles by quality by level|' .. class .. ']]'
end
level = cat:match('^Level%-(%w+) vital articles by quality$')
if level then -- Category:Level-LEVEL vital articles by quality
return top(true, frame)
.. '[[Category:Wikipedia level-' .. level .. ' vital articles|Quality]]'
.. '[[Category:Vital articles by level by quality|' .. level .. ']]'
end
topic = cat:match('^Wikipedia vital articles in ([%a ]+)$')
if topic then -- Category:Wikipedia vital articles in TOPIC
return top(false, frame)
.. '[[Category:Wikipedia vital articles inby topic|' .. (topic=='an ..unknown topic' byand class|'Unknown' ..or classtopic) .. ']]'
.. '[[Category:' .. class .. (class=='Unassessed' and '' or '-Class') .. ' vital articles by topic|' .. (topic=='an unknown topic' and 'Unknown' or topic) .. ']]'
end
topiclevel = cat:match('^Wikipedia vital articles in level%-([%a ]w+) byvital classarticles$')
if level then -- Category:Wikipedia level-LEVEL vital articles
if topic then
return top(true, frame)
.. '[[Category:Wikipedia vital articles inby level|' .. topiclevel .. '|Class]]'
.. '[[Category:Wikipedia vital articles by topic by class|' .. topic .. ']]'
end
class, level = cat:match('^([%a%-]+) level%-(%w+) vital articles by topic$')
if class and level then -- Category:CLASS level-LEVEL vital articles
return top(false, frame)
class = class:match('(%a+)-Class') or 'Unassessed'
.. '[[Category:' .. class .. ' vital articles by level|' .. level .. ']]'
.. '[[Category:Level-' .. string.lower(level) .. ' vital articles by quality|' ..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)
end
.. '[[Category:' .. class .. (class=='Unassessed' and '' or '-Class') .. '-Class vital articles|Topic]]'
.. level, topic = cat:match('[[Category:^Wikipedia level%-(%w+) vital articles byin class([%a by topic|' .. class .. ']]+)$')
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=='an unknown topic' and 'Unknown' or 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:Vital articles in ' .. topic .. ' by quality|' .. class .. ']]'
.. '[[Category:' .. class .. ' vital articles by topic|' .. (topic=='an unknown topic' and 'Unknown' or topic) .. ']]'
end
end