Content deleted Content added
add check that page is valid |
|||
(One intermediate revision by one other user not shown) | |||
Line 1:
local p = {}
function p.
return p._id(id,alt)▼
end▼
▲function p._id(id,alt)
if type(id) == 'string' then▼
id = mw.ustring.upper(mw.ustring.sub(id,1,1))..mw.ustring.sub(id,2)▼
-- id is in the proper format for a Wikidata entity▼
▲ if mw.wikibase.isValidEntityId(id) then
▲ id = mw.wikibase.getEntity(id)
if id then▼
return id.id▼
end▼
end
else
▲ id = mw.wikibase.getEntityIdForTitle(id)
end
▲ if id then
▲ end
-- id is a title that matches a Wikidata entity▼
local instanceOf = mw.wikibase.getBestStatements(id, 'P31')[1] --instance of▼
if instanceOf and instanceOf.mainsnak.datavalue.value.id ~= 'Q4167410' then▼
▲
-- not disambiguation▼
return checkId(idOrTitle)
else
▲ return mw.wikibase.getEntity(id).id
local eid = mw.wikibase.getEntityIdForTitle(idOrTitle)
▲ -- instance-of value is missing or is not "disambiguation"
return checkId(eid)
▲ end
else
-- idOrTitle is a title, but no wikidata item exists for that title
local page = mw.title.new(idOrTitle)
if page then -- valid title
local rtarget = page.redirectTarget
if rtarget then -- title is a Wikipedia redirect
end
end
end
end
end
return alt
end
|