From WikiChip
Editing User talk:David
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.
Latest revision | Your text | ||
Line 109: | Line 109: | ||
<source lang="Lua"> | <source lang="Lua"> | ||
− | [...] | + | function append_packaging_data(infobox, arg_name, pdata) |
+ | local package_name = origArgs[arg_name] | ||
+ | if not package_name or package_name == '' then return end | ||
+ | |||
+ | -- Reject unexpected input, esp. smw.ask operators []:|?*~ | ||
+ | -- Should display error msg | ||
+ | if mw.ustring.find(package_name, '[^%w %-+._,/]') then return end | ||
+ | |||
+ | local package_location, info, result = {} | ||
+ | local page_name = package_name | ||
+ | for field in string.gmatch(package_name, "([^,]+),?") do | ||
+ | table.insert(package_location, field) | ||
+ | end | ||
+ | if #package_location > 1 then | ||
+ | page_name = package_location[1] .. '/packages/' .. package_location[2] | ||
+ | info = pdata['packages'][package_location[1]][package_location[2]] | ||
+ | end | ||
+ | if mw.smw then | ||
+ | result = mw.smw.ask('[[Category:all ic packages]][[' .. page_name .. ']]' .. | ||
+ | '|?package|?package type|?package pins|?package pitch' .. | ||
+ | '|?package length|?package width|?package height|?socket') | ||
+ | end | ||
+ | local dim_props = {'package length', 'package width', 'package height'} | ||
+ | if type(result) == 'table' and #result >= 1 and result[1]['package'] then | ||
+ | info = result[1] | ||
+ | else | ||
+ | if not info then return end -- should display error msg | ||
+ | page_name = nil | ||
+ | for i, name in ipairs(dim_props) | ||
+ | do info[name] = info.p_size and info.p_size[i] or nil end | ||
+ | end | ||
+ | |||
+ | local function tabled(x) return type(x) == 'table' and x or { x } end | ||
+ | local function show(label, text) | ||
+ | if not text or text == '' then return end | ||
+ | infobox:node(p.add_entry(label, mw.html.create('td'):wikitext(text))) | ||
+ | end | ||
+ | local function param(a) | ||
+ | local prop_names = unpack(a) | ||
+ | local text, sep = '', '' | ||
+ | for i, prop_name in ipairs(tabled(prop_names)) do | ||
+ | local values = info[prop_name] -- single value or table | ||
+ | if values then | ||
+ | local n_values = 0 | ||
+ | for j, value in ipairs(tabled(values)) do | ||
+ | if value and value ~= '' then | ||
+ | if a.set_prop then p.set_val(a.set_prop, value) end | ||
+ | text = text .. sep .. value | ||
+ | sep = a.sep or ', ' | ||
+ | n_values = n_values + 1 | ||
+ | if n_values >= (a.max_values or 1) then break end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | return text | ||
+ | end | ||
+ | local p_type_text, p_type_abbr = param{{'package type', 'p_type'}}, '' | ||
+ | if p_type_text ~= '' and mw.ustring.len(p_type_text) <= 10 then | ||
+ | p_type_abbr = ' (' .. p_type_text .. ')' | ||
+ | p_type_text = '' | ||
+ | end | ||
+ | local p_name = param{{'package', 'p_name'}, set_prop='package', max_values=10} | ||
+ | if p_name ~= '' then | ||
+ | if page_name then p_name = '[[' .. page_name .. '|' .. p_name .. ']]' end | ||
+ | show('Package', p_name .. p_type_abbr) | ||
+ | end | ||
+ | show('Package Type', p_type_text) | ||
+ | show('Dimension', param{dim_props, sep=' × '}) | ||
+ | show('Pitch', param{{'package pitch', 'p_pitch'}, max_values=2, sep=' × '}) | ||
+ | show('Contacts', param{{'package pins', 'p_contacts'}}) | ||
+ | show('Socket', param{{'socket', 'p_socket'}, set_prop='socket', max_values=10}) | ||
+ | end | ||
</source> | </source> | ||
− | Of course it would help if [[Module:package]], which already accepts the required data as parameters, would set corresponding package and socket properties, as below for instance. Note the example adds a missing 'package pitch 2' parameter and limits 'package dimension' to three values rather than ten. The proposed property names were already used in subobjects by templates like [[Template:packages/cavium/fcbga-1217]] invoked by the obsolete Module:chip 'package module' parameter. I would prefer a property 'package contacts' over 'package pins' though. Regrettably most of these properties are currently undefined and default to type Page <span class="plainlinks">([https://en.wikichip.org/w/index.php?title=Special%3AProperties&property=package 1] [https://en.wikichip.org/w/index.php?title=Special%3AProperties&property=socket 2])</span> so they won't display nicely. For another obstacle on Wikichip property page changes do not seem to enter the SMW database voluntarily. Take for instance [[Property:l1$ size]] which requests to be displayed in KiB but shows MiB, or [[Property:integrated gpu execution units]] which is typed as Number but still defaults to Page. Also package properties may not enter the database immediately | + | In the main function: |
+ | <source lang="Lua"> | ||
+ | [...] | ||
+ | -- Packaging | ||
+ | local has_arg_pkg_name = has_arg('package name') or has_arg('package name 1') | ||
+ | if has_arg('package module 1') or has_arg_pkg_name or has_arg('back image') then | ||
+ | p.add_separator(infobox, 'Packaging') | ||
+ | end | ||
+ | |||
+ | if has_arg_pkg_name then | ||
+ | local pdata = require('Module:packaging data') | ||
+ | -- Also accept name, name 2, name 3 for consistency. | ||
+ | append_packaging_data(infobox, 'package name', pdata) | ||
+ | for i = 1, 10 do | ||
+ | append_packaging_data(infobox, 'package name ' .. i, pdata) | ||
+ | end | ||
+ | end | ||
+ | [...] | ||
+ | </source> | ||
+ | |||
+ | Of course it would help if [[Module:package]], which already accepts the required data as parameters, would set corresponding package and socket properties, as below for instance. Note the example adds a missing 'package pitch 2' parameter and limits 'package dimension' to three values rather than ten. The proposed property names were already used in subobjects by templates like [[Template:packages/cavium/fcbga-1217]] invoked by the obsolete Module:chip 'package module' parameter. I would prefer a property 'package contacts' over 'package pins' though. Regrettably most of these properties are currently undefined and default to type Page <span class="plainlinks">([https://en.wikichip.org/w/index.php?title=Special%3AProperties&property=package 1] [https://en.wikichip.org/w/index.php?title=Special%3AProperties&property=socket 2])</span> so they won't display nicely. For another obstacle on Wikichip property page changes do not seem to enter the SMW database voluntarily. Take for instance [[Property:l1$ size]] which requests to be displayed in KiB but still shows MiB, or [[Property:integrated gpu execution units]] which is typed as Number but still defaults to Page. Also package properties may not enter the database immediately, a [[Special:Ask/-5B-5BCategory-3Aall-20ic-20packages-5D-5D/-5B-5Bamd-2Fpackages-2Fsocket_sp5-5D-5D/-3Fpackage/-3Fpackage-20type/-3Fpackage-20pins/-3Fpackage-20pitch/-3Fpackage-20length/-3Fpackage-20width/-3Fpackage-20height/-3Fsocket|manual query]] will show the problem. | ||
<source lang="Lua"> | <source lang="Lua"> | ||
− | [...] | + | [...] |
− | + | p.add_separator(infobox, 'General Info') | |
+ | |||
+ | local function entry(a) | ||
+ | local label, arg_name = unpack(a) | ||
+ | if not has_arg(arg_name) then return end | ||
+ | local function text(i, value) | ||
+ | local prop_name = a.prop_name or arg_name -- {} for none | ||
+ | if type(prop_name) == 'table' then | ||
+ | if i > #prop_name then | ||
+ | if a.print then return a.print(value) end | ||
+ | return value | ||
+ | end | ||
+ | prop_name = prop_name[i] | ||
+ | end | ||
+ | return '[[' .. prop_name .. '::' .. value .. | ||
+ | (a.print and ('| ]]' .. a.print(value)) or ']]') | ||
+ | end | ||
+ | local td = mw.html.create('td'):wikitext(text(1, arg(arg_name))) | ||
+ | for i = 2, (a.max_args or 1) do | ||
+ | local value = origArgs[arg_name .. ' ' .. i] | ||
+ | if not value or value == '' then break end | ||
+ | td:wikitext((a.sep or ', ') .. text(i, value)) | ||
+ | end | ||
+ | if label then infobox:node(p.add_entry(label, td)) end | ||
+ | return td | ||
+ | end | ||
+ | local function link(s) return '[[' .. mw.ustring.lower(s) .. '|' .. s .. ']]' end | ||
+ | |||
+ | local uarch_link | ||
+ | if has_arg('designer') then | ||
+ | uarch_link = function(s) return '[[' .. mw.ustring.lower(arg('designer') .. | ||
+ | '/microarchitectures/' .. s) .. '|' .. s .. ']]' end | ||
+ | local td = entry{nil, 'designer', max_args=10, print=link} | ||
+ | infobox:node(p.add_entry('Designer', td:attr('style', 'width: 99%;'))) | ||
+ | end | ||
− | + | if has_arg('first launched') or has_arg('first announced') then | |
+ | local release, sep = mw.html.create('td'), '' | ||
+ | if has_arg('first announced') then | ||
+ | release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)') | ||
+ | sep = '<br/>' | ||
+ | end | ||
+ | if has_arg('first launched') then | ||
+ | release:wikitext(sep .. '[[first launched::' .. arg('first launched') .. ']] (launched)') | ||
+ | end | ||
+ | infobox:node(p.add_entry('Introduction', release)) | ||
+ | end | ||
− | + | entry{'Market', 'market', max_args=5, prop_name='market segment'} | |
+ | entry{'Microarchitecture', 'microarch', max_args=10, | ||
+ | prop_name='microarchitecture', print=uarch_link} | ||
+ | entry{'Chipset', 'chipset', max_args=10} | ||
+ | entry{'<abbr title="Thermal Design Power">TDP</abbr>', 'tdp', max_args=10} | ||
− | == | + | if has_arg('package name') or has_arg('package type') then |
− | + | p.add_separator(infobox, 'Package') | |
+ | entry{'Name', 'package name', max_args=10, prop_name='package', sep=',<br/>'} | ||
+ | entry{'Type', 'package type'} | ||
+ | entry{'Contacts', 'package contacts', prop_name='package pins'} | ||
+ | entry{'Dimension', 'package dimension', max_args=3, sep=' × ', | ||
+ | prop_name={'package length', 'package width', 'package height'}} | ||
+ | entry{'Pitch', 'package pitch', max_args=2, sep=' × '} | ||
+ | end | ||
− | + | if has_arg('socket name') or has_arg('socket type') then | |
+ | p.add_separator(infobox, 'Socket') | ||
+ | entry{'Name', 'socket name', prop_name='socket', max_args=10, sep=',<br/>'} | ||
+ | entry{'Type', 'socket type', prop_name={}} | ||
+ | end | ||
+ | [...] | ||
+ | </source> | ||
− | + | Kind regards, [[User:QuietRub|QR]] ([[User talk:QuietRub|talk]]) 03:47, 13 March 2023 (EDT) |