From WikiChip
Difference between revisions of "Module:chip"

Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
local origArgs
  
 
function p.add_file_prefix(str)
 
function p.add_file_prefix(str)
Line 24: Line 25:
 
   e:node(right)
 
   e:node(right)
 
   return e   
 
   return e   
 +
end
 +
 +
function has_arg(name)
 +
-- The argument can exist and be empty or not exist at all
 +
return string.len(origArgs[name] or '') > 0
 +
end
 +
 +
function arg(name)
 +
return origArgs[name]
 
end
 
end
  
 
function p.chip(frame)
 
function p.chip(frame)
 +
 +
    if frame == mw.getCurrentFrame() then
 +
        origArgs = frame:getParent().args
 +
    else
 +
        origArgs = frame.args
 +
    end
 +
 +
 
     local infobox = mw.html.create('table')
 
     local infobox = mw.html.create('table')
  
Line 33: Line 51:
  
 
     -- header
 
     -- header
     if frame.args.title then
+
     if has_arg('title') then
 
       infobox
 
       infobox
 
         :tag('tr')
 
         :tag('tr')
Line 39: Line 57:
 
             :attr('class', 'chip-infobox-header')
 
             :attr('class', 'chip-infobox-header')
 
             :attr('colspan', '2')
 
             :attr('colspan', '2')
             :wikitext('[[name::' .. frame.args.title .. ']]')
+
             :wikitext('[[name::' .. arg('title') .. ']]')
 
     end
 
     end
  
 
     -- image
 
     -- image
     if frame.args.image or frame.args.no_image ~= 'true' then
+
     if has_arg('no image') then
       local image = frame.args.image and p.add_file_prefix(frame.args.image) or "File:no photo (ic).svg"
+
      infobox
       local image_size = frame.args.image_size or "200px"  
+
        :tag('tr')
 +
          :tag('td')
 +
            :attr('class', 'chip-infobox-pic')
 +
            :attr('colspan', '2')
 +
            :wikitext('[[File:no photo (ic).svg|link=|200px]]')
 +
elseif has_arg('image') then
 +
       local image = p.add_file_prefix(arg('image'))
 +
       local image_size = has_arg('image size') and arg('image size') or "200px"  
 
       infobox
 
       infobox
 
         :tag('tr')
 
         :tag('tr')
Line 54: Line 79:
  
 
       -- add a caption, if provided
 
       -- add a caption, if provided
       if frame.args.caption then
+
       if has_arg('caption') then
 
         infobox
 
         infobox
 
           :tag('tr')
 
           :tag('tr')
Line 60: Line 85:
 
               :attr('class', 'chip-infobox-pic-caption')
 
               :attr('class', 'chip-infobox-pic-caption')
 
               :attr('colspan', '2')
 
               :attr('colspan', '2')
               :wikitext('[[image capation::' .. frame.args.caption .. ']]')
+
               :wikitext('[[image capation::' .. arg('caption') .. ']]')
 
       end
 
       end
 
     end
 
     end
Line 69: Line 94:
 
      
 
      
 
     -- designer
 
     -- designer
     if frame.args.designer then
+
     if has_arg('designer') then
       local designers = mw.html.create('td'):wikitext('[[designer::' .. frame.args.designer .. ']]')
+
       local designers = mw.html.create('td'):wikitext('[[designer::' .. arg('designer') .. ']]')
 
       for i = 2, 10 do
 
       for i = 2, 10 do
       if not frame.args['designer_' .. i] then break end
+
       if not has_arg('designer ' .. i) then break end
       designers:wikitext(', [[designer::' .. frame.args['designer_' .. i] .. ']][[category:microprocessor models by ' .. mw.ustring.lower(frame.args['designer_' .. i]) .. ']]')
+
       designers:wikitext(', [[designer::' .. arg('designer ' .. i) .. ']]' ..
 +
      '[[category:microprocessor models by ' .. mw.ustring.lower(arg('designer ' .. i)) .. ']]')
 
       end
 
       end
 
     infobox:node(p.add_entry('Designer', designers))
 
     infobox:node(p.add_entry('Designer', designers))
Line 79: Line 105:
 
      
 
      
 
     -- manufacturer
 
     -- manufacturer
     if frame.args.manufacturer then
+
     if has_arg('manufacturer') then
       local manufacturers = mw.html.create('td'):wikitext('[[manufacturer::' .. frame.args.manufacturer .. ']]')
+
       local manufacturers = mw.html.create('td'):wikitext('[[manufacturer::' .. arg('manufacturer') .. ']]')
 
       for i = 2, 10 do
 
       for i = 2, 10 do
 
       if not frame.args['manufacturer_' .. i] then break end
 
       if not frame.args['manufacturer_' .. i] then break end
       manufacturers:wikitext(', [[manufacturer::' .. frame.args['manufacturer_' .. i] .. ']][[category:microprocessor models by ' .. mw.ustring.lower(frame.args['manufacturer_' .. i]) .. ']]')
+
       manufacturers:wikitext(', [[manufacturer::' .. arg('manufacturer ' .. i) .. ']]' ..
 +
      '[[category:microprocessor models by ' .. mw.ustring.lower(arg('manufacturer ' .. i)) .. ']]')
 
       end
 
       end
 
     infobox:node(p.add_entry('Manufacturer', manufacturers))
 
     infobox:node(p.add_entry('Manufacturer', manufacturers))
Line 89: Line 116:
 
 
 
-- model number
 
-- model number
if frame.args.model_number then
+
if has_arg('model number') then
  infobox:node(p.add_entry('Model Number', mw.html.create('td'):wikitext('[[model number::' .. frame.args.model_number .. ']]')))
+
  infobox:node(p.add_entry('Model Number', mw.html.create('td'):wikitext('[[model number::' .. arg('model number') .. ']]')))
 
end
 
end
 
      
 
      
 
     -- part number
 
     -- part number
     if frame.args.part_number then
+
     if has_arg('part number') then
       local parts = mw.html.create('td'):wikitext('[[part number::' .. frame.args.part_number .. ']]')
+
       local parts = mw.html.create('td'):wikitext('[[part number::' .. arg('part number') .. ']]')
 
       for i = 1, 10 do
 
       for i = 1, 10 do
       if not frame.args['part_number_' .. i] then break end
+
       if not has_arg('part number ' .. i) then break end
       parts:wikitext(', [[part number::' .. frame.args['part_number_' .. i] .. ']]')
+
       parts:wikitext(', [[part number::' .. arg('part number ' .. i) .. ']]')
 
       end
 
       end
 
     infobox:node(p.add_entry('Part Number', parts))
 
     infobox:node(p.add_entry('Part Number', parts))
Line 104: Line 131:
 
      
 
      
 
     -- s-spec
 
     -- s-spec
     if frame.args.s_spec or frame.args.s_spec_qs then
+
     if has_arg('s spec') or has_arg('s spec qs') then
 
       local parts = mw.html.create('td')
 
       local parts = mw.html.create('td')
       if frame.args.s_spec then
+
       if has_arg('s spec') then
 
         parts:wikitext('[[s-spec::' .. frame.args.s_spec .. ']]')
 
         parts:wikitext('[[s-spec::' .. frame.args.s_spec .. ']]')
 
         for i = 2, 30 do
 
         for i = 2, 30 do
Line 113: Line 140:
 
         end
 
         end
 
       end
 
       end
       if frame.args.s_spec_qs then
+
       if has_arg('s spec qs') then
       if frame.args.s_spec then
+
       if has_arg('s spec') then
 
         parts:wikitext('<br>')
 
         parts:wikitext('<br>')
 
   end
 
   end
         parts:wikitext('[[s-spec (qs)::' .. frame.args.s_spec_qs .. ']] ([[qualification sample|QS]])')
+
         parts:wikitext('[[s-spec (qs)::' .. arg('s spec qs') .. ']] ([[qualification sample|QS]])')
 
         for i = 2, 30 do
 
         for i = 2, 30 do
         if not frame.args['s_spec_qs_' .. i] then break end
+
         if not has_arg('s spec qs ' .. i) then break end
         parts:wikitext(', [[s-spec (qs)::' .. frame.args['s_spec_qs_' .. i] .. ']]')
+
         parts:wikitext(', [[s-spec (qs)::' .. arg('s spec qs ' .. i) .. ']]')
 
         end
 
         end
 
       end
 
       end
Line 127: Line 154:
 
 
 
-- market segment
 
-- market segment
     if frame.args.market then
+
     if has_arg('market') then
       local markets = mw.html.create('td'):wikitext('[[market segment::' .. frame.args.market .. ']]')
+
       local markets = mw.html.create('td'):wikitext('[[market segment::' .. arg('market') .. ']]')
 
       for i = 2, 5 do
 
       for i = 2, 5 do
       if not frame.args['market_' .. i] then break end
+
       if not has_arg('market ' .. i) then break end
       markets:wikitext(', [[market segment::' .. frame.args['market_' .. i] .. ']]')
+
       markets:wikitext(', [[market segment::' .. arg('market ' .. i) .. ']]')
 
       end
 
       end
 
     infobox:node(p.add_entry('Market', markets))
 
     infobox:node(p.add_entry('Market', markets))
Line 137: Line 164:
 
 
 
-- release date
 
-- release date
if frame.args.first_launched or frame.args.first_announced then
+
if has_arg('first launched') or has_arg('first announced') then
 
  local release = mw.html.create('td')
 
  local release = mw.html.create('td')
  if frame.args.first_announced then
+
  if has_arg('first announced') then
    release:wikitext('[[first launched::' .. frame.args.first_announced .. ']] (announced)')
+
    release:wikitext('[[first launched::' .. arg('first announced') .. ']] (announced)')
 
  end
 
  end
  if frame.args.first_launched then
+
  if has_arg('first launched') then
  if frame.args.first_announced then
+
  if has_arg('first announced') then
 
    release:wikitext('<br>')
 
    release:wikitext('<br>')
 
   end
 
   end
    release:wikitext('[[first launched::' .. frame.args.first_launched .. ']] (launch)')
+
    release:wikitext('[[first launched::' .. arg('first launched') .. ']] (launched)')
 
  end
 
  end
 
  infobox:node(p.add_entry('Release', release))
 
  infobox:node(p.add_entry('Release', release))
Line 152: Line 179:
 
 
 
-- EOL
 
-- EOL
if frame.args.last_order or frame.args.last_shipment then
+
if has_arg('last order') or has_arg('last shipment') then
 
  local release = mw.html.create('td')
 
  local release = mw.html.create('td')
 
  if frame.args.last_order then
 
  if frame.args.last_order then
    release:wikitext('[[last order::' .. frame.args.last_order .. ']] (last order)')
+
    release:wikitext('[[last order::' .. arg('last order') .. ']] (last order)')
 
  end
 
  end
  if frame.args.last_shipment then
+
  if has_arg('last shipment') then
  if frame.args.last_order then
+
  if has_arg('last order') then
 
    release:wikitext('<br>')
 
    release:wikitext('<br>')
 
   end
 
   end
    release:wikitext('[[last shipment::' .. frame.args.last_shipment .. ']] (last order)')
+
    release:wikitext('[[last shipment::' .. arg('last shipment') .. ']] (last shipment)')
 
  end
 
  end
 
  infobox:node(p.add_entry('End-of-life', release))
 
  infobox:node(p.add_entry('End-of-life', release))
Line 167: Line 194:
 
 
 
-- release price
 
-- release price
if frame.args.release_price then
+
if has_arg('release price') then
  infobox:node(p.add_entry('Release Price', mw.html.create('td'):wikitext('[[release price::' .. frame.args.release_price .. ']]')))
+
  infobox:node(p.add_entry('Release Price', mw.html.create('td'):wikitext('[[release price::' .. arg('release price') .. ']]')))
 
end
 
end
  

Revision as of 14:09, 7 June 2017

To add this template, simple add
{{chip}}
to the page and save. The chip infobox will have a small [Edit Values] button at the top-right corner which can be used to add values using a form.
local p = {}
local origArgs

function p.add_file_prefix(str)
  if string.match(string.lower(str), '^file:') then
    return str
  else
    return 'File:' .. str
  end
end

function p.add_separator(title)
  return mw.html.create('tr')
           :tag('td')
           :attr('class', 'chip-infobox-sep')
           :attr('colspan', '2')
           :wikitext(title)
end

function p.add_entry(value, right)
  local e = mw.html.create('tr')
  e:tag('th')
    :attr('class', 'chip-infobox-entry')
    :wikitext(value)
  e:node(right)
  return e   
end

function has_arg(name)
	-- The argument can exist and be empty or not exist at all
	return string.len(origArgs[name] or '') > 0
end

function arg(name)
	return origArgs[name]
end

function p.chip(frame)
	
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame.args
    end
	
	
    local infobox = mw.html.create('table')

    infobox
        :attr('class', 'chip-infobox')

    -- header
    if has_arg('title') then
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-header')
            :attr('colspan', '2')
            :wikitext('[[name::' .. arg('title') .. ']]')
    end

    -- image
    if has_arg('no image') then
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-pic')
            :attr('colspan', '2')
            :wikitext('[[File:no photo (ic).svg|link=|200px]]')
	elseif has_arg('image') then
      local image = p.add_file_prefix(arg('image'))
      local image_size = has_arg('image size') and arg('image size') or "200px" 
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-pic')
            :attr('colspan', '2')
            :wikitext('[[image::' .. image .. '| ]][[' .. image .. '|' .. image_size .. ']]')

      -- add a caption, if provided
      if has_arg('caption') then
        infobox
          :tag('tr')
            :tag('td')
              :attr('class', 'chip-infobox-pic-caption')
              :attr('colspan', '2')
              :wikitext('[[image capation::' .. arg('caption') .. ']]')
      end
    end

    -- ####################################################################
    -- some general info first
    infobox:node(p.add_separator('General Info'))
    
    -- designer
    if has_arg('designer') then
      local designers = mw.html.create('td'):wikitext('[[designer::' .. arg('designer') .. ']]')
      for i = 2, 10 do
      	if not has_arg('designer ' .. i) then break end
      	designers:wikitext(', [[designer::' .. arg('designer ' .. i) .. ']]' ..
      		'[[category:microprocessor models by ' .. mw.ustring.lower(arg('designer ' .. i)) .. ']]')
      end
   	  infobox:node(p.add_entry('Designer', designers))
	end
    
    -- manufacturer
    if has_arg('manufacturer') then
      local manufacturers = mw.html.create('td'):wikitext('[[manufacturer::' .. arg('manufacturer') .. ']]')
      for i = 2, 10 do
      	if not frame.args['manufacturer_' .. i] then break end
      	manufacturers:wikitext(', [[manufacturer::' .. arg('manufacturer ' .. i) .. ']]' ..
      		'[[category:microprocessor models by ' .. mw.ustring.lower(arg('manufacturer ' .. i)) .. ']]')
      end
   	  infobox:node(p.add_entry('Manufacturer', manufacturers))
	end
	
	-- model number
	if has_arg('model number') then
	  infobox:node(p.add_entry('Model Number', mw.html.create('td'):wikitext('[[model number::' .. arg('model number') .. ']]')))
	end
    
    -- part number
    if has_arg('part number') then
      local parts = mw.html.create('td'):wikitext('[[part number::' .. arg('part number') .. ']]')
      for i = 1, 10 do
      	if not has_arg('part number ' .. i) then break end
      	parts:wikitext(', [[part number::' .. arg('part number ' .. i) .. ']]')
      end
   	  infobox:node(p.add_entry('Part Number', parts))
	end
    
    -- s-spec
    if has_arg('s spec') or has_arg('s spec qs') then
      local parts = mw.html.create('td')
      if has_arg('s spec') then
        parts:wikitext('[[s-spec::' .. frame.args.s_spec .. ']]')
        for i = 2, 30 do
        	if not frame.args['s_spec_' .. i] then break end
        	parts:wikitext(', [[s-spec::' .. frame.args['s_spec_' .. i] .. ']]')
        end
      end
      if has_arg('s spec qs') then
      	if has_arg('s spec') then
      	  	parts:wikitext('<br>')
  		end
        parts:wikitext('[[s-spec (qs)::' .. arg('s spec qs') .. ']] ([[qualification sample|QS]])')
        for i = 2, 30 do
        	if not has_arg('s spec qs ' .. i) then break end
        	parts:wikitext(', [[s-spec (qs)::' .. arg('s spec qs ' .. i) .. ']]')
        end
      end
   	  infobox:node(p.add_entry('S-Spec', parts))
	end
	
	-- market segment
    if has_arg('market') then
      local markets = mw.html.create('td'):wikitext('[[market segment::' .. arg('market') .. ']]')
      for i = 2, 5 do
      	if not has_arg('market ' .. i) then break end
      	markets:wikitext(', [[market segment::' .. arg('market ' .. i) .. ']]')
      end
   	  infobox:node(p.add_entry('Market', markets))
	end
	
	-- release date
	if has_arg('first launched') or has_arg('first announced') then
	  local release = mw.html.create('td')
	  if has_arg('first announced') then
	    release:wikitext('[[first launched::' .. arg('first announced') .. ']] (announced)')
	  end
	  if has_arg('first launched') then
	  	if has_arg('first announced') then
	  	  release:wikitext('<br>')	
  		end
	    release:wikitext('[[first launched::' .. arg('first launched') .. ']] (launched)')
	  end
	  infobox:node(p.add_entry('Release', release))
	end
	
	-- EOL
	if has_arg('last order') or has_arg('last shipment') then
	  local release = mw.html.create('td')
	  if frame.args.last_order then
	    release:wikitext('[[last order::' .. arg('last order') .. ']] (last order)')
	  end
	  if has_arg('last shipment') then
	  	if has_arg('last order') then
	  	  release:wikitext('<br>')	
  		end
	    release:wikitext('[[last shipment::' .. arg('last shipment') .. ']] (last shipment)')
	  end
	  infobox:node(p.add_entry('End-of-life', release))
	end
	
	-- release price
	if has_arg('release price') then
	  infobox:node(p.add_entry('Release Price', mw.html.create('td'):wikitext('[[release price::' .. arg('release price') .. ']]')))
	end

    -- ####################################################################
    -- some general specs
    infobox:node(p.add_separator('General Specs'))
	
	-- family
	if frame.args.family then
	  infobox:node(p.add_entry('Family', mw.html.create('td'):wikitext('[[microprocessor family::' .. frame.args.family .. ']]')))
	end
	
	-- series
	if frame.args.series then
	  infobox:node(p.add_entry('Series', mw.html.create('td'):wikitext('[[microprocessor series::' .. frame.args.series .. ']]')))
	end
	
	-- locked?
	if frame.args.locked then
	  infobox:node(p.add_entry('Locked', mw.html.create('td'):wikitext('[[has unlocked clock multiplier::' .. frame.args.locked .. ']]')))
	end
    
    -- frequency
    if frame.args.frequency then
      local frequencies = mw.html.create('td'):wikitext('[[base frequency::' .. frame.args.frequency .. ']]')
      for i = 2, 10 do
      	if not frame.args['frequency_' .. i] then break end
      	frequencies:wikitext(', [[base frequency::' .. frame.args['frequency_' .. i] .. ']]')
      end
   	  infobox:node(p.add_entry('Frequency', frequencies))
	end
    
    -- turbo frequency
    if frame.args.turbo_frequency then
      local turbo = mw.html.create('td')
      for i = 1, 30 do
      	--sometimes turbo is not specified for odd-cores, so skip 2 each time, so we can't break
        --if not frame.args['turbo_frequency' .. i] then break end
        if frame.args['turbo_frequency' .. i] then
        	local s = i > 1 and 's' or ''
        	local br = i > 1 and ',<br>' or ''
      	  turbo:wikitext(br .. ' [[turbo frequency (' .. i .. ' core' .. s .. ')::' .. frame.args['turbo_frequency' .. i] .. '| ]]' ..
      	    frame.args['turbo_frequency' .. i] .. ' (' .. i .. ' core' .. s .. ')')
      	end
      end
   	  infobox:node(p.add_entry('Turbo Frequency', turbo))
	end
	
	-- bus type
	if frame.args.bus_type then
	  infobox:node(p.add_entry('Bus type', mw.html.create('td'):wikitext('[[bus type::' .. frame.args.bus_type .. ']]')))
	end
	
	-- bus speed
	if frame.args.bus_speed then
	  infobox:node(p.add_entry('Bus speed', mw.html.create('td'):wikitext('[[bus speed::' .. frame.args.bus_speed .. ']]')))
	end
	
	-- bus rate
	if frame.args.bus_rate then
		local links = ''
	  if frame.args.bus_links then
	    links = '[[bus links::' .. frame.args.bus_links .. ']]&nbsp;×&nbsp;'
	  end
	  infobox:node(p.add_entry('Bus rate', mw.html.create('td'):wikitext(links .. '[[bus rate::' .. frame.args.bus_rate .. ']]')))
	end
	
	-- clock mult
	if frame.args.clock_multiplier then
	  infobox:node(p.add_entry('Clock multiplier', mw.html.create('td'):wikitext('[[clock multiplier::' .. frame.args.clock_multiplier .. ']]')))
	end
	
	-- CPUID
    if frame.args.cpuid then
      local cpuid = mw.html.create('td'):wikitext('[[cpuid::' .. frame.args.cpuid .. ']]')
      for i = 2, 10 do
      	if not frame.args['cpuid_' .. i] then break end
      	cpuid:wikitext(', [[cpuid::' .. frame.args['cpuid_' .. i] .. ']]')
      end
   	  infobox:node(p.add_entry('CPUID', cpuid))
	end

    -- ####################################################################
    -- some general info first
    infobox:node(p.add_separator('Microarchitecture'))
	
	-- ISA
    if frame.args.isa or frame.args.isa_family then
      local isa = mw.html.create('td'):wikitext('[[isa::' .. frame.args.isa .. ']]')
      for i = 2, 10 do
      	if not frame.args['isa_' .. i] then break end
      	isa:wikitext(', [[isa::' .. frame.args['isa_' .. i] .. ']]')
      end
      if frame.args.isa_family then
        isa:wikitext('&nbsp;([[isa family::' .. frame.args.isa_family .. ']])')
  	  end
   	  infobox:node(p.add_entry('ISA', isa))
	end
	
	-- microarch
    if frame.args.microarch then
      local microarchs = mw.html.create('td'):wikitext('[[microarchitecture::' .. frame.args.microarch .. ']]')
      for i = 2, 10 do
      	if not frame.args['microarch_' .. i] then break end
      	microarchs:wikitext(', [[microarchitecture::' .. frame.args['microarch_' .. i] .. ']]')
      end
   	  infobox:node(p.add_entry('µarch', microarchs))
	end

    return infobox
end

return p