317
редагувань
starcitizen>Alistair3149 (Fix undeclared `_` variable in `getDynamicRequireList(…)`) |
м (56 ревізій: Template:Infobox_Species from StarCitizenTools) |
||
| (Не показані 10 проміжних версій 2 користувачів) | |||
| Рядок 104: | Рядок 104: | ||
---@return string[] Sequence of strings | ---@return string[] Sequence of strings | ||
local function getDynamicRequireList( query ) | local function getDynamicRequireList( query ) | ||
local isDynamic = true; | |||
if query:find( '%.%.' ) then | if query:find( '%.%.' ) then | ||
query = mw.text.split( query, '..', true ) | query = mw.text.split( query, '..', true ) | ||
| Рядок 111: | Рядок 113: | ||
else | else | ||
local _; _, query = query:match( '(["\'])(.-)%1' ) | local _; _, query = query:match( '(["\'])(.-)%1' ) | ||
query = query:gsub( '%%%a', '%%' ) | |||
if query == nil then | |||
return {}, isDynamic | |||
end | |||
local replacements; | |||
query, replacements = query:gsub( '%%%a', '%%' ) | |||
if replacements == 0 then | |||
isDynamic = false; | |||
end | |||
end | end | ||
query = query:gsub( '^[Mm]odule:', '' ) | query = query:gsub( '^[Mm]odule:', '' ) | ||
if query:find( '^[Dd]ata/' ) then | |||
return { 'Module:' .. query }, isDynamic; -- This format will later be used by formatDynamicQueryLink() | |||
end | |||
if dynamicRequireListQueryCache[ query ] then | if dynamicRequireListQueryCache[ query ] then | ||
return dynamicRequireListQueryCache[ query ] | return dynamicRequireListQueryCache[ query ], isDynamic; | ||
end | end | ||
| Рядок 138: | Рядок 153: | ||
dynamicRequireListQueryCache[ query ] = list | dynamicRequireListQueryCache[ query ] = list | ||
return list | return list, isDynamic; | ||
end | end | ||
| Рядок 214: | Рядок 229: | ||
match = mw.text.trim( match ) | match = mw.text.trim( match ) | ||
if func == 'require' | local dynList, isDynamic; | ||
if func == 'require' then | |||
dynList, isDynamic = getDynamicRequireList(match); | |||
if (isDynamic == false and #dynList == 1) then | |||
table.insert(requireList, dynList[1]); | |||
else for _, x in ipairs(dynList) do | |||
table.insert( dynamicRequirelist, x ) | table.insert( dynamicRequirelist, x ) | ||
end end | |||
elseif func == 'mw.loadData' then | |||
dynList, isDynamic = getDynamicRequireList(match); | |||
if (isDynamic == false and #dynList == 1) then | |||
table.insert(loadDataList, dynList[1]); | |||
else for _, x in ipairs(dynList) do | |||
table.insert( dynamicLoadDataList, x ) | |||
end end | |||
end | end | ||
end | end | ||
| Рядок 298: | Рядок 324: | ||
return invokeList | return invokeList | ||
end | end | ||
| Рядок 331: | Рядок 330: | ||
---@return string | ---@return string | ||
local function messageBoxUnused( pageName, addCategories ) | local function messageBoxUnused( pageName, addCategories ) | ||
local mbox = require( 'Module:Mbox' )._mbox | |||
local category = addCategories and '[[Category:Unused modules]]' or '' | |||
return mbox( | |||
'This module is unused.', | |||
string.format( 'This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add <code>{{[[Template:Documentation|Documentation]]}}</code>/<code>{{[[Template:No documentation|No documentation]]}}</code> to the calling template\'s or parent\'s module documentation.', | |||
pageName | |||
), | |||
{ icon = 'WikimediaUI-Alert.svg' } | |||
) .. category | |||
end | end | ||
| Рядок 603: | Рядок 591: | ||
) | ) | ||
table.insert( res, mHatnote._hatnote( msg, { icon='WikimediaUI-Code.svg' } ) ) | table.insert( res, mHatnote._hatnote( msg, { icon='WikimediaUI-Code.svg' } ) ) | ||
end | end | ||
| Рядок 662: | Рядок 626: | ||
moduleIsUsed = true -- Don't show sandbox modules as unused | moduleIsUsed = true -- Don't show sandbox modules as unused | ||
end | end | ||
if currentPageName:find( '^Template:' ) then | if currentPageName:find( '^Template:' ) then | ||
local ok, invokeList = pcall( getInvokeCallList, currentPageName ) | local ok, invokeList = pcall( getInvokeCallList, currentPageName ) | ||
if ok then | if ok then | ||
return formatInvokeCallList( currentPageName, addCategories, invokeList | return formatInvokeCallList( currentPageName, addCategories, invokeList ) | ||
else | else | ||
return userError(invokeList) | return userError(invokeList) | ||
| Рядок 733: | Рядок 695: | ||
table.insert( res, formatUsedTemplatesList( currentPageName, addCategories, usedTemplateList ) ) | table.insert( res, formatUsedTemplatesList( currentPageName, addCategories, usedTemplateList ) ) | ||
table.insert( res, formatRequiredByList( currentPageName, addCategories, whatModulesLinkHere ) ) | table.insert( res, formatRequiredByList( currentPageName, addCategories, whatModulesLinkHere ) ) | ||
if addCategories then | if addCategories then | ||