Extension:ParsoidBatchAPI

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
ParsoidBatchAPI
Release status: unmaintained
Implementation API
Description Batch API for Parsoid
Author(s) Tim Starling (WMF)talk
Latest version 1.0.0
MediaWiki 1.25
License Creative Commons Zero v1.0 Universal
Download
  • $wgParsoidBatchAPI_AllowedIPs
Translate the ParsoidBatchAPI extension if it is available at translatewiki.net
Check usage and version matrix.

ParsoidBatchAPI provides an API module which the legacy node Parsoid service could use to more efficiently communicate with MediaWiki. This would reduce the amount of MediaWiki CPU time that Parsoid uses. It is not used for the modern PHP Parsoid library.

Installation[edit]

  • Download and place the file(s) in a directory called ParsoidBatchAPI in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'ParsoidBatchAPI' );
    
  • In Parsoid's config.yaml, add:
useBatchAPI: true
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration parameters[edit]

$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[edit]

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[edit]

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[edit]

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[edit]

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[edit]

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:

{"parsoid-batch":[{"text":"<p>hello\n</p>","modules":[],"modulescripts":[],"modulestyles":[],"categories":[]}]}

See also[edit]