Content deleted Content added
reorganise example output lines |
m change source to syntaxhighlight |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1:
{{Module rating|protected}}
{{Used in system}}
This module provides an API for information about [[WP:SIP|IP addresses that Wikipedia considers sensitive]]. The intention is that this one API can be used for templates, Lua modules, and software using the [[mw:API:Main page|MediaWiki Action API]] such as JavaScript gadgets and bots.
Line 11 ⟶ 13:
To load this module from Lua modules, use:
<
local querySensitiveIPs = require('Module:Sensitive IP addresses/API').query
</syntaxhighlight>
The query function is called with named parameters. For example:
<
local result = querySensitiveIPs{
test = {'1.2.3.4', '5.6.7.8'}
}
</syntaxhighlight>
== Parameters ==
Line 39 ⟶ 41:
The top level object contains exactly one child object. If the query executed successfully, this object has a key of <code>sensitiveips</code> and contains the query results.
<
{
"sensitiveips": {
Line 45 ⟶ 47:
}
}
</syntaxhighlight>
If there were any errors when executing the query, the child of the top-level object has a key of <code>error</code> and contains error information. The error object has three keys: <code>code</code>, the error ID; <code>info</code>, the error message; and <code>*</code>, a message about where to find the API documentation. The error IDs all have a prefix of "sipa". For example:
<
{
"error": {
Line 57 ⟶ 59:
}
}
</syntaxhighlight>
=== Sensitive IPs object ===
Line 91 ⟶ 93:
* <code>name</code> - the name of the entity. This is a plain string, containing no wikitext, and is always present.
* <code>description</code> - a description of the entity. This is a string, and may contain wikitext. This field is optional, and may not be present.
* <code>reason</code> - the reason that the entity's IP ranges are sensitive. The possible reasons are <code>{{#invoke:Sensitive IP addresses/API|_getSensitivityReasons|</code>, <code>|</code> and <code>}}</code>.
* <code>ipv4-ranges</code> - 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.
* <code>ipv6-ranges</code> - 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.
Line 102 ⟶ 105:
Query:
<
querySensitiveIPs{
test = {'1.2.3.4'}
}
</syntaxhighlight>
Result:
<
{
["sensitiveips"] = {
}
}
</syntaxhighlight>
=== One match ===
Query:
<
querySensitiveIPs{
test = {'156.33.5.76'}
}
</syntaxhighlight>
Result:
<
{
["sensitiveips"] = {
Line 149 ⟶ 152:
["id"] = "ussenate",
["name"] = "United States Senate",
["description"] = "the [[United States Senate]]",
["reason"] = "political",
["ipv4Ranges"] = {
Line 165 ⟶ 168:
},
}
</syntaxhighlight>
=== One match, JSON output ===
Line 171 ⟶ 174:
Query:
Query:
<
querySensitiveIPs{
format = 'json',
test = {'156.33.5.76'}
}
</syntaxhighlight>
Result:
<
{
"sensitiveips":{
Line 202 ⟶ 205:
"id": "ussenate",
"name": "United States Senate",
"description": "the [[United States Senate]]",
"reason": "political",
"ipv6Ranges": [
Line 218 ⟶ 221:
}
}
</syntaxhighlight>
=== Entity IDs ===
<
querySensitiveIPs{
format = 'json',
entities = {'usdhs', 'usdoj'}
}
</syntaxhighlight>
Result:
<
{
"sensitiveips": {
Line 237 ⟶ 240:
"id": "usdoj",
"name": "United States Department of Justice",
"description": "the [[United States Department of Justice]]",
"reason": "political",
"ipv4Ranges": [
Line 246 ⟶ 249:
"id": "usdhs",
"name": "United States Department of Homeland Security",
"description": "the [[United States Department of Homeland Security]]",
"reason": "political",
"ipv4Ranges": [
Line 261 ⟶ 264:
}
}
</syntaxhighlight>
=== Invalid IP error ===
Query:
<
querySensitiveIPs{
test = {'foo'}
}
</syntaxhighlight>
Result:
<
{
["error"] = {
Line 281 ⟶ 284:
}
}
</syntaxhighlight>
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
|