בדוקי עריכות אוטומטית, אינטערפעיס רעדאקטארן, אינטערפעיס אדמיניסטראַטאָרן, סיסאפן, מייבאים, מעדכנים, מייבא, אספקלריה רעדאקטארן
46,362
רעדאגירונגען
ק (1 רעוויזיע אימפארטירט פון wikipedia:he:יחידה:PropertyLink: אימפארטירט פון די העברעאישע וויקיפעדיע. זע דארט ביישטייערער ליסטע) |
(אפדעיט) צייכן: מאנועל צוריקשטעל |
||
| שורה 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 | ||
| שורה 214: | שורה 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 | entityId = entityId or mw.wikibase.getEntityIdForCurrentPage() | ||
if entityId == nil then return end -- entity doesnt exist | if entityId == nil then return end -- entity doesnt exist | ||
options = { | options = { | ||
| שורה 278: | שורה 280: | ||
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 | ||
| שורה 291: | שורה 294: | ||
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' | |||
local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | |||
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 | 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) | ||
| שורה 319: | שורה 509: | ||
function getItem( propertyName, entityId ) | function getItem( propertyName, entityId ) | ||
local entity = entityId | 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) | ||
| שורה 337: | שורה 527: | ||
function getImageLink( propName, width, align, description, border, entityId) | function getImageLink( propName, width, align, description, border, entityId) | ||
return --the entity doesnt exist or have no claims | 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 | |||
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 | ||
| שורה 359: | שורה 562: | ||
function getSitelinksFromQid(frame) | function getSitelinksFromQid(frame) | ||
resTable =mw.wikibase.getEntity(string.upper(frame.args[1] )) | resTable = mw.wikibase.getEntity(string.upper(frame.args[1] )) | ||
resTable = resTable["sitelinks"] | resTable = resTable["sitelinks"] | ||
s= "<table>\n" | s= "<table>\n" | ||
| שורה 366: | שורה 569: | ||
s=s.."<tr>".. "<td>" .. k.."</td>".. "<td>" .. v.title.."</td>".."</tr>" .. "\n" | s=s.."<tr>".. "<td>" .. k.."</td>".. "<td>" .. v.title.."</td>".."</tr>" .. "\n" | ||
end | 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 | end | ||
return { | return { | ||
imageLink = imageLink, | imageLink = imageLink, | ||
| שורה 385: | שורה 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, | getPageEntry = getPageEntry, | ||
getSitelinksFromQid=getSitelinksFromQid, | getSitelinksFromQid = getSitelinksFromQid, | ||
createInterwikiForQid = createInterwikiForQid, | |||
['יש פריט'] = hasEntry | ['יש פריט'] = hasEntry | ||
} | } | ||
רעדאגירונגען