לדלג לתוכן

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

מתוך צפונות ויקי
מאין תקציר עריכה
מאין תקציר עריכה
שורה 2: שורה 2:


function p.property(propName)
function p.property(propName)
         entity = mw.wikibase.getEntity()
    if true then
       
         return propName
        if entity == nil or entity.claims == nil then
    end
            return nil --the entity doesnt exist or have no claims
    entity = mw.wikibase.getEntity()
   
    if entity == nil or entity.claims == nil then
        return nil --the entity doesnt exist or have no claims
    end
    property = entity.claims[propName]
    if property == nil then
        return nil --no such property for this item
    end
    property = property[0]
    propValue = property.mainsnak.datavalue
    if propValue ==nil then
        return nil --property doesnt exist
    end
    if propValue['type']=='wikibase-entityid' then
        linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id'])
        linkTitle = mw.wikibase.label("Q" ..propValue.value['numeric-id'])
        if not ((linkTarget == nil) or (linkTitle==nil)) then
            return "[[" .. linkTarget .. "|" .. linkTitle .."]]"
         end
         end
        property = entity.claims[propName]
    elseif propValue['type']=='string' then
        if property == nil then
        return propValue.value
            return nil --no such property for this item
    end
        end
    return nil
        property = property[0]
        propValue = property.mainsnak.datavalue
        if propValue ==nil then
            return nil --property doesnt exist
        end
        if propValue['type']=='wikibase-entityid' then
            linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id'])
            linkTitle = mw.wikibase.label("Q" ..propValue.value['numeric-id'])
            if not ((linkTarget == nil) or (linkTitle==nil)) then
                return "[[" .. linkTarget .. "|" .. linkTitle .."]]"
            end
        elseif propValue['type']=='string' then
            return propValue.value
        end
        return nil
          
          
end
end
return p
return p

גרסה מ־13:18, 5 באפריל 2013

יחידה זו משמשת כדי לקשר בוויקיפדיה לפי ויקינתונים. היחידה מיועדת לשימוש בעיקר בתבניות וכוללת את הפונקציות הבאות:

  • property או מאפיין - לקבלת קישור לפי "קביעה" מוויקינתונים
    • פרמטרים: שם המאפיין (property) המתאים (בצורה של P123). למשל בערך דמויי כלב:
      • {{#invoke:PropertyLink|property|p171}} - יחזיר "[[טורפים (סדרת יונקים)|טורפים]]" (טורפים), להבדיל מ־[[{{#property:p70}}]], שיחזיר "[[טורפים]]" (טורפים), שהוא דף פירושונים.
  • label או תווית: דומה לפונקציה הקודמת, רק שלא מחזיר קישור אלא ללא קישור - מחזיר את התווית (label) וללא תלות בקישור כלשהו שקיים או לא קיים בוויקיפדיה בעברית
    • פרמטרים: שם המאפיין (property) המתאים (בצורה של P123)
  • imageLink או תמונה: פונקציה שמחזירה תמונה שמתאימה לשילוב בתבנית מידע בערך.
    • פרמטרים:
      • פרמטר ראשון - (אופציונלי) אם לא מקבל פרמטר בכלל משתמש ב־d:Property:p18 (מאפיין כללי של תמונה), אחרת משתמש בפרמטר המאפיין המכיל את התמונה
      • width - גודל התמונה (אחרת 220px)
  • hasEntry או יש פריט: פונקציה שמחזירה "1" אם לערך יש פריט ויקינתונים; או "" אם אין.
    • פרמטרים: אין

הערות נוספות:

ייתכן שבעתיד תהיה תמיכה מובנית לפחות בחלק מהאפשרויות הנ"ל ראו בmeta:Wikidata/Notes/Inclusion_syntax#Items

local p = {}

function p.property(propName)
    if true then
        return propName
    end
    entity = mw.wikibase.getEntity()
    
    if entity == nil or entity.claims == nil then
        return nil --the entity doesnt exist or have no claims
    end
    property = entity.claims[propName]
    if property == nil then
        return nil --no such property for this item
    end
    property = property[0]
    propValue = property.mainsnak.datavalue
    if propValue ==nil then
        return nil --property doesnt exist
    end
    if propValue['type']=='wikibase-entityid' then
        linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id'])
        linkTitle = mw.wikibase.label("Q" ..propValue.value['numeric-id'])
        if not ((linkTarget == nil) or (linkTitle==nil)) then
            return "[[" .. linkTarget .. "|" .. linkTitle .."]]"
        end
    elseif propValue['type']=='string' then
        return propValue.value
    end
    return nil
        
end
return p