לדלג לתוכן

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

מתוך צפונות ויקי
מאין תקציר עריכה
לבקשת ערן
שורה 1: שורה 1:
local p = {}
function property( frame )
 
         local entity = mw.wikibase.getEntity()
function p.property(frame)
         if not entity or not entity.claims then return nil end--the entity doesnt exist or have no claims
         entity = mw.wikibase.getEntity()
         local propertyName = type( frame ) == string and frame or frame.args[1]
         if entity == nil or entity.claims == nil then return nil end--the entity doesnt exist or have no claims
         local property = entity.claims[propertyName]
         propertyName = nil
         if not property then return '' end--no such property for this item
        if frame.args ==nil then
            propertyName = frame
        else
            propertyName = frame.args[1]
         end
        property = entity.claims[propertyName]
         if property == nil then return nil end--no such property for this item
         property = property[0]
         property = property[0]
         propValue = property.mainsnak.datavalue
         local propValue = property.mainsnak and property.mainsnak.datavalue
         if propValue ==nil then return nil end --property doesnt exist
         if not propValue then return '' end --property doesnt exist
         if propValue['type']=='wikibase-entityid' then
         if propValue['type'] == 'wikibase-entityid' then
             linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id'])
             local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] )
             linkTitle = mw.wikibase.label("Q" ..propValue.value['numeric-id'])
             local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
             if not ((linkTarget == nil) or (linkTitle==nil)) then
             return linkTarget and linkTitle and mw.ustring.format("[[%s|%s]]", linkTarget, linkTitle)
                return "[[" .. linkTarget .. "|" .. linkTitle .."]]"
                 or linkTitle
            else
         elseif propValue and propValue['type'] == 'string' then return propValue.value end
                 return linkTitle
         return ''
            end
         elseif propValue['type']=='string' then
            return propValue.value
        end
         return nil
end
end


-- Return the label for property, or the label of the linked entiy of that property
-- Return the label for property, or the label of the linked entiy of that property
function p.label(frame)
function label( frame )
       entity = mw.wikibase.getEntity()
       local entity = mw.wikibase.getEntity()
         if entity == nil or entity.claims == nil then return nil end--the entity doesnt exist or have no claims
         if not entity or not entity.claims then return '' end--the entity doesnt exist or have no claims
         propertyName = nil
         local propertyName = type( frame ) == "string" and frame or frame.args[1]
        if frame.args ==nil then
         local property = entity.claims[propertyName]
            propertyName = frame
         if not property then return '' end--no such property for this item
        else
            propertyName = frame.args[1]
         end
        property = entity.claims[propertyName]
         if property == nil then return nil end--no such property for this item
          
          
         property = property[0]
         property = property[0]
         propValue = property.mainsnak.datavalue
         local propValue = property.mainsnak.datavalue
         if propValue ==nil then return nil end --property doesnt exist
         if not propValue then return '' end --property doesnt exist


         if propValue['type']=='wikibase-entityid' then
         if propValue['type']=='wikibase-entityid' then
             return mw.wikibase.label("Q" ..propValue.value['numeric-id'])
             return mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
         elseif propValue['type']=='string' then
         elseif propValue['type'] == 'string' then
             return propValue.value
             return propValue.value
         end
         end
         return nil
         return ''
end
end


      
      
--use this function to get associated image to be used in the article
--use this function to get associated image to be used in the article
function p.imageLink(frame)
function imageLink( frame )
     entity = mw.wikibase.getEntity()
     local entity = mw.wikibase.getEntity()
     if entity == nil or entity.claims == nil then
     if not entity or not entity.claims then return '' end --the entity doesnt exist or have no claims
            return nil --the entity doesnt exist or have no claims
     local property = entity.claims[frame and frame.args and frame.args[1] or "p18"]
     end
    property = entity.claims[(frame and frame.args and frame.args[1]) or "p18"]
     if property then
     if property then
         width = (frame and frame.args and frame.args["width"]) or "220px"
         local width = frame and frame.args and frame.args["width"] or "220"
         property = '[[File:' .. property[0].mainsnak.datavalue.value ..'|'..width .. ']]'
         return mw.usitring.format( '[[File:%s|%spx]]', property, width )
     end
     end
     return property
     return ''
end
end


return p
return {
    imageLink = imageLink,
    ['תמונה'] = imageLink,
    label = label,
    ['תוית'] = label,
    property = property,
    ['תכונה'] = property,   
}

גרסה מ־15:53, 6 באפריל 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

function property( frame )
        local entity = mw.wikibase.getEntity()
        if not entity or not entity.claims then return nil end--the entity doesnt exist or have no claims
        local propertyName = type( frame ) == string and frame or frame.args[1]
        local property = entity.claims[propertyName]
        if not property then return '' end--no such property for this item
        property = property[0]
        local propValue = property.mainsnak and property.mainsnak.datavalue
        if not propValue then return '' end --property doesnt exist
        if propValue['type'] == 'wikibase-entityid' then
            local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] )
            local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
            return linkTarget and linkTitle and mw.ustring.format("[[%s|%s]]", linkTarget, linkTitle)
                or linkTitle
        elseif propValue and propValue['type'] == 'string' then return propValue.value end
        return ''
end

-- Return the label for property, or the label of the linked entiy of that property
function label( frame )
       local entity = mw.wikibase.getEntity()
        if not entity or not entity.claims then return '' end--the entity doesnt exist or have no claims
        local propertyName = type( frame ) == "string" and frame or frame.args[1]
        local property = entity.claims[propertyName]
        if not property then return '' end--no such property for this item
        
        property = property[0]
        local propValue = property.mainsnak.datavalue
        if not propValue then return '' end --property doesnt exist

        if propValue['type']=='wikibase-entityid' then
            return mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
        elseif propValue['type'] == 'string' then
            return propValue.value
        end
        return ''
end

    
--use this function to get associated image to be used in the article
function imageLink( frame )
    local entity = mw.wikibase.getEntity()
    if not entity or not entity.claims then return '' end --the entity doesnt exist or have no claims
    local property = entity.claims[frame and frame.args and frame.args[1] or "p18"]
    if property then
        local width = frame and frame.args and frame.args["width"] or "220"
        return mw.usitring.format( '[[File:%s|%spx]]', property, width )
    end
    return ''
end

return {
    imageLink = imageLink,
    ['תמונה'] = imageLink,
    label = label,
    ['תוית'] = label,
    property = property,
    ['תכונה'] = property,    
}