Difference between revisions of "Module:Entity"
Jump to navigation
Jump to search
(28 intermediate revisions by the same user not shown) | |||
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 ) | ||
+ | |||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | 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 | ||
+ | else | ||
+ | return "" | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.getPropFromIndex ( frame ) | ||
+ | |||
+ | arg1 = frame.args[1] | ||
+ | arg2 = frame.args[2] | ||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | currElement = currEntity:getAllStatements(arg1)[tonumber(arg2)] | ||
+ | if currElement ~= nil then | ||
+ | pv = currEntity:getAllStatements(arg1)[tonumber(arg2)].mainsnak.datavalue.value['id'] | ||
+ | sl = mw.wikibase.getSitelink(pv) | ||
+ | if sl ~= nil then | ||
+ | return sl | ||
+ | else | ||
+ | return mw.wikibase.getEntity(currEntity:getAllStatements(arg1)[tonumber(arg2)].mainsnak.datavalue.value['id']):getLabel() | ||
+ | end | ||
+ | else | ||
+ | return "" | ||
+ | end | ||
+ | else | ||
+ | return "" | ||
+ | end | ||
+ | end | ||
+ | function p.get2ndLevelSL ( frame ) | ||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity2 = mw.wikibase.getEntity(pv) | ||
+ | if currEntity2 ~= nil then | ||
+ | pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] | ||
+ | sl = mw.wikibase.getSitelink(pv2) | ||
+ | if sl ~= nil then | ||
+ | return sl | ||
+ | else | ||
+ | return currEntity2:formatPropertyValues( frame.args[2] ).value | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.get3rdLevelSL ( frame ) | ||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity2 = mw.wikibase.getEntity(pv) | ||
+ | if currEntity2 ~= nil then | ||
+ | pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity3 = mw.wikibase.getEntity(pv2) | ||
+ | if currEntity3 ~= nil then | ||
+ | pv3 = currEntity3:getBestStatements( frame.args[3] )[1].mainsnak.datavalue.value['id'] | ||
+ | sl = mw.wikibase.getSitelink(pv3) | ||
+ | if sl ~= nil then | ||
+ | return sl | ||
+ | else | ||
+ | return currEntity3:formatPropertyValues( frame.args[3] ).value | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.get2ndLevelProp ( frame ) | ||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity2 = mw.wikibase.getEntity(pv) | ||
+ | if currEntity2 ~= nil then | ||
+ | if (currEntity2:getBestStatements( frame.args[2] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] | ||
+ | if pv2 ~= nil then | ||
+ | return pv2 | ||
+ | else | ||
+ | return currEntity2:formatPropertyValues( frame.args[2] ).value | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.get3rdLevelProp ( frame ) | ||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) | ||
+ | currEntity = mw.wikibase.getEntity(currEntityId) | ||
+ | if currEntity ~= nil then | ||
+ | if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity2 = mw.wikibase.getEntity(pv) | ||
+ | if currEntity2 ~= nil then | ||
+ | if (currEntity2:getBestStatements( frame.args[2] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] | ||
+ | currEntity3 = mw.wikibase.getEntity(pv2) | ||
+ | if currEntity3 ~= nil then | ||
+ | if (currEntity3:getBestStatements( frame.args[3] )[1] == nil) then | ||
+ | return | ||
+ | end | ||
+ | pv3 = currEntity3:getBestStatements( frame.args[3] )[1].mainsnak.datavalue.value['id'] | ||
+ | if pv3 ~= nil then | ||
+ | return pv3 | ||
+ | else | ||
+ | return currEntity3:formatPropertyValues( frame.args[3] ).value | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | |||
+ | |||
+ | function p.getCurrentLabel ( frame ) | ||
+ | |||
+ | currTitle = mw.title.getCurrentTitle().text | ||
+ | return currTitle | ||
+ | end | ||
+ | |||
return p | return p |
Latest revision as of 17:17, 17 February 2020
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) if currEntity ~= nil then if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then return end 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 else return "" end end function p.getPropFromIndex ( frame ) arg1 = frame.args[1] arg2 = frame.args[2] currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) if currEntity ~= nil then currElement = currEntity:getAllStatements(arg1)[tonumber(arg2)] if currElement ~= nil then pv = currEntity:getAllStatements(arg1)[tonumber(arg2)].mainsnak.datavalue.value['id'] sl = mw.wikibase.getSitelink(pv) if sl ~= nil then return sl else return mw.wikibase.getEntity(currEntity:getAllStatements(arg1)[tonumber(arg2)].mainsnak.datavalue.value['id']):getLabel() end else return "" end else return "" end end function p.get2ndLevelSL ( frame ) currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) if currEntity ~= nil then pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] currEntity2 = mw.wikibase.getEntity(pv) if currEntity2 ~= nil then pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] sl = mw.wikibase.getSitelink(pv2) if sl ~= nil then return sl else return currEntity2:formatPropertyValues( frame.args[2] ).value end end end end function p.get3rdLevelSL ( frame ) currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) if currEntity ~= nil then pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] currEntity2 = mw.wikibase.getEntity(pv) if currEntity2 ~= nil then pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] currEntity3 = mw.wikibase.getEntity(pv2) if currEntity3 ~= nil then pv3 = currEntity3:getBestStatements( frame.args[3] )[1].mainsnak.datavalue.value['id'] sl = mw.wikibase.getSitelink(pv3) if sl ~= nil then return sl else return currEntity3:formatPropertyValues( frame.args[3] ).value end end end end end function p.get2ndLevelProp ( frame ) currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) if currEntity ~= nil then if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then return end pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] currEntity2 = mw.wikibase.getEntity(pv) if currEntity2 ~= nil then if (currEntity2:getBestStatements( frame.args[2] )[1] == nil) then return end pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] if pv2 ~= nil then return pv2 else return currEntity2:formatPropertyValues( frame.args[2] ).value end end end end function p.get3rdLevelProp ( frame ) currTitle = mw.title.getCurrentTitle().text currEntityId = mw.wikibase.getEntityIdForTitle(currTitle) currEntity = mw.wikibase.getEntity(currEntityId) if currEntity ~= nil then if (currEntity:getBestStatements( frame.args[1] )[1] == nil) then return end pv = currEntity:getBestStatements( frame.args[1] )[1].mainsnak.datavalue.value['id'] currEntity2 = mw.wikibase.getEntity(pv) if currEntity2 ~= nil then if (currEntity2:getBestStatements( frame.args[2] )[1] == nil) then return end pv2 = currEntity2:getBestStatements( frame.args[2] )[1].mainsnak.datavalue.value['id'] currEntity3 = mw.wikibase.getEntity(pv2) if currEntity3 ~= nil then if (currEntity3:getBestStatements( frame.args[3] )[1] == nil) then return end pv3 = currEntity3:getBestStatements( frame.args[3] )[1].mainsnak.datavalue.value['id'] if pv3 ~= nil then return pv3 else return currEntity3:formatPropertyValues( frame.args[3] ).value end end end end end function p.getCurrentLabel ( frame ) currTitle = mw.title.getCurrentTitle().text return currTitle end return p