Module:User:Jarekt/table row
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
SELECT ?item WHERE {
?item wdt:P170 wd:Q381238 . # Witkacy as creator
MINUS{ ?item wdt:P31 wd:Q3658341 .} # no literary characters
MINUS{ ?item wdt:P31 wd:Q125191 .} # no photographs
optional{ ?item p:P528 [ pq:P972 wd:Q106425660; ps:P528 ?kdm] . }
optional{ ?item wdt:P156/wdt:P528 ?prev .}
optional{ ?item wdt:P155/wdt:P528 ?next .}
bind( if( bound(?kdm) && strStarts(str(?kdm), "I "), CONCAT(STR( ?kdm ), ".5"),
if( bound(?next), CONCAT(STR( ?next ), ".9"),
if( bound(?prev), CONCAT(STR( ?prev ), ".1"),
"Z") ) ) as ?kdmn ) .
OPTIONAL {
?item rdfs:label ?Len
FILTER((LANG(?Len)) = "en")
}
filter (?item!=wd:Q107095853)
} order by ?kdmn
Creation steps[edit]
- Fill a spreadsheet with
- A2=Q-code from above query
- B2=CONCATENATE("{{subst:User:Jarekt/witkacy row|",A2,"}}")
- C2=C1+1/490
- D2=ROUND(C2-0.5,0)
- use blank user page and add
{{subst:User:Jarekt/witkacy row|header}}
|}
to it. Than copy content of column B 500 rows at a time and paste into the table.
- Adjust to Polish Wiki in Notebook++:
- "[[File:" -> "[[Plik:"
- "\[\[w:pl:([^\|]*)\|\1\]\]" -> "\1"
Code
local getDate = require("Module:Wikidata date")._date -- used for processing of date properties
local core = require('Module:Core')
local p = {}
-- ===========================================================================
local function green(qcode, text)
return '[[:d:'.. qcode ..'|<span style="color: green; text-decoration: inherit;">'.. text ..'</span>]]'
end
-- ===========================================================================
local function getEntityLabel(entity, userLang)
local label
-- build language fallback list
local langList = mw.language.getFallbacksFor(userLang)
table.insert(langList, 1, userLang)
-- get label
for _, lang in ipairs(langList) do -- loop over language fallback list looking for label in the specific language
label = entity:getLabel(lang)
if label then break end -- label found and we are done
end
label = label or entity.id -- fallback value
return green(entity.id, label)
end
-------------------------------------------------------------------------------
local function getItemLabel(id, userLang)
-- code equivalent to require("Module:Wikidata label")._getLabel with Wikidata=- option
local label, link
-- build language fallback list
local langList = mw.language.getFallbacksFor(userLang)
table.insert(langList, 1, userLang)
for _, lang in ipairs(langList) do -- loop over language fallback list looking for label in the specific language
label = mw.wikibase.getLabelByLang(id, lang)
if label then break end -- label found and we are done
end
return label or id
end
-- ===========================================================================
local function getLabel_pl(id)
local sitelink = mw.wikibase.getSitelink(id, 'plwiki')
local label = getItemLabel(id, 'pl')
if sitelink then
return '[[w:pl:' .. sitelink .. '|' .. label ..']]'
else
return green(id, label)
end
end
-- ===========================================================================
local function getValueByQual(entity, prop, qualID, qvalue, lang)
local Res = {}
if entity.claims and entity.claims[prop] then
for k, statement in ipairs( entity:getBestStatements( prop )) do
if (statement.mainsnak.snaktype == "value" and statement.qualifiers and statement.qualifiers[qualID]) then
local snak = statement.qualifiers[qualID][1]
if (snak.snaktype == "value" and snak.datatype == 'wikibase-item' and snak.datavalue.value.id == qvalue) then
return statement.mainsnak.datavalue.value
end
end
end
end
return ''
end
-- ===========================================================================
local function getValue(entity, prop)
return (core.parseStatements(entity:getBestStatements( prop ), nil ) or {''})[1]
end
-- ===========================================================================
local function getItemValue(entity, prop, lang)
return (core.parseStatements(entity:getBestStatements( prop ), lang ) or {''})[1]
end
-------------------------------------------------------------------------------
local function getPropertyWithQual(entity, prop, qualifiers, lang)
local Res = {}
if entity.claims and entity.claims[prop] then
for k, statement in ipairs( entity:getBestStatements( prop )) do
local res, val = {}, nil -- table with fields: key, value, P... (qualifiers)
if (statement.mainsnak.snaktype == "value") then
val = statement.mainsnak.datavalue.value
if val.id then
val = val.id
elseif val.text then
res.value_lang = val.language
val = val.text
end
else
val = statement.mainsnak.snaktype
end
res.value = val
for iQual, qual in ipairs( qualifiers ) do
if statement.qualifiers and statement.qualifiers[qual] then
local snak = statement.qualifiers[qual][1]
if (snak.snaktype == "value" and snak.datatype == 'wikibase-item') then
val = snak.datavalue.value.id
elseif (snak.snaktype == "value" and snak.datatype == 'string') then
val = snak.datavalue.value
else
val = nil
end
res[qual] = val
end
end
table.insert(Res, res)
end
end
return Res
end
-- ===========================================================================
local function get_title_pl(entity)
local title = "''".. getEntityLabel(entity, 'pl') .. "''"
local id = getValue(entity, 'P921')
if id ~= '' then
title = title .. '<br />(osoba: ' .. getLabel_pl(id) .. ')'
end
return title
end
-- ===========================================================================
function p.get_collection_pl(entity)
local collection = {}
local prop = getPropertyWithQual(entity, 'P195', {'P518', 'P582', 'P828', 'P3831'}) -- (P3831) and no end time (P582)
local id = getValue(entity, 'P217')
for _, p in ipairs(prop) do
local val = nil
if p.P518=='Q114187913' then --applies to part = photograph of the artwork
val = 'praca znana z fotografii'
elseif p.value=='somevalue' and not p.P582 and p.P3831=='Q768717' then -- object has role = private collection
val = 'własność prywatna'
if val ~= '' and id ~= '' and string.sub(id,1,4)=='N.D.' then
val = val .. '<br />(' .. green('Q116259175','MNK') ..' ' .. id .. ')'
elseif val ~= '' and id ~= '' then
val = val .. '<br />(Numer inwentarza: ' .. id .. ')'
end
elseif p.value=='novalue' and p.P828=='Q4140840' then -- has cause = lost artwork
val = 'praca zaginiona'
elseif p.value=='novalue' and p.P828=='Q328376' then -- has cause = Nazi plunder
val = 'praca zaginiona w czasie II wojny światowej'
elseif p.value=='novalue' and p.P828=='Q21745157' then -- has cause = destroyed artwork (Q21745157)
val = 'praca zniszczona'
elseif p.value then
val = getLabel_pl(p.value)
if val ~= '' and id ~= '' then
val = val .. '<br />(Numer inwentarza: ' .. id .. ')'
end
end
table.insert(collection, val)
end
local col = table.concat( collection, ',<br />')
col = mw.ustring.gsub(col, ',<br />praca znana z fotografii', ', znana z fotografii')
col = mw.ustring.gsub(col, 'praca znana z fotografii,<br />praca zaginiona', 'praca zaginiona, znana z fotografii')
return col
end
-- ===========================================================================
function p.get_medium_pl(entity, lang)
-- material used (P186) (item property) / applies to part (P518) (item property)
local prop = getPropertyWithQual(entity, 'P186', {'P828', 'P518'}, lang)
if not prop then
return '' -- if no P186 statements then exit
end
local LUT1 = {
Q189085 = 'pastel', Q14674='ołówek', Q1424515='węgiel', Q296955='olej', Q1783255='kredka',
Q22915256='akwarela', Q127418='atrament', Q12981547='tusz', Q204330='gwasz', Q99826317='kredka',
Q69158='kredka', Q175166='tempera', Q901944='sangwina', Q147690='kreda', Q15123870='litografia',
Q22669857='kolaż'
}
local LUT2 = {
Q11472='papierze', Q14934005='tekturze', Q389782='tekturze', Q18668582='tekturze',
Q219803='dykcie', Q106857709='desce', Q287='desce', Q12321255='płótnie', Q8231603='tkaninie'
}
local material = {}
local surface = ''
for _, p in ipairs(prop) do
if p.P518=='Q861259' then -- applies to part: painting surface
surface = ' na ' .. (LUT2[p.value] or p.value)
else
table.insert(material, LUT1[p.value])
end
end
return mw.text.listToText( material, ', ', ' i ' ) .. surface
end
-- ===========================================================================
function p.get_date(entity, lang)
local cdate = getDate (entity, 'P571', lang).str
local patrn = '%<div style="display: none;"%>date QS:[^%<]+%</div%>'
cdate = mw.ustring.gsub(cdate, patrn, '')
patrn = '%<time class="dtstart" datetime="%d%d%d%d" lang="%w%w" dir="ltr" style="white%-space:nowrap"%>(%d%d%d%d)%</time%>'
cdate = mw.ustring.gsub(cdate, patrn, '%1')
cdate = mw.ustring.gsub(cdate, 'od około (%d%d%d%d) do około (%d%d%d%d)', 'około %1-%2')
cdate = mw.ustring.gsub(cdate, 'przed środek 19', 'do połowy 19')
return cdate
end
-- ===========================================================================
function p.get_size(entity)
local h = getValue(entity, 'P2048')
local w = getValue(entity, 'P2049')
local dim = ''
if h ~= '' and w ~= '' then
dim = h .. '×' .. w .. ' cm'
dim = string.gsub(dim, '%.', ',')
end
return dim
end
-- ===========================================================================
function p.get_inscription_pl(entity)
--[[
Wikidata
inscription (P1684) - Monolingual text
applies to part (P518) - item property
]]
local LUT = {
-- positions stored in "applies to part (P518)" qualifier
Q15332388 = "u dołu",
Q17525439 = "u dołu",
Q11812678 = "u dołu",
Q15332375 = "u góry",
Q17525438 = "u góry",
Q23595 = "po środku",
Q13196750 = "po lewej",
Q17525441 = "po lewej",
Q14565199 = "po prawej",
Q17525442 = "po prawej",
Q27956549 = "lewy górny róg",
Q27956533 = "prawy górny róg",
Q27956553 = "lewy dolny róg",
Q27956561 = "prawy dolny róg",
Q9368452 = "z tyłu",
Q1542661 = "z tyłu", -- reverse
Q32198402 = "z tyłu", -- reverse
Q16938807 = "z tyłu" -- reverse
}
local AllInsc = {}
local prop = getPropertyWithQual(entity, 'P1684', {'P518'}) -- "inscription (P1684)") and applies to part (P518)
for _, p in ipairs(prop) do
if p.value~='novalue' then
local insc = '„' .. p.value .. '”'
if p.P518 then -- applies to part (P518) used for location
local pos = LUT[p.P518]
if pos then
insc = pos .. ': ' .. insc
end
end
table.insert(AllInsc, insc)
end
end
if #AllInsc>0 then
return table.concat(AllInsc,", <br/>")
end
return ''
end
-- ===========================================================================
function p.get_KTBB(entity)
local prop = getPropertyWithQual(entity, 'P1433', {'P1545'})
for _, p in ipairs(prop) do
if p.value=='Q116145383' then --published in = Catalog of Teodor Białynicki-Birula's collection
return p.P1545
end
end
return ''
end
-- ===========================================================================
function p.row(frame)
local lang = frame.args.lang or 'pl'
local qid = frame.args[1]
local ext = frame.args[2] -- extended
if qid=='header' then
local kdm = green('Q106425660','KDM')
if ext=='KTBB' then -- add KTBB column
kdm = kdm .. '\n!' .. green('Q116145383','KTBB')
end
return '{| class="wikitable sortable" style="width:100%"\n!Ilustracja\n!Tytuł\n!Data\n!' .. kdm .. '\n!Kolekcja\n!Technika\n!Wymiary\n!Sygnatura\n|-'
elseif qid=='end' then
return '|}'
elseif mw.ustring.sub(qid, 1, 1)=='Q' then
local collection, id, dim
local entity = mw.wikibase.getEntity(qid)
local image = getValue(entity, 'P18')
if image == '' then
image = '[[File:Brak zdjęcia.svg|center|100px]]'
else
image = '[[File:' .. image .. '|center|150px]]'
end
local D = {image}
table.insert(D, get_title_pl(entity) ) -- title
table.insert(D, p.get_date(entity, lang)) -- date
table.insert(D, getValueByQual(entity, 'P528', 'P972', 'Q106425660' )) -- kdm
if ext=='KTBB' then -- add KTBB column
table.insert(D, p.get_KTBB(entity))
end
table.insert(D, p.get_collection_pl(entity)) -- collection
table.insert(D, p.get_medium_pl(entity, lang)) -- medium
table.insert(D, p.get_size(entity)) -- size
table.insert(D, p.get_inscription_pl(entity)) -- sygnatura
return '| ' .. table.concat(D," \n| ") .. '\n|-'
else
return qid
end
end
return p