אונטערשייד צווישן ווערסיעס פון "יחידה:PropertyLink"

8,771 בייטן אראפגענומען ,  פֿאַר 2 יאָר
אפדעיט
ק (מיון לפי מבחין מפרמטר)
 
(אפדעיט)
 
(8 מיטלסטע ווערסיעס פון 4 באַניצער נישט געוויזן.)
שורה 1: שורה 1:
local FEMALE_FORM_PROPERTY = 'P2521'
local FEMALE_FORM_PROPERTY = 'P2521'
local Date = require('Module:תאריך')
local Date = require('Module:דאטום')
local wikidataModule = require('Module:Wikidata')
local WDS = require('Module:WikidataSelectors')


--[[  
--[[  
שורה 7: שורה 9:
function asOfDateQualifier(claim)
function asOfDateQualifier(claim)
local AS_OF_PROPERTY = 'P585'
local AS_OF_PROPERTY = 'P585'
local wikidataModule = require('Module:Wikidata')
local value
local value
local error
local error
שורה 35: שורה 36:
local langElementId = 'Q9288' -- hebrew
local langElementId = 'Q9288' -- hebrew
local labelFilter = 'P5061[language:'..langCode..'], P5061[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']'
local labelFilter = 'P5061[language:'..langCode..'], P5061[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']'
local WDS = require( 'Module:WikidataSelectors' )
local labelClaims = WDS.filter( {['P5061']=unitSymbol }, labelFilter )
local labelClaims = WDS.filter( {['P5061']=unitSymbol }, labelFilter )
for r, claim in pairs( labelClaims ) do
for r, claim in pairs( labelClaims ) do
if claim.mainsnak and claim.mainsnak.datavalue.type == 'monolingualtext' and claim.mainsnak.datavalue.value.text then
if claim.mainsnak and claim.mainsnak.datavalue.type == 'monolingualtext' and claim.mainsnak.datavalue.value.text then
unit = claim.mainsnak.datavalue.value.text
unit = claim.mainsnak.datavalue.value.text
break;
break
elseif claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.type == 'string' and claim.mainsnak.datavalue.value ~= '' then
elseif claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.type == 'string' and claim.mainsnak.datavalue.value ~= '' then
unit = claim.mainsnak.datavalue.value
unit = claim.mainsnak.datavalue.value
break;
break
end
end
end
end
שורה 55: שורה 55:


function getPropertyQualifier(property, qualifier)
function getPropertyQualifier(property, qualifier)
local wikidataModule = require('Module:Wikidata')
local entity = mw.wikibase.getEntityIdForCurrentPage()
local entity = mw.wikibase.getEntityIdForCurrentPage()
     if not entity then return end --the entity doesnt exist or have no claims
     if not entity then return end --the entity doesnt exist or have no claims
שורה 66: שורה 65:


local function missingLabelCategory(propertyName)
local function missingLabelCategory(propertyName)
return '[[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית: ' .. (mw.wikibase.label( propertyName) or propertyName) .. ']][[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית]]'
return '[[קאַטעגאָריע:ויקינתונים:ערכים_חסרי_תווית_בעברית: ' .. (mw.wikibase.label( propertyName) or propertyName) .. ']][[קאַטעגאָריע:ויקינתונים:ערכים_חסרי_תווית_בעברית]]'
end
end


local function getFemaleLabelForEntityId( entityId )
local function getFemaleLabelForEntityId( entityId )
local WDS = require('Module:WikidataSelectors')
local femaleForm = mw.wikibase.getBestStatements(entityId, FEMALE_FORM_PROPERTY)
local femaleForm = mw.wikibase.getBestStatements(entityId, FEMALE_FORM_PROPERTY)
שורה 97: שורה 95:
@param {string} entityId - id of entity to link to (e.g Q42)
@param {string} entityId - id of entity to link to (e.g Q42)
@param {string} genderAwareEntity - entity from which to fetch gender for gender form
@param {string} genderAwareEntity - entity from which to fetch gender for gender form
@param {bool} noLinktoWikidata - if true, returns without the link to Wikidata
@returns {string, bool} formattedValue, missingTranslation - the formatted value along with indicator of missing translation
@returns {string, bool} formattedValue, missingTranslation - the formatted value along with indicator of missing translation
]]
]]
function formatEntity(entityId, genderAwareEntity)
function formatEntity(entityId, genderAwareEntity, noLinktoWikidata)
local linkTarget = mw.wikibase.sitelink( entityId )
local linkTarget = mw.wikibase.sitelink( entityId )
     local localLabel, langLabel, missingFemaleForm
     local localLabel, langLabel, missingFemaleForm
שורה 152: שורה 151:
     formattedValue = mw.ustring.format('<span lang="en" dir="ltr">%s</span>', localLabel)
     formattedValue = mw.ustring.format('<span lang="en" dir="ltr">%s</span>', localLabel)
     else
     else
formattedValue = mw.ustring.format( "[[:d:%s|%s]]", entityId, entityId )
    if noLinktoWikidata then
    formattedValue = 'בפסקה זו רשומה אחת נוספת שטרם תורגמה'
else
formattedValue = mw.ustring.format( "[[:d:%s|%s]]", entityId, entityId )
end
end
end
     end
     end
שורה 158: שורה 161:
end
end


function formatOptionalQualifiers(property, qualifiers, qualifiersSep)
function formatOptionalQualifiers(property, qualifiers, qualifiersSep, defaultValue, addParenthesis)
if (qualifiers==nil) or (#qualifiers == 0) or (not property.qualifiers) then return '' end
if (qualifiers==nil) or (#qualifiers == 0) or (not property.qualifiers) then return '' end
qualifiersSep = qualifiersSep or ', '
qualifiersSep = qualifiersSep or ', '
שורה 164: שורה 167:
local formmatedQualifiers = {}
local formmatedQualifiers = {}
local warnings = ''
local warnings = ''
local defaultIsOn = true
for _, optionalQualifier in pairs( qualifiers ) do
for _, optionalQualifier in pairs( qualifiers ) do
-- handling case of "first or default" qualifier (e.g.: for 'P1/P2' take P1 if exists, otherwise - P2)
-- handling case of "first or default" qualifier (e.g.: for 'P1/P2' take P1 if exists, otherwise - P2)
local was_found = false
for selectableQualifier in string.gmatch(optionalQualifier, '[^/]+') do
for selectableQualifier in string.gmatch(optionalQualifier, '[^/]+') do
if selectableQualifier and property.qualifiers[selectableQualifier] then
if selectableQualifier and property.qualifiers[selectableQualifier] then
שורה 179: שורה 185:
local formattedValue = '<span title="'.. mw.wikibase.label(selectableQualifier)..'" class="propertylink-wikidata-qualifier">'..mw.wikibase.formatValues(property.qualifiers[selectableQualifier]) ..'</span>'
local formattedValue = '<span title="'.. mw.wikibase.label(selectableQualifier)..'" class="propertylink-wikidata-qualifier">'..mw.wikibase.formatValues(property.qualifiers[selectableQualifier]) ..'</span>'
table.insert(formmatedQualifiers, formattedValue)
table.insert(formmatedQualifiers, formattedValue)
was_found = true
defaultIsOn = false
break -- found first available value
break -- found first available value
end
end
elseif string.sub(selectableQualifier, 1, 1) ~= 'P' then
elseif string.sub(selectableQualifier, 1, 1) ~= 'P' then
table.insert(formmatedQualifiers, selectableQualifier)
table.insert(formmatedQualifiers, selectableQualifier)
was_found = true
defaultIsOn = false
break -- found first available value
break -- found first available value
end
end
end
if not was_found then
table.insert(formmatedQualifiers, defaultValue)
end
end
local res = ""
if not defaultIsOn then
res = table.concat( formmatedQualifiers, qualifiersSep)
if #formmatedQualifiers > 0 and addParenthesis then
res = mw.ustring.format('<span style="font-size:0.9em"> (%s)</span>', res)
end
end
end
end
local res =  table.concat( formmatedQualifiers, qualifiersSep)
if #formmatedQualifiers > 0 then
res = mw.ustring.format('<span style="font-size:0.9em;"> (%s)</span>', res)
end
return res .. warnings
return res .. warnings
end
end
שורה 216: שורה 232:
function getProperty( propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware )
function getProperty( propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware )
if propertyName==nil or #propertyName==0 then return end -- no property specified
if propertyName==nil or #propertyName==0 then return end -- no property specified
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
entityId = entityId
if entityId == nil then return end -- entity doesnt exist
if entityId == nil then return end -- entity doesnt exist
options = {
options = {
שורה 233: שורה 249:


function property( frame )
function property( frame )
    if frame.args['entity']==nil and frame.args['title'] and #frame.args['title']>0  then
    return ''
        frame.args['entity'] = mw.wikibase.getEntityIdForTitle( frame.args['title'] )
        if frame.args['entity']==nil then return end
    end
    return getProperty(string.upper(frame.args[1]), (frame.args[2] and string.len(frame.args[2])>0) or false, true, frame.args['entity'], frame.args['sep'], frame.args['q'])
end
end


שורה 280: שורה 292:
function getPropertyByOptions( propertyName, entityId, options )
function getPropertyByOptions( propertyName, entityId, options )
-- verify entity exists
-- verify entity exists
if entityId == nil then entityId = mw.wikibase.getEntityIdForCurrentPage() end
if entityId==nil then return end
if entityId==nil then return end
שורה 294: שורה 305:
options['source'] = options['source'] or false
options['source'] = options['source'] or false
options['filter'] = options['filter'] or nil
options['filter'] = options['filter'] or nil
options['sort'] = options['sort'] or 'P1545'
options['sort'] = options['sort'] or { 'P1545' }
options['default-value'] = options['default-value'] or nil


    local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName)
    return --no such property for this item
    if (not propertyVals) or (#propertyVals==0) then return end --no such property for this item
    local resTable = {}
    local missingTranslation = 0
    local hasFallbackTransation = false
 
    local sortByQualifier = function(t1, t2)
    if t1 and t2 then
    local q1 = t1.qualifiers
    local q2 = t2.qualifiers
    local c1 = nil
    local c2 = nil
    if q1 and q2 then
    if q1[options['sort']] and q1[options['sort']][1] and q1[options['sort']][1].datavalue and q1[options['sort']][1].datavalue.value then
    if q1[options['sort']][1].datavalue.type == 'string' then
    c1 = q1[options['sort']][1].datavalue.value
    elseif q1[options['sort']][1].datavalue.type == 'quantity' then
    c1 = q1[options['sort']][1].datavalue.value.amount
    elseif q1[options['sort']][1].datavalue.type == 'time' then
    c1 = q1[options['sort']][1].datavalue.value.time
    end
    end
    if q2[options['sort']] and q2[options['sort']][1] and q2[options['sort']][1].datavalue and q2[options['sort']][1].datavalue.value then
    if q2[options['sort']][1].datavalue.type == 'string' then
    c2 = q2[options['sort']][1].datavalue.value
    elseif q2[options['sort']][1].datavalue.type == 'quantity' then
    c2 = q2[options['sort']][1].datavalue.value.amount
    elseif q2[options['sort']][1].datavalue.type == 'time' then
    c2 = q2[options['sort']][1].datavalue.value.time
    end
    end
    if c1 and c2 then
    return c1<c2
    elseif c1 then
    return true
    elseif c2 then
    return false
    end
    elseif q1 then
return true
    elseif q2 then
return false
end
else
if t1 then
return true
end
if t2 then
return false
end
    end
return false
    end
    if options['sort'] then
    table.sort(propertyVals, sortByQualifier)
    end
 
if options['filter'] then
propertyVals = options['filter'](propertyVals)
end
 
    for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    if not propValue then
    if options['allowNA'] and (property.mainsnak and property.mainsnak.snaktype)=='somevalue' then
    return 'לא ידוע'
    else
    --property doesnt exist
    return
end
    end
   
local isImage = (property.mainsnak.datatype == 'commonsMedia')
    if propValue['type'] == 'wikibase-entityid' then
    local formattedValue, valueMissingTranslation, fallbackLang = formatEntity( propValue.value['id'], options['entity-gender-aware'] and entityId)
        if not valueMissingTranslation or fallbackLang then
        hasFallbackTransation = hasFallbackTransation or fallbackLang
        if formattedValue then
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        end
        if options['source'] and property.references then
    formattedValue  = formattedValue.. refStatement(property)
    end
        table.insert(resTable, formattedValue)
        else
        missingTranslation = missingTranslation + 1
        end
    elseif propValue['type'] == 'string' then
    if isImage then
    table.insert(resTable, mw.ustring.format( '[[File:%s|%s]]', propValue.value, options['img-width'] ))
    else
    local formattedValue = propValue.value
        if formattedValue then
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        end
        table.insert(resTable, formattedValue)
    end
    elseif propValue['type'] == 'monolingualtext' then
    -- for monolingualtext print the language as title
    local formattedValue = mw.ustring.format('<span lang="%s" title="%s">%s</span>', propValue.value.language,
        mw.language.fetchLanguageName( propValue.value.language , 'he'), propValue.value.text)
    table.insert(resTable, formattedValue)
    elseif propValue['type'] == 'quantity' then
    local formattedValue = formatQuantity(property)
    if options['source'] and property.references then
    formattedValue  = formattedValue.. refStatement(property)
    end
    if formattedValue then
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        end
    table.insert(resTable, formattedValue)
    elseif propValue['type'] == 'time' then
    local timeValue = Date.newFromWikidataValue( property.mainsnak.datavalue.value ):toHebrewString()
    local timeWarning = property['qualifiers'] and property['qualifiers']['P1480'] and property['qualifiers']['P1480'][1]
    and property['qualifiers']['P1480'][1].datavalue  and property['qualifiers']['P1480'][1].datavalue.value
    if timeWarning then
    timeWarning = timeWarning and timeWarning['id']
    if timeWarning == 'Q5727902' then
    timeValue = timeValue .. '[[Circa|?]]'
    else
    local circu = mw.wikibase.getLabelByLang( timeWarning, 'he' )
    if circu then
    timeValue = timeValue .. ' ' .. circu
    end
    end
    end
    --local timeValue = mw.wikibase.renderSnak( property.mainsnak )
    timeValue = mw.ustring.gsub(timeValue, '^(%d+ %a+) (%d+)$', '[[%1]] [[%2]]')
    table.insert(resTable, timeValue)
    elseif propValue['type'] == 'globecoordinate' then
    local frame = mw.getCurrentFrame()
    local formattedValue
    local globe = propValue.value.globe
    if globe == 'http://www.wikidata.org/entity/Q2' then globe = nil
    else
    local globeMapping = require('Module:Wikidata/Globes')
    if globeMapping[globe] then
    globe = 'globe:' .. globeMapping[globe]
    else
    globe = nil
    end
end
    if globe then
    local northSouth = (propValue.value.latitude>=0 and 'N') or 'S'
    local eastWest = (propValue.value.longitude>=0) and 'E' or  'W'
    formattedValue = frame:expandTemplate{ title = 'Coord', args = { math.abs(propValue.value.latitude), northSouth, math.abs(propValue.value.longitude), eastWest, globe, display = options['coord-display'] or 'inline' } }
    else
    formattedValue = frame:expandTemplate{ title = 'Coord', args = { propValue.value.latitude, propValue.value.longitude, display = options['coord-display'] or 'inline' } }
    end
    table.insert(resTable, formattedValue)
    else
    table.insert(resTable, mw.wikibase.formatValue( property.mainsnak ))
    end
    if not options['allowMulti'] then
    break
    end
end
if missingTranslation > 0 and #resTable> 0 then
if missingTranslation == 1 then
    table.insert(resTable, 'בפסקה זו רשומה אחת נוספת שטרם תורגמה')
else
    table.insert(resTable, 'בפסקה זו '..missingTranslation..' רשומות נוספות שטרם תורגמו')
end
end
-- bidi isolation - properly show mix or RTL and LTR statements
if #resTable>1 then
local isolateValues = {}
local needIsolation = false
for k,v in pairs(resTable) do
needIsolation = needIsolation or string.find( v, '[a-zA-Z]')
table.insert(isolateValues, mw.ustring.format('<span style="unicode-bidi:isolate">%s</span>', v))
end
if needIsolation then resTable = isolateValues end
end
local result = ''
-- special case * - listify
if options['seperator'] == '*' and #resTable>1 then
result = '*' .. table.concat( resTable, '\n*' )
else
result = table.concat( resTable, options['seperator'] )
end
if hasFallbackTransation or (missingTranslation > 0 ) then
result = result .. missingLabelCategory( propertyName )
end
return result
end
end


function getLabel( propertyName, entityId )
function getLabel( propertyName, entityId )
     local entity = entityId or mw.wikibase.getEntityIdForCurrentPage()
     local entity = entityId
     if not entity then return end--the entity doesnt exist or have no claims
     if not entity then return end--the entity doesnt exist or have no claims
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
שורה 509: שורה 335:


function getItem( propertyName, entityId )
function getItem( propertyName, entityId )
     local entity = entityId or mw.wikibase.getEntityIdForCurrentPage()
     local entity = entityId
     if not entity then return end--the entity doesnt exist or have no claims
     if not entity then return end--the entity doesnt exist or have no claims
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
שורה 527: שורה 353:


function getImageLink( propName, width, align, description, border, entityId)
function getImageLink( propName, width, align, description, border, entityId)
if not entityId then entityId = mw.wikibase.getEntityIdForCurrentPage() end -- entityId wasn't provided explicitly
    return --the entity doesnt exist or have no claims
    if not entityId then return end --the entity doesnt exist or have no claims
    local property =  mw.wikibase.getBestStatements(entityId, propName or 'P18')
    if property and property[1] then
    if property[1].mainsnak and property[1].mainsnak.snaktype=='novalue' then
    return '[[d:'..mw.wikibase.getEntityIdForCurrentPage()..'#'..(propName or "P18")..'|' ..'לא ידוע]]'
    end
        local width = width or "220"
        local extraParameters = width..'px'
        if align then extraParameters = extraParameters .. '|' .. align end
        if description then extraParameters = extraParameters .. '|' .. description end
        if border and (#border > 0) then extraParameters =extraParameters..'|' ..'border' end
        return mw.ustring.format( '[[File:%s|%s]]', property[1].mainsnak.datavalue.value, extraParameters )
    end
end
end