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

מאין תקציר עריכה
מ 20 גרסאות של הדף wikipedia:he:יחידה:תבנית_מידע יובאו
 
(105 גרסאות ביניים של 9 משתמשים אינן מוצגות)
שורה 1: שורה 1:
local propertyLink = require('Module:PropertyLink')
local propertyLink = require('Module:PropertyLink')
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local Infobox = {}
local Infobox = {}
function Infobox:new()
function Infobox:new()
שורה 21: שורה 22:
for k,v in pairs(self.templateParams) do
for k,v in pairs(self.templateParams) do
if mw.ustring.match( k, '-ויקינתונים') then
if mw.ustring.match( k, '-ויקינתונים') then
templateDocumentation = templateDocumentation .. '[[קטגוריה:תבניות שמשתמשות בוויקינתונים]]'
templateDocumentation = templateDocumentation .. '[[קטגוריה:תבניות מידע שמשתמשות בוויקינתונים]]'
break
break
end
end
שורה 62: שורה 63:
local  titleCaption = self.root
local  titleCaption = self.root
         :tag('caption')
         :tag('caption')
        :attr('dir', 'auto')
             :addClass(self.args.titleclass)
             :addClass(self.args.titleclass)
             :cssText(self.args.titlestyle)
             :cssText(self.args.titlestyle)
שורה 87: שורה 89:
if self.args.rightImage or self.args.leftImage then
if self.args.rightImage or self.args.leftImage then
if self.args.rightImageDesc~=nil and #(self.args.rightImageDesc)>0 then
if self.args.rightImage and self.args.rightImageDesc~=nil and #(self.args.rightImageDesc)>0 then
self.args.rightImage = self.args.rightImage..'<div>' .. self.args.rightImageDesc .. '</div>'
self.args.rightImage = self.args.rightImage..'<div>' .. self.args.rightImageDesc .. '</div>'
end
end
if self.args.leftImageDesc~=nil and #(self.args.leftImageDesc)>0 then
if self.args.leftImage and self.args.leftImageDesc~=nil and #(self.args.leftImageDesc)>0 then
self.args.leftImage = self.args.leftImage .. '<div>' .. self.args.leftImageDesc .. '</div>'
self.args.leftImage = self.args.leftImage .. '<div>' .. self.args.leftImageDesc .. '</div>'
end
end
שורה 100: שורה 102:
row:tag('table')
row:tag('table')
:css('width','100%')
:css('width','100%')
:css('display','table')
:tag('tr')
:tag('tr')
:tag('td')
:tag('td')
שורה 142: שורה 145:
local wbEdit='' -- link to wikidata
local wbEdit='' -- link to wikidata
if self.args.usingWikidata then
if self.args.usingWikidata then
local entityId = mw.wikibase.getEntityIdForCurrentPage()
wbEdit = '[[File:Wikidata-logo S.svg|22px|link=d:'..self.args.entityId..'|לעריכה בוויקינתונים שמשמש מקור לחלק מהמידע בתבנית]]'
wbEdit = '[[File:Wikidata-logo S.svg|20px|link=d:'..entityId..'|לעריכה בוויקינתונים שמשמש מקור לחלק מהמידע בתבנית]]'
wbEdit = wbEdit .. mw.ustring.format(' [[File:OOjs UI icon info big.svg|16px|link=%s]]', 'עזרה:תבנית מידע')
end
end
if #wbEdit > 0 then
if #wbEdit > 0 then
שורה 175: שורה 178:
                     :cssText(self.args.headerstyle)
                     :cssText(self.args.headerstyle)
                     :cssText(rowArgs.headerstyle)
                     :cssText(rowArgs.headerstyle)
                     :wikitext(rowArgs.header)
                    :newline()
                     :wikitext(rowArgs.data)
     elseif rowArgs.data and #(rowArgs.data) > 0 then
     elseif rowArgs.data and #(rowArgs.data) > 0 then
         local row = self.root:tag('tr')
         local row = self.root:tag('tr')
שורה 187: שורה 191:
                     :attr('scope', 'row')
                     :attr('scope', 'row')
                     :attr('id', rowArgs.labelid)
                     :attr('id', rowArgs.labelid)
                    :css('text-align', 'right')
                     :cssText(self.args.labelstyle)
                     :cssText(self.args.labelstyle)
                     :cssText(rowArgs.labelstyle)
                     :cssText(rowArgs.labelstyle)
                    :newline()
                     :wikitext(rowArgs.label)
                     :wikitext(rowArgs.label)
                     :done()
                     :done()
שורה 218: שורה 222:
function Infobox:removeEmptyHeaders()
function Infobox:removeEmptyHeaders()
  local lastHeaderIndex=nil
  local lastHeaderIndex=nil
  local removeFirstHeader = (not self.args.image or #self.args.image==0) -- remove the first header if there is no image
 
  local hasImage = (self.args.image~=nil and #self.args.image>0)
hasImage = hasImage or (self.args.rightImage~=nil and #self.args.rightImage>0)
hasImage = hasImage or (self.args.leftImage~=nil and #self.args.leftImage>0)  
 
local removeFirstHeader = nil
if self.args.removeFirstHeader~=nil then
removeFirstHeader = (not hasImage) and self.args.removeFirstHeader -- remove the first header if there are no images & the first header is generic
else
removeFirstHeader = (not hasImage)-- default, remove the first header if there are no images
end
 
  local tempTemplateStructure = {}
  local tempTemplateStructure = {}
  for i,v in pairs(self.templateStructure) do
  for i,v in pairs(self.templateStructure) do
שורה 228: שורה 242:
  if lastHeaderIndex then
  if lastHeaderIndex then
  if not removeFirstHeader then
  if not removeFirstHeader then
  table.insert(tempTemplateStructure, self.templateStructure[lastHeaderIndex])
  -- skip headers that are only spaces/nowiki - marking structure seperation
local headerData =mw.text.unstripNoWiki( self.templateStructure[lastHeaderIndex].data )
local headerDataNoSpace = mw.ustring.gsub(headerData, "%s", "")
if #headerDataNoSpace >0 then
table.insert(tempTemplateStructure, self.templateStructure[lastHeaderIndex])
end
  end
  end
  lastHeaderIndex = nil
  lastHeaderIndex = nil
שורה 245: שורה 264:
function Infobox:renderInfobox()
function Infobox:renderInfobox()
self:removeEmptyHeaders()
self:removeEmptyHeaders()
-- error if there is no data/structure given to template from wiki page or wikidata
if ((#self.templateStructure)==0) and not self.args.subtemplate then
local templateTitle = mw.getCurrentFrame():getParent():getTitle()
errors = {}
local templateName = mw.ustring.gsub(templateTitle, 'תבנית:', '', 1)
if mw.title.getCurrentTitle().namespace==0 then
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות בתבנית '..templateName..']]')
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות בתבנית מידע]]')
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות]]' )
else
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות מחוץ למרחב הערכים]]')
end
local report = 'תבנית {{' .. templateName .. '}} ריקה מתוכן. יש להזין פרמטרים בערך או בוויקינתונים. ' .. table.concat(errors, '')
local ParamValidator = require('Module:ParamValidator')
return ParamValidator.wrapReport(report, templateName, {})
end
-- sub infobox
-- sub infobox
if self.args.title == '-' then
if self.args.subtemplate then
self.root:cssText(self.args.tablestyle):css('width', '100%')
self.root:cssText(self.args.tablestyle):css('width', '100%'):css('line-height', '1.4em')
else
else
self.root:addClass('infobox'):css('width', '18em'):cssText(self.args.tablestyle)
self.root:addClass('infobox'):cssText(self.args.tablestyle)
end
end
if self.args.tableclass then
if self.args.tableclass then
שורה 258: שורה 294:
self:renderTitle()
self:renderTitle()
end
end
self:renderImages()
 
if not self.args.subtemplate then
self:renderImages()
end
local infobox_rows={}
local infobox_rows={}
שורה 275: שורה 313:
This function adds image using valueArg, or if not specified by the user tries to get image from wikidata using property
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)
function getValueOrWikidataImage(args)
valueArg = args.valueArg
if valueArg and #valueArg>0 then  
if valueArg and #valueArg>0 then  
if valueArg == '-' then
if valueArg == '-' then
שורה 283: שורה 322:
not mw.ustring.match(valueArg, '^ *%[%[') and  
not mw.ustring.match(valueArg, '^ *%[%[') and  
  not  mw.ustring.match(valueArg, '^ *<') then
  not  mw.ustring.match(valueArg, '^ *<') then
  local imgSuffix = '|220px'
  local imgSuffix = '|'..args.width .. 'px'
  if imgDesc~=nil and #imgDesc>0 then
  if args.imgDesc~=nil and #args.imgDesc>0 then
  imgSuffix = imgSuffix .. '|' .. imgDesc
  imgSuffix = imgSuffix .. '|' .. args.imgDesc
  end
  end
  imgSuffix = imgSuffix .. ']]'
  imgSuffix = imgSuffix .. ']]'
שורה 295: שורה 334:
else
else
valueArg = '[[File:' .. valueArg .. imgSuffix
valueArg = '[[File:' .. valueArg .. imgSuffix
end
elseif args.imgDesc~=nil and #args.imgDesc>0 and not mw.ustring.match(args.imgDesc, '%[%[קטגוריה:ערכים להחלפת תמונה בחופשית%]%]$') then
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 = mw.ustring.gsub(valueArg, "%]%]$", "")
mw.log(args.imgDesc)
local imgSuffix = '|' .. args.imgDesc .. ']]'
valueArg = valueArg .. imgSuffix
end
end
end
end
שורה 300: שורה 349:
end
end
end
end
if wikidataArg then  
if args.wikidataArg and args.args.entityId~=nil then  
return propertyLink.getImageLink(wikidataArg, width)
args.args.usingWikidata = true
return propertyLink.getImageLink(args.wikidataArg, args.width, nil, nil,nil, args.args.entityId)
end
end
return ''
return ''
שורה 307: שורה 357:
end
end


--[[
Split category links from value, return tuple of whether data exists and maitainance cats in case no data exists
]]
function splitMaintainceCategory(value)
function splitMaintainceCategory(value)
local maintainceCats = nil
local maintainceCats = nil
שורה 314: שורה 367:
end
end
return hasData, maintainceCats
return hasData, maintainceCats
end
function getPropertyByOptions( propertyName, entityId, options )
if propertyName == nil or #propertyName == 0 then
return nil
end
local res = propertyLink.getPropertyByOptions(propertyName, entityId, options)
if (res==nil) or (#res == 0) then
return nil
end
local hasData, maintainceCats = splitMaintainceCategory(res)
if hasData then
local link = mw.title.makeTitle( 0, entityId, propertyName, 'wikidata' ):fullUrl('uselang=he')
res = res .. mw.ustring.format(' [[File:Blue pencil RTL.svg|15px|link=%s|עריכת הנתון בוויקינתונים]]', link)
end
return res
end
--[[
Filters statements to statements with existing links only
]]
function filterExists( propertyVals )
local tempVals = {}
    for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    if propValue and propValue.value then
    local linkTarget = mw.wikibase.sitelink( propValue.value['id'] )
if linkTarget then
table.insert(tempVals, property)
end
end
end
return tempVals
end
end


שורה 319: שורה 408:
This function fills missing parameter using wikidata
This function fills missing parameter using wikidata
]]
]]
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, frame)
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, entityId, frame)
local inWikidata = false
local inWikidata = false
local hasData=false
local hasData=false
local maintainceCats = nil
local maintainceCats = nil
local propertyName = nil
local includeWikidataRef = frame and frame:getParent()
if entityId == nil then return inWikidata, maintainceCats end -- early terminate
includeWikidataRef = includeWikidataRef and includeWikidataRef.args and includeWikidataRef.args['ויקינתונים-מקורות'] == 'כן'
local wikidataOptions = {
['entity-gender-aware'] =  templateParams[missingParam..'-ויקינתונים-מגדר'] == 'כן',
['source'] = includeWikidataRef
}
if templateParams[missingParam..'-ויקינתונים-סינון'] == 'קיים' then
wikidataOptions['filter'] = filterExists
elseif templateParams[missingParam..'-ויקינתונים-סינון'] and mw.ustring.match(templateParams[missingParam..'-ויקינתונים-סינון'], 'filter[a-zA-Z]+') then
local moduleTitle = mw.ustring.match( frame:getParent():getTitle(), 'תבנית:(.+)' )
moduleTitle = mw.ustring.format('יחידה:%s', moduleTitle)
local filterFunc = mw.ustring.match(templateParams[missingParam..'-ויקינתונים-סינון'],'filter[a-zA-Z]+')
wikidataOptions['filter'] = require(moduleTitle)[filterFunc]
end
if templateParams[missingParam..'-ויקינתונים-פרטים']~=nil then
wikidataOptions['qualifiers'] = {}
wikidataOptions['qualifiers-sep'] = templateParams[missingParam..'-ויקינתונים-פרטים-הפרדה'] or nil
for v in string.gmatch(templateParams[missingParam..'-ויקינתונים-פרטים'], "[^,%s]+") do
    table.insert(wikidataOptions['qualifiers'], v)
end
end
if templateParams[missingParam..'-ויקינתונים-תמונה-גודל']~=nil then
wikidataOptions['img-width'] = templateParams[missingParam..'-ויקינתונים-תמונה-גודל']
end
if templateParams[missingParam..'-ויקינתונים'] then
if templateParams[missingParam..'-ויקינתונים'] then
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים']) or nil
if templateParams[missingParam..'-ויקינתונים-יחידה'] then
templateArg.data = require('Module:Convert').convert(mw.getCurrentFrame():newChild{ args = {
['input'] = templateParams[missingParam..'-ויקינתונים'],
[2] = templateParams[missingParam..'-ויקינתונים-יחידה'],
['disp'] = 'out',
['qid'] = entityId,
['abbr']='off'
} }:newChild{})
else
templateArg.data = getPropertyByOptions(templateParams[missingParam..'-ויקינתונים'], entityId,  wikidataOptions) or nil
end
inWikidata = templateArg.data and #(templateArg.data)>0
inWikidata = templateArg.data and #(templateArg.data)>0
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
local genderAware = templateParams[missingParam..'-ויקינתונים-מגדר'] == 'כן'
wikidataOptions['allowMulti'] = true
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים-מרובה'], true, false, nil, templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה'], templateParams[missingParam..'-ויקינתונים-פרטים'], genderAware) or nil
wikidataOptions['seperator'] = templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה']
wikidataOptions['sort'] = templateParams[missingParam..'-ויקינתונים-מרובה-מיון'] or nil
paramsData = {}
-- split multiple params to include all of them (e.g: "P1,P2")
for paramToFetch in string.gmatch(templateParams[missingParam..'-ויקינתונים-מרובה'], '([^,]+)') do
-- split optional params to include ONLY the first one of them (e.g: "P1/P2")
for optionalParam in string.gmatch(paramToFetch, '([^/]+)') do
if (string.sub(optionalParam, 1, 1) == 'P' or string.sub(optionalParam, 1, 1) == 'Q') then
if getPropertyByOptions(optionalParam, entityId, wikidataOptions) then
table.insert(paramsData, getPropertyByOptions(optionalParam, entityId,  wikidataOptions) or nil)
-- found one of the optionals - stop the loop
break
end
else
-- one of the optionals is static data - take it and stop the loop
table.insert(paramsData, optionalParam)
break
end
end
end
templateArg.data = table.concat(paramsData, wikidataOptions['seperator'])
inWikidata = templateArg.data and #(templateArg.data)>0
inWikidata = templateArg.data and #(templateArg.data)>0
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then
elseif 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..'-ויקינתונים-פשוט'], entityId)
if wikidataParamValue and #wikidataParamValue>0 then
if wikidataParamValue and #wikidataParamValue>0 then
templateArg.data = frame:preprocess(mw.ustring.gsub(templateArg.data, '\{\{\{('..missingParam..')\}\}\}', wikidataParamValue))
templateArg.data = frame:preprocess(mw.ustring.gsub(templateArg.data, '\{\{\{('..missingParam..')\}\}\}', wikidataParamValue))
inWikidata = true
inWikidata = true
end
end
-- special cases
elseif missingParam == 'קואורדינטות' then
elseif missingParam == 'קואורדינטות' then
templateArg.data = frame:expandTemplate{ title = 'קואורדינטות מוויקינתונים', args = { display = 'title,inline' } }
templateArg.data = propertyLink.getPropertyByOptions('P625', entityId, {['coord-display'] = templateParams['קואורדינטות-תצוגה'] or 'title,inline' })
inWikidata = templateArg.data and #(templateArg.data)>0
inWikidata = templateArg.data and #(templateArg.data)>0
elseif  missingParam == 'מפה' and templateParams['מפה-זום'] then
inWikidata = (#mw.wikibase.getBestStatements(entityId, 'P625'))>0
if inWikidata then
local defaultZoom = templateParams['מפה-זום']
templateArg.data = frame:expandTemplate{ title = 'מפה דינמית', args = {
['יישור'] = 'center',
['זום ברירת מחדל'] = defaultZoom,
['פריטים'] = entityId
} }
end
end
end
if inWikidata then
if inWikidata then
hasData, maintainceCats = splitMaintainceCategory(templateArg.data)
hasData, maintainceCats = splitMaintainceCategory(templateArg.data)
if hasData then
if not hasData then
propertyName=templateParams[missingParam..'-ויקינתונים'] or templateParams[missingParam..'-ויקינתונים-מרובה'] or templateParams[missingParam..'-ויקינתונים-פשוט']
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
inWikidata = false
maintainceCats = maintainceCats
maintainceCats = maintainceCats
שורה 358: שורה 510:
end
end


--[[
This function fills missing parameter using wikidata
]]
function crossValidateWikidata(missingParam, templateParams, templateArg, frame, entityId)
local matching = nil
local propertyName
if entityId == nil or missingParam==nil then
return nil
end
if templateParams[missingParam..'-ויקינתונים'] then
propertyName = templateParams[missingParam..'-ויקינתונים']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then
propertyName = templateParams[missingParam..'-ויקינתונים-פשוט']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
local genderAware = templateParams[missingParam..'-ויקינתונים-מגדר'] == 'כן'
propertyName =  templateParams[missingParam..'-ויקינתונים-מרובה']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
end
if matching then
return WikidataCrossValidation.maintainceCategory(matching, propertyName)
end
end
--[[
If template doesn't specify title parameter, the default is name (fallback by title) + origin name (fallback by wikidata)
]]
function standardTitle(templateArgs, isSubTemplate, entityId)
local name = templateArgs['שם']
if name=='-' then return name end --
if isSubTemplate then return name or '' end
if not name or #name==0 then --fallback to title
name = mw.title.getCurrentTitle().text
    name = mw.ustring.gsub(name, " *[(].*[)]","")
end
local originName = templateArgs['שם בשפת המקור']
if originName == '-' then
originName = ''
else
-- use wikidata as fallback
if (not originName or #originName==0) and entityId~=nil then
local propertyVals = mw.wikibase.getBestStatements(entityId, 'P1705')
if #propertyVals == 0 then propertyVals = mw.wikibase.getBestStatements(entityId, 'P1476') end
if #propertyVals == 0 then propertyVals = mw.wikibase.getBestStatements(entityId, 'P1559') end
if #propertyVals > 0 then
local propValue = propertyVals[1].mainsnak and propertyVals[1].mainsnak.datavalue
if  propValue and propValue.value and propValue.value.text and propValue.value.text~=name then
originName = mw.ustring.format('<span lang="%s" title="%s">%s</span>', propValue.value.language,
        mw.language.fetchLanguageName( propValue.value.language , 'he'), propValue.value.text)
    end
end
end
if originName and #originName and originName~=name then
name = name..'<br>'..originName
end
end
return name
end


function Infobox:parseArgs(frame)
function Infobox:parseArgs(frame)
שורה 365: שורה 583:
local args={}
local args={}
local templateStructure = {}
local templateStructure = {}
args.subtemplate = frame.args['תת-תבנית']
args.entityId = templateArgs['qid'] or templateParams['qid'] or mw.wikibase.getEntityIdForCurrentPage()
-- disable wikidata fetching
if args.entityId == '' or args.entityId == '-' then args.entityId = nil end
args.title = frame.args['כותרת תבנית'] or standardTitle(templateArgs, args.subtemplate, args.entityId)
if args.title=='-' then args.subtemplate = true end
args.titlestyle = templateParams['כותרת תבנית-עיצוב']
args.titleclass = templateParams['כותרת תבנית-מחלקה']
args.subtitle = templateParams['תת כותרת תבנית']
args.subtitlestyle = templateParams['תת כותרת תבנית-עיצוב']
args.subtitleclass = templateParams['תת כותרת תבנית-מחלקה']
args.rightImage = getValueOrWikidataImage{
valueArg=templateParams['תמונה ימין'],
wikidataArg=templateParams['תמונה ימין-ויקינתונים'],
width='100x80',
args=args
}
args.rightImageDesc = templateParams['כיתוב ימין']
args.leftImage = getValueOrWikidataImage{
valueArg=templateParams['תמונה שמאל'],
wikidataArg=templateParams['תמונה שמאל-ויקינתונים'],
width='100x80',
args=args
}
args.leftImageDesc = templateParams['כיתוב שמאל']
args.imageDesc = templateParams['כיתוב']
if templateParams['תמונה ללא שאיבה אוטומטית'] ==  'כן' then
args.image = getValueOrWikidataImage{
valueArg=templateParams['תמונה'],
wikidataArg=templateParams['תמונה-ויקינתונים'],
width=templateParams['תמונה-גודל'] or '220',
imgDesc=args.imageDesc,
args=args
}
else
args.image = getValueOrWikidataImage{
valueArg=templateParams['תמונה'],
wikidataArg=templateParams['תמונה-ויקינתונים'] or 'P18',
width=templateParams['תמונה-גודל'] or '220',
imgDesc=args.imageDesc,
args=args
}
end
args.removeFirstHeader = false-- default based on vote on 18/7/21
    -- explictly override the default
    if templateParams['כותרת כללית'] ==  'כן' then
args.removeFirstHeader = true
elseif templateParams['כותרת כללית'] ==  'לא' then
args.removeFirstHeader = false
end
args.headerclass = templateParams['כותרת-מחלקה']
args.title = frame.args['כותרת תבנית']
args.headerstyle = templateParams['כותרת-עיצוב']
args.titlestyle = frame.args['כותרת תבנית-עיצוב']
     args.rowsstyle = templateParams['שורה-עיצוב']
args.titleclass = frame.args['כותרת תבנית-מחלקה']
     args.labelstyle = templateParams['תווית-עיצוב']
args.subtitle = frame.args['תת כותרת תבנית']
     args.datastyle = templateParams['מידע-עיצוב']
args.subtitlestyle = frame.args['תת כותרת תבנית-עיצוב']
args.tablestyle = templateArgs['טבלה-עיצוב'] or templateParams['טבלה-עיצוב']
args.subtitleclass = frame.args['תת כותרת תבנית-מחלקה']
args.tableclass = templateArgs['טבלה-מחלקה'] or templateParams['טבלה-מחלקה']
args.rightImage = getValueOrWikidataImage(frame.args['תמונה ימין'], frame.args['תמונה ימין-ויקינתונים'], '100')
local pageNs = mw.title.getCurrentTitle().namespace
args.rightImageDesc = frame.args['כיתוב ימין']
local subpageText = mw.title.getCurrentTitle().subpageText
args.leftImage = getValueOrWikidataImage(frame.args['תמונה שמאל'], frame.args['תמונה שמאל-ויקינתונים'], '100')
local isSelfUse = (pageNs==10 and subpageText ~= "תיעוד")
args.leftImageDesc = frame.args['כיתוב שמאל']
self.autoDocumentation = templateParams['תיעוד-אוטומטי']
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 labelPrefix = 'תווית'
שורה 396: שורה 654:
local rowStyleClassPrefix = 'מחלקה-שורה'
local rowStyleClassPrefix = 'מחלקה-שורה'
local styleSuffix = '-עיצוב'
local styleSuffix = '-עיצוב'
local explicitWikidata = '-ויקינתונים-מפורש'
local k=0
local k=0
local processedParams = {}
local processedParams = {['0']=1} -- param0 may be used by Lua, not be template
local wikidataCats = {}
local wikidataCats = {}
for k,v in pairs(templateParams) do
for k,v in pairs(templateParams) do
שורה 407: שורה 666:
local subHeaderName = templateParams[subheader..i]
local subHeaderName = templateParams[subheader..i]
if subHeaderName and #subHeaderName>0  then --subheader type
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})
table.insert(templateStructure, {header=1,data=subHeaderName,rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], headerstyle=templateParams[subheader..i..styleSuffix], indic=indic})
else
else
local labelName = templateParams[labelPrefix..i]
local labelName = templateParams[labelPrefix..i]
local dataTemplate = templateParams[dataPrefix..i]
local dataTemplate = templateParams[dataPrefix..i]
if dataTemplate then
if dataTemplate then
-- if parameter contains only category with no value, replace with with nil and add teh value to maintaince category
-- if parameter contains only category with no value, replace with with nil and add the value to maintaince category
local hasData, maintainceCats = splitMaintainceCategory(dataTemplate)
local hasData, maintainceCats = splitMaintainceCategory(dataTemplate)
if maintainceCats and not hasData then
if maintainceCats and not hasData then
שורה 433: שורה 692:
labelName = label_data_names
labelName = label_data_names
label_data_names = mw.text.trim(label_data_names, '%[%]')
label_data_names = mw.text.trim(label_data_names, '%[%]')
if templateArgs[label_data_names] and #templateArgs[label_data_names]>0 then
local hasContent = templateArgs[label_data_names] and #templateArgs[label_data_names]>0
-- + and use explicit wikidata replace the content with such if available from wikidata
local isExplicitWikidataParam = templateParams[label_data_names..explicitWikidata]
local isExplicitWikidataEnabled = false
if isExplicitWikidataParam then
isExplicitWikidataEnabled = templateArgs[label_data_names]~=nil and mw.ustring.match(templateArgs[label_data_names], '^ *+$')
end
local skipContent = false
if hasContent and not isExplicitWikidataEnabled then
dataTemplate = templateArgs[label_data_names]
dataTemplate = templateArgs[label_data_names]
else
else
if isExplicitWikidataParam and not isExplicitWikidataEnabled then
skipContent = true
end
dataTemplate = '{{{' ..label_data_names.. '}}}'
dataTemplate = '{{{' ..label_data_names.. '}}}'
end
end
table.insert(templateStructure, {label=labelName, data=dataTemplate, rowstyle=templateParams[rowStylePrefix..i], rowclass=templateParams[rowStyleClassPrefix..i], datastyle=templateParams[dataPrefix..i..styleSuffix],  
if not skipContent then
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})
labelstyle=templateParams[labelPrefix..i..styleSuffix], indic=indic})
end
end
end
end
end
שורה 449: שורה 722:
-- use wikidata / remove unused parameters
-- use wikidata / remove unused parameters
if not isSelfUse then
if not isSelfUse then
local entriesToRemove = {}
local crossValidatedFields = {}
for k,v in pairs(templateStructure) do
for k,v in pairs(templateStructure) do
if v.data then
if v.data then
שורה 454: שורה 730:
local ignoreParam = mw.ustring.match(v.data, '^%-$')
local ignoreParam = mw.ustring.match(v.data, '^%-$')
if ignoreParam then
if ignoreParam then
templateStructure[k]=nil
table.insert(entriesToRemove, 1, k)
else
else
-- otherwise if the template isn't full - try to use wikidata to fill it
-- otherwise if the template isn't full or if there is a Wikidata-beats tag - them try to use wikidata to fill it
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}')
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}')
                    if not m and v.label and templateParams[v.label..'-ויקינתונים-גובר']~=nil then
                        m = templateParams[v.label..'-ויקינתונים-גובר']
                    end
if m then
if m then
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before
local inWikidata, maintainceCats = fillMissingParamFromWikidata(m, templateParams, v, frame)
local inWikidata, maintainceCats = fillMissingParamFromWikidata(m, templateParams, v, args.entityId, frame)
if maintainceCats then
if maintainceCats then
table.insert(wikidataCats, maintainceCats)
table.insert(wikidataCats, maintainceCats)
end
end
-- if data isn't available remove it
if inWikidata then
if inWikidata then
crossValidatedFields[m] = 1
args.usingWikidata = true
args.usingWikidata = true
else
else
templateStructure[k]=nil
-- if data isn't available remove it
table.insert(entriesToRemove, 1, k)
-- no need to cross validate it
crossValidatedFields[m] = 1
end
end
end
end
end
end
end
for k,v in pairs(templateArgs) do
if crossValidatedFields[k]==nil and v and #v>0 and pageNs==0 and k~= 'תמונה' then
local maintainceCats = crossValidateWikidata(k,templateParams, v, frame, args.entityId)
if maintainceCats and #maintainceCats>0 then
table.insert(wikidataCats, maintainceCats)
end
end
end
end
end
end
for k,v in pairs(entriesToRemove) do table.remove(templateStructure, v) end
 
-- use wikidata in title
-- use wikidata in title
if args.title then
if args.title then
שורה 481: שורה 776:
local inWikidata = false
local inWikidata = false
if templateParams[m..'-ויקינתונים'] then
if templateParams[m..'-ויקינתונים'] then
local wikidataParamValue = propertyLink.getProperty(templateParams[m..'-ויקינתונים']) or nil
local wikidataParamValue = getPropertyByOptions(templateParams[m..'-ויקינתונים'], args.entityId) or nil
if wikidataParamValue then
if wikidataParamValue then
args.title = wikidataParamValue
args.title = wikidataParamValue
שורה 495: שורה 790:
end
end
end
end
 
self.args = args
self.args = args
self.templateStructure = templateStructure
self.templateStructure = templateStructure
שורה 510: שורה 805:


return {
return {
['מידע']=infobox
['מידע']=infobox,
Infobox=Infobox
}
}