יחידה:PropertyLink: הבדלים בין גרסאות בדף
אין תקציר עריכה |
מ 8 גרסאות של הדף wikipedia:he:יחידה:PropertyLink יובאו |
||
| (16 גרסאות ביניים של 4 משתמשים אינן מוצגות) | |||
| שורה 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 | ||
| שורה 292: | שורה 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) | 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 | ||
| שורה 298: | שורה 301: | ||
local missingTranslation = 0 | 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 | if options['filter'] then | ||
| שורה 503: | שורה 557: | ||
-- returns the wikidata Qid, if exists, "" otherwise | -- returns the wikidata Qid, if exists, "" otherwise | ||
function getPageEntry() | 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 | end | ||
return { | return { | ||
| שורה 524: | שורה 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, | |||
createInterwikiForQid = createInterwikiForQid, | |||
['יש פריט'] = hasEntry | ['יש פריט'] = hasEntry | ||
} | } | ||