Jump to content

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

From Wikipedia, the free encyclopedia
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.header = function(frame)
p.main = function()
return p.headerForTitle(mw.title.getCurrentTitle())
return p.makeHeader(mw.title.getCurrentTitle())
end
end


p.headerForTitle = function(title)
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
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 gadget = p.belongsToGadget(title)
local repo = gadgets.parse()
local shortName = title.text:gsub('^Gadget%-', '')
if gadget then
for name, config in pairs(repo) do
return 'Part of '..gadget.name..' gadget ' ..
if arr_contains(config.pages, shortName) then
(gadget.isDefault and '<b>enabled by default</b>' or
'used by '..gadget.usage..' users ')
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
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
end
if msg:len() > 0 then

return messageBox.main('fmbox', {
p.belongsToGadget = function(title)
text = msg,
local repo = gadgets.parse()
type = 'notice',
local shortName = title.text:gsub('^Gadget%-', '')
image = '[[File:Template-info.svg]]',
for name, config in pairs(repo) do
style = '',
if arr_contains(config.pages, shortName) then
class = 'code-page-header'
return {
})
name = name,
else
usage = gadgets.get_usage(name),
return ''
isDefault = config.options.default ~= nil
}
end
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