Jump to content

Module:User:SD0001/Code page header: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
wip
Redirected page to Module:Script doc auto
Tag: New redirect
 
Line 1: Line 1:
local messageBox = require('Module:Message box')
return require [[Module:Script doc auto]]
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

Latest revision as of 09:27, 28 January 2024

return require [[Module:Script doc auto]]