Modul:Wikidata utilities: Unterschied zwischen den Versionen

KKeine Bearbeitungszusammenfassung
(checkId entfernt)
Zeile 1: Zeile 1:
local fw = {}
local fw = {}
function fw.checkId( id ) -- only syntax check
if ( not id ) or ( type( id ) ~= 'string' ) or ( id == '' ) then
return ''
end
local i = id:upper()
if not mw.ustring.match( i, '^Q[%d]+$') then
if mw.ustring.match( i, '^[%d]+$') then -- only number
return 'Q' .. i
else -- invalid id
return ''
end
end
return i
end


function fw.getEntity( id )
function fw.getEntity( id )
local wrongQualifier = false
local wrongQualifier = false
local entity = nil
local entity = nil
 
local i = fw.checkId( id )
if not id or id == '' then
if i ~= '' then
return '', entity, wrongQualifier
end
if mw.wikibase.isValidEntityId( id ) then
-- expensive function call
-- expensive function call
entity = mw.wikibase.getEntity( i )
entity = mw.wikibase.getEntity( id )
if not entity then
i = ''
wrongQualifier = true
end
else
if id ~= '' then wrongQualifier = true end
end
end
return i, entity, wrongQualifier
if not entity then
id = ''
wrongQualifier = true
end
 
return id, entity, wrongQualifier
end
end