Module:WikiProject banner and Module:WikiProject banner/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
m fix |
Undid revision 1284991949 by Tule-hog (talk) - using /sandbox1 so i don't pollute history |
||
Line 1: | Line 1: | ||
require('strict') |
require('strict') |
||
local p = {} |
local p = {} |
||
local sandbox |
local sandbox = '/sandbox' -- BE SURE TO COMMENT OUT this definition when deploying to live |
||
local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or '')) |
local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or '')) |
||
local auxiliary = cfg.auxiliary_module .. (sandbox or '') |
local auxiliary = cfg.auxiliary_module .. (sandbox or '') |
||
Line 45: | Line 45: | ||
return fallback or target |
return fallback or target |
||
end |
end |
||
end |
|||
-- Checks for invalid parameter usage in redirect pages. |
|||
local function check_for_invalid_parameters_in_redirects(args) |
|||
if type(args) ~= "table" then |
|||
return "" |
|||
end |
|||
local invalid_parameters = { |
|||
attention = true, |
|||
["map-needed"] = true, |
|||
["needs-image"] = true, |
|||
["needs-infobox"] = true, |
|||
["needs-photo"] = true, |
|||
} |
|||
for key in pairs(args) do |
|||
if invalid_parameters[key] then |
|||
return "[[Category:Pages using WikiProject banners with invalid parameters]]" |
|||
end |
|||
end |
|||
return "" |
|||
end |
|||
-- Checks for invalid usage of parameters. |
|||
local function check_for_invalid_parameters(args) |
|||
if type(args) ~= "table" then |
|||
return "" |
|||
end |
|||
-- A list of valid values for parameters and their values. |
|||
local valid_parameters = { |
|||
["attention"] = true, |
|||
["category"] = false, |
|||
["importance"] = "importance", -- the taskforce-importance parameters should also be passed through this. |
|||
["map-needed"] = true, |
|||
["needs-image"] = true, |
|||
["needs-infobox"] = true, |
|||
["needs-photo"] = true, |
|||
} |
|||
-- Convert valid values into a lookup table. |
|||
local valid_values = { |
|||
[true] = { yes = true, y = true }, |
|||
[false] = { no = true, n = true }, |
|||
["importance"] = { low = true, mid = true, high = true }, |
|||
} |
|||
-- Function to check if a value is valid (case insensitive). |
|||
local function is_valid_value(value, expected_value) |
|||
-- Ensure value is a string |
|||
if type(value) ~= "string" then |
|||
return false |
|||
end |
|||
return valid_values[expected_value][string.lower(value)] == true |
|||
end |
|||
for key, expected_value in pairs(valid_parameters) do |
|||
local arg_value = args[key] |
|||
if arg_value and not is_valid_value(arg_value, expected_value) then |
|||
return "[[Category:Pages using WikiProject banners with invalid parameters]]" |
|||
end |
|||
end |
|||
-- Check for dynamically named "x-importance" parameters. |
|||
for key, value in pairs(args) do |
|||
if key:match(".*%-importance$") then -- Match anything ending in "-importance" |
|||
if not is_valid_value(value, "importance") then |
|||
return "[[Category:Pages using WikiProject banners with invalid parameters]]" |
|||
end |
|||
end |
|||
end |
|||
return "" |
|||
end |
end |
||
Line 325: | Line 400: | ||
local check_fallbacks = function(class, category) |
local check_fallbacks = function(class, category) |
||
if article then -- no fallbacks for articles |
if article then -- no fallbacks for articles |
||
return class |
|||
elseif args.QUALITY_CRITERIA=='custom' then -- no fallbacks for projects with custom quality scales |
|||
return class |
return class |
||
else -- check fallbacks for non-article classes |
else -- check fallbacks for non-article classes |