Modulo:Testo

'A Wikisource.

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

local p={}

-- logica:
-- leggere la pagina indicata nel parametro 1
-- risalire alla pagina Indice, se c'è, e leggerla
-- estrarre i dati significativi da entrambe

function p.testo(frame) 
	local result="prova"
	local title=mw.title.getCurrentTitle()
	frame=frame:getParent()
	-- carico i parametri di testo
	--local args=frame_1.args
	local args=frame.args
	if string.sub(args[1],1,1)=="/" then 
		args[1]=title.text..args[1]
	end
	if args[2]==nil then
		args[2]=mw.text.split(args[1],"/")
		args[2]=args[2][#args[2]]
	end
	local dataNs0={}
	local dataIndex={}
	-- catturo titolo e testo della pagina puntata da testo
	dataNs0.title=mw.title.new(args[1])
	dataNs0.text=dataNs0.title:getContent()
	if not dataNs0.text then
		return args[1]
	end
	dataNs0.index=string.match(dataNs0.text,'index="(.-)"')
	-- dataNs0.SAL=string.match(dataNs0.text,"avz=(%d+)")
	-- dataNs0.codeSAL=" [[File:xxx%.svg|9px]]"
	-- dataNs0.codeSAL=string.gsub(dataNs0.codeSAL,"xxx",dataNs0.SAL)
	dataNs0.linkEpub='[[File:EPUB silk icon.svg|12px|link='..'https://tools.wmflabs.org/wsexport/tool/book.php?lang=www&format=epub&page='..mw.uri.encode(args[1], "WIKI" )..']]  '
	-- se esiste riferimento a Indice
	if dataNs0.index ~=nil then
		-- catturo titolo e testo della pagina collegata ed estraggo i dati bbliografici
		dataIndex.indexLink='<span class="ws-noexport">[[File:Crystal_Clear_app_kdict.png|14px|link=Index:'..dataNs0.index..']]</span>&nbsp;&nbsp;'
		dataIndex.title=mw.title.new("Index:"..dataNs0.index)
		dataIndex.text=dataIndex.title:getContent()
		dataIndex.autore=string.match(dataIndex.text,"Author=(.-)\n|")
		dataIndex.editore=string.match(dataIndex.text,"Publisher=(.-)\n|")
		dataIndex.anno=string.match(dataIndex.text,"Year=(.-)\n|")
		dataIndex.luogo=string.match(dataIndex.text,"Address=(.-)\n|")
		dataIndex.traduttore=string.match(dataIndex.text,"Translator=(.-)\n|")
		dataIndex.lingua=string.match(dataIndex.text,"Language=(.-)\n|")
	else
		args.tipo="tradizionale"
	end
	if args.tipo==nil then args.tipo="" end
	result="''[["..args[1].."|"..args[2].."]]'' "-- ..dataNs0.codeSAL
	-- se non + in ns0 oppure è Pagina principale
	if title.namespace~=0 or title.text=="Main Page"  then
		if args.tipo~="tradizionale" then
			if string.find(dataIndex.autore,"%[%[") ~= nil then
				result=result..dataIndex.autore
			else
				result=result..", [[Author:"..dataIndex.autore.."|"..dataIndex.autore.."]]"
			end	
		
			if dataIndex.traduttore~=nil and dataIndex.traduttore~="" then
				result=result..", traduzione di [[Author:"..dataIndex.traduttore.."|"..dataIndex.traduttore.."]]"
			end
			if dataIndex.luogo~=nil and dataIndex.luogo~="" then
				result=result..", "..dataIndex.luogo
			end
			if dataIndex.editore~=nil and dataIndex.editore~="" then
				result=result..", "..dataIndex.editore
			end
			if dataIndex.anno~=nil and dataIndex.anno~="" then
				result=result..", "..dataIndex.anno
			end
			
			-- result=result..", "..dataIndex.luogo..", "..dataIndex.editore..", "..dataIndex.anno
		end
	end
	if (title.namespace~=0 or title.text=="Main page") and dataIndex.indexLink ~= nil then
		result= dataIndex.indexLink..result
	end
	if (title.namespace~=0 or title.text=="Main page")  then
		result= dataNs0.linkEpub..result
	end
	return result
	
end

return p