|
|
| שורה 216: |
שורה 216: |
| 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: |
שורה 233: |
|
| |
|
| 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: |
שורה 276: |
| 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 |
| | | |
| שורה 296: |
שורה 291: |
| options['sort'] = options['sort'] or 'P1545' | | options['sort'] = options['sort'] or 'P1545' |
|
| |
|
| 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: |
שורה 318: |
|
| |
|
| 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: |
שורה 336: |
|
| |
|
| 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 |
| | | |