Jump to content

Module:Sandbox/Gnosygnu

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gnosygnu (talk | contribs) at 22:22, 9 May 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--This Module is for various Lua experimentation.
--It is not meant to be used by other pages, and can be safely deleted.
local p = {}

function p.string_compare_gt(frame)
  return frame.args[1] > frame.args[2]
end

function p.string_compare_lte(frame)
  return frame.args[1] <= frame.args[2]
end

function p.string_compare_example(frame)
  return ('АД' > 'Аг') and ('АД' <= 'Аж')
end

function p.test()
	local entity = mw.wikibase.sitelink('Q2')
	return entity
end

function p.wikibase_test(frame)
  local entity = mw.wikibase.getEntityObject()
  if not entity then
    return 'no entity'
  end
  local claims = entity.claims
  if not claims then
    return 'no claims'
  end
  local prop = claims[frame.args[1]]
  if not prop then
    return 'missing:'..frame.args[1]
  end
  local rv = ''
  local val = prop[0]
  if not val then
    rv = rv .. '0:nil;'
  else
    rv = rv .. '0:val;'  
  end
  val = prop[1]
  if not val then
    rv = rv .. '1:nil;'
  else
    rv = rv .. '1:val;'  
  end
  for i = 1, #prop do
  	rv = rv .. tostring(i) .. prop[i].rank
  end
  return rv
end

return p