Module:Sensitive IP addresses/summary
Appearance
This module generates a wikitable summarizing IP ranges that Wikipedia considers sensitive. It is used by Template:Sensitive IP addresses.
Sample output
IPv4 | IPv6 | Description |
---|---|---|
143.228.0.0/16, 143.231.0.0/16, 137.18.0.0/16, 12.185.56.0/29, 12.147.170.144/28, 74.119.128.0/22 | 2620:0:e20::/46 | the United States House of Representatives |
156.33.0.0/16 | 2620:0:8a0::/48, 2600:803:618::/48 | the United States Senate |
149.101.0.0/16 | 2607:f330::/32 | the United States Department of Justice |
65.165.132.0/24, 204.248.24.0/24, 216.81.80.0/20 | the United States Department of Homeland Security | |
131.132.0.0/14, 131.136.0.0/14, 131.140.0.0/15 | the Canadian Department of National Defence | |
192.197.82.0/24 | the Canadian House of Commons | |
194.60.0.0/18 | the Parliament of the United Kingdom | |
138.162.0.0/16 | the United States Department of the Navy and the United States Marine Corps | |
91.198.174.0/24, 185.15.56.0/22, 198.35.26.0/23, 208.80.152.0/22 | 2620:0:860::/46, 2a02:ec80::/32 | the Wikimedia Foundation |
Usage
{{#invoke:Sensitive IP addresses/summary|table | reason = | rangeseparator = | notes = yes/no | mainheader = | class = | style = | cellstyle = }}
Parameters
reason
- filter the entries by the reason they are sensitive. The available reasons arepolitical
andtechnical
. (optional)rangeseparator
- a custom separator for IP ranges in entries with multiple IP ranges. The default is ", ".notes
- set to "yes" to show the "Notes" column. (optional)mainheader
- A custom header row at the top, spanning the whole width of the table. (optional)class
- custom HTML class for the main<table>...</table>
element. (optional)style
- custom CSS styles for the main<table>...</table>
element. (optional)cellstyle
- custom CSS styles for every<th>...</th>
and<td>...</td>
element. (optional)
local mSIPA_API = require('Module:Sensitive IP addresses/API')
local yesno = require('Module:Yesno')
local p = {}
function p._table(options)
-- Return a wikitext table summarizing all the sensitive IP ranges
-- and the entities they belong to.
-- Set up options
options = options or {}
local separator = options.separator or ', '
local showNotes = yesno(options.notes)
local nColumns = showNotes and 3 or 4
-- Get the entity data
local data = mSIPA_API.query{entities={'all'}}
if data['error'] then
error(string.format('%s: %s', data['error'].code, data['error'].info))
end
-- Make the table root
local root = mw.html.create('table')
if options.class then
root:addClass(options.class)
end
if options.style then
root:cssText(options.style)
end
-- Add main header
if yesno(options.mainheader) then
root:tag('tr'):tag('td')
:attr('colspan', nColumns)
:wikitext(options.mainheader)
end
-- Add column headers
local headerRow = root:tag('tr')
headerRow
:tag('th')
:wikitext('[[IPv4]]')
:done()
:tag('th')
:wikitext('[[IPv6]]')
:done()
:tag('th')
:wikitext('Description')
if showNotes then
headerRow:tag('th'):wikitext('Notes')
end
-- Add data cells
for i, id in ipairs(data.sensitiveips['entity-ids']) do
local entityData = data.sensitiveips.entities[id]
if not options.reason or options.reason == entityData.reason then
local dataRow = root:tag('tr')
dataRow
:tag('td')
:wikitext(entityData.ipv4Ranges
and table.concat(entityData.ipv4Ranges, separator)
or nil
)
:done()
:tag('td')
:wikitext(entityData.ipv6Ranges
and table.concat(entityData.ipv6Ranges, separator)
or nil
)
:done()
:tag('td')
:wikitext(entityData.description or entityData.name)
if showNotes then
dataRow:tag('td'):wikitext(entityData.notes)
end
end
end
return tostring(root)
end
function p.table(frame)
local args = require('Module:Arguments').getArgs()
return p._table(args)
end
return p