Difference between revisions of "Module:Infobox body of water tracking"

From blackwiki
Jump to navigation Jump to search
test>Frietjes
(not what this tracks)
test>Frietjes
Line 21: Line 21:
 
     local args = frame:getParent().args
 
     local args = frame:getParent().args
 
     local AZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
     local AZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 +
    local warnmsg = {}
 
      
 
      
 
     if (isblank(args['image']) and isblank(args['image_lake']) ) then
 
     if (isblank(args['image']) and isblank(args['image_lake']) ) then
Line 35: Line 36:
 
   
 
   
 
     local duplicate_parameters = 0
 
     local duplicate_parameters = 0
 
+
local duplicate_list = {
if (args['child'] and args['embed']) then
+
{'child', 'embed'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'name', 'lake_name'},
    end
+
         {'image', 'image_lake'},
    if (args['name'] and args['lake_name']) then
+
         {'alt', 'alt_lake'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'caption', 'caption_lake'},
    end
+
         {'coordinates', 'coords'},
    if (args['image'] and args['image_lake']) then
+
         {'lake_type', 'type'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'ocean_type', 'type'},
    end
+
         {'lake_type', 'ocean_type'},
    if (args['alt'] and args['alt_lake']) then
+
        {'part_of', 'parent'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'basin_countries', 'countries'},
    end
+
         {'catchment_km2', 'catchment'},
    if (args['caption'] and args['caption_lake']) then
+
         {'length_km', 'length'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'width_km', 'width'},
    end
+
         {'area_km2', 'area'},
    if (args['coordinates'] and args['coords']) then
+
         {'depth_m', 'depth'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'max-depth_m', 'max-depth'},
    end
+
         {'volume_km3', 'volume'},
    if (args['lake_type'] and args['type']) then
+
         {'shore_km', 'shore'},
         duplicate_parameters = duplicate_parameters + 1
+
         {'elevation_m', 'elevation'},
    end
+
         {'settlements', 'cities'},
    if (args['ocean_type'] and args['type']) then
+
        {'extra', 'nrhp'},
         duplicate_parameters = duplicate_parameters + 1
+
        {'extra', 'embedded'},
    end
+
         {'embedded', 'nrhp'}
    if (args['part_of'] and args['parent']) then
+
     }
         duplicate_parameters = duplicate_parameters + 1
+
     for i, params in ipairs(duplicate_list) do
    end
+
    if args[params[1]] and args[params[2]] then
    if (args['basin_countries'] and args['countries']) then
+
    duplicate_parameters = duplicate_parameters + 1
         duplicate_parameters = duplicate_parameters + 1
+
    table.insert(warnmsg, 'Cannot use <code>' .. params[1] .. '</code> and <code>' .. params[2] .. '</code> at the same time.')
    end
+
    end
    if (args['catchment_km2'] and args ['catchment']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['length_km'] and args['length']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['width_km'] and args['width']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['area_km2'] and args['area']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['depth_m'] and args['depth']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['max-depth_m'] and args['max-depth']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['volume_km3'] and args['volume']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['shore_km'] and args['shore']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['elevation_m'] and args['elevation']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['settlements'] and args['cities']) then
 
         duplicate_parameters = duplicate_parameters + 1
 
     end
 
     if (args['extra'] and args['nrhp']) then
 
        duplicate_parameters = duplicate_parameters + 1
 
    end
 
    if (args['extra'] and args['embedded']) then
 
        duplicate_parameters = duplicate_parameters + 1
 
 
     end
 
     end
 
     if (duplicate_parameters > 0) then
 
     if (duplicate_parameters > 0) then
Line 109: Line 75:
 
      
 
      
 
     local no_convert_parameters = 0
 
     local no_convert_parameters = 0
     if hasnoconvert(args['catchment'] or '') then
+
     local dim_list = {
        no_convert_parameters = no_convert_parameters + 1
+
    'catchment', 'length', 'width', 'area', 'depth', 'max-depth', 'volume',
    end
+
    'shore', 'elevation', 'temperature_low', 'temperature_high'}
    if hasnoconvert(args['length'] or '') then
+
for i, param in ipairs(dim_list) do
        no_convert_parameters = no_convert_parameters + 1
+
  if hasnoconvert(args[param] or '') then
    end
+
    no_convert_parameters = no_convert_parameters + 1
    if hasnoconvert(args['width'] or '') then
+
    table.insert(warnmsg, 'Unconverted dimensions in <code>' .. param .. '</code>')
        no_convert_parameters = no_convert_parameters + 1
+
end
    end
+
end
    if hasnoconvert(args['area'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['depth'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['max-depth'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['volume'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['shore'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['elevation'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['temperature_low'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
    if hasnoconvert(args['temperature_high'] or '') then
 
        no_convert_parameters = no_convert_parameters + 1
 
    end
 
 
 
 
     if (no_convert_parameters > 0) then
 
     if (no_convert_parameters > 0) then
         cats = cats .. '[[Category:Pages using infobox body of water with non-automatically converted dimension parameters|' ..
+
         cats = cats .. '[[Category:Pages using infobox body of water with a non-automatically converted dimension|' ..
 
         string.sub(AZ,no_convert_parameters, no_convert_parameters+1) .. ']]'
 
         string.sub(AZ,no_convert_parameters, no_convert_parameters+1) .. ']]'
 
     end
 
     end
 +
   
 +
    if #warnmsg > 0 then
 +
if frame:preprocess( "{{REVISIONID}}" ) == "" then
 +
cats = '<div class="hatnote" style="color:red"><strong>Infobox school warning:</strong> ' .. table.concat(warnmsg, '<br>') .. '</div>' .. cats
 +
end
 +
end
  
 
     return cats
 
     return cats

Revision as of 14:17, 11 October 2018

local p = {}

function p.tracking(frame)
    local function isblank( val ) 
        return (val == nil) or val:match('^[%s]*$')
    end
    
    local function hasnoconvert( val )
    	local res = nil
    	val = mw.text.killMarkers(val)
    	if val:match('[0-9]') then
    		res = 1
    		if val:match('[%(][−0-9%.]') and val:match('[%)]') then
    			res = nil
    		end
		end
		return res
	end
    
    local cats = ''
    local args = frame:getParent().args
    local AZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    local warnmsg = {}
    
    if (isblank(args['image']) and isblank(args['image_lake']) ) then
    	if mw.title.getCurrentTitle().namespace == 0 then
	        cats = cats .. '[[Category:Articles using infobox body of water without image]]'
	    end
    end
    
    if isblank(args['coords']) and isblank(args['coordinates']) then 
    	if mw.title.getCurrentTitle().namespace == 0 then
	        cats = cats .. '[[Category:Articles using infobox body of water without coordinates]]'
	    end
    end
 
    local duplicate_parameters = 0
	local duplicate_list = {
		{'child', 'embed'},
        {'name', 'lake_name'},
        {'image', 'image_lake'},
        {'alt', 'alt_lake'},
        {'caption', 'caption_lake'},
        {'coordinates', 'coords'},
        {'lake_type', 'type'},
        {'ocean_type', 'type'},
        {'lake_type', 'ocean_type'},
        {'part_of', 'parent'},
        {'basin_countries', 'countries'},
        {'catchment_km2', 'catchment'},
        {'length_km', 'length'},
        {'width_km', 'width'},
        {'area_km2', 'area'},
        {'depth_m', 'depth'},
        {'max-depth_m', 'max-depth'},
        {'volume_km3', 'volume'},
        {'shore_km', 'shore'},
        {'elevation_m', 'elevation'},
        {'settlements', 'cities'},
        {'extra', 'nrhp'},
        {'extra', 'embedded'},
        {'embedded', 'nrhp'}
    }
    for i, params in ipairs(duplicate_list) do
    	if args[params[1]] and args[params[2]] then
    		duplicate_parameters = duplicate_parameters + 1
    		table.insert(warnmsg, 'Cannot use <code>' .. params[1] .. '</code> and <code>' .. params[2] .. '</code> at the same time.')
    	end
    end
    if (duplicate_parameters > 0) then
        cats = cats .. '[[Category:Pages using infobox body of water with ' ..
        	'duplicate parameters|' .. 
        	string.sub(AZ, duplicate_parameters, duplicate_parameters+1) .. ']]'
    end
    
    local no_convert_parameters = 0
    local dim_list = {
    	'catchment', 'length', 'width', 'area', 'depth', 'max-depth', 'volume',
    	'shore', 'elevation', 'temperature_low', 'temperature_high'}
	for i, param in ipairs(dim_list) do
	   if hasnoconvert(args[param] or '') then
	     no_convert_parameters = no_convert_parameters + 1
	     table.insert(warnmsg, 'Unconverted dimensions in <code>' .. param .. '</code>')
		end
	end
    if (no_convert_parameters > 0) then
        cats = cats .. '[[Category:Pages using infobox body of water with a non-automatically converted dimension|' ..
        	string.sub(AZ,no_convert_parameters, no_convert_parameters+1) .. ']]'
    end
    
    if #warnmsg > 0 then
		if frame:preprocess( "{{REVISIONID}}" ) == "" then
			cats = '<div class="hatnote" style="color:red"><strong>Infobox school warning:</strong> ' .. table.concat(warnmsg, '<br>') .. '</div>' .. cats
		end
	end

    return cats
end
    
return p