localp={}functionp._entityid(_,id,alt)-- backwards compatibility for deprecated _entityid functionreturnp._id(id,alt)endfunctionp._id(id,alt)iftype(id)=='string'thenid=mw.ustring.upper(mw.ustring.sub(id,1,1))..mw.ustring.sub(id,2)ifmw.ustring.match(id,'^Q%d+$')then-- id is in the proper format for a Wikidata entityifmw.wikibase.isValidEntityId(id)then-- id is validid=mw.wikibase.getEntity(id)ifidthen-- entity existsreturnid.idendendelseid=mw.wikibase.getEntityIdForTitle(id)ifidthen-- id is a title that matches a Wikidata entitylocalinstanceOf=mw.wikibase.getBestStatements(id,'P31')[1]--instance ofifinstanceOfandinstanceOf.mainsnak.datavalue.value.id~='Q4167410'then-- not disambiguationreturnmw.wikibase.getEntity(id).idelseifinstanceOf==nilthen-- id is a title, but is missing an instance-of valuereturnmw.wikibase.getEntity(id).idendendendendreturnaltornilendfunctionp.entityid(frame)returnp._id(frame.args[1],frame.args[2])endreturnp