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

אין תקציר עריכה
מ 20 גרסאות של הדף wikipedia:he:יחידה:תבנית_מידע יובאו
 
(38 גרסאות ביניים של 8 משתמשים אינן מוצגות)
שורה 22: שורה 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
שורה 222: שורה 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
שורה 232: שורה 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
שורה 262: שורה 277:
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות מחוץ למרחב הערכים]]')
table.insert(errors, '[[קטגוריה:שגיאות פרמטריות מחוץ למרחב הערכים]]')
end
end
local report = 'תבנית ריקה מתוכן. יש להזין פרמטרים בערך או בוויקינתונים. ' .. table.concat(errors, '')
local report = 'תבנית {{' .. templateName .. '}} ריקה מתוכן. יש להזין פרמטרים בערך או בוויקינתונים. ' .. table.concat(errors, '')
local ParamValidator = require('Module:ParamValidator')
local ParamValidator = require('Module:ParamValidator')
return ParamValidator.wrapReport(report, templateName, {})
return ParamValidator.wrapReport(report, templateName, {})
שורה 319: שורה 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
שורה 405: שורה 430:
if templateParams[missingParam..'-ויקינתונים-פרטים']~=nil then
if templateParams[missingParam..'-ויקינתונים-פרטים']~=nil then
wikidataOptions['qualifiers'] = { templateParams[missingParam..'-ויקינתונים-פרטים'] }
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
end
if templateParams[missingParam..'-ויקינתונים-תמונה-גודל']~=nil then
if templateParams[missingParam..'-ויקינתונים-תמונה-גודל']~=nil then
שורה 426: שורה 455:
wikidataOptions['allowMulti'] = true
wikidataOptions['allowMulti'] = true
wikidataOptions['seperator'] = templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה']
wikidataOptions['seperator'] = templateParams[missingParam..'-ויקינתונים-מרובה-הפרדה']
templateArg.data = getPropertyByOptions(templateParams[missingParam..'-ויקינתונים-מרובה'], entityId,  wikidataOptions) or nil
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
שורה 444: שורה 492:
if inWikidata then
if inWikidata then
local defaultZoom = templateParams['מפה-זום']
local defaultZoom = templateParams['מפה-זום']
-- TODO: use entityid and dont ignore it
templateArg.data = frame:expandTemplate{ title = 'מפה דינמית', args = {  
templateArg.data = frame:expandTemplate{ title = 'מפה דינמית', args = {  
['יישור'] = 'center',  
['יישור'] = 'center',  
['זום ברירת מחדל'] = defaultZoom
['זום ברירת מחדל'] = defaultZoom,
['פריטים'] = entityId
} }
} }
end
end
שורה 466: שורה 514:
This function fills missing parameter using wikidata
This function fills missing parameter using wikidata
]]
]]
function crossValidateWikidata(missingParam, templateParams, templateArg, frame)
function crossValidateWikidata(missingParam, templateParams, templateArg, frame, entityId)
local matching = nil
local matching = nil
local propertyName
local propertyName
if missingParam==nil then
 
if entityId == nil or missingParam==nil then
return nil
return nil
end
end
if templateParams[missingParam..'-ויקינתונים'] then
if templateParams[missingParam..'-ויקינתונים'] then
propertyName = templateParams[missingParam..'-ויקינתונים']
propertyName = templateParams[missingParam..'-ויקינתונים']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName)
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then
propertyName = templateParams[missingParam..'-ויקינתונים-פשוט']
propertyName = templateParams[missingParam..'-ויקינתונים-פשוט']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName)
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
local genderAware = templateParams[missingParam..'-ויקינתונים-מגדר'] == 'כן'
local genderAware = templateParams[missingParam..'-ויקינתונים-מגדר'] == 'כן'
propertyName =  templateParams[missingParam..'-ויקינתונים-מרובה']
propertyName =  templateParams[missingParam..'-ויקינתונים-מרובה']
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName)
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
end
end
שורה 536: שורה 585:
args.subtemplate = frame.args['תת-תבנית']
args.subtemplate = frame.args['תת-תבנית']
args.entityId = templateArgs['qid'] or templateParams['qid'] or mw.wikibase.getEntityIdForCurrentPage()
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)
args.title = frame.args['כותרת תבנית'] or standardTitle(templateArgs, args.subtemplate, args.entityId)
if args.title=='-' then args.subtemplate = true end
if args.title=='-' then args.subtemplate = true end
שורה 558: שורה 609:
args.leftImageDesc = templateParams['כיתוב שמאל']
args.leftImageDesc = templateParams['כיתוב שמאל']
args.imageDesc = templateParams['כיתוב']
args.imageDesc = templateParams['כיתוב']
args.image = getValueOrWikidataImage{
if templateParams['תמונה ללא שאיבה אוטומטית'] ==  'כן' then
valueArg=templateParams['תמונה'],
args.image = getValueOrWikidataImage{
wikidataArg=templateParams['תמונה-ויקינתונים'] or 'P18',
valueArg=templateParams['תמונה'],
width=templateParams['תמונה-גודל'] or '220',
wikidataArg=templateParams['תמונה-ויקינתונים'],
imgDesc=args.imageDesc,
width=templateParams['תמונה-גודל'] or '220',
args=args
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.headerclass = templateParams['כותרת-מחלקה']
args.headerstyle = templateParams['כותרת-עיצוב']
args.headerstyle = templateParams['כותרת-עיצוב']
שורה 573: שורה 643:
args.tableclass = templateArgs['טבלה-מחלקה'] or templateParams['טבלה-מחלקה']
args.tableclass = templateArgs['טבלה-מחלקה'] or templateParams['טבלה-מחלקה']
local pageNs = mw.title.getCurrentTitle().namespace
local pageNs = mw.title.getCurrentTitle().namespace
local isSelfUse = (pageNs==10)
local subpageText = mw.title.getCurrentTitle().subpageText
local isSelfUse = (pageNs==10 and subpageText ~= "תיעוד")
self.autoDocumentation = templateParams['תיעוד-אוטומטי']
self.autoDocumentation = templateParams['תיעוד-אוטומטי']


שורה 583: שורה 654:
local rowStyleClassPrefix = 'מחלקה-שורה'
local rowStyleClassPrefix = 'מחלקה-שורה'
local styleSuffix = '-עיצוב'
local styleSuffix = '-עיצוב'
local explicitWikidata = '-ויקינתונים-מפורש'
local k=0
local k=0
local processedParams = {['0']=1} -- param0 may be used by Lua, not be template
local processedParams = {['0']=1} -- param0 may be used by Lua, not be template
שורה 599: שורה 671:
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
שורה 620: שורה 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
שורה 646: שורה 732:
table.insert(entriesToRemove, 1, k)
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
שורה 665: שורה 754:
end
end
end
end
end
end
end
end
שורה 672: שורה 761:
for k,v in pairs(templateArgs) do
for k,v in pairs(templateArgs) do
if crossValidatedFields[k]==nil and v and #v>0 and pageNs==0 and k~= 'תמונה' then
if crossValidatedFields[k]==nil and v and #v>0 and pageNs==0 and k~= 'תמונה' then
local maintainceCats = crossValidateWikidata(k,templateParams, v, frame)
local maintainceCats = crossValidateWikidata(k,templateParams, v, frame, args.entityId)
if maintainceCats and #maintainceCats>0 then
if maintainceCats and #maintainceCats>0 then
table.insert(wikidataCats, maintainceCats)
table.insert(wikidataCats, maintainceCats)