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

קפיצה לניווט קפיצה לחיפוש
3,487 בייטן אראפגענומען ,  פֿאַר 3 יאָר
ייבוא מוויקיפדיה העברית, ראה רשימת התורמים
ק (rv)
צייכן: צוריקגעשטעלט
(ייבוא מוויקיפדיה העברית, ראה רשימת התורמים)
צייכן: צוריקגעשטעלט
שורה 12: שורה 12:
value, error = wikidataModule.getValueOfClaim(claim, AS_OF_PROPERTY, nil)
value, error = wikidataModule.getValueOfClaim(claim, AS_OF_PROPERTY, nil)
if value then
if value then
return ' (אין '..value ..')'
return ' (נכון ל־'..value ..')'
end
end
return ''
return ''
שורה 33: שורה 33:
if unitSymbol then
if unitSymbol then
local writingSystemElementId = 'Q33513' -- hebrew writing system
local writingSystemElementId = 'Q33513' -- hebrew writing system
local langElementId = 'Q8641' -- yiddish
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 WDS = require( 'Module:WikidataSelectors' )
שורה 66: שורה 66:


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


שורה 104: שורה 104:
     local formattedValue
     local formattedValue
     local missingTranslation = false
     local missingTranslation = false
    local fallbackLanguage = false
     if genderAwareEntity then
     if genderAwareEntity then
     local gender = mw.wikibase.getBestStatements(genderAwareEntity, 'P21') -- P21 - gender
     local gender = mw.wikibase.getBestStatements(genderAwareEntity, 'P21') -- P21 - gender
שורה 126: שורה 127:
     end
     end
      
      
     local isLocalLabel = langLabel=='yi'
     local isLocalLabel = langLabel=='he'
     -- fallback if there is target but no label, use target as label
     -- fallback if there is target but no label, use target as label
     if linkTarget and not isLocalLabel then
     if linkTarget and not isLocalLabel then
שורה 132: שורה 133:
     isLocalLabel = true
     isLocalLabel = true
     end
     end
   
     if localLabel and isLocalLabel then
     if localLabel and isLocalLabel then
if linkTarget and localLabel and linkTarget == localLabel then
if linkTarget and localLabel and linkTarget == localLabel then
שורה 146: שורה 146:
missingTranslation = true
missingTranslation = true
-- in that case we would unfourtanly can show only the entity id which is meaningless for users
-- in that case we would unfourtanly can show only the entity id which is meaningless for users
formattedValue = mw.ustring.format( "[[:d:%s|%s]]", entityId, entityId )
if langLabel=='en' then
fallbackLanguage = true
    formattedValue = mw.ustring.format('<span lang="en" dir="ltr">%s</span>', localLabel)
    else
formattedValue = mw.ustring.format( "[[:d:%s|%s]]", entityId, entityId )
end
     end
     end
     return formattedValue, missingTranslation
     return formattedValue, missingTranslation, fallbackLanguage
end
end


שורה 158: שורה 163:
local warnings = ''
local warnings = ''
for _, optionalQualifier in pairs( qualifiers ) do
for _, optionalQualifier in pairs( qualifiers ) do
if optionalQualifier and property.qualifiers[optionalQualifier] then
-- handling case of "first or default" qualifier (e.g.: for 'P1/P2' take P1 if exists, otherwise - P2)
local optionalQualifierVal = mw.wikibase.formatValues(property.qualifiers[optionalQualifier])
for selectableQualifier in string.gmatch(optionalQualifier, '[^/]+') do
local isQualLocalLabel = true
if selectableQualifier and property.qualifiers[selectableQualifier] then
if optionalQualifierVal and property.qualifiers[optionalQualifier][1] and property.qualifiers[optionalQualifier][1]['datatype']=='wikibase-item' then  
local optionalQualifierVal = mw.wikibase.formatValues(property.qualifiers[selectableQualifier])
for i, optionalQValues in ipairs(property.qualifiers[optionalQualifier]) do
local isQualLocalLabel = true
local qualLabel, qualLang = mw.wikibase.getLabelWithLang( optionalQValues['datavalue']['value']['id'] )
if optionalQualifierVal and property.qualifiers[selectableQualifier][1] and property.qualifiers[selectableQualifier][1]['datatype']=='wikibase-item' then  
isQualLocalLabel = isQualLocalLabel and (qualLang=='yi')
for i, optionalQValues in ipairs(property.qualifiers[selectableQualifier]) do
local qualLabel, qualLang = mw.wikibase.getLabelWithLang( optionalQValues['datavalue']['value']['id'] )
isQualLocalLabel = isQualLocalLabel and (qualLang=='he')
end
end
end
end
if optionalQualifierVal then
if optionalQualifierVal then
local formattedValue = '<span title="'.. mw.wikibase.label(selectableQualifier)..'" class="propertylink-wikidata-qualifier">'..mw.wikibase.formatValues(property.qualifiers[selectableQualifier]) ..'</span>'
if isQualLocalLabel then
local formattedValue = '<span title="'.. mw.wikibase.label(optionalQualifier)..'" class="propertylink-wikidata-qualifier">'..mw.wikibase.formatValues(property.qualifiers[optionalQualifier]) ..'</span>'
table.insert(formmatedQualifiers, formattedValue)
table.insert(formmatedQualifiers, formattedValue)
else
break -- found first available value
warnings = missingLabelCategory(optionalQualifier)
end
end
elseif string.sub(selectableQualifier, 1, 1) ~= 'P' then
table.insert(formmatedQualifiers, selectableQualifier)
break -- found first available value
end
end
end
end
שורה 206: שורה 214:
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 = {
שורה 223: שורה 231:


function property( frame )
function property( frame )
     return getProperty(string.upper(frame.args[1]), (frame.args[2] and string.len(frame.args[2])>0) or false, true, frame.args['entity'])
    if frame.args['entity']==nil and frame.args['title'] and #frame.args['title']>0  then
        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


שורה 266: שורה 278:
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
שורה 279: שורה 290:
options['img-width'] = options['img-width'] or '250px'
options['img-width'] = options['img-width'] or '250px'
options['source'] = options['source'] or false
options['source'] = options['source'] or false
options['filter'] = options['filter'] 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 = false
    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 = formatEntity("Q" .. propValue.value['numeric-id'], options['entity-gender-aware'] and entityId)
        if not valueMissingTranslation then
        if formattedValue then
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        end
        table.insert(resTable, formattedValue)
        else
        missingTranslation = true
        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 , 'yi'), 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 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
    formattedValue = frame:expandTemplate{ title = 'Coord', args = { propValue.value.latitude, propValue.value.longitude, 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 then return missingLabelCategory( propertyName ) 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
-- special case * - listify
if options['seperator'] == '*' and #resTable>1 then
return '*' .. table.concat( resTable, '\n*' )
else
return table.concat( resTable, options['seperator'] )
end
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)
שורה 394: שורה 306:


     if propValue['type'] == 'wikibase-entityid' then
     if propValue['type'] == 'wikibase-entityid' then
         local label, lang = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
         local label, lang = mw.wikibase.label( propValue.value['id'] )
         return label
         return label
     elseif propValue['type'] == 'string' then
     elseif propValue['type'] == 'string' then
שורה 406: שורה 318:
end
end


function getImageLink( propName, width, align, description, border)
function getItem( propertyName, entityId )
     local entityId = mw.wikibase.getEntityIdForCurrentPage()
     local entity = entityId
     if not entityId 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(entityId, propName or 'P18')
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
     if property and property[1] then
     if not property or not property[1] then return end --no such property for this item
    if property[1].mainsnak and property[1].mainsnak.snaktype=='novalue' then
   
    return '[[d:'..mw.wikibase.getEntityIdForCurrentPage()..'#'..(propName or "P18")..'|' ..'לא ידוע]]'
    property = property[1]
    end
    local propValue = property.mainsnak.datavalue
        local width = width or "220"
    if not propValue then return '' end --property doesnt exist
        local extraParameters = width..'px'
 
        if align then extraParameters = extraParameters .. '|' .. align end
    return propValue.value['id']
        if description then extraParameters = extraParameters .. '|' .. description end
end
        if border and (#border > 0) then extraParameters =extraParameters..'|' ..'border' end
 
        return mw.ustring.format( '[[File:%s|%s]]', property[1].mainsnak.datavalue.value, extraParameters )
-- Return the Item for property, or the item of the linked entiy of that property
     end
function item( frame )
    return getItem( string.upper(frame.args[1] ))
end
 
function getImageLink( propName, width, align, description, border, entityId)
     return --the entity doesnt exist or have no claims
end
end
      
      
שורה 436: שורה 353:
end
end


-- returns the wikidata Qid, if exists, "" otherwise
function getPageEntry(frame)
return mw.wikibase.getEntityIdForTitle(string.upper(frame.args[1] ))
end
function getSitelinksFromQid(frame)
resTable =mw.wikibase.getEntity(string.upper(frame.args[1] ))
resTable = resTable["sitelinks"]
s= "<table>\n"
for k,v in pairs(resTable) do
if  v.title then
s=s.."<tr>".. "<td>" .. k.."</td>".. "<td>" .. v.title.."</td>".."</tr>" .. "\n"
end
end
return s .. "</table>"
end
return {
return {
     imageLink = imageLink,
     imageLink = imageLink,
שורה 441: שורה 376:
     label = label,
     label = label,
     ['תווית'] = label,
     ['תווית'] = label,
    item = item,
    ['פריט'] = item,
     formatEntity = formatEntity,
     formatEntity = formatEntity,
     property = property,
     property = property,
     propertyWithGender = propertyWithGender,
     propertyWithGender = propertyWithGender,
     ['מאפיין'] = property,
     ['מאפיין'] = property,
    ['אייגנשאפט'] = property,
     getProperty = getProperty,
     getProperty = getProperty,
     getPropertyByOptions = getPropertyByOptions,
     getPropertyByOptions = getPropertyByOptions,
שורה 452: שורה 388:
     getLabel = getLabel,
     getLabel = getLabel,
     hasEntry = hasEntry,
     hasEntry = hasEntry,
    getPageEntry = getPageEntry,
    getSitelinksFromQid=getSitelinksFromQid,
     ['יש פריט'] = hasEntry
     ['יש פריט'] = hasEntry
}
}

נאוויגאציע מעניו