יחידה:מזהים חיצוניים
קפיצה לניווט
קפיצה לחיפוש
יחידה זו משמשת בסיס ליצירת תבניות פרופילים לקישורים חיצוניים.
שימוש בתבניות מזהים חיצוניים
- נהוג להוסיף תבניות מזהים חיצוניים בפרק הקישורים החיצוניים
- הקישורים מוצגים כפריטי רשימה
- כאשר נדרשים בקישור החיצוני להחליף את כותרת הנושא (ברירת המחדל היא שם הדף):
- לדריסה בכל האתרים שבתבנית - ניתן להוסיף פרמטר שם
- לדריסה של כותרת באתר ספציפי - ניתן להוסיף פרמטר "שם-<שם האתר>"
יצירת תבניות פרופילים
{{#invoke:מזהים חיצוניים|פריטים| |כותרת=פרופילים ב<נושא>: |<מזהה ויקינתונים>-<שם אתר לתצוגה>=<קישור> |<שם אתר לתצוגה>-סמליל=<שם קובץ> }}
כאשר:
- כותרת - היא כותרת כללית לכל הקישורים בתצוגה קומפקטית
- כל קישור חיצוני מזוהה באמצעות שורה שבה:
- מזהה תבנית הוא שדה (property) מוויקינתונים
- שם אתר לתצוגה הוא שם האתר שיוצג
- קישור
- כאשר הקישור הוא מחרוזת ריקה הקישור נלקח מוויקינתונים
- לחלופין ניתן לדרוס את הקישור ולהוסיף מחרוזת קישור ידנית ובה להוסיף $1 לציון מזהה (בדומה לתבניות URL שמוגדרות בd:Property:P1630). אפשרות זו שימושית למשל כאשר רוצים לדרוס כתובת URL לכתובת בגרסה העברית.
- ניתן להגדיר סמלילים לקישורים חיצוניים באמצעות פרמטרים מסוג "שם האתר-סמליל". סמלילים מוצגים בפריסה מורחבת (כאשר יש מעט קישורים)
דוגמאות שימוש
ניתן להיעזר בתבניות אחרות שמשתמשות ביחידה זו כדוגמאות (מיוחד:דפים המקושרים לכאן/יחידה:מזהים חיצוניים)
local config = {
compactLinks=false
}
function renderLinksList(links, title)
local res = ''
for k,linkStruct in pairs(links) do
local logolink
if linkStruct.logo then
logolink = linkStruct.logo
else
logolink = ''
end
res = res..mw.ustring.format('\n*%s [%s %s]%s', logolink, linkStruct.link, linkStruct.subject, linkStruct.linkDescription)
end
if title and #links>5 then
res = '{| class ="mw-collapsible mw-collapsed"\n! '..title..'\n|-\n|\n' .. res ..'\n|}'
end
return res
end
function renderCompactLinks(title, links)
local Navbox = require('Module:Navbox')
local elementsCat = ''
local outString = ''
local formatedLinks = {}
for k,linkStruct in pairs(links) do
table.insert(formatedLinks, mw.ustring.format('\n* <span class="nowrap">[%s %s]</span>', linkStruct.link, linkStruct.siteName))
end
if #formatedLinks > 0 then
local pencil = ''
local itemId = mw.wikibase.getEntityIdForCurrentPage()
if itemId then
local pencilLink = mw.title.makeTitle( 0, itemId, '', 'wikidata' ):fullUrl('uselang=he')
pencil = mw.ustring.format(' [[File:Blue pencil RTL.svg|15px|link=%s|עריכת הנתון בוויקינתונים]]', pencilLink)
end
outString = Navbox._navbox( {
name = title,
navboxclass = 'external-ifentifiers',
bodyclass = 'hlist',
group1 = title ..pencil,
list1 = table.concat( formatedLinks ),
liststyle = 'text-align:right;'
} )
end
local stylesheet = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'יחידה:מזהים חיצוניים/style.css' } }
return stylesheet..outString
end
local function getWikidata(entityId, prop)
local properyVal = mw.wikibase.getBestStatements(entityId, prop)
local propValue = properyVal and #properyVal>0 and properyVal[1].mainsnak and properyVal[1].mainsnak.datavalue and properyVal[1].mainsnak.datavalue.value
return propValue
end
--[[
Render external links according to wikidata, where we have profile template to define the links
]]
function renderLinksTemplate(frame)
local templateParams = frame.args
local templateArgs = frame:getParent().args
local DEFAULT_TITLE = 'מזהים חיצוניים'
local DEFAULT_COMPACT_THRESHOLD = 0
if templateParams['קומפקטי'] then config['compactLinks'] = true end
local linksThreshold = templateParams['רשימה קומפקטית'] or DEFAULT_COMPACT_THRESHOLD -- threshold for rendering as compact list. Default to 0 - always compact
local title = templateParams['כותרת'] or DEFAULT_TITLE -- no title provided to the compacts links
local res=''
local articleTitle = tostring(mw.title.getCurrentTitle())
local subject = mw.ustring.gsub(articleTitle, " *[(].*[)]","")
if templateArgs['שם'] then
subject=templateArgs['שם']
end
local entityId = templateArgs['יישות']
local entity = mw.wikibase.getEntityObject(entityId)
if not entity then
return -- no wikidata entity exist
end
local links = {}
for k,linkTemplate in pairs(templateParams) do
local propery, sitename= string.match(k, '(P[0-9]+)-(.+)$')
if propery and sitename then
local siteSubject = templateArgs['שם-'..sitename]
local sitelogo = templateParams[sitename..'-סמליל']
local siteDescription = templateParams[sitename..'-תיאור']
local propValue = getWikidata( entityId, propery )
if propValue then
local link
-- if no link template provided, auto populate it using extraction from formatValue
if string.len( linkTemplate ) == 0 then
link = string.match(mw.wikibase.formatValue(properyVal[1].mainsnak), '%[([^ ]+)')
else
propValue = frame:preprocess('{{urlencode:'..propValue..'|WIKI}}')--mw.uri.encode(propValue, 'WIKI') see T174239
propValue = mw.ustring.gsub( propValue, "%%", "%%%%" )
link = string.gsub( linkTemplate, '$1', propValue)
end
table.insert(links, {
link=link,
siteName=sitename,
subject=subject,
logo=sitelogo,
linkDescription=siteDescription or mw.ustring.format('באתר [[%s]]', sitename)
})
end
end
end
if #links>linksThreshold and config['compactLinks'] and title then
return renderCompactLinks(title, links)
else
return renderLinksList(links)
end
end
--[[
Render external links according to wikidata, based on JSON subpages
]]
function rednerLinksJson(frame)
local templateParams = frame.args
local templateArgs = frame:getParent().args
local listsOfLinks = mw.text.split(templateParams['רשימות'],',')
local entityId = templateArgs['יישות']
if entityId=='' or entityId==nil then
entityId = mw.wikibase.getEntityIdForCurrentPage()
end
if not entityId then
return -- no wikidata entity exist
end
local result = ''
for _, vList in pairs(listsOfLinks) do
local listTemplate = mw.title.new('מזהים חיצוניים/'..vList..'.json','Module'):getContent()
if listTemplate==nil or listTemplate=='' then
error('לא קיימת רשימה מזהים ב[[יחידה:מזהים חיצוניים/'..vList..'.json]]')
end
local social = mw.text.jsonDecode(listTemplate)
local links = {}
for _, v in pairs(social['items']) do
local propValue = getWikidata( entityId, v['wikidata'] )
if propValue then
local link
-- if no link template provided, auto populate it using extraction from formatValue
if string.len( v.link ) == 0 then
link = string.match(mw.wikibase.formatValue(properyVal[1].mainsnak), '%[([^ ]+)')
else
propValue = frame:preprocess('{{urlencode:'..propValue..'|WIKI}}')--mw.uri.encode(propValue, 'WIKI') see T174239
propValue = mw.ustring.gsub( propValue, "%%", "%%%%" )
link = v.link .. propValue
end
table.insert(links, {
link= link,
subject = frame:preprocess(v['link-text']),
logo=v['logo'] and frame:preprocess(v['logo']),
linkDescription=frame:preprocess(v['text-suffix'])
})
end
end
if #links>0 then
result = result ..'\n' .. renderLinksList(links, social.title)
end
end
return result
end
return {
['פריטים'] = renderLinksTemplate,
['מזהים'] = rednerLinksJson
}