Modul:Wikidata/Sorters/alpha
Vzhled
require 'Modul:No globals'
local p = {}
local lib = require 'Modul:Wikidata/lib'
local Collation = require 'Modul:Collation'
local Formatters = require 'Modul:Wikidata/Formatters'
local cache = {}
local function getLabel(value)
if not cache[value] then
cache[value] = mw.wikibase.label(value) or false
end
return cache[value] or nil
end
local function getValue(snak)
local value = Formatters.getRawValue(snak)
if snak.datavalue.type == 'wikibase-entityid' then
return getLabel(value)
end
return value
end
function p.isCompleteSnak(snak)
return lib.IsSnakValue(snak) and (
snak.datavalue.type == 'string' or
snak.datavalue.type == 'monolingualtext' or
((getValue(snak) and true) or false)
)
end
function p.isCompleteStatement(statement)
return p.isCompleteSnak(statement.mainsnak)
end
function p.mayCompareSnak(snak)
local valueType = lib.datatypeToValueType[snak.datatype]
return valueType == 'monolingualtext' or valueType == 'string' or valueType == 'wikibase-entityid'
end
function p.mayCompareStatement(statement)
return p.mayCompareSnak(statement.mainsnak)
end
function p.compareSnaks(first, second)
return Collation.compare(getValue(first), getValue(second))
end
function p.compareStatements(first, second)
return p.compareSnaks(first.mainsnak, second.mainsnak)
end
return p