Module:Sensitive IP addresses/API/doc

This module provides an API for information about IP addresses that Wikipedia considers sensitive. The intention is that this one API can be used for templates, Lua modules, and software using the MediaWiki Action API such as JavaScript gadgets and bots.

From templates
Templates wishing to make use of this API need to use an intermediary Lua module to parse the results of API queries. One such module, used to create a wikitable summary of sensitive IPs, exists at Module:Sensitive IP addresses/summary.

From Lua
To load this module from Lua modules, use:

The query function is called with named parameters. For example:

Parameters
The following parameters are available to the query function:


 * - an array of IP addresses and/or IP ranges to test for sensitivity. IP addresses and ranges can be IPv4 or IPv6, and ranges must be in CIDR notation.
 * - an array of entity IDs to get information about. An entity is a country or organization which is considered sensitive, and for which blocks should be handled with care. Entity IDs are defined in Module:Sensitive IP addresses/list along with the rest of the sensitive IP data. For example,  is the ID for the United States House of Representatives. If the special ID   is contained in the array, information about all entities will be included in the result.
 * - the format to return results in. Use  to return a JSON-formatted string, and use   to return a Lua table. If this option is not specified, a Lua table is returned by default.

Results
By default, the query function returns a Lua table, but it can return a JSON object if the  option is set to. Whether Lua or JSON, the structure of the object returned is similar to the structure of query results from the MediaWiki Action API.

Top-level object
The top level object contains exactly one child object. If the query executed successfully, this object has a key of  and contains the query results.

If there were any errors when executing the query, the child of the top-level object has a key of  and contains error information. The error object has three keys:, the error ID;  , the error message; and  , a message about where to find the API documentation. The error IDs all have a prefix of "sipa". For example:

Sensitive IPs object
If the query was successful, the  child object will be present and can contain the following objects and arrays:
 * - an array of IP address objects or IP range objects, where the corresponding IP address or IP range string was specified in the  query option, and where Wikipedia regards that IP address or IP range as being sensitive. If no IPs or ranges were tested for, or if no matches were found, this array will not be present in the results.
 * - an object with CIDR IP range strings as keys, and matched-range objects as values, where the IP range matches one of the IP addresses or IP ranges tested for with the  query option. If no IPs or ranges were tested for, or if no matches were found, this object will not be present.
 * - an object with entity IDs as keys, and entity objects as values. An entity is a country or organization which has IP addresses that Wikipedia considers sensitive. Entity IDs are defined in Module:Sensitive IP addresses/list; for example,  is the ID for the United States House of Representatives. Entities will be included in this object if an IP range belonging to them is matched by one of the IP addresses or IP ranges tested for with the   query option, or if their entity ID is specified in the   query option.
 * - an array of entity ID strings, in the order they are defined in Module:Sensitive IP addresses/list. The entity IDs in this array correspond one-to-one with the entity ID keys of the  result object. This array can be useful for outputting the IDs in the same order that they were defined in the list.

IP address objects
An IP address object represents a single IPv4 or IPv6 address that matches a sensitive IP range. IP address objects contain the following fields:
 * - the string representation of the IP address, e.g. "1.2.3.4" or "2001:d8::ffff:ab:cdef".
 * - the string "ip" (used to differentiate between IP address objects and IP range objects).
 * - the version of the IP protocol the address uses. This is either "IPv4" or "IPv6".
 * - the sensitive IP range that the address matches, in CIDR notation.
 * - the entity ID of the entity that owns the sensitive IP range that the address matches.

IP range objects
An IP range object represents an IPv4 or IPv6 range that overlaps with a sensitive IP range. IP range objects contain the following fields:
 * - the CIDR string representation of the range, e.g. "1.2.3.0/24" or "2001:d8::ffff:ab:0/16".
 * - the string "range" (used to differentiate between IP range objects and IP address objects).
 * - the version of the IP protocol the range uses. This is either "IPv4" or "IPv6".
 * - the sensitive IP range that the tested range overlaps, in CIDR notation.
 * - the entity ID of the entity that owns the sensitive IP range that the tested range overlaps.

Entity objects
An entity object represents a country or organization that has IP ranges which Wikipedia considers sensitive. Entity objects may contain the following fields:
 * - the entity ID. This is a unique string used to identify the entity. This field is always present.
 * - the name of the entity. This is a plain string, containing no wikitext, and is always present.
 * - a description of the entity. This is a string, and may contain wikitext. This field is optional, and may not be present.
 * - the reason that the entity's IP ranges are sensitive. The possible reasons are,   and.
 * - an array of IPv4 CIDR strings that belong to the entity, and are considered as sensitive by Wikipedia. This field is optional, and may not be present.
 * - an array of IPv6 CIDR strings that belong to the entity, and are considered as sensitive by Wikipedia. This field is optional, and may not be present.
 * - notes about the entity or its ranges. This field is optional, and may not be present.

Examples
Here are some examples of some queries from Lua and the results they produce.

No matches
Query:

Result:

One match
Query:

Result:

One match, JSON output
Query: Query:

Result:

Entity IDs
Result:

Invalid IP error
Query:

Result: