ARBEIT MACHT FREI
Moduł:Capitalize folder
Przejdź do nawigacji
Przejdź do wyszukiwania
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Capitalize folder/opis
-- Normalizes folder capitalization under includes/
-- Only paths starting with "includes/" are processed.
-- Case-insensitive matches are mapped to canonical names.
-- Intended to be called from Template:Capitalize folder
local this = {}
-- canonical mappings (case-insensitive lookup)
local folders = {
----------------------------------------------------------------
-- Special rules (kept at top intentionally)
----------------------------------------------------------------
libs = 'libs',
pagers = 'Pager',
skins = 'Skin',
----------------------------------------------------------------
-- Other folders (alphabetically sorted)
----------------------------------------------------------------
changetags = 'ChangeTags',
commentformatter = 'CommentFormatter',
commentstore = 'CommentStore',
connectionmanager = 'ConnectionManager',
db = 'DB',
dbal = 'DBAL',
dependencystore = 'DependencyStore',
editpage = 'EditPage',
eventrelayer = 'EventRelayer',
externalstore = 'ExternalStore',
filebackend = 'FileBackend',
fileiteration = 'FileIteration',
fileop = 'FileOps',
fileophandle = 'FileOpHandle',
filerepo = 'FileRepo',
formfields = 'FormFields',
fsfile = 'FSFile',
historyblob = 'HistoryBlob',
hookcontainer = 'HookContainer',
htmlform = 'HTMLForm',
jobqueue = 'JobQueue',
lbfactory = 'LBFactory',
loadbalancer = 'LoadBalancer',
loadmonitor = 'LoadMonitor',
lockmanager = 'LockManager',
objectcache = 'ObjectCache',
paramvalidator = 'ParamValidator',
querybuilder = 'QueryBuilder',
recentchanges = 'RecentChanges',
resourceloader = 'ResourceLoader',
resultwrapper = 'ResultWrapper',
revisiondelete = 'RevisionDelete',
revisionlist = 'RevisionList',
searchwidgets = 'SearchWidgets',
sitestats = 'SiteStats',
specialpage = 'SpecialPage',
uuid = 'UUID',
wikimap = 'WikiMap',
}
function this.normalize(frame)
-- template arguments
local args = frame.args or {}
-- parent arguments (safe lookup)
local pargs = {}
if frame.getParent then
local parent = frame:getParent()
if parent and parent.args then
pargs = parent.args
end
end
-- obtain path parameter
local path = args[1] or pargs[1] or ''
path = mw.text.trim(path)
if path == '' then
return ''
end
-- remember whether the path ends with a slash
local hasTrailingSlash = path:sub(-1) == '/'
-- only normalize under includes/
if not path:match('^includes/') then
-- still restore trailing slash (if present)
if hasTrailingSlash and path:sub(-1) ~= '/' then
return path .. '/'
end
return path
end
-- split into components
local parts = {}
for p in path:gmatch('[^/]+') do
table.insert(parts, p)
end
-- normalize each folder after "includes"
for i = 2, #parts do
local lowered = mw.ustring.lower(parts[i])
if folders[lowered] then
parts[i] = folders[lowered]
else
-- not in table → ucfirst
parts[i] = mw.ustring.upper(mw.ustring.sub(parts[i],1,1)) ..
mw.ustring.sub(parts[i],2)
end
end
local normalized = table.concat(parts, '/')
-- restore trailing slash (if present)
if hasTrailingSlash then
normalized = normalized .. '/'
end
return normalized
end
return this