Extension:WikiLambda/API
This page is part of the MediaWiki Action API documentation. |
The WikiLambda extension has a simple API to search and fetch WikiFunctions content and retrieve it in different formats and after different transformations.
The internal API endpoints are modules and submodules of MediaWiki Action API. You can make requests, explore the examples and see the results in the MediaWiki API Sandbox.
This document only describes APIs reserved for internal use. For external APIs, consult the Wikifunctions Public API documentation in the API Portal.
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
wikilambda_edit
[edit]This API allows to create/edit persisted ZObject pages in Wikifunctions. The API expects the parameter zobject
to be a valid JSON representation of the ZObject in its canonical form.
To create a new ZObject, the parameter zid
must be omitted, and Wikifunctions will find and assign the next available ZID. Also, the keys from the JSON ZObject that refer to its identity (for example, Z2K1
or the values of Z4K1
and Z3K2
), must be set to the Null Reference (Z0
).
To edit an existing ZObject, the parameter zid
must have the ZID of the ZObject to edit (which will be the same one as the internal identity keys).
Documentation
[edit]Method: GET
Action: wikilambda_edit
Request: api.php? action=wikilambda_edit & format=json & summary=<SUMMARY> & zid=<ZID> & zobject=<URL_ENCODED_JSON_OBJECT>
Response:
{
"wikilambda_edit": {
"success": "",
"articleId": 1096,
"title": "Z10001",
"page": "Z10001"
}
}
Parameters
[edit]name | description |
---|---|
summary
required | string |
Summary message for the edit.
E.g. |
zid
optional | string |
ZID of the ZObject to edit. In case of creating a new ZObject, the field must be empty.
E.g. |
zobject
required | string |
JSON representation of the ZObject to be saved, in canonical form. If it's a new ZObject to be saved, the self-referential keys must be replaced by Z0 instead of the ZID. For example Z2K1 and Z4K1 must take the value of Z0, and the key IDs must be Z0K1, Z0K2, etc.
E.g. |
token
required | string |
CSRF token |
Possible Errors
[edit]This API can return a wide variety of errors, because the provided ZObject is parsed and validated against the canonical schemata. All the validation errors will be wrapped in a error of type Z502
. Apart from the validation errors, Wikifunctions can detect a variety of problems described below.
error name | error type (Z50) | description |
---|---|---|
Validation error | Z502
|
The given ZObject is not well formed. The error body will contain the nested sub-errors that better describe the problem. For more information about nesting of validation error, read the Representation of errors page in meta. |
Invalid page title | Z556
|
The given ZID is an invalid page title and could not be created. |
Unmatching ZID and page title | Z555
|
The given ZID and the content of the self-referential keys (E.g. Z2K1) does not match. |
User does not have permission to edit | Z557
|
The user is not logged in or does not have the required permissions to create or edit pages. |
Disallowed root type | Z553
|
The ZPersistentObject or ZObject passed as the value of the zobject parameter is disallowed from being saved directly as a page. Disallowed ZObjects are Z3/Key, Z5/Error, Z16/Code, Z17/Argument declaration, Z18/Argument reference and Z39/Key reference.
|
Disallowed root type | Z553
|
The ZPersistentObject or ZObject passed as the value of the zobject parameter is disallowed from being saved directly as a page. Disallowed ZObjects are Z3/Key, Z5/Error, Z16/Code, Z17/Argument declaration, Z18/Argument reference and Z39/Key reference.
|
Label clash | Z554
|
The given label for a language clashes with another ZObject's label in that language. |
Examples
[edit]- api.php? action=wikilambda_edit & format=json & summary=<SUMMARY> & zobject=urlencode(ZOBJECT) & token=%2B\
- Where ZOBJECT is:
{ "Z1K1": "Z2", "Z2K1": "Z0", "Z2K2": "zobject value", "Z2K3": { "Z1K1": "Z12", "Z12K1": [{ "Z1K1": "Z11", "Z11K1": "Z1002", "Z11K2": "zobject label" }] } }
- Creates and saves a new ZObject in the database (empty values) and returns the newly assigned ZID.
- api.php? action=wikilambda_edit & format=json & summary=Edit zobject & zid=Z10004 & zobject=urlencode(ZOBJECT) & token=%2B\
- Where ZOBJECT is:
{ "Z1K1": "Z2", "Z2K1": { "Z1K1": "Z6", "Z6K1": "Z10004" }, "Z2K2": "new zobject value", "Z2K3": { "Z1K1": "Z12", "Z12K1": [{ "Z1K1": "Z11", "Z11K1": "Z1002", "Z11K2": "new zobject label" }] } }
- Edits the ZObject with title Z10004 and overwrites it with the given JSON ZObject.
wikilambda_function_call
[edit]One of the entrypoints to the Wikifunctions orchestration and evaluation back-end. This API receives a required JSON formatted ZObject and sends it to the function-orchestrator services for it to be evaluated and returned. Hence, the ZObject sent must be a Z7/Function call.
Documentation
[edit]Method: GET
Action: wikilambda_function_call
Request: api.php? action=wikilambda_function_call & format=json & wikilambda_function_call_zobject=<URL_ENCODED_JSON_FUNCTION>
Response:
{
"query": {
"wikilambda_function_call": {
"Orchestrated": {
"success": "",
"data": "{\"Z1K1\":\"Z22\",\"Z22K1\":{\"Z1K1\":\"Z40\",\"Z40K1\":\"Z42\"},\"Z22K2\":\"Z23\"}"
}
}
}
}
Parameters
[edit]name | description |
---|---|
wikilambda_function_call_zobject
required | string |
JSON representation of the ZObject to send for its execution
E.g. |
Possible Errors
[edit]Describe function-orchestrator and evaluator most probable errors
error name | error type (Z50) | description |
---|---|---|
Connection error | (TODO) | Unable to connect to the function orchestrator service. |
Validation error | Z502
|
The given function call is not well formed. The error body will contain the nested sub-errors that better describe the problem. For more information about nesting of validation error, read the Representation of errors page in meta. |
Zid not found | Z504
|
One of the Type ZIDs from the objects involved in the function call cannot be found and hence cannot be validated. |
Argument type mismatch | Z506
|
The type of an argument instantiated in the function call does not match with its function argument definition. |
Error in evaluation | Z507
|
Something happened during the execution step which raised an error. The returned value of this error will also include the error propagated from the function evaluator and/or executor services. |
Argument value error | Z516
|
One of the arguments passed to a built-in function had a wrong value or type. |
Return type mismatch | Z517
|
The type returned by a function call does not match the expected type from that function definition. |
Object type mismatch | Z518
|
One of the arguments passed to the function call cannot be processed or their type evaluated. |
Unexpected ZObject type | Z542
|
(TODO) Currently this is Z539
The ZObject passed as |
Examples
[edit]- api.php? action=wikilambda_function_call & format=json & wikilambda_function_call_zobject=<URL_ENCODED_JSON_FUNCTION>
- Where the function is:
{ "Z1K1": "Z7", "Z7K1": "Z802", "Z802K1": { "Z1K1": "Z40", "Z40K1": "Z42" }, "Z802K2": ["arbitrary ZObject"], "Z802K3": { "Z1K1": "Z40", "Z40K1": "Z42" } }
- Requests the execution of the function with ZID Z802 (built-in function
If(condition, then, else)
), where the value ofZ802K1/Condition
isZ42/False
. The expected result is to be returned the value ofZ802K3/Else
. The returned result, as expected: { "query": { "wikilambda_function_call": { "Orchestrated": { "success": "", "data": "{\"Z1K1\":\"Z22\",\"Z22K1\":{\"Z1K1\":\"Z40\",\"Z40K1\":\"Z42\"},\"Z22K2\":\"Z23\"}" } } } }
- Observe what happens when, instead of passing
Z42/False
as the condition, we passZ41/True
: { "query": { "wikilambda_function_call": { "Orchestrated": { "success": "", "data": "{\"Z1K1\":\"Z22\",\"Z22K1\":[\"arbitrary ZObject\"],\"Z22K2\":\"Z23\"}" } } } }
wikilambda_perform_test
[edit]This is an internal API endpoint to query test results for a ZFunction. Accepts a Z8/Function
, a list of Z14/Implementations
, and a list of Z20/Testers
. Accepts a ZID for the ZFunction, and a list of either ZIDs or full JSON ZObjects for the ZImplementations and ZTesters.
If a test result is up-to-date in the results database cache, it will be retrieved from there. Otherwise, the test will be run by a call to the WikiFunctions orchestrator.
In addition, under certain conditions this API reorders the implementations of the given function and updates the function's Z8K4/implementations
property in persistent storage. The reordering indicates increasing average execution times of the orchestrator (and possibly other backend services) in running the ZTesters. Reordering only involves the function's currently attached ZImplementations and ZTesters. For reordering to occur, the requested ZImplementations / ZTesters must either be blank or a superset of currently attached ZImplementations / ZTesters, and there must be no results retrieved from the cache.
Documentation
[edit]Method: GET
Action: wikilambda_perform_test
Request: api.php? action=wikilambda_perform_test & format=json & wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_zimplementations=Z913 & wikilambda_perform_test_ztesters=Z8130
Response:
{
"query": {
"wikilambda_perform_test": [
{
"zFunctionId": "Z813",
"zImplementationId": "Z913",
"zTesterId": "Z8130",
"testMetadata": "...",
"validateStatus": "..."
}
]
}
}
Parameters
[edit]name | description |
---|---|
wikilambda_perform_test_zfunction
required | string |
String ZID of the Z8/Function to test.
E.g. |
wikilambda_perform_test_zimplementations
optional | string |
Valid JSON representation of a list of Z14/Implementation objects. Each object can be either a canonical reference (ZID to that implementation), a literal Z14/Implementation object, or a literal Z2/Persistent object wrapping a Z14/Implementation.
E.g. If blank, all associated implementations will be run. |
wikilambda_perform_test_ztest
optional | string |
Valid JSON representation of a list of Z20/Tester objects. Each object can be either a canonical reference (ZID to that tester), a literal Z20/Tester object, or a literal Z2/Persistent object wrapping a Z20/Tester.
E.g. If blank, all associated testers will be run. |
Possible Errors
[edit]If an error occurs when evaluating a given ZTester's Z20K2, this error will be found in the "errors" entry of the returned "testMetadata". The error may be of any sort returned by wikilambda_function_call
. If an error occurs when evaluating Z20K3, this will be found in the "validateErrors" entry.
Other errors this API method may return:
error name | description |
---|---|
wikilambda-performtest-error-unknown-zid | No object found with the ZID provided for the ZFunction, or the ZID provided for one of the given ZImplementations or ZTesters. |
wikilambda-performtest-error-nonfunction | The ZID provided for the ZFunction does not refer to an object of that type. |
wikilambda-performtest-error-nonimplementation | The ZID provided for a ZImplementation does not refer to an object of that type. |
wikilambda-performtest-error-nontester | The ZID provided for a ZTester does not refer to an object of that type. |
Examples
[edit]- api.php? action=wikilambda_perform_test & format=json & wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_zimplementations=Z913 & wikilambda_perform_test_ztesters=Z8130
- Requests running ZTester Z8130 on ZFunction Z813, with Z813 implemented by ZImplementation Z913.
- api.php? action=wikilambda_perform_test & format=json & wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_zimplementations=Z913
- Requests running all available ZTesters for ZFunction Z813, with Z813 implemented by Z913.
- api.php? action=wikilambda_perform_test & format=json&wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_ztesters=Z8130
- Requests running ZTester Z8130 on ZFunction Z813, with Z813 implemented by each of its available ZImplementations in turn.
- api.php? action=wikilambda_perform_test & format=json & wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_zimplementations=<URL_ENCODED_JSON_ZIMPLEMENTATION> & wikilambda_perform_test_ztesters=Z8130
- Requests running ZTester Z8130 on ZFunction Z813, with Z813 implemented by the ZImplementation encoded in URL_ENCODED_JSON_ZIMPLEMENTATION. Where URL_ENCODED_JSON_ZIMPLEMENTATION is
{ "Z1K1": "Z14", "Z14K1": "Z813", "Z14K3": { "Z1K1": "Z16", "Z16K1": { "Z1K1": "Z61", "Z61K1": "javascript" }, "Z16K2": "function Z813( Z813K1 ) {\n return Z813K1.length === 0;\n}" } }
- api.php? action=wikilambda_perform_test & format=json&wikilambda_perform_test_zfunction=Z813 & wikilambda_perform_test_zimplementations=Z913 & wikilambda_perform_test_ztesters=<URL_ENCODED_JSON_ZTESTER>
- Requests running the ZTester encoded in URL_ENCODED_JSON_ZTESTER on ZFunction Z813, with Z813 implemented by ZImplementation Z913. Where URL_ENCODED_JSON_ZTESTER is:
{ "Z1K1": "Z20", "Z20K1": "Z813", "Z20K2": { "Z1K1": "Z7", "Z7K1": "Z813", "Z813K1": [ "Z1" ] }, "Z20K3": { "Z1K1": "Z7", "Z7K1": "Z844", "Z844K2": { "Z1K1": "Z40", "Z40K1": "Z41" } } }
wikilambdaload_zobjects
[edit]Similarly to the wikilambda_fetch
API detailed below, this API returns an aggregation of ZObject pages from Wikifunctions. This API is a list submodule of the action=query API and is dedicated to extension-wide internal requests. The return format is an array with the valid JSON representation of the ZObjects requested. It provides different parameters to configure the type of format to serialize the ZObjects to (either normal or canonical form) and the language for the object labels.
Documentation
[edit]Method: GET
Action: query
List: wikilambdaload_zobjects
Request: api.php? action=query & format=json & list=wikilambdaload_zobjects & wikilambdaload_zids=Z111|Z112 & wikilambdaload_language=en & wikilambdaload_canonical=1
Response:
{
"batchcomplete": "",
"query": {
"wikilambdaload_zobjects": {
"Z111": {
"success": "",
"data": {
"Z1K1": "Z2",
"Z2K1": "Z111"
}
},
"Z112": {
"success": "",
"data": {
"Z1K1": "Z2",
"Z2K1": "Z112"
}
}
}
}
}
Parameters
[edit]name | description |
---|---|
wikilambdaload_zids
required | string |
List of ZObject Identifiers (ZIDs) to fetch, separated by pipes.
E.g. |
wikilambdaload_revisions
optional | string |
List of Revision IDs to fetch, separated by pipes. The number of revision IDs, if set, must be equal to the number of ZIDs above.
E.g. |
wikilambdaload_language
optional | string |
String code for the language in which to return the results. Must be an accepted MediaWiki language code. If not present, the API will return the root label in all available languages.
E.g. |
wikilambdaload_get_dependencies
optional | boolean |
When set to true, returns not only the requested ZObjects, but also the dependency types. These are: for every object of type Type/Z4, the types of all its keys, and for every object of type Function/Z8, the types of all its arguments. The default value is false.
E.g. |
Possible Errors
[edit]Unlike the wikilambda_fetch API, this API can handle errors while still returning the information of the ZObjects that have been found. The returned errors will also be ZObjects of type ZError (Z5). To distinguish between the return of an error in the API execution and the return of a requested ZError object, the response includes the value `success` for each of the requested `ZIDs`.
The possible errors that can be returned for an individual ZID are detailed below.
error name | error type (Z50) | description |
---|---|---|
Invalid ZID | Z549
|
The given ZID is an invalid ZObject ID. This means that it does not follow the expected format of ID starting with the capital letter Z and followed by a natural number. |
ZID not found | Z550
|
The given ZID does not exist in this wiki. |
Examples
[edit]- api.php? action=query & format=json & list=wikilambdaload_zobjects & wikilambdaload_zids=Z1|Z2
- Returns the canonical JSON representation of the ZObjects with ZID
Z1
andZ2
with its labels in all available languages.
- api.php? action=query & format=json & list=wikilambdaload_zobjects & wikilambdaload_zids=Z3|Z4 & wikilambdaload_language=ay
- Returns the canonical JSON representation of the ZObjects with ZIDs
Z3
andZ4
with all its ZMultilingual String (Z12) objects filtered to only return Aymaran labels. If an Aymaran label is not found, it will return those in any of the available fallback languages.
- api.php? action=query & format=json & list=wikilambdaload_zobjects & wikilambdaload_zids=Z6 & wikilambdaload_get_dependencies=true
- Returns the canonical representation of the ZObjects with zid Z802 (the function If), and the dependent type Z40 (which is referred by one of the function argument).
wikilambdasearch_labels
[edit]This API query list generator lets you search ZObjects by their labels or aliases in a given language. It also provides a series of parameters that allow to filter by the ZObject type or by the return type of existing ZFunctions. It principally exists to support the look-ahead search system, and it's generally used in the front-end components that allow the user to search and select persisted ZObjects.
Documentation
[edit]Method: GET
Action: query
List: wikilambdasearch_labels
Request: api.php? action=query & format=json & list=wikilambdasearch_labels & wikilambdasearch_search=join & wikilambdasearch_language=eu & wikilambdasearch_type=Z4 & wikilambdasearch_return_type=Z4 & wikilambdasearch_strict_return_type=true
Response:
{
"batchcomplete": "",
"query": {
"wikilambdasearch_labels": [
{
"page_id": 0,
"page_is_redirect": false,
"page_namespace": 0,
"page_content_model": "zobject",
"page_title": "Z12767",
"page_type": "Z8",
"return_type": null,
"match_label": "join lists",
"match_is_primary": "0",
"match_lang": "Z1002",
"match_rate": 0.4,
"label": "concatenate two untyped lists",
"type_label": "Function"
},
]
}
}
Parameters
[edit]name | description |
---|---|
wikilambdasearch_search
required | string |
The search term to find in all the present labels.
E.g. |
wikilambdasearch_language
required | string |
String code for the language in which to return the results. Must be an accepted MediaWiki language code. If the labels aren't present for this language, use fallback languages.
E.g. |
wikilambdasearch_nofallback
optional | boolean (default=false) |
Whether to search only in the given language and not its fallback languages. If set to true, it will ignore the fallback languages and only search in the requested language.
E.g. |
wikilambdasearch_exact
optional | boolean (default=false) |
Whether to search for exact matches. If disabled, input will be taken as a case-insensitive, Unicode-normalised search with accents on Latin characters ignored.
E.g. |
wikilambdasearch_type
optional | string |
Restrict matches to a specific type of ZObject. If present, the search term will only be matched against the labels of ZObjects of the specified type. This is particularly useful for UI components such as the Type selector, which autocompletes a search input with only available ZType (Z4) objects.
E.g. |
wikilambdasearch_return_type
optional | string |
Restrict matches to ZFunctions that can return the given type, including those who return a generic ZObject. If present, the search term will only be matched against the labels of the specified type. If present along with the wikilambdasearch_type, the results will contain all results matching the type OR the return_type.
E.g. |
wikilambdasearch_strict_return_type
optional | boolean (default=false) |
If the parameter wikilambdasearch_return_type is present, setting this parameter to true will exclude the generic ZObjects from the result and will only return the rows that match strictly the return type passed as a parameter. If the parameter wikilambdasearch_return_type is not set, this value is irrelevant: it will not affect those matches returned by type (parameter wikilambdasearch_type).
E.g. |
wikilambdasearch_limit
optional | integer |
The maximum number of results to return. The value must be between 1 and 5000. Enter max to use the maximum limit.
E.g. |
wikilambdasearch_continue
optional | integer |
When more results are available, use this to continue.
E.g. |
Possible Errors
[edit]None. When nothing is found it will return an empty list.
Examples
[edit]- api.php? action=query & format=json & list=wikilambdasearch_labels & wikilambdasearch_search=ThisLabelDoesNotExist & wikilambdasearch_language=en
- No labels in English match or contain the substring ThisLabelDoesNotExist, so an empty batch is returned.
- api.php? action=query & format=json & list=wikilambdasearch_labels & wikilambdasearch_search=TEX & wikilambdasearch_language=en
- Return every label matching or containing the substring TEX in English. This might ensure that at least two builtin ZObjects will be returned: Z12 "Multilingual text" and Z11 "Monolingual text".
- api.php? action=query & format=json & list=wikilambdasearch_labels & wikilambdasearch_search=TEX & wikilambdasearch_language=en & wikilambdasearch_exact=1
- Return every label matching or containing the exact substring TEX in English. This will not return the two ZObjects returned in the previous example, as this search is case-sensitive.
- api.php? action=query & format=json & list=wikilambdasearch_labels & wikilambdasearch_language=en & wikilambdasearch_return_type=Z40
- Return the English label of every entry that has a ZBoolean (Z40) return type, including those that have a generic ZObject (Z1) return type.
- api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_language=en&wikilambdasearch_return_type=Z40&wikilambdasearch_strict_return_type=true
- Return the English label of every entry that has strictly a ZBoolean (Z40) return type.
wikilambdafn_search
[edit]This API query list searches for the IDs of all ZObjects associated with a provided Z8/Function
ZID and that belong to a given type (either Z14/Implementations
or Z20/Testers
).
Documentation
[edit]Method: GET
Action: query
List: wikilambdafn_search
Request: api.php? action=query & format=json & list=wikilambdafn_search & wikilambdafn_zfunction_id=Z801 & wikilambdafn_type=Z20
Response:
{
"batchcomplete": "",
"query": {
"wikilambdafn_search": [
"Z8010",
"Z8011",
"Z8012",
"Z8013"
]
}
}
Parameters
[edit]name | description |
---|---|
wikilambdafn_zfunction_id
required | string |
ZID belonging to the function of which we want to retrieve the associated ZObjects.
E.g. |
wikilambdafn_type
required | string |
Type of ZObjects related to the given function that we would like to retrieve. The value of this field is not restricted, although the typical values related to functions would be Z14/Implementation or Z20/Tester.
E.g. |
wikilambdafn_limit
optional | integer |
The maximum number of results to return. The value must be between 1 and 5000. Enter max to use the maximum limit.
E.g. |
wikilambdafn_continue
optional | integer |
When more results are available, use this to continue.
E.g. |
Possible Errors
[edit]None. When nothing is found it will return an empty list.
Examples
[edit]- api.php? action=query & format=json & list=wikilambdafn_search & wikilambdafn_zfunction_id=Z801 & wikilambdafn_type=Z20
- Returns the list of Z20/Testers associated to the function with ZID Z801
- api.php? action=query & format=json & list=wikilambdafn_search & wikilambdafn_zfunction_id=Z801 & wikilambdafn_type=Z14
- Returns the list of Z14/Implementations associated to the function with ZID Z801
wikilambda_supported_programming_languages
[edit]This is an internal API to retrieve the programming languages supported by the back-end evaluator service at the time of running, and so determine which languages to recommend to users on the front end. It takes no parameters.
Documentation
[edit]Method: GET
Action: wikilambda_supported_programming_languages
Request: api.php? action=wikilambda_supported_programming_languages
Response:
{
"query": {
"wikilambda_supported_programming_languages": {
"success": true,
"data": "[\"javascript-es2020\",\"javascript-es2019\",\"javascript-es2018\",\"javascript-es2017\",\"javascript-es2016\",\"javascript-es2015\",\"javascript\",\"python-3-9\",\"python-3-8\",\"python-3-7\",\"python-3\",\"python\"]"
}
}
}
Response content:
[edit]Key | Value | Description |
---|---|---|
success | "true" | "false" | Whether the server responded. |
data | string | An escaped JSON array of the supported programming languages (by internal WikiLambda name). |
Possible Errors
[edit]None, unless the orchestrator back-end service doesn't respond.