Module:DependencyList: Difference between revisions

No edit summary
No edit summary
Line 27: Line 27:
         end
         end
     end
     end
end
---@param str string
---@return string
local function formatModuleName( str )
    return (str:gsub( '^([\'\"])(.-)%1$', function(_, x) return x end ) -- Only remove quotes at start and end of string if both are the same type
    :gsub( '_', ' ' )
    :gsub( '^.', string.upper )
    :gsub( ':(.)', function(x) return ':'..x:upper() end ))
end
end


Line 39: Line 48:
     query = table.concat( query )
     query = table.concat( query )
     query = query:gsub( '^[Mm]odule:', '' )
     query = query:gsub( '^[Mm]odule:', '' )
    if query:find( '^[Ee]xchange/' ) or query:find( '^[Dd]ata/' ) then
        return { 'Module:' .. query }  -- This format will later be used by formatDynamicQueryLink()
    end


     if dynamicRequireListQueryCache[ query ] then
     if dynamicRequireListQueryCache[ query ] then
Line 99: Line 112:
             end
             end
         elseif match ~= '' then
         elseif match ~= '' then
             match = match:gsub( '[\"\']', '' ):gsub( '_', ' ' )
             match = formatModuleName( match )


             if match == 'libraryUtil' then
             if match == 'LibraryUtil' then
                 match = 'Module:LibraryUtil'
                 match = 'Module:LibraryUtil'
             end
             end
Line 118: Line 131:
             end
             end
         elseif match ~= '' then
         elseif match ~= '' then
             match = match:gsub( '[\"\']', '' ):gsub( '_', ' ' )
             match = formatModuleName( match )
             table.insert( loadDataList, match )
             table.insert( loadDataList, match )
         end
         end
Line 162: Line 175:
                     if name:find( ':' ) then
                     if name:find( ':' ) then
                         local ns = name:match( '^(.-):' )
                         local ns = name:match( '^(.-):' )
                         if enum.contains( {'', 'template', 'user'}, ns:lower() ) then
                         if enum.contains( {'', 'template', 'calculator', 'user'}, ns:lower() ) then
                             table.insert( usedTemplateList, name )
                             table.insert( usedTemplateList, name )
                         elseif ns == ns:upper() then
                         elseif ns == ns:upper() then
Line 191: Line 204:


     return requireList, loadDataList, usedTemplateList
     return requireList, loadDataList, usedTemplateList
end
--- Makes the first letter of the input string upper case
---@param str string
---@return string
local function ucfirst( str )
    return str:gsub( '^.', function(c) return c:upper() end )
end
end


Line 210: Line 216:


     for moduleName, funcName in string.gmatch( content, '{{[{|safeubt:}]-#[Ii]nvoke:([^|]+)|([^}|]+)[^}]*}}' ) do
     for moduleName, funcName in string.gmatch( content, '{{[{|safeubt:}]-#[Ii]nvoke:([^|]+)|([^}|]+)[^}]*}}' ) do
        moduleName = ucfirst( moduleName )
         moduleName = string.format( 'Module:%s', moduleName )
         moduleName = string.format( 'Module:%s', moduleName )
         moduleName = moduleName:gsub( '_', ' ' )
         moduleName = formatModuleName( moduleName )
         table.insert( invokeList, {moduleName=moduleName, funcName=funcName} )
         table.insert( invokeList, {moduleName=moduleName, funcName=funcName} )
     end
     end
Line 312: Line 317:
local function formatInvokedByList( moduleName, addCategories, whatLinksHere )
local function formatInvokedByList( moduleName, addCategories, whatLinksHere )
     local templateData = enum.map( whatLinksHere, function(x) return {templateName=x, invokeList=getInvokeCallList(x)} end )
     local templateData = enum.map( whatLinksHere, function(x) return {templateName=x, invokeList=getInvokeCallList(x)} end )
     templateData = enum.filter( templateData, function(x) return enum.any( x.invokeList, function(y) return y.moduleName==moduleName end ) end )
     templateData = enum.filter( templateData, function(x)
        return enum.any( x.invokeList, function(y)
            return y.moduleName:lower() == moduleName:lower()
        end )
    end )


     local invokedByList = {}
     local invokedByList = {}
Line 361: Line 370:


     local requiredByList = enum.map( childModuleData, function ( item )
     local requiredByList = enum.map( childModuleData, function ( item )
         if enum.any( item.requireList, function(x) return x==moduleName end ) then
         if enum.any( item.requireList, function(x) return x:lower()==moduleName:lower() end ) then
             if item.name:find( '%%' ) then
             if item.name:find( '%%' ) then
                 return formatDynamicQueryLink( item.name )
                 return formatDynamicQueryLink( item.name )
Line 371: Line 380:


     local loadedByList = enum.map( childModuleData, function ( item )
     local loadedByList = enum.map( childModuleData, function ( item )
         if enum.any( item.loadDataList, function(x) return x==moduleName end ) then
         if enum.any( item.loadDataList, function(x) return x:lower()==moduleName:lower() end ) then
             if item.name:find( '%%' ) then
             if item.name:find( '%%' ) then
                 return formatDynamicQueryLink( item.name )
                 return formatDynamicQueryLink( item.name )
Line 498: Line 507:
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()


    -- Leave early if not in module, template or calculator namespace or if module is part of exchange, sandbox or data groups
     if param.is_empty( currentPageName ) and (
     if param.is_empty( currentPageName ) and (
    ( title.nsText ~= 'Module' and title.nsText ~= 'Template') or
        ( not enum.contains( {'Module', 'Template', 'Calculator'}, title.nsText ) ) or
    ( title.text:find( '^Sandbox/' ) ) ) then
        ( title.nsText == 'Module' and ( enum.contains( {'Exchange', 'Exchange historical', 'Sandbox', 'Data'}, title.text:match( '^(.-)/' ) ) ) )
    ) then
         return ''
         return ''
     end
     end
Line 506: Line 517:
     currentPageName = param.default_to( currentPageName, title.fullText )
     currentPageName = param.default_to( currentPageName, title.fullText )
     currentPageName = string.gsub( currentPageName, '/[Dd]oc$', '' )
     currentPageName = string.gsub( currentPageName, '/[Dd]oc$', '' )
     currentPageName = string.gsub( currentPageName, '_', ' ' )
     currentPageName = formatModuleName( currentPageName )
    currentPageName = ucfirst( currentPageName:gsub( ':(.)', function(c) return ':'..c:upper() end ) )
     addCategories = yn( param.default_to( addCategories, title.subpageText~='doc' ) )
     addCategories = yn( param.default_to( addCategories, title.subpageText~='doc' ) )
     moduleIsUsed = yn( param.default_to( isUsed, false ) )
     moduleIsUsed = yn( param.default_to( isUsed, false ) )


     if currentPageName:find( '^Template:' ) then
     if currentPageName:find( '^Template:' ) or currentPageName:find( '^Calculator:' ) then
         local invokeList = getInvokeCallList( currentPageName )
         local invokeList = getInvokeCallList( currentPageName )
         return formatInvokeCallList( currentPageName, addCategories, invokeList )
         return formatInvokeCallList( currentPageName, addCategories, invokeList )
Line 517: Line 527:


     local whatTemplatesLinkHere, whatModulesLinkHere = dpl.ask( {
     local whatTemplatesLinkHere, whatModulesLinkHere = dpl.ask( {
         namespace = 'Template',
         namespace = 'Template|Calculator',
         linksto = currentPageName,
         linksto = currentPageName,
         distinct = 'strict',
         distinct = 'strict',
Line 527: Line 537:
         namespace = 'Module',
         namespace = 'Module',
         linksto = currentPageName,
         linksto = currentPageName,
         nottitlematch = '%/doc|%sandbox%|' .. currentPageName:gsub( 'Module:', '' ),
         nottitlematch = '%/doc|%sandbox%|Exchange/%|Exchange historical/%|Data/%|' .. currentPageName:gsub( 'Module:', '' ),
         distinct = 'strict',
         distinct = 'strict',
         ignorecase = true,
         ignorecase = true,