Moduli:NotableWorks
-- Module: NotableWorks local p = {}
-- Function to get the current page's RUWIKI.Data item ID function p.getPageWikidataId()
local pageWikidata = mw.wikibase.getEntityIdForCurrentPage() return pageWikidata
end
-- Function to retrieve creator (P170) from the page's RUWIKI.Data item function p.getCreator(entityId)
local wd = mw.wikibase.getEntity(entityId)
if wd and wd.claims and wd.claims['P170'] then
for _, claim in ipairs(wd.claims['P170']) do
local creator = claim.mainsnak.datavalue and claim.mainsnak.datavalue.value
if creator then
return creator.id
end
end
end
return nil -- No creator found
end
-- Get all notable works (P800) for the entity function p.processNotableWorksClaims(notableWorks, wd)
if wd and wd.claims and wd.claims['P800'] then
for _, claim in ipairs(wd.claims['P800']) do
-- Add the label of each notable work to the list
local workEntityId = claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value.id
local label = mw.wikibase.getLabel( workEntityId, 'olo' )
-- if not label then
-- label = 'Label should be filled. WorkEntityId = '..workEntityId
--end
local oldLabel = label
local wwd = mw.wikibase.getEntity(workEntityId)
local olowiki = wwd and wwd.sitelinks and wwd.sitelinks.olowiki and wwd.sitelinks.olowiki.title
if label then
local bracketPos
-- label = string.gsub(label, 'vestokuva', ) -- label = string.gsub(label, 'rinduvestos', ) -- label = string.gsub(label, 'kohokuva', ) -- label = string.gsub(label, 'pačas', ) -- label = string.gsub(label, 'mustopačas', ) -- label = string.gsub(label, 'portriettu', )
label = string.gsub(label, ', ,', ',')
label = string.gsub(label, '%(, ', '(')
label = string.gsub(label, '%(,', '(')
label = string.gsub(label, '%( %)', )
label = string.gsub(label, '%(%)', )
-- if label then -- bracketPos = string.find(label, " %(") - 1 -- end -- if bracketPos then -- label = string.sub(label, 1, bracketPos)..''..string.sub(label, bracketPos)..'' -- end
if olowiki then
label = ""..label..""
end
--label = label..' ! '..oldLabel
table.insert(notableWorks, label)
end
end
end
end
function p.getCreatorLabel(frame)
local entityId = frame.args[1]
-- If no entityId is provided, use the current page's Wikidata ID
if not entityId or entityId == "" then
entityId = p.getPageWikidataId()
local creatorEntityId = p.getCreator(entityId)
if creatorEntityId then
entityId = creatorEntityId
end
end
creatorLabel = mw.wikibase.getLabel( entityId, 'olo' ) return creatorLabel
end
-- Main function to return notable works as comma-separated text function p.getNotableWorks(frame)
-- Get the Wikidata ID passed as a parameter local entityId = frame.args[1]
-- If no entityId is provided, use the current page's Wikidata ID
if not entityId or entityId == "" then
entityId = p.getPageWikidataId()
end
local notableWorks = {}
-- Fetch the entity from RW.Data
local wd = mw.wikibase.getEntity(entityId)
p.processNotableWorksClaims(notableWorks, wd)
if #notableWorks == 0 then local creatorEntityId = p.getCreator(entityId) if creatorEntityId then wd = mw.wikibase.getEntity(creatorEntityId) p.processNotableWorksClaims(notableWorks, wd) end end -- Return the notable works as a comma-separated list local worksList = "\n* "..table.concat(notableWorks, "\n*").."\n" return worksList
end
return p