Module:Wd: Difference between revisions

867 bytes removed ,  25 February 2021
no edit summary
No edit summary
No edit summary
Line 652: Line 652:
local title = nil
local title = nil
local prefix= ""
local prefix= ""
if not id then
id = mw.wikibase.getEntityIdForCurrentPage()
if not id then
return ""
end
end


id = id:upper()  -- just to be sure
id = id:upper()  -- just to be sure
Line 665: Line 657:
if raw then
if raw then
-- check if given id actually exists
-- check if given id actually exists
if mw.wikibase.isValidEntityId(id) and mw.wikibase.entityExists(id) then
if id:sub(1,1) == "P" then
label = id
 
if id:sub(1,1) == "P" then
prefix = "Property:"
prefix = "Property:"
end
end
end


prefix = "d:" .. prefix
prefix = "d:" .. prefix
Line 687: Line 675:


-- get label
-- get label
if not label then
label = mw.wikibase.getLabelByLang(id, self.langCode)
end
end
end


if not label then
if not label then
Line 2,395: Line 2,380:
-- get the entity ID from either the positional argument, the eid argument or the page argument
-- get the entity ID from either the positional argument, the eid argument or the page argument
cfg.entityID = getEntityId(lastArg, args[p.args.eid], args[p.args.page], true)
cfg.entityID = getEntityId(lastArg, args[p.args.eid], args[p.args.page], true)
if cfg.entityID == "" or not mw.wikibase.entityExists(cfg.entityID) then
return ""  -- we cannot continue without an entity
end


-- serve according to the given command
-- serve according to the given command
Line 2,405: Line 2,386:
elseif funcName == p.generalCommands.title then
elseif funcName == p.generalCommands.title then
cfg.inSitelinks = true
cfg.inSitelinks = true
if cfg.entityID:sub(1,1) == "Q" then
value = mw.wikibase.getSitelink(cfg.entityID)
end


if cfg.curState.linked and value then
if cfg.curState.linked and value then
value = buildWikilink(value)
value = buildWikilink(value)
end
elseif funcName == p.generalCommands.description then
value = mw.wikibase.getDescription(cfg.entityID)
else
local parsedFormat, formatParams
local hooks = {count = 0}
cfg.entity = mw.wikibase.getEntity(cfg.entityID)
if funcName == p.generalCommands.alias or funcName == p.generalCommands.badge then
cfg.curState.singleValue = true
end
end