Modulo:Categoria per anno

Il Modulo:Categoria per anno categorizza una pagina in base ad un certo anno ricavabile da una certa proprietà Wikidata come la data di fondazione o creazione (P571).

Uso

local s = require('Modulo:Categoria per anno')._main( {'Software del %d'} )

Parametri

1|cat
Parte della categoria (obbligatoria) come ad esempio Software del %d.
prop
Proprietà Wikidata nel caso non sia la P571 (data di fondazione o creazione (P571)).
value
Valore dell'anno fornito dalla voce invece che da Wikidata come ad esempio 1984 o 28 marzo 1984 ecc.
checkCat
Categoria relativa al {{Controllo Wikidata}} nel caso sia diversa da Data di fondazione o creazione.
checkGenre
Vedi genere nel {{Controllo Wikidata}}.
ns
Vedi ns nel {{Controllo Wikidata}}.
from
Elemento Wikidata come ad esempio Q1431 da cui leggerne la proprietà. Da utilizzare solo se si è consci del contatore delle funzioni dispendiose.
raw
Impostare a true per avere solo il nome della categoria ed evitare il {{Controllo Wikidata}} (utile ad esempio nei test).


Pagine correlate


local p = {}

local DEFAULT_PROP = 'P571'
local DEFAULT_CHECK_CAT = 'Data di fondazione o creazione'
local DEFAULT_CHECK_GENRE = 'fs'

local function err(msg)
	string.format('<span class="error">msg</span>', msg)
end

function p._main(args)
	local s = ''

	args.cat = args[1] or args.cat

	if not args.cat then
		return err('richiesto parametro cat')
	end

	if not args.prop then
		args.prop = DEFAULT_PROP
	end

	local value = require('Modulo:Wikidata')._getProperty( {
		args.prop,
		args.value,
		from = args.from
	} )
	if value then
		local year = mw.ustring.match(value, '%d%d%d%d')
		if year then
			s = s .. string.format(
				args.raw and '%s' or '[[Categoria:%s]]',
				string.format(args.cat, year)
			)
		end
	end

	if not args.raw then
		if DEFAULT_PROP == args.prop and not args.checkCat then
			args.checkCat   = DEFAULT_CHECK_CAT
			args.checkGenre = DEFAULT_CHECK_GENRE
		end
		local check = require('Modulo:Controllo Wikidata')._main( {
			args.prop,
			args.value,
			args.checkCat,
			genere  = args.checkGenre,
			ns = args.ns
		} )
		if check then
			s = s .. check
		end
	end

	return s
end

function p.main(frame)
	local getArgs = require('Modulo:Arguments').getArgs
	return p._main( getArgs(frame) )
end

return p