Modul:RedLinkRemover

De la Wikipedia, enciclopedia liberă

Documentația acestui modul poate fi creată la Modul:RedLinkRemover/doc

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local StringUtils = require('Modul:StringUtils')

p.fromString = function(text)
	if not text then return nil end
	local replacedText = mw.ustring.gsub(text, "%[%[([^%]|]*)|?([^%]]*)%]%]", function(...)
		local article = arg[1]
		if StringUtils._startsWithAny({article, "Imagine:", "Fișier:", "File:", "Media:", "Image:"}) then return nil end
		local articleObj = mw.title.new(article)
		if not articleObj.exists then
			return arg[2] and mw.ustring.len(arg[2]) > 0 and arg[2] or arg[1]
		end
	end)
	return replacedText
end

p.fromFrame = function(frame)
	local args = getArgs(frame)
	if not args[1] then return nil end
	local text = args[1]
	return p.fromString(text)
end
	
return p