Modul:Wikidata/lib: Porovnání verzí
Skočit na navigaci
Skočit na vyhledávání
+formatTextInLanguage
m (naimportována 1 revize) |
*>Matěj Suchánek (+formatTextInLanguage) |
||
Řádek 6: | Řádek 6: | ||
begin = { 'P569', 'P580' }, | begin = { 'P569', 'P580' }, | ||
ending = { 'P570', 'P582' }, | ending = { 'P570', 'P582' }, | ||
lang = { 'P364', 'P407' }, | lang = { 'P364', 'P407', 'P2439' }, | ||
point = { 'P571', 'P577', 'P585' }, | point = { 'P571', 'P577', 'P585' }, | ||
} | }, | ||
datatypeToValueType = { | |||
['commonsMedia'] = 'string', | |||
['external-id'] = 'string', | |||
['geo-shape'] = 'string', | |||
['globe-coordinate'] = 'globecoordinate', | |||
['math'] = 'string', | |||
['monolingualtext'] = 'monolingualtext', | |||
['quantity'] = 'quantity', | |||
['string'] = 'string', | |||
['tabular-data'] = 'string', | |||
['time'] = 'time', | |||
['url'] = 'string', | |||
['wikibase-item'] = 'wikibase-entityid', | |||
['wikibase-property'] = 'wikibase-entityid', | |||
}, | |||
} | } | ||
Řádek 15: | Řádek 30: | ||
function p.addWdClass(str) | function p.addWdClass(str) | ||
return '<span class="wd">' .. str .. '</span>' | return '<span class="wd">' .. str .. '</span>' | ||
end | |||
function p.formatTextInLanguage(text, language) | |||
return mw.text.tag('span', { lang = language }, text) | |||
end | end | ||
function p.IsSnakValue(snak) | function p.IsSnakValue(snak) | ||
return snak.snaktype == 'value' | return snak.snaktype == 'value' | ||
end | |||
function p.getLabelInLanguage(entityId, langs) | |||
langs = p.textToTable(langs) | |||
local label, lang = mw.wikibase.getLabelWithLang(entityId) | |||
if label then | |||
for _, lg in ipairs(langs) do | |||
if lg == lang then | |||
return label, lang | |||
end | |||
end | |||
end | |||
return nil, nil | |||
end | end | ||
Řádek 34: | Řádek 66: | ||
local options = options or {} | local options = options or {} | ||
local split_pattern = options.split_pattern or "%s*,%s*" | local split_pattern = options.split_pattern or "%s*,%s*" | ||
something = mw.text.split(something, split_pattern) | something = mw.text.split(something, split_pattern) | ||
end | end | ||
Řádek 47: | Řádek 72: | ||
end | end | ||
function p.getItemIdFromURI(uri) | |||
return mw.ustring.match(uri, '(Q%d+)') | |||
end | |||
function p.isPropertyId(value) | |||
return mw.ustring.match(value, '^[Pp][1-9]%d-$') and true | |||
end | |||
function p.simpleCompare(first, second) | |||
if first == second then | |||
return 0 | |||
end | |||
if first < second then | |||
return -1 | |||
else | |||
return 1 | |||
end | |||
end | |||
-- @deprecated | |||
function p.getEntityIdFromValue(value) | function p.getEntityIdFromValue(value) | ||
local entityType = value['entity-type'] | local entityType = value['entity-type'] | ||
Řádek 76: | Řádek 121: | ||
allowed = { allowed } | allowed = { allowed } | ||
end | end | ||
return p.formatError('invalid-datatype2', method, mw.listToText(allowed, '“, „', '“ nebo „'), provided) | return p.formatError('invalid-datatype2', method, mw.text.listToText(allowed, '“, „', '“ nebo „'), provided) | ||
end | end | ||
return p | return p |