Jump to content

Module:ResolveEntityId

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}functionp._id(idOrTitle,alt)localfunctioncheckId(id)ifidandmw.wikibase.entityExists(id)thenlocalsitelink=mw.wikibase.getSitelink(id)ifsitelinkthenreturnmw.wikibase.getEntityIdForTitle(sitelink)ormw.wikibase.getEntity(id).idendreturnmw.wikibase.getEntity(id).idelsereturnaltendendiftype(idOrTitle)=='string'thenidOrTitle=mw.ustring.upper(mw.ustring.sub(idOrTitle,1,1))..mw.ustring.sub(idOrTitle,2)ifmw.wikibase.isValidEntityId(idOrTitle)then-- idOrTitle is in the proper format for a Wikidata entity IDreturncheckId(idOrTitle)elselocaleid=mw.wikibase.getEntityIdForTitle(idOrTitle)ifeidthen-- idOrTitle is a title that matches a Wikidata entitylocalinstanceOf=mw.wikibase.getBestStatements(eid,'P31')[1]--instance ofifnotinstanceOforinstanceOf.mainsnak.datavalue.value.id~='Q4167410'then-- instance-of value is missing or is not "disambiguation"returncheckId(eid)endelse-- idOrTitle is a title, but no wikidata item exists for that titlelocalpage=mw.title.new(idOrTitle)ifpagethen-- valid titlelocalrtarget=page.redirectTargetifrtargetthen-- title is a Wikipedia redirectreturnp._id(rtarget.fullText,alt)endendendendendreturnaltendfunctionp.entityid(frame)returnp._id(frame.args[1],frame.args[2])endreturnp
close