Difference between revisions of "Module:Entity"
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
return mw.wikibase.getSitelink(mw.wikibase.getEntityIdForTitle(frame.args[0])) | return mw.wikibase.getSitelink(mw.wikibase.getEntityIdForTitle(frame.args[0])) | ||
end | end | ||
− | |||
function p.getProp ( frame ) | function p.getProp ( frame ) | ||
− | + | ||
− | + | currTitle = mw.title.getCurrentTitle().text | |
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] | ||
sl = mw.wikibase.getSitelink(pv) | sl = mw.wikibase.getSitelink(pv) | ||
if sl ~= nil then | if sl ~= nil then | ||
return sl | return sl | ||
else | else | ||
− | return | + | return currEntity:formatPropertyValues( frame.args[1] ).value |
end | end | ||
end | end | ||
+ | |||
function p.get2ndLevelProp ( frame ) | function p.get2ndLevelProp ( frame ) |
Revision as of 21:21, 16 April 2019
Documentation for this module may be created at Module:Entity/doc
local p = {} -- p stands for package function p.get( frame ) return mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text) end function p.getUrl ( frame ) return mw.wikibase.getEntityUrl(mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text)) end function p.getSiteLink ( frame ) return mw.wikibase.getSitelink(mw.wikibase.getEntityIdForTitle(frame.args[0])) end function p.getProp ( frame ) currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] sl = mw.wikibase.getSitelink(pv) if sl ~= nil then return sl else return currEntity:formatPropertyValues( frame.args[1] ).value end end function p.get2ndLevelProp ( frame ) -- return mw.wikibase.getEntityIdForTitle(mw.wikibase.getEntity(mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text)):formatPropertyValues( frame.args[1] ).value) pv = mw.wikibase.getEntity(mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text)):getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] pv2 = mw.wikibase.getEntity(pv):getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] if pv2 ~= nil then return pv2 else return mw.wikibase.getEntity(pv):formatPropertyValues( frame.args[2] ).value end end function p.get2ndLevelSL ( frame ) -- return mw.wikibase.getEntityIdForTitle(mw.wikibase.getEntity(mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text)):formatPropertyValues( frame.args[1] ).value) pv = mw.wikibase.getEntity(mw.wikibase.getEntityIdForTitle(mw.title.getCurrentTitle().text)):getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] pv2 = mw.wikibase.getEntity(pv):getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] sl = mw.wikibase.getSitelink(pv2) if sl ~= nil then return sl else return mw.wikibase.getEntity(pv):formatPropertyValues( frame.args[2] ).value end end return p