Module:Sensitive IP addresses/summary
Appearance
![]() | This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
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 |
---|---|---|
12.147.170.144/28, 12.185.56.0/29, 74.119.128.0/22, 137.18.0.0/16, 143.228.0.0/16, 143.231.0.0/16 | 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 |
165.119.0.0/16, 198.137.240.0/23, 204.68.207.0/24 | 2620:10F:B000::/40 | the Executive Office of the President of the United States |
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 | 2600:400::/32 | 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 |
45.79.106.114/32 | 2600:3c01::f03c:93ff:fe24:db1b/128 | dashboard.wikiedu.org OAuth application, maintained by Wiki Education Foundation |
192.0.2.0/24 | RFC 5737 reserved test range |
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
local mainHeader = root:tag('tr'):tag('td')
mainHeader:attr('colspan', nColumns)
local mainHeaderText = '[[Wikipedia:Blocking IP addresses#Sensitive IP addresses|Sensitive IP addresses]]'
if yesno(options.rangecalculator) then
mainHeaderText = mainHeaderText .. ' ([http://www.subnet-calculator.com/cidr.php IPv4 range calculator] - [http://www.gestioip.net/cgi-bin/subnet_calculator.cgi IPv6 range calculator])'
end
if options.mainheaderrule then
mainHeaderText = mainHeaderText .. '\n<hr style="margin: 4px 0;" />'
end
mainHeader:wikitext(mainHeaderText)
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(frame, {
wrappers = 'Template:Sensitive IP addresses'
})
return p._table(args)
end
return p