Ir al contenido

Módulo:Proofreadpage index template/pruebas

De Wikisource, la biblioteca libre.
Documentación del módulo

Esta página pretende facilitar las pruebas de Módulo:Proofreadpage index template mediante Módulo:Proofreadpage index template/pruebas y los siguientes ejemplos:


Índice con 1 autor y un traductor, ambos de Wikidata:

Autor Johann David Wyss Modificar el valor en Wikidata
Traductor M. Leal y Madrigal Modificar el valor en Wikidata
Título El Robinson suizo Modificar el valor en Wikidata
Año 1864 Modificar el valor en Wikidata
Lugar Barcelona Modificar el valor en Wikidata
Editorial Sociedad Editorial La Maravilla y Librería Española Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q107297266
Progreso Corregido — Todas las páginas corregidas pero no todas validadas
Ayuda
Páginas (Nivel)
Páginas

Índice con 2 ilustradores:

Autor Julio Verne Modificar el valor en Wikidata
Título Cristóbal Colón
Subtítulo 1436-1506 Modificar el valor en Wikidata
Año 1884 Modificar el valor en Wikidata
Lugar París Modificar el valor en Wikidata
Ilustrador Léon Benett y Charles-Émile Mathis Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q111109568
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con 3 autores:

Autor Teócrito, Bión de Esmirna y Mosco de Siracusa Modificar el valor en Wikidata
Traductor Ignacio Montes de Oca y Obregón Modificar el valor en Wikidata
Prologuista Marcelino Menéndez y Pelayo, Miguel Antonio Caro y Ignacio Montes de Oca y Obregón Modificar el valor en Wikidata
Título Poetas bucólicos griegos Modificar el valor en Wikidata
Año 1880 Modificar el valor en Wikidata
Lugar Madrid Modificar el valor en Wikidata
Editorial Imprenta Central a cargo de Víctor Saiz Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q109782702
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice sin autores:

Título Anales de la Sociedad Científica Argentina
Volumen 30 Modificar el valor en Wikidata
Año 1890 Modificar el valor en Wikidata
Editorial Sociedad Científica Argentina Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q124994898
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con autor anónimo:

Autor Anónimo Modificar el valor en Wikidata
Traductor Antonio Zinny Modificar el valor en Wikidata
Título Invasiones Inglesas
Subtítulo Proceso instruido al Teniente General Don Juan Whitelocke Modificar el valor en Wikidata
Año 1913 Modificar el valor en Wikidata
Lugar Buenos Aires Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q66227023
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con P2093 (nombre del autor):

Autor Congreso General Constituyente
Título Constitución de las Provincias Unidas en Sudamérica
Año 1819 Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q120785961
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con ambos P2093 (nombre del autor) y P50 (autor) :

Autor Marcela Peredo, Pedro Harris Moya y Juan Pablo Díaz Fuenzalida Modificar el valor en Wikidata
Título 100 preguntas sobre la Constitución Modificar el valor en Wikidata
Año marzo 2020 Modificar el valor en Wikidata
Editorial Ediciones Universidad Autónoma de Chile Modificar el valor en Wikidata
Fuente Archivo
Metadatos* Q99204030
Progreso Corregido — Todas las páginas corregidas pero no todas validadas
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con autor «valor desconocido» => P5997 «Maristany, Fernando»:

Autor Maristany, Fernando, Guillermo Valencia Castillo, Carmela Eulate Sanjurjo, Teodoro Llorente Olivares, Enrique Díez-Canedo y Victor Hugo Modificar el valor en Wikidata
Título Poesías
Año 1925 Modificar el valor en Wikidata
Editorial Ed Claridad Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q132508417
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Índice con autor «valor desconocido» => P1932 «D. A . A. P. y G.»:

Autor José María Sbarbi y Osuna, D. A . A. P. y G., Ferdinand Denis, Crispin Caramillo y Ramon Alexo de Zidra Modificar el valor en Wikidata
Editor José María Sbarbi y Osuna Modificar el valor en Wikidata
Prologuista José María Sbarbi y Osuna Modificar el valor en Wikidata
Título El Refranero general Español
Subtítulo parte recopilado, y parte compuesto Modificar el valor en Wikidata
Volumen 5 Modificar el valor en Wikidata
Año 1876 Modificar el valor en Wikidata
Lugar Madrid Modificar el valor en Wikidata
Imprenta Imprenta de A. Gómez Fuentenebro Modificar el valor en Wikidata
Editorial Fuentenebro Modificar el valor en Wikidata
Fuente Archivo
Metadatos Q133506696
Progreso Por corregir
Ayuda
Páginas (Nivel)
tabla_de_páginas

Uso

Ver y añadir ejemplos en la página Módulo:Proofreadpage index template/ejemplos.
Esta documentación está transcluida desde Módulo:Proofreadpage index template/pruebas/doc.
Por favor, añade las categorías a la subpágina de documentación.
(subpáginas - enlaces)

--------------------------------------------------------------------------------
-- Adaptado de https://en.wikisource.org/wiki/Module:Proofreadpage_index_template
--           y https://ca.wikisource.org/wiki/Module:Proofreadpage_index_template
-- This is a module to implement logic for [[MediaWiki:Proofreadpage index template]]
--------------------------------------------------------------------------------
-- Ejemplo (función p.fields):
-- {{#invoke:Proofreadpage index template|fields|NomPag=El Robinson suizo (1864).pdf|NomPagE=El_Robinson_suizo_(1864).pdf|Paginas=tabla|Wikidata=Q107297266}}
--------------------------------------------------------------------------------

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

local p = {} --p stands for package

-- mapping of field ID to field properties
local headings = {
	
	title		=	{	txt = 'Título', 'P1476'},
	subtitle	=	{	txt = 'Subtítulo', 'P1680'},
	serie		=	{	txt = 'Serie o colección', ''},
	volum		=	{ 	txt = 'Volumen', 'P478'},
	
	author		=	{	txt = 'Autor [[Archivo:Commons-emblem-notice.svg|20px|enlace=|alt=|frameless|link=Ayuda:Autores]]',	'P50'},
	editor		=	{	txt = 'Editor',	'P98'},
	illustrator =	{	txt = 'Ilustrador', 'P110'},
	translator	=	{	txt = 'Traductor',	'P655'},
	introducer  =   {   txt = 'Prologuista', 'P2679'},
	
	year		=	{	txt = 'Año', 'P577'},
	editorial	=	{	txt = 'Editorial', 'P123'},
	printer 	=	{	txt = 'Imprenta', 'P872'},
	place		=	{	txt = 'Lugar', 'P291'},
	country		=	{	txt = 'País', ''},	--derechos (P495) pasar a Wikidata realmente?
	
	source		=	{	txt = 'Fuente',	''},
	modernizar	=	{	txt = 'Modernización de la ortografía',	''},
	quality 	=	{	txt = 'Progreso', ''},
	wikidata	=	{	txt = 'Metadatos', ''},
	
	cadena_autor=   {'P2093'},
}

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_image(content, nompage, qid, nompag)
	if nompage == nil or nompage == '' then error('nompage no puede ser nulo') end
	local s = ''

	--Miramos si en WD hay 1 o más P996, capturamos el que coincida, y le miramos el P4714 (nº pág. con título).
	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']
				--decode: nompag podría venir con "'" en lugar de "'" (apóstrofe)
				if mw.text.decode(nompag) == commonsFilename then
					P4714 = Wikidata.claim{item=qid, property="P996", qualifier="P4714", lang="es", list=false}
				end
			end
		end
	end	

	s = s .. '<tr><td valign="top">'
	if content then
	else
		if P4714 == '' then
			content = '1'	--si no hay nada de nada
		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 .. '</td>'
	s = s .. '<td valign="top"><table style="margin-left:0">'	--se cierran en construct_field_paginas
	return s
end

local function construct_field_paginas(content, nompage)

	if nompage == nil or nompage == '' then return "Error en construct_field_pagines (nompage)" end
	if content == nil or content == '' then return "Error en construct_field_pagines (content)" end
	local s = ''
	s = s .. '</table></td></tr>'
	s = s .. '<tr><td valign="top" colspan="2"><span class="plainlinks">'
	s = s .. '<b>[//es.wikisource.org/wiki/File:' .. nompage .. '?action=purge Páginas]</b></span>'
	s = s .. ' ([[Ayuda:Nivel_de_las_páginas|Nivel]])\n'
	s = s .. '<div style="padding-left:0.5em; background-color:#F0F0F0;">\n' .. content .. '</div></td></tr>'
	s = s .. '</table></td>'
	return s
end

local function construct_field_sumario(content)
	local s = ''
	if content then
		s = '<td width="33%" valign="top">' .. content .. '</td>'
	end
	return s
end
--------------------------------------------------------------------------------
-- Get an Item based on what's passed in the 'wikidata' or 'page' parameters of
-- the args, or the current page's ID otherwise.
local function getItem( args )
	local id = nil
	if type( args ) == 'string' and args ~= '' then
		id = args
	end
	return mw.wikibase.getEntity( id )
end
--------------------------------------------------------------------------------
-- Exported method. Get wikitext for displaying an edition's badges from Wikidata.
-- Adaptado de https://ca.wikisource.org/wiki/Module:Edition
local function badge( args )
	local item = getItem( args )	--por defecto, id de la página
	if args.qid ~= nil then			--pero si pasamos un qid, id pasado
		item = mw.wikibase.getEntity(args.qid)
	end
	if not ( item and item.sitelinks and item.sitelinks.eswikisource and item.sitelinks.eswikisource.badges ) then
		return ''
	end
	local badges = item.sitelinks.eswikisource.badges
	local out = ''
	for _, badge in pairs( badges ) do
		local badgeOut = ''
		local badgeItem = mw.wikibase.getEntity( badge )
		local wikisourceBadgeClass = 'Q75042035'
		if badgeItem.claims.P31[1].mainsnak.datavalue.value.id == wikisourceBadgeClass and badgeItem.claims.P18 ~= nil then
			if badge ~= nil then
				badgeOut = badgeOut .. badge --Q20748091 (no corr.), Q20748092 (corr.), Q20748093 (val.), Q20748094 (err.)
			end
			out = out .. badgeOut
		end
	end
	return mw.getCurrentFrame():preprocess( out )
end

local function wdws(args)
	--básicos
	local id = args.id
	local qid = args.qid
	local WS = args.content
	--variables
	local list = args.list or false
	local fmt = args.formatting or ''

	local siWDsiWS = false
	local noWDsiWS = false
	local siWDnoWS = false
	
	local P = headings[id][1]
	if not P or P == '' then return WS, false, false, false end
	
	if qid then
		local WD = Wikidata.claim{item=qid, property=P, lang="es", list=list, formatting=fmt}
		if WD then
			if WS then
				siWDsiWS = true
			else
				siWDnoWS = true
				WS = WD
			end
		end
		if not WD and WS then noWDsiWS = true end
	end
	
	return WS, siWDsiWS, noWDsiWS, siWDnoWS
end
-- construct a basic "field" row
local function construct_field(id, content, qid, nompag)
	
	if id == nil then error( "Error en construct_field" ) end
	if not qid then	qid = '' end
	local CatError = "[[Categoría:Índices con discrepancias respecto a Wikidata"	
	local contentAux = content
	local siWDsiWS = false	--hay contenido en WD y en WS (se puede borrar)
	local noWDsiWS = false	--no hay contenido en WD pero sí en WS (no borrar hasta migrarlo a WD)
	local caterror = false  --campo generó error
	
	-- casos generales
	---- list = true: admite valores múltiples
	if id == 'translator' or id =='illustrator' or id == 'editor' or id == 'introducer' or id == 'editorial' or id == 'printer' then
		content, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid, list=true}
	end
	
	---- formatting = label: enlaza sólo cuando corresponda
	if  id == 'place' or id == 'country' then
		content, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid, formatting='label'}
	end
	
	---- formato para fecha
	if id == 'year' then
		content, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid, formatting=" j xg Y"}
	end
	
	---- resto de casos
	if id == 'subtitle' or id == 'volum' then
		content, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid}
	end
	
	-- casos especiales
	if id == 'author' then
		content, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid, list=true}
		if content == 'valor desconocido' then
			content = '[[:Categoría:Obras de autores anónimos|Anónimo]]'
		end
		local cadena_autor, _, _, _ = wdws{id='cadena_autor', content=false, qid=qid, list=true}
		if content and cadena_autor then
			content = content .. ', ' .. cadena_autor
		elseif not content and cadena_autor then
			content = cadena_autor
		end
		
	end
	
	if id == 'title' then
		wTitulo, siWDsiWS, noWDsiWS, siWDnoWS = wdws{id=id, content=content, qid=qid}
		siWDnoWS = false
		if not content then
			local wSiteLink = mw.wikibase.getSitelink(qid)
			if wSiteLink then
				siWDnoWS = true
				if wTitulo then
					content = "''[[" .. wSiteLink .. "|" .. wTitulo .. "]]''"
				else
					content = "''[[" .. wSiteLink .. "]]''"
				end
			elseif wTitulo then
				content = "''[["..wTitulo.."]]''"	
			end
		end
	end
	

	if id == 'serie' then
	end

	if id == 'modernizar' then
		if content then
			if content == 'S' then
				content = '[[Wikisource:Modernización de textos|Ortografía antigua — El lector puede elegir modernizar la ortografía]]'
			else
				content = 'No modernizar'
			end
		end
	end

	if id == 'source' then
		if content == nil then
			if nompag == nil then
				content = content .. CatError .. "|Nompag]]"
				caterror = 'ERROR: Nompag'
			else	--todo: se podría buscar los identificadores de Wikidata P675 (GB), P724 (IA), etc.
				content = "[[:File:" .. nompag .. "|Archivo]]"
			end
		else
			-- revisar: en general la fuente la explicitamos localmente con una plantilla
			-- tenemos que trackear si está en Wikidata? cual propiedad?
			-- noWDsiWS = true
		end
	end

	if id == 'wikidata' then
		if nompag == nil then
			return CatError .. "|Pagename]]"	
		end
		if content == nil then
			return "[[Categoría:Índices no conectados a 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]]"
			caterror = 'ERROR: QID NO EXISTE'
		end
		if #mw.wikibase.getBestStatements(qid,'P996') == 0 then
			local wTitulo = mw.title.getCurrentTitle()	--Nombre sin "Índice:"
			if wTitulo.text then
				local wArchivo = mw.title.new( wTitulo.text, 'File' )
				if wArchivo.exists then
					--Archivo no está en Commons pero sí localmente en Wikisource (casos excepcionales)
				else
					--No hay archivo local ni P996: hay que añadirlo (archivo en Commons) al ítem en Wikidata.
					content = content .. CatError .. "|Commons]]"
					caterror = 'ERROR: SIN P996 (archivo en Commons)'
				end
    		else
				content = content .. CatError .. "|Error]]"
				caterror = 'ERROR: SIN TEXTO EN ÍNDICE'
			end
		else
			local FileMatch = ''
			local FileOnCommonsStmts = mw.wikibase.getAllStatements (qid, 'P996');
			for _, stmt in pairs( FileOnCommonsStmts ) do
				local commonsFilename = stmt['mainsnak']['datavalue']['value']
				if mw.text.decode(nompag) == mw.text.decode(commonsFilename) then	--decode por si apóstrofe llega como "&#39;"
					FileMatch = commonsFilename
				end
			end
			if FileMatch == '' then
				content = content .. CatError .. "|Fichero]]"
				caterror = 'ERROR: P996 REFIERE OTRO FICHERO'
			end
		end
	end	
	
	if id == 'quality' then

		if qid then
			local badges = badge(qid)
			if badges then
				-- revisar: lo mismo que en source, necesidad de trackear?
				-- if content then siWDsiWS = true end
				content = "C"
				if badges == "Q20748091" then content = "C" end
				if badges == "Q20748092" then content = "V" end
				if badges == "Q20748093" then content = "T" end
				if badges == "Q20748094" then content = "L" end
			else
				--if content then noWDsiWS = true end
			end
			if contentAux then --tiene preferecia lo informado a mano
				content = contentAux
			end	
		end

		if content == nil then
			content = "[[Categoría:Índices no corregidos]][[:Categoría:Índices no corregidos|Por corregir]]"
		elseif content == 'C' then
			content = "[[Categoría:Índices no corregidos]][[:Categoría:Índices no corregidos|Por corregir]]"
		elseif content == 'P' then
			content = "[[Categoría:Índices sin pagelist]][[:Categoría:Índices sin pagelist|Por corregir - pendiente crear <nowiki><pagelist/></nowiki>]]"
		elseif content == 'V' then
			content = "[[Categoría:Índices corregidos]][[:Categoría:Índices corregidos|Corregido — Todas las páginas corregidas pero no todas validadas]]"
		elseif content == 'T' then
			content = "[[Categoría:Índices validados]][[:Categoría:Índices validados|Terminado — Todas las páginas validadas]]"
		elseif content == 'L' then
			content = "[[Categoría:Índices dañados]][[:Categoría:Índices dañados|Archivo fuente debe ser arreglado antes de corregirlo]]"
		else
			content = "[[Categoría:Índices no corregidos]][[:Categoría:Índices no corregidos|Por corregir]]"
		end
	end	
	
	if content == nil or content == '' then
		return ''
	end
	
	local title = get_heading( id )
	if siWDnoWS == true then
		local lapiz = ' <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("es"):plain(), '{{WBREPONAME}}', 'Wikidata')
		if id == 'title' then
			content = content .. lapiz	.. "|link=https://www.wikidata.org/wiki/" .. qid .. "?uselang=es#sitelinks-wikisource]]</span>"
		else
			local P = headings[id][1]
			if P and P ~= '' then
				content = content .. lapiz .. "|link=https://www.wikidata.org/wiki/" .. qid .. "?uselang=es#" .. P .. "]]</span>"
			end
		end
	end
	if siWDsiWS == true then
		content = content .. "[[Categoría:Índices con datos en Wikidata]]"
		title = title .. "<span style='color:red; font-size:75%;' title='Datos en Wikidata'>*</span>"
	end
	if noWDsiWS == true then
		content = content .. "[[Categoría:índices con datos para Wikidata]]"
		title = title .. "<span style='color:green; font-size:75%;' title='Datos para Wikidata'>*</span>"
	end
	if caterror and caterror ~= '' then
		title = title .. "<span style='color:red; font-size:75%;' title='"..caterror.."'>*</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 width="100%"><tr><td valign="top"><table>'
	s = s .. construct_image(args['Imagen'], args['NomPagE'], args['Wikidata'], args['NomPag'])

	-- Tras la imagen, intentamos mostrar una fila por campo (si no hay contenido, no aparece)
	s = s .. construct_field('author', args['Autor'], args['Wikidata'])
	s = s .. construct_field('translator', args['Traductor'], args['Wikidata'])
	s = s .. construct_field('editor', args['Editor'], args['Wikidata'])
	s = s .. construct_field('introducer', args['Prologuista'], args['Wikidata'])
	s = s .. construct_field('title', args['Titulo'], args['Wikidata'])
	s = s .. construct_field('subtitle', args['Subtitulo'], args['Wikidata'])
	s = s .. construct_field('volum', args['Volumen'], args['Wikidata'])
	s = s .. construct_field('year', args['Ano'], args['Wikidata'])
	s = s .. construct_field('place', args['Lugar'], args['Wikidata'])
	s = s .. construct_field('country', args['derechos'], args['Wikidata'])
	s = s .. construct_field('printer', args['Imprenta'], args['Wikidata'])
	s = s .. construct_field('editorial', args['Editorial'], args['Wikidata'])
	s = s .. construct_field('illustrator', args['Ilustrador'], args['Wikidata'])
	s = s .. construct_field('source', args['Fuente'], args['Wikidata'], args['NomPag'])
	s = s .. construct_field('serie', args['Serie'], args['Wikidata'])	--a mano
	s = s .. construct_field('modernizar', args['Modernizacion'], args['Wikidata'])	--a mano
	s = s .. construct_field('wikidata', args['Wikidata'], args['Wikidata'], args['NomPag'])
	s = s .. construct_field('quality', args['Progreso'], args['Wikidata'])
	s = s .. '<tr><td colspan="2">[[Archivo:Commons-emblem-notice.svg|20px|enlace=|alt=|frameless]] [[Ayuda:Índices|Ayuda]]</td></tr>'
	s = s .. construct_field_paginas(args['Paginas'], args['NomPagE'])
	s = s .. construct_field_sumario(args['Notas'])
	s = s .. '</tr></table>'
	return s
	
end

return p