-- This module creates a warning about sensitive IP addresses that is intended-- to be placed in via the message.
local querySensitiveIPs = require('Module:Sensitive IP addresses').querylocal mIP = require('Module:IP')local IPAddress = mIP.IPAddresslocal 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 nilend
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 querySensitiveIPsend
local function parseSensitivityData(sensitivityData) -- Parse the data from the sensitive IP API call, and return a table with -- information about the first match that we can use as arguments to a -- template call. local function parse(sensitivityData) sensitivityData = sensitivityData.sensitiveips if #sensitivityData.matches
'ip' then ret.ip = sensitivityData.matches[1].ip elseif ret.type
local success, ret = pcall(parse, sensitivityData) if success and ret then return ret else return nil endend
local function renderMessage(rawMessage, messageArgs) local message if rawMessage then message = mw.message.newRawMessage(rawMessage) else message = mw.message.new('sensitive-ip-block-text') end local wikitext = message:params(messageArgs.type, messageArgs.type
local p =
function p._main(args, title) args = args or title = title or mw.title.getCurrentTitle local ipOrSubnet = parseTitle(title) if not ipOrSubnet then return nil end local sensitivityData = fetchSensitivityData(ipOrSubnet) if not sensitivityData then return nil end local messageArgs = parseSensitivityData(sensitivityData) return renderMessage(args.message, messageArgs)end
function p.main(frame) local args = require('Module:Arguments').getArgs(frame) return p._main(args)end
function p._exportFunctions return end
return p