Jump to content

Extension:External Data/Local programs

From mediawiki.org
Warning Warning: Consider replacing this feature with a web connection to a containerised service as described at the page about presets.

As of version 3.0, you can use External Data to retrieve data returned by a program run server-side. There are two ways to do this: by calling one of the standard parser (or Lua functions), or by calling a custom tag, defined with the 'tag' field in the data source definition, which handles both the retrieval and display of the data (the tag emulation mode). One advantage of the latter approach is that it allows for outputting raw HTML (most importantly, SVG); see the "Tag emulation mode" below for how to do it.

For the former approach: starting with version 3.2, the recommended way to retrieve program data is to use one of the display functions (#external_value, #for_external_table, etc.), passing in the necessary parameters for the data retrieval, most notably "source=". You can also retrieve program data by calling either #get_program_data or #get_external_data. In all of these cases, you must specify the information for the program in the variable $wgExternalDataSources in LocalSettings.php.

For any of these parser functions, you can also call its corresponding Lua function.

Simple example

[edit]

A simple example, involving only text processing, is below:

// apt-cache show
$wgExternalDataSources['apt-cache show'] = [
    'command'       => 'apt-cache show $package$',
    'params'        => [ 'package' ],
    'param filters' => [ 'package' => '/^[\w-]+$/' ]
];

and

{{#get_program_data:
    program = apt-cache show <!-- The parameter 'program' can be passed as 'source' or even anonymously, provided there are no equal signs in it -->
  | package = graphviz-doc
  | data = key=1,value=2
  | format = CSV
  | delimiter = :
 }}
 {| class="wikitable"
 ! Key !! Value {{#for_external_table:<nowiki/>
 {{!}}-
 {{!}} {{{key}}} {{!}}{{!}} {{{value}}}
 }}
 |}

Tag emulation mode

[edit]