Vés al contingut

Mòdul:Proofreadpage index template/proves

De Viquitexts

Aquesta pàgina preten facilitar les proves de Mòdul:Proofreadpage index template mitjançant un seguit d'exemples:


{{#invoke:Proofreadpage index template/proves|fields|NomPag=Mar y cel (1903).djvu|NomPagE=Mar_y_cel_(1903).djvu|Pàgines=proves|Qid=Q19533394}}

Autor Àngel Guimerà i Jorge Modifica el valor a Wikidata
Títol Mar y cel Modifica el valor a Wikidata
Subtítol Tragedia en tres actes y en vers Modifica el valor a Wikidata
Impressor Impremta La Renaixensa Modifica el valor a Wikidata
Lloc d'edició Barcelona Modifica el valor a Wikidata
Data d'edició 1903 Modifica el valor a Wikidata
Edició 5 Modifica el valor a Wikidata
Digitalització Fitxer
Wikidata Q19533394
Nivell Llibre validat
Pàgines
proves

Impremta «referit com a» «Estampa de'n Felip Guasp»:
{{#invoke:Proofreadpage index template/proves|fields|NomPag=Pastorells amb alegría d'en Jafet y compañía - Bartomeu Ferrà Perelló (1892).pdf|NomPagE=Pastorells_amb_alegría_d'en_Jafet_y_compañía_-_Bartomeu_Ferrà_Perelló_(1892).pdf|Pàgines=proves|Qid=Q136696243}}

Autor Bartomeu Ferrà i Perelló Modifica el valor a Wikidata
Títol Pastorells amb alegría d'en Jafet y compañía Modifica el valor a Wikidata
Subtítol composts per representar devant lo Sant Misteri de Bethlem Modifica el valor a Wikidata
Impressor Estampa de'n Felip Guasp Modifica el valor a Wikidata
Lloc d'edició Palma Modifica el valor a Wikidata
Data d'edició 1892 Modifica el valor a Wikidata
Digitalització Fitxer
Wikidata Q136696243
Nivell Llibre incomplet
Pàgines
proves

Autor «personalitzat», sense id a Wikidata («Nelo el de Foyos»)
{{#invoke:Proofreadpage index template/proves|fields|NomPag=Colloqui dels Borbons 1868.djvu|NomPagE=Colloqui_dels_Borbons_1868.djvu|Pàgines=proves|Qid=Q122228052}}

Autor Nelo el de Foyos Modifica el valor a Wikidata
Títol El coloqui dels Borbons Modifica el valor a Wikidata
Impressor Imprenta del Avisador Valenciano Modifica el valor a Wikidata
Data d'edició 1868 Modifica el valor a Wikidata
Digitalització Fitxer
Wikidata Q122228052
Nivell Llibre incomplet
Pàgines
proves

Sense Wikidata
{{#invoke:Proofreadpage index template/proves|fields|NomPag=Biblioteca d'autors grecs i llatins (1910).djvu|NomPagE=Biblioteca_d'autors_grecs_i_llatins_(1910).djvu|Pàgines=proves|Títol=''[[Himne a Afrodita (Antoni Rubió i Lluch)|Himne a Afrodita]], [[Teseu]], [[Eros fugitiu]], [[Olímpica I]]''|Autor=[[Safo de Lesbos]], [[Baquílides]], [[Moscos de Siracusa]], [[Píndar]]||Imatge=5}}

Autor Safo de Lesbos, Baquílides, Moscos de Siracusa, Píndar
Títol Himne a Afrodita, Teseu, Eros fugitiu, Olímpica I
Digitalització Fitxer
Nivell Per defecte Llibre incomplet
Pàgines
proves

--------------------------------------------------------------------------------
-- Adaptat de https://en.wikisource.org/wiki/Module:Proofreadpage_index_template
-- This is a module to implement logic for [[MediaWiki:Proofreadpage index template]]
--------------------------------------------------------------------------------

local Wikidata = require('Module:Wikidata/proves')
local getArgs = require('Module:Arguments').getArgs

local p = {} --p stands for package

-- mapping of field ID to field properties
local headings = {
	author =		{	txt = 'Autor', 'P50'	},
	compositor =	{   txt = 'Compositor', 'P86'},
	year =			{	txt = 'Data d\'edició',	'P577'},
	source =		{	txt = 'Digitalització',	''},
	edition =		{	txt = 'Edició', 'P393'	},
	editor =		{	txt = 'Editor', 'P123'	},
	epilogue =		{   txt = 'Epíleg', 'P2680'	},
	illustrator =	{   txt = 'Il·lustrador','P110'},
	printer =		{	txt = 'Impressor','P872'},
	place = 		{	txt = 'Lloc d\'edició','P291'},
	quality =		{	txt = 'Nivell', ''		},
	parts = 		{   txt = 'Parts', 'P527'	},
	prologue =		{   txt = 'Pròleg', '2679'	},
	subtitle =		{	txt = 'Subtítol', 'P1680'},
	title = 		{	txt = 'Títol', 'P1476'	},
	translator =	{	txt = 'Traductor', 'P655'},
	volum = 		{   txt = 'Volum', 'P478'	},
	wikidata =		{	txt = 'Wikidata', ''	}
}

local function get_heading(id)
	if headings[id] then
		return headings[id]['txt']
	end
	error( "Can't find heading for ID: " .. id )
end

local function construct_imatge(content, sumari, nompage, qid, nompag)
	if nompage == nil or nompage == '' then error('nompage no pot ser nul') end
	local s = ''

	--Mirem si a WD hi ha 1 o més P996, agafem el que coincideixi, i li mirem el P4714 (nº pàg. amb títol).
	local P4714 = ''
	if qid then
		local FileOnCommonsStmts = mw.wikibase.getAllStatements (qid, 'P996');
		if FileOnCommonsStmts then
			for _, stmt in pairs( FileOnCommonsStmts ) do
				local commonsFilename = stmt['mainsnak']['datavalue']['value']
				--Cal decodificar nompag, per exemple, per l'apòstrof "'" arriba com "'"
				if mw.text.decode(nompag) == commonsFilename then
					P4714 = Wikidata.claim{item=qid, property="P996", qualifier="P4714", lang="ca", list=false, editicon=false}
				end
			end
		end
	end	

	s = s .. '<td><div style="float:left;">'
	if content then
	else
		if P4714 == '' then
			content = '1'	--si no hi ha res de res
		else
			content = P4714
		end
		if content == nil then content = '1' end
	end
	if tonumber(content) == nil then
		s = s .. content
	else
		s = s .. '<span id="ws-cover" style="display:none; speak:none;">'
		s = s .. nompage .. "/" .. content .. "</span>"
		s = s .. '[[File:' .. nompage .. '|page=' .. content .. '|frameless]]'
	end
	s = s .. '</div></td>\n'

	if sumari == nil then
		s = s .. '<td>'
	else
		s = s .. '<td width="45%">'
	end
	s = s .. '<table>' --es tanca a construct_field_pagines
	return s
end

local function construct_field_pagines(content, nompage)

	if nompage == nil or nompage == '' then return "Error nompage a construct_field_pagines" end
	if content == nil or content == '' then return "Error content a construct_field_pagines" end
	local s = ''
	s = s .. '\n<td valign="top"><span class="plainlinks">'
	s = s .. '<b>[//ca.wikisource.org/wiki/Index:' .. nompage .. '?action=purge Pàgines]</b></span></td>\n'
	s = s .. '<td valign="top" align="left" bgcolor="#F0F0F0">\n'
	s = s .. '<div style="padding-left:0.5em">\n' .. content .. '</div>'
	s = s .. '</td>'
	s = s .. '</table>'
	return s
end

local function construct_field_sumari(content)
	local s = ''
	if content then
		s = '<td width="45%">' .. content .. '</td>'
	end
	return s
end

-- construct a basic "field" row
local function construct_field(id, content, qid, nompag)

	if id == nil then error( "Error a construct_field" ) end

	local CatError = "[[Categoria:Llibres amb discrepàncies respecte a Wikidata"	
	local contentAux = content
	local noVT = false	--hi ha contingut a WD i a VT (cal esborrar-lo)
	local noWD = false	--hi ha contingut a VT però no a WD (cal moure'l i esborrar-lo)
	local nomesWD = false	--hi ha contingut només a WD però no a VT

	if id == 'author' then
		if qid then
			local AutorP50 = Wikidata.claim{item=qid, property="P50", lang="ca", list=true, editicon=false}
			if AutorP50 then
				if AutorP50 == 'valor desconegut' then AutorP50 = '[[Autor:Anònim|Anònim]]' end
				if content then
					noVT = true
				else
					content = AutorP50
					nomesWD = true
				end
			else
				if content then
					noVT = true
				else
					AutorP50 = Wikidata.claim{item=qid, property="P2093", lang="ca", list=true, editicon=false}	-- p.ex. Q122228052
					if AutorP50 then
						content = AutorP50
						nomesWD = true
					end
				end
			end
			if not AutorP50 and content then noWD = true end
		end
	end

	if id == 'translator' then
		if qid then
			local wTraductor = Wikidata.claim{item=qid, property="P655", lang="ca", list=true, editicon=false}
			if wTraductor then
				if content then
					noVT = true
				else
					content = wTraductor
					nomesWD = true
				end
			end
			if not wTraductor and content then noWD = true end
		end
	end

	if id == 'title' then
		if qid then
			local wSiteLink = Wikidata.getSiteLink{item=qid}
			local wTitol = Wikidata.claim{item=qid, property="P1476", lang="ca", list=false, editicon=false}					
			if wSiteLink then
				if content then
					noVT = true
				else
					nomesWD = true
					if wTitol then
						content = "''[[" .. wSiteLink .. "|" .. wTitol .. "]]''"
					else
						content = "''[[" .. wSiteLink .. "]]''"
					end	
				end
			else	
				if content then
					noWD = true
				else
					if wTitol then
						content = "''[[" .. wTitol .. "]]''"
						nomesWD = true
					end
				end	
			end
		end
	end
	
	if id == 'subtitle' then	--No vé per paràmetre
		if qid then
			local wSubtitol = Wikidata.claim{item=qid, property="P1680", lang="ca", list=false, editicon=false}
			if wSubtitol then
				content = "''" .. wSubtitol .. "''"
				nomesWD = true
			else content = '' end
		end
	end
	
	if id == 'volum' then	--No vé per paràmetre
		if qid then
			local wVolum = Wikidata.claim{item=qid, property="P478", lang="ca", list=true, editicon=false}
			if wVolum then
				content = wVolum
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'parts' then	--No vé per paràmetre
		if qid then
			local wParts = Wikidata.claim{item=qid, property="P527", lang="ca", list=true, editicon=false}
			if wParts then
				content = wParts
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'prologue' then	--No vé per paràmetre
		if qid then
			local wProleg = Wikidata.claim{item=qid, property="P2679", lang="ca", list=true, editicon=false}
			if wProleg then
				content = wProleg
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'epilogue' then	--No vé per paràmetre
		if qid then
			local wEpileg = Wikidata.claim{item=qid, property="P2680", lang="ca", list=true, editicon=false}
			if wEpileg then
				content = wEpileg
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'illustrator' then
		if qid then
			local wIlustrator = Wikidata.claim{item=qid, property="P110", lang="ca", list=true, editicon=false}
			if wIlustrator then
				if content then
					noVT = true
				else
					content = wIlustrator
					nomesWD = true
				end
			end
			if not wIlustrator and content then noWD = true end
		end
	end

	if id == 'compositor' then	--No vé per paràmetre
		if qid then
			local wCompositor = Wikidata.claim{item=qid, property="P86", lang="ca", list=true, editicon=false}
			if wCompositor then
				content = wCompositor
				nomesWD = true
			else content = '' end
		end
	end
	
	if id == 'editor' then
		if qid then
			local wPublisher = Wikidata.claim{item=qid, property="P123", lang="ca", list=true, editicon=false, formatting='label'}
			if wPublisher then
				if content then
					noVT = true
				else
					content = wPublisher
					nomesWD = true
				end
			end
			if not wPublisher and content then noWD = true end
		end
	end

	if id == 'printer' then	--No vé per paràmetre
		if qid then
			local wImpressor = Wikidata.claim{item=qid, property="P872", lang="ca", list=false, editicon=false, formatting='label'}
			if wImpressor then
				content = wImpressor
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'place' then
		if qid then
			local wPlace = Wikidata.claim{item=qid, property="P291", lang="ca", list=false, editicon=false, formatting='label'}
			if wPlace then
				if content then
					noVT = true
					content = content .. "[[Categoria:Llibres editats a " .. contentAux .. "]]"
				else
					local LlistaLlocs = Wikidata.claim{item=qid, property="P291", lang="ca", list=true, editicon=false, formatting='label'}
					content = LlistaLlocs .. "[[Categoria:Llibres editats a " .. wPlace .. "]]"	--només categ. 1er
					nomesWD = true
				end
			end
			if not wPlace and content then noWD = true end
		else	
			if content then
				content = content .. "[[Categoria:Llibres editats a " .. contentAux .. "]]"
			end	
		end
	end

	if id == 'year' then
		if qid then
			local wData = Wikidata.claim{item=qid, property="P577", lang="ca", list=false, editicon=false, formatting=" j xg Y"}
			if wData then
				if content then
					noVT = true
				else
					content = wData
					nomesWD = true
				end
			end
			if not wData and content then noWD = true end
		end
	end

	if id == 'edition' then	--No vé per paràmetre
		if qid then
			local wEdicio = Wikidata.claim{item=qid, property="P393", lang="ca", list=false, editicon=false, formatting='label'}
			if wEdicio then
				content = wEdicio
				nomesWD = true
			else content = '' end
		end
	end

	if id == 'source' then
		if content == nil then
			if nompag == nil then
				content = content .. CatError .. "|Nompag]]"
			else
				content = "[[:File:" .. nompag .. "|Fitxer]]"
			end
		else
			noWD = true
		end
	end

	if id == 'wikidata' then
		if nompag == nil then
			return CatError .. "|Pagename]]"	
		end
		if content == nil then
			return "[[Categoria:Llibres no connectats amb Wikidata]]"
		end
		content = "[[File:Wikidata-logo.svg|20px|link=d:" .. contentAux .. "]] [[d:" .. contentAux .. "|" .. contentAux .. "]]"

		if mw.wikibase.entityExists(qid) == false then
			content = content .. CatError .. "|Qid]]"	
		end
		if Wikidata.validProperty{"P996", item=qid} == nil then
			local wTitol = mw.title.getCurrentTitle()	--Nom sense "Llibre:"
			if wTitol.text then
				local wFitxer = mw.title.new( wTitol.text, 'File' )
				if wFitxer.exists then
					--Fitxer no està a Commons però és localment a Viquitexts (casos excepcionals)
				else	
					--No hi fitxer local ni P996: cal afegir-la (fitxer a Commons) a l'ítem (a Wikidata)
					content = content .. CatError .. "|Commons]]"	
				end
    		else
				content = content .. CatError .. "|Error]]"
			end
		else
			local FileMatch = ''
			local FileOnCommonsStmts = mw.wikibase.getAllStatements (qid, 'P996');
			for _, stmt in pairs( FileOnCommonsStmts ) do
				local commonsFilename = stmt['mainsnak']['datavalue']['value']
				--Cal decodificar nompag, per exemple, per l'apòstrof "'" arriba com "&#39;"
				if mw.text.decode(nompag) == commonsFilename then
					FileMatch = commonsFilename
				end
			end
			if FileMatch == '' then
				content = content .. CatError .. "|Fitxer]]"
			end
		end
	end	
	
	if id == 'quality' then

		if qid then
			local badges = require("Module:Edition").badge{args={qid=qid}}
			if badges then
				if content then noVT = true end
				content = "I"
				if badges == "Q20748093" then content = "V" end
				if badges == "Q20748092" then content = "R" end
				if badges == "Q20748091" then content = "I" end
				if badges == "Q20748094" then content = "E" end
			else
				if content then noWD = true end
			end
			if contentAux then --de moment, té preferència allò posat a mà
				content = contentAux
			end	
		end

		if content == nil then
			content = "Per defecte&nbsp;[[Categoria:Llibres no revisats]][[:Categoria:Llibres no revisats|Llibre incomplet]]"
		elseif content == 'I' then
			content = "[[Categoria:Llibres no revisats]][[:Categoria:Llibres no revisats|Llibre incomplet]]"
		elseif content == 'R' then
			content = "[[Categoria:Llibres revisats]][[:Categoria:Llibres revisats|Llibre amb pàgines pendents de validar]]"
		elseif content == 'V' then
			content = "[[Categoria:Llibres validats]][[:Categoria:Llibres validats|Llibre validat]]"
		elseif content == 'E' then
			content = "[[Categoria:Llibres amb errors]][[:Categoria:Llibres amb errors|Llibre amb errors]]"
		else
			content = "Per defecte&nbsp;[[Categoria:Llibres no revisats]][[:Categoria:Llibres no revisats|Llibre incomplet]]"
		end
	end	
	
	if content == nil or content == '' then
		return ''
	end

	local title = get_heading( id )
	if nomesWD then
		local llapis = ' <span class="penicon" data-bridge-edit-flow="single-best-value">'
				.. "[[File:Arbcom ru editing.svg|10px|baseline|"
				.. string.gsub(mw.message.new('Wikibase-client-data-bridge-bailout-suggestion-go-to-repo-button'):inLanguage("ca"):plain(), '{{WBREPONAME}}', 'Wikidata')
		if id == 'title' then
			content = content .. llapis	.. "|link=https://www.wikidata.org/wiki/" .. qid .. "?uselang=ca#sitelinks-wikisource]]</span>"
		else
			local P = headings[id][1]
			if P and P ~= '' then
				content = content .. llapis .. "|link=https://www.wikidata.org/wiki/" .. qid .. "?uselang=ca#" .. P .. "]]</span>"
			end
		end
	end
	if noVT == true then
		content = content .. "[[Categoria:Llibres amb dades a Wikidata]]"
		title = title .. "<span style='color:red; font-size:75%;'>*</span>"
	end
	if noWD == true then
		content = content .. "[[Categoria:Llibres amb dades per a Wikidata]]"
		title = title .. "<span style='color:green; font-size:75%;'>*</span>"
	end
	
	local s = ''
	s = s .. '\n<tr>'
	s = s .. '<th valign="top" align="left"><b>' .. title .. '</b></th>\n'
	s = s .. '<td>' .. content .. '</td>\n'
	s = s .. '</tr>\n'

	return s
end

function p.fields(frame)
	
	local args = getArgs(frame)

	local s = ""

	s = s .. '<table><tr valign="top">'
	s = s .. construct_imatge(args['Imatge'], args['Sumari'], args['NomPagE'], args['Qid'], args['NomPag'])
	s = s .. construct_field('author', args['Autor'], args['Qid'])
	s = s .. construct_field('translator', args['Traductor'], args['Qid'])
	s = s .. construct_field('title', args['Títol'], args['Qid'])
	s = s .. construct_field('subtitle', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('volum', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('parts', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('prologue', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('epilogue', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('illustrator', args['Il·lustrador'], args['Qid'])
	s = s .. construct_field('compositor', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('editor', args['Editor'], args['Qid'])
	s = s .. construct_field('printer', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('place', args['Lloc'], args['Qid'])
	s = s .. construct_field('year', args['Any'], args['Qid'])
	s = s .. construct_field('edition', args['Qid'], args['Qid'])	--sense arg.
	s = s .. construct_field('source', args['Font'], args['Qid'], args['NomPag'])
	s = s .. construct_field('wikidata', args['Qid'], args['Qid'], args['NomPag'])
	s = s .. construct_field('quality', args['Nivell'], args['Qid'])
	s = s .. construct_field_pagines(args['Pàgines'], args['NomPagE'])
	s = s .. construct_field_sumari(args['Sumari'])
	s = s .. '</tr></table>'

	return s
	
end

return p