Module:User:SD0001/Code page header: Difference between revisions
Appearance
Content deleted Content added
←Created page with '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' t...' |
wip |
||
Line 1: | Line 1: | ||
local messageBox = require('Module:Message box') |
|||
local gadgets = require('Module:User:SD0001/Gadgets') |
local gadgets = require('Module:User:SD0001/Gadgets') |
||
Line 12: | Line 13: | ||
local p = {} |
local p = {} |
||
p. |
p.main = function() |
||
return p. |
return p.makeHeader(mw.title.getCurrentTitle()) |
||
end |
end |
||
p. |
p._makeHeader = function(frame) |
||
return p.makeHeader(mw.title.new(require('Module:Arguments').getArgs(frame)[1])) |
|||
⚫ | |||
⚫ | |||
local model = title.contentModel |
local model = title.contentModel |
||
if model ~= 'javascript' and model ~= 'css' and model ~= 'json' then |
if model ~= 'javascript' and model ~= 'css' and model ~= 'json' then |
||
Line 22: | Line 27: | ||
end |
end |
||
local msg = '' |
|||
if title.namespace == 8 and title.text:find('^Gadget-') ~= nil then |
if title.namespace == 8 and title.text:find('^Gadget-') ~= nil then |
||
local |
local repo = gadgets.parse() |
||
⚫ | |||
if gadget then |
|||
⚫ | |||
return 'Part of '..gadget.name..' gadget ' .. |
|||
⚫ | |||
⚫ | |||
msg = msg .. |
|||
'This page is loaded as a part of ' .. |
|||
'[[Special:Gadgets#gadget-'..name..'|'..name..']] gadget ' .. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
elseif title.namespace == 2 then |
|||
-- if model == 'javascript' then |
|||
⚫ | |||
-- elseif model == 'css' then |
|||
-- return 'User css' |
|||
-- elseif model == 'json' then |
|||
-- return 'User json' |
|||
-- end |
|||
end |
end |
||
⚫ | |||
if msg:len() > 0 then |
|||
return messageBox.main('fmbox', { |
|||
⚫ | |||
⚫ | |||
local repo = gadgets.parse() |
|||
type = 'notice', |
|||
⚫ | |||
image = '[[File:Template-info.svg]]', |
|||
⚫ | |||
style = '', |
|||
⚫ | |||
class = 'code-page-header' |
|||
return { |
|||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
⚫ | |||
isDefault = config.options.default ~= nil |
|||
⚫ | |||
⚫ | |||
end |
end |
||
return nil |
|||
end |
end |
||
Revision as of 14:35, 20 January 2024
local messageBox = require('Module:Message box')
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.main = function()
return p.makeHeader(mw.title.getCurrentTitle())
end
p._makeHeader = function(frame)
return p.makeHeader(mw.title.new(require('Module:Arguments').getArgs(frame)[1]))
end
p.makeHeader = function(title)
local model = title.contentModel
if model ~= 'javascript' and model ~= 'css' and model ~= 'json' then
return ''
end
local msg = ''
if title.namespace == 8 and title.text:find('^Gadget-') ~= nil then
local repo = gadgets.parse()
local shortName = title.text:gsub('^Gadget%-', '')
for name, config in pairs(repo) do
if arr_contains(config.pages, shortName) then
msg = msg ..
'This page is loaded as a part of ' ..
'[[Special:Gadgets#gadget-'..name..'|'..name..']] gadget ' ..
(config.options.default ~= nil and '<b>enabled by default</b>' or
'used by '..gadgets.get_usage(name)..' users ') .. '<br>'
end
end
end
if msg:len() > 0 then
return messageBox.main('fmbox', {
text = msg,
type = 'notice',
image = '[[File:Template-info.svg]]',
style = '',
class = 'code-page-header'
})
else
return ''
end
end
return p