Модуль:NotableWorks
Харагдаса
Для документации этого модуля может быть создана страница Модуль:NotableWorks/doc
-- 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, 'bxr' )
-- if not label then
-- label = 'Label should be filled. WorkEntityId = '..workEntityId
--end
local oldLabel = label
local wwd = mw.wikibase.getEntity(workEntityId)
local ruwiki = wwd and wwd.sitelinks and wwd.sitelinks.bxrwiki and wwd.sitelinks.bxrwiki.title
if label then
local bracketPos
-- label = string.gsub(label, 'скульптура', '')
-- label = string.gsub(label, 'бюст', '')
-- label = string.gsub(label, 'барельеф', '')
-- label = string.gsub(label, 'статуя', '')
-- label = string.gsub(label, 'памятник', '')
-- label = string.gsub(label, 'портрет', '')
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)..'<font color=gray>'..string.sub(label, bracketPos)..'</font>'
-- end
if bxrwiki then
label = "[["..bxrwiki.."|"..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, 'bxr' )
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