Module:User:SD0001/Code page header
Appearance
local gadgets = require('Module:User:SD0001/Gadgets')
local function arr_contains(array, val)
for _, value in ipairs(array) do
if value == val then
return true
end
end
return false
end
local p = {}
p.header = function(frame)
return p.headerForTitle(mw.title.getCurrentTitle())
end
p.headerForTitle = function(title)
local model = title.contentModel
if model ~= 'javascript' and model ~= 'css' and model ~= 'json' then
return ''
end
if title.namespace == 8 and title.text:find('^Gadget-') ~= nil then
local gadget = p.belongsToGadget(title)
if gadget then
return 'Part of '..gadget.name..' gadget ' ..
(gadget.isDefault and '<b>enabled by default</b>' or
'used by '..gadget.usage..' users ')
end
elseif title.namespace == 2 then
-- if model == 'javascript' then
-- return 'User js'
-- elseif model == 'css' then
-- return 'User css'
-- elseif model == 'json' then
-- return 'User json'
-- end
end
end
p.belongsToGadget = function(title)
local repo = gadgets.parse()
local shortName = title.text:gsub('^Gadget%-', '')
for name, config in pairs(repo) do
if arr_contains(config.pages, shortName) then
return {
name = name,
usage = gadgets.get_usage(name),
isDefault = config.options.default ~= nil
}
end
end
return nil
end
return p