Lompat ke isi

Modul:Wikibase: Perbedaan antara revisi

Dari Wikipedia bahasa Indonesia, ensiklopedia bebas
Konten dihapus Konten ditambahkan
Perbarui sintaks LUA per versi terbaru dari modul yang bersangkutan.
Uzume (bicara | kontrib)
strict
 
(3 revisi perantara oleh 2 pengguna tidak ditampilkan)
Baris 1: Baris 1:
---------- Module:Wikibase ----------------
---------- Module:Wikibase ----------------
require('strict')
local p = {}
local p = {}


-- Return the item ID of the item linked to the current page.
-- Return the entity ID of the item linked to the current page.
function p.id(frame)
function p.id(frame)
if not mw.wikibase then
if not mw.wikibase then
return "no mw.wikibase"
return "no mw.wikibase"
end
end
entity = mw.wikibase.getEntityObject()
return mw.wikibase.getEntityIdForCurrentPage() or "no entity"

if entity == nil then
return "no entity"
end
return entity.id
end
end


-- Return the WD entity URL of a given data item, or of connected page
-- Return the URL of an entity given its entity ID
-- if no argument is provided to this method.
-- or the item linked to the current page if no argument is provided.
function p.wdurl(frame)
function p.wdurl(frame)
return mw.wikibase.getEntityUrl(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to entity URL of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.getEntityUrl( id )
end
end


-- Return the label of a given data item, or of connected page
-- Return the label of an entity given its entity ID
-- if no argument is provided to this method.
-- or the item linked to the current page if no argument is provided.
function p.label(frame)
function p.label(frame)
return mw.wikibase.getLabel(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to label of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.label( id )
end
end


-- Return the description of a given data item, or of connected page
-- Return the description of an entity given its entity ID
-- if no argument is provided to this method.
-- or the item linked to the current page if no argument is provided.
function p.description(frame)
function p.description(frame)
return mw.wikibase.getDescription(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to description of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.description( id )
end
end


-- Return the local page about a given data item, or of connected page
-- Return the local title of an item given its entity ID
-- or the item linked to the current page if no argument is provided.
-- if id is not specified.
function p.page(frame)
function p.page(frame)
if frame.args[1] == nil then
local qid = frame.args[1] and mw.text.trim(frame.args[1])
if not qid or qid == '' then
entity = mw.wikibase.getEntityObject()
qid = mw.wikibase.getEntityIdForCurrentPage() -- default the item connected to the current page
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
end
return mw.wikibase.sitelink( id )
return mw.wikibase.getSitelink(qid or '') -- requires one string arg
end
end


-- Return the data type of a property
-- Return the data type of a property given its entity ID.
function p.datatype(frame)
function p.datatype(frame)
if frame.args[1] and string.find(frame.args[1], "Property:P") then
local prop = mw.wikibase.getEntity(frame.args[1] and mw.text.trim(frame.args[1]):upper():gsub('PROPERTY:P', 'P')) -- trim and remove any "Property:" prefix
return prop and prop.datatype
if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P")) then
end
return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype

end
-- Returns true if property datavalue is found excluding novalue/somevalue and deprecated rank
elseif frame.args[1] and string.find(frame.args[1], "P") then
function p.validProperty(frame)
if mw.wikibase.getEntityObject(frame.args[1]) then
return mw.wikibase.getEntityObject(frame.args[1]).datatype
local property = mw.text.trim(frame.args[1])
local item = frame.args.item or frame.args.from; if item == '' then item = nil end
end
if item == nil then item = mw.wikibase.getEntityIdForCurrentPage() end
end
if item == nil then return end
local properties = mw.wikibase.getBestStatements(item, property)
if #properties == 0 then return end
return properties[1].mainsnak.datavalue and true or nil
end
end



Revisi terkini sejak 14 April 2024 19.52

---------- Module:Wikibase ----------------
require('strict')
local p = {}

-- Return the entity ID of the item linked to the current page.
function p.id(frame)
	if not mw.wikibase then
		return "no mw.wikibase"
	end
	return mw.wikibase.getEntityIdForCurrentPage() or "no entity"
end

-- Return the URL of an entity given its entity ID
-- or the item linked to the current page if no argument is provided.
function p.wdurl(frame)
	return mw.wikibase.getEntityUrl(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to entity URL of the item linked to the current page
end

-- Return the label of an entity given its entity ID
-- or the item linked to the current page if no argument is provided.
function p.label(frame)
	return mw.wikibase.getLabel(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to label of the item linked to the current page
end

-- Return the description of an entity given its entity ID
-- or the item linked to the current page if no argument is provided.
function p.description(frame)
	return mw.wikibase.getDescription(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to description of the item linked to the current page
end

-- Return the local title of an item given its entity ID
-- or the item linked to the current page if no argument is provided.
function p.page(frame)
	local qid = frame.args[1] and mw.text.trim(frame.args[1])
	if not qid or qid == '' then
		qid = mw.wikibase.getEntityIdForCurrentPage() -- default the item connected to the current page
	end
	return mw.wikibase.getSitelink(qid or '') -- requires one string arg
end

-- Return the data type of a property given its entity ID.
function p.datatype(frame)
	local prop = mw.wikibase.getEntity(frame.args[1] and mw.text.trim(frame.args[1]):upper():gsub('PROPERTY:P', 'P')) -- trim and remove any "Property:" prefix
	return prop and prop.datatype
end

-- Returns true if property datavalue is found excluding novalue/somevalue and deprecated rank
function p.validProperty(frame)
	local property = mw.text.trim(frame.args[1])
	local item = frame.args.item or frame.args.from; if item == '' then item = nil end
	if item == nil then item = mw.wikibase.getEntityIdForCurrentPage() end
	if item == nil then return end
	local properties = mw.wikibase.getBestStatements(item, property)
	if #properties == 0 then return end
	return properties[1].mainsnak.datavalue and true or nil
end

return p