Diferencia entre revisiones de «Módulo:Transcluder»

Contenido eliminado Contenido añadido
Actualizo a la última versión
Actualizo a la última versión
Línea 10:
end
 
-- Helper function to match from a list of regular expressions
-- Like so: match pre..list[1]..post or pre..list[2]..post or ...
local function matchAny(text, pre, list, post, init)
Línea 19:
end
return nil
end
 
-- Like matchAny but for Category/File links with less overhead
local function matchAnyLink(text, list)
local match
for _, v in ipairs(list) do
match = string.match(text, '%[%[%s*' .. v .. '%s*:.*%]%]')
if match then break end
end
return match
end
 
Línea 60 ⟶ 70:
for _, range in pairs(ranges) do
range = mw.text.trim(range)
local min, max = string.match(range, '^(%d+)%s*%[-–—]%s*(%d+)$') -- '3-5' to min=3 max=5
if not max then min, max = string.match(range, '^((%d+))$') end -- '1' to min=1 max=1
if max then
Línea 128 ⟶ 138:
-- @return Local name of the namespace and all aliases, for example {'File','Image','Archivo','Imagen'}
local function getNamespaces(name)
local namespaces = mw.clone(mw.site.namespaces[name].aliases) -- Bugfix: https://en.wikipedia.org/w/index.php?diff=1056921358
table.insert(namespaces, mw.site.namespaces[name].name)
table.insert(namespaces, mw.site.namespaces[name].canonicalName)
Línea 173 ⟶ 183:
local count = 0
for file in string.gmatch(text, '%b[]') do
if matchAnymatchAnyLink(file, '%[%[%s*', fileNamespaces, '%s*:.*%]%]') then
name = string.match(file, '%[%[[^:]-:([^]|]+)')
count = count + 1
Línea 352 ⟶ 362:
local count = 0
for category in string.gmatch(text, '%b[]') do
if matchAnymatchAnyLink(category, '%[%[%s*', categoryNamespaces, '%s*:.*%]%]') then
name = string.match(category, '%[%[[^:]-:([^]|]+)')
count = count + 1
Línea 378 ⟶ 388:
-- doesn't remove citations like <ref name="Foo" /> if Foo is defined elsewhere
if flags and not truthy(flags) then
text = mw.ustringstring.gsub(text, '<%s*[Rr][Ee][Ff][^>/]*>.-<%s*/%s*[Rr][Ee][Ff]%s*>', '')
text = mw.ustringstring.gsub(text, '<%s*[Rr][Ee][Ff][^>/]*/%s*>', '')
return references, text
end
Línea 424 ⟶ 434:
local count = 0
local prefix, section, suffix
for title in string.gmatch('\n' .. text .. '\n==', '\n==+%s*([^=]+)%s*==+\n') do
count = count + 1
prefix, section, suffix = string.match('\n' .. text .. '\n==', '\n()==+%s*' .. escapeString(title) .. '%s*==+(.-)()\n==')
Línea 496 ⟶ 506:
end
end
page = string.gsub(page, '"', '') -- remove any quotation marks from the page title
text = mw.ustring.gsub(text, '<%s*[Rr][Ee][Ff][^>]*name%s*=%s*["\']?([^"\'>/]+)["\']?[^>/]*(/?)%s*>', '<ref name="' .. page .. ' %1"%2>')
text = mw.ustring.gsub(text, '<%s*[Rr][Ee][Ff]%s*group%s*=%s*["\']?[^"\'>/]+["\']%s*>', '<ref>')
Línea 529 ⟶ 540:
local fileDescription
local frame = mw.getCurrentFrame()
for file in mw.ustringstring.gmatch(text, '%b[]') do
if matchAnymatchAnyLink(file, '%[%[%s*', fileNamespaces, '%s*:.*%]%]') then
fileName = 'File:' .. mw.ustringstring.match(file, '%[%[[^:]-:([^]|]+)')
fileDescription, fileName = getText(fileName)
if fileName then
Línea 537 ⟶ 548:
fileDescription = frame:preprocess('{{' .. fileName .. '}}') -- try Commons
end
if fileDescription and mw.ustringstring.match(fileDescription, '[Nn]on%-free') then
text = removeString(text, file)
end