Viquitexts
cawikisource
https://ca.wikisource.org/wiki/P%C3%A0gina_principal
MediaWiki 1.47.0-wmf.2
first-letter
Media
Especial
Discussió
Usuari
Usuari Discussió
Viquitexts
Viquitexts Discussió
Fitxer
Fitxer Discussió
MediaWiki
MediaWiki Discussió
Plantilla
Plantilla Discussió
Ajuda
Ajuda Discussió
Categoria
Categoria Discussió
Pàgina
Pàgina Discussió
Llibre
Llibre Discussió
Autor
Autor Discussió
TimedText
TimedText talk
Mòdul
Mòdul Discussió
Event
Event talk
MediaWiki:Common.css
8
4922
184384
173711
2026-05-14T20:46:13Z
ABreault (WMF)
11500
For [[phab:T425558|T425558]]
184384
css
text/css
/* Estil prose: justificat i més estret per facilitar la lectura */
.prose p {
}
.prose {
width: 35em;
text-align:justify;
margin:0px auto;
}
/* Indentar inici de paràgraf */
.ns-0 .mw-parser-output > p,
.ns-0 .prp-pages-output > p,
.ns-102 .mw-parser-output > p,
.ns-102 .prp-pages-output > p {
text-indent: 2em;
}
/* T425558 */
.ns-0 .mw-parser-output > section > p,
.ns-0 .prp-pages-output > section > p,
.ns-102 .mw-parser-output > section > p,
.ns-102 .prp-pages-output > section > p {
text-indent: 2em;
}
/* No indentar classe dropinitial de la plantilla:LletraInicial */
.ns-102 .mw-parser-output p:first-of-type,
.ns-0 .mw-parser-output > .dropinitial + p,
.ns-0 .prp-pages-output > .dropinitial + p,
.ns-102 .mw-parser-output > .dropinitial + p,
.ns-102 .prp-pages-output > .dropinitial + p {
text-indent: 0;
}
/* T425558 */
.ns-0 .mw-parser-output > section > .dropinitial + p,
.ns-0 .prp-pages-output > section > .dropinitial + p,
.ns-102 .mw-parser-output > section > .dropinitial + p,
.ns-102 .prp-pages-output > section > .dropinitial + p {
text-indent: 0;
}
/* No indentar dintre de poem */
.poem p {
text-indent: 0;
}
/* Copiat de es.source: evita ús de la Plantilla:AproparVersos */
.poem p {
margin: 0;
}
/* Quality: dóna color al nivell de qualitat (vg. Ajuda:Qualitat de les pàgines) */
.quality4 {
background-color: #90ff90;
color: black;
}
.quality3 {
background-color: #ffe867;
color: black;
}
.quality2 {
background-color: #b0b0ff;
color: black;
}
.quality1 {
background-color: #ffa0a0;
color: black;
}
.quality0 {
background-color: #ddd;
color: black;
}
/* Redireccions en cursiva a Especial:Allpages, llista de seguiment i categories */
.allpagesredirect a, .watchlistredir a, .redirect-in-category {
font-style: italic;
}
/* classe alineanegatif : création d'une indentation négative */
.alineanegatif {
text-indent: -2em;
padding-left:2em;
}
.alineanegatif p{
text-indent: -2em;
}
/*Per a que referències no aumentin espai d'interliniat*/
sup.reference {
font-weight: lighter;
word-spacing: 0em;
font-size: 0.75em;
margin-left:0em;
margin-right:0em;
}
sup.reference a {
color: #777;
}
/*Color rosa als errors detectats per MediaWiki:Gadget-PossiblesErrors.js*/
.Erreurs-communes {
background-color : #FCDFFF;
color: black;
vertical-align : inherit;
}
/*Números de pàgina no quedin semiamagats i no funcionals si mida text massa gran.*/
#text-wrap { margin-left:3em; position:relative; }
/*Visualització de Plantilla:Nota dreta i Plantilla:Nota esquerra al ns Pàgina*/
body.ns-102 .sidenote-left { position:absolute; left:0; width:3em; text-indent:0em; text-align:left;}
body.ns-102 .sidenote-right { position:absolute; right:0; width:3em; text-indent:0em; text-align:left;}
/* Infobox template style */
.infobox {
border: 1px solid #aaa;
background-color: #f9f9f9;
color: black;
margin: 0.5em 0 0.5em 1em;
padding: 0.2em;
float: right;
clear: right;
}
.infobox td,
.infobox th {
vertical-align: top;
}
ac0ddmp2dqc5815psx5b9yzhwwimloq
Mòdul:Wikidata
828
34117
184380
179567
2026-05-14T20:11:11Z
Aleator
20
neteja de codi, -s/ús (getUnit, unitSymbol...)
184380
Scribunto
text/plain
local p = {}
-- Initialization of variables --------------------
local i18n = { -- internationalisation at [[Module:Wikidata/i18n]]
["errors"] = {
["property-not-found"] = "Property not found.",
["qualifier-not-found"] = "Qualifier not found.",
},
["datetime"] = {
-- $1 is a placeholder for the actual number
["beforenow"] = "$1 BCE", -- how to format negative numbers for precisions 0 to 5
["afternow"] = "$1 CE", -- how to format positive numbers for precisions 0 to 5
["bc"] = "$1 BCE", -- how print negative years
["ad"] = "$1", -- how print 1st century AD dates
[0] = "$1 billion years", -- precision: billion years
[1] = "$100 million years", -- precision: hundred million years
[2] = "$10 million years", -- precision: ten million years
[3] = "$1 million years", -- precision: million years
[4] = "$100000 years", -- precision: hundred thousand years; thousand separators added afterwards
[5] = "$10000 years", -- precision: ten thousand years; thousand separators added afterwards
[6] = "$1 millennium", -- precision: millennium
[7] = "$1 century", -- precision: century
[8] = "$1s", -- precision: decade
-- the following use the format of #time parser function
[9] = "Y", -- precision: year,
[10] = "F Y", -- precision: month
[11] = "F j, Y", -- precision: day
["hms"] = {["hours"] = "h", ["minutes"] = "m", ["seconds"] = "s"}, -- duration: xh xm xs
},
["years-old"] = {"", ""}, -- year(s) old, as in {{PLURAL:$1|singular|plural}}
-- two values for most languages, up to six values for some languages
-- see documentation of PLURAL magic word in your language, examples:
-- ["years-old"] = {"singular", "paucal", "plural"} in Russian and other Slavic languages
-- ["years-old"] = {"zero", "one", "two", "few 3-10", "many 11-99", "other 100-102"} in Arabic
["cite"] = { -- cite parameters
["title"] = "title",
["author"] = "author",
["date"] = "date",
["pages"] = "pages",
["language"] = "language",
-- cite web parameters
["url"] = "url",
["website"] = "website",
["access-date"] = "access-date",
["archive-url"] = "archive-url",
["archive-date"] = "archive-date",
["publisher"] = "publisher",
["quote"] = "quote",
-- cite journal parameters
["work"] = "work",
["issue"] = "issue",
["issn"] = "issn",
["doi"] = "doi"
},
-- default local wiki settings
["addpencil"] = false, -- adds a pencil icon linked to Wikidata statement, planned to overwrite by Wikidata Bridge
["categorylabels"] = "", -- Category:Pages with Wikidata labels not translated (void for no local category)
["categoryprop"] = "", -- Category:Pages using Wikidata property $1 (void for no local category)
["categoryref"] = "", -- Category:Pages with references from Wikidata (void for no local category)
["addfallback"] = {} -- additional fallback language codes
}
local cases = {} -- functions for local grammatical cases defined at [[Module:Wikidata/i18n]]
local required = ... -- variadic arguments from require function
local wiki =
{
langcode = mw.language.getContentLanguage().code,
module_title = required or mw.getCurrentFrame():getTitle()
}
local untranslated -- used in infobox modules: nil or true
local _ -- variable for unused returned values, avoiding globals
-- Module local functions --------------------------------------------
-- Credit to http://stackoverflow.com/a/1283608/2644759, cc-by-sa 3.0
local function tableMerge(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
local function loadI18n(lang)
local exist, res = pcall(require, wiki.module_title .. "/i18n")
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
cases = res.cases
end
if lang ~= wiki.langcode then
exist, res = pcall(require, wiki.module_title .. "/i18n/" .. lang)
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
tableMerge(cases, res.cases)
end
end
end
-- Table of language codes: requested or default and its fallbacks
local function findLang(langcode)
if mw.language.isKnownLanguageTag(langcode or '') == false then
local cframe = mw.getCurrentFrame()
local pframe = cframe:getParent()
langcode = pframe and pframe.args.lang
if mw.language.isKnownLanguageTag(langcode or '') == false then
if not mw.title.getCurrentTitle().isContentPage then
langcode = cframe:preprocess('{{int:lang}}')
end
if mw.language.isKnownLanguageTag(langcode or '') == false then
langcode = wiki.langcode
end
end
end
loadI18n(langcode)
local languages = mw.language.getFallbacksFor(langcode)
table.insert(languages, 1, langcode)
if langcode == wiki.langcode then
for _, l in ipairs(i18n.addfallback) do
table.insert(languages, l)
end
end
return languages
end
-- Argument is 'set' when it exists (not nil) or when it is not an empty string.
local function isSet(var)
return not (var == nil or (type(var) == 'string' and mw.text.trim(var) == ''))
end
-- Set local case to a label
local function case(localcase, label, ...)
if not isSet(label) then return label end
if type(localcase) == "function" then
return localcase(label)
elseif localcase == "smallcaps" then
return '<span style="font-variant: small-caps;">' .. label .. '</span>'
elseif cases[localcase] then
return cases[localcase](label, ...)
end
return label
end
-- get safely a serialized snak
local function getSnak(statement, snaks)
local ret = statement
for i, v in ipairs(snaks) do
if not ret then return end
ret = ret[v]
end
return ret
end
-- mw.wikibase.getLabelWithLang or getLabelByLang with a table of languages
local function getLabelByLangs(id, languages)
local label
local lang
for _, l in ipairs(languages) do
if l == wiki.langcode then
-- using getLabelWithLang when possible instead of getLabelByLang
label, l = mw.wikibase.getLabelWithLang(id)
else
label = mw.wikibase.getLabelByLang(id, l)
end
if label then
lang = l
break
end
end
return label, lang
end
-- getBestStatements if bestrank=true, else getAllStatements with no deprecated
local function getStatements(entityId, property, bestrank)
local claims = {}
if not (entityId and mw.ustring.match(property, "^P%d+$")) then return claims end
if bestrank then
claims = mw.wikibase.getBestStatements(entityId, property)
else
local allclaims = mw.wikibase.getAllStatements(entityId, property)
for _, c in ipairs(allclaims) do
if c.rank ~= "deprecated" then
table.insert(claims, c)
end
end
end
return claims
end
-- Is gender femenine? true or false
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
local gender_id = getSnak(claims, {1, "mainsnak", "datavalue", "value", "id"})
if gender_id == "Q6581072" or gender_id == "Q1052281" or gender_id == "Q43445" then -- female, transgender female, female organism
return true
end
return false
end
-- Fetch female form of label
local function feminineForm(id, lang)
local feminine_claims = getStatements(id, 'P2521')
for _, feminine_claim in ipairs(feminine_claims) do
if getSnak(feminine_claim, {'mainsnak', 'datavalue', 'value', 'language'}) == lang then
return feminine_claim.mainsnak.datavalue.value.text
end
end
end
-- Add an icon for no label in requested language
local function addLabelIcon(label_id, lang, uselang, icon)
local ret_lang, ret_icon = '', ''
if icon then
if lang and lang ~= uselang then
ret_lang = " <sup>(" .. lang .. ")</sup>"
end
if label_id and (lang == nil or lang ~= uselang) then
local namespace = ''
if string.sub(label_id, 1, 1) == 'P' then
namespace = 'Property:'
end
ret_icon = " [[File:Noun Project label icon 1116097 cc mirror.svg|10px|baseline|"
.. mw.message.new('Translate-taction-translate'):inLanguage(uselang):plain()
.. "|link=https://www.wikidata.org/wiki/" .. namespace .. label_id .. "?uselang=" .. uselang .. "]]"
untranslated = true
end
if isSet(i18n.categorylabels) and lang ~= uselang and uselang == wiki.langcode then
ret_icon = ret_icon .. '[[' .. i18n.categorylabels .. (lang and ']]' or '/Q]]')
end
end
return ret_lang .. ret_icon
end
-- editicon values: true/false (no=false), right, void defaults to i18n.addpencil
-- labelicon only by parameter
local function setIcons(arg, parg)
local val = arg == nil and parg or arg
local edit_icon, label_icon
if not isSet(val) then
edit_icon, label_icon = i18n.addpencil, true
elseif val == false or val == "false" or val == "no" then
edit_icon, label_icon = false, false
else
edit_icon, label_icon = val, true
end
return edit_icon, label_icon
end
-- Add an icon for editing a statement with requirements for Wikidata Bridge
local function addEditIcon(parameters)
local ret = ''
if parameters.editicon and parameters.id and parameters.property then
local icon_style = parameters.editicon == "right" and ' style="float: right;"' or ''
ret = ' <span class="penicon" data-bridge-edit-flow="single-best-value"' .. icon_style .. '>'
.. "[[File:Arbcom ru editing.svg|10px|baseline|"
.. string.gsub(mw.message.new('Wikibase-client-data-bridge-bailout-suggestion-go-to-repo-button'):inLanguage(parameters.lang[1]):plain(), '{{WBREPONAME}}', 'Wikidata')
.. "|link=https://www.wikidata.org/wiki/" .. parameters.id .. "?uselang=" .. parameters.lang[1] .. "#" .. parameters.property .. "]]"
.. "</span>"
if isSet(i18n.categoryprop) then
ret = ret .. "[[" .. string.gsub(i18n.categoryprop, '$1', parameters.property) .. "]]"
end
end
return ret
end
-- add edit icon to the last element of a table
local function addEditIconTable(thetable, parameters)
if #thetable == 0 or parameters.editicon == false then
return thetable
end
local last_element = thetable[#thetable]
local the_icon = addEditIcon(parameters)
-- add it before last html closing tags
local tags = ''
local rev_element = string.reverse(last_element)
for tag in string.gmatch(rev_element, '(>%l+/<)') do
if string.match(rev_element, '^' .. tags .. tag) then
tags = tags .. tag
else
break
end
end
local last_tags = string.reverse(tags)
local offset = string.find(last_element, last_tags .. '$')
if offset then
thetable[#thetable] = string.sub(last_element, 1, offset - 1) .. the_icon .. last_tags
else
thetable[#thetable] = last_element .. the_icon
end
return thetable
end
-- Escape Lua captures
local function captureEscapes(text)
return mw.ustring.gsub(text, "(%%%d)", "%%%1")
end
-- expandTemplate or callParserFunction
local function expandBraces(text, formatting)
if text == nil or formatting == nil then return text end
-- only expand braces if provided in argument, not included in value as in Q1164668
if mw.ustring.find(formatting, '{{', 1, true) == nil then return text end
if type(text) ~= "string" then
text = tostring(text)
end
for braces in mw.ustring.gmatch(text, "{{(.-)}}") do
local parts = mw.text.split(braces, "|")
local title_part = parts[1]
local parameters = {}
for i = 2, #parts do
local subparts = mw.ustring.find(parts[i], "=")
if subparts then
local param_name = mw.ustring.sub(parts[i], 1, subparts - 1)
local param_value = mw.ustring.sub(parts[i], subparts + 1, -1)
-- reconstruct broken links by parts
if i < #parts and mw.ustring.find(param_value, "[[", 1, true) and not mw.ustring.find(param_value, "]]", 1, true) then
parameters[param_name] = param_value
local part_next = i + 1
while parts[part_next] and mw.ustring.find(parts[part_next], "]]", 1, true) do
parameters[param_name] = parameters[param_name] .. "|" .. parts[part_next]
part_next = part_next + 1
end
else
parameters[param_name] = param_value
end
elseif not mw.ustring.find(parts[i], "]]", 1, true) then
table.insert(parameters, parts[i])
end
end
local braces_expanded
if mw.ustring.find(title_part, ":")
and mw.text.split(title_part, ":")[1] ~= mw.site.namespaces[10].name -- not a prefix Template:
then
braces_expanded = mw.getCurrentFrame():callParserFunction{name=title_part, args=parameters}
else
braces_expanded = mw.getCurrentFrame():expandTemplate{title=title_part, args=parameters}
end
braces = mw.ustring.gsub(braces, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") -- escape magic characters
braces_expanded = captureEscapes(braces_expanded)
text = mw.ustring.gsub(text, "{{" .. braces .. "}}", braces_expanded)
end
return text
end
local function printDatatypeTime(data, parameters)
-- Dates and times are stored in ISO 8601 format
local timestamp = data.time
local post_format
local calendar_add = ""
local precision = data.precision or 11
if string.sub(timestamp, 1, 1) == '-' then
post_format = i18n.datetime["bc"]
elseif string.sub(timestamp, 2, 3) == '00' then
post_format = i18n.datetime["ad"]
elseif precision > 8 then
-- calendar model
local calendar_model = {["Q12138"] = "gregorian", ["Q1985727"] = "gregorian", ["Q11184"] = "julian", ["Q1985786"] = "julian"}
local calendar_id = mw.text.split(data.calendarmodel, 'entity/')[2]
if (timestamp < "+1582-10-15T00:00:00Z" and calendar_model[calendar_id] == "gregorian")
or (timestamp > "+1582-10-04T00:00:00Z" and calendar_model[calendar_id] == "julian")
then
calendar_add = " <sup>(" .. mw.message.new('Wikibase-time-calendar-' .. calendar_model[calendar_id]):inLanguage(parameters.lang[1]):plain() .. ")</sup>"
end
end
local function formatTime(form, stamp)
local pattern
if type(form) == "function" then
pattern = form(stamp)
else
pattern = form
end
stamp = tostring(stamp)
if mw.ustring.find(pattern, "$1") then
return mw.ustring.gsub(pattern, "$1", stamp)
elseif string.sub(stamp, 1, 1) == '-' then -- formatDate() only supports years from 0
stamp = '+' .. string.sub(stamp, 2)
elseif string.sub(stamp, 1, 1) ~= '+' then -- not a valid timestamp, it is a number
stamp = string.format("%04d", stamp)
end
local ret = mw.language.new(parameters.lang[1]):formatDate(pattern, stamp)
ret = string.gsub(ret, "^(%[?%[?)0+", "%1") -- supress leading zeros
ret = string.gsub(ret, "( %[?%[?)0+", "%1")
return ret
end
local function postFormat(t)
if post_format and mw.ustring.find(post_format, "$1") then
return mw.ustring.gsub(post_format, "$1", t)
end
return t
end
local intyear = tonumber(string.match(timestamp, "[+-](%d+)"))
local ret
if precision <= 5 then -- precision is 10000 years or more
local factor = 10 ^ ((5 - precision) + 4)
local y2 = math.ceil(math.abs(intyear) / factor)
local relative = formatTime(i18n.datetime[precision], y2)
if post_format == i18n.datetime["bc"] then
ret = mw.ustring.gsub(i18n.datetime.beforenow, "$1", relative)
else
ret = mw.ustring.gsub(i18n.datetime.afternow, "$1", relative)
end
local ret_number = string.match(ret, "%d+")
if ret_number ~= nil then
ret = mw.ustring.gsub(ret, ret_number, mw.language.new(parameters.lang[1]):formatNum(tonumber(ret_number)))
end
elseif precision == 6 or precision == 7 then -- millennia or centuries
local card = math.floor((intyear - 1) / 10^(9 - precision)) + 1
ret = formatTime(i18n.datetime[precision], card)
ret = postFormat(ret)
elseif precision == 8 then -- decades
local card = math.floor(math.abs(intyear) / 10) * 10
ret = formatTime(i18n.datetime[8], card)
ret = postFormat(ret)
elseif intyear > 9999 then -- not a valid timestamp
return
elseif precision == 9 or parameters.formatting == 'Y' then -- precision is year
ret = formatTime(i18n.datetime[9], intyear)
ret = postFormat(ret) .. calendar_add
elseif precision == 10 then -- month
ret = formatTime(i18n.datetime[10], timestamp .. " + 1 day") -- formatDate yyyy-mm-00 returns the previous month
ret = postFormat(ret) .. calendar_add
else -- precision 11, day
ret = formatTime(parameters.formatting or i18n.datetime[11], timestamp)
ret = postFormat(ret) .. calendar_add
end
return ret, timestamp
end
-- format data value wikibase-entityid: types wikibase-item, wikibase-property
local function printDatatypeEntity(data, parameters)
local entity_id = data['id']
if parameters.formatting == 'raw' then
return entity_id, entity_id
end
local entity_page = 'Special:EntityPage/' .. entity_id
local label, lang = getLabelByLangs(entity_id, parameters.lang)
local sitelink = mw.wikibase.getSitelink(entity_id)
local parameter = parameters.formatting
local labelcase = label or sitelink
if parameters.referit and parameters.referit ~= '' then labelcase = parameters.referit end
if parameters.gender == 'feminineform' then
labelcase = feminineForm(entity_id, lang) or labelcase
end
if parameters.case ~= 'gender' then
labelcase = case(parameters.case, labelcase, lang, parameters.lang[1], entity_id, parameters.id)
end
local ret1, ret2
if parameter == 'label' then
ret1 = labelcase or entity_id
ret2 = labelcase or entity_id
elseif parameter == 'sitelink' then
ret1 = (sitelink or 'd:' .. entity_page)
ret2 = sitelink or entity_id
elseif mw.ustring.find((parameter or ''), '$1', 1, true) then -- formatting = a pattern
ret1 = mw.ustring.gsub(parameter, '$1', labelcase or entity_id)
ret1 = expandBraces(ret1, parameter)
ret2 = labelcase or entity_id
else
if parameter == "ucfirst" or parameter == "ucinternallink" then
if labelcase and lang then
labelcase = mw.language.new(lang):ucfirst(labelcase)
end
-- only first of a list, reset formatting for next ones
if parameter == "ucinterlanllink" then
parameters.formatting = 'internallink'
else
parameters.formatting = nil -- default format
end
end
if sitelink then
ret1 = '[[' .. sitelink .. '|' .. labelcase .. ']]'
ret2 = labelcase
elseif label and string.match(parameter or '', 'internallink$') and not mw.wikibase.getEntityIdForTitle(label) then
ret1 = '[[' .. label .. '|' .. labelcase .. ']]'
ret2 = labelcase
else
ret1 = '[[d:' .. entity_page .. '|<span style="color:#5f9cbb;">' .. (labelcase or entity_id) .. '</span>]]'
ret2 = labelcase or entity_id
end
end
return ret1 .. addLabelIcon(entity_id, lang, parameters.lang[1], parameters.labelicon), ret2
end
-- format data type monolingualtext
local function getSnakValue(snak, parameters)
if snak.snaktype == 'value' then
-- see Special:ListDatatypes
if snak.datatype == 'wikibase-item' or snak.datatype == 'wikibase-property' then
return printDatatypeEntity(snak.datavalue.value, parameters)
elseif snak.datatype == "time" then
return printDatatypeTime(snak.datavalue.value, parameters)
end
elseif snak.snaktype == 'somevalue' then
if parameters.referit and parameters.referit ~= '' then return parameters.referit end
end
return mw.wikibase.renderSnak(snak)
end
local function printError(key)
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
local function getQualifierSnak(claim, qualifierId, parameters)
-- a "snak" is Wikidata terminology for a typed key/value pair
-- a claim consists of a main snak holding the main information of this claim,
-- as well as a list of attribute snaks and a list of references snaks
if qualifierId then
-- search the attribute snak with the given qualifier as key
if claim.qualifiers then
local qualifier = claim.qualifiers[qualifierId]
if qualifier then
if qualifier[1].datatype == "monolingualtext" then
-- iterate over monolingualtext qualifiers to get local language
for idx in pairs(qualifier) do
if getSnak(qualifier[idx], {"datavalue", "value", "language"}) == parameters.lang[1] then
return qualifier[idx]
end
end
elseif parameters.list then
return qualifier
else
return qualifier[1]
end
end
end
return nil, printError("qualifier-not-found")
else
-- otherwise return the main snak
return claim.mainsnak
end
end
local function getReferitValue(claim)
local result = ""
if claim.qualifiers then
if claim.qualifiers['P1932'] then
local wqualif = claim.qualifiers['P1932'][1].datavalue.value
if wqualif and wqualif ~= '' then
return wqualif
end
end
end
return result
end
local function getValueOfClaim(claim, qualifierId, parameters)
local snak, error = getQualifierSnak(claim, qualifierId, parameters)
parameters.referit=getReferitValue(claim)
if not snak then
return nil, nil, error
elseif snak[1] then -- a multi qualifier
local result, sortkey = {}, {}
local maxvals = tonumber(parameters.list)
for idx in pairs(snak) do
result[#result + 1], sortkey[#sortkey + 1] = getSnakValue(snak[idx], parameters)
if maxvals and maxvals == #result then break end
end
return mw.text.listToText(result, parameters.qseparator, parameters.qconjunction), sortkey[1]
else -- a property or a qualifier
return getSnakValue(snak, parameters)
end
end
local function getValueOfParentClaim(claim, qualifierId, parameters)
local qids = mw.text.split(qualifierId, '/', true)
local value, sortkey, valueraw = {}, {}, {}
local parent_raw, value_text
if qids[1] == parameters.property then
parent_raw, _, _ = getValueOfClaim(claim, nil, {["formatting"]="raw", ["lang"]=parameters.lang})
else
parent_raw, _, _ = getValueOfClaim(claim, qids[1], {["formatting"]="raw", ["lang"]=parameters.lang, ["list"]=true, ["qseparator"]='/', ["qconjunction"]='/'})
end
if string.sub(parent_raw or '', 1, 1) == "Q" then -- protection for 'no value'
local parent_qids = mw.text.split(parent_raw, '/', true)
for idx, p_qid in ipairs(parent_qids) do
local parent_claims = mw.wikibase.getBestStatements(p_qid, qids[2])
if parent_claims[1] then
value[idx], sortkey[idx], _ = getValueOfClaim(parent_claims[1], nil, parameters)
-- raw parent value needed for while/black lists, lang for avoiding an error on types other than entity
valueraw[idx], _, _ = getValueOfClaim(parent_claims[1], nil, {["formatting"]="raw", ["lang"]=parameters.lang})
end
end
end
if value[1] then
value_text = mw.text.listToText(value, parameters.qseparator, parameters.qconjunction)
end
return value_text, sortkey[1], valueraw[1]
end
-- see d:Help:Sources
local function getReferences(claim, parameters)
if not isSet(parameters.references) then return '' end
local lang = parameters.lang
local maxrefs = tonumber(parameters.references) or 1
local notproperref = {
["P143"] = true, -- imported from
["P3452"] = true, -- inferred from
["P887"] = true, -- based on heuristic
["P4656"] = true -- Wikimedia import URL
}
local result = {}
-- traverse through all references
for ref in pairs(claim.references or {}) do
local refparts
local refs = {}
local validref = true
local ref_id
-- traverse through all parts of the current reference
for snakkey, snakval in pairs(claim.references[ref].snaks or {}) do
for partkey, _ in pairs(claim.references[ref].snaks[snakkey] or {}) do
if notproperref[snakkey] then -- not a proper reference
validref = false
break
end
end
if validref then
for snakidx = 1, #snakval do
if snakidx > 1 then refparts = refparts .. ", " end
refparts = refparts or '' .. (getSnakValue(snakval[snakidx], {lang=lang}) or '')
end
refs[snakkey] = refparts
refparts = nil
if snakkey == "P248" then -- stated in
ref_id = getSnak(snakval, {1, "datavalue", "value", "id"})
end
end
end
-- fill missing values with parent item
if ref_id then
local function refParent(qid, pid, formatting)
local snak = getSnak(mw.wikibase.getBestStatements(qid, pid), {1, "mainsnak"})
return snak and getSnakValue(snak, {formatting=formatting, lang=lang})
end
refs['P50'] = refs['P50'] or refParent(ref_id, 'P50', 'label') -- author
refs['P407'] = refs['P407'] or refParent(ref_id, 'P407', 'label') -- language of work
refs['P123'] = refs['P123'] or refParent(ref_id, 'P123', 'label') -- publisher
refs['P577'] = refs['P577'] or refParent(ref_id, 'P577') -- date
refs['P1433'] = refs['P1433'] or refParent(ref_id, 'P1433', 'label') -- published in
refs['P304'] = refs['P304'] or refParent(ref_id, 'P304') -- page(s)
refs['P433'] = refs['P433'] or refParent(ref_id, 'P433') -- issue
refs['P236'] = refs['P236'] or refParent(ref_id, 'P236') -- ISSN
refs['P356'] = refs['P356'] or refParent(ref_id, 'P356') -- DOI
end
-- get title of local templates for citing references
local template_web = mw.wikibase.getSitelink('Q5637226') or ""
template_web = mw.text.split(template_web, ":")[2] -- split off namespace from front
local template_journal = mw.wikibase.getSitelink('Q5624899') or ""
template_journal = mw.text.split(template_journal, ":")[2]
local citeParams = {}
if refs['P854'] and (refs['P1476'] or refs['P248']) and template_web then
-- if both "reference URL" and "title" (or "stated in") are present, then use cite web template
citeParams[i18n['cite']['url']] = refs['P854']
if refs['P248'] and refs['P1476'] == nil then
citeParams[i18n['cite']['title']] = refs['P248']:match("^%[%[.-|(.-)%]%]")
else
citeParams[i18n['cite']['title']] = refs['P1476']
citeParams[i18n['cite']['website']] = refs['P248']
end
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['language']] = refs['P407']
citeParams[i18n['cite']['publisher']] = refs['P123']
citeParams[i18n['cite']['date']] = refs['P577']
citeParams[i18n['cite']['pages']] = refs['P304']
citeParams[i18n['cite']['access-date']] = refs['P813']
citeParams[i18n['cite']['archive-url']] = refs['P1065']
citeParams[i18n['cite']['archive-date']] = refs['P2960']
citeParams[i18n['cite']['quote']] = refs['P1683']
refparts = mw.getCurrentFrame():expandTemplate{title=template_web, args=citeParams}
elseif refs['P1433'] and (refs['P1476'] or refs['P248']) and template_journal then
-- if both "published in" and "title" (or "stated in") are present, then use cite journal template
citeParams[i18n['cite']['work']] = refs['P1433']
citeParams[i18n['cite']['title']] = refs['P1476'] or refs['P248']
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['date']] = refs['P577']
citeParams[i18n['cite']['issue']] = refs['P433']
citeParams[i18n['cite']['pages']] = refs['P304']
citeParams[i18n['cite']['language']] = refs['P407']
citeParams[i18n['cite']['issn']] = refs['P236']
citeParams[i18n['cite']['doi']] = refs['P356']
refparts = mw.getCurrentFrame():expandTemplate{title=template_journal, args=citeParams}
elseif validref then
-- raw ouput
local snaksorder = claim.references[ref]["snaks-order"]
local function indexed(a)
for _, b in ipairs(snaksorder) do
if b == a then return true end
end
return false
end
for k, _ in pairs(refs or {}) do
if not indexed(k) then
table.insert(snaksorder, k)
end
end
local italics = "''"
for _, k in ipairs(snaksorder) do
if refs[k] then
refparts = refparts and refparts .. " " or ""
refparts = refparts .. mw.ustring.gsub(getLabelByLangs(k, lang), "^%l", mw.ustring.upper) .. ": "
refparts = refparts .. italics .. refs[k] .. italics .. "."
italics = ""
end
end
end
if refparts then
local ref_name = claim.references[ref].hash
result[#result + 1] = mw.getCurrentFrame():extensionTag("ref", refparts, {name=ref_name})
if maxrefs and maxrefs == #result then break end
end
end
if type(result) == 'table' and #result > 0 and isSet(i18n.categoryref) then
return mw.text.listToText(result) .. "[[" ..i18n.categoryref .. "]]"
end
return mw.text.listToText(result)
end
-- Set whitelist or blacklist values
local function setWhiteOrBlackList(num_qual, args)
local lists = {['whitelist']={}, ['blacklist']={}, ['ignorevalue']={}, ['selectvalue']={}}
for i = 0, num_qual do
for k, _ in pairs(lists) do
if isSet(args[k .. i]) then
lists[k][tostring(i)] = {}
local pattern = 'Q%d+'
if string.sub(args[k .. i], 1, 1) ~= 'Q' then
pattern = '[^%p%s]+'
end
for q in string.gmatch(args[k .. i], pattern) do
lists[k][tostring(i)][q] = true
end
end
end
end
return lists['whitelist'], lists['blacklist'], lists['ignorevalue'], lists['selectvalue']
end
local function tableParameters(args, parameters, column)
local column_params = mw.clone(parameters)
column_params.formatting = args["colformat"..column]; if column_params.formatting == "" then column_params.formatting = nil end
column_params.convert = args["convert" .. column]
if args["case" .. column] then
column_params.case = args["case" .. column]
end
return column_params
end
local function getEntityId(args, pargs, unnamed)
pargs = pargs or {}
local id = args.item or args.from or (unnamed and mw.text.trim(args[1] or '') or nil)
if not isSet(id) then
id = pargs.item or pargs.from or (unnamed and mw.text.trim(pargs[1] or '') or nil)
end
if isSet(id) then
if string.find(id, ":") then -- remove prefix as Property:Pid
id = mw.text.split(id, ":")[2]
end
else
id = mw.wikibase.getEntityIdForCurrentPage()
end
return id
end
local function getArg(value, default, aliases)
if type(value) == 'boolean' then return value
elseif value == "false" or value == "no" then return false
elseif value == "true" or value == "yes" then return true
elseif value and aliases and aliases[value] then return aliases[value]
elseif isSet(value) then return value
elseif default then return default
else return nil
end
end
-- Main function claim ---------------------------------------------
-- on debug console use: =p.claim{item="Q...", property="P...", ...}
function p.claim(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local is_sandbox = isSet(pargs.sandbox)
if not required and is_sandbox then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).claim(frame)
end
--If a value is already set, use it
if isSet(args.value) then
if args.value == 'NONE' then
return
else
return args.value
end
end
-- arguments
local parameters = {}
parameters.id = getEntityId(args, pargs)
if parameters.id == nil then return end
parameters.property = string.upper(args.property or "")
local qualifierId = {}
qualifierId[1] = getArg(string.upper(args.qualifier or ""))
local i = 2
while isSet(args["qualifier" .. i]) do
qualifierId[i] = string.upper(args["qualifier" .. i])
i = i + 1
end
parameters.formatting = getArg(args.formatting)
parameters.convert = getArg(args.convert)
parameters.case = args.case
parameters.list = getArg(args.list, true, {firstrank='bestrank'})
parameters.shownovalue = getArg(args.shownovalue, true)
parameters.separator = getArg(args.separator)
parameters.conjunction = getArg(args.conjunction, parameters.separator)
parameters.qseparator = parameters.separator
parameters.qconjunction = parameters.conjunction
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
local rowformat = args.rowformat
parameters.references = args.references
local showerrors = args.showerrors
local default = args.default
if default then showerrors = nil end
parameters.lang = findLang(args.lang)
if parameters.formatting == "raw" then
parameters.editicon, parameters.labelicon = false, false
else
parameters.editicon, parameters.labelicon = setIcons(args.editicon, pargs.editicon) -- needs loadI18n by findLand
end
-- fetch property
local claims = {}
local bestrank = (parameters.list == false or parameters.list == 'bestrank') and parameters.list ~= 'lang'
for pp in string.gmatch(parameters.property, 'P%d+') do
claims = getStatements(parameters.id, pp, bestrank)
if #claims > 0 then
parameters.property = pp
break
end
end
if #claims == 0 then
if showerrors then return printError("property-not-found") else return default end
end
-- defaults for table
local preformat, postformat = "", ""
local whitelisted = false
local whitelist, blacklist, ignorevalue, selectvalue = {}, {}, {}, {}
if parameters.formatting == "table" then
parameters.separator = parameters.separator or "<br />"
parameters.conjunction = parameters.conjunction or "<br />"
parameters.qseparator = ", "
parameters.qconjunction = ", "
if not rowformat then
rowformat = "$0 ($1"
i = 2
while qualifierId[i] do
rowformat = rowformat .. ", $" .. i
i = i + 1
end
rowformat = rowformat .. ")"
elseif mw.ustring.find(rowformat, "^[*#]") then
parameters.separator = "</li><li>"
parameters.conjunction = "</li><li>"
if mw.ustring.match(rowformat, "^[*#]") == "*" then
preformat = "<ul><li>"
postformat = "</li></ul>"
else
preformat = "<ol><li>"
postformat = "</li></ol>"
end
rowformat = mw.ustring.gsub(rowformat, "^[*#] ?", "")
end
-- set whitelist and blacklist values
whitelist, blacklist, ignorevalue, selectvalue = setWhiteOrBlackList(#qualifierId, args)
local next = next
if next(whitelist) ~= nil then whitelisted = true end
end
-- set feminine case if gender is requested
local itemgender = args.itemgender
local idgender
if itemgender then
if string.match(itemgender, "^P%d+$") then
local snak_id = getSnak(mw.wikibase.getBestStatements(parameters.id, itemgender), {1, "mainsnak", "datavalue", "value", "id"})
if snak_id then
idgender = snak_id
end
elseif string.match(itemgender, "^Q%d+$") then
idgender = itemgender
end
end
local gender_requested = false
if parameters.case == "gender" or idgender then
gender_requested = true
elseif parameters.formatting == "table" then
for ii=0, #qualifierId do
if args["case" .. ii] and args["case" .. ii] == "gender" then
gender_requested = true
break
end
end
end
if gender_requested then
if feminineGender(idgender or parameters.id) then
parameters.gender = "feminineform"
end
end
-- get initial sort indices
local sortindices = {}
for idx in pairs(claims) do
sortindices[#sortindices + 1] = idx
end
-- sort by claim rank
local comparator = function(a, b)
local rankmap = { deprecated = 2, normal = 1, preferred = 0 }
local ranka = rankmap[claims[a].rank or "normal"] .. string.format("%08d", a)
local rankb = rankmap[claims[b].rank or "normal"] .. string.format("%08d", b)
return ranka < rankb
end
table.sort(sortindices, comparator)
local result, result2, result_query
local error
if parameters.list or parameters.formatting == "table" then
-- convert LF to line feed, <br /> may not work on some cases
parameters.separator = parameters.separator == "LF" and "\010" or parameters.separator
parameters.conjunction = parameters.conjunction == "LF" and "\010" or parameters.conjunction
-- i18n separators
parameters.separator = parameters.separator or mw.message.new('Comma-separator'):inLanguage(parameters.lang[1]):plain()
parameters.conjunction = parameters.conjunction or (mw.message.new('And'):inLanguage(parameters.lang[1]):plain() .. mw.message.new('Word-separator'):inLanguage(parameters.lang[1]):plain())
-- iterate over all elements and return their value (if existing)
local value
local sortkey
local values = {}
local sortkeys = {}
local refs = {}
local rowlist = {} -- rows to list with whitelist or blacklist
for idx in pairs(claims) do
local claim = claims[sortindices[idx]]
local reference = {}
if not whitelisted then rowlist[idx] = true end
if parameters.formatting == "table" then
local params = tableParameters(args, parameters, "0")
value, sortkey, error = getValueOfClaim(claim, nil, params)
if value then
values[#values + 1] = {}
sortkeys[#sortkeys + 1] = {}
refs[#refs + 1] = {}
if whitelist["0"] or blacklist["0"] then
local valueraw, _, _ = getValueOfClaim(claim, nil, {["formatting"]="raw", ["lang"]=params.lang})
if whitelist["0"] and whitelist["0"][valueraw or ""] then
rowlist[#values] = true
elseif blacklist["0"] and blacklist["0"][valueraw or ""] then
rowlist[#values] = false
end
end
for k, qual in ipairs(qualifierId) do
local j = tostring(k)
params = tableParameters(args, parameters, j)
local valueq, sortkeyq, valueraw
if qual == parameters.property then -- hack for getting the property with another formatting, i.e. colformat1=raw
valueq, sortkeyq, _ = getValueOfClaim(claim, nil, params)
else
for q in mw.text.gsplit(qual, '%s*OR%s*') do
if string.find(q, ".+/.+") then
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 = getStatements(parameters.id, string.sub(q, 2), bestrank)
if #claim2 > 0 then
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
end
else
valueq, sortkeyq, _ = getValueOfClaim(claim, q, params)
end
if valueq then
qual = q
break
end
end
end
values[#values]["col" .. j] = valueq
sortkeys[#sortkeys]["col" .. j] = sortkeyq or valueq
if whitelist[j] or blacklist[j] or ignorevalue[j] or selectvalue[j] then
valueq = valueraw or getValueOfClaim(claim, qual, {["formatting"]="raw", ["lang"]=params.lang})
if whitelist[j] and whitelist[j][valueq or ""] then
rowlist[#values] = true
elseif blacklist[j] and blacklist[j][valueq or ""] then
rowlist[#values] = false
elseif ignorevalue[j] and ignorevalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
elseif selectvalue[j] and not selectvalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
end
end
end
end
else
value, sortkey, error = getValueOfClaim(claim, qualifierId[1], parameters)
values[#values + 1] = {}
sortkeys[#sortkeys + 1] = {}
refs[#refs + 1] = {}
end
if not value and showerrors then value = error end
if value then
if isSet(parameters.references) and claim.references then reference = claim.references end
refs[#refs]["col0"] = reference
values[#values]["col0"] = value
sortkeys[#sortkeys]["col0"] = sortkey or value
end
end
-- sort and format results
sortindices = {}
for idx in pairs(values) do
sortindices[#sortindices + 1] = idx
end
if sorting_col then
local sorting_table = mw.text.split(sorting_col, '%D+')
local comparator = function(a, b)
local valuea, valueb
local m = 1
while valuea == valueb and m <= #sorting_table do
valuea = sortkeys[a]["col" .. sorting_table[m]] or ''
valueb = sortkeys[b]["col" .. sorting_table[m]] or ''
m = m + 1
end
if sorting_up then
return valueb > valuea
end
return valueb < valuea
end
table.sort(sortindices, comparator)
end
local maxvals = tonumber(parameters.list)
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference = getReferences({["references"] = refs[sortindices[idx]]["col0"]}, parameters)
value = valuerow["col0"]
if parameters.formatting == "table" then
if not rowlist[sortindices[idx]] then
value = nil
else
local rowformatting = rowformat .. "$" -- fake end character added for easy gsub
value = mw.ustring.gsub(rowformatting, "$0", {["$0"] = value})
value = mw.ustring.gsub(value, "$R0", reference) -- add reference
for h, _ in ipairs(qualifierId) do
local valueq = valuerow["col" .. h]
if args["rowsubformat" .. h] and isSet(valueq) then
-- add fake end character $
-- gsub $h not followed by a number so $1 doesn't match $10, $11...
-- remove fake end character
valueq = captureEscapes(valueq)
valueq = mw.ustring.gsub(args["rowsubformat" .. h] .. "$", "$" .. h .. "(%D)", valueq .. "%1")
valueq = string.sub(valueq, 1, -2)
rowformatting = mw.ustring.gsub(rowformatting, "$" .. h .. "(%D)", args["rowsubformat" .. h] .. "%1")
end
valueq = valueq and captureEscapes(valueq) or ''
value = mw.ustring.gsub(value, "$" .. h .. "(%D)", valueq .. "%1")
end
value = string.sub(value, 1, -2) -- remove fake end character
value = expandBraces(value, rowformatting)
end
elseif value then
value = expandBraces(value, parameters.formatting)
value = value .. reference
end
if isSet(value) then
result[#result + 1] = value
if not parameters.list or (maxvals and maxvals == #result) then
break
end
end
end
if args.query == 'num' then
result_query = 0
for _, v in pairs(rowlist) do
result_query = result_query + (v and 1 or 0)
end
end
if #result > 0 then
if parameters.formatting == 'table' then
result = addEditIconTable(result, parameters) -- in a table, add edit icon on last element
end
result = preformat .. mw.text.listToText(result, parameters.separator, parameters.conjunction) .. postformat
else
result = ''
end
else
-- return first element
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result and isSet(parameters.references) then result = result .. getReferences(claim, parameters) end
if args.query == 'num' then result_query = 1 end
end
if isSet(result) then
if not (parameters.formatting == 'table' or (result2 and result2 == 'no-icon')) then
-- add edit icon, except table added previously and except explicit no-icon internal flag
result = result .. addEditIcon(parameters)
end
else
if showerrors then result = error else result = default end
end
if args.query == 'untranslated' and required and not is_sandbox then
result_query = untranslated
end
return result, result_query or ''
end
-- Local functions for getParentValues -----------------------
local function uc_first(word)
if word == nil then return end
return mw.ustring.upper(mw.ustring.sub(word, 1, 1)) .. mw.ustring.sub(word, 2)
end
local function getPropertyValue(id, property, parameter, langs, labelicon, wcase)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak = getSnak(snaks, {1, "mainsnak"})
if mysnak == nil then
return
end
local entity_id
local result = '-' -- default for 'no value'
if mysnak.datavalue then
entity_id = "Q" .. tostring(mysnak.datavalue.value['numeric-id'])
result, _ = getSnakValue(mysnak, {formatting=parameter, lang=langs, labelicon=labelicon, case=wcase})
end
return entity_id, result
end
local function getParentObjects(id,
prop_format,
label_format,
languages,
propertySupString,
propertyLabel,
propertyLink,
label_show,
labelicon0,
labelicon1,
upto_number,
upto_label,
upto_value,
last_only,
grammatical_case,
include_self)
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local maxloop = 10
if upto_number then
maxloop = tonumber(upto_number)
elseif next(upto_label) or next(upto_value) then
maxloop = 50
end
local labels_filter = next(label_show)
local result = {}
local id_value = id
for iter = 1, maxloop do
local link, label, labelwicon, linktext, id_label
for _, propertySup in pairs(propertySups) do
local _id_value, _link = getPropertyValue(id_value, propertySup, prop_format, languages, labelicon1, grammatical_case)
if _id_value and _link then id_value = _id_value; link = _link break end
end
if not id_value or not link then break end
if propertyLink then
_, linktext = getPropertyValue(id_value, propertyLink, "label", languages)
if linktext then
link = mw.ustring.gsub(link, "%[%[(.*)%|.+%]%]", "[[%1|" .. linktext .. "]]")
end
end
id_label, label = getPropertyValue(id_value, propertyLabel, label_format, languages, false, "infoboxlabel")
if labelicon0 then
_, labelwicon = getPropertyValue(id_value, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
else
labelwicon = label
end
if labels_filter == nil or (label_show[id_label] or label_show[label]) then
result[#result + 1] = {labelwicon, link}
label_show[id_label or 'none'], label_show[label or 'none'] = nil, nil -- only first label found
end
if upto_label[id_label] or upto_label[label] or upto_value[id_value] then
break
end
end
if last_only then
result = {result[#result]}
end
if include_self then
local label_self, link_self
_, label_self = getPropertyValue(id, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
link_self, _ = getLabelByLangs(id, languages)
table.insert(result, 1, {label_self, link_self})
end
return result
end
local function parentObjectsToString(result,
rowformat,
cascade,
sorting)
local ret = {}
local first = 1
local last = #result
local iter = 1
if sorting == "-1" then first = #result; last = 1; iter = -1 end
for i = first, last, iter do
local rowtext = mw.ustring.gsub(rowformat, "$[01]", {["$0"] = result[i][1], ["$1"] = result[i][2]})
ret[#ret + 1] = expandBraces(rowtext, rowformat)
end
if cascade then
local direction = mw.language.new(wiki.langcode):isRTL() and "right" or "left"
local suffix = ""
for i = 1, #ret do
ret[i] = '<ul style="line-height:100%; margin-' .. direction .. ':0.45em; padding-' .. direction .. ':0;"><li>' .. ret[i]
suffix = suffix .. '</li></ul>'
end
ret[#ret] = ret[#ret] .. suffix
end
return ret
end
-- Returns pairs of parent label and property value fetching a recursive tree
function p.getParentValues(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getParentValues(frame)
end
local id = getEntityId(args, pargs)
if id == nil then return end
local languages = findLang(args.lang)
local propertySup = getArg(args.property, "P131") --administrative entity
local propertyLabel = getArg(args.label, "P31") --instance
local propertyLink = getArg(args.valuetext)
local property_format = getArg(args.formatting)
local label_format = getArg(args.labelformat, "label")
local upto_number = getArg(args.upto)
local last_only = getArg(args.last_only, false)
local editicon, labelicon = setIcons(args.editicon, pargs.editicon)
local include_self = getArg(args.include_self, false)
local pcase = getArg(args.case)
local upto_label = {}
for q in string.gmatch(args.uptolabelid or '', 'Q%d+') do
upto_label[q] = true
end
if type(upto_number) == 'string' then
upto_label[uc_first(upto_number)] = true
upto_number = nil
require(wiki.module_title .. '/debug').track('upto') -- replace upto by uptolabelid
end
local upto_value = {}
for q in string.gmatch(args.uptovalueid or args.uptolinkid or '', 'Q%d+') do
upto_value[q] = true
end
local label_show = {}
for q in string.gmatch(args.showlabelid or '', 'Q%d+') do
label_show[q] = true
end
for _, v in ipairs(mw.text.split(args.labelshow or '', "/")) do
if v ~= '' then
label_show[uc_first(v)] = true
require(wiki.module_title .. '/debug').track('labelshow') -- replace labelshow by showlabelid
end
end
local rowformat = args.rowformat; if not isSet(rowformat) then rowformat = "$0 = $1" end
local labelicon0, labelicon1 = labelicon, labelicon
if string.find(label_format, '{{.*$0.*}}') or (string.find(rowformat, '{{.*$0.*}}') and label_format ~= 'raw') then
labelicon0 = false
end
local result = getParentObjects(id,
property_format,
label_format,
languages,
propertySup,
propertyLabel,
propertyLink,
label_show,
labelicon0,
labelicon1,
upto_number,
upto_label,
upto_value,
last_only,
pcase,
include_self)
if #result == 0 then return end
local separator = args.separator; if not isSet(separator) then separator = "<br />" end
local sorting = args.sorting; if sorting == "" then sorting = nil end
local cascade = (args.cascade == "true" or args.cascade == "yes")
local ret = parentObjectsToString(result,
rowformat,
cascade,
sorting)
ret = addEditIconTable(ret, {property=propertySup, editicon=editicon, id=id, lang=languages})
return mw.text.listToText(ret, separator, separator)
end
-- Link with a parent label --------------------
function p.linkWithParentLabel(frame)
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).linkWithParentLabel(frame)
end
local args = {}
if frame.args then
for k, v in pairs(frame.args) do -- metatable
args[k] = v
end
else
args = frame -- via require
end
if isSet(args.value) then
return args.value
end
-- get id value of property/qualifier
local largs = mw.clone(args)
largs.list = tonumber(args.list) and args.list or true
largs.formatting = "raw"
largs.separator = "/·/"
largs.editicon = false
local items_list, _ = p.claim(largs)
if not isSet(items_list) then return end
local items_table = mw.text.split(items_list, "/·/", true)
-- get internal link of property/qualifier
largs.formatting = "internallink"
local link_list, _ = p.claim(largs)
local link_table = mw.text.split(link_list, "/·/", true)
-- get label of parent property
local parent_claim = getSnak(getStatements(items_table[1], args.parent, true), {1, "mainsnak", "datatype"})
if parent_claim == 'monolingualtext' then
largs.formatting = nil
largs.list = 'lang'
else
largs.formatting = "label"
largs.list = false
end
largs.property = args.parent
largs.qualifier = nil
for i, v in ipairs(items_table) do
largs.item = v
local link_label, _ = p.claim(largs)
if isSet(link_label) then
link_table[i] = mw.ustring.gsub(link_table[i] or '', "%[%[(.*)%|.+%]%]", "[[%1|" .. link_label .. "]]")
end
end
args.editicon, _ = setIcons(args.editicon, pargs.editicon)
args.id = getEntityId(args, pargs)
args.lang = findLang(args.lang)
return mw.text.listToText(link_table) .. addEditIcon(args)
end
-- Gets a label in a given language (content language by default) or its fallbacks, optionnally linked.
function p.getLabel(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getLabel(frame)
end
local id = getEntityId(args, pargs, 1)
if id == nil then return end
local languages = findLang(args.lang)
local labelicon = false
if mw.wikibase.isValidEntityId(id) then
_, labelicon = setIcons(args.editicon, pargs.editicon)
end
local label_icon = ''
local label, lang
if args.label then
label = args.label
else
-- exceptions or labels fixed
local exist, labels = pcall(require, wiki.module_title .. "/labels" .. (languages[1] == wiki.langcode and '' or '/' .. languages[1]))
if exist and labels.infoboxLabelsFromId and next(labels.infoboxLabelsFromId) ~= nil then
label = labels.infoboxLabelsFromId[id]
end
if label == nil then
label, lang = getLabelByLangs(id, languages)
if label then
if isSet(args.itemgender) and feminineGender(args.itemgender) then
label = feminineForm(id, lang) or label
end
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
if args.case then
label = case(args.case, label, lang)
end
end
label_icon = addLabelIcon(id, lang, languages[1], labelicon)
end
end
local linked = args.linked
local ret2 = required and untranslated or ''
if isSet(linked) and linked ~= "no" then
local article = mw.wikibase.getSitelink(id) or ("d:Special:EntityPage/" .. id)
return "[[" .. article .. "|" .. (label or id) .. "]]" .. label_icon, ret2
else
return (label or id) .. label_icon, ret2
end
end
-- Utilities -----------------------------
-- See also module ../debug.
-- Copied from Module:Wikibase
function p.getSiteLink(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs, 1)
if id == nil then return end
return mw.wikibase.getSitelink(id, mw.text.trim(args[2] or ''))
end
-- Helper function for the default language code used
function p.lang(frame)
local lang = frame and frame.args[1] -- nil via require
return findLang(lang)[1]
end
-- Number of statements
function p.numStatements(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs)
if id == nil then return 0 end
local prop = mw.text.trim(args[1] or '')
local num = {}
if not isSet(prop) and frame.args then
args = {}
for k, v in pairs(pargs) do
args[k] = v
end
for k, v in pairs(frame.args) do
args[k] = v
end
args.query = 'num'
_, num = p.claim(args)
return num
elseif args[2] then -- qualifier
local qual = mw.text.trim(args[2])
local values = p.claim{item=id, property=prop, qualifier=qual, formatting='raw', separator='/·/'}
if values then
num = mw.text.split(values, '/·/')
end
else
num = mw.wikibase.getBestStatements(id, prop)
end
return #num
end
-- Returns true if property datavalue is found excluding novalue/somevalue
function p.validProperty(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local item = getEntityId(args, pargs)
if item == nil then return end
local property = mw.text.trim(args[1])
local prop_data = getSnak(mw.wikibase.getBestStatements(item, property), {1, "mainsnak", "datavalue"})
return prop_data and true or nil
end
function p.editAtWikidata(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local value = isSet(args[1])
if value then return end
local param = {}
param.id = getEntityId(args, pargs)
param.property = args.property
param.lang = findLang(args.lang)
param.editicon, _ = setIcons(args.editicon)
return addEditIcon(param)
end
function p.formatNum(frame)
local num = tonumber(mw.text.trim(frame.args[1]))
local lang = findLang(mw.text.trim(frame.args[2]))
return mw.language.new(lang[1]):formatNum(num)
end
return p
9run9w8j8jbipj8zdttauepsvm3zzuy
Mòdul:Wikidata/ús
828
34118
184386
179568
2026-05-14T21:00:52Z
Aleator
20
/* Vegeu també */ -enllaç a Mòdul:Wikibase
184386
wikitext
text/x-wiki
<!-- SI US PLAU, AFEGIU LES CATEGORIES AL FINAL D'AQUESTA PÀGINA I ELS INTERWIKIS A WIKIDATA -->
Aquest mòdul extrau dades formatades de Wikidata. Funciona en la llengua local del wiki, o en una llengua específica per a proves, i té opcions de configuració.
== Funcions ==
Funció bàsica:
* <code>[[#Funció claim|claim]]</code>: Retorna el valor (o els valors) d'una declaració o d'un qualificador formatat amb paràmetres o amb un format per defecte segons el tipus de dada.
Altres funcions:
* <code>[[#Funció getLabel|getLabel]]</code>: retorna una etiqueta en la llengua especificada, o la llengua per defecte.
* <code>[[#Funció getParentValues|getParentValues]]</code>: retorna etiquetes i valors superiors d'una propietat de forma recursiva.
* <code>[[#Funció linkWithParentLabel|linkWithParentLabel]]</code>: crea un enllaç amb l'etiqueta d'una propietat superior. Per exemple per enllaçar [[d:Property:P405|P405]] amb l'etiqueta [[d:Property:P835|P835]] definida en el corresponent ítem superior.
Altres [[#Utilitats|utilitats]]: getSiteLink, lang, numStatements.
== Funció claim ==
Retorna el valor (o els valors) d'una declaració o d'un qualificador formatat amb paràmetres o amb un format per defecte segons el tipus de dada. Per defecte està referit a l'ítem de Wikidata (Qid) associat a la pàgina actual.
Sintaxi completa:
:<code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|claim|item= |lang= |property= |qualifier= |value= |list= |tablesort= |formatting= |separator= |conjunction= |editicon= |showerrors= |default= }}</nowiki></code>
Sintaxi addicional pel format de taula:
:<code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|claim|item= |lang= |property= |qualifier= |qualifier2= |...|qualifier</nowiki>''x''<nowiki>= |formatting=table |tablesort= |sorting= |rowformat= |rowsubformat1= |...|rowsubformat</nowiki>''x''<nowiki>= |colformat0= |...|colformat</nowiki>''x''<nowiki>= |case0= |...|case</nowiki>''x''<nowiki>= |separator= |conjunction= |editicon= |showerrors= |default= |references= }}</nowiki></code>
=== Paràmetres generals ===
*<code>item=</code> (opcional) Permet indicar un ítem (Qid) diferent a l'ítem associat a la pàgina actual. Cal fer-lo servir <u>amb moderació</u> pel seu <u>alt consum</u> de recursos. Es pot usar també com a paràmetre de l'entorn superior de la plantilla. Té com a àlies <code>from</code>.
*<code>lang=</code> (opcional) Permet indicar el codi d'una llengua determinada. Es pot usar també com a paràmetre de l'entorn superior de la plantilla. Per defecte usa la llengua local del wiki per a l'espai principal d'articles o la llengua d'usuari definida en les preferències per a altres espais de noms. Si no troba el valor en aquesta llengua ho intenta en les llengües alternatives definides en el MediaWiki. Per exemple per català les llengües alternatives són occità i anglès. En cas que el valor no s'hagi trobat en la llengua demanada, hi afegeix el codi de llengua i una icona d'etiqueta per a traduir-ho a Wikidata. Aquesta icona es pot eliminar amb el paràmetre editicon.
*<code>property=</code> (obligatori) Identificador de la propietat de la declaració (Pid). Es poden definir diferents propietats alternatives amb qualsevol separador, per exemple "P17 o P131", i obtindrà la primera que trobi. Accepta també una p minúscula, però no és recomanat. Igualment accepta l'etiqueta de la propietat, per exemple property=estat equival a property=P17 per la propietat [[d:Property:P17|P17]].
*<code>qualifier=</code> (opcional) Qualificador (Pid) del valor de la propietat.
*<code>value=</code> (opcional) Valor preferent al de Wikidata. Pot ser un paràmetre opcional en una plantilla amb el format <nowiki>{{{paràmetre|}}}</nowiki>, així si existeix pren el valor del paràmetre i si està buit llavors obté el valor de Wikidata.
** <code>value=NONE</code> Amb aquest valor no treu res de Wikidata. Permet configurar un paràmetre per a que no tregui cap valor de Wikidata, o bé treure només valors informats en la plantilla amb <code><nowiki>{{{paràmetre|NONE}}}</nowiki></code>. És equivalent a la sintaxi wiki: <code><nowiki>{{#ifeq:{{{paràmetre|}}}|NONE|<!-- no res -->}}</nowiki></code>.
*<code>references=</code> (opcional) Amb qualsevol valor mostrarà les referències del valor obtingut. Si troba [[d:Property:P854|P854]] més o bé [[d:Property:P1476|P1476]] o bé [[d:Property:P248|P248]] llavors ho formata amb la versió local de [[d:Q5637226|Q5637226]] i amb els paràmetres traduïts a la taula i18n["cite"] de [[Module:{{ROOTPAGENAME}}/i18n]]. Si troba [[d:Property:P1433|P1433]], més títol o afirmat, llavors ho formata amb [[d:Q5624899|Q5624899]]}. En cas contrari ho formata com a text.
*: En cas d'usar-ho amb formatting=table (vegeu [[#Paràmetres de taula de propietat i qualificadors|més avall]]) cal definir on han d'aparèixer les referències en el paràmetre "rowformat".
*<code>list=</code> (opcional):
** <code>list=true</code> (per defecte) Mostra una llista de tots els valors preferents i normals (vegeu ''separator'' i ''conjuction'' més avall). En cap cas obté els valors obsolets.
** <code>list=false</code> o <code>list=no</code> Mostra només un valor, el de rang més alt segons l'ordre preferent/normal, o el més antic dels que tenen el rang més alt.
** <code>list=bestrank</code> Mostra una llista dels valors amb el rang més alt. És equivalent a list=true si tots tenen el mateix rang. És equivalent a list=false si només hi ha un valor amb el rang més alt. El valor <code>firstrank</code> és un àlies.
** <code>list=lang</code> En cas de valors monolingües només treu els corresponents a la llengua del paràmetre lang. Vegeu el paràmetre lang.
** <code>list=''<número>''</code> Número màxim de valors a llistar. Amb list=1 és equivalent a list=false. Amb list=0 és equivalent a list=true.
** <code>tablesort=0</code> (opcional) ordenació ascendent de la llista. Per defecte l'ordenació és pel rang (preferent, normal) i per l'antiguitat de definició a Wikidata.
* <code>separator=</code> (opcional) Separador a usar en llistes o taules. En cas de llistes, per defecte és [[MediaWiki:Comma-separator]], en català una coma i un espai en blanc ', '. En cas de taules per defecte és un salt de línia <nowiki><br /></nowiki>. En algun cas, si s'inclou en etiquetes que usen [[mw:Strip marker|strip markers]], pot ser que un <nowiki><br /></nowiki> no funcioni. L'alternativa és usar separator=LF per a un caràcter de control [[w:salt de línia|line feed]].
* <code>conjunction=</code> (opcional) Conjunció a usar com a separador diferent entre els dos últims elements de la llista. Per defecte és igual a separator si està definit i si no és [[MediaWiki:And]] més [[MediaWiki:Word-separator]], en català ' i '. En el cas de taules per defecte és un salt de línia <nowiki><br /></nowiki>.
*<code>case=</code> (opcional) Cas gramatical a generar, depenent de la llengua local, o canvis a aplicar en el wiki local definits a [[Module:{{ROOTPAGENAME}}/i18n]]. Com a casos generals tractats pel mòdul:
** case=gender, segons la definició de [[d:Property:P21|P21]] de l'element (pàgina actual, item o itemgender) treu el valor de [[d:Property:P2521|P2521]].
** case=smallcaps, treu l'etiqueta en versaleta.
*: Vegeu la documentació de [[Module:{{ROOTPAGENAME}}/i18n]] per a altres casos locals.
*<code>itemgender=</code> (opcional) Element on es comprova [[d:Property:P21|P21]] per aplicar la forma femenina si fos necessari, per defecte <code>item</code>. S'usa en combinació amb case=gender o case=infoboxlabel.
*<code>editicon=</code> (opcional) Defineix si es posa alguna icona. Per defecte és ''true''. Amb valors editicon=false o editicon=no és ''false''. Les icones poden ser: una icona d'etiqueta [[File:Noun Project label icon 1116097 cc mirror.svg|10px|baseline|Tradueix|link=d:Q12069631]] en cas que l'etiqueta no s'hagi trobat en la llengua demanada, i un petit llapis [[File:Arbcom ru editing.svg|10px|baseline|Modifica|link=d:Q12069631#P31]] com a icona per mostrar i poder editar la declaració a Wikitada (en el futur gestionat per [[mw:Wikidata Bridge]]). La icona del llapis es mostrarà si està definida en la configuració pel wiki a [[Module:{{ROOTPAGENAME}}/i18n]] amb el valor ["addpencil"] = true.
*<code>showerrors=</code> (opcional) Amb qualsevol valor mostra el missatge d'error, si n'hi ha cap. Si no està definit mostrarà el paràmetre default en cas d'error.
*<code>default=</code> (opcional) Text a mostrar en cas d'error. No té cap efecte si està definit el paràmetre showerrors. Si no està definit, i tampoc el paràmetre showerrors, retornarà un valor buit en cas d'error.
*<code>sandbox=</code> (opcional) Amb qualsevol valor desvia les crides al [[Module:{{ROOTPAGENAME}}/proves]]. El títol de la subpàgina l'obté de [[MediaWiki:Sandboxlink-subpage-name]], en català "proves". El paràmetre es pot usar en l'entorn de plantilla. Com a paràmetre d'invoke o de require no té sentit per les proves. A usar només provisionalment o en previsualització, el mòdul de proves no hauria de tenir cap enllaç permanent.
=== Paràmetres de formatació ===
<code>formatting=</code> (opcional) Format desitjat. Valors possibles, per a cada tipus de dada:
Dada amb valor d'element (''entity''):
* <code>formatting=raw</code> Número identificador de l'element.
* <code>formatting=label</code> Etiqueta de l'element en la llengua demanada, alguna de les llengües alternatives o bé com a ''raw''.
* <code>formatting=sitelink</code> Títol de la pàgina de la Viquipèdia de l'element, sense enllaç. Si no existeix retorna el format raw amb el prefix d:.
* <code>formatting=internallink</code> Enllaç intern sempre que sigui possible, bé a la pàgina de la Viquipèdia (sitelink) o bé a l'etiqueta (possiblement un enllaç vermell). Com a darrera opció enllaça a Wikidata.
* <code>formatting=''pattern''</code> Format segons un patró usant $1 com a paràmetre a substituir. Pot incloure plantilles o funcions parser amb el format: {{tl|((}}nom-de-la-plantilla<nowiki>{{!}}</nowiki>$1{{tl|))}} o bé {{tl|((}}nom-de-la-plantilla<nowiki>{{!}}</nowiki>nom_paràmetre{{tl|1==}}$1{{tl|))}}, o similar.
: El format per defecte és un enllaç conduït, bé a ''sitelink'' o bé a wikitada:''raw'', usant ''label'' com a etiqueta de l'enllaç.
:* <code>formatting=ucfirst</code> Variant del format per defecte amb majúscula inicial en l'etiqueta. En una llista només posa majúscula en el primer valor.
:* <code>formatting=ucinternallink</code> Combinació del format "ucfirst" i "internallink".
=== Paràmetres de taula de propietat i qualificadors ===
{| class="wikitable" style="float:right;"
! !! propietat !! qualificador1 !! qualificador2 etc.
|-
! valors 1a declaració
| $0 || $1 || $2, etc.
|-
! 2a, etc.
| $0 || $1 || $2, etc.
|}
<code>formatting=table</code> Una declaració amb qualificadors es considera com una taula de valors mostrada a la dreta. Es pot indicar el format de les files i de cada columna de la taula. Els separadors per a cada fila són per defecte salts de línia (vegeu ''separator'' i ''conjunction'' més amunt). Si realment voleu el resultat en una taula wiki podeu usar separator=<nowiki></tr><tr></nowiki> amb les corresponents etiquetes d'apertura i tancament abans i desprès de l'invoke. Paràmetres específics per a aquest format:
Columnes:
* <code>qualifier1 ... qualifier''x''=</code> Qualificadors amb un número consecutiu i il·limitat. El paràmetre general <code>qualifier</code> és un àlies per qualifier1.
** <code>qualifier''x'' = P''id1'' OR P''id2''</code> Definició alternativa d'un qualificador quan el primer no existeix. Un cas d'ús típic és [[d:Property:P585|P585]] OR [[d:Property:P580|P580]]. No hi ha límit per successius OR. Els espais en blanc d'abans i després són opcionals.
** <code>qualifier''x'' = P''id1''/P''id2''</code> De l'element corresponent a P''id1'' (un qualificador o una propietat) obté la propietat superior P''id2''. Permet obtenir dades addicionals en la taula encara que definides en l'element superior. Per exemple, per obtenir les línies de metro amb la seva icona: qualifier=P81/P154. Es pot combinar amb l'opció OR prenent prioritat l'OR.
** <code>qualifier''x'' = /P''id''</code> Equivalent a l'anterior però sense P''id1'', obté una segona propietat del mateix element. Permet obtenir dades definides bé en un qualificador o bé en una propietat.
* <code>colformat0 ... colformat''x''=</code> Format opcional a aplicar a les columnes, usant 0 per la propietat i 1-x pels qualificadors. Accepta la mateixa sintaxi que <code>formatting</code> per a cada tipus de dada. Vegeu més amunt [[#Paràmetres de formatació]].
* <code>case0 ... case''x''=</code> Cas gramatical a aplicar a cada columna. El paràmetre <code>case</code>, sense numeració, s'aplica a tots els valors. Vegeu més amunt [[#Paràmetres generals]].
* <code>convert0 ... convert''x''=</code> Conversió d'unitats a aplicar a cada columna. Vegeu més amunt [[#Paràmetres de formatació]] per format numèric.
* <code>whitelist0 ... whitelist''x''=</code> Llista dels ítems a mostrar per a una columna, usant qualsevol separador.
* <code>blacklist0 ... blacklist''x''=</code> Llista dels ítems que no es mostraran per a una columna, usant qualsevol separador. En cas d'usar whitelist per a una columna i blacklist per a una altra els resultats poden ser inesperats (vegeu un [https://ca.wikipedia.org/w/index.php?title=Tema:Ujnttzn0w9k1x0vq&topic_showPostId=ujsb7o283btc0pix#flow-post-ujsb7o283btc0pix comentari al respecte])
Files:
* <code>rowformat=</code> Format de les files de propietat més qualificadors. La propietat s'indica amb $0 i els qualificadors $1 a $x. Per defecte és <code>rowformat=$0 ($1, ... $x)</code>. Pot incloure marques de llistes * o # i també plantilles o funcions parser amb el format: {{tl|((}}plantilla<nowiki>{{!}}</nowiki>paràmetre<nowiki>{{!}}</nowiki>nom{{tl|1==}}paràmetre{{tl|))}}. En cas d'usar el paràmetre "references" (vegeu [[#Paràmetres generals|més amunt]]) cal indicar on han d'aparèixer les referències amb $R0.
* <code>rowsubformat1 ... rowsubformat''x''=</code> Format previ a aplicar a $1-$x definits en rowformat, només si existeix el valor. Per exemple, "rowformat=$0 $1" i "rowsubformat1=($1)" resulta "$0 ($1)" o bé "$0" si $1 està buit, evitant uns parèntesis buits. Un rowsubformat pot contenir diferents variables $1-$x. Cal tenir en compte que les substitucions en fan de forma seqüencial per ordre numèric, per tant pot incloure un $x posterior però no un d'anterior ja que haurà estat tractat.
* <code>tablesort=</code> amb valors de 0 a x, permet ordenar la taula per la propietat (0) o els qualificadors (1 a x). L'ordenació és ascendent alfabèticament, numèricament o per dates, segons el tipus de dada. Accepta múltiples claus usant qualsevol separador, p. ex. <code>tablesort=0/2/1</code>. Per defecte l'ordenació és pel rang de la propietat (preferent, normal) i per l'antiguitat de definició a Wikidata.
* <code>sorting=-1</code> inverteix l'ordenació fent-la descendent. Amb qualsevol altre valor, o en el seu defecte, l'ordenació és ascendent. En cas de <code>tablesort</code> amb múltiples claus, el criteri de <code>sorting</code> s'aplicarà a totes per igual.
* <code>list=false</code> Treu només la primera fila de la taula, segons l'ordre indicat o l'ordre per defecte.
== Funció getLabel ==
Retorna l'etiqueta d'un element.
* <code>1=</code> (primer paràmetre posicional, requerit) Identificador de l'ítem de Wikidata (Qid o Pid). Àlies: <code>item</code>, <code>from</code>.
* <code>lang=</code> (opcional) Codi de llengua, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
* <code>itemgender=</code> (opcional) Identificador de l'ítem que determina el gènere a usar, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
* <code>linked=</code> (opcional) Amb qualsevol valor, excepte 'no', retorna l'etiqueta enllaçada a l'article local o bé a Wikidata.
* <code>label=</code> (opcional) Treu l'etiqueta indicada. Només té sentit amb linked= per generar un enllaç amb l'etiqueta de label=.
* <code>editicon=</code> (opcional) permet eliminar la icona del llapis, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
== Funció getParentValues ==
Retorna de forma recursiva valors d'una propietat usant com a etiqueta un valor superior. Per exemple pot estraure l'estructura administativa o la classificació de tàxons.
* <code>item=</code> (opcional) Permet indicar un item (Qid) diferent a l'article actiu. Aquest accés arbitrari a Wikidata està limitat pel seu alt consum de recursos.
* <code>property=</code> (opcional) Propietat de la declaració (Pid). Per defecte és [[d:Property:P131|P131]]. Admet una llista de valors alternatius usant qualsevol separador.
* <code>label=</code> (opcional) Propietat superior a usar com a etiqueta. Per defecte és [[d:Property:P31|P31]].
* <code>upto=</code> (opcional) Darrera iteració a extraure, si abans no ha trobat cap propietat no existent. Tipus de valors:
** upto=''etiqueta'': darrera etiqueta a consultar, per exemple "upto=estat".
** upto=''valor numèric'': nombre màxim d'iteracions. Per defecte és 10 com a protecció, normalment un valor més alt del que serà necessari.
* <code>uptolabelid=</code> (opcional) Alternatiu a <code>upto=''etiqueta''</code> usant el Qid.
* <code>uptovalueid=</code> (opcional) Alternatiu a <code>uptolabelid</code> usant el Qid del valor en lloc de l'etiqueta. Admet valors múltiples usant qualsevol separador. Àlies uptolinkid mantingut provisionalment per compatibilitat.
* <code>labelshow=</code> (opcional) Filtre d'etiquetes a mostrar, separades per una barra / si són més d'una. Per exemple "labelshow=municipi/comarca". Mostra el primer valor trobat per a cada etiqueta, sense repeticions posteriors de la mateixa etiqueta.
* <code>showlabelid=</code> (opcional) Alternatiu a <code>labelshow</code> usant Qid i qualsevol separador.
* <code>include_self=true</code> (opcional) Inclou l'etiqueta de la pròpia pàgina en la llista generada.
* <code>sorting=-1</code> (opcional) Ordenació descendent de la llista.
* <code>last_only=true</code> (opcional) Només mostra el darrer valor obtingut. Per exemple amb uptolinkid=Qid només mostrarà el valor corresponent a Qid.
* <code>formatting=</code> (opcional) Format del valor de la propietat. Per defecte és un enllaç conduït local o a Wikidata (vegeu més amunt [[#Paràmetres de formatació|formatting]] de la funció claim per valors ''entity'').
* <code>valuetext=</code> (opcional) Propietat a usar com a text de l'enllaç amb el valor 'property' com a enllaç conduït.
* <code>labelformat=</code> (opcional) Format de l'etiqueta. Per defecte és "label" (vegeu més amunt [[#Paràmetres de formatació|formatting]] de la funció claim per valors ''entity'').
* <code>rowformat=</code> (opcional) Format de sortida per a cada parell de valors obtingut, indicant $0 per l'etiqueta i $1 pel valor. Per defecte és "rowformat=$0 = $1" mostrant per exemple "comarca = <nowiki>[[Maresme]]</nowiki>"
* <code>separator=</code> (opcional) Separador per a cada parell de valors obtingut, per defecte és <nowiki><br /></nowiki>.
* <code>cascade=true</code> (opcional) opció de presentació amb sagnat. Pot ser útil quan només s'utilitza $1 a rowformat.
Nota: les etiquetes es modifiquen amb un format adequat a les necessitats d'una infotaula segons les definicions a [[Module:{{ROOTPAGENAME}}/labels]]. Per exemple, "municipi del Brasil" es presenta com a "Municipi".
== Funció linkWithParentLabel ==
Crea un enllaç amb l'etiqueta d'una propietat superior.
Accepta la majoria de paràmetres de la funció [[#Funció claim|claim]], excepte "formatting" que usa el valor per defecte "internallink". Addicionalment:
* <code>parent=</code> és la propietat a usar en l'etiqueta corresponent a l'ítem superior del valor obtingut per "property/qualifier". Accepta valors alternatius amb qualsevol separador, igual que el paràmetre "property" de la funció claim.
== Utilitats ==
* <code>getSiteLink</code> Retorna el títol de pàgina local per un element donat. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|getSiteLink|<Qid>|<wiki>}}</nowiki></code>
*: Sense cap paràmetre retorna la pròpia pàgina. Proporcionant l'id retornarà la pàgina local enllaçada en l'element corresponent. En cas de no existir o ser erroni no retorna res. Amb un segon paràmetre amb un codi de wiki obté la pàgina en el wiki especificat (enwiki, frwiki,... cawiktionary, etc.)
* <code>lang</code> Retorna el codi de llengua tal com el gestiona la funció claim. Vegeu [[#Paràmetres generals]] més amunt. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|lang|{{{lang|}}}}}</nowiki></code>
*: El paràmetre <code>lang</code> és el codi de la llengua aportat explícitament.
* <code>numStatements</code> Retorna el nombre de declaracions que té una propietat multi-valor, comptant les de rang més alt. Permet decidir el tractament a donar a llistes llargues. Amb un segon paràmetre compta el nombre de declaracions d'un qualificador. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|<Pid>|item={{{item|}}} }}</nowiki></code>
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|<Pid>|<Qual_id>|item={{{item|}}} }}</nowiki></code>
*: Exemple: <nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|P47|item=Q1861}}</nowiki> → {{#invoke:{{ROOTPAGENAME}}|numStatements|P47|item=Q1861}}
* <code>validProperty</code> Retorna "null" si la propietat no existeix, o només té valors amb marcador "sense valor" o "valor desconegut" o obsolet. Sintaxi:
*: <code><nowiki>{{#invoke:<nowiki>{{ROOTPAGENAME}}<nowiki>|validProperty|<Pid>|item={{{item|}}}</nowiki></code>
*: Es pot usar com a alternativa a #property. Per compatibilitat amb aquesta funció parser, el paràmetre <code>from</code> és un àlies de <code>item</code>.
* Per a funcions de depuració vegeu [[Module:{{BASEPAGENAME}}/debug]].
== Redireccions a Wikidata ==
Un element de Wikidata pot ser una redirecció a un altre element, sovint com a resultat d'una fusió. Els valors d'una propietat poden ser provisionalment una redirecció, normalment corregit per bot al cap d'una setmana. El tractament de les redireccions és el següent:
* Funció claim
** Amb formatting=raw no retorna el Qid redirigit sinó el Qid final de la redirecció.
** Amb paràmetres whitelist o blacklist, si la llista de valors inclou alguna redirecció, considera tant el Qid redirigit com el nou Qid final.
* Funció getLabel
** Si es demana l'etiqueta d'un Qid redirigit, la buscarà en el Qid final.
En tots els casos afegeix un rastreig per poder corregir en les plantilles els Qid redirigits. Es poden trobar a [[Special:WhatLinksHere/Template:Track/wikidata/redirect]].
La resolució de redireccions a Wikidata està pendent de [[phab:T157868]]. La solució tècnica adoptada provisionalment pot provocar un alt consum de recursos si un element no té cap etiqueta en la llengua local ni en les llengües alternatives. Es recomana comprovar el rastreig [[Special:WhatLinksHere/Template:Track/wikidata/label]] per afegir les etiquetes que manquen.
==Crides des d'un altre mòdul==
Totes les funcions (claim, getLabel, getParentValues, linkWithParentLabel, lang) es poden cridar des d'altres mòduls via <code>require</code> amb els mateixos paràmetres proporcionats en una taula, per exemple:
:<nowiki>require("Module:</nowiki>{{ROOTPAGENAME}}<nowiki>").claim{item="Q...", property="P...", ...}</nowiki>
:<nowiki>require("Module:</nowiki>{{ROOTPAGENAME}}<nowiki>").getLabel({"Q...", ['lang']="ca"})</nowiki>
Les funcions claim i getLabel retornen com a segon valor la variable untranslated (nil o true) per a tractament específic en mòduls d'infotaules.
== Exemples ==
Els exemples a continuació són mostres provades en les pàgines corresponents. Es poden fer proves a [[w:Viquipèdia:Proves de Wikidata]], comprovacions en previsualització d'una pàgina o usar el paràmetre <code>item</code> per un element de Wikidata diferent de la pàgina actual.
*Ús simple:
:<nowiki>{{#invoke:Wikidata | claim |property=P20}}</nowiki> a l'article [[w:Jean-François Champollion]] dóna: {{#invoke:Wikidata | claim |property=P20|item=Q260|showerrors=sip}}
:és la propietat [[d:Property:P20|P20]], per defecte amb el valor enllaçat.
*Sense enllaç:
:<nowiki>{{#invoke:Wikidata | claim | property=P20 | formatting=label}}</nowiki> dóna: {{#invoke:Wikidata | claim | property=P20 | formatting=label|item=Q260|showerrors=sip}}
*Valor preferent:
:<nowiki>{{#invoke:Wikidata | claim | property=P20 | value={{{lloc_mort|}}} }}</nowiki> en la infotaula de l'article donarà
:el valor de <nowiki>{{{lloc_mort|}}}</nowiki> si està definit en l'article, en cas contrari [[París]]
*Valor tipus data:
:<nowiki>{{#invoke:Wikidata | claim | property=P569}}</nowiki> dóna la data de naixement amb el format per defecte:
: {{#invoke:Wikidata | claim | property=P569|item=Q260|showerrors=sip}}
*Formatat amb un patró:
:<nowiki>{{#invoke:Wikidata | claim | property=P214 | formatting=[http://viaf.org/viaf/$1 $1]}}</nowiki> dóna:
:{{#invoke:Wikidata | claim | property=P214 | formatting=[http://viaf.org/viaf/$1 $1]|item=Q260|showerrors=sip}}
*Llista de valors:
:<nowiki>{{#invoke:Wikidata | claim | property=P47}}</nowiki> a [[Alcoià]] dóna:
: {{#invoke:Wikidata | claim | property=P47 | item=Q746061 |showerrors=sip}}
:Cal notar l'enllaç conduït <nowiki>[[Comtat (País Valencià)|Comtat]]</nowiki>
*Llista formatada:
:<nowiki>{{#invoke:Wikidata | claim | property=P150 | separator=<br /> | conjunction=<br />}}</nowiki> dóna
: {{#invoke:Wikidata | claim | property=P150 | separator=<br /> | conjunction=<br /> | item=Q746061 |showerrors=sip}}
== Dependències ==
* Subpàgines relatives al mòdul principal. El títol del mòdul està definit a la variable <code>module_title = </code>. En una nova instal·lació amb un títol diferent cal modificar aquesta variable.
** [[Module:{{ROOTPAGENAME}}/i18n|../i18n]] (opcional): traduccions de missatges i formats locals. Si s'usa <code>lang</code> diferent al local cerca la subpàgina corresponent, per exemple [[Module:{{BASEPAGENAME}}/i18n/eu|../i18n/eu]]. Si no existeix, surt en anglès per defecte.
** [[Module:{{ROOTPAGENAME}}/Units|../Units]] (opcional): tractament d'unitats, en plural o amb codi. Si no existeix, treu el nom complet de la unitat en singular.
** [[Module:{{ROOTPAGENAME}}/labels|../labels]] (opcional): excepcions i correccions d'etiquetes per a una infotaula.
** [[Module:{{ROOTPAGENAME}}/debug|../debug]]: pot aparèixer ocasionalment per la funció track de manteniment.
* Missatges Mediawiki utilitzats depenent de la llengua:
** [[Mediawiki:Comma-separator]], [[Mediawiki:And]], [[Mediawiki:Word-separator]]
** [[Mediawiki:Wikibase-snakview-snaktypeselector-novalue]], [[Mediawiki:Wikibase-snakview-snaktypeselector-somevalue]]
** [[Mediawiki:Wikibase-time-calendar-gregorian]], [[Mediawiki:Wikibase-time-calendar-julian]]
** [[Mediawiki:Translate-taction-translate]]
** [[MediaWiki:Sandboxlink-subpage-name]]
*: Si és necessari es poden crear, o modificar, a [[m:translatewiki.net|Translatewiki]]. Per accedir-hi directament activeu l'enllaç corresponent amb el títol del missatge i el codi de llengua <code><nowiki>[[translatewiki:MediaWiki:</nowiki>''<missatge>''/''<lang>'']]</code>.
==Vegeu també==
* [[mw:Extension:Wikibase Client/Lua|Llibreria mw.wikibase]] (funcions bàsiques).
<includeonly>
[[Categoria:Mòduls de Viquitexts]]
</includeonly>
45lhncqyf5n4h193ic9utql89aybfcy
184389
184386
2026-05-14T21:34:01Z
Aleator
20
/* Dependències */ - /Units
184389
wikitext
text/x-wiki
<!-- SI US PLAU, AFEGIU LES CATEGORIES AL FINAL D'AQUESTA PÀGINA I ELS INTERWIKIS A WIKIDATA -->
Aquest mòdul extrau dades formatades de Wikidata. Funciona en la llengua local del wiki, o en una llengua específica per a proves, i té opcions de configuració.
== Funcions ==
Funció bàsica:
* <code>[[#Funció claim|claim]]</code>: Retorna el valor (o els valors) d'una declaració o d'un qualificador formatat amb paràmetres o amb un format per defecte segons el tipus de dada.
Altres funcions:
* <code>[[#Funció getLabel|getLabel]]</code>: retorna una etiqueta en la llengua especificada, o la llengua per defecte.
* <code>[[#Funció getParentValues|getParentValues]]</code>: retorna etiquetes i valors superiors d'una propietat de forma recursiva.
* <code>[[#Funció linkWithParentLabel|linkWithParentLabel]]</code>: crea un enllaç amb l'etiqueta d'una propietat superior. Per exemple per enllaçar [[d:Property:P405|P405]] amb l'etiqueta [[d:Property:P835|P835]] definida en el corresponent ítem superior.
Altres [[#Utilitats|utilitats]]: getSiteLink, lang, numStatements.
== Funció claim ==
Retorna el valor (o els valors) d'una declaració o d'un qualificador formatat amb paràmetres o amb un format per defecte segons el tipus de dada. Per defecte està referit a l'ítem de Wikidata (Qid) associat a la pàgina actual.
Sintaxi completa:
:<code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|claim|item= |lang= |property= |qualifier= |value= |list= |tablesort= |formatting= |separator= |conjunction= |editicon= |showerrors= |default= }}</nowiki></code>
Sintaxi addicional pel format de taula:
:<code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|claim|item= |lang= |property= |qualifier= |qualifier2= |...|qualifier</nowiki>''x''<nowiki>= |formatting=table |tablesort= |sorting= |rowformat= |rowsubformat1= |...|rowsubformat</nowiki>''x''<nowiki>= |colformat0= |...|colformat</nowiki>''x''<nowiki>= |case0= |...|case</nowiki>''x''<nowiki>= |separator= |conjunction= |editicon= |showerrors= |default= |references= }}</nowiki></code>
=== Paràmetres generals ===
*<code>item=</code> (opcional) Permet indicar un ítem (Qid) diferent a l'ítem associat a la pàgina actual. Cal fer-lo servir <u>amb moderació</u> pel seu <u>alt consum</u> de recursos. Es pot usar també com a paràmetre de l'entorn superior de la plantilla. Té com a àlies <code>from</code>.
*<code>lang=</code> (opcional) Permet indicar el codi d'una llengua determinada. Es pot usar també com a paràmetre de l'entorn superior de la plantilla. Per defecte usa la llengua local del wiki per a l'espai principal d'articles o la llengua d'usuari definida en les preferències per a altres espais de noms. Si no troba el valor en aquesta llengua ho intenta en les llengües alternatives definides en el MediaWiki. Per exemple per català les llengües alternatives són occità i anglès. En cas que el valor no s'hagi trobat en la llengua demanada, hi afegeix el codi de llengua i una icona d'etiqueta per a traduir-ho a Wikidata. Aquesta icona es pot eliminar amb el paràmetre editicon.
*<code>property=</code> (obligatori) Identificador de la propietat de la declaració (Pid). Es poden definir diferents propietats alternatives amb qualsevol separador, per exemple "P17 o P131", i obtindrà la primera que trobi. Accepta també una p minúscula, però no és recomanat. Igualment accepta l'etiqueta de la propietat, per exemple property=estat equival a property=P17 per la propietat [[d:Property:P17|P17]].
*<code>qualifier=</code> (opcional) Qualificador (Pid) del valor de la propietat.
*<code>value=</code> (opcional) Valor preferent al de Wikidata. Pot ser un paràmetre opcional en una plantilla amb el format <nowiki>{{{paràmetre|}}}</nowiki>, així si existeix pren el valor del paràmetre i si està buit llavors obté el valor de Wikidata.
** <code>value=NONE</code> Amb aquest valor no treu res de Wikidata. Permet configurar un paràmetre per a que no tregui cap valor de Wikidata, o bé treure només valors informats en la plantilla amb <code><nowiki>{{{paràmetre|NONE}}}</nowiki></code>. És equivalent a la sintaxi wiki: <code><nowiki>{{#ifeq:{{{paràmetre|}}}|NONE|<!-- no res -->}}</nowiki></code>.
*<code>references=</code> (opcional) Amb qualsevol valor mostrarà les referències del valor obtingut. Si troba [[d:Property:P854|P854]] més o bé [[d:Property:P1476|P1476]] o bé [[d:Property:P248|P248]] llavors ho formata amb la versió local de [[d:Q5637226|Q5637226]] i amb els paràmetres traduïts a la taula i18n["cite"] de [[Module:{{ROOTPAGENAME}}/i18n]]. Si troba [[d:Property:P1433|P1433]], més títol o afirmat, llavors ho formata amb [[d:Q5624899|Q5624899]]}. En cas contrari ho formata com a text.
*: En cas d'usar-ho amb formatting=table (vegeu [[#Paràmetres de taula de propietat i qualificadors|més avall]]) cal definir on han d'aparèixer les referències en el paràmetre "rowformat".
*<code>list=</code> (opcional):
** <code>list=true</code> (per defecte) Mostra una llista de tots els valors preferents i normals (vegeu ''separator'' i ''conjuction'' més avall). En cap cas obté els valors obsolets.
** <code>list=false</code> o <code>list=no</code> Mostra només un valor, el de rang més alt segons l'ordre preferent/normal, o el més antic dels que tenen el rang més alt.
** <code>list=bestrank</code> Mostra una llista dels valors amb el rang més alt. És equivalent a list=true si tots tenen el mateix rang. És equivalent a list=false si només hi ha un valor amb el rang més alt. El valor <code>firstrank</code> és un àlies.
** <code>list=lang</code> En cas de valors monolingües només treu els corresponents a la llengua del paràmetre lang. Vegeu el paràmetre lang.
** <code>list=''<número>''</code> Número màxim de valors a llistar. Amb list=1 és equivalent a list=false. Amb list=0 és equivalent a list=true.
** <code>tablesort=0</code> (opcional) ordenació ascendent de la llista. Per defecte l'ordenació és pel rang (preferent, normal) i per l'antiguitat de definició a Wikidata.
* <code>separator=</code> (opcional) Separador a usar en llistes o taules. En cas de llistes, per defecte és [[MediaWiki:Comma-separator]], en català una coma i un espai en blanc ', '. En cas de taules per defecte és un salt de línia <nowiki><br /></nowiki>. En algun cas, si s'inclou en etiquetes que usen [[mw:Strip marker|strip markers]], pot ser que un <nowiki><br /></nowiki> no funcioni. L'alternativa és usar separator=LF per a un caràcter de control [[w:salt de línia|line feed]].
* <code>conjunction=</code> (opcional) Conjunció a usar com a separador diferent entre els dos últims elements de la llista. Per defecte és igual a separator si està definit i si no és [[MediaWiki:And]] més [[MediaWiki:Word-separator]], en català ' i '. En el cas de taules per defecte és un salt de línia <nowiki><br /></nowiki>.
*<code>case=</code> (opcional) Cas gramatical a generar, depenent de la llengua local, o canvis a aplicar en el wiki local definits a [[Module:{{ROOTPAGENAME}}/i18n]]. Com a casos generals tractats pel mòdul:
** case=gender, segons la definició de [[d:Property:P21|P21]] de l'element (pàgina actual, item o itemgender) treu el valor de [[d:Property:P2521|P2521]].
** case=smallcaps, treu l'etiqueta en versaleta.
*: Vegeu la documentació de [[Module:{{ROOTPAGENAME}}/i18n]] per a altres casos locals.
*<code>itemgender=</code> (opcional) Element on es comprova [[d:Property:P21|P21]] per aplicar la forma femenina si fos necessari, per defecte <code>item</code>. S'usa en combinació amb case=gender o case=infoboxlabel.
*<code>editicon=</code> (opcional) Defineix si es posa alguna icona. Per defecte és ''true''. Amb valors editicon=false o editicon=no és ''false''. Les icones poden ser: una icona d'etiqueta [[File:Noun Project label icon 1116097 cc mirror.svg|10px|baseline|Tradueix|link=d:Q12069631]] en cas que l'etiqueta no s'hagi trobat en la llengua demanada, i un petit llapis [[File:Arbcom ru editing.svg|10px|baseline|Modifica|link=d:Q12069631#P31]] com a icona per mostrar i poder editar la declaració a Wikitada (en el futur gestionat per [[mw:Wikidata Bridge]]). La icona del llapis es mostrarà si està definida en la configuració pel wiki a [[Module:{{ROOTPAGENAME}}/i18n]] amb el valor ["addpencil"] = true.
*<code>showerrors=</code> (opcional) Amb qualsevol valor mostra el missatge d'error, si n'hi ha cap. Si no està definit mostrarà el paràmetre default en cas d'error.
*<code>default=</code> (opcional) Text a mostrar en cas d'error. No té cap efecte si està definit el paràmetre showerrors. Si no està definit, i tampoc el paràmetre showerrors, retornarà un valor buit en cas d'error.
*<code>sandbox=</code> (opcional) Amb qualsevol valor desvia les crides al [[Module:{{ROOTPAGENAME}}/proves]]. El títol de la subpàgina l'obté de [[MediaWiki:Sandboxlink-subpage-name]], en català "proves". El paràmetre es pot usar en l'entorn de plantilla. Com a paràmetre d'invoke o de require no té sentit per les proves. A usar només provisionalment o en previsualització, el mòdul de proves no hauria de tenir cap enllaç permanent.
=== Paràmetres de formatació ===
<code>formatting=</code> (opcional) Format desitjat. Valors possibles, per a cada tipus de dada:
Dada amb valor d'element (''entity''):
* <code>formatting=raw</code> Número identificador de l'element.
* <code>formatting=label</code> Etiqueta de l'element en la llengua demanada, alguna de les llengües alternatives o bé com a ''raw''.
* <code>formatting=sitelink</code> Títol de la pàgina de la Viquipèdia de l'element, sense enllaç. Si no existeix retorna el format raw amb el prefix d:.
* <code>formatting=internallink</code> Enllaç intern sempre que sigui possible, bé a la pàgina de la Viquipèdia (sitelink) o bé a l'etiqueta (possiblement un enllaç vermell). Com a darrera opció enllaça a Wikidata.
* <code>formatting=''pattern''</code> Format segons un patró usant $1 com a paràmetre a substituir. Pot incloure plantilles o funcions parser amb el format: {{tl|((}}nom-de-la-plantilla<nowiki>{{!}}</nowiki>$1{{tl|))}} o bé {{tl|((}}nom-de-la-plantilla<nowiki>{{!}}</nowiki>nom_paràmetre{{tl|1==}}$1{{tl|))}}, o similar.
: El format per defecte és un enllaç conduït, bé a ''sitelink'' o bé a wikitada:''raw'', usant ''label'' com a etiqueta de l'enllaç.
:* <code>formatting=ucfirst</code> Variant del format per defecte amb majúscula inicial en l'etiqueta. En una llista només posa majúscula en el primer valor.
:* <code>formatting=ucinternallink</code> Combinació del format "ucfirst" i "internallink".
=== Paràmetres de taula de propietat i qualificadors ===
{| class="wikitable" style="float:right;"
! !! propietat !! qualificador1 !! qualificador2 etc.
|-
! valors 1a declaració
| $0 || $1 || $2, etc.
|-
! 2a, etc.
| $0 || $1 || $2, etc.
|}
<code>formatting=table</code> Una declaració amb qualificadors es considera com una taula de valors mostrada a la dreta. Es pot indicar el format de les files i de cada columna de la taula. Els separadors per a cada fila són per defecte salts de línia (vegeu ''separator'' i ''conjunction'' més amunt). Si realment voleu el resultat en una taula wiki podeu usar separator=<nowiki></tr><tr></nowiki> amb les corresponents etiquetes d'apertura i tancament abans i desprès de l'invoke. Paràmetres específics per a aquest format:
Columnes:
* <code>qualifier1 ... qualifier''x''=</code> Qualificadors amb un número consecutiu i il·limitat. El paràmetre general <code>qualifier</code> és un àlies per qualifier1.
** <code>qualifier''x'' = P''id1'' OR P''id2''</code> Definició alternativa d'un qualificador quan el primer no existeix. Un cas d'ús típic és [[d:Property:P585|P585]] OR [[d:Property:P580|P580]]. No hi ha límit per successius OR. Els espais en blanc d'abans i després són opcionals.
** <code>qualifier''x'' = P''id1''/P''id2''</code> De l'element corresponent a P''id1'' (un qualificador o una propietat) obté la propietat superior P''id2''. Permet obtenir dades addicionals en la taula encara que definides en l'element superior. Per exemple, per obtenir les línies de metro amb la seva icona: qualifier=P81/P154. Es pot combinar amb l'opció OR prenent prioritat l'OR.
** <code>qualifier''x'' = /P''id''</code> Equivalent a l'anterior però sense P''id1'', obté una segona propietat del mateix element. Permet obtenir dades definides bé en un qualificador o bé en una propietat.
* <code>colformat0 ... colformat''x''=</code> Format opcional a aplicar a les columnes, usant 0 per la propietat i 1-x pels qualificadors. Accepta la mateixa sintaxi que <code>formatting</code> per a cada tipus de dada. Vegeu més amunt [[#Paràmetres de formatació]].
* <code>case0 ... case''x''=</code> Cas gramatical a aplicar a cada columna. El paràmetre <code>case</code>, sense numeració, s'aplica a tots els valors. Vegeu més amunt [[#Paràmetres generals]].
* <code>convert0 ... convert''x''=</code> Conversió d'unitats a aplicar a cada columna. Vegeu més amunt [[#Paràmetres de formatació]] per format numèric.
* <code>whitelist0 ... whitelist''x''=</code> Llista dels ítems a mostrar per a una columna, usant qualsevol separador.
* <code>blacklist0 ... blacklist''x''=</code> Llista dels ítems que no es mostraran per a una columna, usant qualsevol separador. En cas d'usar whitelist per a una columna i blacklist per a una altra els resultats poden ser inesperats (vegeu un [https://ca.wikipedia.org/w/index.php?title=Tema:Ujnttzn0w9k1x0vq&topic_showPostId=ujsb7o283btc0pix#flow-post-ujsb7o283btc0pix comentari al respecte])
Files:
* <code>rowformat=</code> Format de les files de propietat més qualificadors. La propietat s'indica amb $0 i els qualificadors $1 a $x. Per defecte és <code>rowformat=$0 ($1, ... $x)</code>. Pot incloure marques de llistes * o # i també plantilles o funcions parser amb el format: {{tl|((}}plantilla<nowiki>{{!}}</nowiki>paràmetre<nowiki>{{!}}</nowiki>nom{{tl|1==}}paràmetre{{tl|))}}. En cas d'usar el paràmetre "references" (vegeu [[#Paràmetres generals|més amunt]]) cal indicar on han d'aparèixer les referències amb $R0.
* <code>rowsubformat1 ... rowsubformat''x''=</code> Format previ a aplicar a $1-$x definits en rowformat, només si existeix el valor. Per exemple, "rowformat=$0 $1" i "rowsubformat1=($1)" resulta "$0 ($1)" o bé "$0" si $1 està buit, evitant uns parèntesis buits. Un rowsubformat pot contenir diferents variables $1-$x. Cal tenir en compte que les substitucions en fan de forma seqüencial per ordre numèric, per tant pot incloure un $x posterior però no un d'anterior ja que haurà estat tractat.
* <code>tablesort=</code> amb valors de 0 a x, permet ordenar la taula per la propietat (0) o els qualificadors (1 a x). L'ordenació és ascendent alfabèticament, numèricament o per dates, segons el tipus de dada. Accepta múltiples claus usant qualsevol separador, p. ex. <code>tablesort=0/2/1</code>. Per defecte l'ordenació és pel rang de la propietat (preferent, normal) i per l'antiguitat de definició a Wikidata.
* <code>sorting=-1</code> inverteix l'ordenació fent-la descendent. Amb qualsevol altre valor, o en el seu defecte, l'ordenació és ascendent. En cas de <code>tablesort</code> amb múltiples claus, el criteri de <code>sorting</code> s'aplicarà a totes per igual.
* <code>list=false</code> Treu només la primera fila de la taula, segons l'ordre indicat o l'ordre per defecte.
== Funció getLabel ==
Retorna l'etiqueta d'un element.
* <code>1=</code> (primer paràmetre posicional, requerit) Identificador de l'ítem de Wikidata (Qid o Pid). Àlies: <code>item</code>, <code>from</code>.
* <code>lang=</code> (opcional) Codi de llengua, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
* <code>itemgender=</code> (opcional) Identificador de l'ítem que determina el gènere a usar, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
* <code>linked=</code> (opcional) Amb qualsevol valor, excepte 'no', retorna l'etiqueta enllaçada a l'article local o bé a Wikidata.
* <code>label=</code> (opcional) Treu l'etiqueta indicada. Només té sentit amb linked= per generar un enllaç amb l'etiqueta de label=.
* <code>editicon=</code> (opcional) permet eliminar la icona del llapis, com en la funció claim. Vegeu més amunt [[#Paràmetres generals]].
== Funció getParentValues ==
Retorna de forma recursiva valors d'una propietat usant com a etiqueta un valor superior. Per exemple pot estraure l'estructura administativa o la classificació de tàxons.
* <code>item=</code> (opcional) Permet indicar un item (Qid) diferent a l'article actiu. Aquest accés arbitrari a Wikidata està limitat pel seu alt consum de recursos.
* <code>property=</code> (opcional) Propietat de la declaració (Pid). Per defecte és [[d:Property:P131|P131]]. Admet una llista de valors alternatius usant qualsevol separador.
* <code>label=</code> (opcional) Propietat superior a usar com a etiqueta. Per defecte és [[d:Property:P31|P31]].
* <code>upto=</code> (opcional) Darrera iteració a extraure, si abans no ha trobat cap propietat no existent. Tipus de valors:
** upto=''etiqueta'': darrera etiqueta a consultar, per exemple "upto=estat".
** upto=''valor numèric'': nombre màxim d'iteracions. Per defecte és 10 com a protecció, normalment un valor més alt del que serà necessari.
* <code>uptolabelid=</code> (opcional) Alternatiu a <code>upto=''etiqueta''</code> usant el Qid.
* <code>uptovalueid=</code> (opcional) Alternatiu a <code>uptolabelid</code> usant el Qid del valor en lloc de l'etiqueta. Admet valors múltiples usant qualsevol separador. Àlies uptolinkid mantingut provisionalment per compatibilitat.
* <code>labelshow=</code> (opcional) Filtre d'etiquetes a mostrar, separades per una barra / si són més d'una. Per exemple "labelshow=municipi/comarca". Mostra el primer valor trobat per a cada etiqueta, sense repeticions posteriors de la mateixa etiqueta.
* <code>showlabelid=</code> (opcional) Alternatiu a <code>labelshow</code> usant Qid i qualsevol separador.
* <code>include_self=true</code> (opcional) Inclou l'etiqueta de la pròpia pàgina en la llista generada.
* <code>sorting=-1</code> (opcional) Ordenació descendent de la llista.
* <code>last_only=true</code> (opcional) Només mostra el darrer valor obtingut. Per exemple amb uptolinkid=Qid només mostrarà el valor corresponent a Qid.
* <code>formatting=</code> (opcional) Format del valor de la propietat. Per defecte és un enllaç conduït local o a Wikidata (vegeu més amunt [[#Paràmetres de formatació|formatting]] de la funció claim per valors ''entity'').
* <code>valuetext=</code> (opcional) Propietat a usar com a text de l'enllaç amb el valor 'property' com a enllaç conduït.
* <code>labelformat=</code> (opcional) Format de l'etiqueta. Per defecte és "label" (vegeu més amunt [[#Paràmetres de formatació|formatting]] de la funció claim per valors ''entity'').
* <code>rowformat=</code> (opcional) Format de sortida per a cada parell de valors obtingut, indicant $0 per l'etiqueta i $1 pel valor. Per defecte és "rowformat=$0 = $1" mostrant per exemple "comarca = <nowiki>[[Maresme]]</nowiki>"
* <code>separator=</code> (opcional) Separador per a cada parell de valors obtingut, per defecte és <nowiki><br /></nowiki>.
* <code>cascade=true</code> (opcional) opció de presentació amb sagnat. Pot ser útil quan només s'utilitza $1 a rowformat.
Nota: les etiquetes es modifiquen amb un format adequat a les necessitats d'una infotaula segons les definicions a [[Module:{{ROOTPAGENAME}}/labels]]. Per exemple, "municipi del Brasil" es presenta com a "Municipi".
== Funció linkWithParentLabel ==
Crea un enllaç amb l'etiqueta d'una propietat superior.
Accepta la majoria de paràmetres de la funció [[#Funció claim|claim]], excepte "formatting" que usa el valor per defecte "internallink". Addicionalment:
* <code>parent=</code> és la propietat a usar en l'etiqueta corresponent a l'ítem superior del valor obtingut per "property/qualifier". Accepta valors alternatius amb qualsevol separador, igual que el paràmetre "property" de la funció claim.
== Utilitats ==
* <code>getSiteLink</code> Retorna el títol de pàgina local per un element donat. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|getSiteLink|<Qid>|<wiki>}}</nowiki></code>
*: Sense cap paràmetre retorna la pròpia pàgina. Proporcionant l'id retornarà la pàgina local enllaçada en l'element corresponent. En cas de no existir o ser erroni no retorna res. Amb un segon paràmetre amb un codi de wiki obté la pàgina en el wiki especificat (enwiki, frwiki,... cawiktionary, etc.)
* <code>lang</code> Retorna el codi de llengua tal com el gestiona la funció claim. Vegeu [[#Paràmetres generals]] més amunt. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|lang|{{{lang|}}}}}</nowiki></code>
*: El paràmetre <code>lang</code> és el codi de la llengua aportat explícitament.
* <code>numStatements</code> Retorna el nombre de declaracions que té una propietat multi-valor, comptant les de rang més alt. Permet decidir el tractament a donar a llistes llargues. Amb un segon paràmetre compta el nombre de declaracions d'un qualificador. Sintaxi:
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|<Pid>|item={{{item|}}} }}</nowiki></code>
*: <code><nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|<Pid>|<Qual_id>|item={{{item|}}} }}</nowiki></code>
*: Exemple: <nowiki>{{#invoke:</nowiki>{{ROOTPAGENAME}}<nowiki>|numStatements|P47|item=Q1861}}</nowiki> → {{#invoke:{{ROOTPAGENAME}}|numStatements|P47|item=Q1861}}
* <code>validProperty</code> Retorna "null" si la propietat no existeix, o només té valors amb marcador "sense valor" o "valor desconegut" o obsolet. Sintaxi:
*: <code><nowiki>{{#invoke:<nowiki>{{ROOTPAGENAME}}<nowiki>|validProperty|<Pid>|item={{{item|}}}</nowiki></code>
*: Es pot usar com a alternativa a #property. Per compatibilitat amb aquesta funció parser, el paràmetre <code>from</code> és un àlies de <code>item</code>.
* Per a funcions de depuració vegeu [[Module:{{BASEPAGENAME}}/debug]].
== Redireccions a Wikidata ==
Un element de Wikidata pot ser una redirecció a un altre element, sovint com a resultat d'una fusió. Els valors d'una propietat poden ser provisionalment una redirecció, normalment corregit per bot al cap d'una setmana. El tractament de les redireccions és el següent:
* Funció claim
** Amb formatting=raw no retorna el Qid redirigit sinó el Qid final de la redirecció.
** Amb paràmetres whitelist o blacklist, si la llista de valors inclou alguna redirecció, considera tant el Qid redirigit com el nou Qid final.
* Funció getLabel
** Si es demana l'etiqueta d'un Qid redirigit, la buscarà en el Qid final.
En tots els casos afegeix un rastreig per poder corregir en les plantilles els Qid redirigits. Es poden trobar a [[Special:WhatLinksHere/Template:Track/wikidata/redirect]].
La resolució de redireccions a Wikidata està pendent de [[phab:T157868]]. La solució tècnica adoptada provisionalment pot provocar un alt consum de recursos si un element no té cap etiqueta en la llengua local ni en les llengües alternatives. Es recomana comprovar el rastreig [[Special:WhatLinksHere/Template:Track/wikidata/label]] per afegir les etiquetes que manquen.
==Crides des d'un altre mòdul==
Totes les funcions (claim, getLabel, getParentValues, linkWithParentLabel, lang) es poden cridar des d'altres mòduls via <code>require</code> amb els mateixos paràmetres proporcionats en una taula, per exemple:
:<nowiki>require("Module:</nowiki>{{ROOTPAGENAME}}<nowiki>").claim{item="Q...", property="P...", ...}</nowiki>
:<nowiki>require("Module:</nowiki>{{ROOTPAGENAME}}<nowiki>").getLabel({"Q...", ['lang']="ca"})</nowiki>
Les funcions claim i getLabel retornen com a segon valor la variable untranslated (nil o true) per a tractament específic en mòduls d'infotaules.
== Exemples ==
Els exemples a continuació són mostres provades en les pàgines corresponents. Es poden fer proves a [[w:Viquipèdia:Proves de Wikidata]], comprovacions en previsualització d'una pàgina o usar el paràmetre <code>item</code> per un element de Wikidata diferent de la pàgina actual.
*Ús simple:
:<nowiki>{{#invoke:Wikidata | claim |property=P20}}</nowiki> a l'article [[w:Jean-François Champollion]] dóna: {{#invoke:Wikidata | claim |property=P20|item=Q260|showerrors=sip}}
:és la propietat [[d:Property:P20|P20]], per defecte amb el valor enllaçat.
*Sense enllaç:
:<nowiki>{{#invoke:Wikidata | claim | property=P20 | formatting=label}}</nowiki> dóna: {{#invoke:Wikidata | claim | property=P20 | formatting=label|item=Q260|showerrors=sip}}
*Valor preferent:
:<nowiki>{{#invoke:Wikidata | claim | property=P20 | value={{{lloc_mort|}}} }}</nowiki> en la infotaula de l'article donarà
:el valor de <nowiki>{{{lloc_mort|}}}</nowiki> si està definit en l'article, en cas contrari [[París]]
*Valor tipus data:
:<nowiki>{{#invoke:Wikidata | claim | property=P569}}</nowiki> dóna la data de naixement amb el format per defecte:
: {{#invoke:Wikidata | claim | property=P569|item=Q260|showerrors=sip}}
*Formatat amb un patró:
:<nowiki>{{#invoke:Wikidata | claim | property=P214 | formatting=[http://viaf.org/viaf/$1 $1]}}</nowiki> dóna:
:{{#invoke:Wikidata | claim | property=P214 | formatting=[http://viaf.org/viaf/$1 $1]|item=Q260|showerrors=sip}}
*Llista de valors:
:<nowiki>{{#invoke:Wikidata | claim | property=P47}}</nowiki> a [[Alcoià]] dóna:
: {{#invoke:Wikidata | claim | property=P47 | item=Q746061 |showerrors=sip}}
:Cal notar l'enllaç conduït <nowiki>[[Comtat (País Valencià)|Comtat]]</nowiki>
*Llista formatada:
:<nowiki>{{#invoke:Wikidata | claim | property=P150 | separator=<br /> | conjunction=<br />}}</nowiki> dóna
: {{#invoke:Wikidata | claim | property=P150 | separator=<br /> | conjunction=<br /> | item=Q746061 |showerrors=sip}}
== Dependències ==
* Subpàgines relatives al mòdul principal. El títol del mòdul està definit a la variable <code>module_title = </code>. En una nova instal·lació amb un títol diferent cal modificar aquesta variable.
** [[Module:{{ROOTPAGENAME}}/i18n|../i18n]] (opcional): traduccions de missatges i formats locals. Si s'usa <code>lang</code> diferent al local cerca la subpàgina corresponent, per exemple [[Module:{{BASEPAGENAME}}/i18n/eu|../i18n/eu]]. Si no existeix, surt en anglès per defecte.
** [[Module:{{ROOTPAGENAME}}/labels|../labels]] (opcional): excepcions i correccions d'etiquetes per a una infotaula.
** [[Module:{{ROOTPAGENAME}}/debug|../debug]]: pot aparèixer ocasionalment per la funció track de manteniment.
* Missatges Mediawiki utilitzats depenent de la llengua:
** [[Mediawiki:Comma-separator]], [[Mediawiki:And]], [[Mediawiki:Word-separator]]
** [[Mediawiki:Wikibase-snakview-snaktypeselector-novalue]], [[Mediawiki:Wikibase-snakview-snaktypeselector-somevalue]]
** [[Mediawiki:Wikibase-time-calendar-gregorian]], [[Mediawiki:Wikibase-time-calendar-julian]]
** [[Mediawiki:Translate-taction-translate]]
** [[MediaWiki:Sandboxlink-subpage-name]]
*: Si és necessari es poden crear, o modificar, a [[m:translatewiki.net|Translatewiki]]. Per accedir-hi directament activeu l'enllaç corresponent amb el títol del missatge i el codi de llengua <code><nowiki>[[translatewiki:MediaWiki:</nowiki>''<missatge>''/''<lang>'']]</code>.
==Vegeu també==
* [[mw:Extension:Wikibase Client/Lua|Llibreria mw.wikibase]] (funcions bàsiques).
<includeonly>
[[Categoria:Mòduls de Viquitexts]]
</includeonly>
9comwr22ld443qe2b6gymtlgr0ce5ad
Plantilla:Mentor/Aleatori
10
38484
184387
86686
2026-05-14T21:23:14Z
Aleator
20
-Micru
184387
wikitext
text/x-wiki
{{llista aleatòria
| KRLS
| Docosong
}}<!-- Afegiu-vos més amunt, al final de la llista
--><noinclude>
{{ús de la plantilla}}
</noinclude>
gmlm4jpkfzxonn40rru8e1bzxamwuqw
Mòdul:Paràmetres
828
38507
184388
86883
2026-05-14T21:26:45Z
Aleator
20
neteja de codi: només es fa servir «p.numPara» a «Plantilla:Llista aleatòria»
184388
Scribunto
text/plain
--[[
Aquest mòdul està pensat per ajudar a assegurar la compatibilitat entre plantilles, sobretot en casos
quan una plantilla s'actualitza al cap d'uns anys i cal que funcioni tant amb el nou
plantejament com amb l'original.
]]
local p = {}
--[[ numPara
Compta el número de paràmetres, passats pel frame superior;
a notar que #frame.args no funciona per ser una metataula
]]
function p.numPara( frame )
local args = frame:getParent().args
if args[1] == nil then return 0 end
local comptaArgs = {}
for k, v in ipairs(args) do
comptaArgs[k] = v
end
return #comptaArgs
end
return p
8ax94o3qxyvs608cq6zh8weugav88wt
Mòdul:Infobox
828
40623
184381
173702
2026-05-14T20:22:22Z
Aleator
20
neteja de codi
184381
Scribunto
text/plain
--
-- This module implements {{Infobox}}
--
local p = {}
local args = {}
local origArgs
local root
local function notempty( s ) return s and s:match( '%S' ) end
local function fixChildBoxes(sval, tt)
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1')
end
if s:match(marker) then
local subcells = mw.text.split(s, marker)
s = ''
for k = 1, #subcells do
if k == 1 then
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
elseif k == #subcells then
local rowstyle = ' style="display:none"'
if notempty(subcells[k]) then rowstyle = '' end
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. subcells[k]
elseif notempty(subcells[k]) then
if (k % 2) == 0 then
s = s .. subcells[k]
else
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. subcells[k] .. '</' .. tt .. '></tr>'
end
end
end
end
-- the next two lines add a newline at the end of lists for the PHP parser
-- https://en.wikipedia.org/w/index.php?title=Template_talk:Infobox_musical_artist&oldid=849054481
-- remove when [[:phab:T191516]] is fixed or OBE
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
return s
else
return sval
end
end
local function union(t1, t2)
-- Returns the union of the values of two tables, as a sequence.
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
for k, v in pairs(t2) do
vals[v] = true
end
local ret = {}
for k, v in pairs(vals) do
table.insert(ret, k)
end
return ret
end
local function getArgNums(prefix)
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
local function addRow(rowArgs)
-- Adds a row to the infobox, with either a header cell
-- or a label/data cell combination.
if rowArgs.header then
root
:tag('tr')
:addClass(rowArgs.rowclass)
:cssText(rowArgs.rowstyle)
:attr('id', rowArgs.rowid)
:tag('th')
:attr('colspan', 2)
:attr('id', rowArgs.headerid)
:addClass(rowArgs.class)
:addClass(args.headerclass)
:css('text-align', 'center')
:cssText(args.headerstyle)
:cssText(rowArgs.rowcellstyle)
:wikitext(fixChildBoxes(rowArgs.header, 'th'))
elseif rowArgs.data then
local row = root:tag('tr')
row:addClass(rowArgs.rowclass)
row:cssText(rowArgs.rowstyle)
row:attr('id', rowArgs.rowid)
if rowArgs.label then
row
:tag('th')
:attr('scope', 'row')
:attr('id', rowArgs.labelid)
:css('text-align', 'left') -- NOU
:cssText(args.labelstyle)
:cssText(rowArgs.rowcellstyle)
:wikitext(rowArgs.label)
:done()
end
local dataCell = row:tag('td')
if not rowArgs.label then
dataCell
:attr('colspan', 2)
:css('text-align', 'center')
end
dataCell
:attr('id', rowArgs.dataid)
:addClass(rowArgs.class)
:cssText(rowArgs.datastyle)
:cssText(rowArgs.rowcellstyle)
:wikitext(fixChildBoxes(rowArgs.data, 'td'))
end
end
local function renderTitle()
if not args.title then return end
root
:tag('caption')
:addClass(args.titleclass)
:css('font-weight', 'bold') --NOU
:cssText(args.titlestyle)
:wikitext(args.title)
end
local function renderAboveRow()
if not args.above then return end
root
:tag('tr')
:tag('th')
:attr('colspan', 2)
:addClass(args.aboveclass)
:css('text-align', 'center')
:css('font-size', '125%')
:css('font-weight', 'bold')
:cssText(args.abovestyle)
:wikitext(fixChildBoxes(args.above,'th'))
end
local function renderBelowRow()
if not args.below then return end
root
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass(args.belowclass)
:css('text-align', 'center')
:cssText(args.belowstyle)
:wikitext(fixChildBoxes(args.below,'td'))
end
local function renderSubheaders()
if args.subheader then
args.subheader1 = args.subheader
end
if args.subheaderrowclass then
args.subheaderrowclass1 = args.subheaderrowclass
end
local subheadernums = getArgNums('subheader')
for k, num in ipairs(subheadernums) do
addRow({
data = args['subheader' .. tostring(num)],
datastyle = args.subheaderstyle,
rowcellstyle = args['subheaderstyle' .. tostring(num)],
class = args.subheaderclass,
rowclass = args['subheaderrowclass' .. tostring(num)]
})
end
end
local function renderImages()
if args.image then
args.image1 = args.image
end
if args.caption then
args.caption1 = args.caption
end
local imagenums = getArgNums('image')
for k, num in ipairs(imagenums) do
local caption = args['caption' .. tostring(num)]
local data = mw.html.create():wikitext(args['image' .. tostring(num)])
if caption then
data
:tag('div')
:cssText(args.captionstyle)
:wikitext(caption)
end
addRow({
data = tostring(data),
datastyle = args.imagestyle,
class = args.imageclass,
rowclass = args['imagerowclass' .. tostring(num)]
})
end
end
local function renderRows()
-- Gets the union of the header and data argument numbers,
-- and renders them all in order using addRow.
local rownums = union(getArgNums('header'), getArgNums('data'))
table.sort(rownums)
for k, num in ipairs(rownums) do
addRow({
header = args['header' .. tostring(num)],
label = args['label' .. tostring(num)],
data = args['data' .. tostring(num)],
datastyle = args.datastyle,
class = args['class' .. tostring(num)],
rowclass = args['rowclass' .. tostring(num)],
rowstyle = args['rowstyle' .. tostring(num)],
rowcellstyle = args['rowcellstyle' .. tostring(num)],
dataid = args['dataid' .. tostring(num)],
labelid = args['labelid' .. tostring(num)],
headerid = args['headerid' .. tostring(num)],
rowid = args['rowid' .. tostring(num)]
})
end
end
local function renderItalicTitle()
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
end
end
local function renderTrackingCategories()
if args.decat ~= 'yes' then
if args.child == 'yes' then
if args.title then
root:wikitext('[[Categoria:Pàgines que fan servir infotaules incrustades amb el paràmetre del títol]]')
end
elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root:wikitext('[[Categoria:Articles amb infotaules sense paràmetres de dades]]')
end
end
end
local function _infobox()
-- Specify the overall layout of the infobox, with special settings
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
root = mw.html.create('table')
root
:addClass((args.subbox ~= 'yes') and 'infobox' or nil)
:addClass(args.bodyclass)
if args.subbox == 'yes' then
root
:css('padding', '0')
:css('border', 'none')
:css('margin', '-3px')
:css('width', 'auto')
:css('min-width', '100%')
:css('font-size', '100%')
:css('clear', 'none')
:css('float', 'none')
else
root
:css('font-size', '90%') --NOU
:css('width', '25em') --CANVIAT
--:css('width', '22em')
end
root
:cssText(args.bodystyle)
renderTitle()
renderAboveRow()
else
root = mw.html.create()
root
:wikitext(args.title)
end
renderSubheaders()
renderImages()
renderRows()
renderBelowRow()
renderItalicTitle()
renderTrackingCategories()
return tostring(root)
end
local function preprocessSingleArg(argName)
-- If the argument exists and isn't blank, add it to the argument table.
-- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
if origArgs[argName] and origArgs[argName] ~= '' then
args[argName] = origArgs[argName]
end
end
local function preprocessArgs(prefixTable, step)
-- Assign the parameters with the given prefixes to the args table, in order, in batches
-- of the step size specified. This is to prevent references etc. from appearing in the
-- wrong order. The prefixTable should be an array containing tables, each of which has
-- two possible fields, a "prefix" string and a "depend" table. The function always parses
-- parameters containing the "prefix" string, but only parses parameters in the "depend"
-- table if the prefix parameter is present and non-blank.
if type(prefixTable) ~= 'table' then
error("Hi ha un valor no-taula per a la taula de prefix", 2)
end
if type(step) ~= 'number' then
error("Hi ha un valor numèric (step) que no és vàlid", 2)
end
-- Get arguments without a number suffix, and check for bad input.
for i,v in ipairs(prefixTable) do
if type(v) ~= 'table' or type(v.prefix) ~= "string" or (v.depend and type(v.depend) ~= 'table') then
error('Hi ha una entrada que no és vàlida per a la taula de prefix preprocessArgs', 2)
end
preprocessSingleArg(v.prefix)
-- Only parse the depend parameter if the prefix parameter is present and not blank.
if args[v.prefix] and v.depend then
for j, dependValue in ipairs(v.depend) do
if type(dependValue) ~= 'string' then
error('El valor del paràmetre "depend" detectat en preprocessArgs no és vàlid')
end
preprocessSingleArg(dependValue)
end
end
end
-- Get arguments with number suffixes.
local a = 1 -- Counter variable.
local moreArgumentsExist = true
while moreArgumentsExist == true do
moreArgumentsExist = false
for i = a, a + step - 1 do
for j,v in ipairs(prefixTable) do
local prefixArgName = v.prefix .. tostring(i)
if origArgs[prefixArgName] then
moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
preprocessSingleArg(prefixArgName)
end
-- Process the depend table if the prefix argument is present and not blank, or
-- we are processing "prefix1" and "prefix" is present and not blank, and
-- if the depend table is present.
if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
for jj,dependValue in ipairs(v.depend) do
local dependArgName = dependValue .. tostring(i)
preprocessSingleArg(dependArgName)
end
end
end
end
a = a + step
end
end
function p.infobox(frame)
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- Parse the data parameters in the same order that the old {{infobox}} did, so that
-- references etc. will display in the expected places. Parameters that depend on
-- another parameter are only processed if that parameter is present, to avoid
-- phantom references appearing in article reference lists.
preprocessSingleArg('child')
preprocessSingleArg('bodyclass')
preprocessSingleArg('subbox')
preprocessSingleArg('bodystyle')
preprocessSingleArg('title')
preprocessSingleArg('titleclass')
preprocessSingleArg('titlestyle')
preprocessSingleArg('above')
preprocessSingleArg('aboveclass')
preprocessSingleArg('abovestyle')
preprocessArgs({
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
}, 10)
preprocessSingleArg('subheaderstyle')
preprocessSingleArg('subheaderclass')
preprocessArgs({
{prefix = 'image', depend = {'caption', 'imagerowclass'}}
}, 10)
preprocessSingleArg('captionstyle')
preprocessSingleArg('imagestyle')
preprocessSingleArg('imageclass')
preprocessArgs({
{prefix = 'header'},
{prefix = 'data', depend = {'label'}},
{prefix = 'rowclass'},
{prefix = 'rowstyle'},
{prefix = 'rowcellstyle'},
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'labelid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 50)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
preprocessSingleArg('datastyle')
preprocessSingleArg('below')
preprocessSingleArg('belowclass')
preprocessSingleArg('belowstyle')
preprocessSingleArg('name')
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
preprocessSingleArg('decat')
preprocessSingleArg('wikidata')
preprocessSingleArg('item')
return _infobox()
end
return p
ky8akr48ly5jj8xwm5lj8mblnfco8fk
Mòdul:InfoboxImage
828
40625
184382
97325
2026-05-14T20:36:12Z
Aleator
20
neteja de codi; només usat en Plantilla:Autor
184382
Scribunto
text/plain
-- Inputs:
-- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link
-- size - size to display the image
-- maxsize - maximum size for image
-- sizedefault - default size to display the image if size param is blank
-- alt - alt text for image
-- title - title text for image
-- border - set to yes if border
-- center - set to yes, if the image has to be centered
-- upright - upright image param
-- link - page to visit when clicking on image
-- Outputs:
-- Formatted image.
-- More details available at the "Module:InfoboxImage/doc" page
local i = {};
function i.InfoboxImage(frame)
local image = frame.args["image"];
if image == "" or image == nil then
return "";
end
if image == " " then
return image;
end
if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then
return "";
end
if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then
return "";
end
if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then
return "";
end
if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then
return "";
end
if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then
return "";
end
if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then
return "";
end
if mw.ustring.sub(image,1,2) == "[[" then
-- search for thumbnail images and add to tracking cat if found
if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
return image .. "[[Categoria:Articles amb infotaules que usen miniatures]]";
elseif mw.title.getCurrentTitle().namespace == 0 and string.find(image, "^%[%[[FfIi]") then
-- some templates like {{cal foto}} add "[[Category", actually not a File syntax
return image .. "[[Categoria:Articles amb sintaxi de fitxer obsoleta]]";
else
return image;
end
elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
return image;
elseif mw.ustring.sub(image,1,1) == "<" then
return image;
elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then
-- Found strip marker at begining, so pass don't process at all
return image;
else
local result
local size = frame.args["size"];
local maxsize = frame.args["maxsize"];
local sizedefault = frame.args["sizedefault"];
local alt = frame.args["alt"];
local link = frame.args["link"];
local title = frame.args["title"];
local border = frame.args["border"];
local upright = frame.args["upright"] or "";
local thumbtime = frame.args["thumbtime"] or "";
local center= frame.args["center"];
-- remove prefix if exists
local allNames = mw.site.namespaces[6].aliases
allNames[#allNames + 1] = mw.site.namespaces[6].name
allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
for ii, name in ipairs(allNames) do
if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
break
end
end
if maxsize ~= "" and maxsize ~= nil then
-- if no sizedefault then set to maxsize
if sizedefault == "" or sizedefault == nil then
sizedefault = maxsize
end
-- check to see if size bigger than maxsize
if size ~= "" and size ~= nil then
local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
if sizenumber>maxsizenumber and maxsizenumber>0 then
size = maxsize;
end
end
end
-- add px to size if just a number
if (tonumber(size) or 0) > 0 then
size = size .. "px";
end
result = "[[File:" .. image;
if size ~= "" and size ~= nil then
result = result .. "|" .. size;
elseif sizedefault ~= "" and sizedefault ~= nil then
result = result .. "|" .. sizedefault;
else
result = result .. "|frameless";
end
if center == "yes" then
result = result .. "|center"
end
if alt ~= "" and alt ~= nil then
result = result .. "|alt=" .. alt;
end
if link ~= "" and link ~= nil then
result = result .. "|link=" .. link;
end
if border == "yes" then
result = result .. "|border";
end
if upright ~= "" then
result = result .. "|upright=" .. upright;
end
if thumbtime ~= "" then
result = result .. "|thumbtime=" .. thumbtime;
end
if title ~= "" and title ~= nil then
result = result .. "|" .. title;
elseif alt ~= "" and alt ~= nil then
result = result .. "|" .. alt;
end
result = result .. "]]";
return result;
end
end
return i;
ncc3etod83glyrio3zdahuoy54hg4s9
Mòdul:Edition
828
53547
184383
183181
2026-05-14T20:42:23Z
Aleator
20
neteja de codi
184383
Scribunto
text/plain
--------------------------------------------------------------------------------
-- Adaptat de https://en.wikisource.org/wiki/Module:Edition
--------------------------------------------------------------------------------
require('strict')
local Wikidata = require('Module:Wikidata')
--------------------------------------------------------------------------------
-- 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 args is a table with an appropriate element, use it.
if type( args ) == 'table' then
if args.wikidata ~= '' and args.wikidata ~= nil then
id = args.wikidata
elseif args.wikidata_id ~= '' and args.wikidata_id ~= nil then
id = args.wikidata_id
elseif args.page ~= '' and args.page ~= nil then
local title = mw.title.new( args.page )
id = mw.wikibase.getEntityIdForTitle( title.nsText .. title.text )
-- If no entity for this page, maybe it's a subpage and we should look for the root page's entity.
if id == nil then
id = mw.wikibase.getEntityIdForTitle( title.nsText .. title.rootText )
end
end
end
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.
-- Test: =p.badge({args={qid='Q19527599'}})
local function badge( args )
local item = getItem( args ) --per defecte, id de la pàgina
if args.qid ~= nil then --però si passem un qid, id passat
item = mw.wikibase.getEntity(args.qid)
end
if not ( item and item.sitelinks and item.sitelinks.cawikisource and item.sitelinks.cawikisource.badges ) then
return ''
end
local badges = item.sitelinks.cawikisource.badges
local out = ''
for _, wbadge in pairs( badges ) do
local badgeOut = ''
local badgeItem = mw.wikibase.getEntity( wbadge )
local wikisourceBadgeClass = 'Q75042035'
if badgeItem.claims.P31[1].mainsnak.datavalue.value.id == wikisourceBadgeClass and badgeItem.claims.P18 ~= nil then
if wbadge ~= nil then
badgeOut = badgeOut .. wbadge --Q20748091 (no revisat), Q20748092 (revisat), Q20748093 (validat), Q20748094 (problemàtic)
end
out = out .. badgeOut
end
end
return mw.getCurrentFrame():preprocess( out )
end
--------------------------------------------------------------------------------
-- Obra: estàndard "inline" de declaració d'una obra per a les pàgines d'Autor
-- Prova {{ED}}: =p.obra({args={tipus='desambigua', qid='Q123401416', etiqueta='El títol'}})
-- Prova {{OW}}: =p.obra({args={tipus='llibre', qid='Q123401416'}})
local function obra( args )
local tipus = args['tipus'] --tipus de crida
local qid = args['qid'] --id de Wikidata
local etiqueta = args['etiqueta'] --etiqueta de l'enllaç intern
local s = ''
local CategoriaError = '[[Categoria:Pàgines amb errors diversos|'
local SenseWikidata = false
local IconaWikidata = '[[File:Wikidata-logo.svg|20px|link=d:'
local Icona100 = '<span title="Índex validat">[[File:100%.svg|10px|alt=Índex validat|link=]]</span> '
local Icona075 = '<span title="Índex no validat">[[File:75%.svg|10px|alt=Índex no validat|link=]]</span> '
local Icona025 = '<span title="Índex incomplet">[[File:25%.svg|10px|alt=Índex incomplet|link=]]</span> '
local IconaErr = '<span title="Índex amb errors">[[File:Purple Exclamation.svg|10px|alt=Índex amb errors|link=]]</span> '
local IconaLlibre = '[[File:Open book nae 02.svg|20px|link=:Llibre:'
local FileMatch = ''
local wSiteLink
local wTitol
local P996 = false
if tipus == nil or tipus == '' then return '' end
if tipus == "desambigua" then --[[Plantilla:ED]]
local IconaDesambigua = ' [[File:Disambig.svg|15px|link=]]'
if qid == nil or qid == '' then
s = s .. IconaDesambigua
SenseWikidata = true
else
if mw.wikibase.entityExists(qid) == true then
s = s .. IconaWikidata .. qid .. ']]'
s = s .. IconaDesambigua
wSiteLink = Wikidata.getSiteLink{item=qid}
if wSiteLink then
if etiqueta == nil or etiqueta == '' then
s = s .. " ''[[" .. wSiteLink .. "]]''"
else
s = s .. " ''[[" .. wSiteLink .. "|" .. etiqueta .. "]]''"
end
else
SenseWikidata = true
end
else
s = s .. 'Identificador inexistent' .. CategoriaError .. 'i]]'
end
end
if SenseWikidata == true then
if etiqueta == nil or etiqueta == '' then
s = s .. " ''sense títol''" .. CategoriaError .. 'e]]'
else
s = s .. " ''[[" .. etiqueta .. "]]''"
end
end
elseif tipus == 'llibre' then --[[Plantilla:OW]]
if qid == nil or qid == '' then
s = s .. " qid no informat " .. CategoriaError .. 'q]]'
else
if mw.wikibase.entityExists(qid) == true then
s = s .. '<span class="mw-customtoggle-' .. qid .. '" >𝍢</span>'
s = s .. '<span class="mw-collapsible mw-collapsed" id="mw-customcollapsible-' .. qid .. '">'
s = s .. IconaWikidata .. qid .. ']]'
local Insignia = badge(args)
if Insignia == 'Q20748093' then s = s .. Icona100
elseif Insignia == 'Q20748092' then s = s .. Icona075
elseif Insignia == 'Q20748091' then s = s .. Icona025
elseif Insignia == 'Q20748094' then s = s .. IconaErr end
if Wikidata.validProperty{"P996", item=qid} == nil then
else --hi ha P996 (un o varis)
local FileOnCommonsStmts = mw.wikibase.getAllStatements (qid, 'P996');
for _, stmt in pairs( FileOnCommonsStmts ) do
--Mirem per cada P996 si està creat el Llibre a Viquitexts (1 per edició)
local commonsFilename = stmt['mainsnak']['datavalue']['value']
local wLlibre = mw.title.new( commonsFilename, 'Index' )
if wLlibre.exists then
FileMatch = wLlibre.text
P996 = true
end
end
if P996 == true then
s = s .. IconaLlibre .. FileMatch .. ']] '
end
end
wTitol = Wikidata.claim{item=qid, property="P1476", lang="ca", list=false, editicon=false}
wSiteLink = Wikidata.getSiteLink{item=qid}
if wSiteLink then
if wTitol == nil or wTitol == '' then
s = s .. mw.getCurrentFrame():preprocess("{{Export|" .. wSiteLink .. "}}</span> " .. "''[[" .. wSiteLink .. "]]''")
else
s = s .. mw.getCurrentFrame():preprocess("{{Export|" .. wSiteLink .. "}}</span> " .. "''[[" .. wSiteLink .. "|" .. wTitol .. "]]''")
end
else
s = s .. '</span>'
if wTitol == nil or wTitol == '' then
s = s .. "error: no hi ha títol ni SiteLink" .. CategoriaError .. 's]]'
else
--Si no hi ha sitelink, la pàg. no ha d'existir. Si es vol enllaç, afegir-lo a Wikidata.
s = s .. " " .. "''" .. wTitol .. "''"
end
end
local wTrad = Wikidata.claim{item=qid, property="P655", lang="ca", list=true, editicon=false}
local wAutorList = Wikidata.claim{item=qid, property="P50", lang="ca", list=true, editicon=false}
local AutorInformat = false
if wTrad then
if wAutorList then
if mw.getCurrentFrame():preprocess("{{NAMESPACE}}") == 'Autor' then
local AutorWS = Wikidata.getSiteLink{item=Wikidata.claim{item=qid, property="P50", lang="ca", list=false, editicon=false, formatting='raw'}}
if AutorWS == "Autor:" .. mw.getCurrentFrame():preprocess("{{PAGENAME}}") then
s = s .. ", traduït per " .. wTrad
else
AutorInformat = true
if wAutorList ~= "valor desconegut" then
s = s .. ", per " .. wAutorList
end
end
else
AutorInformat = true
s = s .. ", per " .. wAutorList .. ", traduït per " .. wTrad
end
end
end
local wPrefaci= Wikidata.claim{item=qid, property="P2679", lang="ca", list=false, editicon=false, formatting='internallink'}
if wPrefaci then
if wAutorList then
if mw.getCurrentFrame():preprocess("{{NAMESPACE}}") == 'Autor' then
local PrefaciWS = Wikidata.getSiteLink{item=Wikidata.claim{item=qid, property="P2679", lang="ca", list=false, editicon=false, formatting='raw'}}
if PrefaciWS == 'Autor:' .. mw.getCurrentFrame():preprocess("{{PAGENAME}}") then
if AutorInformat == false then
AutorInformat = true
if wAutorList ~= "valor desconegut" then
s = s .. ", per " .. wAutorList
end
end
else
s = s .. ", prologat per " .. wPrefaci
end
else
s = s .. ", prologat per " .. wPrefaci
end
end
end
local wEpileg = Wikidata.claim{item=qid, property="P2680", lang="ca", list=false, editicon=false}
if wEpileg then
local wAutor = Wikidata.claim{item=qid, property="P50", lang="ca", list=false, editicon=false, formatting='label'}
if wAutor then
if mw.getCurrentFrame():preprocess("{{NAMESPACE}}") == 'Autor' then
if wAutor == mw.getCurrentFrame():preprocess("{{PAGENAME}}") then
s = s .. ", epilogat per " .. wEpileg
else
AutorInformat = true
s = s .. ", per " .. wAutor
end
else
s = s .. ", epilogat per " .. wEpileg
end
end
end
if mw.getCurrentFrame():preprocess("{{NAMESPACE}}") == 'Autor' then
else
if wAutorList and AutorInformat == false then
if wAutorList == 'valor desconegut' then
else
s = s .. ", per " .. wAutorList
end
end
end
if P996 == false then
local wPartDe = Wikidata.claim{item=qid, property="P361", lang="ca", list=false, editicon=false}
if wPartDe then
s = s .. ", part de ''" .. wPartDe .. "''"
end
end
local wData = Wikidata.claim{item=qid, property="P577", lang="ca", list=false, editicon=false, formatting="j xg Y"}
if wData then
s = s .. " (" .. wData .. ")"
end
local wTeParts = Wikidata.claim{item=qid, property="P527", lang="ca", list=true, editicon=false}
if wTeParts then
s = s .. ". Inclou: " .. wTeParts .. "."
end
else
s = s .. " qid erroni " .. CategoriaError .. 'x]]'
end
end
else
s = s .. 'Error tipus Edition'
end
return s
end
--------------------------------------------------------------------------------
-- Export all public functions.
return {
badge = function( frame ) return badge( frame.args ) end;
obra = function( frame ) return obra( frame.args ) end;
}
4yct0j4bomrjy6yg7vyisqi5qd1udto
Mòdul:Header
828
54412
184385
182370
2026-05-14T20:57:09Z
Aleator
20
neteja de codi
184385
Scribunto
text/plain
-------------------------------------------------------------------------
-- Construcció de la capçalera
-- Adaptat de https://es.wikisource.org/wiki/Module:Encabezado
-------------------------------------------------------------------------
local p = {}
local Wikidata = require('Module:Wikidata')
local Args = require('Module:Arguments')
local categories = ''
local params = { --1 = vigent, 0 = obsolet. Per ordre alfabètic:
['any']=1,['autor']=1,['compositor']=1,['current']=1,['editor']=1,['footer']=1,['from']=1,
['header']=1,['imatge']=1,['idioma']=1,['ilustrador']=1,['index']=1,['info']=1,['lloc']=1,
['next']=1,['nivell']=1,['nomcategoria']=1,['prev']=1,['qid']=1,
['subtitol']=1,['sumari']=1,['titol']=1,['to']=1,['traductor']=1,['value']=1,
}
local altparams= {['anterior']='prev',['il·lustrador']='ilustrador',
['següent']='next',['subtítol']='subtitol',['sub-títol']='subtitol',['títol']='titol',
}
local function alias(args, altTable)
local _args = {}
for k, v in pairs(args) do
k = mw.ustring.lower(tostring(k))
if altTable[k] then
_args[altTable[k]] = v
else
_args[k] = v
end
end
return _args
end
local function errorMessage(text)
local html = mw.html.create('div')
html:addClass('error')
:wikitext(text)
categories=categories..'[[Categoria:Pàgines amb errors diversos|E]]'
return tostring(html)
end
local function delink(s)
if not s:match("%[") then
return s
end
local result = s
result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
result = mw.text.decode(result, true) -- decode HTML entities.
-- Remove the colon if the link is using the [[Help:Colon trick]].
if result:match("%[%[:") then
result = "[[" .. result:match("%[%[:(.*%]%])")
end
-- Find the display area of the wikilink
if result:match("|") then -- Find if we're dealing with a pipecd link.
result = result:match("%[%[.-%|(.+)%]%]")
-- Remove new lines from the display of multiline piped links,
-- where the pipe is before the first new line.
result = result:gsub("\n", "")
else
result = result:match("%[%[(.-)%]%]")
end
return result
end
local function linkMicroformat(param, valor)
if valor and valor ~= '' then
return mw.html.create('span')
:addClass('ws-' .. param)
:wikitext(delink(valor))
else return '' end
end
local function microformat(d, argus)
local uformat = mw.html.create('div')
:cssText('display:none')
:attr('id', 'ws-data')
:addClass('ws-noexport')
--Exclosos: compositor, subtitol... vegeu [[:old:Wikisource:Microformat]]
uformat:node( linkMicroformat( 'title', d.titol ) )
if d.autor then
uformat:node( linkMicroformat( 'author', d.autor ) )
end
if d.traductor then
uformat:node( linkMicroformat( 'translator', d.traductor ) )
end
if d.ilustrador ~= '' then
uformat:node( linkMicroformat( 'illustrator', d.ilustrador ) )
end
if d.editor ~= '' then
uformat:node( linkMicroformat( 'publisher', d.editor ) )
end
if d.any then
uformat:node( linkMicroformat( 'year', d.any ) )
end
if d.lloc ~= '' then
uformat:node( linkMicroformat( 'place', d.lloc ) )
end
if d.nivell ~= '' then
uformat:node( linkMicroformat( 'progress', d.nivell ) )
end
if d.volum ~= '' then
uformat:node( linkMicroformat( 'volume', d.volum ) )
end
if d.index then
uformat:node( linkMicroformat( 'scan', d.index ) )
if d.imatge ~= '' then
uformat:node( linkMicroformat( 'cover', d.index .. '/' .. d.imatge ) )
end
end
if argus.sumari and argus.sumari ~= '' then
uformat:tag('div') --no pot ser span
:addClass('ws-summary')
:wikitext(argus.sumari)
end
return tostring(uformat)
end
local function resoldreWikidataImatge(argus, parametro)
local ws = argus[parametro] --imatge
if not ws or ws == '' then
ws = '1'
if not argus['qid'] or argus['qid'] == '' then return ws end
if not argus['index'] or argus['index'] == '' then return ws end
local FileOnCommonsStmts = mw.wikibase.getAllStatements (argus['qid'], 'P996');
if FileOnCommonsStmts then
for _, stmt in pairs( FileOnCommonsStmts ) do
local commonsFilename = stmt['mainsnak']['datavalue']['value'] --=argus['index']
if commonsFilename and commonsFilename ~= '' then
--Cal decodificar nompag, per exemple, per l'apòstrof "'" arriba com "'"
if mw.text.decode(argus['index']) == commonsFilename then
ws = Wikidata.claim{item=argus['qid'], property="P996", qualifier="P4714", lang="ca", list=false, editicon=false}
end
end
end
end
end
if not ws or ws == '' then ws = '1' end
if ws and ws~= '' then return ws end
end
local function resoldreWikidataProgress(argus, parametro)
local ws = argus[parametro] --nivell
if not ws or ws == '' then
ws = "I"
if not argus['qid'] or argus['qid'] == '' then return ws end
local badges = require("Module:Edition").badge{args={qid=argus['qid']}}
if badges and badges ~='' then
if badges == "Q20748093" then ws = "V" end
if badges == "Q20748092" then ws = "R" end
if badges == "Q20748091" then ws = "I" end
if badges == "Q20748094" then ws = "E" end
end
end
if ws and ws~= '' then return ws end
end
local function resoldreWikidata(argus, parametro, PID)
local ws = argus[parametro]
if not ws or ws == '' then
ws = Wikidata.claim{item=argus['qid'], property=PID, lang="ca", list=false, editicon=false}
end
if ws and ws~= '' then return ws end
end
local function resoldreWikidataPersona(argus, parametro, PID)
local ws = argus[parametro]
if not ws or ws == '' then
ws = Wikidata.claim{item=argus['qid'], property=PID, lang="ca", list=true, editicon=false}
end
if ws and ws~= '' then return ws end
end
local function consolidat(argus) -- Si no s'ha informat, captura la dada de Wikidata
local data = {}
local props = {
any = {'any', 'P577'},
autor = {'autor','P50', true}, --todo: else P2093
editor = {'editor', 'P123'},
ilustrador = {'ilustrador', 'P110', true},
imatge = {'imatge', true, true, true, true},
index = {'index', 'P996'},
lloc = {'lloc', 'P291'},
nivell = {'nivell', true, true, true},
subtitol = {'subtitol', 'P1680'},
titol = {'titol', 'P1476'},
traductor = {'traductor', 'P655', true},
volum = {'volum', 'P478'},
}
for k, v in pairs(props) do
if v[5] then
data[k] = resoldreWikidataImatge(argus, v[1])
elseif v[4] then
data[k] = resoldreWikidataProgress(argus, v[1])
elseif v[3] then
data[k] = resoldreWikidataPersona(argus, v[1], v[2])
else
data[k] = resoldreWikidata(argus, v[1], v[2])
end
end
return data
end
--=p.header({qid='Q19529123',prev="[[../Capítol 48|Capítol 48]]"})
--=p.header({current='mig',prev='antes',next='luego',titol='El Títol',subtitol='El subtítol',autor='Autor',info='això és una nota'})
function p.header( frame )
local titol = mw.title.getCurrentTitle()
local essub = titol.isSubpage
local linkPagina = mw.title.getCurrentTitle().text
local textoenlace = mw.uri.encode(linkPagina,"QUERY")
local argus = Args.getArgs(frame)
argus = alias(argus, altparams)
local d = consolidat(argus)
-- estructura HTML
local html = mw.html.create()
local divPrincipal = html:tag('div')
:attr('id','headerContainer')
:addClass('noprint ws-noexport')
:css('background', '#eff5f9')
:css('color', 'black')
:css('display', 'table')
:css('width', '95%')
:css('text-align', 'center')
:css('padding', '1em')
:css('border-top', '1px solid #aaaaaa')
:css('border-bottom', '8px solid #355291')
local divMig = divPrincipal:tag('div')
:addClass('middle-div')
:css('width', '95%')
:css('display', 'table-cell')
:css('vertical-align', 'middle')
if argus['current'] and argus['current'] ~= '' then
divMig:wikitext('Sou a «'.. argus['current'] ..'»<br />')
end
if not d.titol then d.titol = textoenlace end
divMig:wikitext('<span style="font-size:125%;"><b>' .. d.titol .. '</b></span><br />')
if not essub then
if d.subtitol then
divMig:wikitext(d.subtitol ..'<br />')
end
end
if d.autor then
if d.autor == 'valor desconegut' then
d.autor = '[[Autor:Anònim|Anònim]]'
categories = categories..'[[Categoria:Texts anònims]]'
end
divMig:wikitext(d.autor ..'<br>')
end
if d.traductor then
for _,v in ipairs(mw.text.split(d.traductor, '[/,]')) do
if delink(v) == 'Anònim' then
categories = categories..'[[Categoria:Texts anònims]]'
end
end
divMig:wikitext('(traduït per '..d.traductor..')<br>')
end
if d.any and not argus['noany'] then
if d.any ~= "valor desconegut" then
divMig:wikitext(' ('.. d.any ..')')
end
end
local divMigInf = divMig:tag('div'):addClass('noprint plainlinks lower-div')
local divInfo = divMigInf:tag('span')
:attr('id','headerinfo')
:css('background-color','#eff5f9')
:css('color','black')
:css('text-align','center')
:css('font-size','80%')
if argus['info'] and argus['info'] ~= '' then
divInfo:wikitext(argus['info'])
end
local LinkExport = 'https://ws-export.wmcloud.org/?lang=ca&page='..textoenlace..'&format='
local w = '<br /><span style=\"font-size:80%\">'
w = w .. 'Baixa com a [[File:EPUB silk icon.svg|12px|link='..LinkExport..'epub|Baixa com a ePub]]'
w = w .. ' [[File:Document-pdf.svg|15px|link='..LinkExport..'pdf|Baixa com a PDF]]'
w = w .. ' [[File:Mobi_icon.svg|22px|link='..LinkExport..'mobi|Baixa com a mobi]]</span>'
divMigInf:wikitext(w)
local divFinal = divMig:tag('div')
:attr('id', 'header-final')
:addClass('noprint ws-noexport')
:css('display', 'table')
:css('width', '100%')
local divPrev = divFinal:tag('div')
:attr('id','headerprevious')
:css('padding', '0')
:css('display', 'table-cell')
:css('vertical-align', 'bottom')
:css('align', 'float-left')
:css('text-align', 'left')
local divNext = divFinal:tag('div')
:attr('id','headernext')
:css('padding', '0')
:css('display', 'table-cell')
:css('vertical-align', 'bottom')
:css('align', 'float-right')
:css('text-align', 'right')
if argus['prev'] and argus['prev'] ~= '' then
divPrev:wikitext('[[Fitxer:Breezeicons-actions-22-go-previous.svg|30px|link=]] '..argus['prev'])
end
if argus['next'] and argus['next'] ~= '' then
divNext:wikitext(argus['next'] .. ' [[Fitxer:Breezeicons-actions-22-go-next.svg|30px|link=]]')
end
if titol.namespace == 0 then --només namespace principal
if argus['nomcategoria'] and argus['nomcategoria'] ~= '' then
if argus['nomcategoria'] == 'cap' then
else
categories = categories..'[[Categoria:' .. argus['nomcategoria'] .. ']]'
end
else
categories = categories..'[[Categoria:' .. titol.rootText .. ']]'
end
if argus['idioma'] and argus['idioma'] ~= '' then
categories = categories..'[[Categoria:Texts originàriament en '..argus['idioma']..']]'
end
end
for k,v in pairs(argus) do
if params[k] or altparams[k] then
if params[k] == 0 then
categories = categories..'[[Categoria:Pàgines amb errors diversos|K]]'
end
else
html:wikitext(errorMessage('Error: paràmetre '..k..' no reconegut'))
categories=categories..'[[Categoria:Pàgines amb errors diversos|P]]'
end
end
html:wikitext(categories)
html:wikitext(microformat(d, argus))
return tostring(html)
end
return p
t9ytyc01i6rcr9owqyxi4ujizbvth41