Modulo:Common

Da Wikisource

La documentazione per questo modulo può essere creata in Modulo:Common/man

local p = {}
local item = mw.wikibase.getEntityObject()
local lang = mw.getContentLanguage()

function p.getProofreadStatus()
	if item and item.sitelinks and item.sitelinks.vecwikisource.badges then
		badge = item.sitelinks.vecwikisource.badges[1]
		if badge then
			if badge == 'Q20748091' then
				return 1
			elseif badge == 'Q20748094' then
				return 2
			elseif badge == 'Q20748092' then
				return 3
			elseif badge == 'Q20748093' then
				return 4
			end
		end
	else
		return nil
	end
end

-- *** FUNZIONI DI UTILITA' PER WIKISOURCE **

--ritorna il namespace corrente
function p.getNamespace() 
	return mw.title.getCurrentTitle().nsText
end

--true se siamo nel ns 0
function p.isNS0() 
	return mw.title.getCurrentTitle().namespace == 0
end

--true se siamo nel ns Autore
function p.isNSAutore() 
	return p.getNamespace() == 'Autor'
end

--true se siamo in una sottopagina
function p.isSubpage() 
	return mw.title.getCurrentTitle().isSubpage
end


-- stampa la tabella (per i log)
function p.printTable(T, depth)
	depth = depth or 0
	local out = ''
	for k, v in pairs(T) do 
		out = out ..'\n' .. string.rep(' ', depth) .. k .. ' = ' .. p.printElement(v, depth)
	end
	return out
end

-- stampa un elemento qualunque
function p.printElement(el, depth)
	depth = depth or 0
	if (type(el) == "table") then return '{'..p.printTable(el, depth+1)..'}'
	else return tostring(el)
	end
end

function p.replace()
	frame = mw.getCurrentFrame()
	str = frame.args[1]
	fnd = frame.args[2]
	res = string.gsub(str, fnd:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1"), "")
	return res
end

return p
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikisource.org/w/index.php?title=Modulo:Common&oldid=68124"