יחידה:מזהים חיצוניים
מתוך ויקיפדיה, האנציקלופדיה החופשית
פעולות נוספות
יחידה זו משמשת בסיס ליצירת תבניות פרופילים לקישורים חיצוניים.
שימוש בתבניות מזהים חיצוניים עריכה
- נהוג להוסיף תבניות מזהים חיצוניים בפרק הקישורים החיצוניים
- הקישורים מוצגים כפריטי רשימה
- כאשר נדרשים בקישור החיצוני להחליף את כותרת הנושא (ברירת המחדל היא שם הדף):
- לדריסה בכל האתרים שבתבנית - ניתן להוסיף פרמטר שם
- לדריסה של כותרת באתר ספציפי - ניתן להוסיף פרמטר "שם-<שם האתר>"
רשימות מזהים עריכה
יש להגדיר מזהים חיצונים לפי נושאים, המשמשים כבסיס נתונים לתבנית. ניתן למצוא דוגמאות בדפי המשנה:
הרשימות תומכות בפרטים הבאים:
- wikidata - מאפיין ויקינתונים שממנו התבנית יכולה לשאוב מידע
- link - קישור לאתר החיצוני
- link-text - התוכן שיופיע בכל קישור
- text-suffix - סיומת המתארת את הקישור
- logo - לוגו של האתר
יצירת תבניות פרופילים עריכה
יש להגדיר את הרשימות הרלוונטיות לאותו נושא.
לדוגמה:
{{#invoke:מזהים חיצוניים|מזהים|רשימות=רשתות חברתיות,קולנוענים-מוזיקאים,שירותי הזרמה}}
דוגמאות שימוש עריכה
ניתן להיעזר בתבניות אחרות שמשתמשות ביחידה זו כדוגמאות (מיוחד:דפים המקושרים לכאן/יחידה:מזהים חיצוניים)
- תבנית:פרופילי אישים (הכללה) (→ קישורים | עריכה)
- תבנית:אנציקלופדיות (→ קישורים | עריכה)
-- [Pinkas] Wikibase Client is not installed; route mw.wikibase through a local no-op stub
-- so Wikidata-backed fields degrade to nil/empty instead of raising Lua errors. No external
-- data is ever fetched. See [[Module:Wikibase-stub]].
if not mw.wikibase then mw.wikibase = require( 'Module:Wikibase-stub' ) end
local config = {
compactLinks=false,
listCollapseThreshold=10,
}
local p = {}
--[[
Renders links as list.
@param links list of links as struct. Struct should have link, subject used for the link and link text. logo and linkDescription.
@param title Title to aggregate the links
@param collapseThreshold Number of links which exceeding it would mark them to appear as collapsble element
]]
function p.renderLinksList(links, title, collapseThreshold)
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 collapseThreshold>0 and #links >= collapseThreshold then
res = '{| class ="mw-collapsible mw-collapsed"\n! '..title..'\n|-\n|\n' .. res ..'\n|}'
end
return res
end
function p.renderCompactLinksGroups(titlesLinks, externalNavbox)
local Navbox = require('Module:Navbox')
local elementsCat = ''
local navBoxTable = {
name = 'externalIdentifiers',
navboxclass = 'external-ifentifiers',
bodyclass = 'hlist',
liststyle = 'text-align:right;'
}
-- override default navbox with external one
if externalNavbox~= nil then
navBoxTable = externalNavbox
end
local i=0
for _,vList in pairs(titlesLinks) do
local formatedLinks = {}
for _, linkStruct in pairs(vList.list) do
--if linkStruct.logo then
-- table.insert(formatedLinks, mw.ustring.format('\n* <span class="nowrap">%s [%s %s]</span>', linkStruct.logo, linkStruct.link, linkStruct.siteName))
--else
table.insert(formatedLinks, mw.ustring.format('\n* <span class="nowrap">[%s %s]</span>', linkStruct.link, linkStruct.siteName))
--end
end
if #formatedLinks > 0 then
i=i+1
navBoxTable['group'..i] = vList.title
navBoxTable['list'..i] = table.concat( formatedLinks )
end
end
-- no links
if i==0 then
if externalNavbox~=nil then return externalNavbox, 0 end
return '' -- nothing
end
if externalNavbox~=nil then
return navBoxTable, i
else
local outString = Navbox._navbox( navBoxTable )
local stylesheet = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'יחידה:מזהים חיצוניים/style.css' } }
return stylesheet..outString
end
end
function p.renderCompactLinks(title, links)
vlist = { { title = title, list = links } }
return p.renderCompactLinksGroups(vlist)
end
local function getWikidata(entityId, prop, snak)
local properyVal = mw.wikibase.getBestStatements(entityId, prop)
local mainSnak = properyVal and #properyVal>0 and properyVal[1].mainsnak
if mainSnak and properyVal[1].mainsnak.snaktype=='novalue' then
return nil
end
if snak or mainSnak==nil then
return mainSnak
end
local propValue = mainSnak.datavalue and mainSnak.datavalue.value
return propValue
end
--[[
Render external links according to wikidata, where we have profile template to define the links
]]
function p.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 = mw.uri.encode(propValue, 'WIKI')
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 p.renderCompactLinks(title, links)
else
return p.renderLinksList(links)
end
end
function p.rednerLinksJsonNavbox(entityId, listsOfLinks, externalNavbox)
local result = ''
if externalNavbox then result=externalNavbox end
if entityId == nil then
return result
end
local linksGroups = {} -- {[1] { title = title of the group, list = list of links}
local linkCounter = 0
listsOfLinks = mw.text.split(listsOfLinks,',')
local frame = mw.getCurrentFrame()
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'], true )
if propValue then
local link
-- if no link template provided, auto populate it using extraction from formatValue
if v.link==nil or string.len( v.link ) == 0 then
link = mw.wikibase.formatValue(propValue)
link = mw.ustring.gsub( link, "<span>%[(.+) .+", "%1" )
else
propValue = propValue.datavalue and propValue.datavalue.value or ''
propValue = mw.uri.encode(propValue, 'WIKI')
propValue = mw.ustring.gsub( propValue, "%%", "%%%%" )
link = v.link .. propValue
end
local subject = frame:preprocess(v['link-text']) -- allow to override it with linkText? but it would be global for all links...
table.insert(links, {
link= link,
subject = subject,
logo=v['logo'] and frame:preprocess(v['logo']),
linkDescription=frame:preprocess(v['text-suffix']),
siteName=v['compact-text']
})
end
end
if #links>0 then
linkCounter = linkCounter + #links
table.insert(linksGroups, {
title= social.title,
list = links,
render = social.render
})
end
end
result = p.renderCompactLinksGroups(linksGroups, externalNavbox)
return result
end
--[[
Render external links according to wikidata, based on JSON subpages
]]
function p.rednerLinksJson(frame)
local templateParams = frame.args
local templateArgs = frame:getParent().args
local entityId = templateArgs['ישות']
local linkText = templateArgs['1']
if entityId=='' or entityId==nil then
entityId = mw.wikibase.getEntityIdForCurrentPage()
end
return p.rednerLinksJsonNavbox(entityId, templateParams['רשימות'])
end
-- alias
p['פריטים'] = p.renderLinksTemplate
p['מזהים'] = p.rednerLinksJson
return p