יחידה:PropertyLink: הבדלים בין גרסאות בדף

מאין תקציר עריכה
מ 8 גרסאות של הדף wikipedia:he:יחידה:PropertyLink יובאו
 
(50 גרסאות ביניים של 9 משתמשים אינן מוצגות)
שורה 20: שורה 20:
local propValue = property.mainsnak and property.mainsnak.datavalue
local propValue = property.mainsnak and property.mainsnak.datavalue
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
local langCode = lang:getCode()
local asOfDate = asOfDateQualifier(property)
local asOfDate = asOfDateQualifier(property)
local localAmount = lang:formatNum( tonumber(propValue.value.amount) )
local localAmount = lang:formatNum( tonumber(propValue.value.amount) )
local unit = ''
local unit = ''
if propValue.value.unit and string.match( propValue.value.unit, 'http://www.wikidata.org/entity/' ) then
if propValue.value.unit and string.match( propValue.value.unit, 'http://www.wikidata.org/entity/' ) then
local unitEntityId = string.gsub( propValue.value.unit, 'http://www.wikidata.org/entity/', '' );
local unitEntityId = string.gsub( propValue.value.unit, 'http://www.wikidata.org/entity/', '' )
if unitEntityId and #unitEntityId>0 then
if unitEntityId and #unitEntityId>0 then
-- name from label
-- name from label
unit =  mw.wikibase.label( unitEntityId );
unit =  mw.wikibase.label( unitEntityId ) or ''
local unitSymbol = mw.wikibase.getBestStatements(unitEntityId, 'P558')
local unitSymbol = mw.wikibase.getBestStatements(unitEntityId, 'P5061')
--  name from properties
--  name from properties
if unitSymbol then
if unitSymbol then
local writingSystemElementId = 'Q33513'; -- hebrew writing system
local writingSystemElementId = 'Q33513' -- hebrew writing system
local langElementId = 'Q9288'; -- hebrew
local langElementId = 'Q9288' -- hebrew
local labelFilter = 'P558[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']';
local labelFilter = 'P5061[language:'..langCode..'], P5061[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']'
local WDS = require( 'Module:WikidataSelectors' );
local WDS = require( 'Module:WikidataSelectors' )
local labelClaims = WDS.filter( {['P558']=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
if claim.mainsnak and claim.mainsnak.datavalue.type == 'monolingualtext' and claim.mainsnak.datavalue.value.text then
and claim.mainsnak.datavalue
unit = claim.mainsnak.datavalue.value.text
and claim.mainsnak.datavalue.type == 'string'
break;
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
שורה 48: שורה 48:
end
end
unit = ' ' .. unit;
unit = ' ' .. unit
end
end
     end
     end
שורה 75: שורה 75:
if not femaleForm then return nil, false end
if not femaleForm then return nil, false end
local femLabels = WDS.filterByLanguage( femaleForm, 'he' );
local femLabels = WDS.filterByLanguage( femaleForm, 'he' )
if femLabels ~= nil and
if femLabels ~= nil and
  femLabels[1] and
  femLabels[1] and
שורה 82: שורה 82:
  femLabels[1].mainsnak.datavalue.value and
  femLabels[1].mainsnak.datavalue.value and
  femLabels[1].mainsnak.datavalue.value.text then
  femLabels[1].mainsnak.datavalue.value.text then
return femLabels[1].mainsnak.datavalue.value.text;
return femLabels[1].mainsnak.datavalue.value.text
end
end


return nil, (#femaleForm)>0;
return nil, #femaleForm > 0
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
שורה 111: שורה 112:
                     gender[1].mainsnak.datavalue and
                     gender[1].mainsnak.datavalue and
                     gender[1].mainsnak.datavalue.value and
                     gender[1].mainsnak.datavalue.value and
                     gender[1].mainsnak.datavalue.value["numeric-id"] == 6581072
                     (gender[1].mainsnak.datavalue.value["numeric-id"] == 6581072
                  or gender[1].mainsnak.datavalue.value["numeric-id"] == 1052281
                  or gender[1].mainsnak.datavalue.value["numeric-id"] == 15145779)


     if isFemale then
     if isFemale then
שורה 132: שורה 135:
     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: שורה 148:
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: שורה 165:
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=='he')
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)..'">'..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
שורה 205: שורה 215:
]]
]]
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
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
if entityId == nil then return end
if entityId == nil then return end -- entity doesnt exist
options = {
options = {
['allowMulti'] = allowMulti,
['allowMulti'] = allowMulti,
שורה 222: שורה 233:


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
 
function propertyWithGender(frame)
return getProperty(string.upper(frame.args[1]), (frame.args[2] and string.len(frame.args[2])>0) or false, true, frame.args['entity'], ', ', '', true)
end
 
-- formatted reference for statement. Only for non imported statements
function refStatement(statement)
if not statement.references or #statement.references == 0 then return '' end -- no reference
local formattedReferences = {}
local frame = mw.getCurrentFrame()
for j, curRef in ipairs(statement.references) do
local isImportedRef = curRef.snaks and (curRef.snaks['P143'] or curRef.snaks['P4656'])
if not isImportedRef then
if curRef.snaks['P854'] then
table.insert(formattedReferences, frame:extensionTag{  name = 'ref', content = mw.wikibase.renderSnak(curRef.snaks['P854'][1])})
elseif curRef.snaks['P2699'] then
table.insert(formattedReferences, frame:extensionTag{  name = 'ref', content = mw.wikibase.renderSnak(curRef.snaks['P2699'][1])})
else
table.insert(formattedReferences, frame:extensionTag{  name = 'ref', content = mw.wikibase.formatValues(curRef.snaks)})
end
end
end
return table.concat(formattedReferences, '')
end
end


שורה 253: שורה 292:
options['qualifiers-sep'] = options['qualifiers-sep'] or ', '
options['qualifiers-sep'] = options['qualifiers-sep'] or ', '
options['img-width'] = options['img-width'] or '250px'
options['img-width'] = options['img-width'] or '250px'
options['source'] = options['source'] or false
options['filter'] = options['filter'] or nil
options['sort'] = options['sort'] or 'P1545'
 
     local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName)
     local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName)
     if (not propertyVals) or (#propertyVals==0) then return end --no such property for this item
     if (not propertyVals) or (#propertyVals==0) then return end --no such property for this item
     local resTable = {}
     local resTable = {}
     local missingTranslation = false
     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
     for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    local propValue = property.mainsnak and property.mainsnak.datavalue
שורה 271: שורה 370:
local isImage = (property.mainsnak.datatype == 'commonsMedia')
local isImage = (property.mainsnak.datatype == 'commonsMedia')
    if propValue['type'] == 'wikibase-entityid' then
    if propValue['type'] == 'wikibase-entityid' then
    local formattedValue, valueMissingTranslation = formatEntity("Q" .. propValue.value['numeric-id'], options['entity-gender-aware'] and entityId)
    local formattedValue, valueMissingTranslation, fallbackLang = formatEntity( propValue.value['id'], options['entity-gender-aware'] and entityId)
        if not valueMissingTranslation then
        if not valueMissingTranslation or fallbackLang then
        hasFallbackTransation = hasFallbackTransation or fallbackLang
        if formattedValue then
        if formattedValue then
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
        end
        end
        if options['source'] and property.references then
    formattedValue  = formattedValue.. refStatement(property)
    end
         table.insert(resTable, formattedValue)
         table.insert(resTable, formattedValue)
        else
        else
        missingTranslation = true
        missingTranslation = missingTranslation + 1
        end
        end
    elseif propValue['type'] == 'string' then
    elseif propValue['type'] == 'string' then
שורה 297: שורה 400:
    elseif propValue['type'] == 'quantity' then
    elseif propValue['type'] == 'quantity' then
    local formattedValue = formatQuantity(property)
    local formattedValue = formatQuantity(property)
    if options['source'] and property.references then
    formattedValue  = formattedValue.. refStatement(property)
    end
    if formattedValue then
    if formattedValue then
         formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
         formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep'])
שורה 303: שורה 409:
    elseif propValue['type'] == 'time' then
    elseif propValue['type'] == 'time' then
    local timeValue = Date.newFromWikidataValue( property.mainsnak.datavalue.value ):toHebrewString()
    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 )
    --local timeValue = mw.wikibase.renderSnak( property.mainsnak )
    timeValue = mw.ustring.gsub(timeValue, '^(%d+ %a+) (%d+)$', '[[%1]] [[%2]]')  
    timeValue = mw.ustring.gsub(timeValue, '^(%d+ %a+) (%d+)$', '[[%1]] [[%2]]')  
    table.insert(resTable, timeValue)
    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
    end
    if not options['allowMulti'] then
    if not options['allowMulti'] then
שורה 312: שורה 454:
end
end
if missingTranslation then return missingLabelCategory( propertyName ) 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  
-- special case * - listify  
if options['seperator'] == '*' and #resTable>1 then
if options['seperator'] == '*' and #resTable>1 then
return '*' .. table.concat( resTable, '\n*' )
result = '*' .. table.concat( resTable, '\n*' )
else
else
return table.concat( resTable, options['seperator'] )
result = table.concat( resTable, options['seperator'] )
end
end
if hasFallbackTransation or (missingTranslation > 0 ) then
result = result .. missingLabelCategory( propertyName )
end
return result
end
end


function getLabel( propertyName )
function getLabel( propertyName, entityId )
     local entity = mw.wikibase.getEntityIdForCurrentPage()
     local entity = entityId or 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
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
     local property =  mw.wikibase.getBestStatements(entity, propertyName)
שורה 333: שורה 496:


     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
שורה 345: שורה 508:
end
end


function getImageLink( propName, width, align, description, border)
function getItem( propertyName, entityId )
    local entityId = mw.wikibase.getEntityIdForCurrentPage()
    local entity = entityId or mw.wikibase.getEntityIdForCurrentPage()
    if not entity then return end--the entity doesnt exist or have no claims
    local property =  mw.wikibase.getBestStatements(entity, propertyName)
    if not property or not property[1] then return end --no such property for this item
   
    property = property[1]
    local propValue = property.mainsnak.datavalue
    if not propValue then return '' end --property doesnt exist
 
    return propValue.value['id']
end
 
-- Return the Item for property, or the item of the linked entiy of that property
function item( frame )
    return getItem( string.upper(frame.args[1] ))
end
 
function getImageLink( propName, width, align, description, border, entityId)
if not entityId then entityId = mw.wikibase.getEntityIdForCurrentPage() end -- entityId wasn't provided explicitly
     if not entityId then return end --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')
     local property =  mw.wikibase.getBestStatements(entityId, propName or 'P18')
שורה 374: שורה 555:
     return 1
     return 1
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
local function createInterwikiForQid(frame)
local raw = mw.wikibase.getEntity( string.upper( frame.args[1] ) )["sitelinks"]
local interwikis = ''
for site, val in pairs(raw) do
truncated, found = string.gsub(site, 'wiki$', '')
truncated = string.gsub(truncated, '_', '-')
if found == 1 and truncated ~= 'he' and truncated ~= 'commons' then interwikis = interwikis .. '[[' .. truncated .. ':' .. val.title .. ']]' end
end
return interwikis
end


return {
return {
שורה 380: שורה 590:
     label = label,
     label = label,
     ['תווית'] = label,
     ['תווית'] = label,
    item = item,
    ['פריט'] = item,
     formatEntity = formatEntity,
     formatEntity = formatEntity,
     property = property,
     property = property,
    propertyWithGender = propertyWithGender,
     ['מאפיין'] = property,
     ['מאפיין'] = property,
     getProperty = getProperty,
     getProperty = getProperty,
     getPropertyByOptions = getPropertyByOptions,
     getPropertyByOptions = getPropertyByOptions,
     getPropertyQualifier = getPropertyQualifier,
     getPropertyQualifier = getPropertyQualifier,
    getItem = getItem,
     getImageLink = getImageLink,
     getImageLink = getImageLink,
     getLabel = getLabel,
     getLabel = getLabel,
     hasEntry = hasEntry,
     hasEntry = hasEntry,
    getPageEntry = getPageEntry,
    getSitelinksFromQid = getSitelinksFromQid,
    createInterwikiForQid = createInterwikiForQid,
     ['יש פריט'] = hasEntry
     ['יש פריט'] = hasEntry
}
}