יחידה:ויקינתונים

מתוך ויקיטקסט, מאגר הטקסטים החופשי
קפיצה לניווט קפיצה לחיפוש

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:ויקינתונים/תיעוד

-- Copied from //en.wikipedia.org/w/index.php?title=Module:Wikidata&oldid=573526337

local p = {}
 
-- This is used to get a normal wiki-linked value, or a comma separated list of them if multiple values exist
p.getValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for k, v in pairs(entity.claims[propertyID]) do
                if (mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"])) then
                    out[#out + 1] = "[[" .. mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
                else
                    out[#out + 1] = "[[:d:" .. "Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "]]<small><abbr title='Article is not yet available in this wiki'>[?]</abbr></small>"
                end
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end
 
-- Added for he.wikisource
-- This is used to get a normal wiki-linked value, or a comma separated list of them if multiple values exist
p.getOneValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for k, v in pairs(entity.claims[propertyID]) do
                if (mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"])) then
                    return "[[" .. mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
                else
                    return "[[:d:" .. "Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "]]<small><abbr title='Article is not yet available in this wiki'>[?]</abbr></small>"
                end
            end
        else
            return ""
        end
    else
        return input_parm
    end
end
 
-- This is used to get a value like 'male' (for property p21) which won't be linked
p.getRawValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for k, v in pairs(entity.claims[propertyID]) do
                out[#out + 1] = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"])
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end
 
-- Added for he.wikisource
p.getOneRawValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            for k, v in pairs(entity.claims[propertyID]) do
            	if type(v.mainsnak.datavalue.value) == "table" then
            		if v.mainsnak.datavalue.value["numeric-id"] then
            			return mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"])
            		else
            			return v.mainsnak.datavalue.value.time
            		end
            	else
                	return v.mainsnak.datavalue.value
                end
            end
        else
            return ""
        end
    else
        return input_parm
    end
end
 
-- This is used to get a date value for date_of_birth (p569), etc. which won't be linked -- consolidate by testing if entity.claims[propertyID].mainsnak.datavalue.type is "time"
p.getDateValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    local date_format = mw.text.trim(frame.args[3] or "dmy")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            local dt = {}
            for k, v in pairs(entity.claims[propertyID]) do
                local d = v.mainsnak.datavalue.value.time
                dt.year = string.sub(d, 9, 12)
                dt.month = string.sub(d, 14, 15)
                dt.day = string.sub(d, 17, 18)
                if date_format == "dmy" then
                    out[#out + 1] = os.date("%e %B %Y", os.time(dt))
                else
                    out[#out + 1] = os.date("%B %e, %Y", os.time(dt))
                end
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end
 
-- Added for he.wikisource
-- This is used to get name of page on other site.
p.getSitelink = function(frame)
    local siteID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" or input_parm == "_קח_ויקינתונים_" then
        local entity = mw.wikibase.getEntity()
        if entity.sitelinks[siteID] ~= nil then
        	return entity.sitelinks[siteID].title
        else
            return ""
        end
    else
        return input_parm
    end
end

function getPropertyOfItem(item, property, propertyFormat, single)
	-- Currently cannot work. See https://bugzilla.wikimedia.org/show_bug.cgi?id=47930
	return item
end

p["מאפיין_של_פריט"] = function(frame)
	local item = mw.text.trim(frame.args[1] or "")
	local property = mw.text.trim(frame.args[2] or "")
	local formatHe = mw.text.trim(frame.args[3] or "טקסט")
	local single = ((mw.text.trim(frame.args[4] or "") == "רשימה") or true)
	local propertyFormat = "text"
	if formatHe == "תמונה" then propertyFormat = "picture" end
	return getPropertyOfItem( item, property, propertyFormat, single )
end

p["קבל_ערך"] = function(frame)
    return p.getValue(frame)
end
p["קבל_ערך_אחד"] = function(frame)
    return p.getOneValue(frame)
end
p["קבל_ערך_גולמי"] = function(frame)
    return p.getRawValue(frame)
end
p["קבל_ערך_גולמי_אחד"] = function(frame)
    return p.getOneRawValue(frame)
end

return p