Add modules using `require("strict")` to Category:Strict mode modules
starcitizen>Alistair3149 (Use `pcall` to invoke `getRequireList` from `p._main` to avoid breaking {{Documentation}} when the module page doesn’t yet exist) |
starcitizen>Alistair3149 (Add modules using `require("strict")` to Category:Strict mode modules) |
||
| Рядок 16: | Рядок 16: | ||
local builtins = { | local builtins = { | ||
-- ["libraryUtil"] = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#libraryUtil", | --[[ | ||
["strict"] = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#strict", | ["libraryUtil"] = { | ||
link = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#libraryUtil", | |||
categories = {}, | |||
} | |||
]] | |||
["strict"] = { | |||
link = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#strict", | |||
categories = { "Strict mode modules" }, | |||
}, | |||
}; | }; | ||
| Рядок 70: | Рядок 78: | ||
local builtin = builtins[name]; | local builtin = builtins[name]; | ||
if builtin then | if builtin then | ||
return builtin .. "|" .. name; | return builtin.link .. "|" .. name, builtin; | ||
end | end | ||
end | end | ||
| Рядок 136: | Рядок 144: | ||
---@param moduleName string | ---@param moduleName string | ||
---@param searchForUsedTemplates boolean | ---@param searchForUsedTemplates boolean | ||
---@return string[], string[], string[] | ---@return string[], string[], string[], string[] | ||
local function getRequireList( moduleName, searchForUsedTemplates ) | local function getRequireList( moduleName, searchForUsedTemplates ) | ||
local content = mw.title.new( moduleName ):getContent() | local content = mw.title.new( moduleName ):getContent() | ||
| Рядок 144: | Рядок 152: | ||
local dynamicRequirelist = arr{} | local dynamicRequirelist = arr{} | ||
local dynamicLoadDataList = arr{} | local dynamicLoadDataList = arr{} | ||
local extraCategories = arr{} | |||
assert( content ~= nil, string.format( '%s does not exist', moduleName ) ) | assert( content ~= nil, string.format( '%s does not exist', moduleName ) ) | ||
| Рядок 158: | Рядок 167: | ||
end | end | ||
elseif match ~= '' then | elseif match ~= '' then | ||
match = formatModuleName( match, true ) | local builtin; | ||
match, builtin = formatModuleName( match, true ) | |||
table.insert( requireList, match ) | table.insert( requireList, match ) | ||
if builtin then | |||
local builtinCategories = builtin.categories; | |||
if type(builtinCategories) == "table" then | |||
for _, x in ipairs(builtinCategories) do | |||
table.insert(extraCategories, x); | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
| Рядок 248: | Рядок 267: | ||
loadDataList = loadDataList:unique() | loadDataList = loadDataList:unique() | ||
usedTemplateList = usedTemplateList:unique() | usedTemplateList = usedTemplateList:unique() | ||
extraCategories = extraCategories:unique() | |||
table.sort( requireList ) | table.sort( requireList ) | ||
table.sort( loadDataList ) | table.sort( loadDataList ) | ||
table.sort( usedTemplateList ) | table.sort( usedTemplateList ) | ||
table.sort( extraCategories ) | |||
return requireList, loadDataList, usedTemplateList | return requireList, loadDataList, usedTemplateList, extraCategories | ||
end | end | ||
| Рядок 672: | Рядок 693: | ||
} ) | } ) | ||
local requireList, loadDataList, usedTemplateList; | local requireList, loadDataList, usedTemplateList, extraCategories; | ||
do | do | ||
local ok; | local ok; | ||
ok, requireList, loadDataList, usedTemplateList = pcall(getRequireList, currentPageName, true); | ok, requireList, loadDataList, usedTemplateList, extraCategories = pcall(getRequireList, currentPageName, true); | ||
if not ok then | if not ok then | ||
return userError(requireList); | return userError(requireList); | ||
| Рядок 713: | Рядок 734: | ||
table.insert( res, formatRequiredByList( currentPageName, addCategories, whatModulesLinkHere ) ) | table.insert( res, formatRequiredByList( currentPageName, addCategories, whatModulesLinkHere ) ) | ||
table.insert( res, formatTemplateStylesList( currentPageName, addCategories, templateStylesList ) ) | table.insert( res, formatTemplateStylesList( currentPageName, addCategories, templateStylesList ) ) | ||
if addCategories then | |||
extraCategories = arr.map(extraCategories, function(categoryName) | |||
return "[[Category:" .. categoryName .. "]]"; | |||
end); | |||
table.insert(res, table.concat(extraCategories)); | |||
end | |||
if not moduleIsUsed then | if not moduleIsUsed then | ||