Extension:ParsoidBatchAPI

ParsoidBatchAPI provides an API module which Parsoid uses to more efficiently communicate with MediaWiki. This reduces the amount of MediaWiki CPU time that Parsoid uses.

Configuration parameters

 * $wgParsoidBatchAPI_AllowedIPs : An array of IP ranges in CIDR notation which specify which clients allowed to use the API. By default, all IP addresses are allowed.

API description
Post to api.php with action=parsoid-batch and formatversion=2. The only module parameter is "batch", which is set to a JSON-encoded batch specification. The batch specification consists of an array of item parameters. The return value consists of an array, with the result of each item in each corresponding array element.

Without formatversion=2, it is possible for array elements to go missing due to modification by the API output stage, which would lose the correspondence with input items.

The "action" parameter is required and may be:

parse
Transform the specified wikitext to HTML, and return the HTML and some other items from ParserOutput which are useful to Parsoid.

Parameters:
 * title : The context title
 * text : The wikitext

Return value:
 * text : The HTML
 * modules : An array of RL module names, from ParserOutput::getModules
 * modulescripts : An array of RL module scripts, from ParserOutput::getModuleScripts
 * modulestyles : An array of RL module stylesheets, from ParserOutput::getModuleStyles
 * categories : An array of categories, formatted in the same way as the MW core API module action=parse. Each array element is an object, with the "*" element containing the category name, and the "sortkey" element containing the sort key.

preprocess
Run the specified text through the preprocessor, and return the resulting text as well as some other items from ParserOutput which are useful to Parsoid.

Parameters:
 * title : The context title
 * text : The wikitext

Return value:
 * wikitext : The expanded wikitext
 * categories : An array of categories, formatted in the same way as the MW core API module action=parse. Each array element is an object, with the "*" element containing the category name, and the "sortkey" element containing the sort key.
 * properties: An array of properties, from ParserOutput::getProperties, formatted as in the MW core API module action=expandtemplates. Each array element is an object, with the "*" element containing the property value, and the "name" element containing the property name.
 * modulescripts : An array of RL module scripts, from ParserOutput::getModuleScripts
 * modulestyles : An array of RL module stylesheets, from ParserOutput::getModuleStyles
 * categories : An array of categories, formatted in the same way as the MW core API module action=parse. Each array element is an object, with the "*" element containing the category name, and the "sortkey" element containing the sort key.

imageinfo
Parameters:
 * filename : The filename, not including namespace prefix
 * txopts : Optional. An object containing transform parameters to pass through to File::transform. If this is omitted, a source width transform will be done, including rendering if required by File::mustRender.

If the file is not found, the return value will be null. Otherwise it will be an object as follows.

Return value:
 * width : The width of the source file, as given by File::getWidth
 * height : The height of the source file, as given by File::getHeight
 * thumberror : Optional. If there was a transform error, this will be set to the error text.
 * thumburl : Optional. The URL of the transform output, from MediaTransformOutput::getUrl. For images this is the thumbnail URL, but for audio files it will be a useless icon URL.
 * thumbwidth : Optional. The width of the transformed file from MediaTransformOutput::getWidth.
 * thumbheight : Optional. The height of the transformed file from MediaTransformOutput::getHeight.

Note that the thumbwidth and thumbheight parameters are directly from the MTO object, they not modified in the case of a client-side transformation as they are in the MW core action=imageinfo. So they refer to the width and height of the intended client-side display, not the width and height of the image pointed to by thumburl. This is the correct behaviour for Parsoid.

Example
curl -w\\n 'http://example.com/api.php' \ -F action=parsoid-batch               \ -F format=json                        \ -F formatversion=2                    \ -F 'batch=[{"action":"parse","title":"Foo","text":"hello"}]'

Returns: