Module:Sensitive IP addresses/blocktext
Appearance
-- This module creates a warning about sensitive IP addresses that is intended
-- to be placed in [[Special:Block]] via the [[Mediawiki:Blockiptext]] message.
local querySensitiveIPs = require('Module:Sensitive IP addresses').query
local mIP = require('Module:IP')
local IPAddress = mIP.IPAddress
local Subnet = mIP.Subnet
local function normalizeIPOrSubnet(ipOrSubnet)
-- Normalize an IP address or subnet.
-- If ipOrSubnet is not a valid IP address or subnet, returns nil.
local ipSuccess, ipObj = pcall(IPAddress.new, ipOrSubnet)
if ipSuccess and ipObj then
return tostring(ipObj)
end
local subnetSuccess, subnetObj = pcall(Subnet.new, ipOrSubnet)
if subnetSuccess and subnetObj then
return tostring(subnetObj)
end
return nil
end
local function parseTitle(title)
-- Parse a title. If the subpage(s) of the root page are a valid IP
-- address or subnet, then return the normalized IP address or subnet.
local ipOrSubnet = title.text:gsub('^.-/', '')
return normalizeIPOrSubnet(ipOrSubnet)
end
local function fetchSensitivityData(ipOrSubnet)
return querySensitiveIPs{test = {ipOrSubnet}}
end
local function generateMessage(sensitivityData)
end
local p = {}
function p._main(args, title)
if not title then
title = mw.title.getCurrentTitle()
end
local ipOrSubnet = parseTitle(title)
if not ipOrSubnet then
return nil
end
return generateMessage(fetchSensitivityData(ipOrSubnet))
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return p._main(args)
end
function p._exportFunctions()
return {
parseTitle = parseTitle,
fetchSensitivityData = fetchSensitivityData,
}
end
return p