Extension:External Data

Description
External Data is a MediaWiki extension that allows for using values on a wiki page that were retrieved from an external XML or CSV file.

It defines two parser functions: #get_external_data and #external_value. #get_external_data retrieves the data from a URL that holds XML or CSV, and assigns it to variables on the page; and #external_value displays the value of any such variable.

In this way, External Data resembles the Variables extension (not to be confused with the other Variables extension), which also allows for setting and then displaying variables; though in this case, the values originate from an external URL, not from the page itself.

Currently, a CSV file must be literally a CSV file, i.e., delimited by commas instead of tabs or any other character, for parsing to work.

Download
You can download the External Data code in either one of these two compressed files:


 * external_data_0.1.tar.gz
 * external_data_0.1.zip

You can also download the code directly via SVN from the MediaWiki source code repository, at http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ExternalData/. From a command line, you can call the following:

svn checkout http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ExternalData/

You can also view the code online here.

Installation
To install this extension, create an 'ExternalData' directory (either by extracting a compressed file or downloading via SVN), and place this directory within the main MediaWiki 'extensions' directory. Then, in the file 'LocalSettings.php', add the following line:

Author
External Data was written by Yaron Koren, reachable at yaron57 -at- gmail.com.

Usage
To get data from an external URL, call the following:

...where 'URL' is the full URL of the XML or CSV file, 'format' is one of either 'XML' or 'CSV', the "external variable names" are the names of the values in the XML or CSV file (in the case of a CSV file, the names are simply the indexes of the values ("1", "2", "3" etc.)), and the "internal variable names" are the names that are later passed in to #external_value.

More than one #get_external_data call can be used in a page. If this happens, though, make sure that every local variable name is unique.

To display data that was retrieved, call the following:

As an example, this page contains the following text:

.
 * Germany borders the following countries and bodies of water:
 * Germany has population.

The page gets data from a URL at semanticweb.org, generated by the Semantic MediaWiki extension. That URL contains the following text:

Germany,"North Sea,Denmark,Baltic Sea,Poland,Czech Republic,Austria,Switzerland,France,Luxembourg,Belgium,Netherlands","82,411,000",3.5705e+11 m²

Because the URL is in CSV format, the "external variable names" are simply indexes. The values are set to the local variables 'bordered countries', 'population' and 'area', respectively.

The page then uses #external_value to display the 'bordered countries' and 'population' values; although it uses the #arraymap function, defined by the Semantic Forms extension, to apply some transformations to the 'bordered countries' value (you can ignore this detail if you want).

Bugs and feature requests
Send any bug reports, requests or code patches to Yaron Koren, at yaron57 -at- gmail.com.