Модуль:Wikidata2: юрамалар арасында аерма

Wikipedia — ирекле энциклопедия проектыннан ([http://tt.wikipedia.org.ttcysuttlart1999.aylandirow.tmf.org.ru/wiki/Wikidata2 latin yazuında])
Контент бетерелгән Контент өстәлгән
Ajdar (бәхәс | кертем)
Яңа бит: «local i18n = { ["errors"] = { ["property-param-not-provided"] = "Не дан параметр свойства", ["entity-not-found"] = "Сущность н…»
 
Lucie Kaffee (WMDE) (бәхәс | кертем)
Change from mw.wikibase.getEntity (deprecated) to mw.wikibase.getEntityObject
Юл номеры - 17: Юл номеры - 17:
function getEntityFromId( id )
function getEntityFromId( id )
if id then
if id then
return mw.wikibase.getEntity( id )
return mw.wikibase.getEntityObject( id )
end
end
return mw.wikibase.getEntity()
return mw.wikibase.getEntityObject()
end
end


Юл номеры - 25: Юл номеры - 25:
local prefix = ''
local prefix = ''
if value['entity-type'] == 'item' then
if value['entity-type'] == 'item' then
prefix = 'q'
prefix = 'Q'
elseif value['entity-type'] == 'property' then
elseif value['entity-type'] == 'property' then
prefix = 'p'
prefix = 'P'
else
else
return formatError( 'unknown-entity-type' )
return formatError( 'unknown-entity-type' )
Юл номеры - 33: Юл номеры - 33:
return prefix .. value['numeric-id']
return prefix .. value['numeric-id']
end
end

function formatError( key )
function formatError( key )
return '<span class="error">' .. i18n.errors[key] .. '</span>'
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
end



function formatStatements( options )
function formatStatements( options )
Юл номеры - 50: Юл номеры - 49:
end
end


if (entity.claims == nil) or (not entity.claims[string.lower(options.property)]) then
if (entity.claims == nil) or (not entity.claims[string.upper(options.property)]) then
return '' --TODO error?
return '' --TODO error?
end
end
Юл номеры - 56: Юл номеры - 55:
--Format statement and concat them cleanly
--Format statement and concat them cleanly
local formattedStatements = {}
local formattedStatements = {}
for i, statement in pairs( entity.claims[string.lower(options.property)] ) do
for i, statement in pairs( entity.claims[string.upper(options.property)] ) do
table.insert( formattedStatements, formatStatement( statement, options ) )
table.insert( formattedStatements, formatStatement( statement, options ) )
end
end

27 фев 2015, 12:29 юрамасы

{{Wikidata}} эчендә кулланыла (параметрлар тасвирламасын шунда ук карагыз). Модуль:Wikidata/config ярдәмендә көйләнелә




local i18n = {
    ["errors"] = {
        ["property-param-not-provided"] = "Не дан параметр свойства",
        ["entity-not-found"] = "Сущность не найдена.",
        ["unknown-claim-type"] = "Неизвестный тип заявления.",
        ["unknown-snak-type"] = "Неизвестный тип снэка.",
        ["unknown-datavalue-type"] = "Неизвестный тип значения данных.",
        ["unknown-entity-type"] = "Неизвестный тип сущности.",
        ["unknown-value-module"] = "Вы должны установить и значение-модуль, и значение-функцию.",
        ["value-module-not-found"] = "Модуль, на который указывает значение, не найден.",
        ["value-function-not-found"] = "Функция, на которую указывает значение, не найдена."
    },
    ["somevalue"] = "",
    ["novalue"] = ""
}

function getEntityFromId( id )
    if id then
        return mw.wikibase.getEntityObject( id )
    end
    return mw.wikibase.getEntityObject()
end

function getEntityIdFromValue( value )
    local prefix = ''
    if value['entity-type'] == 'item' then
        prefix = 'Q'
    elseif value['entity-type'] == 'property' then
        prefix = 'P'
    else
        return formatError( 'unknown-entity-type' )
    end
    return prefix .. value['numeric-id']
end
 
function formatError( key )
    return '<span class="error">' .. i18n.errors[key] .. '</span>'
end

function formatStatements( options )
    if not options.property then
        return formatError( 'property-param-not-provided' )
    end

    --Get entity
    local entity = getEntityFromId( options.entityId )
    if not entity then
        return -- formatError( 'entity-not-found' )
    end

    if (entity.claims == nil) or (not entity.claims[string.upper(options.property)]) then
        return '' --TODO error?
    end

    --Format statement and concat them cleanly
    local formattedStatements = {}
    for i, statement in pairs( entity.claims[string.upper(options.property)] ) do
        table.insert( formattedStatements, formatStatement( statement, options ) )
    end
    return mw.text.listToText( formattedStatements, options.separator, options.conjunction )
end

function formatStatement( statement, options )
    if not statement.type or statement.type ~= 'statement' then
        return formatError( 'unknown-claim-type' )
    end

    return formatSnak( statement.mainsnak, options )
    --TODO reference and qualifiers
end

function formatSnak( snak, options )
    if snak.snaktype == 'somevalue' then
        return i18n['somevalue']
    elseif snak.snaktype == 'novalue' then
        return i18n['novalue']
    elseif snak.snaktype == 'value' then
        return formatDatavalue( snak.datavalue, options )
    else
        return formatError( 'unknown-snak-type' )
    end
end

function formatGlobeCoordinate( value, options )
    if options['subvalue'] == 'latitude' then
        return value['latitude']
    elseif options['subvalue'] == 'longitude' then
        return value['longitude']
    else
        local globe = '' -- TODO
    
        local coord = '{{coord|'
        coord = coord .. value['latitude'] .. '|' .. value['longitude']
        coord = coord .. '|globe:' .. globe
        if options['display'] then
            coord = coord .. '|display=' .. options.display
        else
            coord = coord .. '|display=title'
        end
        coord = coord .. '|format=dms'
        coord = coord .. '}}'

        return g_frame:preprocess(coord)
    end
end

function formatDatavalue( datavalue, options )
    --Use the customize handler if provided
    if options['value-module'] or options['value-function'] then
        if not options['value-module'] or not options['value-function'] then
            return formatError( 'unknown-value-module' )
        end
        local formatter = require ('Module:' .. options['value-module'])
        if formatter == nil then
            return formatError( 'value-module-not-found' )
        end
        local fun = formatter[options['value-function']]
        if fun == nil then
            return formatError( 'value-function-not-found' )
        end
        return fun( datavalue.value, options )
    end

    --Default formatters
    if datavalue.type == 'wikibase-entityid' then
        return formatEntityId( getEntityIdFromValue( datavalue.value ), options )
    elseif datavalue.type == 'string' then
        return datavalue.value --TODO ids + media
    elseif datavalue.type == 'globecoordinate' then
        return formatGlobeCoordinate( datavalue.value, options ) 
    else
        return formatError( 'unknown-datavalue-type' )
    end
end

function formatEntityId( entityId, options )
    local label = mw.wikibase.label( entityId )
    local link = mw.wikibase.sitelink( entityId )
    if link then
        if label then
            return '[[' .. link .. '|' .. label .. ']]'
        else
            return '[[' .. link .. ']]'
        end
    else
        return label --TODO what if no links and label + fallback language?
    end
end

local p = {}

function p.formatStatements( frame )
    g_frame = frame
    local args = frame.args

    --If a value if already set, use it
    if args.value and args.value ~= '' then
        return args.value
    end
    return formatStatements( frame.args )
end

return p