יחידה:תבנית מידע – הבדלי גרסאות
תוכן שנמחק תוכן שנוסף
מאין תקציר עריכה |
ניסוי |
||
שורה 300: | שורה 300: | ||
end |
end |
||
end |
end |
||
if wikidataArg then |
if not empty(wikidataArg) then |
||
return propertyLink.getImageLink(wikidataArg, width) |
return propertyLink.getImageLink(wikidataArg, width) |
||
end |
end |
||
שורה 319: | שורה 319: | ||
This function fills missing parameter using wikidata |
This function fills missing parameter using wikidata |
||
]] |
]] |
||
function empty(p) |
|||
mw.log('calling empty. p=', p) |
|||
return not p or mw.text.trim(p) == '' |
|||
end |
|||
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, frame) |
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, frame) |
||
local inWikidata = false |
local inWikidata = false |
||
שורה 324: | שורה 330: | ||
local maintainceCats = nil |
local maintainceCats = nil |
||
local propertyName = nil |
local propertyName = nil |
||
if templateParams[missingParam..'-ויקינתונים'] then |
if not empty(templateParams[missingParam..'-ויקינתונים']) then |
||
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים']) or nil |
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים']) or nil |
||
inWikidata = templateArg.data and #(templateArg.data)>0 |
inWikidata = templateArg.data and #(templateArg.data)>0 |
||
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then |
elseif not empty(templateParams[missingParam..'-ויקינתונים-מרובה']) then |
||
mw.log('wikidata-many: ', missingParam, templateParams[missingParam..'-ויקינתונים-מרובה']) |
|||
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים-מרובה'], true, false, nil, templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה'], templateParams[missingParam..'-ויקינתונים-פרטים']) or nil |
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים-מרובה'], true, false, nil, templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה'], templateParams[missingParam..'-ויקינתונים-פרטים']) or nil |
||
inWikidata = templateArg.data and #(templateArg.data)>0 |
inWikidata = templateArg.data and #(templateArg.data)>0 |
||
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then |
elseif not empty(templateParams[missingParam..'-ויקינתונים-פשוט']) then |
||
-- use data should be taken from wikidata and link must not be added |
-- use data should be taken from wikidata and link must not be added |
||
local wikidataParamValue = propertyLink.getLabel(templateParams[missingParam..'-ויקינתונים-פשוט']) |
local wikidataParamValue = propertyLink.getLabel(templateParams[missingParam..'-ויקינתונים-פשוט']) |
||
שורה 344: | שורה 351: | ||
hasData, maintainceCats = splitMaintainceCategory(templateArg.data) |
hasData, maintainceCats = splitMaintainceCategory(templateArg.data) |
||
if hasData then |
if hasData then |
||
propertyName=templateParams[missingParam..'-ויקינתונים'] or templateParams[missingParam..'-ויקינתונים-מרובה'] |
propertyName=templateParams[missingParam..'-ויקינתונים'] or templateParams[missingParam..'-ויקינתונים-מרובה']-- very suspicious!emptystring evaluates to true in lua!!! |
||
if propertyName then |
if propertyName then |
||
templateArg.data = templateArg.data.. ' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/'..mw.wikibase.getEntityIdForCurrentPage().. '?uselang=he#'..propertyName..'|עריכת הנתון בוויקינתונים]]' |
templateArg.data = templateArg.data.. ' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/'..mw.wikibase.getEntityIdForCurrentPage().. '?uselang=he#'..propertyName..'|עריכת הנתון בוויקינתונים]]' |
||
שורה 479: | שורה 486: | ||
if m then |
if m then |
||
local inWikidata = false |
local inWikidata = false |
||
if templateParams[m..'-ויקינתונים'] then |
if not empty(templateParams[m..'-ויקינתונים']) then |
||
local wikidataParamValue = propertyLink.getProperty(templateParams[m..'-ויקינתונים']) or nil |
local wikidataParamValue = propertyLink.getProperty(templateParams[m..'-ויקינתונים']) or nil |
||
if wikidataParamValue then |
if wikidataParamValue then |
||
args.title = wikidataParamValue |
args.title = wikidataParamValue |
||
end |
end |
||
elseif templateParams[m..'-ויקינתונים-פשוט'] then |
elseif not empty(templateParams[m..'-ויקינתונים-פשוט']) then |
||
-- use data should be taken from wikidata and link must not be added |
-- use data should be taken from wikidata and link must not be added |
||
local wikidataParamValue = propertyLink.getLabel(templateParams[m..'-ויקינתונים-פשוט']) |
local wikidataParamValue = propertyLink.getLabel(templateParams[m..'-ויקינתונים-פשוט']) |
גרסה מ־00:37, 18 באוגוסט 2017
תבנית מידע היא יחידה המשמשת ליצירת תבניות מידע (infobox) בצורה קלה והמקושרות לוויקינתונים.
אופן השימוש
להלן תיעוד קצר של הפרמטרים הנתמכים על ידי היחידה. ניתן להיעזר גם ב#דוגמאות שימוש.
הגדרת פרמטרים
- היחידה תומכת בקבלת פרמטרים ממסופרים כאשר המספר מגדיר יחס סדר בין הפרמטרים
- סוגי הפרמטרים הנתמכים (יש להחליף את X במספר)
- תוויתX – תווית עבור פרמטר מספר X (לא יוצג ללא מילוי מידעX)
- מידעX – תוכן עבור פרמטר X
- אם מופיע פרמטר תוויתX, יופיע משמאל לתווית המתאימה שהוגדרה
- אם לא מופיע פרמטר תוויתX, יוצג בשתי עמודות
- תווית-מידעX – קיצור דרך כדי לציין פרמטר שהתווית שלו זהה לשם הפרמטר (מקביל ל0"תוויתX=שם הפרמטר" בצירוף "מידעX={{{שם הפרמטר|}}}". התווית יכולה להכיל קישור, אשר מוסר משם הפרמטר.
- מידע-פרמטריX – קיצור דרך ל-מידעX כדי לציין פרמטר בודד.
- כותרתX – כותרת שתופיע לפני מקבץ של פרמטרים (הפרמטרים X+1, X+2 וכו'). הכותרת תופיע רק אם הפרמטרים שמופיעים בינה לבין הכותרת הבאה אחריה מלאים. (ראו removeEmptyHeaders)
- תמונה וכיתוב – הגדרת התוכן שיופיע כתמונה, והתוכן שיופיע ככיתוב
- תמונה ימין ותמונה שמאל – תוכן שיופיע עבור תמונה שתופיע מימין/שמאל (בתבנית שתומכות בתמונה ימנית ושמאלית)
- כותרת תבנית – מציין את הכותרת הראשית לתבנית. אם לא מוגדר בתבנית, כותרת ברירת המחדל היא פרמטר שם ולאחריו שם בשפת המקור.
תמיכה בוויקינתונים
התבנית תומכת במילוי אוטומטי של מידע מוויקינתונים כאשר לא מוזן מידע על ידי המשתמשים:
- עבור {{{שם הפרמטר}}} היחידה מחפשת הגדרה של "שם הפרמטר-ויקינתונים" המגדיר את שם התכונה שיש למשוך מוויקינתונים במקרה שהמידע לא הוזן על ידי המשתמש. לשימושים מתקדמים:
- שם הפרמטר-ויקינתונים מגדיר משיכה חכמה של פרמטרים מוויקינתונים, שיודעת להוסיף קישורים מתאימים לערכים, להגדיר תמונות , ולהוסיף "נכון ל" עבור ערכים מספריים (ראו עוד ביחידה:PropertyLink)
- שם הפרמטר-ויקינתונים-פשוט – מגדיר משיכה לא חכמה של פרמטרים מוויקינתונים
- שם הפרמטר-ויקינתונים-מרובה – מגדיר שאפשר למשוך מספר ערכים מוויקינתונים, כשכל ערך מופרד בפסיק. ניתן להעביר מספר פרמטרים בצורה "P1,P2" כך שגם P1 וגם P2 יימשכו, או "P1/P2" כך שאם P1 קיים הוא יימשך, אחרת - P2.
- שם הפרמטר-ויקינתונים-גובר – מגדיר שגם אם יש ערך שמוזן בתבנית, הערך מוויקינתונים ידרוס אותו. הפרמטר הוא התווית של השדה כדי למנוע מצב שבו לא מוגדרת תווית או שהתווית לא תואמת את השם שיש לשאוב מוויקינתונים.
פרמטרים מיוחדים:
- קואורדינטות – עבור פרמטר שנקרא קואורידנטות התבנית מוסיפה בצורה אוטומטית {{קואורדינטות מוויקינתונים}}. אין צורך להגדיר בצורה מיוחדת, אך יש להימנע ממתן שם "קואורדינטות" לפרמטר שלא מיועד לקואורדינטות גאוגרפיות
- מפה-זום – עבור תבניות שמצפות למפה (פרמטר בשם מפה), ניתן לציין פרמטר זה להוספה אוטומטית של מפה עם זום ברירת מחדל במידה והעורכים לא ציינו מפה ספציפית בערך.
- qid – ניתן לציין את שם היישות שממנה התבנית תשלוף מידע, לאו דווקא היישות של הערך (אפשרות זו לא נתמכת עבור קואורדינטות ועבור מפה)
הגדרות מתקדמות נוספות לשליטה על אופן התצוגה של ערכים מיובאים מוויקינתונים:
- שם הפרמטר-ויקינתונים-מרובה-הפרדה – מאפשר להגדיר את התו המפריד בין ערכים שונים. ברירת המחדל היא פסיק (,). בשדות שעשויות להכיל תוכן רב, מומלץ להגדיר את ההפרדה כשבירת שורה (<br>)
- שם הפרמטר-ויקינתונים-מגדר – יש לציין "כן" אם ערכי הפרמטר תלויים במגדר. למשל בפרמטר של "עיסוק" נרצה "סופר" או "סופרת" בהתאם למין.
- שם הפרמטר-ויקינתונים-פרטים – מאפשר להגדיר פרט אופציונלי נוסף שיופיע בסוגריים ליד הנתון. הפרט הנוסף צריך להיות מזהה של מבחין (Qualifier). אפשר למשוך מספר מבחינים, כאשר הם מופרדים בפסיק.
- שם הפרמטר-ויקינתונים-פרטים-הפרדה – מציין את ההפרדה בין כל אחד מאחד ממאפייני המשנה.
- שם הפרמטר-ויקינתונים-פרטים-ברירת מחדל – מציין את ערך ברירת המחדל שיוכנס אליו במידה ואחד ממאפייני המשנה לא קיים (יעבוד רק אם חסר לפחות אחד ממאפייני המשנה וקיים לפחות ערך אחר ממאפייני המשנה).
- שם הפרמטר-ויקינתונים-סינון – מאפשר סינון של ערכים. במידה ויוכנס "קיים", יתאפשרו רק ערכים קיימים בוויקיפדיה העברית.
עיצוב
הפרמטרים הבאים מאפשרים שליטה על עיצוב התבנית:
- עיצוב-שורהX – שליטה על עיצוב שורה
- תוויתX-עיצוב – שליטה על עיצוב תוויתX
- מידעX-עיצוב – שליטה על עיצוב מידעX
- כותרתX-עיצוב – שליטה על עיצוב כותרתX
- כותרת תבנית-עיצוב – הגדרת עיצוב לכותרת התבנית
- כותרת תבנית-מחלקה – הגדרת מחלקת עיצוב לכותרת התבנית
- טבלה-עיצוב – מגדירה את עיצוב הטבלה
- טבלה-מחלקה – מגדירה מחלקה לעיצוב הטבלה. דוגמאות למחלקות שימושיות:
- infobox-nowrap-labels – מגדירה ללא שבירות שורה בתוויות
- bordered – מוסיפה מסגרות
הסתרת פרמטר
כאשר מעוניינים להסתיר פרמטר שהתבנית מקבלת, ניתן להגדיר את הערך שלו כ"-".
דוגמאות שימוש
ניתן להיעזר בתבניות אחרות שמשתמשות ביחידה זו כדוגמאות (מיוחד:דפים המקושרים לכאן/יחידה:תבנית מידע)
- תבנית:יסוד כימי (הכללה) (→ קישורים | עריכה)
- תבנית:צבע (הכללה) (→ קישורים | עריכה)
- תבנית:מספר שלם (הכללה) (→ קישורים | עריכה)
- תבנית:קבוצת כדורגל (הכללה) (→ קישורים | עריכה)
- תבנית:רק"ם (הכללה) (→ קישורים | עריכה)
- תבנית:חברה מסחרית (הכללה) (→ קישורים | עריכה)
- תבנית:ספר (הכללה) (→ קישורים | עריכה)
- תבנית:מוזיקה (הכללה) (→ קישורים | עריכה)
- תבנית:חומצת אמינו (הכללה) (→ קישורים | עריכה)
- תבנית:שפה (הכללה) (→ קישורים | עריכה)
- תבנית:סרט (הכללה) (→ קישורים | עריכה)
- תבנית:תוכנה (הכללה) (→ קישורים | עריכה)
- תבנית:הכוחות המזוינים של ארצות הברית (הכללה) (→ קישורים | עריכה)
- תבנית:ערך תזונתי (הכללה) (→ קישורים | עריכה)
- תבנית:נהר (הכללה) (→ קישורים | עריכה)
- תבנית:מערכת הפעלה (הכללה) (→ קישורים | עריכה)
- תבנית:אישיות כדורגל (הכללה) (→ קישורים | עריכה)
- תבנית:תוכנית טלוויזיה (הכללה) (→ קישורים | עריכה)
- תבנית:תרכובת (הכללה) (→ קישורים | עריכה)
- תבנית:כוכב (הכללה) (→ קישורים | עריכה)
- תבנית:מינרל (הכללה) (→ קישורים | עריכה)
- תבנית:נבחרת לאומית (הכללה) (→ קישורים | עריכה)
- תבנית:טייס חלל (הכללה) (→ קישורים | עריכה)
- תבנית:מתאבק (הכללה) (→ קישורים | עריכה)
- תבנית:משימת חלל (הכללה) (→ קישורים | עריכה)
- תבנית:טניסאי (הכללה) (→ קישורים | עריכה)
- תבנית:פילוסוף (הכללה) (→ קישורים | עריכה)
- תבנית:גוף מים (הכללה) (→ קישורים | עריכה)
- תבנית:תוכנית לימודים (הכללה) (→ קישורים | עריכה)
- תבנית:אולימפיאדה (הכללה) (→ קישורים | עריכה)
- תבנית:קבוצה אתנית (הכללה) (→ קישורים | עריכה)
- תבנית:הכוחות המזוינים של ברית המועצות (הכללה) (→ קישורים | עריכה)
- תבנית:הכוחות המזוינים של בריטניה (הכללה) (→ קישורים | עריכה)
- תבנית:הכוחות המזוינים של ברזיל (הכללה) (→ קישורים | עריכה)
- תבנית:אופרה (הכללה) (→ קישורים | עריכה)
- תבנית:מפל מים (הכללה) (→ קישורים | עריכה)
- תבנית:תרופה (הכללה) (→ קישורים | עריכה)
- תבנית:עיתון (הכללה) (→ קישורים | עריכה)
- תבנית:טיל (הכללה) (→ קישורים | עריכה)
- תבנית:מחשב (הכללה) (→ קישורים | עריכה)
- תבנית:משקה (הכללה) (→ קישורים | עריכה)
- תבנית:אצטדיון (הכללה) (→ קישורים | עריכה)
- תבנית:אישיות משחק (הכללה) (→ קישורים | עריכה)
- תבנית:קוקטייל (הכללה) (→ קישורים | עריכה)
- תבנית:מטבע (הכללה) (→ קישורים | עריכה)
- תבנית:חג (הכללה) (→ קישורים | עריכה)
- תבנית:ליגה (הכללה) (→ קישורים | עריכה)
- תבנית:תנועת נוער (הכללה) (→ קישורים | עריכה)
- תבנית:נתוני התפלגות (הכללה) (→ קישורים | עריכה)
- תבנית:כלי רכב (הכללה) (→ קישורים | עריכה)
local propertyLink = require('Module:PropertyLink')
local Infobox = {}
function Infobox:new()
local o = {
args={},
templateStructure={},
isSelfUse=false,
autoDocumentation=false,
wikidataCats= {},
root = mw.html.create('table')
}
setmetatable(o, self)
self.__index = self
return o
end
function Infobox:render()
if self.isSelfUse then
local templateDocumentation=''
for k,v in pairs(self.templateParams) do
if mw.ustring.match( k, '-ויקינתונים') then
templateDocumentation = templateDocumentation .. '[[קטגוריה:תבניות שמשתמשות בוויקינתונים]]'
break
end
end
if self.autoDocumentation then
templateDocumentation = templateDocumentation .. self:_generateDocumentation()
end
return self:renderInfobox() .. templateDocumentation
end
return self:renderInfobox() .. table.concat(self.wikidataCats, '')
end
--[[
Generate auto documentation for template.
]]
function Infobox:_generateDocumentation()
local labelDataPrefix = 'תווית-מידע'
local parameters = {}
for k,v in pairs(self.templateParams) do
if mw.ustring.match( tostring(k),'תווית%-מידע%d' ) then
table.insert(parameters, '"'..string.gsub(v, '"', '\\"')..'":'..'{ "description": ""}')
else
for mm in mw.ustring.gmatch( tostring(v),'%{%{%{(.-)[%}|]') do
table.insert(parameters, '"'..string.gsub(mm, '"', '\\"')..'":'..'{ "description": ""}')
end
end
end
local templateDoc = '{ "params": { '..table.concat(parameters,'\n,')..'}}'
return frame:extensionTag( 'templatedata', templateDoc )
end
--[[
Renders the infobox title
]]
function Infobox:renderTitle()
-- renders the title
local titleCaption = self.root
:tag('caption')
:addClass(self.args.titleclass)
:cssText(self.args.titlestyle)
:wikitext(self.args.title)
if self.args.subtitle and self.args.subtitle~=nil and #(self.args.subtitle)>0 then
local row = self.root:tag('tr')
:tag('th')
:attr('colspan', 2)
:css('text-align','center')
:cssText(self.args.subtitlestyle)
:addClass(self.args.subtitleclass)
:wikitext(self.args.subtitle)
end
return self.titleCaption
end
--[[
Renders the right/left images (possibly 1/2/none of them available) and the main image
]]
function Infobox:renderImages()
-- render right an left images
self.args.rightImage = self.args.rightImage~=nil and #(self.args.rightImage)>0 and self.args.rightImage
self.args.leftImage = self.args.leftImage~=nil and #(self.args.leftImage)>0 and self.args.leftImage
if self.args.rightImage or self.args.leftImage then
if self.args.rightImageDesc~=nil and #(self.args.rightImageDesc)>0 then
self.args.rightImage = self.args.rightImage..'<div>' .. self.args.rightImageDesc .. '</div>'
end
if self.args.leftImageDesc~=nil and #(self.args.leftImageDesc)>0 then
self.args.leftImage = self.args.leftImage .. '<div>' .. self.args.leftImageDesc .. '</div>'
end
local row = self.root:tag('tr')
:tag('td')
:attr('colspan', 2)
:css('text-align','center')
if self.args.rightImage and self.args.leftImage then
row:tag('table')
:css('width','100%')
:tag('tr')
:tag('td')
:css('width','50%')
:css('vertical-align','middle')
:css('text-align','center')
:wikitext(self.args.rightImage)
:tag('td')
:css('width','50%')
:css('vertical-align','middle')
:css('text-align','center')
:wikitext(self.args.leftImage)
:done()
else
row:wikitext(self.args.leftImage or self.args.rightImage)
end
end
-- render the main image
if self.args.image then
self.root:tag('tr')
:tag('td')
:attr('colspan', 2)
:css('text-align','center')
:wikitext(self.args.image)
if self.args.imageDesc and #self.args.imageDesc>0 then
self.root:tag('tr')
:tag('td')
:attr('colspan', 2)
:addClass('thumbcaption')
:addClass('borderless')
:css('text-align','center')
:wikitext(self.args.imageDesc)
end
end
end
--[[
Adds edit links for easier editing of the template. If the template use data from wikidata it also adds edit link in Wikidata
]]
function Infobox:renderEditLinks()
local wbEdit='' -- link to wikidata
if self.args.usingWikidata then
local entity = mw.wikibase.getEntityObject()
wbEdit = '[[File:Wikidata-logo S.svg|20px|link=d:'..entity.id..'|לעריכה בוויקינתונים שמשמש מקור לחלק מהמידע בתבנית]]'
end
if #wbEdit > 0 then
self.root:tag('tr')
:tag('td')
:attr('colspan', 2)
:css('text-align','left')
:wikitext(wbEdit)
end
end
--[[
Adds a styled row to the table
]]
function Infobox:addRow(rowArgs)
-- Adds a row to the infobox, with either a header cell
-- or a label/data cell combination.
if rowArgs.header then
self.root
:tag('tr')
:addClass(rowArgs.rowclass)
:cssText(self.args.rowsstyle)
:cssText(rowArgs.rowstyle)
:attr('id', rowArgs.rowid)
:tag('th')
:attr('colspan', 2)
:attr('id', rowArgs.headerid)
:addClass(rowArgs.class)
:addClass(self.args.headerclass)
:css('text-align', 'center')
:cssText(self.args.headerstyle)
:cssText(rowArgs.headerstyle)
:wikitext(rowArgs.header)
elseif rowArgs.data and #(rowArgs.data) > 0 then
local row = self.root:tag('tr')
row:addClass(rowArgs.rowclass)
:cssText(self.args.rowsstyle)
:cssText(rowArgs.rowstyle)
:attr('id', rowArgs.rowid)
if rowArgs.label then
row
:tag('th')
:attr('scope', 'row')
:attr('id', rowArgs.labelid)
:css('text-align', 'right')
:cssText(self.args.labelstyle)
:cssText(rowArgs.labelstyle)
:wikitext(rowArgs.label)
:done()
end
local dataCell = row:tag('td')
if not rowArgs.label then
dataCell
:attr('colspan', 2)
if not rowArgs.datastyle then
dataCell:css('text-align', 'center')
end
end
dataCell
:attr('id', rowArgs.dataid)
:addClass(rowArgs.class)
:cssText(self.args.datastyle)
:cssText(rowArgs.datastyle)
:newline()
:wikitext(rowArgs.data)
end
end
--[[
This function removes redundent keys from templateStructure: nil entries and header entries with no data
]]
function Infobox:removeEmptyHeaders()
local lastHeaderIndex=nil
local removeFirstHeader = (not self.args.image or #self.args.image==0) -- remove the first header if there is no image
local tempTemplateStructure = {}
for i,v in pairs(self.templateStructure) do
if v~=nil then
if v.header then
lastHeaderIndex = i
else
if lastHeaderIndex then
if not removeFirstHeader then
table.insert(tempTemplateStructure, self.templateStructure[lastHeaderIndex])
end
lastHeaderIndex = nil
end
removeFirstHeader = false
table.insert(tempTemplateStructure, v)
end
end
end
self.templateStructure=tempTemplateStructure
end
--[[
This function builds the infobox table using structure templateStructure and args
]]
function Infobox:renderInfobox()
self:removeEmptyHeaders()
-- sub infobox
if self.args.title == '-' then
self.root:cssText(self.args.tablestyle):css('width', '100%')
else
self.root:addClass('infobox'):css('width', '18em'):cssText(self.args.tablestyle)
end
if self.args.tableclass then
self.root:addClass(self.args.tableclass)
end
if self.args.title ~='-' then
self:renderTitle()
end
self:renderImages()
local infobox_rows={}
for k,v in pairs(self.templateStructure) do
self:addRow(v)
end
if self.args.title ~= '-' then
self:renderEditLinks()
end
return tostring(self.root)
end
--[[
This function adds image using valueArg, or if not specified by the user tries to get image from wikidata using property
]]
function getValueOrWikidataImage(valueArg, wikidataArg, width, imgDesc)
if valueArg and #valueArg>0 then
if valueArg == '-' then
return nil
else
if not mw.ustring.match(valueArg, '^ *%[%[') and
not mw.ustring.match(valueArg, '^ *%[%[') and
not mw.ustring.match(valueArg, '^ *<') then
local imgSuffix = '|220px'
if imgDesc~=nil and #imgDesc>0 then
imgSuffix = imgSuffix .. '|' .. imgDesc
end
imgSuffix = imgSuffix .. ']]'
if mw.ustring.match(valueArg, '^[Ff]ile:') or
mw.ustring.match(valueArg, '^[Ii]mage:') or
mw.ustring.match(valueArg, '^קובץ:') or
mw.ustring.match(valueArg, '^תמונה:') then
valueArg = '[[' .. valueArg .. imgSuffix
else
valueArg = '[[File:' .. valueArg .. imgSuffix
end
end
return valueArg
end
end
if not empty(wikidataArg) then
return propertyLink.getImageLink(wikidataArg, width)
end
return ''
end
function splitMaintainceCategory(value)
local maintainceCats = nil
local hasData = #(mw.ustring.gsub(value, '%[%[קטגוריה:.-%]%]', ''))>0
if not hasData then
maintainceCats = value
end
return hasData, maintainceCats
end
--[[
This function fills missing parameter using wikidata
]]
function empty(p)
mw.log('calling empty. p=', p)
return not p or mw.text.trim(p) == ''
end
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, frame)
local inWikidata = false
local hasData=false
local maintainceCats = nil
local propertyName = nil
if not empty(templateParams[missingParam..'-ויקינתונים']) then
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים']) or nil
inWikidata = templateArg.data and #(templateArg.data)>0
elseif not empty(templateParams[missingParam..'-ויקינתונים-מרובה']) then
mw.log('wikidata-many: ', missingParam, templateParams[missingParam..'-ויקינתונים-מרובה'])
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים-מרובה'], true, false, nil, templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה'], templateParams[missingParam..'-ויקינתונים-פרטים']) or nil
inWikidata = templateArg.data and #(templateArg.data)>0
elseif not empty(templateParams[missingParam..'-ויקינתונים-פשוט']) then
-- use data should be taken from wikidata and link must not be added
local wikidataParamValue = propertyLink.getLabel(templateParams[missingParam..'-ויקינתונים-פשוט'])
if wikidataParamValue and #wikidataParamValue>0 then
templateArg.data = frame:preprocess(mw.ustring.gsub(templateArg.data, '\{\{\{('..missingParam..')\}\}\}', wikidataParamValue))
inWikidata = true
end
elseif missingParam == 'קואורדינטות' then
templateArg.data = frame:expandTemplate{ title = 'קואורדינטות מוויקינתונים', args = { display = 'title,inline' } }
inWikidata = templateArg.data and #(templateArg.data)>0
end
if inWikidata then
hasData, maintainceCats = splitMaintainceCategory(templateArg.data)
if hasData then
propertyName=templateParams[missingParam..'-ויקינתונים'] or templateParams[missingParam..'-ויקינתונים-מרובה']-- very suspicious!emptystring evaluates to true in lua!!!
if propertyName then
templateArg.data = templateArg.data.. ' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/'..mw.wikibase.getEntityIdForCurrentPage().. '?uselang=he#'..propertyName..'|עריכת הנתון בוויקינתונים]]'
end
else
inWikidata = false
maintainceCats = maintainceCats
end
end
return inWikidata, maintainceCats
end
function Infobox:parseArgs(frame)
local DEFAULT_IMAGE_PROPERTY = 'P18'
local templateParams = frame.args
local templateArgs = frame:getParent().args
local args={}
local templateStructure = {}
args.title = frame.args['כותרת תבנית']
args.titlestyle = frame.args['כותרת תבנית-עיצוב']
args.titleclass = frame.args['כותרת תבנית-מחלקה']
args.subtitle = frame.args['תת כותרת תבנית']
args.subtitlestyle = frame.args['תת כותרת תבנית-עיצוב']
args.subtitleclass = frame.args['תת כותרת תבנית-מחלקה']
args.rightImage = getValueOrWikidataImage(frame.args['תמונה ימין'], frame.args['תמונה ימין-ויקינתונים'], '100')
args.rightImageDesc = frame.args['כיתוב ימין']
args.leftImage = getValueOrWikidataImage(frame.args['תמונה שמאל'], frame.args['תמונה שמאל-ויקינתונים'], '100')
args.leftImageDesc = frame.args['כיתוב שמאל']
args.imageDesc = frame.args['כיתוב']
args.image = getValueOrWikidataImage(frame.args['תמונה'], frame.args['תמונה-ויקינתונים'] or 'P18', '250', args.imageDesc)
args.headerclass = frame.args['כותרת-מחלקה']
args.headerstyle = frame.args['כותרת-עיצוב']
args.rowsstyle = frame.args['שורה-עיצוב']
args.labelstyle = frame.args['תווית-עיצוב']
args.datastyle = frame.args['מידע-עיצוב']
args.tablestyle = frame.args['טבלה-עיצוב']
args.tableclass = frame.args['טבלה-מחלקה']
local isSelfUse = (mw.title.getCurrentTitle().namespace==10)
self.autoDocumentation = frame.args['תיעוד-אוטומטי']
local labelPrefix = 'תווית'
local dataPrefix = 'מידע'
local subheader = 'כותרת'
local labelDataPrefix = 'תווית-מידע'
local rowStylePrefix = 'עיצוב-שורה'
local rowStyleClassPrefix = 'מחלקה-שורה'
local styleSuffix = '-עיצוב'
local k=0
local processedParams = {}
local wikidataCats = {}
for k,v in pairs(templateParams) do
local i= string.match(k, '.-([0-9]+)$')
if i and not (processedParams[i]) then
indic = tonumber(i)
processedParams[i]=1
local subHeaderName = templateParams[subheader..i]
if subHeaderName and #subHeaderName>0 then --subheader type
table.insert(templateStructure, {header=subHeaderName,rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], headerstyle=templateParams[subheader..i..styleSuffix], indic=indic})
else
local labelName = templateParams[labelPrefix..i]
local dataTemplate = templateParams[dataPrefix..i]
if dataTemplate then
-- if parameter contains only category with no value, replace with with nil and add teh value to maintaince category
local hasData, maintainceCats = splitMaintainceCategory(dataTemplate)
if maintainceCats and not hasData then
table.insert(wikidataCats, maintainceCats)
dataTemplate=nil
end
end
if labelName and dataTemplate then
--label: data type
table.insert(templateStructure, {label=labelName, data=dataTemplate, rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], datastyle=templateParams[dataPrefix..i..styleSuffix],
labelstyle=templateParams[labelPrefix..i..styleSuffix], indic=indic})
elseif labelName and not dataTemplate then
--skip it. no only label [use subheader]
elseif not labelName and dataTemplate then
--only data type
table.insert(templateStructure, {data=dataTemplate, rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], datastyle=templateParams[dataPrefix..i..styleSuffix], indic=indic})
else
local label_data_names = templateParams[labelDataPrefix..i]
if label_data_names then
labelName = label_data_names
label_data_names = mw.text.trim(label_data_names, '%[%]')
if templateArgs[label_data_names] and #templateArgs[label_data_names]>0 then
dataTemplate = templateArgs[label_data_names]
else
dataTemplate = '{{{' ..label_data_names.. '}}}'
end
table.insert(templateStructure, {label=labelName, data=dataTemplate, rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], datastyle=templateParams[dataPrefix..i..styleSuffix],
labelstyle=templateParams[labelPrefix..i..styleSuffix], indic=indic})
end
end
end
end
end
table.sort(templateStructure, function (x, y) return x.indic<y.indic end)
-- use wikidata / remove unused parameters
if not isSelfUse then
for k,v in pairs(templateStructure) do
if v.data then
-- remove parameters that were explicitly defined to be removed
local ignoreParam = mw.ustring.match(v.data, '^%-$')
if ignoreParam then
templateStructure[k]=nil
else
-- otherwise if the template isn't full - try to use wikidata to fill it
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}')
if m then
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before
local inWikidata, maintainceCats = fillMissingParamFromWikidata(m, templateParams, v, frame)
if maintainceCats then
table.insert(wikidataCats, maintainceCats)
end
-- if data isn't available remove it
if inWikidata then
args.usingWikidata = true
else
templateStructure[k]=nil
end
end
end
end
end
-- use wikidata in title
if args.title then
local m = mw.ustring.match(args.title, '\{\{\{(.-)\|?\}\}\}')
if m then
local inWikidata = false
if not empty(templateParams[m..'-ויקינתונים']) then
local wikidataParamValue = propertyLink.getProperty(templateParams[m..'-ויקינתונים']) or nil
if wikidataParamValue then
args.title = wikidataParamValue
end
elseif not empty(templateParams[m..'-ויקינתונים-פשוט']) then
-- use data should be taken from wikidata and link must not be added
local wikidataParamValue = propertyLink.getLabel(templateParams[m..'-ויקינתונים-פשוט'])
if wikidataParamValue then
args.title = frame:preprocess(mw.ustring.gsub(args.title, '\{\{\{('..m..')\|?\}\}\}', wikidataParamValue))
end
end
end
end
end
self.args = args
self.templateStructure = templateStructure
self.wikidataCats = wikidataCats
self.isSelfUse = isSelfUse
self.templateParams = templateParams
end
function infobox(frame)
local infoObj = Infobox:new()
infoObj:parseArgs(frame)
return infoObj:render()
end
return {
['מידע']=infobox
}