יחידה:PropertyLink: הבדלים בין גרסאות בדף
מ מיותר, אם אין תרגום בכל השורות, resTable ריקה ויוחזר משתנה ריק |
מ 8 גרסאות של הדף wikipedia:he:יחידה:PropertyLink יובאו |
||
| (29 גרסאות ביניים של 7 משתמשים אינן מוצגות) | |||
| שורה 112: | שורה 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 or gender[1].mainsnak.datavalue.value["numeric-id"] == 1052281) | (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 | ||
| שורה 163: | שורה 165: | ||
local warnings = '' | local warnings = '' | ||
for _, optionalQualifier in pairs( qualifiers ) do | for _, optionalQualifier in pairs( qualifiers ) do | ||
if optionalQualifier and property.qualifiers[ | -- handling case of "first or default" qualifier (e.g.: for 'P1/P2' take P1 if exists, otherwise - P2) | ||
for selectableQualifier in string.gmatch(optionalQualifier, '[^/]+') do | |||
if selectableQualifier and property.qualifiers[selectableQualifier] then | |||
local optionalQualifierVal = mw.wikibase.formatValues(property.qualifiers[selectableQualifier]) | |||
local isQualLocalLabel = true | |||
if optionalQualifierVal and property.qualifiers[selectableQualifier][1] and property.qualifiers[selectableQualifier][1]['datatype']=='wikibase-item' then | |||
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 | ||
if optionalQualifierVal then | |||
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( | |||
table.insert(formmatedQualifiers, formattedValue) | table.insert(formmatedQualifiers, formattedValue) | ||
break -- found first available value | |||
end | end | ||
elseif string.sub(selectableQualifier, 1, 1) ~= 'P' then | |||
table.insert(formmatedQualifiers, selectableQualifier) | |||
break -- found first available value | |||
end | end | ||
end | end | ||
| שורה 232: | שורה 237: | ||
if frame.args['entity']==nil then return end | if frame.args['entity']==nil then return end | ||
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']) | 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 | ||
| שורה 288: | שורה 293: | ||
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 | |||
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 = | local missingTranslation = 0 | ||
local hasFallbackTransation = false | 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 | ||
| שורה 307: | שורה 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, fallbackLang = formatEntity( | local formattedValue, valueMissingTranslation, fallbackLang = formatEntity( propValue.value['id'], options['entity-gender-aware'] and entityId) | ||
if not valueMissingTranslation or fallbackLang then | if not valueMissingTranslation or fallbackLang then | ||
hasFallbackTransation = hasFallbackTransation or fallbackLang | hasFallbackTransation = hasFallbackTransation or fallbackLang | ||
| שורה 318: | שורה 381: | ||
table.insert(resTable, formattedValue) | table.insert(resTable, formattedValue) | ||
else | else | ||
missingTranslation = | missingTranslation = missingTranslation + 1 | ||
end | end | ||
elseif propValue['type'] == 'string' then | elseif propValue['type'] == 'string' then | ||
| שורה 391: | שורה 454: | ||
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 | -- bidi isolation - properly show mix or RTL and LTR statements | ||
| שורה 410: | שורה 479: | ||
result = table.concat( resTable, options['seperator'] ) | result = table.concat( resTable, options['seperator'] ) | ||
end | end | ||
if hasFallbackTransation then | if hasFallbackTransation or (missingTranslation > 0 ) then | ||
result = result .. missingLabelCategory( propertyName ) | result = result .. missingLabelCategory( propertyName ) | ||
end | end | ||
| שורה 427: | שורה 496: | ||
if propValue['type'] == 'wikibase-entityid' then | if propValue['type'] == 'wikibase-entityid' then | ||
local label, lang = mw.wikibase.label( | local label, lang = mw.wikibase.label( propValue.value['id'] ) | ||
return label | return label | ||
elseif propValue['type'] == 'string' then | elseif propValue['type'] == 'string' then | ||
| שורה 437: | שורה 506: | ||
function label( frame ) | function label( frame ) | ||
return getLabel( string.upper(frame.args[1] )) | return getLabel( string.upper(frame.args[1] )) | ||
end | |||
function getItem( propertyName, entityId ) | |||
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 | end | ||
| שורה 468: | שורה 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 { | ||
| שורה 474: | שורה 590: | ||
label = label, | label = label, | ||
['תווית'] = label, | ['תווית'] = label, | ||
item = item, | |||
['פריט'] = item, | |||
formatEntity = formatEntity, | formatEntity = formatEntity, | ||
property = property, | property = property, | ||
| שורה 481: | שורה 599: | ||
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 | ||
} | } | ||